@itz4blitz/agentful 0.1.10 → 0.1.11

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.
@@ -17,6 +17,7 @@ You are the **Product Analyzer Agent**. You analyze product specifications for q
17
17
  - Identify warnings that SHOULD be addressed
18
18
  - Calculate readiness score (0-100%)
19
19
  - Output structured analysis to `.agentful/product-analysis.json`
20
+ - **NEW**: Reverse-engineer product specs from existing codebases using domain detection
20
21
 
21
22
  ## Core Principles
22
23
 
@@ -63,6 +64,101 @@ else:
63
64
  error("No product specification found")
64
65
  ```
65
66
 
67
+ ## Reverse Engineering from Codebase
68
+
69
+ When operating in **REVERSE_ENGINEER mode** (invoked by `/agentful-product` when no spec exists but code does):
70
+
71
+ ### Step 1: Read Architecture Analysis
72
+
73
+ ```bash
74
+ # Check if architecture.json exists from npx @itz4blitz/agentful init
75
+ architecture_exists = exists(".agentful/architecture.json")
76
+
77
+ if architecture_exists:
78
+ architecture = Read(".agentful/architecture.json")
79
+ else:
80
+ # No pre-analysis available, manual scan needed
81
+ error("Run 'npx @itz4blitz/agentful init' first to analyze codebase")
82
+ ```
83
+
84
+ ### Step 2: Display Domain Detection Results
85
+
86
+ Use the domain detection data from `architecture.json`:
87
+
88
+ ```javascript
89
+ {
90
+ "domains": ["authentication", "user-management", "api-management", "database"],
91
+ "domainConfidence": {
92
+ "authentication": 0.82,
93
+ "user-management": 0.87,
94
+ "api-management": 0.65,
95
+ "database": 0.81
96
+ },
97
+ "patterns": {
98
+ "imports": [...],
99
+ "exports": [...],
100
+ "styling": ["tailwind"],
101
+ "stateManagement": ["react-hooks"],
102
+ "apiPatterns": ["express-routes"],
103
+ "testingFrameworks": ["jest"]
104
+ },
105
+ "tech_stack": {
106
+ "framework": "Next.js",
107
+ "language": "TypeScript",
108
+ "database": "PostgreSQL",
109
+ "orm": "Prisma"
110
+ }
111
+ }
112
+ ```
113
+
114
+ ### Step 3: Scan Code for Features Within Domains
115
+
116
+ For each detected domain, use **Glob and Read** to find related files and infer features:
117
+
118
+ ```bash
119
+ # Example: Scanning authentication domain
120
+ auth_files = Glob("src/**/auth/**/*.ts") OR Glob("src/**/authentication/**/*.ts")
121
+
122
+ for file in auth_files:
123
+ content = Read(file)
124
+ # Look for:
125
+ # - Function/class names (e.g., handleLogin, PasswordResetService)
126
+ # - Exported APIs (e.g., POST /auth/login)
127
+ # - Route definitions
128
+ # - Database schemas related to auth
129
+ ```
130
+
131
+ **Feature detection heuristics:**
132
+
133
+ - File named `login.ts` or contains `handleLogin` → "Login & Logout" feature
134
+ - File named `password.ts` or contains `resetPassword` → "Password Reset" feature
135
+ - File contains `createUser`, `updateUser` → "User CRUD" feature
136
+ - Prisma schema with `User` model → "User Management" feature
137
+ - Routes like `/api/users/:id` → "User API" feature
138
+
139
+ ### Step 4: Generate Product Spec with Confidence Levels
140
+
141
+ Create `.claude/product/index.md` with:
142
+
143
+ 1. **Tech stack section** - From `architecture.json`
144
+ 2. **Domains section** - One section per domain
145
+ 3. **Features per domain** - Inferred from code scanning
146
+ 4. **Acceptance criteria** - Generic/inferred based on feature type
147
+ 5. **Confidence level** - Show for each domain
148
+ 6. **Note at top** - "Reverse-engineered from codebase, review and refine"
149
+
150
+ ### Step 5: Optionally Create Hierarchical Structure
151
+
152
+ If confidence > 70% for a domain, create:
153
+
154
+ ```
155
+ .claude/product/domains/{domain}/
156
+ ├── index.md # Domain overview
157
+ └── features/
158
+ ├── feature1.md # Per-feature file
159
+ └── feature2.md
160
+ ```
161
+
66
162
  ## Quality Dimensions
67
163
 
68
164
  ### 1. Completeness Analysis
@@ -11,7 +11,7 @@ This command intelligently handles all product planning scenarios with auto-dete
11
11
 
12
12
  The command detects the current state and acts accordingly:
13
13
 
14
- 1. **No product spec exists** → Interactive init mode
14
+ 1. **No product spec exists** → Check if codebase exists to reverse-engineer, else interactive init
15
15
  2. **Product spec exists, never analyzed** → Run analysis
16
16
  3. **Analysis exists with unresolved blocking issues** → Refinement mode
17
17
  4. **Analysis exists, ready** → Show status report
@@ -32,9 +32,15 @@ if user_text:
32
32
  product_spec_exists = exists(".claude/product/index.md") OR exists("PRODUCT.md")
33
33
 
34
34
  if !product_spec_exists:
35
- # No product spec found
36
- mode = "INIT"
37
- goto INIT_MODE
35
+ # No product spec found - check if we can reverse-engineer from code
36
+ has_substantial_codebase = check_codebase_exists()
37
+
38
+ if has_substantial_codebase:
39
+ mode = "REVERSE_ENGINEER"
40
+ goto REVERSE_ENGINEER_MODE
41
+ else:
42
+ mode = "INIT"
43
+ goto INIT_MODE
38
44
 
39
45
  # Step 3: Check if analysis exists
40
46
  analysis_exists = exists(".claude/product/product-analysis.json")
@@ -60,9 +66,238 @@ goto STATUS_MODE
60
66
 
61
67
  ---
62
68
 
69
+ ## Mode 0: REVERSE_ENGINEER (Codebase Analysis)
70
+
71
+ When no product spec exists but substantial codebase detected, offer to reverse-engineer the product spec from existing code.
72
+
73
+ ### Detection Criteria
74
+
75
+ A "substantial codebase" is detected when:
76
+ - Project has source directories (src/, app/, lib/, etc.)
77
+ - Contains actual implementation files (not just config)
78
+ - Has at least 10+ code files
79
+ - Not an empty project
80
+
81
+ ### Process
82
+
83
+ ```
84
+ 🔍 Analyzing Existing Codebase
85
+
86
+ I detected an existing codebase without a product specification.
87
+
88
+ Would you like me to:
89
+
90
+ [A] Analyze your codebase and generate a product spec
91
+ I'll scan your code to detect domains, features, and tech stack,
92
+ then create a product specification based on what exists.
93
+
94
+ [B] Create product spec from scratch (ignore existing code)
95
+ Walk through interactive Q&A to define your product manually.
96
+
97
+ Your choice: > _______________________________
98
+ ```
99
+
100
+ **If user chooses [A]:**
101
+
102
+ ```
103
+ 🔍 Scanning codebase to detect domains and features...
104
+
105
+ Reading project structure...
106
+ Analyzing tech stack...
107
+ Detecting domains from code organization...
108
+ Identifying features and capabilities...
109
+ ```
110
+
111
+ **Use the project analyzer** to scan the codebase:
112
+
113
+ ```bash
114
+ # Read architecture.json if exists from init, otherwise run analysis
115
+ architecture = Read(".agentful/architecture.json") OR analyzeProject()
116
+
117
+ # Show detected domains with confidence
118
+ ```
119
+
120
+ **Display results:**
121
+
122
+ ```
123
+ 📊 Detected Domains & Features
124
+
125
+ Based on your codebase structure and code analysis:
126
+
127
+ Domains detected:
128
+
129
+ • authentication ████████░░ 82%
130
+ Features found:
131
+ - JWT token generation (src/auth/jwt.ts)
132
+ - Login/logout endpoints (src/auth/routes.ts)
133
+ - Password reset flow (src/auth/password.ts)
134
+
135
+ • user-management █████████░ 87%
136
+ Features found:
137
+ - User CRUD operations (src/users/service.ts)
138
+ - Profile management (src/users/profile.ts)
139
+ - Role-based permissions (src/users/roles.ts)
140
+
141
+ • api-management ██████░░░░ 65%
142
+ Features found:
143
+ - REST endpoints (src/api/routes/)
144
+ - Request validation (src/api/middleware/)
145
+ - Error handling (src/api/errors.ts)
146
+
147
+ • database ████████░░ 81%
148
+ Features found:
149
+ - Prisma schema (prisma/schema.prisma)
150
+ - Migration system (prisma/migrations/)
151
+ - Database client (src/lib/db.ts)
152
+
153
+ ────────────────────────────────────────────────────────
154
+
155
+ Tech Stack detected:
156
+ Language: TypeScript
157
+ Framework: Next.js 14
158
+ Database: PostgreSQL with Prisma
159
+ Auth: JWT tokens
160
+ Testing: Jest + Playwright
161
+
162
+ ────────────────────────────────────────────────────────
163
+
164
+ I'll now generate a product specification based on this analysis.
165
+ This will create .claude/product/index.md with:
166
+ - Detected domains organized hierarchically
167
+ - Features extracted from your code
168
+ - Tech stack specifications
169
+ - Inferred acceptance criteria
170
+
171
+ You can refine the generated spec afterward.
172
+
173
+ Generate product spec? (y/n): > _______________________________
174
+ ```
175
+
176
+ **If yes:**
177
+
178
+ 1. Generate `.claude/product/index.md` with hierarchical structure:
179
+
180
+ ```markdown
181
+ # Product Specification
182
+
183
+ > **Note**: This specification was reverse-engineered from existing codebase.
184
+ > Review and refine as needed.
185
+
186
+ ## Overview
187
+
188
+ [Inferred from package.json description or README if available]
189
+
190
+ ## Tech Stack
191
+
192
+ ### Frontend
193
+ - **Framework**: Next.js 14
194
+ - **Language**: TypeScript
195
+ - **Styling**: [Detected: Tailwind CSS]
196
+ - **State Management**: [Detected: React Context]
197
+
198
+ ### Backend
199
+ - **Runtime**: Node.js
200
+ - **Framework**: Next.js API Routes
201
+ - **Language**: TypeScript
202
+
203
+ ### Database
204
+ - **Database**: PostgreSQL
205
+ - **ORM**: Prisma
206
+
207
+ ### Authentication
208
+ - **Method**: JWT tokens
209
+
210
+ ### Testing
211
+ - **Unit**: Jest
212
+ - **E2E**: Playwright
213
+
214
+ ## Domains
215
+
216
+ ### 1. Authentication (CRITICAL) - 82% confidence
217
+
218
+ **Features detected:**
219
+
220
+ #### Login & Logout
221
+ **Status**: Implemented
222
+ **Location**: `src/auth/routes.ts`, `src/auth/jwt.ts`
223
+
224
+ **Acceptance Criteria** (inferred):
225
+ - [ ] User can login with email/password
226
+ - [ ] JWT token generated on successful login
227
+ - [ ] Token includes user ID and roles
228
+ - [ ] Logout invalidates current session
229
+
230
+ #### Password Reset
231
+ **Status**: Implemented
232
+ **Location**: `src/auth/password.ts`
233
+
234
+ **Acceptance Criteria** (inferred):
235
+ - [ ] User can request password reset via email
236
+ - [ ] Reset link expires after 24 hours
237
+ - [ ] User can set new password with reset token
238
+
239
+ ---
240
+
241
+ ### 2. User Management (HIGH) - 87% confidence
242
+
243
+ **Features detected:**
244
+
245
+ #### User CRUD Operations
246
+ **Status**: Implemented
247
+ **Location**: `src/users/service.ts`
248
+
249
+ **Acceptance Criteria** (inferred):
250
+ - [ ] Create new users
251
+ - [ ] Read user profiles
252
+ - [ ] Update user information
253
+ - [ ] Delete user accounts
254
+
255
+ #### Profile Management
256
+ **Status**: Implemented
257
+ **Location**: `src/users/profile.ts`
258
+
259
+ **Acceptance Criteria** (inferred):
260
+ - [ ] Users can view their profile
261
+ - [ ] Users can edit profile fields
262
+ - [ ] Avatar upload supported
263
+ - [ ] Changes validated and saved
264
+
265
+ ---
266
+
267
+ [Continue for each domain...]
268
+ ```
269
+
270
+ 2. Create `.claude/product/domains/` structure if confidence > 70%:
271
+
272
+ ```
273
+ .claude/product/
274
+ ├── index.md
275
+ └── domains/
276
+ ├── authentication/
277
+ │ ├── index.md
278
+ │ └── features/
279
+ │ ├── login.md
280
+ │ └── password-reset.md
281
+ ├── user-management/
282
+ │ └── features/
283
+ │ ├── crud.md
284
+ │ └── profile.md
285
+ └── api-management/
286
+ └── features/
287
+ └── rest-endpoints.md
288
+ ```
289
+
290
+ 3. Immediately run ANALYSIS mode on the generated spec
291
+
292
+ **If user chooses [B]:**
293
+
294
+ Fall through to INIT mode (interactive Q&A)
295
+
296
+ ---
297
+
63
298
  ## Mode 1: INIT (Interactive Initialization)
64
299
 
65
- When no product spec exists, guide the user through creation.
300
+ When no product spec exists and no substantial codebase detected, guide the user through creation.
66
301
 
67
302
  ### Process
68
303
 
@@ -746,12 +981,46 @@ Since the product-analyzer agent doesn't exist as a file, the Task tool will use
746
981
 
747
982
  ## Example Flows
748
983
 
749
- ### Flow 1: New User, Empty Project
984
+ ### Flow 1: Reverse Engineer from Production Codebase
985
+
986
+ ```
987
+ User: /agentful-product
988
+ [Has production codebase, no product spec]
989
+
990
+ Command: [Detects no product spec exists]
991
+ [Detects substantial codebase]
992
+ [Enters REVERSE_ENGINEER mode]
993
+ [Offers: analyze codebase or manual init]
994
+
995
+ User: [Chooses option A - analyze codebase]
996
+
997
+ Command: [Reads .agentful/architecture.json]
998
+ [Shows detected domains with confidence bars]
999
+ [Shows detected tech stack]
1000
+ [Lists features found per domain]
1001
+ [Asks: Generate product spec?]
1002
+
1003
+ User: [Confirms yes]
1004
+
1005
+ Command: [Generates .claude/product/index.md]
1006
+ [Creates hierarchical structure for high-confidence domains]
1007
+ [Runs ANALYSIS mode on generated spec]
1008
+ [Shows readiness score]
1009
+
1010
+ User: /agentful-product
1011
+ [If blocking issues exist]
1012
+
1013
+ Command: [Enters REFINEMENT mode]
1014
+ [Walks through each issue]
1015
+ ```
1016
+
1017
+ ### Flow 2: New User, Empty Project
750
1018
 
751
1019
  ```
752
1020
  User: /agentful-product
753
1021
 
754
1022
  Command: [Detects no product spec exists]
1023
+ [Detects no substantial codebase]
755
1024
  [Enters INIT mode]
756
1025
 
757
1026
  Command: "📋 Product Specification Setup..."
@@ -779,7 +1048,7 @@ Command: [Updates product spec]
779
1048
  [Suggests running /agentful-start]
780
1049
  ```
781
1050
 
782
- ### Flow 2: Existing Product Spec, Never Analyzed
1051
+ ### Flow 3: Existing Product Spec, Never Analyzed
783
1052
 
784
1053
  ```
785
1054
  User: /agentful-product
@@ -791,7 +1060,7 @@ Command: [Detects product spec exists]
791
1060
  [Shows readiness score and issues]
792
1061
  ```
793
1062
 
794
- ### Flow 3: Ready Product, Status Check
1063
+ ### Flow 4: Ready Product, Status Check
795
1064
 
796
1065
  ```
797
1066
  User: /agentful-product
@@ -803,7 +1072,7 @@ Command: [Detects product spec exists]
803
1072
  [Shows readiness score, warnings, next steps]
804
1073
  ```
805
1074
 
806
- ### Flow 4: User Has Question
1075
+ ### Flow 5: User Has Question
807
1076
 
808
1077
  ```
809
1078
  User: /agentful-product "Should I use REST or GraphQL?"
@@ -319,6 +319,7 @@ It learns **your project's patterns** and generates agents that match your conve
319
319
  │ └─ Template creation │
320
320
  ├─────────────────────────────────────────────┤
321
321
  │ Slash Commands (Claude Code) │
322
+ │ ├─ /agentful-product (requirements) │
322
323
  │ ├─ /agentful-start (orchestrator) │
323
324
  │ ├─ /agentful-status (progress) │
324
325
  │ ├─ /agentful-validate (quality gates) │
package/README.md CHANGED
@@ -21,7 +21,24 @@ This command creates the necessary directory structure and configuration files i
21
21
 
22
22
  ### 1. Define Product Specification
23
23
 
24
- After initialization, edit your product specification file with features and requirements.
24
+ After initialization, define your product requirements:
25
+
26
+ #### Option A: Interactive Planning (Recommended)
27
+
28
+ ```bash
29
+ claude # Start Claude Code
30
+ ```
31
+
32
+ Use `/agentful-product` for guided product planning:
33
+ - **New projects**: Interactive Q&A creates your product spec
34
+ - **Existing specs**: Analyzes for gaps, ambiguities, blocking issues
35
+ - **Readiness scoring**: Get a score (0-100) before development
36
+ - **Issue resolution**: Walk through blocking issues with smart suggestions
37
+ - **Q&A mode**: Ask planning questions in context
38
+
39
+ #### Option B: Manual Creation
40
+
41
+ Create your specification manually:
25
42
 
26
43
  **Flat structure** (single file at project root):
27
44
  - `PRODUCT.md` - All features in one file
@@ -132,6 +149,7 @@ Runtime state is stored in `.agentful/`:
132
149
 
133
150
  | Command | Description |
134
151
  |---------|-------------|
152
+ | `/agentful-product` | Smart product planning: create, analyze, and refine requirements |
135
153
  | `/agentful-start` | Start or resume autonomous development |
136
154
  | `/agentful-status` | Display progress and current state |
137
155
  | `/agentful-validate` | Run all quality checks |
package/bin/cli.js CHANGED
@@ -339,79 +339,48 @@ ${analysis && analysis.domains.length > 0 ? analysis.domains.map((d, i) => `${i
339
339
  // Update .gitignore
340
340
  checkGitignore();
341
341
 
342
- // Perform smart project analysis (unless explicitly disabled)
342
+ // Perform essential project detection (unless explicitly disabled)
343
343
  if (smart) {
344
344
  console.log('');
345
- log(colors.bright, '🔍 Analyzing your project...');
345
+ log(colors.bright, '🔍 Detecting project essentials...');
346
346
  console.log('');
347
347
 
348
348
  try {
349
- const startTime = Date.now();
350
349
  analysis = await analyzeProject(targetDir);
351
350
  await exportToArchitectureJson(targetDir, analysis);
352
- const duration = ((Date.now() - startTime) / 1000).toFixed(1);
353
351
 
354
- // Show detected tech stack
352
+ // Show only essential info
355
353
  if (analysis.language && analysis.language !== 'unknown') {
356
354
  log(colors.cyan, ` Language: ${analysis.language}`);
357
- if (analysis.primaryLanguage && analysis.primaryLanguage !== analysis.language) {
358
- log(colors.dim, ` Primary: ${analysis.primaryLanguage}`);
359
- }
360
355
  }
361
356
 
362
357
  if (analysis.frameworks.length > 0) {
363
- log(colors.cyan, ` Frameworks: ${analysis.frameworks.join(', ')}`);
358
+ log(colors.cyan, ` Framework: ${analysis.frameworks[0]}`);
364
359
  }
365
360
 
366
361
  if (analysis.packageManager && analysis.packageManager !== 'unknown') {
367
362
  log(colors.cyan, ` Package Mgr: ${analysis.packageManager}`);
368
363
  }
369
364
 
370
- if (analysis.buildSystem && analysis.buildSystem !== 'unknown') {
371
- log(colors.cyan, ` Build: ${analysis.buildSystem}`);
372
- }
373
-
374
365
  console.log('');
366
+ log(colors.dim, ` ✓ Detection complete`);
375
367
 
376
- // Show detected domains
377
- if (analysis.domains.length > 0) {
378
- log(colors.bright, '📊 Detected domains:');
379
- console.log('');
380
-
381
- analysis.domains.slice(0, 5).forEach(domain => {
382
- const confidence = analysis.domainConfidence[domain] || 0.5;
383
- const confidenceBar = '█'.repeat(Math.round(confidence * 10)) + '░'.repeat(10 - Math.round(confidence * 10));
384
- const confidencePct = Math.round(confidence * 100);
385
-
386
- // Color code based on confidence
387
- let confidenceColor = colors.red;
388
- if (confidence >= 0.8) confidenceColor = colors.green;
389
- else if (confidence >= 0.5) confidenceColor = colors.yellow;
390
-
391
- log(confidenceColor, ` • ${domain.padEnd(20)} ${confidenceBar} ${confidencePct}%`);
392
- });
393
-
394
- if (analysis.domains.length > 5) {
395
- log(colors.dim, ` ... and ${analysis.domains.length - 5} more`);
396
- }
397
-
398
- console.log('');
399
- }
400
-
401
- log(colors.dim, ` Analysis completed in ${duration}s (${Math.round(analysis.confidence * 100)}% confidence)`);
402
-
403
- // Show warnings if any
368
+ // Show critical warnings only
404
369
  if (analysis.warnings && analysis.warnings.length > 0) {
405
- console.log('');
406
- log(colors.yellow, '⚠️ Warnings:');
407
- analysis.warnings.slice(0, 3).forEach(warning => {
408
- log(colors.dim, ` • ${warning}`);
409
- });
370
+ const criticalWarnings = analysis.warnings.filter(w =>
371
+ w.includes('empty') || w.includes('not detect')
372
+ );
373
+ if (criticalWarnings.length > 0) {
374
+ console.log('');
375
+ log(colors.yellow, '⚠️ Warnings:');
376
+ criticalWarnings.forEach(warning => {
377
+ log(colors.dim, ` • ${warning}`);
378
+ });
379
+ }
410
380
  }
411
381
 
412
382
  } catch (error) {
413
- log(colors.dim, ' ⊙ Smart analysis skipped (project may be empty or unsupported)');
414
- log(colors.dim, ` Error: ${error.message}`);
383
+ log(colors.dim, ' ⊙ Detection skipped (project may be empty)');
415
384
  analysis = null;
416
385
  }
417
386
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itz4blitz/agentful",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Autonomous product development kit for Claude Code with smart product analysis and natural conversation",
5
5
  "type": "module",
6
6
  "bin": {
package/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.1.10"
2
+ "version": "0.1.11"
3
3
  }