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