@voodocs/cli 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.
@@ -0,0 +1,734 @@
1
+ """
2
+ AI instruction templates for VooDocs Context System.
3
+
4
+ This module provides templates for generating AI assistant instructions
5
+ that teach them how to use the VooDocs context system effectively.
6
+ """
7
+
8
+ from typing import Dict, Optional
9
+
10
+
11
+ def generate_cursorrules(project_name: str, project_purpose: str) -> str:
12
+ """
13
+ Generate .cursorrules content for Cursor AI.
14
+
15
+ Args:
16
+ project_name: Name of the project
17
+ project_purpose: Brief purpose of the project
18
+
19
+ Returns:
20
+ Content for .cursorrules file
21
+ """
22
+ return f"""# {project_name} - VooDocs Context System
23
+
24
+ ## Project Overview
25
+ {project_purpose}
26
+
27
+ ## VooDocs Context System (v0.2.0+)
28
+
29
+ This project uses VooDocs with the Context System for intelligent documentation and validation.
30
+
31
+ ### Context File Location
32
+ - **Context file**: `.voodocs.context` (YAML format)
33
+ - **Auto-generated**: From @voodocs annotations in code
34
+ - **Version controlled**: Track context changes over time
35
+
36
+ ### Essential Commands
37
+
38
+ #### Before Starting Work
39
+ ```bash
40
+ # Read the project context to understand architecture, invariants, and assumptions
41
+ voodocs context view
42
+ ```
43
+
44
+ #### During Development
45
+ ```bash
46
+ # Add @voodocs annotations to your code (see format below)
47
+ # Then auto-generate context from annotations
48
+ voodocs context generate --update
49
+
50
+ # Check if code respects documented invariants
51
+ voodocs context check
52
+
53
+ # Query specific information
54
+ voodocs context query "search term" --section invariants
55
+ ```
56
+
57
+ #### Before Committing
58
+ ```bash
59
+ # Validate context and check invariants
60
+ voodocs context validate --check-invariants
61
+
62
+ # Update context version with description
63
+ voodocs context update --description "Brief description of changes"
64
+ ```
65
+
66
+ #### Architecture & Documentation
67
+ ```bash
68
+ # Generate architecture diagrams
69
+ voodocs context diagram --type modules --output docs/architecture.mmd
70
+
71
+ # View full context as Markdown
72
+ voodocs context view > docs/CONTEXT.md
73
+ ```
74
+
75
+ ### @voodocs Annotation Format
76
+
77
+ Add to Python/TypeScript/JavaScript files:
78
+
79
+ **Python:**
80
+ ```python
81
+ \"\"\"@voodocs
82
+ module_purpose: "Brief description of what this module does"
83
+ dependencies: [
84
+ "other-module: What it provides",
85
+ "external-lib: Why we use it"
86
+ ]
87
+ assumptions: [
88
+ "Database connection is established",
89
+ "User is authenticated",
90
+ "Environment variables are set"
91
+ ]
92
+ invariants: [
93
+ "All user input must be validated",
94
+ "Passwords must be hashed before storage",
95
+ "API keys must never be logged"
96
+ ]
97
+ security_model: "Brief description of security approach"
98
+ performance_notes: "Expected performance characteristics"
99
+ \"\"\"
100
+ ```
101
+
102
+ **TypeScript/JavaScript:**
103
+ ```typescript
104
+ /**@voodocs
105
+ module_purpose: "Brief description of what this module does"
106
+ dependencies: [
107
+ "react: UI framework",
108
+ "axios: HTTP client"
109
+ ]
110
+ assumptions: [
111
+ "API endpoint is available",
112
+ "User has valid token"
113
+ ]
114
+ invariants: [
115
+ "All API responses must be validated",
116
+ "Errors must be handled gracefully"
117
+ ]
118
+ */
119
+ ```
120
+
121
+ ### Context-Aware Development Workflow
122
+
123
+ 1. **Understand Context**: Always run `voodocs context view` before making changes
124
+ 2. **Check Invariants**: Ensure you understand the global invariants that must be respected
125
+ 3. **Add Annotations**: Document your code with @voodocs annotations as you write
126
+ 4. **Update Context**: Run `voodocs context generate --update` after adding features
127
+ 5. **Validate**: Run `voodocs context check` to ensure invariants are respected
128
+ 6. **Update Version**: Use `voodocs context update` to track context changes
129
+
130
+ ### What to Document
131
+
132
+ **Module Purpose**: What this module does and why it exists
133
+ **Dependencies**: What this module depends on (internal and external)
134
+ **Assumptions**: What must be true for this module to work correctly
135
+ **Invariants**: Rules that must always hold (security, data integrity, etc.)
136
+ **Security Model**: How this module handles security concerns
137
+ **Performance Notes**: Expected performance characteristics and bottlenecks
138
+
139
+ ### Context Sections
140
+
141
+ The `.voodocs.context` file contains:
142
+
143
+ - **Project**: Name, purpose, domain
144
+ - **Versioning**: Code version, context version, last updated
145
+ - **Invariants**: Global rules that must always hold
146
+ - **Assumptions**: System-wide assumptions
147
+ - **Architecture**: Modules, decisions, patterns
148
+ - **Critical Paths**: Important workflows
149
+ - **Dependencies**: External libraries and tools
150
+ - **Known Issues**: Bugs and limitations
151
+ - **Change History**: Version tracking with Git integration
152
+
153
+ ### Best Practices
154
+
155
+ 1. **Read context first**: Always check context before making changes
156
+ 2. **Document as you code**: Add @voodocs annotations while writing code
157
+ 3. **Keep invariants clear**: Make invariants specific and testable
158
+ 4. **Update regularly**: Run `voodocs context generate --update` frequently
159
+ 5. **Validate before commit**: Run `voodocs context check` before committing
160
+ 6. **Track changes**: Use `voodocs context update` to document what changed
161
+
162
+ ### CI/CD Integration
163
+
164
+ The context system can be integrated into CI/CD pipelines:
165
+
166
+ ```yaml
167
+ # GitHub Actions example
168
+ - name: Validate Context
169
+ run: voodocs context validate --check-invariants
170
+
171
+ - name: Check Invariants
172
+ run: voodocs context check --format json
173
+ ```
174
+
175
+ ### Querying Context
176
+
177
+ Search for specific information:
178
+
179
+ ```bash
180
+ # Find security-related invariants
181
+ voodocs context query "security" --section invariants
182
+
183
+ # Find authentication assumptions
184
+ voodocs context query "auth" --section assumptions --format json
185
+
186
+ # Search all sections
187
+ voodocs context query "database"
188
+ ```
189
+
190
+ ### Architecture Diagrams
191
+
192
+ Generate visual documentation:
193
+
194
+ ```bash
195
+ # Module dependency diagram
196
+ voodocs context diagram --type modules
197
+
198
+ # External dependencies
199
+ voodocs context diagram --type dependencies
200
+
201
+ # Critical path workflows
202
+ voodocs context diagram --type flow
203
+
204
+ # Generate all diagrams
205
+ voodocs context diagram --type all --output docs/arch
206
+ ```
207
+
208
+ ### Remember
209
+
210
+ - The context system is your source of truth for project understanding
211
+ - Invariants are enforced rules - respect them
212
+ - Assumptions are documented expectations - validate them
213
+ - Context is version-controlled - track changes
214
+ - Always check context before making architectural decisions
215
+
216
+ ---
217
+
218
+ **VooDocs Context System** - AI-native documentation that keeps code and context in sync.
219
+ """
220
+
221
+
222
+ def generate_context_guide(project_name: str, project_purpose: str) -> str:
223
+ """
224
+ Generate comprehensive context guide for AI assistants.
225
+
226
+ Args:
227
+ project_name: Name of the project
228
+ project_purpose: Brief purpose of the project
229
+
230
+ Returns:
231
+ Content for VOODOCS_CONTEXT_GUIDE.md file
232
+ """
233
+ return f"""# VooDocs Context System Guide - {project_name}
234
+
235
+ ## Project Overview
236
+
237
+ **Name**: {project_name}
238
+ **Purpose**: {project_purpose}
239
+
240
+ This project uses the **VooDocs Context System** (v0.2.0+) for intelligent documentation, validation, and architecture management.
241
+
242
+ ---
243
+
244
+ ## What is the Context System?
245
+
246
+ The VooDocs Context System is an AI-native documentation framework that:
247
+
248
+ 1. **Auto-generates** project context from code annotations
249
+ 2. **Validates** code against documented invariants
250
+ 3. **Tracks** changes with version control integration
251
+ 4. **Visualizes** architecture with auto-generated diagrams
252
+ 5. **Queries** like a database for instant information
253
+
254
+ ---
255
+
256
+ ## Quick Start
257
+
258
+ ### 1. View Current Context
259
+
260
+ ```bash
261
+ voodocs context view
262
+ ```
263
+
264
+ This shows you:
265
+ - Project purpose and domain
266
+ - Global invariants (rules that must hold)
267
+ - System assumptions
268
+ - Architecture and modules
269
+ - Dependencies
270
+ - Known issues
271
+
272
+ **Do this before making any changes!**
273
+
274
+ ### 2. Check Invariants
275
+
276
+ ```bash
277
+ voodocs context check
278
+ ```
279
+
280
+ This validates that the code respects all documented invariants:
281
+ - Password hashing
282
+ - API key protection
283
+ - SQL injection prevention
284
+ - Input validation
285
+ - Error handling
286
+ - And more...
287
+
288
+ ### 3. Update Context
289
+
290
+ ```bash
291
+ voodocs context generate --update
292
+ ```
293
+
294
+ This scans the codebase for @voodocs annotations and updates the context file.
295
+
296
+ ---
297
+
298
+ ## The `.voodocs.context` File
299
+
300
+ **Location**: `./.voodocs.context`
301
+ **Format**: YAML
302
+ **Purpose**: Single source of truth for project understanding
303
+
304
+ ### Structure
305
+
306
+ ```yaml
307
+ project:
308
+ name: "{project_name}"
309
+ purpose: "{project_purpose}"
310
+ domain: "Application domain"
311
+
312
+ versioning:
313
+ code_version: "1.0.0"
314
+ context_version: "1.0"
315
+ last_updated: "2025-12-19"
316
+
317
+ invariants:
318
+ global:
319
+ - "All passwords must be hashed before storage"
320
+ - "API keys must never be logged"
321
+ - "All database queries must use parameterized statements"
322
+
323
+ assumptions:
324
+ - "Database connection is established at startup"
325
+ - "User authentication is handled by auth service"
326
+
327
+ architecture:
328
+ modules:
329
+ module-name:
330
+ purpose: "What this module does"
331
+ dependencies: ["other-module"]
332
+
333
+ dependencies:
334
+ external:
335
+ - name: "library-name"
336
+ version: "1.0.0"
337
+ purpose: "Why we use it"
338
+
339
+ critical_paths:
340
+ - name: "User Login Flow"
341
+ steps:
342
+ - "User enters credentials"
343
+ - "Credentials validated"
344
+ - "JWT token generated"
345
+ - "Token returned to client"
346
+ ```
347
+
348
+ ---
349
+
350
+ ## @voodocs Annotations
351
+
352
+ ### Purpose
353
+
354
+ Annotations are **structured comments** that document:
355
+ - What a module does
356
+ - What it depends on
357
+ - What assumptions it makes
358
+ - What invariants it enforces
359
+
360
+ ### Format
361
+
362
+ **Python:**
363
+ ```python
364
+ \"\"\"@voodocs
365
+ module_purpose: "User authentication and session management"
366
+ dependencies: [
367
+ "bcrypt: Password hashing",
368
+ "jwt: Token generation",
369
+ "database: User storage"
370
+ ]
371
+ assumptions: [
372
+ "Database connection is available",
373
+ "Redis is running for session storage"
374
+ ]
375
+ invariants: [
376
+ "Passwords must be hashed with bcrypt",
377
+ "Sessions must expire after 24 hours",
378
+ "Failed login attempts must be rate-limited"
379
+ ]
380
+ security_model: "Passwords hashed with bcrypt (cost 12), JWTs expire in 24h, rate limiting on failed attempts"
381
+ performance_notes: "O(1) for session lookup (Redis), O(log n) for user lookup (indexed database)"
382
+ \"\"\"
383
+
384
+ def authenticate_user(username: str, password: str) -> Optional[str]:
385
+ # Implementation
386
+ pass
387
+ ```
388
+
389
+ **TypeScript:**
390
+ ```typescript
391
+ /**@voodocs
392
+ module_purpose: "API client for backend communication"
393
+ dependencies: [
394
+ "axios: HTTP client",
395
+ "zod: Response validation"
396
+ ]
397
+ assumptions: [
398
+ "API endpoint is reachable",
399
+ "User has valid authentication token"
400
+ ]
401
+ invariants: [
402
+ "All API responses must be validated",
403
+ "Network errors must be handled gracefully",
404
+ "Retry logic must use exponential backoff"
405
+ ]
406
+ */
407
+
408
+ export class ApiClient {{
409
+ // Implementation
410
+ }}
411
+ ```
412
+
413
+ ### Fields
414
+
415
+ | Field | Required | Description |
416
+ |-------|----------|-------------|
417
+ | `module_purpose` | Yes | Brief description of what this module does |
418
+ | `dependencies` | No | List of dependencies (internal and external) |
419
+ | `assumptions` | No | What must be true for this module to work |
420
+ | `invariants` | No | Rules that must always hold |
421
+ | `security_model` | No | How security is handled |
422
+ | `performance_notes` | No | Expected performance characteristics |
423
+
424
+ ---
425
+
426
+ ## Command Reference
427
+
428
+ ### Context Management
429
+
430
+ | Command | Purpose |
431
+ |---------|---------|
432
+ | `voodocs context init` | Initialize context file |
433
+ | `voodocs context view` | View context as Markdown |
434
+ | `voodocs context status` | Show context status |
435
+
436
+ ### Auto-Generation
437
+
438
+ | Command | Purpose |
439
+ |---------|---------|
440
+ | `voodocs context generate` | Generate context from code |
441
+ | `voodocs context generate --update` | Update existing context |
442
+
443
+ ### Validation
444
+
445
+ | Command | Purpose |
446
+ |---------|---------|
447
+ | `voodocs context validate` | Validate context file |
448
+ | `voodocs context validate --check-invariants` | Validate + check code |
449
+ | `voodocs context check` | Check code against invariants |
450
+ | `voodocs context check --format json` | JSON output for CI/CD |
451
+
452
+ ### Querying
453
+
454
+ | Command | Purpose |
455
+ |---------|---------|
456
+ | `voodocs context query "term"` | Search all sections |
457
+ | `voodocs context query "term" --section invariants` | Search specific section |
458
+ | `voodocs context query "term" --format json` | JSON output |
459
+
460
+ ### Versioning
461
+
462
+ | Command | Purpose |
463
+ |---------|---------|
464
+ | `voodocs context update` | Update context version |
465
+ | `voodocs context sync` | Sync with code version |
466
+ | `voodocs context history` | Show version history |
467
+ | `voodocs context diff v1 v2` | Compare versions |
468
+
469
+ ### Visualization
470
+
471
+ | Command | Purpose |
472
+ |---------|---------|
473
+ | `voodocs context diagram --type modules` | Module diagram |
474
+ | `voodocs context diagram --type dependencies` | Dependency diagram |
475
+ | `voodocs context diagram --type flow` | Flow diagram |
476
+ | `voodocs context diagram --type all` | All diagrams |
477
+
478
+ ---
479
+
480
+ ## Development Workflow
481
+
482
+ ### 1. Before Starting Work
483
+
484
+ ```bash
485
+ # Read the context
486
+ voodocs context view
487
+
488
+ # Check current status
489
+ voodocs context status
490
+
491
+ # Validate everything
492
+ voodocs context validate --check-invariants
493
+ ```
494
+
495
+ ### 2. During Development
496
+
497
+ ```bash
498
+ # Add @voodocs annotations to your code
499
+ # (See annotation format above)
500
+
501
+ # Update context from annotations
502
+ voodocs context generate --update
503
+
504
+ # Check if code respects invariants
505
+ voodocs context check
506
+ ```
507
+
508
+ ### 3. Before Committing
509
+
510
+ ```bash
511
+ # Final validation
512
+ voodocs context validate --check-invariants
513
+
514
+ # Update context version
515
+ voodocs context update --description "Added user authentication module"
516
+
517
+ # Generate updated diagrams
518
+ voodocs context diagram --type all --output docs/architecture
519
+ ```
520
+
521
+ ### 4. During Code Review
522
+
523
+ ```bash
524
+ # Compare context versions
525
+ voodocs context diff v1.0 v1.1
526
+
527
+ # Check specific invariant
528
+ voodocs context check --invariant "password"
529
+
530
+ # Query for specific information
531
+ voodocs context query "authentication" --section assumptions
532
+ ```
533
+
534
+ ---
535
+
536
+ ## Invariant Checking
537
+
538
+ ### What Are Invariants?
539
+
540
+ Invariants are **rules that must always hold**. Examples:
541
+ - "All passwords must be hashed before storage"
542
+ - "API keys must never be logged"
543
+ - "All database queries must use parameterized statements"
544
+
545
+ ### How It Works
546
+
547
+ The invariant checker uses **pattern-based detection** to find violations:
548
+
549
+ ```bash
550
+ voodocs context check
551
+ ```
552
+
553
+ **Output:**
554
+ ```
555
+ ✅ All passwords must be hashed before storage
556
+ No violations found
557
+
558
+ ❌ API keys must never be logged
559
+ Found 2 potential violation(s):
560
+
561
+ 📍 src/auth.py:45
562
+ logger.info(f"Using API key: {{api_key}}")
563
+ → API keys/secrets should not be logged
564
+ ```
565
+
566
+ ### Supported Patterns
567
+
568
+ - Password security (hashing detection)
569
+ - API key protection (logging detection)
570
+ - SQL injection prevention (parameterized queries)
571
+ - Input validation
572
+ - Null/None checking
573
+ - Error handling
574
+
575
+ ---
576
+
577
+ ## Architecture Diagrams
578
+
579
+ ### Generate Diagrams
580
+
581
+ ```bash
582
+ # Module dependency diagram
583
+ voodocs context diagram --type modules --output architecture.mmd
584
+
585
+ # External dependencies
586
+ voodocs context diagram --type dependencies --output dependencies.mmd
587
+
588
+ # Critical path workflows
589
+ voodocs context diagram --type flow --output flows.mmd
590
+ ```
591
+
592
+ ### Viewing Diagrams
593
+
594
+ The diagrams are generated in **Mermaid** format. View them:
595
+ - Copy to [Mermaid Live Editor](https://mermaid.live)
596
+ - Use VS Code with Mermaid extension
597
+ - Render in GitHub (supports Mermaid in markdown)
598
+
599
+ ---
600
+
601
+ ## CI/CD Integration
602
+
603
+ ### GitHub Actions
604
+
605
+ ```yaml
606
+ name: Context Validation
607
+
608
+ on: [push, pull_request]
609
+
610
+ jobs:
611
+ validate:
612
+ runs-on: ubuntu-latest
613
+ steps:
614
+ - uses: actions/checkout@v2
615
+
616
+ - name: Install VooDocs
617
+ run: npm install -g @voodocs/cli
618
+
619
+ - name: Validate Context
620
+ run: voodocs context validate --check-invariants
621
+
622
+ - name: Check Invariants
623
+ run: voodocs context check --format json > violations.json
624
+
625
+ - name: Upload Report
626
+ uses: actions/upload-artifact@v2
627
+ with:
628
+ name: context-report
629
+ path: violations.json
630
+ ```
631
+
632
+ ---
633
+
634
+ ## Best Practices
635
+
636
+ ### 1. Read Context First
637
+ Always run `voodocs context view` before making changes.
638
+
639
+ ### 2. Document As You Code
640
+ Add @voodocs annotations while writing code, not after.
641
+
642
+ ### 3. Keep Invariants Specific
643
+ ❌ Bad: "Data must be valid"
644
+ ✅ Good: "All user input must be validated using Zod schemas"
645
+
646
+ ### 4. Update Regularly
647
+ Run `voodocs context generate --update` frequently during development.
648
+
649
+ ### 5. Validate Before Commit
650
+ Always run `voodocs context check` before committing.
651
+
652
+ ### 6. Track Changes
653
+ Use `voodocs context update` to document what changed and why.
654
+
655
+ ### 7. Query for Understanding
656
+ Use `voodocs context query` to quickly find information.
657
+
658
+ ### 8. Generate Diagrams
659
+ Keep architecture diagrams up-to-date with `voodocs context diagram`.
660
+
661
+ ---
662
+
663
+ ## Troubleshooting
664
+
665
+ ### "No modules found in context"
666
+
667
+ **Problem**: Trying to generate module diagram but no modules defined.
668
+
669
+ **Solution**: Add modules to `.voodocs.context`:
670
+ ```yaml
671
+ architecture:
672
+ modules:
673
+ module-name:
674
+ purpose: "What it does"
675
+ dependencies: []
676
+ ```
677
+
678
+ Or add `module_purpose` to @voodocs annotations and regenerate.
679
+
680
+ ### "Invariant violations found"
681
+
682
+ **Problem**: Code doesn't respect documented invariants.
683
+
684
+ **Solution**:
685
+ 1. Review the violation report
686
+ 2. Fix the code to respect the invariant
687
+ 3. Or update the invariant if it's incorrect
688
+
689
+ ### "Context file not found"
690
+
691
+ **Problem**: No `.voodocs.context` file exists.
692
+
693
+ **Solution**: Run `voodocs context init` to create one.
694
+
695
+ ---
696
+
697
+ ## Summary
698
+
699
+ The VooDocs Context System is your **single source of truth** for:
700
+ - ✅ Project understanding
701
+ - ✅ Architecture documentation
702
+ - ✅ Code validation
703
+ - ✅ Change tracking
704
+ - ✅ Visual documentation
705
+
706
+ **Always check context before making changes!**
707
+
708
+ ---
709
+
710
+ **VooDocs v0.2.0+** - AI-native documentation that keeps code and context in sync.
711
+ """
712
+
713
+
714
+ def generate_ai_instructions(project_name: str, project_purpose: str, ai_type: str = "cursor") -> Dict[str, str]:
715
+ """
716
+ Generate AI instruction files for different AI assistants.
717
+
718
+ Args:
719
+ project_name: Name of the project
720
+ project_purpose: Brief purpose of the project
721
+ ai_type: Type of AI assistant ("cursor", "claude", "copilot", "all")
722
+
723
+ Returns:
724
+ Dictionary mapping filename to content
725
+ """
726
+ instructions = {}
727
+
728
+ if ai_type in ["cursor", "all"]:
729
+ instructions[".cursorrules"] = generate_cursorrules(project_name, project_purpose)
730
+
731
+ if ai_type in ["all", "cursor", "claude", "copilot"]:
732
+ instructions["VOODOCS_CONTEXT_GUIDE.md"] = generate_context_guide(project_name, project_purpose)
733
+
734
+ return instructions