Skip to content

Commit fd857bd

Browse files
authored
Merge pull request #48 from shinpr/fix/code-reading-clarity
fix: Improve code investigation process clarity and AI execution accuracy
2 parents 3fca2f6 + 403c7db commit fd857bd

14 files changed

+77
-23
lines changed

.claude/agents-en/code-reviewer.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You are a code review AI assistant specializing in Design Doc compliance validat
99
## Initial Required Tasks
1010

1111
Load and follow these rule files before starting:
12-
- @docs/rules/ai-development-guide.md - AI Development Guide
12+
- @docs/rules/ai-development-guide.md - AI Development Guide, pre-implementation existing code investigation process
1313
- @docs/rules/technical-spec.md - Technical Specifications
1414
- @docs/rules/typescript.md - TypeScript Development Rules
1515
- @docs/rules/project-context.md - Project Context
@@ -93,6 +93,8 @@ Load and follow these rule files before starting:
9393
- [ ] Data flow follows design
9494
- [ ] Component dependencies correct
9595
- [ ] Responsibilities properly separated
96+
- [ ] Existing codebase analysis section includes similar functionality investigation results
97+
- [ ] No unnecessary duplicate implementations (Pattern 5 from @docs/rules/ai-development-guide.md)
9698

9799
### Quality Validation
98100
- [ ] Comprehensive error handling

.claude/agents-en/task-executor.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ You are a specialized AI assistant for reliably executing individual tasks.
2727
## Mandatory Rules
2828

2929
Load and follow these rule files before starting:
30-
- @docs/rules/ai-development-guide.md - AI Development Guide
30+
- @docs/rules/ai-development-guide.md - AI Development Guide, pre-implementation existing code investigation process
3131
**Follow**: All rules for implementation, testing, and code quality
3232
⚠️ **Exception**: Quality assurance process (Phase1-6) and commits are out of scope
3333
- @docs/rules/typescript-testing.md - Testing Rules
@@ -62,8 +62,13 @@ ls docs/plans/tasks/*.md | grep -E "task-[0-9]{2}\.md$" | head -1
6262
- Complete understanding of task file
6363
- Confirm overall design document (_overview-*.md)
6464
- Grasp impact scope and common processing points
65+
- Check "Existing Codebase Analysis" section in Design Doc
6566

6667
### 3. Implementation Execution
68+
#### Pre-implementation Verification (Following @docs/rules/ai-development-guide.md Pattern 5)
69+
- Re-confirm no existing implementations of similar functionality exist
70+
- Follow decisions recorded in Design Doc (use existing/new implementation)
71+
- If new similar functionality discovered, pause implementation and report
6772
- If all checkboxes are `[x]`, report "already completed" and end
6873
- Staged implementation with incremental verification
6974
- Upon each step completion【Required】Update checkboxes using Edit tool:

.claude/agents-en/technical-designer.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Before starting work, be sure to read and follow these rule files:
1212
- @docs/rules/documentation-criteria.md - Documentation creation criteria
1313
- @docs/rules/technical-spec.md - Project technical specifications
1414
- @docs/rules/typescript.md - TypeScript development rules
15-
- @docs/rules/ai-development-guide.md - AI development guide
15+
- @docs/rules/ai-development-guide.md - AI development guide, pre-implementation existing code investigation process
1616
- @docs/rules/project-context.md - Project context
1717
- @docs/rules/architecture/implementation-approach.md - Metacognitive strategy selection process (used for implementation approach decisions)
1818
- @docs/rules/architecture/ architecture rule files (if exist)
@@ -50,7 +50,7 @@ Details of documentation creation criteria follow @docs/rules/documentation-crit
5050
### Existing Code Investigation【Required】
5151
Must be performed before Design Doc creation:
5252

53-
1. **Implementation Path Verification**
53+
1. **Implementation File Path Verification**
5454
- First grasp overall structure with `Glob: src/**/*.ts`
5555
- Then identify target files with `Grep: "class.*Service" --type ts` or feature names
5656
- Record and distinguish between existing implementation locations and planned new locations
@@ -59,9 +59,18 @@ Must be performed before Design Doc creation:
5959
- List major public methods of target service (about 5 important ones if over 10)
6060
- Identify call sites with `Grep: "ServiceName\." --type ts`
6161

62-
3. **Include in Design Doc**
62+
3. **Similar Functionality Search and Decision** (Pattern 5 prevention from @docs/rules/ai-development-guide.md)
63+
- Search existing code for keywords related to planned functionality
64+
- Look for implementations with same domain, responsibilities, or configuration patterns
65+
- Decision and action:
66+
- Similar functionality found → Use that implementation (do not create new implementation)
67+
- Similar functionality is technical debt → Create ADR improvement proposal before implementation
68+
- No similar functionality → Proceed with new implementation
69+
70+
4. **Include in Design Doc**
6371
- Always include investigation results in "## Existing Codebase Analysis" section
64-
- If planned path differs from actual path, clearly state the reason
72+
- Clearly document similar functionality search results (found implementations or "none")
73+
- Record adopted decision (use existing/improvement proposal/new implementation) and rationale
6574

6675
### Agreement Checklist【Most Important】
6776
Must be performed at the beginning of Design Doc creation:

.claude/agents-en/work-planner.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You are a specialized AI assistant for creating work plan documents.
99
## Initial Mandatory Tasks
1010

1111
Before starting work, be sure to read and follow these rule files:
12-
- @docs/rules/ai-development-guide.md - AI development guide (task management principles)
12+
- @docs/rules/ai-development-guide.md - AI development guide, pre-implementation existing code investigation process, task management principles
1313
- @docs/rules/documentation-criteria.md - Documentation creation criteria
1414
- @docs/rules/technical-spec.md - Technical specifications
1515
- @docs/rules/typescript-testing.md - Testing rules
@@ -75,7 +75,7 @@ Execute file output immediately (considered approved at execution).
7575
5. **Design Doc Compliance**: All task completion criteria derived from Design Doc specifications
7676

7777
### Task Completion Definition: 3 Elements
78-
1. **Implementation Complete**: Code functions
78+
1. **Implementation Complete**: Code functions (including existing code investigation)
7979
2. **Quality Complete**: Tests, type checking, linting pass
8080
3. **Integration Complete**: Coordination with other components verified
8181

.claude/agents-ja/code-reviewer.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tools: Read, Grep, Glob, LS
99
## 初回必須タスク
1010

1111
作業開始前に以下のルールファイルを必ず読み込み、厳守してください:
12-
- @docs/rules/ai-development-guide.md - AI開発ガイド
12+
- @docs/rules/ai-development-guide.md - AI開発ガイド、実装前の既存コード調査プロセス
1313
- @docs/rules/technical-spec.md - 技術仕様
1414
- @docs/rules/typescript.md - TypeScript開発ルール
1515
- @docs/rules/project-context.md - プロジェクトコンテキスト
@@ -93,6 +93,8 @@ tools: Read, Grep, Glob, LS
9393
- [ ] データフローが設計通りか
9494
- [ ] コンポーネント間の依存関係が正しいか
9595
- [ ] 責務の分離が適切か
96+
- [ ] 既存コードベース分析セクションに類似機能調査結果が記載されているか
97+
- [ ] 不必要な重複実装がないか(@docs/rules/ai-development-guide.md パターン5)
9698

9799
### 品質検証
98100
- [ ] エラーハンドリングが網羅的か

.claude/agents-ja/task-executor.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tools: Read, Edit, Write, MultiEdit, Bash, Grep, Glob, LS, TodoWrite
2727
## 必須ルール
2828

2929
作業開始前に以下のルールファイルを必ず読み込み、厳守してください:
30-
- @docs/rules/ai-development-guide.md - AI開発ガイド
30+
- @docs/rules/ai-development-guide.md - AI開発ガイド、実装前の既存コード調査プロセス
3131
**厳守**: 実装・テスト・コード品質に関するすべてのルール
3232
⚠️ **例外**: 品質保証工程(Phase 1-6)・コミット作成は責務範囲外のため適用しない
3333
- @docs/rules/typescript-testing.md - テストルール
@@ -62,8 +62,15 @@ ls docs/plans/tasks/*.md | grep -E "task-[0-9]{2}\.md$" | head -1
6262
- タスクファイルの完全理解
6363
- 全体設計書(_overview-*.md)確認
6464
- 影響範囲と共通化ポイントの把握
65+
- Design Docの「既存コードベース分析」セクションを確認
6566

6667
### 3. 実装実行
68+
#### 実装前の確認(@docs/rules/ai-development-guide.md パターン5準拠)
69+
- 類似機能の既存実装がないか再確認
70+
- Design Docに記載された判断(既存使用/新規実装)に従う
71+
- 新たな類似機能を発見した場合は実装を中断し報告
72+
73+
#### 実装の進行
6774
- 全チェックボックスが`[x]`の場合は「既に完了」と報告して終了
6875
- 段階的実装と逐次確認
6976
- 各ステップ完了時に【必須】Editツールでチェックボックスを更新:

.claude/agents-ja/technical-designer.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tools: Read, Write, Edit, MultiEdit, Glob, LS, TodoWrite, WebSearch
1212
- @docs/rules/documentation-criteria.md - ドキュメント作成基準
1313
- @docs/rules/technical-spec.md - プロジェクトの技術仕様
1414
- @docs/rules/typescript.md - TypeScript開発ルール
15-
- @docs/rules/ai-development-guide.md - AI開発ガイド
15+
- @docs/rules/ai-development-guide.md - AI開発ガイド、実装前の既存コード調査プロセス
1616
- @docs/rules/project-context.md - プロジェクトコンテキスト
1717
- @docs/rules/architecture/implementation-approach.md - メタ認知的戦略選択プロセス(実装アプローチ決定で使用)
1818
- @docs/rules/architecture/ 配下のアーキテクチャルールファイル(存在する場合)
@@ -50,7 +50,7 @@ tools: Read, Write, Edit, MultiEdit, Glob, LS, TodoWrite, WebSearch
5050
### 既存コード調査【必須】
5151
Design Doc作成前に必ず実施:
5252

53-
1. **実装パスの確認**
53+
1. **実装ファイルパスの確認**
5454
- まず `Glob: src/**/*.ts` で全体構造を把握
5555
- 次に `Grep: "class.*Service" --type ts` や機能名で対象ファイルを特定
5656
- 既存実装の場所と新規作成予定の場所を区別して記録
@@ -59,9 +59,18 @@ Design Doc作成前に必ず実施:
5959
- 変更対象サービスの主要publicメソッドを列挙(10個超の場合は重要な5個程度)
6060
- `Grep: "ServiceName\." --type ts` で呼び出し箇所を特定
6161

62-
3. **Design Docへの記載**
62+
3. **類似機能の検索と判断**@docs/rules/ai-development-guide.md パターン5対策)
63+
- 実装予定の機能に関連するキーワードで既存コードを検索
64+
- 同じドメイン、同じ責務、同じ設定パターンの実装を探索
65+
- 判断と行動:
66+
- 類似機能を発見 → その実装を使用する(新規実装は行わない)
67+
- 類似機能が技術的負債 → ADRで改善提案を作成してから実装
68+
- 類似機能なし → 新規実装を進める
69+
70+
4. **Design Docへの記載**
6371
- 「## 既存コードベース分析」セクションに調査結果を必ず記載
64-
- 計画パスと実際のパスが異なる場合は、その理由を明記
72+
- 類似機能の検索結果(発見した実装、または「なし」)を明記
73+
- 採用した判断(既存使用/改善提案/新規実装)とその根拠を記録
6574

6675
### 合意事項チェックリスト【最重要】
6776
Design Doc作成の最初に必ず実施:

.claude/agents-ja/work-planner.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tools: Read, Write, Edit, MultiEdit, Glob, LS, TodoWrite
99
## 初回必須タスク
1010

1111
作業開始前に以下のルールファイルを必ず読み込み、厳守してください:
12-
- @docs/rules/ai-development-guide.md - AI開発ガイドタスク管理の原則
12+
- @docs/rules/ai-development-guide.md - AI開発ガイド、実装前の既存コード調査プロセス、タスク管理の原則
1313
- @docs/rules/documentation-criteria.md - ドキュメント作成基準
1414
- @docs/rules/technical-spec.md - 技術仕様
1515
- @docs/rules/typescript-testing.md - テストルール
@@ -72,7 +72,7 @@ tools: Read, Write, Edit, MultiEdit, Glob, LS, TodoWrite
7272
5. **Design Doc準拠**: 全タスクの完了条件はDesign Docの仕様から導出
7373

7474
### タスク完了定義の3要素
75-
1. **実装完了**: コードが動作する
75+
1. **実装完了**: コードが動作する(既存コード調査を含む)
7676
2. **品質完了**: テスト・型チェック・リントがパス
7777
3. **統合完了**: 他コンポーネントとの連携確認
7878

docs/rules-en/ai-development-guide.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ function validateEmail(email: string, context: 'user' | 'contact' | 'admin') { /
8989
```
9090
- For low certainty cases, create minimal verification code first
9191

92+
### Pattern 5: Insufficient Existing Code Investigation
93+
**Symptom**: Duplicate implementations, architecture inconsistency, integration failures
94+
**Cause**: Insufficient understanding of existing code before implementation
95+
**Avoidance Methods**:
96+
- Before implementation, always search for similar functionality (using domain, responsibility, configuration patterns as keywords)
97+
- Similar functionality found → Use that implementation (do not create new implementation)
98+
- Similar functionality is technical debt → Create ADR improvement proposal before implementation
99+
- No similar functionality exists → Implement new functionality following existing design philosophy
100+
- Record all decisions and rationale in "Existing Codebase Analysis" section of Design Doc
101+
92102
## Debugging Techniques
93103

94104
### 1. Error Analysis Procedure

docs/rules-en/rules-index.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ rules:
4646

4747
ai-development-guide:
4848
file: "ai-development-guide.md"
49-
tags: [anti-patterns, technical-judgment, debugging, quality-commands, rule-of-three, implementation, type-safety, refactoring]
50-
typical-use: "Technical decision criteria, anti-pattern detection, debugging techniques, quality check commands, implementation failure avoidance"
49+
tags: [anti-patterns, technical-judgment, debugging, quality-commands, rule-of-three, implementation, type-safety, refactoring, code-reading, best-practices]
50+
typical-use: "Technical decision criteria, anti-pattern detection, debugging techniques, quality check commands, implementation best practices"
5151
size: medium
5252
key-references:
5353
- "Rule of Three - Martin Fowler"

0 commit comments

Comments
 (0)