aidp 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,8 +57,6 @@ module Aidp
57
57
 
58
58
  # Stop checking if the process is done
59
59
  break if wait.value
60
- rescue
61
- break
62
60
  end
63
61
  end
64
62
 
@@ -88,8 +86,8 @@ module Aidp
88
86
  # Kill the process if it's taking too long
89
87
  begin
90
88
  Process.kill("TERM", wait.pid)
91
- rescue
92
- nil
89
+ rescue Errno::ESRCH
90
+ # Process already terminated
93
91
  end
94
92
 
95
93
  mark_failed("gemini timed out after #{timeout_seconds} seconds")
@@ -101,8 +99,8 @@ module Aidp
101
99
  # Kill the process
102
100
  begin
103
101
  Process.kill("TERM", wait.pid)
104
- rescue
105
- nil
102
+ rescue Errno::ESRCH
103
+ # Process already terminated
106
104
  end
107
105
 
108
106
  mark_failed("gemini execution was interrupted")
data/lib/aidp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aidp
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/aidp.rb CHANGED
@@ -38,6 +38,12 @@ require "aidp/analyze/runner"
38
38
  require "aidp/analyze/steps"
39
39
  require "aidp/analyze/progress"
40
40
 
41
+ # Tree-sitter analysis
42
+ require "aidp/analysis/tree_sitter_grammar_loader"
43
+ require "aidp/analysis/seams"
44
+ require "aidp/analysis/tree_sitter_scan"
45
+ require "aidp/analysis/kb_inspector"
46
+
41
47
  # Execute mode
42
48
  require "aidp/execute/steps"
43
49
  require "aidp/execute/runner"
@@ -0,0 +1,217 @@
1
+ # Tree-sitter Static Analysis Template
2
+
3
+ You are a **Tree-sitter Static Analysis Expert**, specializing in advanced static code analysis using Tree-sitter parsers. Your role is to analyze the codebase using Tree-sitter-powered static analysis, build a comprehensive knowledge base, and provide insights based on Michael Feathers' "Working Effectively with Legacy Code" strategies.
4
+
5
+ ## Your Expertise
6
+
7
+ - Tree-sitter parser technology and AST analysis
8
+ - Static code analysis and metrics calculation
9
+ - Legacy code refactoring strategies (Feathers' techniques)
10
+ - Seam detection and dependency analysis
11
+ - Code complexity and hotspot identification
12
+ - Test coverage analysis and characterization test recommendations
13
+
14
+ ## Analysis Objectives
15
+
16
+ 1. **Knowledge Base Construction**: Build a comprehensive machine-readable knowledge base of the codebase structure
17
+ 2. **Seam Detection**: Identify integration points and dependency injection opportunities using Feathers' strategies
18
+ 3. **Hotspot Analysis**: Identify high-change, high-complexity areas that need attention
19
+ 4. **Dependency Mapping**: Map import/require relationships and detect cycles
20
+ 5. **Test Gap Analysis**: Identify untested public APIs and recommend characterization tests
21
+ 6. **Refactoring Opportunities**: Provide specific, actionable refactoring recommendations
22
+
23
+ ## Required Analysis Steps
24
+
25
+ ### 1. Tree-sitter Knowledge Base Generation
26
+
27
+ Run the Tree-sitter analysis to generate the knowledge base:
28
+
29
+ ```bash
30
+ aidp analyze code --langs ruby,js,ts,py --threads 4
31
+ ```
32
+
33
+ This will generate the following KB files in `.aidp/kb/`:
34
+
35
+ - `symbols.json` - Classes, modules, methods with metadata
36
+ - `imports.json` - Require/import statements and dependencies
37
+ - `calls.json` - Method call relationships
38
+ - `metrics.json` - Complexity and size metrics
39
+ - `seams.json` - Integration points and dependency injection opportunities
40
+ - `hotspots.json` - High-change, high-complexity areas
41
+ - `tests.json` - Test coverage mapping
42
+ - `cycles.json` - Import/dependency cycles
43
+
44
+ ### 2. Seam Analysis and Feathers' Strategy Application
45
+
46
+ Analyze the seams data to identify refactoring opportunities:
47
+
48
+ #### I/O Integration Seams
49
+
50
+ - **File Operations**: `File.*`, `IO.*`, `Dir.*` calls
51
+ - **Network Operations**: `Net::HTTP.*`, `Socket.*` calls
52
+ - **System Operations**: `Kernel.system`, `Process.*` calls
53
+ - **Database Operations**: `ActiveRecord.*`, `Sequel.*` calls
54
+
55
+ **Feathers' Recommendations**:
56
+
57
+ - Extract I/O operations to separate service classes
58
+ - Use dependency injection for external dependencies
59
+ - Create adapter interfaces for external services
60
+
61
+ #### Global State and Singleton Seams
62
+
63
+ - **Global Variables**: `$var`, `@@var` usage
64
+ - **Singleton Patterns**: `include Singleton`, `extend Singleton`
65
+ - **Module-level State**: Mutable state in modules
66
+
67
+ **Feathers' Recommendations**:
68
+
69
+ - Replace singletons with dependency injection
70
+ - Encapsulate global state in configuration objects
71
+ - Use constructor injection for dependencies
72
+
73
+ #### Constructor with Work Seams
74
+
75
+ - **Complex Initialization**: Constructors with significant logic
76
+ - **External Dependencies**: I/O or service calls in constructors
77
+ - **High Complexity**: Constructors with multiple branches
78
+
79
+ **Feathers' Recommendations**:
80
+
81
+ - Extract initialization logic to factory methods
82
+ - Use builder pattern for complex object creation
83
+ - Separate construction from initialization
84
+
85
+ ### 3. Hotspot Analysis and Prioritization
86
+
87
+ Analyze the hotspots data to prioritize refactoring efforts:
88
+
89
+ #### Hotspot Scoring
90
+
91
+ - **Change Frequency**: Number of times files have been modified
92
+ - **Complexity**: Cyclomatic complexity and nesting depth
93
+ - **Size**: Lines of code and method count
94
+ - **Dependencies**: Fan-in and fan-out metrics
95
+
96
+ #### Top 20 Hotspots Analysis
97
+
98
+ For each hotspot, provide:
99
+
100
+ - **Rationale**: Why this area is a hotspot
101
+ - **Risk Assessment**: Potential impact of changes
102
+ - **Refactoring Strategy**: Specific Feathers' techniques to apply
103
+ - **Test Strategy**: Characterization test recommendations
104
+
105
+ ### 4. Dependency Cycle Detection
106
+
107
+ Analyze import cycles and provide breaking strategies:
108
+
109
+ #### Cycle Types
110
+
111
+ - **Import Cycles**: Circular require/import dependencies
112
+ - **Call Cycles**: Circular method call dependencies
113
+ - **Inheritance Cycles**: Circular class inheritance
114
+
115
+ #### Breaking Strategies
116
+
117
+ - **Dependency Inversion**: Extract interfaces and invert dependencies
118
+ - **Event-Driven Architecture**: Use events to decouple components
119
+ - **Facade Pattern**: Create facades to break direct dependencies
120
+
121
+ ### 5. Test Coverage Analysis
122
+
123
+ Analyze untested public APIs and recommend characterization tests:
124
+
125
+ #### Characterization Test Strategy
126
+
127
+ - **Public API Mapping**: Identify all public methods and classes
128
+ - **Test Coverage**: Map existing tests to public APIs
129
+ - **Gap Analysis**: Identify untested public APIs
130
+ - **Test Recommendations**: Suggest specific characterization tests
131
+
132
+ #### Test Implementation Guidelines
133
+
134
+ - **Golden Master Tests**: Capture current behavior before refactoring
135
+ - **Parameterized Tests**: Test with various inputs
136
+ - **Integration Tests**: Test with real dependencies
137
+ - **Mock Tests**: Test with controlled dependencies
138
+
139
+ ## Output Requirements
140
+
141
+ ### 1. Knowledge Base Summary
142
+
143
+ - Total files analyzed
144
+ - Symbol counts by type (classes, modules, methods)
145
+ - Import/dependency statistics
146
+ - Complexity metrics summary
147
+
148
+ ### 2. Seam Analysis Report
149
+
150
+ - **I/O Integration Seams**: List with file locations and refactoring suggestions
151
+ - **Global State Seams**: List with specific global usage and encapsulation strategies
152
+ - **Constructor Work Seams**: List with complexity metrics and extraction recommendations
153
+
154
+ ### 3. Hotspot Analysis Report
155
+
156
+ - **Top 20 Hotspots**: Ranked list with scores and rationale
157
+ - **Refactoring Priorities**: Recommended order for addressing hotspots
158
+ - **Risk Assessment**: Impact analysis for each hotspot
159
+
160
+ ### 4. Dependency Analysis Report
161
+
162
+ - **Import Graph**: Visualization of file dependencies
163
+ - **Cycle Detection**: List of detected cycles with breaking strategies
164
+ - **Coupling Analysis**: High-coupling areas and decoupling recommendations
165
+
166
+ ### 5. Test Strategy Report
167
+
168
+ - **Untested APIs**: List of public APIs without tests
169
+ - **Characterization Test Plan**: Specific test recommendations
170
+ - **Test Implementation Guide**: Step-by-step test creation process
171
+
172
+ ### 6. Refactoring Roadmap
173
+
174
+ - **Phase 1**: Address highest-priority seams and hotspots
175
+ - **Phase 2**: Break dependency cycles
176
+ - **Phase 3**: Implement characterization tests
177
+ - **Phase 4**: Apply systematic refactoring techniques
178
+
179
+ ## Technical Implementation Notes
180
+
181
+ ### Tree-sitter Integration
182
+
183
+ - Use `aidp analyze code` command to generate KB
184
+ - Leverage `aidp kb show` commands for data inspection
185
+ - Generate graphs with `aidp kb graph` for visualization
186
+
187
+ ### Feathers' Techniques Application
188
+
189
+ - **Sprout Method**: Extract small methods from large ones
190
+ - **Sprout Class**: Extract new classes for specific responsibilities
191
+ - **Extract Interface**: Create interfaces for dependency injection
192
+ - **Move Method**: Move methods to appropriate classes
193
+ - **Extract Method**: Break down large methods
194
+
195
+ ### Quality Metrics
196
+
197
+ - **Cyclomatic Complexity**: Target < 10 per method
198
+ - **Lines of Code**: Target < 20 per method
199
+ - **Fan-out**: Target < 7 per method
200
+ - **Nesting Depth**: Target < 4 levels
201
+
202
+ ## Success Criteria
203
+
204
+ 1. **Complete KB Generation**: All source files parsed and analyzed
205
+ 2. **Seam Identification**: All integration points identified with specific recommendations
206
+ 3. **Hotspot Prioritization**: Top 20 hotspots identified with actionable strategies
207
+ 4. **Cycle Detection**: All dependency cycles identified with breaking strategies
208
+ 5. **Test Gap Analysis**: All untested public APIs identified with test recommendations
209
+ 6. **Refactoring Roadmap**: Prioritized, actionable refactoring plan provided
210
+
211
+ ## Deliverables
212
+
213
+ 1. **Knowledge Base Files**: Complete `.aidp/kb/` directory with all JSON files
214
+ 2. **Analysis Report**: Comprehensive markdown report with all findings
215
+ 3. **Visualization Files**: Graph files for dependency visualization
216
+ 4. **Refactoring Plan**: Detailed, prioritized refactoring roadmap
217
+ 5. **Test Strategy**: Specific characterization test recommendations
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aidp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bart Agapinan
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: colorize
@@ -219,6 +219,20 @@ dependencies:
219
219
  - - "~>"
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0.12'
222
+ - !ruby/object:Gem::Dependency
223
+ name: ruby_tree_sitter
224
+ requirement: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - "~>"
227
+ - !ruby/object:Gem::Version
228
+ version: '2.0'
229
+ type: :runtime
230
+ prerelease: false
231
+ version_requirements: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - "~>"
234
+ - !ruby/object:Gem::Version
235
+ version: '2.0'
222
236
  description: The AI-Dev-Pipeline (AIDP) CLI provides a powerful, markdown-driven workflow
223
237
  for software development. It supports in-depth project analysis to understand existing
224
238
  codebases and an execution mode to systematically implement new features.
@@ -233,6 +247,10 @@ files:
233
247
  - README.md
234
248
  - bin/aidp
235
249
  - lib/aidp.rb
250
+ - lib/aidp/analysis/kb_inspector.rb
251
+ - lib/aidp/analysis/seams.rb
252
+ - lib/aidp/analysis/tree_sitter_grammar_loader.rb
253
+ - lib/aidp/analysis/tree_sitter_scan.rb
236
254
  - lib/aidp/analyze/agent_personas.rb
237
255
  - lib/aidp/analyze/agent_tool_executor.rb
238
256
  - lib/aidp/analyze/data_retention_manager.rb
@@ -269,7 +287,6 @@ files:
269
287
  - lib/aidp/database/pg_adapter.rb
270
288
  - lib/aidp/database_config.rb
271
289
  - lib/aidp/database_connection.rb
272
- - lib/aidp/database_migration.rb
273
290
  - lib/aidp/execute/progress.rb
274
291
  - lib/aidp/execute/runner.rb
275
292
  - lib/aidp/execute/steps.rb
@@ -296,6 +313,7 @@ files:
296
313
  - templates/ANALYZE/04_FUNCTIONALITY_ANALYSIS.md
297
314
  - templates/ANALYZE/05_DOCUMENTATION_ANALYSIS.md
298
315
  - templates/ANALYZE/06_STATIC_ANALYSIS.md
316
+ - templates/ANALYZE/06a_tree_sitter_scan.md
299
317
  - templates/ANALYZE/07_REFACTORING_RECOMMENDATIONS.md
300
318
  - templates/COMMON/AGENT_BASE.md
301
319
  - templates/COMMON/CONVENTIONS.md
@@ -339,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
339
357
  - !ruby/object:Gem::Version
340
358
  version: '0'
341
359
  requirements: []
342
- rubygems_version: 3.6.2
360
+ rubygems_version: 3.6.9
343
361
  specification_version: 4
344
362
  summary: A CLI for AI-driven software development, from analysis to execution.
345
363
  test_files: []
@@ -1,158 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sqlite3"
4
- require "fileutils"
5
-
6
- module Aidp
7
- # Handles database migrations for AIDP
8
- class DatabaseMigration
9
- def initialize(project_dir = Dir.pwd)
10
- @project_dir = project_dir
11
- @old_db_path = File.join(project_dir, ".aidp-analysis.db")
12
- @new_db_path = File.join(project_dir, ".aidp.db")
13
- end
14
-
15
- # Migrate database from old to new format
16
- def migrate
17
- # If neither database exists, create new one directly
18
- if !File.exist?(@old_db_path) && !File.exist?(@new_db_path)
19
- create_new_database
20
- return true
21
- end
22
-
23
- # If new database already exists, skip migration
24
- if File.exist?(@new_db_path)
25
- puts "Database .aidp.db already exists, skipping migration"
26
- return false
27
- end
28
-
29
- # Rename old database to new name
30
- FileUtils.mv(@old_db_path, @new_db_path)
31
-
32
- # Open database connection
33
- db = SQLite3::Database.new(@new_db_path)
34
-
35
- # Create new tables for job management
36
- create_job_tables(db)
37
-
38
- # Close connection
39
- db.close
40
-
41
- true
42
- rescue => e
43
- puts "Error during database migration: #{e.message}"
44
- # Try to restore old database if something went wrong
45
- if File.exist?(@new_db_path) && !File.exist?(@old_db_path)
46
- FileUtils.mv(@new_db_path, @old_db_path)
47
- end
48
- false
49
- end
50
-
51
- private
52
-
53
- def create_new_database
54
- db = SQLite3::Database.new(@new_db_path)
55
-
56
- # Create original tables
57
- create_original_tables(db)
58
-
59
- # Create new job tables
60
- create_job_tables(db)
61
-
62
- db.close
63
- end
64
-
65
- def create_original_tables(db)
66
- # Create analysis_results table
67
- db.execute(<<~SQL)
68
- CREATE TABLE analysis_results (
69
- step_name TEXT PRIMARY KEY,
70
- data TEXT NOT NULL,
71
- metadata TEXT,
72
- created_at TEXT NOT NULL,
73
- updated_at TEXT NOT NULL
74
- )
75
- SQL
76
-
77
- # Create analysis_metrics table
78
- db.execute(<<~SQL)
79
- CREATE TABLE analysis_metrics (
80
- id INTEGER PRIMARY KEY AUTOINCREMENT,
81
- step_name TEXT NOT NULL,
82
- metric_name TEXT NOT NULL,
83
- value TEXT NOT NULL,
84
- recorded_at TEXT NOT NULL,
85
- UNIQUE(step_name, metric_name, recorded_at)
86
- )
87
- SQL
88
-
89
- # Create embeddings table
90
- db.execute(<<~SQL)
91
- CREATE TABLE embeddings (
92
- step_name TEXT PRIMARY KEY,
93
- embeddings_data TEXT NOT NULL,
94
- created_at TEXT NOT NULL
95
- )
96
- SQL
97
-
98
- # Create indexes
99
- db.execute("CREATE INDEX idx_analysis_metrics_step_name ON analysis_metrics(step_name)")
100
- db.execute("CREATE INDEX idx_analysis_metrics_recorded_at ON analysis_metrics(recorded_at)")
101
- db.execute("CREATE INDEX idx_analysis_results_updated_at ON analysis_results(updated_at)")
102
- end
103
-
104
- def create_job_tables(db)
105
- # Create jobs table
106
- db.execute(<<~SQL)
107
- CREATE TABLE jobs (
108
- id INTEGER PRIMARY KEY,
109
- job_type TEXT NOT NULL,
110
- provider TEXT NOT NULL,
111
- status TEXT NOT NULL,
112
- created_at INTEGER NOT NULL,
113
- started_at INTEGER,
114
- completed_at INTEGER,
115
- error TEXT,
116
- metadata TEXT
117
- )
118
- SQL
119
-
120
- # Create job_executions table
121
- db.execute(<<~SQL)
122
- CREATE TABLE job_executions (
123
- id INTEGER PRIMARY KEY,
124
- job_id INTEGER NOT NULL,
125
- attempt INTEGER NOT NULL,
126
- status TEXT NOT NULL,
127
- started_at INTEGER NOT NULL,
128
- completed_at INTEGER,
129
- error TEXT,
130
- FOREIGN KEY (job_id) REFERENCES jobs(id)
131
- )
132
- SQL
133
-
134
- # Create job_logs table
135
- db.execute(<<~SQL)
136
- CREATE TABLE job_logs (
137
- id INTEGER PRIMARY KEY,
138
- job_id INTEGER NOT NULL,
139
- execution_id INTEGER NOT NULL,
140
- timestamp INTEGER NOT NULL,
141
- message TEXT NOT NULL,
142
- level TEXT NOT NULL,
143
- metadata TEXT,
144
- FOREIGN KEY (job_id) REFERENCES jobs(id),
145
- FOREIGN KEY (execution_id) REFERENCES job_executions(id)
146
- )
147
- SQL
148
-
149
- # Create indexes for job tables
150
- db.execute("CREATE INDEX idx_jobs_status ON jobs(status)")
151
- db.execute("CREATE INDEX idx_jobs_provider ON jobs(provider)")
152
- db.execute("CREATE INDEX idx_job_executions_job_id ON job_executions(job_id)")
153
- db.execute("CREATE INDEX idx_job_logs_job_id ON job_logs(job_id)")
154
- db.execute("CREATE INDEX idx_job_logs_execution_id ON job_logs(execution_id)")
155
- db.execute("CREATE INDEX idx_job_logs_timestamp ON job_logs(timestamp)")
156
- end
157
- end
158
- end