From f7181fc00c41a8f58b93acb0278576cb837182f5 Mon Sep 17 00:00:00 2001 From: nrslib <38722970+nrslib@users.noreply.github.com> Date: Fri, 30 Jan 2026 01:50:25 +0900 Subject: [PATCH] =?UTF-8?q?workflow=20=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agents/default/ai-antipattern-reviewer.md | 49 ++- .../agents/default/architecture-reviewer.md | 106 +---- resources/global/en/workflows/default.yaml | 396 +++++++---------- .../global/en/workflows/expert-cqrs.yaml | 385 +++++----------- resources/global/en/workflows/expert.yaml | 406 ++++++----------- resources/global/en/workflows/simple.yaml | 222 ++++------ .../agents/default/ai-antipattern-reviewer.md | 49 ++- .../agents/default/architecture-reviewer.md | 96 ---- resources/global/ja/workflows/default.yaml | 334 +++++--------- .../global/ja/workflows/expert-cqrs.yaml | 412 +++--------------- resources/global/ja/workflows/expert.yaml | 379 +++++----------- resources/global/ja/workflows/simple.yaml | 221 ++++------ src/__tests__/instructionBuilder.test.ts | 199 +++++++++ src/config/workflowLoader.ts | 25 +- src/models/index.ts | 1 + src/models/schemas.ts | 18 + src/models/types.ts | 10 + src/workflow/instruction-builder.ts | 214 +++++++-- 18 files changed, 1372 insertions(+), 2150 deletions(-) diff --git a/resources/global/en/agents/default/ai-antipattern-reviewer.md b/resources/global/en/agents/default/ai-antipattern-reviewer.md index 48b722e..b11bc29 100644 --- a/resources/global/en/agents/default/ai-antipattern-reviewer.md +++ b/resources/global/en/agents/default/ai-antipattern-reviewer.md @@ -126,7 +126,54 @@ AI is confidently wrong—code that looks plausible but doesn't work, solutions 2. Check whether each fallback has a legitimate reason 3. REJECT if even one unjustified fallback exists -### 7. Decision Traceability Review +### 7. Unused Code Detection + +**AI tends to generate unnecessary code "for future extensibility", "for symmetry", or "just in case". Delete code that is not called anywhere at present.** + +| Judgment | Criteria | +|----------|----------| +| **REJECT** | Public function/method not called from anywhere | +| **REJECT** | Setter/getter created "for symmetry" but never used | +| **REJECT** | Interface or option prepared for future extension | +| **REJECT** | Exported but grep finds no usage | +| OK | Implicitly called by framework (lifecycle hooks, etc.) | +| OK | Intentionally published as public package API | + +**Verification approach:** +1. Verify with grep that no references exist to changed/deleted code +2. Verify that public module (index files, etc.) export lists match actual implementations +3. Check that old code corresponding to newly added code has been removed + +### 8. Unnecessary Backward Compatibility Code Detection + +**AI tends to leave unnecessary code "for backward compatibility." Don't overlook this.** + +Code that should be deleted: + +| Pattern | Example | Judgment | +|---------|---------|----------| +| deprecated + unused | `@deprecated` annotation with no callers | **Delete immediately** | +| Both new and old API exist | New function exists but old function remains | **Delete old** | +| Migrated wrappers | Created for compatibility but migration complete | **Delete** | +| Comments saying "delete later" | `// TODO: remove after migration` left unattended | **Delete now** | +| Excessive proxy/adapter usage | Complexity added only for backward compatibility | **Replace with simple** | + +Code that should be kept: + +| Pattern | Example | Judgment | +|---------|---------|----------| +| Externally published API | npm package exports | Consider carefully | +| Config file compatibility | Can read old format configs | Maintain until major version | +| During data migration | DB schema migration in progress | Maintain until migration complete | + +**Decision criteria:** +1. **Are there any usage sites?** → Verify with grep/search. Delete if none +2. **Is it externally published?** → If internal only, can delete immediately +3. **Is migration complete?** → If complete, delete + +**Be suspicious when AI says "for backward compatibility."** Verify if it's really needed. + +### 9. Decision Traceability Review **Verify that Coder's decision log is reasonable.** diff --git a/resources/global/en/agents/default/architecture-reviewer.md b/resources/global/en/agents/default/architecture-reviewer.md index 3694ff6..677f44a 100644 --- a/resources/global/en/agents/default/architecture-reviewer.md +++ b/resources/global/en/agents/default/architecture-reviewer.md @@ -191,73 +191,6 @@ if (status === 'interrupted') { } ``` -**Fallback Value Overuse Detection Criteria:** - -Fallback values (`??`, `||`, default arguments) silently swallow "value is missing" cases. They hide what should be errors. - -| Judgment | Criteria | -|----------|----------| -| **REJECT** | Fallback hides a bug where a missing value indicates data inconsistency | -| **REJECT** | Uses meaningless values like `'unknown'`, `'default'`, `''`, `0` as cover | -| **REJECT** | All call sites rely on fallback — no one passes the actual value | -| OK | Defensive default for external input (user input, API responses) | -| OK | Reasonable initial value for optional configuration | - -```typescript -// ❌ REJECT - Fallback hiding a bug -const userName = user.name ?? 'unknown'; // Missing name is data inconsistency -const stepName = step?.name ?? 'default'; // Missing step is a caller bug - -// ❌ REJECT - Option that all call sites omit -function runStep(step: Step, options?: { maxRetries?: number }) { - const retries = options?.maxRetries ?? 3; // No call site passes options -} - -// ✅ OK - Optional user setting with reasonable default -const logLevel = config.logLevel ?? 'info'; // Default if not in config file -const language = userPreference.lang ?? 'en'; // Default if not set - -// ✅ OK - Defensive default for external API -const displayName = apiResponse.nickname ?? apiResponse.email; // Fallback if no nickname -``` - -**Unused Code Detection Criteria:** - -AI tends to generate unnecessary code "for future extensibility", "for symmetry", or "just in case". Delete code that is not called anywhere at present. - -| Judgment | Criteria | -|----------|----------| -| **REJECT** | Public function/method not called from anywhere | -| **REJECT** | Setter/getter created "for symmetry" but never used | -| **REJECT** | Interface or option prepared for future extension | -| **REJECT** | Exported but grep finds no usage | -| OK | Implicitly called by framework (lifecycle hooks, etc.) | -| OK | Intentionally published as public package API | - -```typescript -// ❌ REJECT - Setter "for symmetry" (only get is used) -class WorkflowState { - private _status: Status; - getStatus(): Status { return this._status; } - setStatus(s: Status) { this._status = s; } // No one calls this -} - -// ❌ REJECT - Options for "future extension" -interface EngineOptions { - maxIterations: number; - enableParallel?: boolean; // Not implemented. Not referenced anywhere - pluginHooks?: PluginHook[]; // Not implemented. No plugin system exists -} - -// ❌ REJECT - Exported but unused -export function formatStepName(name: string): string { ... } // grep result: 0 hits - -// ✅ OK - Called by framework -class MyComponent extends React.Component { - componentDidMount() { ... } // Called by React -} -``` - **Direct State Mutation Detection Criteria:** Directly mutating objects or arrays makes changes hard to track and causes unexpected side effects. Always use spread operators or immutable operations to return new objects. @@ -379,36 +312,7 @@ function createUser(data: UserData) { } ``` -### 7. Unnecessary Backward Compatibility Code Detection - -**AI tends to leave unnecessary code "for backward compatibility." Don't overlook this.** - -Code that should be deleted: - -| Pattern | Example | Judgment | -|---------|---------|----------| -| deprecated + unused | `@deprecated` annotation with no callers | **Delete immediately** | -| Both new and old API exist | New function exists but old function remains | **Delete old** | -| Migrated wrappers | Created for compatibility but migration complete | **Delete** | -| Comments saying "delete later" | `// TODO: remove after migration` left unattended | **Delete now** | -| Excessive proxy/adapter usage | Complexity added only for backward compatibility | **Replace with simple** | - -Code that should be kept: - -| Pattern | Example | Judgment | -|---------|---------|----------| -| Externally published API | npm package exports | Consider carefully | -| Config file compatibility | Can read old format configs | Maintain until major version | -| During data migration | DB schema migration in progress | Maintain until migration complete | - -**Decision criteria:** -1. **Are there any usage sites?** → Verify with grep/search. Delete if none -2. **Is it externally published?** → If internal only, can delete immediately -3. **Is migration complete?** → If complete, delete - -**Be suspicious when AI says "for backward compatibility."** Verify if it's really needed. - -### 8. Workaround Detection +### 7. Workaround Detection **Don't overlook compromises made to "just make it work."** @@ -423,7 +327,7 @@ Code that should be kept: **Always point these out.** Temporary fixes become permanent. -### 9. Quality Attributes +### 8. Quality Attributes | Attribute | Review Point | |-----------|--------------| @@ -431,7 +335,7 @@ Code that should be kept: | Maintainability | Easy to modify and fix | | Observability | Logging and monitoring enabled | -### 10. Big Picture +### 9. Big Picture **Caution**: Don't get lost in minor "clean code" nitpicks. @@ -442,7 +346,7 @@ Verify: - Does it align with business requirements - Is naming consistent with the domain -### 11. Change Scope Assessment +### 10. Change Scope Assessment **Check change scope and include in report (non-blocking).** @@ -461,7 +365,7 @@ Verify: **Include as suggestions (non-blocking):** - If splittable, present splitting proposal -### 12. Circular Review Detection +### 11. Circular Review Detection When review count is provided (e.g., "Review count: 3rd"), adjust judgment accordingly. diff --git a/resources/global/en/workflows/default.yaml b/resources/global/en/workflows/default.yaml index a12e484..345dd92 100644 --- a/resources/global/en/workflows/default.yaml +++ b/resources/global/en/workflows/default.yaml @@ -1,26 +1,36 @@ # Default TAKT Workflow -# Plan -> Coder -> Architect Review -> AI Review -> Security Review -> Supervisor Approval +# Plan -> Coder -> AI Review -> Architect Review -> Security Review -> Supervisor Approval # -# Template Variables: -# {iteration} - Workflow-wide turn count (total steps executed across all agents) -# {max_iterations} - Maximum iterations allowed for the workflow -# {step_iteration} - Per-step iteration count (how many times THIS step has been executed) -# {task} - Original user request -# {previous_response} - Output from the previous step -# {git_diff} - Current uncommitted changes (git diff) -# {user_inputs} - Accumulated user inputs during workflow -# {report_dir} - Report directory name (e.g., "20250126-143052-task-summary") +# Boilerplate sections (Workflow Context, User Request, Previous Response, +# Additional User Inputs, Instructions heading) are auto-injected by buildInstruction(). +# Only step-specific content belongs in instruction_template. +# +# Template Variables (available in instruction_template): +# {iteration} - Workflow-wide turn count (total steps executed across all agents) +# {max_iterations} - Maximum iterations allowed for the workflow +# {step_iteration} - Per-step iteration count (how many times THIS step has been executed) +# {previous_response} - Output from the previous step (only when pass_previous_response: true) +# {git_diff} - Current uncommitted changes (git diff) +# {report_dir} - Report directory name (e.g., "20250126-143052-task-summary") +# +# Step-level Fields: +# report: - Report file(s) for the step (auto-injected as Report File/Files in Workflow Context) +# Single: report: 00-plan.md +# Multiple: report: +# - Scope: 01-coder-scope.md +# - Decisions: 02-coder-decisions.md name: default description: Standard development workflow with planning and specialized reviews -max_iterations: 20 +max_iterations: 30 initial_step: plan steps: - name: plan agent: ~/.takt/agents/default/planner.md + report: 00-plan.md allowed_tools: - Read - Glob @@ -42,20 +52,9 @@ steps: - {Question 2} pass_previous_response: true instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: plan (Task Analysis) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/00-plan.md - - ## User Request - {task} - ## Previous Response (when returned from implement) {previous_response} - ## Instructions Analyze the task and create an implementation plan. **Note:** If returned from implement step (Previous Response exists), @@ -94,6 +93,9 @@ steps: - name: implement agent: ~/.takt/agents/default/coder.md + report: + - Scope: 01-coder-scope.md + - Decisions: 02-coder-decisions.md allowed_tools: - Read - Glob @@ -106,26 +108,10 @@ steps: permission_mode: acceptEdits rules: - condition: Implementation complete - next: review + next: ai_review - condition: Cannot proceed, insufficient info next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: implement - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Scope: .takt/reports/{report_dir}/01-coder-scope.md - - Decisions: .takt/reports/{report_dir}/02-coder-decisions.md - - ## User Request - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions Follow the plan from the plan step and implement. Refer to the plan report (00-plan.md) and proceed with implementation. @@ -163,120 +149,9 @@ steps: - **Reason**: {Why this option was chosen} ``` - - name: review - agent: ~/.takt/agents/default/architecture-reviewer.md - allowed_tools: - - Read - - Glob - - Grep - - Write - - WebSearch - - WebFetch - rules: - - condition: No issues found - next: ai_review - - condition: Minor improvements needed - next: improve - - condition: Structural fix required - next: fix - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: review (Architecture Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/03-architect-review.md - - ## Original User Request (Initial request from workflow start) - {task} - - ## Git Diff - ```diff - {git_diff} - ``` - - ## Instructions - Focus on **architecture and design** review. Do NOT review AI-specific issues (that's the next step). - - Review the changes and provide feedback. - - **Report output:** Output to the `Report File` specified above. - - If file does not exist: Create new file - - If file exists: Append with `## Iteration {step_iteration}` section - - **Report format:** - ```markdown - # Architecture Review - - ## Result: APPROVE / IMPROVE / REJECT - - ## Summary - {1-2 sentences summarizing result} - - ## Reviewed Perspectives - - [x] Structure & Design - - [x] Code Quality - - [x] Change Scope - - ## Issues (if REJECT) - | # | Location | Issue | Fix | - |---|----------|-------|-----| - | 1 | `src/file.ts:42` | Issue description | Fix method | - - ## Improvement Suggestions (optional, non-blocking) - - {Future improvement suggestions} - ``` - - **Cognitive load reduction rules:** - - APPROVE + no issues -> Summary only (5 lines or less) - - APPROVE + minor suggestions -> Summary + suggestions (15 lines or less) - - REJECT -> Issues in table format (30 lines or less) - - - name: improve - agent: ~/.takt/agents/default/coder.md - allowed_tools: - - Read - - Glob - - Grep - - Edit - - Write - - Bash - - WebSearch - - WebFetch - permission_mode: acceptEdits - rules: - - condition: Improvements complete - next: review - - condition: Cannot proceed, insufficient info - next: plan - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: improve - - ## Architect Feedback (This is the latest instruction - prioritize this) - {previous_response} - - ## Original User Request (Initial request from workflow start - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions - **Important**: Address the Architect's improvement suggestions. - These are minor improvements, not major design issues. - - Make improvements such as: - - Naming improvements - - Small refactoring - - Adding/fixing comments - - Code organization - pass_previous_response: true - - name: ai_review agent: ~/.takt/agents/default/ai-antipattern-reviewer.md + report: 03-ai-review.md allowed_tools: - Read - Glob @@ -286,26 +161,15 @@ steps: - WebFetch rules: - condition: No AI-specific issues - next: security_review + next: review - condition: AI-specific issues found next: ai_fix instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: ai_review (AI-Generated Code Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/04-ai-review.md - - ## Original User Request (Initial request from workflow start) - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Review the code for AI-specific issues: - Assumption validation - Plausible but wrong patterns @@ -361,21 +225,9 @@ steps: - condition: Cannot proceed, insufficient info next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: ai_fix - ## AI Review Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request from workflow start - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Address the AI Reviewer's feedback. Focus on: - Correcting incorrect assumptions @@ -384,8 +236,125 @@ steps: - Removing scope creep pass_previous_response: true + - name: review + agent: ~/.takt/agents/default/architecture-reviewer.md + report: 04-architect-review.md + allowed_tools: + - Read + - Glob + - Grep + - Write + - WebSearch + - WebFetch + rules: + - condition: No issues found + next: security_review + - condition: Minor improvements needed + next: improve + - condition: Structural fix required + next: fix + instruction_template: | + ## Git Diff + ```diff + {git_diff} + ``` + + Focus on **architecture and design** review. Do NOT review AI-specific issues (that's the ai_review step). + + Review the changes and provide feedback. + + **Report output:** Output to the `Report File` specified above. + - If file does not exist: Create new file + - If file exists: Append with `## Iteration {step_iteration}` section + + **Report format:** + ```markdown + # Architecture Review + + ## Result: APPROVE / IMPROVE / REJECT + + ## Summary + {1-2 sentences summarizing result} + + ## Reviewed Perspectives + - [x] Structure & Design + - [x] Code Quality + - [x] Change Scope + + ## Issues (if REJECT) + | # | Location | Issue | Fix | + |---|----------|-------|-----| + | 1 | `src/file.ts:42` | Issue description | Fix method | + + ## Improvement Suggestions (optional, non-blocking) + - {Future improvement suggestions} + ``` + + **Cognitive load reduction rules:** + - APPROVE + no issues -> Summary only (5 lines or less) + - APPROVE + minor suggestions -> Summary + suggestions (15 lines or less) + - REJECT -> Issues in table format (30 lines or less) + + - name: improve + agent: ~/.takt/agents/default/coder.md + allowed_tools: + - Read + - Glob + - Grep + - Edit + - Write + - Bash + - WebSearch + - WebFetch + permission_mode: acceptEdits + rules: + - condition: Improvements complete + next: review + - condition: Cannot proceed, insufficient info + next: plan + instruction_template: | + ## Architect Feedback (This is the latest instruction - prioritize this) + {previous_response} + + **Important**: Address the Architect's improvement suggestions. + These are minor improvements, not major design issues. + + Make improvements such as: + - Naming improvements + - Small refactoring + - Adding/fixing comments + - Code organization + pass_previous_response: true + + - name: fix + agent: ~/.takt/agents/default/coder.md + allowed_tools: + - Read + - Glob + - Grep + - Edit + - Write + - Bash + - WebSearch + - WebFetch + permission_mode: acceptEdits + rules: + - condition: Architect feedback addressed + next: review + - condition: Cannot proceed, insufficient info + next: plan + instruction_template: | + ## Architect Feedback (This is the latest instruction - prioritize this) + {previous_response} + + **Important**: Address the Architect's feedback. + The "Original User Request" is reference information, not the latest instruction. + Review the session conversation history and fix the issues raised by the Architect. + pass_previous_response: true + - name: security_review agent: ~/.takt/agents/default/security-reviewer.md + report: 05-security-review.md allowed_tools: - Read - Glob @@ -399,22 +368,11 @@ steps: - condition: Vulnerabilities require fix next: security_fix instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: security_review - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/05-security-review.md - - ## Original User Request (Initial request from workflow start) - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Perform security review on the changes. Check for vulnerabilities including: - Injection attacks (SQL, Command, XSS) - Authentication/Authorization issues @@ -473,65 +431,18 @@ steps: - condition: Cannot proceed, insufficient info next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: security_fix - ## Security Review Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request from workflow start - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the vulnerabilities identified in the security review. Security issues require highest priority. pass_previous_response: true - - name: fix - agent: ~/.takt/agents/default/coder.md - allowed_tools: - - Read - - Glob - - Grep - - Edit - - Write - - Bash - - WebSearch - - WebFetch - permission_mode: acceptEdits - rules: - - condition: Architect feedback addressed - next: review - - condition: Cannot proceed, insufficient info - next: plan - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix - - ## Architect Feedback (This is the latest instruction - prioritize this) - {previous_response} - - ## Original User Request (Initial request from workflow start - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions - **Important**: Address the Architect's feedback. - The "Original User Request" is reference information, not the latest instruction. - Review the session conversation history and fix the issues raised by the Architect. - pass_previous_response: true - - name: supervise agent: ~/.takt/agents/default/supervisor.md + report: + - Validation: 06-supervisor-validation.md + - Summary: summary.md allowed_tools: - Read - Glob @@ -546,24 +457,11 @@ steps: - condition: Requirements unmet, tests failing, build errors next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: supervise (final verification) - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Validation: .takt/reports/{report_dir}/06-supervisor-validation.md - - Summary: .takt/reports/{report_dir}/summary.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Run tests, verify the build, and perform final approval. **Workflow Overall Review:** diff --git a/resources/global/en/workflows/expert-cqrs.yaml b/resources/global/en/workflows/expert-cqrs.yaml index b8594b2..fa59e05 100644 --- a/resources/global/en/workflows/expert-cqrs.yaml +++ b/resources/global/en/workflows/expert-cqrs.yaml @@ -1,14 +1,14 @@ -# Expert Review Workflow +# Expert CQRS Review Workflow # Review workflow with CQRS+ES, Frontend, Security, and QA experts # # Flow: -# plan -> implement -> cqrs_es_review -> frontend_review -> ai_review -> security_review -> qa_review -> supervise -> COMPLETE -# ↓ ↓ ↓ ↓ ↓ ↓ -# fix_cqrs_es fix_frontend ai_fix fix_security fix_qa fix_supervisor +# plan -> implement -> ai_review -> cqrs_es_review -> frontend_review -> security_review -> qa_review -> supervise -> COMPLETE +# ↓ ↓ ↓ ↓ ↓ ↓ +# ai_fix fix_cqrs_es fix_frontend fix_security fix_qa fix_supervisor # # Fix destination is determined by Coder based on change impact: -# - fix_security: MINOR→security_review, MAJOR→cqrs_es_review -# - fix_qa: MINOR→qa_review, SECURITY→security_review, MAJOR→cqrs_es_review +# - fix_security: MINOR->security_review, MAJOR->cqrs_es_review +# - fix_qa: MINOR->qa_review, SECURITY->security_review, MAJOR->cqrs_es_review # # Template Variables: # {iteration} - Workflow-wide turn count (total steps executed across all agents) @@ -23,7 +23,7 @@ name: expert-cqrs description: CQRS+ES, Frontend, Security, QA Expert Review -max_iterations: 20 +max_iterations: 30 initial_step: plan @@ -33,6 +33,7 @@ steps: # =========================================== - name: plan agent: ~/.takt/agents/default/planner.md + report: 00-plan.md allowed_tools: - Read - Glob @@ -42,20 +43,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: plan (Task Analysis) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/00-plan.md - - ## User Request - {task} - ## Previous Response (when returned from implement) {previous_response} - ## Instructions Analyze the task and create an implementation plan. **Note:** If returned from implement step (Previous Response exists), @@ -103,6 +93,9 @@ steps: # =========================================== - name: implement agent: ~/.takt/agents/default/coder.md + report: + - Scope: 01-coder-scope.md + - Decisions: 02-coder-decisions.md allowed_tools: - Read - Glob @@ -113,22 +106,6 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: implement - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Scope: .takt/reports/{report_dir}/01-coder-scope.md - - Decisions: .takt/reports/{report_dir}/02-coder-decisions.md - - ## User Request - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions Follow the plan from the plan step and implement. Refer to the plan report (00-plan.md) and proceed with implementation. @@ -167,15 +144,105 @@ steps: ``` rules: - condition: Implementation is complete - next: cqrs_es_review + next: ai_review - condition: Cannot proceed with implementation next: plan # =========================================== - # Phase 2: CQRS+ES Review + # Phase 2: AI Review # =========================================== - - name: cqrs_es_review - agent: ~/.takt/agents/expert-cqrs/cqrs-es-reviewer.md + - name: ai_review + agent: ~/.takt/agents/default/ai-antipattern-reviewer.md + report: 03-ai-review.md + allowed_tools: + - Read + - Glob + - Grep + - Write + - WebSearch + - WebFetch + instruction_template: | + ## Git Diff + ```diff + {git_diff} + ``` + + Review the code for AI-specific issues: + - Assumption validation + - Plausible but wrong patterns + - Context fit with existing codebase + - Scope creep detection + + **Report output:** Output to the `Report File` specified above. + - If file does not exist: Create new file + - If file exists: Append with `## Iteration {step_iteration}` section + + **Report format:** + ```markdown + # AI-Generated Code Review + + ## Result: APPROVE / REJECT + + ## Summary + {One sentence summarizing result} + + ## Verified Items + | Aspect | Result | Notes | + |--------|--------|-------| + | Assumption validity | ✅ | - | + | API/Library existence | ✅ | - | + | Context fit | ✅ | - | + | Scope | ✅ | - | + + ## Issues (if REJECT) + | # | Category | Location | Issue | + |---|----------|----------|-------| + | 1 | Hallucinated API | `src/file.ts:23` | Non-existent method | + ``` + + **Cognitive load reduction rules:** + - No issues → Summary 1 line + check table only (10 lines or less) + - Issues found → + Issues in table format (25 lines or less) + rules: + - condition: No AI-specific issues found + next: cqrs_es_review + - condition: AI-specific issues detected + next: ai_fix + + - name: ai_fix + agent: ~/.takt/agents/default/coder.md + allowed_tools: + - Read + - Glob + - Grep + - Edit + - Write + - Bash + - WebSearch + - WebFetch + instruction_template: | + ## AI Review Feedback (This is the latest instruction - prioritize this) + {previous_response} + + **Important**: Address the AI Reviewer's feedback. + Focus on: + - Correcting incorrect assumptions + - Fixing plausible-but-wrong implementations + - Aligning with existing codebase patterns + - Removing scope creep + pass_previous_response: true + rules: + - condition: AI Reviewer's issues have been fixed + next: ai_review + - condition: Unable to proceed with fixes + next: plan + + # =========================================== + # Phase 3: CQRS+ES Review + # =========================================== + - name: cqrs_es_review + agent: ~/.takt/agents/expert-cqrs/cqrs-es-reviewer.md + report: 04-cqrs-es-review.md allowed_tools: - Read - Glob @@ -184,22 +251,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: cqrs_es_review (CQRS+ES Expert Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/03-cqrs-es-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Review the changes above from the CQRS (Command Query Responsibility Segregation) and Event Sourcing perspective. @@ -258,21 +314,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_cqrs_es - ## CQRS+ES Review Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the issues pointed out by the CQRS+ES expert. Areas of concern: @@ -289,10 +333,11 @@ steps: next: plan # =========================================== - # Phase 3: Frontend Review + # Phase 4: Frontend Review # =========================================== - name: frontend_review agent: ~/.takt/agents/expert/frontend-reviewer.md + report: 05-frontend-review.md allowed_tools: - Read - Glob @@ -301,22 +346,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: frontend_review (Frontend Expert Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/04-frontend-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Review the changes above from the frontend development perspective. **Review Criteria:** @@ -359,7 +393,7 @@ steps: ``` rules: - condition: Frontend design is sound with no issues - next: ai_review + next: security_review - condition: Frontend design issues found next: fix_frontend @@ -375,21 +409,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_frontend - ## Frontend Review Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the issues pointed out by the frontend expert. Areas of concern: @@ -405,122 +427,12 @@ steps: - condition: Unable to proceed with fixes next: plan - # =========================================== - # Phase 4: AI Review - # =========================================== - - name: ai_review - agent: ~/.takt/agents/default/ai-antipattern-reviewer.md - allowed_tools: - - Read - - Glob - - Grep - - Write - - WebSearch - - WebFetch - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: ai_review (AI-Generated Code Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/05-ai-review.md - - ## Original User Request (Initial request from workflow start) - {task} - - ## Git Diff - ```diff - {git_diff} - ``` - - ## Instructions - Review the code for AI-specific issues: - - Assumption validation - - Plausible but wrong patterns - - Context fit with existing codebase - - Scope creep detection - - **Report output:** Output to the `Report File` specified above. - - If file does not exist: Create new file - - If file exists: Append with `## Iteration {step_iteration}` section - - **Report format:** - ```markdown - # AI-Generated Code Review - - ## Result: APPROVE / REJECT - - ## Summary - {One sentence summarizing result} - - ## Verified Items - | Aspect | Result | Notes | - |--------|--------|-------| - | Assumption validity | ✅ | - | - | API/Library existence | ✅ | - | - | Context fit | ✅ | - | - | Scope | ✅ | - | - - ## Issues (if REJECT) - | # | Category | Location | Issue | - |---|----------|----------|-------| - | 1 | Hallucinated API | `src/file.ts:23` | Non-existent method | - ``` - - **Cognitive load reduction rules:** - - No issues → Summary 1 line + check table only (10 lines or less) - - Issues found → + Issues in table format (25 lines or less) - rules: - - condition: No AI-specific issues found - next: security_review - - condition: AI-specific issues detected - next: ai_fix - - - name: ai_fix - agent: ~/.takt/agents/default/coder.md - allowed_tools: - - Read - - Glob - - Grep - - Edit - - Write - - Bash - - WebSearch - - WebFetch - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: ai_fix - - ## AI Review Feedback (This is the latest instruction - prioritize this) - {previous_response} - - ## Original User Request (Initial request from workflow start - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions - **Important**: Address the AI Reviewer's feedback. - Focus on: - - Correcting incorrect assumptions - - Fixing plausible-but-wrong implementations - - Aligning with existing codebase patterns - - Removing scope creep - pass_previous_response: true - rules: - - condition: AI Reviewer's issues have been fixed - next: ai_review - - condition: Unable to proceed with fixes - next: plan - # =========================================== # Phase 5: Security Review # =========================================== - name: security_review agent: ~/.takt/agents/expert/security-reviewer.md + report: 06-security-review.md allowed_tools: - Read - Glob @@ -529,22 +441,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: security_review (Security Expert Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/06-security-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Review the changes above from the security perspective. **Review Criteria:** @@ -600,21 +501,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_security - ## Security Review Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the issues pointed out by the security expert. Security issues should be addressed with highest priority. @@ -645,6 +534,7 @@ steps: # =========================================== - name: qa_review agent: ~/.takt/agents/expert/qa-reviewer.md + report: 07-qa-review.md allowed_tools: - Read - Glob @@ -653,22 +543,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: qa_review (QA Expert Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/07-qa-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Review the changes above from the quality assurance perspective. **Review Criteria:** @@ -724,21 +603,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_qa - ## QA Review Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the issues pointed out by the QA expert. Areas of concern: @@ -773,6 +640,9 @@ steps: # =========================================== - name: supervise agent: ~/.takt/agents/expert/supervisor.md + report: + - Validation: 08-supervisor-validation.md + - Summary: summary.md allowed_tools: - Read - Glob @@ -781,18 +651,6 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: supervise (Final Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Validation: .takt/reports/{report_dir}/08-supervisor-validation.md - - Summary: .takt/reports/{report_dir}/summary.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} @@ -800,13 +658,12 @@ steps: ## Previous Reviews Summary Reaching this step means all the following reviews have been APPROVED: + - AI Review: APPROVED - CQRS+ES Review: APPROVED - Frontend Review: APPROVED - - AI Review: APPROVED - Security Review: APPROVED - QA Review: APPROVED - ## Instructions Run tests, verify the build, and perform final approval. **Workflow Overall Review:** @@ -863,9 +720,9 @@ steps: ## Review Results | Review | Result | |--------|--------| + | AI Review | ✅ APPROVE | | CQRS+ES | ✅ APPROVE | | Frontend | ✅ APPROVE | - | AI Review | ✅ APPROVE | | Security | ✅ APPROVE | | QA | ✅ APPROVE | | Supervisor | ✅ APPROVE | @@ -894,21 +751,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_supervisor - ## Supervisor Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the issues pointed out by the supervisor. The supervisor has identified issues from a big-picture perspective. diff --git a/resources/global/en/workflows/expert.yaml b/resources/global/en/workflows/expert.yaml index cf066ac..a9aa043 100644 --- a/resources/global/en/workflows/expert.yaml +++ b/resources/global/en/workflows/expert.yaml @@ -2,13 +2,16 @@ # Review workflow with Architecture, Frontend, Security, and QA experts # # Flow: -# plan -> implement -> architect_review -> frontend_review -> ai_review -> security_review -> qa_review -> supervise -> COMPLETE -# ↓ ↓ ↓ ↓ ↓ ↓ -# fix_architect fix_frontend ai_fix fix_security fix_qa fix_supervisor +# plan -> implement -> ai_review -> architect_review -> frontend_review -> security_review -> qa_review -> supervise -> COMPLETE +# ↓ ↓ ↓ ↓ ↓ ↓ ↓ +# ai_fix fix_architect fix_frontend fix_security fix_qa fix_supervisor +# +# AI review runs immediately after implementation to catch AI-specific issues early, +# before expert reviews begin. # # Fix destination is determined by Coder based on change impact: -# - fix_security: MINOR→security_review, MAJOR→architect_review -# - fix_qa: MINOR→qa_review, SECURITY→security_review, MAJOR→architect_review +# - fix_security: MINOR->security_review, MAJOR->architect_review +# - fix_qa: MINOR->qa_review, SECURITY->security_review, MAJOR->architect_review # # Template Variables: # {iteration} - Workflow-wide turn count (total steps executed across all agents) @@ -23,7 +26,7 @@ name: expert description: Architecture, Frontend, Security, QA Expert Review -max_iterations: 20 +max_iterations: 30 initial_step: plan @@ -33,6 +36,7 @@ steps: # =========================================== - name: plan agent: ~/.takt/agents/default/planner.md + report: 00-plan.md allowed_tools: - Read - Glob @@ -42,20 +46,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: plan (Task Analysis) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/00-plan.md - - ## User Request - {task} - ## Previous Response (when returned from implement) {previous_response} - ## Instructions Analyze the task and create an implementation plan. **Note:** If returned from implement step (Previous Response exists), @@ -66,7 +59,7 @@ steps: 2. Identify impact scope 3. Decide implementation approach - **Report output:** Output to the `Report File` specified above. + **Report output:** Output to `.takt/reports/{report_dir}/00-plan.md`. - If file does not exist: Create new file - If file exists: Append with `## Iteration {step_iteration}` section @@ -103,6 +96,9 @@ steps: # =========================================== - name: implement agent: ~/.takt/agents/default/coder.md + report: + - Scope: 01-coder-scope.md + - Decisions: 02-coder-decisions.md allowed_tools: - Read - Glob @@ -113,26 +109,12 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: implement - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Scope: .takt/reports/{report_dir}/01-coder-scope.md - - Decisions: .takt/reports/{report_dir}/02-coder-decisions.md - - ## User Request - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions Follow the plan from the plan step and implement. Refer to the plan report (00-plan.md) and proceed with implementation. - **Report output:** Output to the `Report Files` specified above. + **Report output:** Output to the report files specified below. + - Scope: `.takt/reports/{report_dir}/01-coder-scope.md` + - Decisions: `.takt/reports/{report_dir}/02-coder-decisions.md` - If file does not exist: Create new file - If file exists: Append with `## Iteration {step_iteration}` section @@ -167,15 +149,105 @@ steps: ``` rules: - condition: Implementation is complete - next: architect_review + next: ai_review - condition: Cannot proceed with implementation next: plan # =========================================== - # Phase 2: Architecture Review + # Phase 2: AI Review # =========================================== - - name: architect_review - agent: ~/.takt/agents/default/architecture-reviewer.md + - name: ai_review + agent: ~/.takt/agents/default/ai-antipattern-reviewer.md + report: 03-ai-review.md + allowed_tools: + - Read + - Glob + - Grep + - Write + - WebSearch + - WebFetch + instruction_template: | + ## Git Diff + ```diff + {git_diff} + ``` + + Review the code for AI-specific issues: + - Assumption validation + - Plausible but wrong patterns + - Context fit with existing codebase + - Scope creep detection + + **Report output:** Output to `.takt/reports/{report_dir}/03-ai-review.md`. + - If file does not exist: Create new file + - If file exists: Append with `## Iteration {step_iteration}` section + + **Report format:** + ```markdown + # AI-Generated Code Review + + ## Result: APPROVE / REJECT + + ## Summary + {One sentence summarizing result} + + ## Verified Items + | Aspect | Result | Notes | + |--------|--------|-------| + | Assumption validity | ✅ | - | + | API/Library existence | ✅ | - | + | Context fit | ✅ | - | + | Scope | ✅ | - | + + ## Issues (if REJECT) + | # | Category | Location | Issue | + |---|----------|----------|-------| + | 1 | Hallucinated API | `src/file.ts:23` | Non-existent method | + ``` + + **Cognitive load reduction rules:** + - No issues -> Summary 1 line + check table only (10 lines or less) + - Issues found -> + Issues in table format (25 lines or less) + rules: + - condition: No AI-specific issues found + next: architect_review + - condition: AI-specific issues detected + next: ai_fix + + - name: ai_fix + agent: ~/.takt/agents/default/coder.md + allowed_tools: + - Read + - Glob + - Grep + - Edit + - Write + - Bash + - WebSearch + - WebFetch + instruction_template: | + ## AI Review Feedback (This is the latest instruction - prioritize this) + {previous_response} + + **Important**: Address the AI Reviewer's feedback. + Focus on: + - Correcting incorrect assumptions + - Fixing plausible-but-wrong implementations + - Aligning with existing codebase patterns + - Removing scope creep + pass_previous_response: true + rules: + - condition: AI Reviewer's issues have been fixed + next: ai_review + - condition: Unable to proceed with fixes + next: plan + + # =========================================== + # Phase 3: Architecture Review + # =========================================== + - name: architect_review + agent: ~/.takt/agents/default/architecture-reviewer.md + report: 04-architect-review.md allowed_tools: - Read - Glob @@ -184,22 +256,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: architect_review (Architecture Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/03-architect-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Focus on **architecture and design** review. **Review Criteria:** @@ -210,7 +271,7 @@ steps: - Dead code - Call chain verification - **Report output:** Output to the `Report File` specified above. + **Report output:** Output to `.takt/reports/{report_dir}/04-architect-review.md`. - If file does not exist: Create new file - If file exists: Append with `## Iteration {step_iteration}` section @@ -241,9 +302,9 @@ steps: ``` **Cognitive load reduction rules:** - - APPROVE + no issues → Summary only (5 lines or less) - - APPROVE + minor suggestions → Summary + suggestions (15 lines or less) - - REJECT → Issues in table format (30 lines or less) + - APPROVE + no issues -> Summary only (5 lines or less) + - APPROVE + minor suggestions -> Summary + suggestions (15 lines or less) + - REJECT -> Issues in table format (30 lines or less) rules: - condition: No architecture or design issues found next: frontend_review @@ -265,21 +326,9 @@ steps: - WebFetch permission_mode: acceptEdits instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_architect - ## Architect Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Address the Architect's feedback. "Original User Request" is for reference; it's not the latest instruction. Review the session conversation history and fix the Architect's issues. @@ -291,10 +340,11 @@ steps: next: plan # =========================================== - # Phase 3: Frontend Review + # Phase 4: Frontend Review # =========================================== - name: frontend_review agent: ~/.takt/agents/expert/frontend-reviewer.md + report: 05-frontend-review.md allowed_tools: - Read - Glob @@ -303,22 +353,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: frontend_review (Frontend Expert Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/04-frontend-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Review the changes above from the frontend development perspective. **Review Criteria:** @@ -332,7 +371,7 @@ steps: **Note**: If this project does not include frontend code, approve and proceed to the next step. - **Report output:** Output to the `Report File` specified above. + **Report output:** Output to `.takt/reports/{report_dir}/05-frontend-review.md`. - If file does not exist: Create new file - If file exists: Append with `## Iteration {step_iteration}` section @@ -361,7 +400,7 @@ steps: ``` rules: - condition: Frontend design is sound with no issues - next: ai_review + next: security_review - condition: Frontend design issues found next: fix_frontend @@ -377,21 +416,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_frontend - ## Frontend Review Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the issues pointed out by the frontend expert. Areas of concern: @@ -407,122 +434,12 @@ steps: - condition: Unable to proceed with fixes next: plan - # =========================================== - # Phase 4: AI Review - # =========================================== - - name: ai_review - agent: ~/.takt/agents/default/ai-antipattern-reviewer.md - allowed_tools: - - Read - - Glob - - Grep - - Write - - WebSearch - - WebFetch - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: ai_review (AI-Generated Code Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/05-ai-review.md - - ## Original User Request (Initial request from workflow start) - {task} - - ## Git Diff - ```diff - {git_diff} - ``` - - ## Instructions - Review the code for AI-specific issues: - - Assumption validation - - Plausible but wrong patterns - - Context fit with existing codebase - - Scope creep detection - - **Report output:** Output to the `Report File` specified above. - - If file does not exist: Create new file - - If file exists: Append with `## Iteration {step_iteration}` section - - **Report format:** - ```markdown - # AI-Generated Code Review - - ## Result: APPROVE / REJECT - - ## Summary - {One sentence summarizing result} - - ## Verified Items - | Aspect | Result | Notes | - |--------|--------|-------| - | Assumption validity | ✅ | - | - | API/Library existence | ✅ | - | - | Context fit | ✅ | - | - | Scope | ✅ | - | - - ## Issues (if REJECT) - | # | Category | Location | Issue | - |---|----------|----------|-------| - | 1 | Hallucinated API | `src/file.ts:23` | Non-existent method | - ``` - - **Cognitive load reduction rules:** - - No issues → Summary 1 line + check table only (10 lines or less) - - Issues found → + Issues in table format (25 lines or less) - rules: - - condition: No AI-specific issues found - next: security_review - - condition: AI-specific issues detected - next: ai_fix - - - name: ai_fix - agent: ~/.takt/agents/default/coder.md - allowed_tools: - - Read - - Glob - - Grep - - Edit - - Write - - Bash - - WebSearch - - WebFetch - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: ai_fix - - ## AI Review Feedback (This is the latest instruction - prioritize this) - {previous_response} - - ## Original User Request (Initial request from workflow start - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions - **Important**: Address the AI Reviewer's feedback. - Focus on: - - Correcting incorrect assumptions - - Fixing plausible-but-wrong implementations - - Aligning with existing codebase patterns - - Removing scope creep - pass_previous_response: true - rules: - - condition: AI Reviewer's issues have been fixed - next: ai_review - - condition: Unable to proceed with fixes - next: plan - # =========================================== # Phase 5: Security Review # =========================================== - name: security_review agent: ~/.takt/agents/expert/security-reviewer.md + report: 06-security-review.md allowed_tools: - Read - Glob @@ -531,22 +448,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: security_review (Security Expert Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/06-security-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Review the changes above from the security perspective. **Review Criteria:** @@ -556,7 +462,7 @@ steps: - Encryption appropriateness - OWASP Top 10 - **Report output:** Output to the `Report File` specified above. + **Report output:** Output to `.takt/reports/{report_dir}/06-security-review.md`. - If file does not exist: Create new file - If file exists: Append with `## Iteration {step_iteration}` section @@ -602,21 +508,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_security - ## Security Review Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the issues pointed out by the security expert. Security issues should be addressed with highest priority. @@ -647,6 +541,7 @@ steps: # =========================================== - name: qa_review agent: ~/.takt/agents/expert/qa-reviewer.md + report: 07-qa-review.md allowed_tools: - Read - Glob @@ -655,22 +550,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: qa_review (QA Expert Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/07-qa-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Review the changes above from the quality assurance perspective. **Review Criteria:** @@ -681,7 +565,7 @@ steps: - Logging and monitoring - Maintainability - **Report output:** Output to the `Report File` specified above. + **Report output:** Output to `.takt/reports/{report_dir}/07-qa-review.md`. - If file does not exist: Create new file - If file exists: Append with `## Iteration {step_iteration}` section @@ -726,21 +610,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_qa - ## QA Review Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the issues pointed out by the QA expert. Areas of concern: @@ -775,6 +647,9 @@ steps: # =========================================== - name: supervise agent: ~/.takt/agents/expert/supervisor.md + report: + - Validation: 08-supervisor-validation.md + - Summary: summary.md allowed_tools: - Read - Glob @@ -783,18 +658,6 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: supervise (Final Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Validation: .takt/reports/{report_dir}/08-supervisor-validation.md - - Summary: .takt/reports/{report_dir}/summary.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} @@ -808,7 +671,6 @@ steps: - Security Review: APPROVED - QA Review: APPROVED - ## Instructions Run tests, verify the build, and perform final approval. **Workflow Overall Review:** @@ -819,7 +681,9 @@ steps: **Review Reports:** Read all reports in Report Directory and check for any unaddressed improvement suggestions. - **Report output:** Output to the `Report Files` specified above. + **Report output:** Output to the report files specified below. + - Validation: `.takt/reports/{report_dir}/08-supervisor-validation.md` + - Summary: `.takt/reports/{report_dir}/summary.md` - If file does not exist: Create new file - If file exists: Append with `## Iteration {step_iteration}` section @@ -896,21 +760,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: fix_supervisor - ## Supervisor Feedback (This is the latest instruction - prioritize this) {previous_response} - ## Original User Request (Initial request - for reference) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **Important**: Fix the issues pointed out by the supervisor. The supervisor has identified issues from a big-picture perspective. diff --git a/resources/global/en/workflows/simple.yaml b/resources/global/en/workflows/simple.yaml index d64d2ca..d48aa18 100644 --- a/resources/global/en/workflows/simple.yaml +++ b/resources/global/en/workflows/simple.yaml @@ -1,19 +1,24 @@ # Simple TAKT Workflow -# Plan -> Coder -> Architect Review -> AI Review -> Supervisor Approval -# (Simplified version of default - removed improve, fix, ai_fix, security_review, security_fix) +# Plan -> Implement -> AI Review -> Architect Review -> Supervisor Approval # -# Template Variables: -# {iteration} - Workflow-wide turn count (total steps executed across all agents) -# {max_iterations} - Maximum iterations allowed for the workflow -# {step_iteration} - Per-step iteration count (how many times THIS step has been executed) -# {task} - Original user request -# {previous_response} - Output from the previous step -# {git_diff} - Current uncommitted changes (git diff) -# {user_inputs} - Accumulated user inputs during workflow -# {report_dir} - Report directory name (e.g., "20250126-143052-task-summary") +# Template Variables (auto-injected by engine): +# {iteration} - Workflow-wide turn count +# {max_iterations} - Maximum iterations allowed +# {step_iteration} - Per-step iteration count +# {task} - Original user request +# {previous_response} - Output from the previous step +# {git_diff} - Current uncommitted changes (git diff) +# {user_inputs} - Accumulated user inputs during workflow +# {report_dir} - Report directory name +# +# Auto-injected sections (do NOT include in instruction_template): +# ## Workflow Context - iteration, step_iteration, report info +# ## User Request - {task} +# ## Previous Response - {previous_response} +# ## Additional User Inputs - {user_inputs} name: simple -description: Simplified development workflow (plan -> implement -> review -> ai_review -> supervise) +description: Simplified development workflow (plan -> implement -> ai_review -> review -> supervise) max_iterations: 20 @@ -22,6 +27,7 @@ initial_step: plan steps: - name: plan agent: ~/.takt/agents/default/planner.md + report: 00-plan.md allowed_tools: - Read - Glob @@ -39,20 +45,9 @@ steps: next: ABORT pass_previous_response: true instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: plan (Task Analysis) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/00-plan.md - - ## User Request - {task} - ## Previous Response (when returned from implement) {previous_response} - ## Instructions Analyze the task and create an implementation plan. **Note:** If returned from implement step (Previous Response exists), @@ -91,6 +86,9 @@ steps: - name: implement agent: ~/.takt/agents/default/coder.md + report: + - Scope: 01-coder-scope.md + - Decisions: 02-coder-decisions.md allowed_tools: - Read - Glob @@ -103,26 +101,10 @@ steps: permission_mode: acceptEdits rules: - condition: Implementation complete - next: review + next: ai_review - condition: Cannot proceed, insufficient info next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: implement - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Scope: .takt/reports/{report_dir}/01-coder-scope.md - - Decisions: .takt/reports/{report_dir}/02-coder-decisions.md - - ## User Request - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions Follow the plan from the plan step and implement. Refer to the plan report (00-plan.md) and proceed with implementation. @@ -160,8 +142,67 @@ steps: - **Reason**: {Why this option was chosen} ``` + - name: ai_review + agent: ~/.takt/agents/default/ai-antipattern-reviewer.md + report: 03-ai-review.md + allowed_tools: + - Read + - Glob + - Grep + - Write + - WebSearch + - WebFetch + rules: + - condition: No AI-specific issues + next: review + - condition: AI-specific issues found + next: plan + instruction_template: | + ## Git Diff + ```diff + {git_diff} + ``` + + Review the code for AI-specific issues: + - Assumption validation + - Plausible but wrong patterns + - Context fit with existing codebase + - Scope creep detection + + **Report output:** Output to the `Report File` specified above. + - If file does not exist: Create new file + - If file exists: Append with `## Iteration {step_iteration}` section + + **Report format:** + ```markdown + # AI-Generated Code Review + + ## Result: APPROVE / REJECT + + ## Summary + {One sentence summarizing result} + + ## Verified Items + | Aspect | Result | Notes | + |--------|--------|-------| + | Assumption validity | ✅ | - | + | API/Library existence | ✅ | - | + | Context fit | ✅ | - | + | Scope | ✅ | - | + + ## Issues (if REJECT) + | # | Category | Location | Issue | + |---|----------|----------|-------| + | 1 | Hallucinated API | `src/file.ts:23` | Non-existent method | + ``` + + **Cognitive load reduction rules:** + - No issues -> Summary 1 line + check table only (10 lines or less) + - Issues found -> + Issues in table format (25 lines or less) + - name: review agent: ~/.takt/agents/default/architecture-reviewer.md + report: 04-architect-review.md allowed_tools: - Read - Glob @@ -171,27 +212,16 @@ steps: - WebFetch rules: - condition: No issues found - next: ai_review + next: supervise - condition: Structural fix required next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: review (Architecture Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/03-architect-review.md - - ## Original User Request (Initial request from workflow start) - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions - Focus on **architecture and design** review. Do NOT review AI-specific issues (that's the next step). + Focus on **architecture and design** review. Do NOT review AI-specific issues (that's already done). Review the changes and provide feedback. @@ -230,76 +260,11 @@ steps: - APPROVE + minor suggestions -> Summary + suggestions (15 lines or less) - REJECT -> Issues in table format (30 lines or less) - - name: ai_review - agent: ~/.takt/agents/default/ai-antipattern-reviewer.md - allowed_tools: - - Read - - Glob - - Grep - - Write - - WebSearch - - WebFetch - rules: - - condition: No AI-specific issues - next: supervise - - condition: AI-specific issues found - next: plan - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: ai_review (AI-Generated Code Review) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/04-ai-review.md - - ## Original User Request (Initial request from workflow start) - {task} - - ## Git Diff - ```diff - {git_diff} - ``` - - ## Instructions - Review the code for AI-specific issues: - - Assumption validation - - Plausible but wrong patterns - - Context fit with existing codebase - - Scope creep detection - - **Report output:** Output to the `Report File` specified above. - - If file does not exist: Create new file - - If file exists: Append with `## Iteration {step_iteration}` section - - **Report format:** - ```markdown - # AI-Generated Code Review - - ## Result: APPROVE / REJECT - - ## Summary - {One sentence summarizing result} - - ## Verified Items - | Aspect | Result | Notes | - |--------|--------|-------| - | Assumption validity | ✅ | - | - | API/Library existence | ✅ | - | - | Context fit | ✅ | - | - | Scope | ✅ | - | - - ## Issues (if REJECT) - | # | Category | Location | Issue | - |---|----------|----------|-------| - | 1 | Hallucinated API | `src/file.ts:23` | Non-existent method | - ``` - - **Cognitive load reduction rules:** - - No issues -> Summary 1 line + check table only (10 lines or less) - - Issues found -> + Issues in table format (25 lines or less) - - name: supervise agent: ~/.takt/agents/default/supervisor.md + report: + - Validation: 05-supervisor-validation.md + - Summary: summary.md allowed_tools: - Read - Glob @@ -314,24 +279,11 @@ steps: - condition: Requirements unmet, tests failing next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations} (workflow-wide) - - Step Iteration: {step_iteration} (times this step has run) - - Step: supervise (final verification) - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Validation: .takt/reports/{report_dir}/05-supervisor-validation.md - - Summary: .takt/reports/{report_dir}/summary.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions Run tests, verify the build, and perform final approval. **Workflow Overall Review:** @@ -388,8 +340,8 @@ steps: ## Review Results | Review | Result | |--------|--------| - | Architect | ✅ APPROVE | | AI Review | ✅ APPROVE | + | Architect | ✅ APPROVE | | Supervisor | ✅ APPROVE | ## Verification Commands diff --git a/resources/global/ja/agents/default/ai-antipattern-reviewer.md b/resources/global/ja/agents/default/ai-antipattern-reviewer.md index 4f278a0..c351c7d 100644 --- a/resources/global/ja/agents/default/ai-antipattern-reviewer.md +++ b/resources/global/ja/agents/default/ai-antipattern-reviewer.md @@ -149,7 +149,54 @@ AIは自信を持って間違える——もっともらしく見えるが動か 2. 各フォールバックに正当な理由があるか確認 3. 理由なしのフォールバックが1つでもあれば REJECT -### 8. 決定トレーサビリティレビュー +### 8. 未使用コードの検出 + +**AIは「将来の拡張性」「対称性」「念のため」で不要なコードを生成しがちである。現時点で呼ばれていないコードは削除する。** + +| 判定 | 基準 | +|------|------| +| **REJECT** | 現在どこからも呼ばれていないpublic関数・メソッド | +| **REJECT** | 「対称性のため」に作られたが使われていないsetter/getter | +| **REJECT** | 将来の拡張のために用意されたインターフェースやオプション | +| **REJECT** | exportされているが、grep で使用箇所が見つからない | +| OK | フレームワークが暗黙的に呼び出す(ライフサイクルフック等) | +| OK | 公開パッケージのAPIとして意図的に公開している | + +**検証アプローチ:** +1. 変更・削除されたコードを参照している箇所がないか grep で確認 +2. 公開モジュール(index ファイル等)のエクスポート一覧と実体が一致しているか確認 +3. 新規追加されたコードに対応する古いコードが残っていないか確認 + +### 9. 不要な後方互換コードの検出 + +**AIは「後方互換のために」不要なコードを残しがちである。これを見逃さない。** + +削除すべき後方互換コード: + +| パターン | 例 | 判定 | +|---------|-----|------| +| deprecated + 使用箇所なし | `@deprecated` アノテーション付きで誰も使っていない | **即削除** | +| 新APIと旧API両方存在 | 新関数があるのに旧関数も残っている | 旧を**削除** | +| 移行済みのラッパー | 互換のために作ったが移行完了済み | **削除** | +| コメントで「将来削除」 | `// TODO: remove after migration` が放置 | **今すぐ削除** | +| Proxy/アダプタの過剰使用 | 後方互換のためだけに複雑化 | **シンプルに置換** | + +残すべき後方互換コード: + +| パターン | 例 | 判定 | +|---------|-----|------| +| 外部公開API | npm パッケージのエクスポート | 慎重に検討 | +| 設定ファイル互換 | 旧形式の設定を読める | メジャーバージョンまで維持 | +| データ移行中 | DBスキーマ移行の途中 | 移行完了まで維持 | + +**判断基準:** +1. **使用箇所があるか?** → grep/検索で確認。なければ削除 +2. **外部に公開しているか?** → 内部のみなら即削除可能 +3. **移行は完了したか?** → 完了なら削除 + +**AIが「後方互換のため」と言ったら疑う。** 本当に必要か確認せよ。 + +### 10. 決定トレーサビリティレビュー **Coderの決定ログが妥当か検証する。** diff --git a/resources/global/ja/agents/default/architecture-reviewer.md b/resources/global/ja/agents/default/architecture-reviewer.md index 04b77a5..8d3d368 100644 --- a/resources/global/ja/agents/default/architecture-reviewer.md +++ b/resources/global/ja/agents/default/architecture-reviewer.md @@ -191,73 +191,6 @@ if (status === 'interrupted') { } ``` -**フォールバック値の乱用の判定基準:** - -フォールバック値(`??`, `||`, デフォルト引数)は「値が無いケース」を握りつぶす。本来エラーにすべき箇所を隠してしまう。 - -| 判定 | 基準 | -|------|------| -| **REJECT** | 値が無い状態がバグであるのにフォールバックで隠している | -| **REJECT** | `'unknown'`, `'default'`, `''`, `0` など意味のない値でごまかしている | -| **REJECT** | 全呼び出し元がフォールバックに頼り、本来の値を渡していない | -| OK | 外部入力(ユーザー入力、API応答)に対する防御的デフォルト | -| OK | オプショナルな設定項目に対する合理的な初期値 | - -```typescript -// ❌ REJECT - バグを隠すフォールバック -const userName = user.name ?? 'unknown'; // name が無いのはデータ不整合 -const stepName = step?.name ?? 'default'; // step が無いのは呼び出し元のバグ - -// ❌ REJECT - 全呼び出し元が省略しているオプション -function runStep(step: Step, options?: { maxRetries?: number }) { - const retries = options?.maxRetries ?? 3; // 全呼び出し元が options を渡していない -} - -// ✅ OK - ユーザー設定のオプショナルなデフォルト -const logLevel = config.logLevel ?? 'info'; // 設定ファイルに無ければ info -const language = userPreference.lang ?? 'en'; // 未設定なら英語 - -// ✅ OK - 外部APIの防御的デフォルト -const displayName = apiResponse.nickname ?? apiResponse.email; // ニックネーム未設定の場合 -``` - -**未使用コードの判定基準:** - -AIは「将来の拡張性」「対称性」「念のため」で不要なコードを生成しがちである。現時点で呼ばれていないコードは削除する。 - -| 判定 | 基準 | -|------|------| -| **REJECT** | 現在どこからも呼ばれていないpublic関数・メソッド | -| **REJECT** | 「対称性のため」に作られたが使われていないsetter/getter | -| **REJECT** | 将来の拡張のために用意されたインターフェースやオプション | -| **REJECT** | exportされているが、grep で使用箇所が見つからない | -| OK | フレームワークが暗黙的に呼び出す(ライフサイクルフック等) | -| OK | 公開パッケージのAPIとして意図的に公開している | - -```typescript -// ❌ REJECT - 「対称性のため」のsetter(getしか使っていない) -class WorkflowState { - private _status: Status; - getStatus(): Status { return this._status; } - setStatus(s: Status) { this._status = s; } // 誰も呼んでいない -} - -// ❌ REJECT - 「将来の拡張」のためのオプション -interface EngineOptions { - maxIterations: number; - enableParallel?: boolean; // 未実装。どこからも参照されていない - pluginHooks?: PluginHook[]; // 未実装。プラグイン機構は存在しない -} - -// ❌ REJECT - exportされているが使われていない -export function formatStepName(name: string): string { ... } // grep 結果: 0件 - -// ✅ OK - フレームワークが呼ぶ -class MyComponent extends React.Component { - componentDidMount() { ... } // Reactが呼ぶ -} -``` - **状態の直接変更の判定基準:** オブジェクトや配列を直接変更すると、変更の追跡が困難になり、予期しない副作用を生む。常にスプレッド演算子やイミュータブルな操作で新しいオブジェクトを返す。 @@ -379,35 +312,6 @@ function createUser(data: UserData) { } ``` -### 7. 不要な後方互換コードの検出 - -**AIは「後方互換のために」不要なコードを残しがちである。これを見逃さない。** - -削除すべき後方互換コード: - -| パターン | 例 | 判定 | -|---------|-----|------| -| deprecated + 使用箇所なし | `@deprecated` アノテーション付きで誰も使っていない | **即削除** | -| 新APIと旧API両方存在 | 新関数があるのに旧関数も残っている | 旧を**削除** | -| 移行済みのラッパー | 互換のために作ったが移行完了済み | **削除** | -| コメントで「将来削除」 | `// TODO: remove after migration` が放置 | **今すぐ削除** | -| Proxy/アダプタの過剰使用 | 後方互換のためだけに複雑化 | **シンプルに置換** | - -残すべき後方互換コード: - -| パターン | 例 | 判定 | -|---------|-----|------| -| 外部公開API | npm パッケージのエクスポート | 慎重に検討 | -| 設定ファイル互換 | 旧形式の設定を読める | メジャーバージョンまで維持 | -| データ移行中 | DBスキーマ移行の途中 | 移行完了まで維持 | - -**判断基準:** -1. **使用箇所があるか?** → grep/検索で確認。なければ削除 -2. **外部に公開しているか?** → 内部のみなら即削除可能 -3. **移行は完了したか?** → 完了なら削除 - -**AIが「後方互換のため」と言ったら疑う。** 本当に必要か確認せよ。 - ### 7. その場しのぎの検出 **「とりあえず動かす」ための妥協を見逃さない。** diff --git a/resources/global/ja/workflows/default.yaml b/resources/global/ja/workflows/default.yaml index 1b4a128..62a4292 100644 --- a/resources/global/ja/workflows/default.yaml +++ b/resources/global/ja/workflows/default.yaml @@ -1,7 +1,7 @@ # Default TAKT Workflow -# Plan -> Coder -> Architect Review -> AI Review -> Security Review -> Supervisor Approval +# Plan -> Implement -> AI Review -> Architect Review -> Security Review -> Supervisor Approval # -# Template Variables: +# Template Variables (auto-injected by buildInstruction): # {iteration} - Workflow-wide turn count (total steps executed across all agents) # {max_iterations} - Maximum iterations allowed for the workflow # {step_iteration} - Per-step iteration count (how many times THIS step has been executed) @@ -14,13 +14,14 @@ name: default description: Standard development workflow with planning and specialized reviews -max_iterations: 20 +max_iterations: 30 initial_step: plan steps: - name: plan agent: ~/.takt/agents/default/planner.md + report: 00-plan.md allowed_tools: - Read - Glob @@ -44,20 +45,9 @@ steps: - {質問2} pass_previous_response: true instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: plan (タスク分析) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/00-plan.md - - ## User Request - {task} - ## Previous Response (implementからの差し戻し時) {previous_response} - ## Instructions タスクを分析し、実装方針を立ててください。 **注意:** Previous Responseがある場合は差し戻しのため、 @@ -68,7 +58,7 @@ steps: 2. 影響範囲を特定する 3. 実装アプローチを決める - **レポート出力:** 上記の `Report File` に出力してください。 + **レポート出力:** Report File に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -96,6 +86,9 @@ steps: - name: implement agent: ~/.takt/agents/default/coder.md + report: + - Scope: 01-coder-scope.md + - Decisions: 02-coder-decisions.md allowed_tools: - Read - Glob @@ -108,26 +101,10 @@ steps: permission_mode: acceptEdits rules: - condition: 実装完了 - next: review + next: ai_review - condition: 判断できない、情報不足 next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: implement - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Scope: .takt/reports/{report_dir}/01-coder-scope.md - - Decisions: .takt/reports/{report_dir}/02-coder-decisions.md - - ## User Request - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions planステップで立てた計画に従って実装してください。 計画レポート(00-plan.md)を参照し、実装を進めてください。 @@ -136,7 +113,7 @@ steps: - 既存コードを変更した場合は該当するテストを更新 - テストファイルの配置: プロジェクトの規約に従う(例: `__tests__/`, `*.test.ts`) - **レポート出力:** 上記の `Report Files` に出力してください。 + **レポート出力:** Report Files に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -170,8 +147,96 @@ steps: - **理由**: {選んだ理由} ``` + - name: ai_review + agent: ~/.takt/agents/default/ai-antipattern-reviewer.md + report: 03-ai-review.md + allowed_tools: + - Read + - Glob + - Grep + - Write + - WebSearch + - WebFetch + rules: + - condition: AI特有の問題なし + next: review + - condition: AI特有の問題あり + next: ai_fix + instruction_template: | + ## Git Diff + ```diff + {git_diff} + ``` + + AI特有の問題についてコードをレビューしてください: + - 仮定の検証 + - もっともらしいが間違っているパターン + - 既存コードベースとの適合性 + - スコープクリープの検出 + + **レポート出力:** Report File に出力してください。 + - ファイルが存在しない場合: 新規作成 + - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 + + **レポートフォーマット:** + ```markdown + # AI生成コードレビュー + + ## 結果: APPROVE / REJECT + + ## サマリー + {1文で結果を要約} + + ## 検証した項目 + | 観点 | 結果 | 備考 | + |------|------|------| + | 仮定の妥当性 | ✅ | - | + | API/ライブラリの実在 | ✅ | - | + | コンテキスト適合 | ✅ | - | + | スコープ | ✅ | - | + + ## 問題点(REJECTの場合) + | # | カテゴリ | 場所 | 問題 | + |---|---------|------|------| + | 1 | 幻覚API | `src/file.ts:23` | 存在しないメソッド | + ``` + + **認知負荷軽減ルール:** + - 問題なし → サマリー1文 + チェック表のみ(10行以内) + - 問題あり → + 問題を表形式で(25行以内) + + - name: ai_fix + agent: ~/.takt/agents/default/coder.md + allowed_tools: + - Read + - Glob + - Grep + - Edit + - Write + - Bash + - WebSearch + - WebFetch + permission_mode: acceptEdits + rules: + - condition: AI問題の修正完了 + next: review + - condition: 判断できない、情報不足 + next: plan + instruction_template: | + ## AI Review Feedback (これが最新の指示です - 優先して対応してください) + {previous_response} + + **重要**: AI Reviewerのフィードバックに対応してください。 + 以下に集中してください: + - 間違った仮定の修正 + - もっともらしいが間違っている実装の修正 + - 既存コードベースのパターンとの整合 + - スコープクリープの除去 + pass_previous_response: true + - name: review agent: ~/.takt/agents/default/architecture-reviewer.md + report: 04-architect-review.md allowed_tools: - Read - Glob @@ -181,28 +246,17 @@ steps: - WebFetch rules: - condition: 問題なし - next: ai_review + next: security_review - condition: 改善すべき点がある(軽微) next: improve - condition: 構造的な修正が必要 next: fix instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: review (アーキテクチャレビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/03-architect-review.md - - ## Original User Request (ワークフロー開始時の元の要求) - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions **アーキテクチャと設計**のレビューに集中してください。AI特有の問題はレビューしないでください(次のステップで行います)。 変更をレビューしてフィードバックを提供してください。 @@ -215,7 +269,7 @@ steps: - デッドコード - 呼び出しチェーン検証 - **レポート出力:** 上記の `Report File` に出力してください。 + **レポート出力:** Report File に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -268,21 +322,9 @@ steps: - condition: 判断できない、情報不足 next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: improve - ## Architect Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: Architectの改善提案に対応してください。 これらは軽微な改善であり、設計上の大きな問題ではありません。 @@ -293,75 +335,7 @@ steps: - コードの整理 pass_previous_response: true - - name: ai_review - agent: ~/.takt/agents/default/ai-antipattern-reviewer.md - allowed_tools: - - Read - - Glob - - Grep - - Write - - WebSearch - - WebFetch - rules: - - condition: AI特有の問題なし - next: security_review - - condition: AI特有の問題あり - next: ai_fix - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: ai_review (AI生成コードレビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/04-ai-review.md - - ## Original User Request (ワークフロー開始時の元の要求) - {task} - - ## Git Diff - ```diff - {git_diff} - ``` - - ## Instructions - AI特有の問題についてコードをレビューしてください: - - 仮定の検証 - - もっともらしいが間違っているパターン - - 既存コードベースとの適合性 - - スコープクリープの検出 - - **レポート出力:** 上記の `Report File` に出力してください。 - - ファイルが存在しない場合: 新規作成 - - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 - - **レポートフォーマット:** - ```markdown - # AI生成コードレビュー - - ## 結果: APPROVE / REJECT - - ## サマリー - {1文で結果を要約} - - ## 検証した項目 - | 観点 | 結果 | 備考 | - |------|------|------| - | 仮定の妥当性 | ✅ | - | - | API/ライブラリの実在 | ✅ | - | - | コンテキスト適合 | ✅ | - | - | スコープ | ✅ | - | - - ## 問題点(REJECTの場合) - | # | カテゴリ | 場所 | 問題 | - |---|---------|------|------| - | 1 | 幻覚API | `src/file.ts:23` | 存在しないメソッド | - ``` - - **認知負荷軽減ルール:** - - 問題なし → サマリー1文 + チェック表のみ(10行以内) - - 問題あり → + 問題を表形式で(25行以内) - - - name: ai_fix + - name: fix agent: ~/.takt/agents/default/coder.md allowed_tools: - Read @@ -374,36 +348,21 @@ steps: - WebFetch permission_mode: acceptEdits rules: - - condition: AI問題の修正完了 + - condition: Architectの指摘を修正完了 next: review - condition: 判断できない、情報不足 next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: ai_fix - - ## AI Review Feedback (これが最新の指示です - 優先して対応してください) + ## Architect Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions - **重要**: AI Reviewerのフィードバックに対応してください。 - 以下に集中してください: - - 間違った仮定の修正 - - もっともらしいが間違っている実装の修正 - - 既存コードベースのパターンとの整合 - - スコープクリープの除去 + **重要**: Architectのフィードバックに対応してください。 + セッションの会話履歴を確認し、Architectの指摘事項を修正してください。 pass_previous_response: true - name: security_review agent: ~/.takt/agents/default/security-reviewer.md + report: 05-security-review.md allowed_tools: - Read - Glob @@ -417,29 +376,18 @@ steps: - condition: 脆弱性があり修正が必要 next: security_fix instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: security_review - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/05-security-review.md - - ## Original User Request (ワークフロー開始時の元の要求) - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions 変更に対してセキュリティレビューを行ってください。以下の脆弱性を確認してください: - インジェクション攻撃(SQL, コマンド, XSS) - 認証・認可の問題 - データ露出リスク - 暗号化の弱点 - **レポート出力:** 上記の `Report File` に出力してください。 + **レポート出力:** Report File に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -491,65 +439,18 @@ steps: - condition: 判断できない、情報不足 next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: security_fix - ## Security Review Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: セキュリティレビューで指摘された脆弱性を修正してください。 セキュリティの問題は最優先で対応が必要です。 pass_previous_response: true - - name: fix - agent: ~/.takt/agents/default/coder.md - allowed_tools: - - Read - - Glob - - Grep - - Edit - - Write - - Bash - - WebSearch - - WebFetch - permission_mode: acceptEdits - rules: - - condition: Architectの指摘を修正完了 - next: review - - condition: 判断できない、情報不足 - next: plan - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix - - ## Architect Feedback (これが最新の指示です - 優先して対応してください) - {previous_response} - - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions - **重要**: Architectのフィードバックに対応してください。 - 「Original User Request」は参考情報であり、最新の指示ではありません。 - セッションの会話履歴を確認し、Architectの指摘事項を修正してください。 - pass_previous_response: true - - name: supervise agent: ~/.takt/agents/default/supervisor.md + report: + - Validation: 06-supervisor-validation.md + - Summary: summary.md allowed_tools: - Read - Glob @@ -564,24 +465,11 @@ steps: - condition: 要求未達成、テスト失敗、ビルドエラー next: plan instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: supervise (final verification) - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Validation: .takt/reports/{report_dir}/06-supervisor-validation.md - - Summary: .takt/reports/{report_dir}/summary.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions テスト実行、ビルド確認、最終承認を行ってください。 **ワークフロー全体の確認:** @@ -592,7 +480,7 @@ steps: **レポートの確認:** Report Directory内の全レポートを読み、 未対応の改善提案がないか確認してください。 - **レポート出力:** 上記の `Report Files` に出力してください。 + **レポート出力:** Report Files に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 diff --git a/resources/global/ja/workflows/expert-cqrs.yaml b/resources/global/ja/workflows/expert-cqrs.yaml index c69900b..299761f 100644 --- a/resources/global/ja/workflows/expert-cqrs.yaml +++ b/resources/global/ja/workflows/expert-cqrs.yaml @@ -2,9 +2,9 @@ # CQRS+ES、フロントエンド、セキュリティ、QAの専門家によるレビューワークフロー # # フロー: -# plan -> implement -> architect_review -> cqrs_es_review -> frontend_review -> ai_review -> security_review -> qa_review -> supervise -> COMPLETE -# ↓ ↓ ↓ ↓ ↓ ↓ ↓ -# fix_architect fix_cqrs_es fix_frontend ai_fix fix_security fix_qa fix_supervisor +# plan -> implement -> ai_review -> cqrs_es_review -> frontend_review -> security_review -> qa_review -> supervise -> COMPLETE +# ↓ ↓ ↓ ↓ ↓ ↓ +# ai_fix fix_cqrs_es fix_frontend fix_security fix_qa fix_supervisor # # 修正時の戻り先はCoderが判断: # - fix_security: MINOR→security_review, MAJOR→cqrs_es_review @@ -23,7 +23,7 @@ name: expert-cqrs description: CQRS+ES・フロントエンド・セキュリティ・QA専門家レビュー -max_iterations: 20 +max_iterations: 30 initial_step: plan @@ -33,6 +33,7 @@ steps: # =========================================== - name: plan agent: ~/.takt/agents/default/planner.md + report: 00-plan.md allowed_tools: - Read - Glob @@ -42,20 +43,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: plan (タスク分析) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/00-plan.md - - ## User Request - {task} - ## Previous Response (implementからの差し戻し時) {previous_response} - ## Instructions タスクを分析し、実装方針を立ててください。 **注意:** Previous Responseがある場合は差し戻しのため、 @@ -66,7 +56,7 @@ steps: 2. 影響範囲を特定する 3. 実装アプローチを決める - **レポート出力:** 上記の `Report File` に出力してください。 + **レポート出力:** .takt/reports/{report_dir}/00-plan.md に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -103,6 +93,9 @@ steps: # =========================================== - name: implement agent: ~/.takt/agents/default/coder.md + report: + - Scope: 01-coder-scope.md + - Decisions: 02-coder-decisions.md allowed_tools: - Read - Glob @@ -113,26 +106,12 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: implement - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Scope: .takt/reports/{report_dir}/01-coder-scope.md - - Decisions: .takt/reports/{report_dir}/02-coder-decisions.md - - ## User Request - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions planステップで立てた計画に従って実装してください。 計画レポート(00-plan.md)を参照し、実装を進めてください。 - **レポート出力:** 上記の `Report Files` に出力してください。 + **レポート出力:** .takt/reports/{report_dir}/ に出力してください。 + - Scope: .takt/reports/{report_dir}/01-coder-scope.md + - Decisions: .takt/reports/{report_dir}/02-coder-decisions.md - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -167,15 +146,16 @@ steps: ``` rules: - condition: 実装が完了した - next: architect_review + next: ai_review - condition: 実装を進行できない next: plan # =========================================== - # Phase 2: Architecture Review + # Phase 2: AI Review # =========================================== - - name: architect_review - agent: ~/.takt/agents/default/architecture-reviewer.md + - name: ai_review + agent: ~/.takt/agents/default/ai-antipattern-reviewer.md + report: 03-ai-review.md allowed_tools: - Read - Glob @@ -184,75 +164,54 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: architect_review (アーキテクチャレビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/03-architect-review.md - - ## Original User Request (ワークフロー開始時の元の要求) - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions - **アーキテクチャと設計**のレビューに集中してください。 + AI特有の問題についてコードをレビューしてください: + - 仮定の検証 + - もっともらしいが間違っているパターン + - 既存コードベースとの適合性 + - スコープクリープの検出 - **レビュー観点:** - - 構造・設計の妥当性 - - コード品質 - - 変更スコープの適切性 - - テストカバレッジ - - デッドコード - - 呼び出しチェーン検証 - - **レポート出力:** 上記の `Report File` に出力してください。 + **レポート出力:** .takt/reports/{report_dir}/03-ai-review.md に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 **レポートフォーマット:** ```markdown - # アーキテクチャレビュー + # AI生成コードレビュー - ## 結果: APPROVE / IMPROVE / REJECT + ## 結果: APPROVE / REJECT ## サマリー - {1-2文で結果を要約} + {1文で結果を要約} - ## 確認した観点 - - [x] 構造・設計 - - [x] コード品質 - - [x] 変更スコープ - - [x] テストカバレッジ - - [x] デッドコード - - [x] 呼び出しチェーン検証 + ## 検証した項目 + | 観点 | 結果 | 備考 | + |------|------|------| + | 仮定の妥当性 | ✅ | - | + | API/ライブラリの実在 | ✅ | - | + | コンテキスト適合 | ✅ | - | + | スコープ | ✅ | - | ## 問題点(REJECTの場合) - | # | 場所 | 問題 | 修正案 | - |---|------|------|--------| - | 1 | `src/file.ts:42` | 問題の説明 | 修正方法 | - - ## 改善提案(任意・ブロッキングではない) - - {将来的な改善提案} + | # | カテゴリ | 場所 | 問題 | + |---|---------|------|------| + | 1 | 幻覚API | `src/file.ts:23` | 存在しないメソッド | ``` **認知負荷軽減ルール:** - - APPROVE + 問題なし → サマリーのみ(5行以内) - - APPROVE + 軽微な提案 → サマリー + 改善提案(15行以内) - - REJECT → 問題点を表形式で(30行以内) + - 問題なし → サマリー1文 + チェック表のみ(10行以内) + - 問題あり → + 問題を表形式で(25行以内) rules: - - condition: アーキテクチャと設計に問題がない + - condition: AI特有の問題が見つからない next: cqrs_es_review - - condition: 軽微な改善が必要だが構造的な問題はない - next: fix_architect - - condition: 構造的な問題があり修正が必要 - next: fix_architect + - condition: AI特有の問題が検出された + next: ai_fix - - name: fix_architect + - name: ai_fix agent: ~/.takt/agents/default/coder.md allowed_tools: - Read @@ -263,30 +222,20 @@ steps: - Bash - WebSearch - WebFetch - permission_mode: acceptEdits instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_architect - - ## Architect Feedback (これが最新の指示です - 優先して対応してください) + ## AI Review Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions - **重要**: Architectのフィードバックに対応してください。 - 「Original User Request」は参考情報であり、最新の指示ではありません。 - セッションの会話履歴を確認し、Architectの指摘事項を修正してください。 + **重要**: AI Reviewerのフィードバックに対応してください。 + 以下に集中してください: + - 間違った仮定の修正 + - もっともらしいが間違っている実装の修正 + - 既存コードベースのパターンとの整合 + - スコープクリープの除去 pass_previous_response: true rules: - - condition: Architectの指摘に対する修正が完了した - next: architect_review + - condition: AI Reviewerの指摘に対する修正が完了した + next: ai_review - condition: 修正を進行できない next: plan @@ -295,6 +244,7 @@ steps: # =========================================== - name: cqrs_es_review agent: ~/.takt/agents/expert-cqrs/cqrs-es-reviewer.md + report: 04-cqrs-es-review.md allowed_tools: - Read - Glob @@ -303,22 +253,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: cqrs_es_review (CQRS+ES専門レビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/04-cqrs-es-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions CQRS(コマンドクエリ責務分離)とEvent Sourcing(イベントソーシング)の観点から 上記の変更をレビューしてください。 @@ -332,7 +271,7 @@ steps: **注意**: このプロジェクトがCQRS+ESパターンを使用していない場合は、 一般的なドメイン設計の観点からレビューしてください。 - **レポート出力:** 上記の `Report File` に出力してください。 + **レポート出力:** .takt/reports/{report_dir}/04-cqrs-es-review.md に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -377,21 +316,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_cqrs_es - ## CQRS+ES Review Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: CQRS+ES専門家からの指摘を修正してください。 指摘されたポイント: @@ -408,10 +335,11 @@ steps: next: plan # =========================================== - # Phase 3: Frontend Review + # Phase 4: Frontend Review # =========================================== - name: frontend_review agent: ~/.takt/agents/expert/frontend-reviewer.md + report: 05-frontend-review.md allowed_tools: - Read - Glob @@ -420,22 +348,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: frontend_review (フロントエンド専門レビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/05-frontend-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions フロントエンド開発の観点から上記の変更をレビューしてください。 **レビュー観点:** @@ -449,7 +366,7 @@ steps: **注意**: このプロジェクトがフロントエンドを含まない場合は、 問題なしとして次に進んでください。 - **レポート出力:** 上記の `Report File` に出力してください。 + **レポート出力:** .takt/reports/{report_dir}/05-frontend-review.md に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -478,7 +395,7 @@ steps: ``` rules: - condition: フロントエンド設計に問題がない - next: ai_review + next: security_review - condition: フロントエンド設計に問題がある next: fix_frontend @@ -494,21 +411,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_frontend - ## Frontend Review Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: フロントエンド専門家からの指摘を修正してください。 指摘されたポイント: @@ -524,122 +429,12 @@ steps: - condition: 修正を進行できない next: plan - # =========================================== - # Phase 4: AI Review - # =========================================== - - name: ai_review - agent: ~/.takt/agents/default/ai-antipattern-reviewer.md - allowed_tools: - - Read - - Glob - - Grep - - Write - - WebSearch - - WebFetch - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: ai_review (AI生成コードレビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/06-ai-review.md - - ## Original User Request (ワークフロー開始時の元の要求) - {task} - - ## Git Diff - ```diff - {git_diff} - ``` - - ## Instructions - AI特有の問題についてコードをレビューしてください: - - 仮定の検証 - - もっともらしいが間違っているパターン - - 既存コードベースとの適合性 - - スコープクリープの検出 - - **レポート出力:** 上記の `Report File` に出力してください。 - - ファイルが存在しない場合: 新規作成 - - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 - - **レポートフォーマット:** - ```markdown - # AI生成コードレビュー - - ## 結果: APPROVE / REJECT - - ## サマリー - {1文で結果を要約} - - ## 検証した項目 - | 観点 | 結果 | 備考 | - |------|------|------| - | 仮定の妥当性 | ✅ | - | - | API/ライブラリの実在 | ✅ | - | - | コンテキスト適合 | ✅ | - | - | スコープ | ✅ | - | - - ## 問題点(REJECTの場合) - | # | カテゴリ | 場所 | 問題 | - |---|---------|------|------| - | 1 | 幻覚API | `src/file.ts:23` | 存在しないメソッド | - ``` - - **認知負荷軽減ルール:** - - 問題なし → サマリー1文 + チェック表のみ(10行以内) - - 問題あり → + 問題を表形式で(25行以内) - rules: - - condition: AI特有の問題が見つからない - next: security_review - - condition: AI特有の問題が検出された - next: ai_fix - - - name: ai_fix - agent: ~/.takt/agents/default/coder.md - allowed_tools: - - Read - - Glob - - Grep - - Edit - - Write - - Bash - - WebSearch - - WebFetch - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: ai_fix - - ## AI Review Feedback (これが最新の指示です - 優先して対応してください) - {previous_response} - - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions - **重要**: AI Reviewerのフィードバックに対応してください。 - 以下に集中してください: - - 間違った仮定の修正 - - もっともらしいが間違っている実装の修正 - - 既存コードベースのパターンとの整合 - - スコープクリープの除去 - pass_previous_response: true - rules: - - condition: AI Reviewerの指摘に対する修正が完了した - next: ai_review - - condition: 修正を進行できない - next: plan - # =========================================== # Phase 5: Security Review # =========================================== - name: security_review agent: ~/.takt/agents/expert/security-reviewer.md + report: 06-security-review.md allowed_tools: - Read - Glob @@ -648,22 +443,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: security_review (セキュリティ専門レビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/07-security-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions セキュリティの観点から上記の変更をレビューしてください。 **レビュー観点:** @@ -673,7 +457,7 @@ steps: - 暗号化の適切性 - OWASP Top 10 - **レポート出力:** 上記の `Report File` に出力してください。 + **レポート出力:** .takt/reports/{report_dir}/06-security-review.md に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -719,21 +503,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_security - ## Security Review Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: セキュリティ専門家からの指摘を修正してください。 セキュリティ問題は最優先で対応してください。 @@ -764,6 +536,7 @@ steps: # =========================================== - name: qa_review agent: ~/.takt/agents/expert/qa-reviewer.md + report: 07-qa-review.md allowed_tools: - Read - Glob @@ -772,22 +545,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: qa_review (QA専門レビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/08-qa-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions 品質保証の観点から上記の変更をレビューしてください。 **レビュー観点:** @@ -798,7 +560,7 @@ steps: - ログとモニタリング - 保守性 - **レポート出力:** 上記の `Report File` に出力してください。 + **レポート出力:** .takt/reports/{report_dir}/07-qa-review.md に出力してください。 - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -843,21 +605,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_qa - ## QA Review Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: QA専門家からの指摘を修正してください。 指摘されたポイント: @@ -892,6 +642,9 @@ steps: # =========================================== - name: supervise agent: ~/.takt/agents/expert/supervisor.md + report: + - Validation: 08-supervisor-validation.md + - Summary: summary.md allowed_tools: - Read - Glob @@ -900,18 +653,6 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: supervise (最終確認) - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Validation: .takt/reports/{report_dir}/09-supervisor-validation.md - - Summary: .takt/reports/{report_dir}/summary.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} @@ -919,14 +660,12 @@ steps: ## Previous Reviews Summary このステップに到達したということは、以下のレビューがすべてAPPROVEされています: - - Architecture Review: APPROVED + - AI Review: APPROVED - CQRS+ES Review: APPROVED - Frontend Review: APPROVED - - AI Review: APPROVED - Security Review: APPROVED - QA Review: APPROVED - ## Instructions テスト実行、ビルド確認、最終承認を行ってください。 **ワークフロー全体の確認:** @@ -934,10 +673,12 @@ steps: 2. 各レビューステップの指摘が対応されているか 3. 元のタスク目的が達成されているか - **レポートの確認:** Report Directory内の全レポートを読み、 + **レポートの確認:** .takt/reports/{report_dir}/ 内の全レポートを読み、 未対応の改善提案がないか確認してください。 - **レポート出力:** 上記の `Report Files` に出力してください。 + **レポート出力:** + - Validation: .takt/reports/{report_dir}/08-supervisor-validation.md + - Summary: .takt/reports/{report_dir}/summary.md - ファイルが存在しない場合: 新規作成 - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 @@ -983,10 +724,9 @@ steps: ## レビュー結果 | レビュー | 結果 | |---------|------| - | Architecture | ✅ APPROVE | + | AI Review | ✅ APPROVE | | CQRS+ES | ✅ APPROVE | | Frontend | ✅ APPROVE | - | AI Review | ✅ APPROVE | | Security | ✅ APPROVE | | QA | ✅ APPROVE | | Supervisor | ✅ APPROVE | @@ -1015,21 +755,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_supervisor - ## Supervisor Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: 監督者からの指摘を修正してください。 監督者は全体を俯瞰した視点から問題を指摘しています。 diff --git a/resources/global/ja/workflows/expert.yaml b/resources/global/ja/workflows/expert.yaml index a96f296..b104d75 100644 --- a/resources/global/ja/workflows/expert.yaml +++ b/resources/global/ja/workflows/expert.yaml @@ -2,9 +2,9 @@ # アーキテクチャ、フロントエンド、セキュリティ、QAの専門家によるレビューワークフロー # # フロー: -# plan -> implement -> architect_review -> frontend_review -> ai_review -> security_review -> qa_review -> supervise -> COMPLETE -# ↓ ↓ ↓ ↓ ↓ ↓ -# fix_architect fix_frontend ai_fix fix_security fix_qa fix_supervisor +# plan -> implement -> ai_review -> architect_review -> frontend_review -> security_review -> qa_review -> supervise -> COMPLETE +# ↓ ↓ ↓ ↓ ↓ ↓ +# ai_fix fix_architect fix_frontend fix_security fix_qa fix_supervisor # # 修正時の戻り先はCoderが判断: # - fix_security: MINOR→security_review, MAJOR→architect_review @@ -23,7 +23,7 @@ name: expert description: アーキテクチャ・フロントエンド・セキュリティ・QA専門家レビュー -max_iterations: 20 +max_iterations: 30 initial_step: plan @@ -33,6 +33,7 @@ steps: # =========================================== - name: plan agent: ~/.takt/agents/default/planner.md + report: 00-plan.md allowed_tools: - Read - Glob @@ -42,20 +43,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: plan (タスク分析) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/00-plan.md - - ## User Request - {task} - ## Previous Response (implementからの差し戻し時) {previous_response} - ## Instructions タスクを分析し、実装方針を立ててください。 **注意:** Previous Responseがある場合は差し戻しのため、 @@ -103,6 +93,9 @@ steps: # =========================================== - name: implement agent: ~/.takt/agents/default/coder.md + report: + - Scope: 01-coder-scope.md + - Decisions: 02-coder-decisions.md allowed_tools: - Read - Glob @@ -113,22 +106,6 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: implement - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Scope: .takt/reports/{report_dir}/01-coder-scope.md - - Decisions: .takt/reports/{report_dir}/02-coder-decisions.md - - ## User Request - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions planステップで立てた計画に従って実装してください。 計画レポート(00-plan.md)を参照し、実装を進めてください。 @@ -167,15 +144,105 @@ steps: ``` rules: - condition: 実装が完了した - next: architect_review + next: ai_review - condition: 実装を進行できない next: plan # =========================================== - # Phase 2: Architecture Review + # Phase 2: AI Review # =========================================== - - name: architect_review - agent: ~/.takt/agents/default/architecture-reviewer.md + - name: ai_review + agent: ~/.takt/agents/default/ai-antipattern-reviewer.md + report: 03-ai-review.md + allowed_tools: + - Read + - Glob + - Grep + - Write + - WebSearch + - WebFetch + instruction_template: | + ## Git Diff + ```diff + {git_diff} + ``` + + AI特有の問題についてコードをレビューしてください: + - 仮定の検証 + - もっともらしいが間違っているパターン + - 既存コードベースとの適合性 + - スコープクリープの検出 + + **レポート出力:** 上記の `Report File` に出力してください。 + - ファイルが存在しない場合: 新規作成 + - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 + + **レポートフォーマット:** + ```markdown + # AI生成コードレビュー + + ## 結果: APPROVE / REJECT + + ## サマリー + {1文で結果を要約} + + ## 検証した項目 + | 観点 | 結果 | 備考 | + |------|------|------| + | 仮定の妥当性 | ✅ | - | + | API/ライブラリの実在 | ✅ | - | + | コンテキスト適合 | ✅ | - | + | スコープ | ✅ | - | + + ## 問題点(REJECTの場合) + | # | カテゴリ | 場所 | 問題 | + |---|---------|------|------| + | 1 | 幻覚API | `src/file.ts:23` | 存在しないメソッド | + ``` + + **認知負荷軽減ルール:** + - 問題なし → サマリー1文 + チェック表のみ(10行以内) + - 問題あり → + 問題を表形式で(25行以内) + rules: + - condition: AI特有の問題が見つからない + next: architect_review + - condition: AI特有の問題が検出された + next: ai_fix + + - name: ai_fix + agent: ~/.takt/agents/default/coder.md + allowed_tools: + - Read + - Glob + - Grep + - Edit + - Write + - Bash + - WebSearch + - WebFetch + instruction_template: | + ## AI Review Feedback (これが最新の指示です - 優先して対応してください) + {previous_response} + + **重要**: AI Reviewerのフィードバックに対応してください。 + 以下に集中してください: + - 間違った仮定の修正 + - もっともらしいが間違っている実装の修正 + - 既存コードベースのパターンとの整合 + - スコープクリープの除去 + pass_previous_response: true + rules: + - condition: AI Reviewerの指摘に対する修正が完了した + next: ai_review + - condition: 修正を進行できない + next: plan + + # =========================================== + # Phase 3: Architecture Review + # =========================================== + - name: architect_review + agent: ~/.takt/agents/default/architecture-reviewer.md + report: 04-architect-review.md allowed_tools: - Read - Glob @@ -184,22 +251,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: architect_review (アーキテクチャレビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/03-architect-review.md - - ## Original User Request (ワークフロー開始時の元の要求) - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions **アーキテクチャと設計**のレビューに集中してください。 **レビュー観点:** @@ -265,21 +321,9 @@ steps: - WebFetch permission_mode: acceptEdits instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_architect - ## Architect Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: Architectのフィードバックに対応してください。 「Original User Request」は参考情報であり、最新の指示ではありません。 セッションの会話履歴を確認し、Architectの指摘事項を修正してください。 @@ -291,10 +335,11 @@ steps: next: plan # =========================================== - # Phase 3: Frontend Review + # Phase 4: Frontend Review # =========================================== - name: frontend_review agent: ~/.takt/agents/expert/frontend-reviewer.md + report: 05-frontend-review.md allowed_tools: - Read - Glob @@ -303,22 +348,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: frontend_review (フロントエンド専門レビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/04-frontend-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions フロントエンド開発の観点から上記の変更をレビューしてください。 **レビュー観点:** @@ -361,7 +395,7 @@ steps: ``` rules: - condition: フロントエンド設計に問題がない - next: ai_review + next: security_review - condition: フロントエンド設計に問題がある next: fix_frontend @@ -377,21 +411,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_frontend - ## Frontend Review Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: フロントエンド専門家からの指摘を修正してください。 指摘されたポイント: @@ -407,122 +429,12 @@ steps: - condition: 修正を進行できない next: plan - # =========================================== - # Phase 4: AI Review - # =========================================== - - name: ai_review - agent: ~/.takt/agents/default/ai-antipattern-reviewer.md - allowed_tools: - - Read - - Glob - - Grep - - Write - - WebSearch - - WebFetch - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: ai_review (AI生成コードレビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/05-ai-review.md - - ## Original User Request (ワークフロー開始時の元の要求) - {task} - - ## Git Diff - ```diff - {git_diff} - ``` - - ## Instructions - AI特有の問題についてコードをレビューしてください: - - 仮定の検証 - - もっともらしいが間違っているパターン - - 既存コードベースとの適合性 - - スコープクリープの検出 - - **レポート出力:** 上記の `Report File` に出力してください。 - - ファイルが存在しない場合: 新規作成 - - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 - - **レポートフォーマット:** - ```markdown - # AI生成コードレビュー - - ## 結果: APPROVE / REJECT - - ## サマリー - {1文で結果を要約} - - ## 検証した項目 - | 観点 | 結果 | 備考 | - |------|------|------| - | 仮定の妥当性 | ✅ | - | - | API/ライブラリの実在 | ✅ | - | - | コンテキスト適合 | ✅ | - | - | スコープ | ✅ | - | - - ## 問題点(REJECTの場合) - | # | カテゴリ | 場所 | 問題 | - |---|---------|------|------| - | 1 | 幻覚API | `src/file.ts:23` | 存在しないメソッド | - ``` - - **認知負荷軽減ルール:** - - 問題なし → サマリー1文 + チェック表のみ(10行以内) - - 問題あり → + 問題を表形式で(25行以内) - rules: - - condition: AI特有の問題が見つからない - next: security_review - - condition: AI特有の問題が検出された - next: ai_fix - - - name: ai_fix - agent: ~/.takt/agents/default/coder.md - allowed_tools: - - Read - - Glob - - Grep - - Edit - - Write - - Bash - - WebSearch - - WebFetch - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: ai_fix - - ## AI Review Feedback (これが最新の指示です - 優先して対応してください) - {previous_response} - - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions - **重要**: AI Reviewerのフィードバックに対応してください。 - 以下に集中してください: - - 間違った仮定の修正 - - もっともらしいが間違っている実装の修正 - - 既存コードベースのパターンとの整合 - - スコープクリープの除去 - pass_previous_response: true - rules: - - condition: AI Reviewerの指摘に対する修正が完了した - next: ai_review - - condition: 修正を進行できない - next: plan - # =========================================== # Phase 5: Security Review # =========================================== - name: security_review agent: ~/.takt/agents/expert/security-reviewer.md + report: 06-security-review.md allowed_tools: - Read - Glob @@ -531,22 +443,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: security_review (セキュリティ専門レビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/06-security-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions セキュリティの観点から上記の変更をレビューしてください。 **レビュー観点:** @@ -602,21 +503,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_security - ## Security Review Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: セキュリティ専門家からの指摘を修正してください。 セキュリティ問題は最優先で対応してください。 @@ -647,6 +536,7 @@ steps: # =========================================== - name: qa_review agent: ~/.takt/agents/expert/qa-reviewer.md + report: 07-qa-review.md allowed_tools: - Read - Glob @@ -655,22 +545,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: qa_review (QA専門レビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/07-qa-review.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions 品質保証の観点から上記の変更をレビューしてください。 **レビュー観点:** @@ -726,21 +605,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_qa - ## QA Review Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: QA専門家からの指摘を修正してください。 指摘されたポイント: @@ -775,6 +642,9 @@ steps: # =========================================== - name: supervise agent: ~/.takt/agents/expert/supervisor.md + report: + - Validation: 08-supervisor-validation.md + - Summary: summary.md allowed_tools: - Read - Glob @@ -783,18 +653,6 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: supervise (最終確認) - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Validation: .takt/reports/{report_dir}/08-supervisor-validation.md - - Summary: .takt/reports/{report_dir}/summary.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} @@ -802,13 +660,12 @@ steps: ## Previous Reviews Summary このステップに到達したということは、以下のレビューがすべてAPPROVEされています: + - AI Review: APPROVED - Architecture Review: APPROVED - Frontend Review: APPROVED - - AI Review: APPROVED - Security Review: APPROVED - QA Review: APPROVED - ## Instructions テスト実行、ビルド確認、最終承認を行ってください。 **ワークフロー全体の確認:** @@ -865,9 +722,9 @@ steps: ## レビュー結果 | レビュー | 結果 | |---------|------| + | AI Review | ✅ APPROVE | | Architecture | ✅ APPROVE | | Frontend | ✅ APPROVE | - | AI Review | ✅ APPROVE | | Security | ✅ APPROVE | | QA | ✅ APPROVE | | Supervisor | ✅ APPROVE | @@ -896,21 +753,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: fix_supervisor - ## Supervisor Feedback (これが最新の指示です - 優先して対応してください) {previous_response} - ## Original User Request (ワークフロー開始時の元の要求 - 参考情報) - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions **重要**: 監督者からの指摘を修正してください。 監督者は全体を俯瞰した視点から問題を指摘しています。 diff --git a/resources/global/ja/workflows/simple.yaml b/resources/global/ja/workflows/simple.yaml index f97f1f4..c8dc51e 100644 --- a/resources/global/ja/workflows/simple.yaml +++ b/resources/global/ja/workflows/simple.yaml @@ -1,19 +1,19 @@ # Simple TAKT Workflow -# Plan -> Coder -> Architect Review -> AI Review -> Supervisor Approval +# Plan -> Implement -> AI Review -> Architect Review -> Supervisor Approval # (defaultの簡略版 - improve, fix, ai_fix, security_review, security_fix を削除) # -# Template Variables: +# Template Variables (auto-injected): # {iteration} - Workflow-wide turn count (total steps executed across all agents) # {max_iterations} - Maximum iterations allowed for the workflow # {step_iteration} - Per-step iteration count (how many times THIS step has been executed) -# {task} - Original user request -# {previous_response} - Output from the previous step +# {task} - Original user request (auto-injected) +# {previous_response} - Output from the previous step (auto-injected) # {git_diff} - Current uncommitted changes (git diff) -# {user_inputs} - Accumulated user inputs during workflow +# {user_inputs} - Accumulated user inputs during workflow (auto-injected) # {report_dir} - Report directory name (e.g., "20250126-143052-task-summary") name: simple -description: Simplified development workflow (plan -> implement -> review -> ai_review -> supervise) +description: Simplified development workflow (plan -> implement -> ai_review -> review -> supervise) max_iterations: 20 @@ -22,6 +22,7 @@ initial_step: plan steps: - name: plan agent: ~/.takt/agents/default/planner.md + report: 00-plan.md allowed_tools: - Read - Glob @@ -31,20 +32,9 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: plan (タスク分析) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/00-plan.md - - ## User Request - {task} - ## Previous Response (implementからの差し戻し時) {previous_response} - ## Instructions タスクを分析し、実装方針を立ててください。 **注意:** Previous Responseがある場合は差し戻しのため、 @@ -55,10 +45,6 @@ steps: 2. 影響範囲を特定する 3. 実装アプローチを決める - **レポート出力:** 上記の `Report File` に出力してください。 - - ファイルが存在しない場合: 新規作成 - - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 - **レポートフォーマット:** ```markdown # タスク計画 @@ -95,6 +81,9 @@ steps: - name: implement agent: ~/.takt/agents/default/coder.md + report: + - Scope: 01-coder-scope.md + - Decisions: 02-coder-decisions.md allowed_tools: - Read - Glob @@ -106,29 +95,9 @@ steps: - WebFetch permission_mode: acceptEdits instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: implement - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Scope: .takt/reports/{report_dir}/01-coder-scope.md - - Decisions: .takt/reports/{report_dir}/02-coder-decisions.md - - ## User Request - {task} - - ## Additional User Inputs - {user_inputs} - - ## Instructions planステップで立てた計画に従って実装してください。 計画レポート(00-plan.md)を参照し、実装を進めてください。 - **レポート出力:** 上記の `Report Files` に出力してください。 - - ファイルが存在しない場合: 新規作成 - - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 - **Scopeレポートフォーマット(実装開始時に作成):** ```markdown # 変更スコープ宣言 @@ -160,12 +129,13 @@ steps: ``` rules: - condition: "実装完了" - next: review + next: ai_review - condition: "判断できない、情報不足" next: plan - - name: review - agent: ~/.takt/agents/default/architecture-reviewer.md + - name: ai_review + agent: ~/.takt/agents/default/ai-antipattern-reviewer.md + report: 03-ai-review.md allowed_tools: - Read - Glob @@ -174,33 +144,72 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: review (アーキテクチャレビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/03-architect-review.md - - ## Original User Request (ワークフロー開始時の元の要求) - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions - **アーキテクチャと設計**のレビューに集中してください。AI特有の問題はレビューしないでください(次のステップで行います)。 + AI特有の問題についてコードをレビューしてください: + - 仮定の検証 + - もっともらしいが間違っているパターン + - 既存コードベースとの適合性 + - スコープクリープの検出 + + **レポートフォーマット:** + ```markdown + # AI生成コードレビュー + + ## 結果: APPROVE / REJECT + + ## サマリー + {1文で結果を要約} + + ## 検証した項目 + | 観点 | 結果 | 備考 | + |------|------|------| + | 仮定の妥当性 | ✅ | - | + | API/ライブラリの実在 | ✅ | - | + | コンテキスト適合 | ✅ | - | + | スコープ | ✅ | - | + + ## 問題点(REJECTの場合) + | # | カテゴリ | 場所 | 問題 | + |---|---------|------|------| + | 1 | 幻覚API | `src/file.ts:23` | 存在しないメソッド | + ``` + + **認知負荷軽減ルール:** + - 問題なし → サマリー1文 + チェック表のみ(10行以内) + - 問題あり → + 問題を表形式で(25行以内) + rules: + - condition: "AI特有の問題なし" + next: review + - condition: "AI特有の問題あり" + next: plan + + - name: review + agent: ~/.takt/agents/default/architecture-reviewer.md + report: 04-architect-review.md + allowed_tools: + - Read + - Glob + - Grep + - Write + - WebSearch + - WebFetch + instruction_template: | + ## Git Diff + ```diff + {git_diff} + ``` + + **アーキテクチャと設計**のレビューに集中してください。AI特有の問題はレビューしないでください(前のステップで完了済み)。 変更をレビューしてフィードバックを提供してください。 **注意:** simpleワークフローではIMPROVE判定は使用しません。 軽微な改善提案がある場合は APPROVE + コメントとしてください。 - **レポート出力:** 上記の `Report File` に出力してください。 - - ファイルが存在しない場合: 新規作成 - - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 - **レポートフォーマット:** ```markdown # アーキテクチャレビュー @@ -230,80 +239,15 @@ steps: - REJECT → 問題点を表形式で(30行以内) rules: - condition: "問題なし" - next: ai_review - - condition: "構造的な修正必要" - next: plan - - - name: ai_review - agent: ~/.takt/agents/default/ai-antipattern-reviewer.md - allowed_tools: - - Read - - Glob - - Grep - - Write - - WebSearch - - WebFetch - instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: ai_review (AI生成コードレビュー) - - Report Directory: .takt/reports/{report_dir}/ - - Report File: .takt/reports/{report_dir}/04-ai-review.md - - ## Original User Request (ワークフロー開始時の元の要求) - {task} - - ## Git Diff - ```diff - {git_diff} - ``` - - ## Instructions - AI特有の問題についてコードをレビューしてください: - - 仮定の検証 - - もっともらしいが間違っているパターン - - 既存コードベースとの適合性 - - スコープクリープの検出 - - **レポート出力:** 上記の `Report File` に出力してください。 - - ファイルが存在しない場合: 新規作成 - - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 - - **レポートフォーマット:** - ```markdown - # AI生成コードレビュー - - ## 結果: APPROVE / REJECT - - ## サマリー - {1文で結果を要約} - - ## 検証した項目 - | 観点 | 結果 | 備考 | - |------|------|------| - | 仮定の妥当性 | ✅ | - | - | API/ライブラリの実在 | ✅ | - | - | コンテキスト適合 | ✅ | - | - | スコープ | ✅ | - | - - ## 問題点(REJECTの場合) - | # | カテゴリ | 場所 | 問題 | - |---|---------|------|------| - | 1 | 幻覚API | `src/file.ts:23` | 存在しないメソッド | - ``` - - **認知負荷軽減ルール:** - - 問題なし → サマリー1文 + チェック表のみ(10行以内) - - 問題あり → + 問題を表形式で(25行以内) - rules: - - condition: "AI特有の問題なし" next: supervise - - condition: "AI特有の問題あり" + - condition: "構造的な修正必要" next: plan - name: supervise agent: ~/.takt/agents/default/supervisor.md + report: + - Validation: 05-supervisor-validation.md + - Summary: summary.md allowed_tools: - Read - Glob @@ -313,24 +257,11 @@ steps: - WebSearch - WebFetch instruction_template: | - ## Workflow Context - - Iteration: {iteration}/{max_iterations}(ワークフロー全体) - - Step Iteration: {step_iteration}(このステップの実行回数) - - Step: supervise (final verification) - - Report Directory: .takt/reports/{report_dir}/ - - Report Files: - - Validation: .takt/reports/{report_dir}/05-supervisor-validation.md - - Summary: .takt/reports/{report_dir}/summary.md - - ## Original User Request - {task} - ## Git Diff ```diff {git_diff} ``` - ## Instructions テスト実行、ビルド確認、最終承認を行ってください。 **ワークフロー全体の確認:** @@ -341,10 +272,6 @@ steps: **レポートの確認:** Report Directory内の全レポートを読み、 未対応の改善提案がないか確認してください。 - **レポート出力:** 上記の `Report Files` に出力してください。 - - ファイルが存在しない場合: 新規作成 - - ファイルが存在する場合: `## Iteration {step_iteration}` セクションを追記 - **Validationレポートフォーマット:** ```markdown # 最終検証結果 @@ -387,8 +314,8 @@ steps: ## レビュー結果 | レビュー | 結果 | |---------|------| - | Architect | ✅ APPROVE | | AI Review | ✅ APPROVE | + | Architect | ✅ APPROVE | | Supervisor | ✅ APPROVE | ## 確認コマンド diff --git a/src/__tests__/instructionBuilder.test.ts b/src/__tests__/instructionBuilder.test.ts index ed807f9..21c0db4 100644 --- a/src/__tests__/instructionBuilder.test.ts +++ b/src/__tests__/instructionBuilder.test.ts @@ -344,6 +344,205 @@ describe('instruction-builder', () => { }); }); + describe('auto-injected Workflow Context section', () => { + it('should include iteration, step iteration, and step name', () => { + const step = createMinimalStep('Do work'); + step.name = 'implement'; + const context = createMinimalContext({ + iteration: 3, + maxIterations: 20, + stepIteration: 2, + language: 'en', + }); + + const result = buildInstruction(step, context); + + expect(result).toContain('## Workflow Context'); + expect(result).toContain('- Iteration: 3/20'); + expect(result).toContain('- Step Iteration: 2'); + expect(result).toContain('- Step: implement'); + }); + + it('should include single report file when report is a string', () => { + const step = createMinimalStep('Do work'); + step.name = 'plan'; + step.report = '00-plan.md'; + const context = createMinimalContext({ + reportDir: '20260129-test', + language: 'en', + }); + + const result = buildInstruction(step, context); + + expect(result).toContain('- Report Directory: .takt/reports/20260129-test/'); + expect(result).toContain('- Report File: .takt/reports/20260129-test/00-plan.md'); + expect(result).not.toContain('Report Files:'); + }); + + it('should include multiple report files when report is ReportConfig[]', () => { + const step = createMinimalStep('Do work'); + step.name = 'implement'; + step.report = [ + { label: 'Scope', path: '01-scope.md' }, + { label: 'Decisions', path: '02-decisions.md' }, + ]; + const context = createMinimalContext({ + reportDir: '20260129-test', + language: 'en', + }); + + const result = buildInstruction(step, context); + + expect(result).toContain('- Report Directory: .takt/reports/20260129-test/'); + expect(result).toContain('- Report Files:'); + expect(result).toContain(' - Scope: .takt/reports/20260129-test/01-scope.md'); + expect(result).toContain(' - Decisions: .takt/reports/20260129-test/02-decisions.md'); + expect(result).not.toContain('Report File:'); + }); + + it('should NOT include report info when reportDir is undefined', () => { + const step = createMinimalStep('Do work'); + step.report = '00-plan.md'; + const context = createMinimalContext({ language: 'en' }); + + const result = buildInstruction(step, context); + + expect(result).toContain('## Workflow Context'); + expect(result).not.toContain('Report Directory'); + expect(result).not.toContain('Report File'); + }); + + it('should NOT include report info when step has no report', () => { + const step = createMinimalStep('Do work'); + const context = createMinimalContext({ + reportDir: '20260129-test', + language: 'en', + }); + + const result = buildInstruction(step, context); + + expect(result).toContain('## Workflow Context'); + expect(result).not.toContain('Report Directory'); + expect(result).not.toContain('Report File'); + }); + + it('should render Japanese step iteration suffix', () => { + const step = createMinimalStep('Do work'); + const context = createMinimalContext({ + stepIteration: 3, + language: 'ja', + }); + + const result = buildInstruction(step, context); + + expect(result).toContain('- Step Iteration: 3(このステップの実行回数)'); + }); + }); + + describe('auto-injected User Request and Additional User Inputs sections', () => { + it('should include User Request section with task', () => { + const step = createMinimalStep('Do work'); + const context = createMinimalContext({ task: 'Build the feature', language: 'en' }); + + const result = buildInstruction(step, context); + + expect(result).toContain('## User Request\n'); + }); + + it('should include Additional User Inputs section', () => { + const step = createMinimalStep('Do work'); + const context = createMinimalContext({ + userInputs: ['input1', 'input2'], + language: 'en', + }); + + const result = buildInstruction(step, context); + + expect(result).toContain('## Additional User Inputs\n'); + }); + + it('should include Previous Response when passPreviousResponse is true and output exists', () => { + const step = createMinimalStep('Do work'); + step.passPreviousResponse = true; + const context = createMinimalContext({ + previousOutput: { content: 'Previous result', tag: '[TEST:1]' }, + language: 'en', + }); + + const result = buildInstruction(step, context); + + expect(result).toContain('## Previous Response\n'); + }); + + it('should NOT include Previous Response when passPreviousResponse is false', () => { + const step = createMinimalStep('Do work'); + step.passPreviousResponse = false; + const context = createMinimalContext({ + previousOutput: { content: 'Previous result', tag: '[TEST:1]' }, + language: 'en', + }); + + const result = buildInstruction(step, context); + + expect(result).not.toContain('## Previous Response'); + }); + + it('should include Instructions header before template content', () => { + const step = createMinimalStep('My specific instructions here'); + const context = createMinimalContext({ language: 'en' }); + + const result = buildInstruction(step, context); + + const instructionsIdx = result.indexOf('## Instructions'); + const contentIdx = result.indexOf('My specific instructions here'); + expect(instructionsIdx).toBeGreaterThan(-1); + expect(contentIdx).toBeGreaterThan(instructionsIdx); + }); + + it('should skip auto-injected User Request when template contains {task}', () => { + const step = createMinimalStep('Process this: {task}'); + const context = createMinimalContext({ task: 'My task', language: 'en' }); + + const result = buildInstruction(step, context); + + // Auto-injected section should NOT appear + expect(result).not.toContain('## User Request'); + // But template placeholder should be replaced + expect(result).toContain('Process this: My task'); + }); + + it('should skip auto-injected Previous Response when template contains {previous_response}', () => { + const step = createMinimalStep('## Feedback\n{previous_response}\n\nFix the issues.'); + step.passPreviousResponse = true; + const context = createMinimalContext({ + previousOutput: { content: 'Review feedback here', tag: '[TEST:1]' }, + language: 'en', + }); + + const result = buildInstruction(step, context); + + // Auto-injected section should NOT appear + expect(result).not.toContain('## Previous Response\n'); + // But template placeholder should be replaced with content + expect(result).toContain('## Feedback\nReview feedback here'); + }); + + it('should skip auto-injected Additional User Inputs when template contains {user_inputs}', () => { + const step = createMinimalStep('Inputs: {user_inputs}'); + const context = createMinimalContext({ + userInputs: ['extra info'], + language: 'en', + }); + + const result = buildInstruction(step, context); + + // Auto-injected section should NOT appear + expect(result).not.toContain('## Additional User Inputs'); + // But template placeholder should be replaced + expect(result).toContain('Inputs: extra info'); + }); + }); + describe('basic placeholder replacement', () => { it('should replace {task} placeholder', () => { const step = createMinimalStep('Execute: {task}'); diff --git a/src/config/workflowLoader.ts b/src/config/workflowLoader.ts index 794ddc5..d0e7656 100644 --- a/src/config/workflowLoader.ts +++ b/src/config/workflowLoader.ts @@ -8,7 +8,7 @@ import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs'; import { join, dirname, basename } from 'node:path'; import { parse as parseYaml } from 'yaml'; import { WorkflowConfigRawSchema } from '../models/schemas.js'; -import type { WorkflowConfig, WorkflowStep, WorkflowRule } from '../models/types.js'; +import type { WorkflowConfig, WorkflowStep, WorkflowRule, ReportConfig } from '../models/types.js'; import { getGlobalWorkflowsDir } from './paths.js'; /** Get builtin workflow by name */ @@ -54,6 +54,28 @@ function extractAgentDisplayName(agentPath: string): string { return filename; } +/** + * Normalize the raw report field from YAML into internal format. + * + * YAML formats: + * report: "00-plan.md" → string (single file) + * report: → ReportConfig[] (multiple files) + * - Scope: 01-scope.md + * - Decisions: 02-decisions.md + * + * Array items are parsed as single-key objects: [{Scope: "01-scope.md"}, ...] + */ +function normalizeReport( + raw: string | Record[] | undefined, +): string | ReportConfig[] | undefined { + if (raw == null) return undefined; + if (typeof raw === 'string') return raw; + // Convert [{Scope: "01-scope.md"}, ...] to [{label: "Scope", path: "01-scope.md"}, ...] + return raw.flatMap((entry) => + Object.entries(entry).map(([label, path]) => ({ label, path })), + ); +} + /** * Convert raw YAML workflow config to internal format. * Agent paths are resolved relative to the workflow directory. @@ -79,6 +101,7 @@ function normalizeWorkflowConfig(raw: unknown, workflowDir: string): WorkflowCon permissionMode: step.permission_mode, instructionTemplate: step.instruction_template || step.instruction || '{task}', rules, + report: normalizeReport(step.report), passPreviousResponse: step.pass_previous_response, }; }); diff --git a/src/models/index.ts b/src/models/index.ts index b274533..9c97d95 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -2,6 +2,7 @@ export type { AgentType, Status, + ReportConfig, AgentResponse, SessionState, WorkflowStep, diff --git a/src/models/schemas.ts b/src/models/schemas.ts index 05dee5f..c63328a 100644 --- a/src/models/schemas.ts +++ b/src/models/schemas.ts @@ -27,6 +27,22 @@ export const StatusSchema = z.enum([ /** Permission mode schema for tool execution */ export const PermissionModeSchema = z.enum(['default', 'acceptEdits', 'bypassPermissions']); +/** + * Report field schema. + * + * YAML formats: + * report: 00-plan.md # single file + * report: # multiple files (label: path map entries) + * - Scope: 01-scope.md + * - Decisions: 02-decisions.md + * + * Array items are parsed as single-key objects: [{Scope: "01-scope.md"}, ...] + */ +export const ReportFieldSchema = z.union([ + z.string().min(1), + z.array(z.record(z.string(), z.string())).min(1), +]); + /** Rule-based transition schema (new unified format) */ export const WorkflowRuleSchema = z.object({ /** Human-readable condition text */ @@ -52,6 +68,8 @@ export const WorkflowStepRawSchema = z.object({ instruction_template: z.string().optional(), /** Rules for step routing */ rules: z.array(WorkflowRuleSchema).optional(), + /** Report file(s) for this step */ + report: ReportFieldSchema.optional(), pass_previous_response: z.boolean().optional().default(true), }); diff --git a/src/models/types.ts b/src/models/types.ts index 8bfc374..7c1c8b9 100644 --- a/src/models/types.ts +++ b/src/models/types.ts @@ -50,6 +50,14 @@ export interface WorkflowRule { appendix?: string; } +/** Report file configuration for a workflow step */ +export interface ReportConfig { + /** Display label (e.g., "Scope", "Decisions") */ + label: string; + /** File path relative to report directory (e.g., "01-coder-scope.md") */ + path: string; +} + /** Permission mode for tool execution */ export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions'; @@ -73,6 +81,8 @@ export interface WorkflowStep { instructionTemplate: string; /** Rules for step routing */ rules?: WorkflowRule[]; + /** Report file configuration. Single string for one file, array for multiple. */ + report?: string | ReportConfig[]; passPreviousResponse: boolean; } diff --git a/src/workflow/instruction-builder.ts b/src/workflow/instruction-builder.ts index 21440be..676a083 100644 --- a/src/workflow/instruction-builder.ts +++ b/src/workflow/instruction-builder.ts @@ -1,11 +1,14 @@ /** * Instruction template builder for workflow steps * - * Builds the instruction string for agent execution by replacing - * template placeholders with actual values. + * Builds the instruction string for agent execution by: + * 1. Auto-injecting standard sections (Execution Context, Workflow Context, + * User Request, Previous Response, Additional User Inputs, Instructions header) + * 2. Replacing template placeholders with actual values + * 3. Appending auto-generated status rules from workflow rules */ -import type { WorkflowStep, WorkflowRule, AgentResponse, Language } from '../models/types.js'; +import type { WorkflowStep, WorkflowRule, AgentResponse, Language, ReportConfig } from '../models/types.js'; import { getGitDiff } from '../agents/runner.js'; /** @@ -213,76 +216,207 @@ function escapeTemplateChars(str: string): string { return str.replace(/\{/g, '{').replace(/\}/g, '}'); } +/** Localized strings for auto-injected sections */ +const SECTION_STRINGS = { + en: { + workflowContext: '## Workflow Context', + iteration: 'Iteration', + iterationWorkflowWide: '(workflow-wide)', + stepIteration: 'Step Iteration', + stepIterationTimes: '(times this step has run)', + step: 'Step', + reportDirectory: 'Report Directory', + reportFile: 'Report File', + reportFiles: 'Report Files', + userRequest: '## User Request', + previousResponse: '## Previous Response', + additionalUserInputs: '## Additional User Inputs', + instructions: '## Instructions', + }, + ja: { + workflowContext: '## Workflow Context', + iteration: 'Iteration', + iterationWorkflowWide: '(ワークフロー全体)', + stepIteration: 'Step Iteration', + stepIterationTimes: '(このステップの実行回数)', + step: 'Step', + reportDirectory: 'Report Directory', + reportFile: 'Report File', + reportFiles: 'Report Files', + userRequest: '## User Request', + previousResponse: '## Previous Response', + additionalUserInputs: '## Additional User Inputs', + instructions: '## Instructions', + }, +} as const; + /** - * Build instruction from template with context values. - * - * Supported placeholders: - * - {task} - The main task/prompt - * - {iteration} - Current iteration number (workflow-wide turn count) - * - {max_iterations} - Maximum iterations allowed - * - {step_iteration} - Current step's iteration number (how many times this step has been executed) - * - {previous_response} - Output from previous step (if passPreviousResponse is true) - * - {git_diff} - Current git diff output - * - {user_inputs} - Accumulated user inputs - * - {report_dir} - Report directory name (e.g., "20250126-143052-task-summary") + * Render the Workflow Context section. */ -export function buildInstruction( +function renderWorkflowContext( step: WorkflowStep, - context: InstructionContext + context: InstructionContext, + language: Language, ): string { - let instruction = step.instructionTemplate; + const s = SECTION_STRINGS[language]; + const lines: string[] = [ + s.workflowContext, + `- ${s.iteration}: ${context.iteration}/${context.maxIterations}${s.iterationWorkflowWide}`, + `- ${s.stepIteration}: ${context.stepIteration}${s.stepIterationTimes}`, + `- ${s.step}: ${step.name}`, + ]; + + // Report info (only if step has report config AND reportDir is available) + if (step.report && context.reportDir) { + lines.push(`- ${s.reportDirectory}: .takt/reports/${context.reportDir}/`); + + if (typeof step.report === 'string') { + // Single file + lines.push(`- ${s.reportFile}: .takt/reports/${context.reportDir}/${step.report}`); + } else { + // Multiple files + lines.push(`- ${s.reportFiles}:`); + for (const file of step.report as ReportConfig[]) { + lines.push(` - ${file.label}: .takt/reports/${context.reportDir}/${file.path}`); + } + } + } + + return lines.join('\n'); +} + +/** + * Replace template placeholders in the instruction_template body. + * + * These placeholders may still be used in instruction_template for + * backward compatibility or special cases (e.g., {git_diff} in review steps). + */ +function replaceTemplatePlaceholders( + template: string, + step: WorkflowStep, + context: InstructionContext, +): string { + let result = template; + + // These placeholders are also covered by auto-injected sections + // (User Request, Previous Response, Additional User Inputs), but kept here + // for backward compatibility with workflows that still embed them in + // instruction_template (e.g., research.yaml, magi.yaml). + // New workflows should NOT use {task} or {user_inputs} in instruction_template + // since they are auto-injected as separate sections. // Replace {task} - instruction = instruction.replace(/\{task\}/g, escapeTemplateChars(context.task)); + result = result.replace(/\{task\}/g, escapeTemplateChars(context.task)); // Replace {iteration}, {max_iterations}, and {step_iteration} - instruction = instruction.replace(/\{iteration\}/g, String(context.iteration)); - instruction = instruction.replace(/\{max_iterations\}/g, String(context.maxIterations)); - instruction = instruction.replace(/\{step_iteration\}/g, String(context.stepIteration)); + result = result.replace(/\{iteration\}/g, String(context.iteration)); + result = result.replace(/\{max_iterations\}/g, String(context.maxIterations)); + result = result.replace(/\{step_iteration\}/g, String(context.stepIteration)); // Replace {previous_response} if (step.passPreviousResponse) { if (context.previousOutput) { - instruction = instruction.replace( + result = result.replace( /\{previous_response\}/g, - escapeTemplateChars(context.previousOutput.content) + escapeTemplateChars(context.previousOutput.content), ); } else { - instruction = instruction.replace(/\{previous_response\}/g, ''); + result = result.replace(/\{previous_response\}/g, ''); } } // Replace {git_diff} const gitDiff = getGitDiff(context.cwd); - instruction = instruction.replace(/\{git_diff\}/g, gitDiff); + result = result.replace(/\{git_diff\}/g, gitDiff); // Replace {user_inputs} const userInputsStr = context.userInputs.join('\n'); - instruction = instruction.replace( + result = result.replace( /\{user_inputs\}/g, - escapeTemplateChars(userInputsStr) + escapeTemplateChars(userInputsStr), ); - // Replace {report_dir} with the directory name, keeping paths relative. - // In worktree mode, a symlink from cwd/.takt/reports → projectCwd/.takt/reports - // ensures the relative path resolves correctly without embedding absolute paths - // that could cause agents to operate on the wrong repository. + // Replace {report_dir} if (context.reportDir) { - instruction = instruction.replace(/\{report_dir\}/g, context.reportDir); + result = result.replace(/\{report_dir\}/g, context.reportDir); } - // Append auto-generated status rules from rules + return result; +} + +/** + * Build instruction from template with context values. + * + * Generates a complete instruction by auto-injecting standard sections + * around the step-specific instruction_template content: + * + * 1. Execution Context (working directory, rules) — always + * 2. Workflow Context (iteration, step, report info) — always + * 3. User Request ({task}) — unless template contains {task} + * 4. Previous Response — if passPreviousResponse and has content, unless template contains {previous_response} + * 5. Additional User Inputs — unless template contains {user_inputs} + * 6. Instructions header + instruction_template content — always + * 7. Status Output Rules — if rules exist + * + * Template placeholders ({task}, {git_diff}, etc.) are still replaced + * within the instruction_template body for backward compatibility. + * When a placeholder is present in the template, the corresponding + * auto-injected section is skipped to avoid duplication. + */ +export function buildInstruction( + step: WorkflowStep, + context: InstructionContext, +): string { const language = context.language ?? 'en'; + const s = SECTION_STRINGS[language]; + const sections: string[] = []; + + // 1. Execution context metadata (working directory + rules) + const metadata = buildExecutionMetadata(context); + sections.push(renderExecutionMetadata(metadata)); + + // 2. Workflow Context (iteration, step, report info) + sections.push(renderWorkflowContext(step, context, language)); + + // Skip auto-injection for sections whose placeholders exist in the template, + // to avoid duplicate content. Templates using placeholders handle their own layout. + const tmpl = step.instructionTemplate; + const hasTaskPlaceholder = tmpl.includes('{task}'); + const hasPreviousResponsePlaceholder = tmpl.includes('{previous_response}'); + const hasUserInputsPlaceholder = tmpl.includes('{user_inputs}'); + + // 3. User Request (skip if template embeds {task} directly) + if (!hasTaskPlaceholder) { + sections.push(`${s.userRequest}\n${escapeTemplateChars(context.task)}`); + } + + // 4. Previous Response (skip if template embeds {previous_response} directly) + if (step.passPreviousResponse && context.previousOutput && !hasPreviousResponsePlaceholder) { + sections.push( + `${s.previousResponse}\n${escapeTemplateChars(context.previousOutput.content)}`, + ); + } + + // 5. Additional User Inputs (skip if template embeds {user_inputs} directly) + if (!hasUserInputsPlaceholder) { + const userInputsStr = context.userInputs.join('\n'); + sections.push(`${s.additionalUserInputs}\n${escapeTemplateChars(userInputsStr)}`); + } + + // 6. Instructions header + instruction_template content + const processedTemplate = replaceTemplatePlaceholders( + step.instructionTemplate, + step, + context, + ); + sections.push(`${s.instructions}\n${processedTemplate}`); + + // 7. Status rules (auto-generated from rules) if (step.rules && step.rules.length > 0) { const statusHeader = renderStatusRulesHeader(language); const generatedPrompt = generateStatusRulesFromRules(step.name, step.rules, language); - instruction = `${instruction}\n\n${statusHeader}\n${generatedPrompt}`; + sections.push(`${statusHeader}\n${generatedPrompt}`); } - // Prepend execution context metadata so agents see it first. - // Now language-aware, so no need to hide it at the end. - const metadata = buildExecutionMetadata(context); - instruction = `${renderExecutionMetadata(metadata)}\n${instruction}`; - - return instruction; + return sections.join('\n\n'); }