vralphy 0.2.0 → 0.3.1

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.
package/docs/DESIGN.md ADDED
@@ -0,0 +1,537 @@
1
+ # Design Principles
2
+
3
+ The architecture and design decisions behind vralphy.
4
+
5
+ ## Core Principles
6
+
7
+ ### 1. Separation of Concerns
8
+
9
+ vralphy cleanly separates three concerns:
10
+
11
+ **WHAT to build** (`specs/`)
12
+ - Feature specifications
13
+ - Requirements and acceptance criteria
14
+ - Written by humans
15
+
16
+ **HOW to build** (`.vralphy/AGENTS.md`)
17
+ - Operational commands (build, test, lint)
18
+ - Project-specific patterns
19
+ - Generated by AI, maintained by loop
20
+
21
+ **WHAT'S LEFT to build** (`IMPLEMENTATION_PLAN.md`)
22
+ - Prioritized task list
23
+ - Updated by AI during plan/build phases
24
+ - Living document
25
+
26
+ This separation enables autonomous operation while keeping humans in control of requirements.
27
+
28
+ ### 2. Non-Invasive Design
29
+
30
+ vralphy doesn't interfere with existing workflows:
31
+
32
+ **File locations**:
33
+ - All vralphy files in `.vralphy/` directory
34
+ - `.vralphy/AGENTS.md` for vralphy's operational guide
35
+ - Root `AGENTS.md` remains yours for Claude/OpenCode/Codex
36
+ - No collision with existing AI tooling
37
+
38
+ **Git-friendly**:
39
+ - `.vralphy/` can be committed or gitignored
40
+ - Plays nice with existing git workflows
41
+ - Creates clean, descriptive commits
42
+
43
+ ### 3. Engine Abstraction
44
+
45
+ Support multiple AI engines with unified interface:
46
+
47
+ ```typescript
48
+ interface Engine {
49
+ execute(prompt: string, options: ExecuteOptions): AsyncIterable<Chunk>;
50
+ isAvailable(): Promise<boolean>;
51
+ getFlags(options: EngineFlags): string[];
52
+ supportsInteractive(): boolean;
53
+ getCommand(): string;
54
+ }
55
+ ```
56
+
57
+ **Implementations**:
58
+ - `ClaudeEngine` - Anthropic's Claude CLI
59
+ - `OpenCodeEngine` - OpenAI's code assistant
60
+ - `CodexEngine` - Alternative AI engine
61
+
62
+ **Auto-detection**: vralphy detects installed engines at runtime
63
+
64
+ **Benefits**:
65
+ - Users choose their preferred AI provider
66
+ - Easy to add new engines
67
+ - Consistent experience across engines
68
+
69
+ ### 4. Model Tiering
70
+
71
+ Two-tier model system optimizes cost and performance:
72
+
73
+ **Tier 1: Primary/Thinking** (opus by default)
74
+ - **Purpose**: Complex reasoning, orchestration, decisions
75
+ - **Use cases**: Planning, debugging, architecture
76
+ - **Cost**: High, but needed for quality
77
+ - **When**: Strategic decisions, complex analysis
78
+
79
+ **Tier 2: Executor/Subagent** (sonnet by default)
80
+ - **Purpose**: Parallel tasks, file operations
81
+ - **Use cases**: Reading files, searching code, simple edits
82
+ - **Cost**: Low, optimized for volume
83
+ - **When**: Tactical execution, bulk operations
84
+
85
+ **Configurable**:
86
+ ```bash
87
+ vralphy --model opus --executor sonnet build
88
+ ```
89
+
90
+ **Why?**: Expensive models for thinking, cheap models for doing.
91
+
92
+ ### 5. Massive Parallelism
93
+
94
+ vralphy leverages parallel execution for performance:
95
+
96
+ **Planning Phase**:
97
+ ```
98
+ ┌─────────────────────────────────────┐
99
+ │ Read specs/* (250 parallel agents) │
100
+ ├─────────────────────────────────────┤
101
+ │ Search src/* (500 parallel agents) │
102
+ ├─────────────────────────────────────┤
103
+ │ Analyze (1 reasoning agent - opus) │
104
+ └─────────────────────────────────────┘
105
+ ```
106
+
107
+ **Build Phase**:
108
+ ```
109
+ ┌─────────────────────────────────────┐
110
+ │ Search codebase (500 parallel) │
111
+ ├─────────────────────────────────────┤
112
+ │ Write code (1 agent) │
113
+ ├─────────────────────────────────────┤
114
+ │ Run tests (1 sequential agent) │
115
+ ├─────────────────────────────────────┤
116
+ │ Reasoning (1 agent - opus) │
117
+ └─────────────────────────────────────┘
118
+ ```
119
+
120
+ **Why parallel?**:
121
+ - Reading files: IO-bound, parallelizes well
122
+ - Building/testing: Must be sequential
123
+ - Reasoning: Requires focused attention
124
+
125
+ ### 6. Context Efficiency
126
+
127
+ Keep prompts lean to maximize token usage:
128
+
129
+ **Operational guide** (`.vralphy/AGENTS.md`):
130
+ - Max 60 lines
131
+ - Commands only, no explanations
132
+ - No changelogs or history
133
+ - Generated once, maintained minimally
134
+
135
+ **Lazy skill/agent loading**:
136
+ - Skills stored in engine-native locations
137
+ - Loaded on-demand when needed
138
+ - Not injected into every prompt
139
+ - Trigger-based discovery
140
+
141
+ **Prompt templates**:
142
+ - Stored in `.vralphy/prompts/`
143
+ - Customizable per project
144
+ - Interpolated with context variables
145
+
146
+ **Why?**: Tokens are expensive. Load only what you need.
147
+
148
+ ### 7. Specification-Driven Development
149
+
150
+ Specifications are the source of truth:
151
+
152
+ **Specs define**:
153
+ - What features exist
154
+ - Expected behavior
155
+ - Acceptance criteria
156
+ - Edge cases
157
+ - Dependencies
158
+
159
+ **AI uses specs to**:
160
+ - Understand requirements
161
+ - Plan implementation
162
+ - Verify completeness
163
+ - Generate tests
164
+
165
+ **Flow**:
166
+ ```
167
+ Spec → Plan → Code → Tests → Verify against spec
168
+ ```
169
+
170
+ **Benefits**:
171
+ - Clear requirements
172
+ - Testable outcomes
173
+ - Traceable decisions
174
+ - Team alignment
175
+
176
+ ### 8. Incremental Progress
177
+
178
+ Small, focused changes:
179
+
180
+ **Commits**:
181
+ - One feature/fix per commit
182
+ - Descriptive messages
183
+ - Atomic changes
184
+ - Frequent pushes
185
+
186
+ **Iterations**:
187
+ - Plan in small batches (3-5 iterations)
188
+ - Build in small batches (10-20 iterations)
189
+ - Test after each change
190
+ - Update plan frequently
191
+
192
+ **Why?**: Easier to review, debug, and rollback.
193
+
194
+ ### 9. Test-Driven Autonomy
195
+
196
+ Tests gate progress:
197
+
198
+ **Build phase logic**:
199
+ ```
200
+ Implement feature
201
+
202
+ Run tests
203
+
204
+ Tests pass? → Commit + Push → Update plan → Next task
205
+
206
+ Tests fail? → Debug → Run tests again
207
+ ```
208
+
209
+ **Safety**:
210
+ - Never commit failing tests
211
+ - Debug failures automatically
212
+ - Update `.vralphy/AGENTS.md` if test command changes
213
+
214
+ **Benefits**:
215
+ - High confidence in changes
216
+ - Catches regressions early
217
+ - Documents expected behavior
218
+
219
+ ### 10. Fail-Safe Design
220
+
221
+ vralphy handles failures gracefully:
222
+
223
+ **AI generation fails**:
224
+ - `vralphy init` falls back to template
225
+ - User notified, operation continues
226
+ - Degraded mode still functional
227
+
228
+ **Engine unavailable**:
229
+ - `vralphy engines` shows status
230
+ - Clear error messages
231
+ - Installation guidance
232
+
233
+ **Interrupted operations**:
234
+ - Ctrl+C exits cleanly
235
+ - No partial commits
236
+ - Plan remains consistent
237
+
238
+ **Missing files**:
239
+ - `vralphy cleanup` handles gracefully
240
+ - Reports what's missing
241
+ - Doesn't error on not-found
242
+
243
+ ---
244
+
245
+ ## Architecture
246
+
247
+ ### Directory Structure
248
+
249
+ ```
250
+ vralphy/
251
+ ├── src/
252
+ │ ├── commands/ # CLI command implementations
253
+ │ │ ├── build.ts
254
+ │ │ ├── plan.ts
255
+ │ │ ├── spec.ts
256
+ │ │ ├── init.ts
257
+ │ │ └── cleanup.ts
258
+ │ ├── lib/
259
+ │ │ ├── engines/ # Engine implementations
260
+ │ │ │ ├── base.ts # Engine interface
261
+ │ │ │ ├── claude.ts
262
+ │ │ │ ├── opencode.ts
263
+ │ │ │ └── codex.ts
264
+ │ │ ├── config.ts # Configuration handling
265
+ │ │ ├── prompts.ts # Prompt templates
266
+ │ │ ├── context.ts # Project context gathering
267
+ │ │ ├── init.ts # Initialization logic
268
+ │ │ ├── skills.ts # Skill management
269
+ │ │ └── agents.ts # Agent management
270
+ │ └── index.ts # CLI entry point
271
+ ├── docs/ # LLM-friendly documentation
272
+ ├── bin/
273
+ │ └── vralphy.js # Executable wrapper
274
+ └── package.json
275
+ ```
276
+
277
+ ### Project Structure (After Init)
278
+
279
+ ```
280
+ your-project/
281
+ ├── .vralphy/
282
+ │ ├── AGENTS.md # Operational guide
283
+ │ └── prompts/
284
+ │ ├── plan.md
285
+ │ ├── build.md
286
+ │ └── spec.md
287
+ ├── specs/ # Specifications
288
+ │ └── feature.md
289
+ ├── IMPLEMENTATION_PLAN.md # Task list
290
+ └── src/ # Your code
291
+ ```
292
+
293
+ ### Data Flow
294
+
295
+ **Initialization**:
296
+ ```
297
+ Project → Context gathering → AI analysis → AGENTS.md generation → Scaffold creation
298
+ ```
299
+
300
+ **Specification**:
301
+ ```
302
+ User input → AI questions → User answers → Spec generation → Save to specs/
303
+ ```
304
+
305
+ **Planning**:
306
+ ```
307
+ .vralphy/AGENTS.md + specs/* + src/* → AI analysis → IMPLEMENTATION_PLAN.md update
308
+ ```
309
+
310
+ **Building**:
311
+ ```
312
+ IMPLEMENTATION_PLAN.md → Task selection → Code search → Implementation → Test → Commit
313
+ ↑ ↓
314
+ └───────────────────────────── Update plan ──────────────────────────────┘
315
+ ```
316
+
317
+ ---
318
+
319
+ ## Technology Choices
320
+
321
+ ### TypeScript
322
+
323
+ **Why**: Type safety, better tooling, clearer interfaces
324
+
325
+ **Benefits**:
326
+ - Catch errors at compile time
327
+ - IDE autocomplete
328
+ - Self-documenting code
329
+
330
+ ### Commander.js
331
+
332
+ **Why**: Standard CLI framework for Node.js
333
+
334
+ **Benefits**:
335
+ - Clean command syntax
336
+ - Built-in help
337
+ - Argument parsing
338
+
339
+ ### Vitest
340
+
341
+ **Why**: Fast, modern testing framework
342
+
343
+ **Benefits**:
344
+ - ESM support
345
+ - Fast execution
346
+ - Great DX
347
+
348
+ ### ESM (ES Modules)
349
+
350
+ **Why**: Modern JavaScript standard
351
+
352
+ **Benefits**:
353
+ - Native import/export
354
+ - Tree-shaking
355
+ - Future-proof
356
+
357
+ ---
358
+
359
+ ## Design Trade-offs
360
+
361
+ ### AI-Powered Init vs Template-Only
362
+
363
+ **Decision**: AI-powered with template fallback
364
+
365
+ **Trade-off**: Complexity vs quality
366
+ - AI init: Better quality, requires engine, slower
367
+ - Template: Always works, simpler, generic
368
+
369
+ **Resolution**: Both - AI when available, template as fallback
370
+
371
+ ### Monorepo vs Multi-Package
372
+
373
+ **Decision**: Single package (`vralphy`)
374
+
375
+ **Trade-off**: Simplicity vs modularity
376
+ - Single: Easier to install, simpler for users
377
+ - Multi: Better code organization, reusable modules
378
+
379
+ **Resolution**: Single package - user experience wins
380
+
381
+ ### Hardcoded Prompts vs External Files
382
+
383
+ **Decision**: Both - defaults hardcoded, customizable external
384
+
385
+ **Trade-off**: Convenience vs flexibility
386
+ - Hardcoded: Works out of box, no config needed
387
+ - External: Customizable, project-specific
388
+
389
+ **Resolution**: Hardcoded defaults in code, customizable in `.vralphy/prompts/`
390
+
391
+ ### Auto-Commit vs Manual Review
392
+
393
+ **Decision**: Auto-commit with test gates
394
+
395
+ **Trade-off**: Automation vs control
396
+ - Auto: Fully autonomous, faster
397
+ - Manual: More control, safer
398
+
399
+ **Resolution**: Auto-commit only when tests pass - best of both
400
+
401
+ ---
402
+
403
+ ## Extensibility
404
+
405
+ ### Adding New Engines
406
+
407
+ Implement the `Engine` interface:
408
+
409
+ ```typescript
410
+ class MyEngine implements Engine {
411
+ readonly name = 'myengine';
412
+
413
+ async *execute(prompt: string, options: ExecuteOptions): AsyncIterable<Chunk> {
414
+ // Implementation
415
+ }
416
+
417
+ async isAvailable(): Promise<boolean> {
418
+ // Check if engine CLI is installed
419
+ }
420
+
421
+ getFlags(options: EngineFlags): string[] {
422
+ // Return engine-specific flags
423
+ }
424
+
425
+ supportsInteractive(): boolean {
426
+ return true; // or false
427
+ }
428
+
429
+ getCommand(): string {
430
+ return 'myengine';
431
+ }
432
+ }
433
+ ```
434
+
435
+ Register in `src/lib/engines/index.ts`:
436
+ ```typescript
437
+ const engines: Record<EngineName, Engine> = {
438
+ claude: new ClaudeEngine(),
439
+ opencode: new OpenCodeEngine(),
440
+ codex: new CodexEngine(),
441
+ myengine: new MyEngine(),
442
+ };
443
+ ```
444
+
445
+ ### Adding New Commands
446
+
447
+ 1. Create command file: `src/commands/mycommand.ts`
448
+ 2. Export command function
449
+ 3. Register in `src/index.ts`
450
+
451
+ Example:
452
+ ```typescript
453
+ // src/commands/mycommand.ts
454
+ export async function myCommand(options: MyOptions): Promise<void> {
455
+ // Implementation
456
+ }
457
+
458
+ // src/index.ts
459
+ import { myCommand } from './commands/mycommand.js';
460
+
461
+ program
462
+ .command('mycommand')
463
+ .description('Description')
464
+ .action(async (opts) => {
465
+ await myCommand(opts);
466
+ });
467
+ ```
468
+
469
+ ### Customizing Prompts
470
+
471
+ Edit files in `.vralphy/prompts/`:
472
+
473
+ - `plan.md` - Planning phase prompt
474
+ - `build.md` - Build phase prompt
475
+ - `spec.md` - Spec creation prompt
476
+
477
+ Prompts support variables:
478
+ - `${model}` - Primary model
479
+ - `${executor}` - Executor model
480
+ - `${engine}` - Engine name
481
+ - `${skillsDir}` - Skills directory
482
+ - `${agentsDir}` - Agents directory
483
+
484
+ ---
485
+
486
+ ## Security Considerations
487
+
488
+ ### No Secrets in Prompts
489
+
490
+ - Never include API keys or secrets in specs
491
+ - `.vralphy/AGENTS.md` should not contain credentials
492
+ - AI has read access to codebase - keep secrets in env vars
493
+
494
+ ### Git Safety
495
+
496
+ - Never run destructive git commands without user approval
497
+ - Always create new commits (not amend) after hook failures
498
+ - Prefer specific file staging over `git add -A`
499
+ - Never skip git hooks (--no-verify) unless explicitly requested
500
+
501
+ ### Sandboxing
502
+
503
+ - AI executes in project directory context
504
+ - No access outside project directory
505
+ - Uses project's git config and permissions
506
+
507
+ ---
508
+
509
+ ## Performance Considerations
510
+
511
+ ### Parallel Execution
512
+
513
+ - Reading: Highly parallel (250-500 agents)
514
+ - Writing: Sequential (1 agent)
515
+ - Testing: Sequential (1 agent)
516
+ - Reasoning: Focused (1 primary model)
517
+
518
+ ### Token Optimization
519
+
520
+ - Keep `.vralphy/AGENTS.md` under 60 lines
521
+ - Lazy-load skills and agents
522
+ - Use cheap models for bulk operations
523
+ - Use expensive models for reasoning
524
+
525
+ ### Network Efficiency
526
+
527
+ - Stream responses when possible
528
+ - Batch file reads in parallel
529
+ - Cache repeated operations (future enhancement)
530
+
531
+ ---
532
+
533
+ ## Next Steps
534
+
535
+ - Read [METHODOLOGY.md](./METHODOLOGY.md) for the Ralph approach
536
+ - Check [WORKFLOWS.md](./WORKFLOWS.md) for usage patterns
537
+ - See [EXAMPLES.md](./EXAMPLES.md) for real-world cases