loki-mode 4.2.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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +691 -0
  3. package/SKILL.md +191 -0
  4. package/VERSION +1 -0
  5. package/autonomy/.loki/dashboard/index.html +2634 -0
  6. package/autonomy/CONSTITUTION.md +508 -0
  7. package/autonomy/README.md +201 -0
  8. package/autonomy/config.example.yaml +152 -0
  9. package/autonomy/loki +526 -0
  10. package/autonomy/run.sh +3636 -0
  11. package/bin/loki-mode.js +26 -0
  12. package/bin/postinstall.js +60 -0
  13. package/docs/ACKNOWLEDGEMENTS.md +234 -0
  14. package/docs/COMPARISON.md +325 -0
  15. package/docs/COMPETITIVE-ANALYSIS.md +333 -0
  16. package/docs/INSTALLATION.md +547 -0
  17. package/docs/auto-claude-comparison.md +276 -0
  18. package/docs/cursor-comparison.md +225 -0
  19. package/docs/dashboard-guide.md +355 -0
  20. package/docs/screenshots/README.md +149 -0
  21. package/docs/screenshots/dashboard-agents.png +0 -0
  22. package/docs/screenshots/dashboard-tasks.png +0 -0
  23. package/docs/thick2thin.md +173 -0
  24. package/package.json +48 -0
  25. package/references/advanced-patterns.md +453 -0
  26. package/references/agent-types.md +243 -0
  27. package/references/agents.md +1043 -0
  28. package/references/business-ops.md +550 -0
  29. package/references/competitive-analysis.md +216 -0
  30. package/references/confidence-routing.md +371 -0
  31. package/references/core-workflow.md +275 -0
  32. package/references/cursor-learnings.md +207 -0
  33. package/references/deployment.md +604 -0
  34. package/references/lab-research-patterns.md +534 -0
  35. package/references/mcp-integration.md +186 -0
  36. package/references/memory-system.md +467 -0
  37. package/references/openai-patterns.md +647 -0
  38. package/references/production-patterns.md +568 -0
  39. package/references/prompt-repetition.md +192 -0
  40. package/references/quality-control.md +437 -0
  41. package/references/sdlc-phases.md +410 -0
  42. package/references/task-queue.md +361 -0
  43. package/references/tool-orchestration.md +691 -0
  44. package/skills/00-index.md +120 -0
  45. package/skills/agents.md +249 -0
  46. package/skills/artifacts.md +174 -0
  47. package/skills/github-integration.md +218 -0
  48. package/skills/model-selection.md +125 -0
  49. package/skills/parallel-workflows.md +526 -0
  50. package/skills/patterns-advanced.md +188 -0
  51. package/skills/production.md +292 -0
  52. package/skills/quality-gates.md +180 -0
  53. package/skills/testing.md +149 -0
  54. package/skills/troubleshooting.md +109 -0
@@ -0,0 +1,526 @@
1
+ # Parallel Workflows with Git Worktrees
2
+
3
+ > **Research basis:** Claude Code git worktrees pattern, Anthropic "One Feature at a Time" harness, HN production patterns on context isolation.
4
+
5
+ ---
6
+
7
+ ## Why Worktree-Based Parallelism
8
+
9
+ **The Problem:**
10
+ - Single Claude session = sequential work
11
+ - Feature A blocks Feature B
12
+ - Testing waits for development to finish
13
+ - Documentation waits for everything
14
+ - Context bloats with unrelated work
15
+
16
+ **The Solution:**
17
+ - Git worktrees = isolated working directories
18
+ - Multiple Claude sessions = true parallelism
19
+ - Each stream has fresh context
20
+ - Work merges back when complete
21
+
22
+ ```
23
+ Main Worktree (orchestrator)
24
+ |
25
+ +-- ../project-feature-auth (Claude session 1)
26
+ +-- ../project-feature-api (Claude session 2)
27
+ +-- ../project-testing (Claude session 3)
28
+ +-- ../project-docs (Claude session 4)
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Parallel Work Streams
34
+
35
+ | Stream | Purpose | Worktree | Triggers |
36
+ |--------|---------|----------|----------|
37
+ | **feature-N** | Implement features | `../project-feature-{name}` | PRD task breakdown |
38
+ | **testing** | Unit, integration, E2E | `../project-testing` | After feature checkpoint |
39
+ | **qa-validation** | UAT, accessibility | `../project-qa` | After tests pass |
40
+ | **documentation** | Docs, changelog | `../project-docs` | After feature merge |
41
+ | **blog** | Blog posts (if site has blog) | `../project-blog` | After significant releases |
42
+
43
+ ---
44
+
45
+ ## Worktree Management Commands
46
+
47
+ ### Create Feature Worktree
48
+
49
+ ```bash
50
+ # From main worktree
51
+ git worktree add ../project-feature-auth -b feature/auth
52
+
53
+ # Initialize environment
54
+ cd ../project-feature-auth
55
+ npm install # or pip install, cargo build, etc.
56
+ ```
57
+
58
+ ### Create Testing Worktree (tracks main)
59
+
60
+ ```bash
61
+ # Testing always runs against latest main
62
+ git worktree add ../project-testing main
63
+
64
+ # Pull latest before each test run
65
+ cd ../project-testing
66
+ git pull origin main
67
+ ```
68
+
69
+ ### Merge Completed Work
70
+
71
+ ```bash
72
+ # Feature complete, merge back
73
+ cd /path/to/main/worktree
74
+ git merge feature/auth --no-ff -m "feat: User authentication"
75
+
76
+ # Remove worktree
77
+ git worktree remove ../project-feature-auth
78
+ git branch -d feature/auth
79
+ ```
80
+
81
+ ### List and Clean Worktrees
82
+
83
+ ```bash
84
+ # List all worktrees
85
+ git worktree list
86
+
87
+ # Prune stale worktrees
88
+ git worktree prune
89
+ ```
90
+
91
+ ---
92
+
93
+ ## Orchestrator Workflow
94
+
95
+ The main orchestrator manages parallel streams:
96
+
97
+ ```yaml
98
+ orchestrator_workflow:
99
+ 1_plan:
100
+ - Analyze PRD for parallelizable features
101
+ - Create task breakdown with dependencies
102
+ - Identify independent streams
103
+
104
+ 2_spawn:
105
+ - Create worktrees for independent features
106
+ - Launch Claude session per worktree
107
+ - Start testing worktree (tracks main)
108
+
109
+ 3_coordinate:
110
+ - Watch .loki/state/ in each worktree
111
+ - Detect feature completion signals
112
+ - Trigger testing on checkpoints
113
+ - Queue documentation on merges
114
+
115
+ 4_merge:
116
+ - Validate tests pass on feature branch
117
+ - Merge to main
118
+ - Update testing worktree (git pull)
119
+ - Trigger documentation stream
120
+
121
+ 5_cleanup:
122
+ - Remove completed worktrees
123
+ - Archive session logs
124
+ - Update main orchestrator state
125
+ ```
126
+
127
+ ---
128
+
129
+ ## Claude Session Per Worktree
130
+
131
+ Each worktree runs an independent Claude session:
132
+
133
+ ```bash
134
+ # Feature development session
135
+ cd ../project-feature-auth
136
+ claude --dangerously-skip-permissions -p "Loki Mode: Implement user authentication. Read .loki/CONTINUITY.md for context."
137
+
138
+ # Testing session (continuous)
139
+ cd ../project-testing
140
+ claude --dangerously-skip-permissions -p "Loki Mode: Run all tests. Watch for changes. Report failures to .loki/state/test-results.json"
141
+
142
+ # Documentation session
143
+ cd ../project-docs
144
+ claude --dangerously-skip-permissions -p "Loki Mode: Update documentation for recent changes. Check git log for what changed."
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Inter-Stream Communication
150
+
151
+ Streams communicate via `.loki/signals/` and shared git history:
152
+
153
+ ### Signal Files
154
+
155
+ ```
156
+ .loki/signals/
157
+ FEATURE_READY_{name} # Feature ready for testing
158
+ TESTS_PASSED # All tests green
159
+ DOCS_NEEDED # Documentation required
160
+ BLOG_POST_QUEUED # Blog post should be written
161
+ MERGE_REQUESTED_{branch} # Request merge to main
162
+ ```
163
+
164
+ ### Workflow Triggers
165
+
166
+ ```yaml
167
+ feature_complete:
168
+ signal: "Create .loki/signals/FEATURE_READY_{name}"
169
+ triggers:
170
+ - Testing stream pulls feature branch
171
+ - Testing stream runs full suite
172
+ - On pass: create TESTS_PASSED + MERGE_REQUESTED
173
+
174
+ merge_complete:
175
+ signal: "Merge commit on main"
176
+ triggers:
177
+ - Documentation stream updates docs
178
+ - If significant: create BLOG_POST_QUEUED
179
+ - Testing stream pulls latest main
180
+
181
+ blog_trigger:
182
+ signal: "BLOG_POST_QUEUED exists"
183
+ triggers:
184
+ - Blog stream creates post about changes
185
+ - Removes signal when published
186
+ ```
187
+
188
+ ---
189
+
190
+ ## Parallel Testing Strategy
191
+
192
+ ### Continuous Testing Worktree
193
+
194
+ ```bash
195
+ # Testing worktree watches for changes
196
+ while true; do
197
+ # Pull latest from main
198
+ git pull origin main 2>/dev/null
199
+
200
+ # Check for feature branches ready to test
201
+ for signal in .loki/signals/FEATURE_READY_*; do
202
+ if [ -f "$signal" ]; then
203
+ feature=$(basename "$signal" | sed 's/FEATURE_READY_//')
204
+
205
+ # Checkout and test feature
206
+ git checkout "feature/$feature"
207
+ npm test
208
+
209
+ if [ $? -eq 0 ]; then
210
+ touch ".loki/signals/TESTS_PASSED_$feature"
211
+ touch ".loki/signals/MERGE_REQUESTED_$feature"
212
+ else
213
+ touch ".loki/signals/TESTS_FAILED_$feature"
214
+ fi
215
+
216
+ rm "$signal"
217
+ fi
218
+ done
219
+
220
+ sleep 30
221
+ done
222
+ ```
223
+
224
+ ### Parallel Test Execution
225
+
226
+ ```yaml
227
+ test_parallelization:
228
+ unit_tests:
229
+ worktree: "../project-testing"
230
+ command: "npm test -- --parallel"
231
+ model: haiku # Fast, cheap
232
+
233
+ integration_tests:
234
+ worktree: "../project-testing"
235
+ command: "npm run test:integration"
236
+ model: sonnet # More complex
237
+
238
+ e2e_tests:
239
+ worktree: "../project-e2e"
240
+ command: "npx playwright test"
241
+ model: sonnet # Browser automation
242
+
243
+ # All can run simultaneously in different worktrees
244
+ ```
245
+
246
+ ---
247
+
248
+ ## Documentation Stream
249
+
250
+ ### Auto-Documentation Triggers
251
+
252
+ ```yaml
253
+ doc_triggers:
254
+ - New API endpoint added
255
+ - Public function signature changed
256
+ - README mentioned file changed
257
+ - Configuration options added
258
+ - Breaking changes detected
259
+
260
+ doc_workflow:
261
+ 1. Detect trigger from git diff
262
+ 2. Identify affected documentation
263
+ 3. Update docs in ../project-docs worktree
264
+ 4. Create PR or commit to main
265
+ ```
266
+
267
+ ### Blog Stream (if site has blog)
268
+
269
+ ```yaml
270
+ blog_triggers:
271
+ - Major feature release
272
+ - Significant performance improvement
273
+ - Security fix (after patch deployed)
274
+ - Milestone reached (v1.0, 1000 users, etc.)
275
+
276
+ blog_workflow:
277
+ 1. Detect BLOG_POST_QUEUED signal
278
+ 2. Gather context from git log, CONTINUITY.md
279
+ 3. Write blog post draft
280
+ 4. Save to content/blog/ or equivalent
281
+ 5. Create PR for review (or auto-publish)
282
+ ```
283
+
284
+ ---
285
+
286
+ ## Worktree State Tracking
287
+
288
+ ### Orchestrator State Schema
289
+
290
+ ```json
291
+ {
292
+ "worktrees": {
293
+ "main": {
294
+ "path": "/path/to/project",
295
+ "branch": "main",
296
+ "status": "orchestrating",
297
+ "claude_pid": null
298
+ },
299
+ "feature-auth": {
300
+ "path": "/path/to/project-feature-auth",
301
+ "branch": "feature/auth",
302
+ "status": "in_progress",
303
+ "claude_pid": 12345,
304
+ "started_at": "2026-01-19T10:00:00Z",
305
+ "task": "Implement user authentication"
306
+ },
307
+ "testing": {
308
+ "path": "/path/to/project-testing",
309
+ "branch": "main",
310
+ "status": "watching",
311
+ "claude_pid": 12346,
312
+ "last_run": "2026-01-19T10:15:00Z"
313
+ }
314
+ },
315
+ "pending_merges": ["feature/auth"],
316
+ "active_streams": 3
317
+ }
318
+ ```
319
+
320
+ ### Dashboard Integration
321
+
322
+ The Loki dashboard shows worktree status:
323
+
324
+ ```
325
+ Parallel Streams:
326
+ [main] Orchestrating 3 active streams
327
+ [feature-auth] In Progress (45min) Auth implementation
328
+ [feature-api] Tests Running API endpoints
329
+ [testing] Watching Last run: 2 min ago
330
+ [docs] Idle Waiting for merges
331
+ ```
332
+
333
+ ---
334
+
335
+ ## Spawn Parallel Streams Script
336
+
337
+ ```bash
338
+ #!/bin/bash
339
+ # spawn-parallel.sh - Create and launch parallel work streams
340
+
341
+ PROJECT_DIR=$(pwd)
342
+ PROJECT_NAME=$(basename "$PROJECT_DIR")
343
+
344
+ # Parse features from PRD or task list
345
+ features=("auth" "api" "dashboard") # Or read from .loki/queue/
346
+
347
+ # Create feature worktrees
348
+ for feature in "${features[@]}"; do
349
+ worktree_path="../${PROJECT_NAME}-feature-${feature}"
350
+
351
+ if [ ! -d "$worktree_path" ]; then
352
+ git worktree add "$worktree_path" -b "feature/${feature}"
353
+
354
+ # Copy .loki state
355
+ cp -r .loki "$worktree_path/"
356
+
357
+ # Initialize environment
358
+ (cd "$worktree_path" && npm install 2>/dev/null)
359
+ fi
360
+
361
+ # Launch Claude session in background
362
+ (
363
+ cd "$worktree_path"
364
+ claude --dangerously-skip-permissions \
365
+ -p "Loki Mode: Implement ${feature}. Check .loki/CONTINUITY.md for context." \
366
+ >> ".loki/logs/session-${feature}.log" 2>&1
367
+ ) &
368
+
369
+ echo "Spawned: ${feature} (PID: $!)"
370
+ done
371
+
372
+ # Create testing worktree
373
+ testing_path="../${PROJECT_NAME}-testing"
374
+ if [ ! -d "$testing_path" ]; then
375
+ git worktree add "$testing_path" main
376
+ fi
377
+
378
+ # Create docs worktree
379
+ docs_path="../${PROJECT_NAME}-docs"
380
+ if [ ! -d "$docs_path" ]; then
381
+ git worktree add "$docs_path" main
382
+ fi
383
+
384
+ echo "Parallel streams initialized"
385
+ git worktree list
386
+ ```
387
+
388
+ ---
389
+
390
+ ## Optimistic Concurrency Control
391
+
392
+ > **Source:** [Cursor Scaling Learnings](../references/cursor-learnings.md) - file locking failed at scale
393
+
394
+ ### The Problem with Locks
395
+
396
+ Signal files (`.loki/signals/`) can create bottlenecks similar to file locking:
397
+ - Agents wait for signals to clear
398
+ - Deadlocks if agent fails while "holding" a signal
399
+ - Throughput drops as agent count increases
400
+
401
+ ### Optimistic Concurrency Pattern
402
+
403
+ ```yaml
404
+ optimistic_write:
405
+ 1_read:
406
+ action: "Read current state (no lock)"
407
+ example: "Read .loki/state/orchestrator.json"
408
+ capture: "state_version: 42"
409
+
410
+ 2_work:
411
+ action: "Perform work normally"
412
+ example: "Complete task, generate output"
413
+
414
+ 3_write_attempt:
415
+ action: "Attempt write with version check"
416
+ example: |
417
+ current_version=$(jq .version .loki/state/orchestrator.json)
418
+ if [ "$current_version" == "42" ]; then
419
+ # Version unchanged, safe to write
420
+ write_new_state_with_version_43
421
+ else
422
+ # State changed, retry from step 1
423
+ retry_with_backoff
424
+ fi
425
+
426
+ benefits:
427
+ - No waiting for locks
428
+ - No deadlock risk
429
+ - Failed writes are cheap (just retry)
430
+ - Scales to 100+ agents
431
+ ```
432
+
433
+ ### Implementation
434
+
435
+ ```bash
436
+ # Optimistic write function
437
+ optimistic_update_state() {
438
+ local file="$1"
439
+ local update_fn="$2"
440
+ local max_retries=5
441
+ local retry=0
442
+
443
+ while [ $retry -lt $max_retries ]; do
444
+ # Read current version
445
+ local version=$(jq -r '.version // 0' "$file" 2>/dev/null || echo "0")
446
+
447
+ # Apply update
448
+ local new_content=$($update_fn "$file")
449
+
450
+ # Attempt atomic write with version check
451
+ local current_version=$(jq -r '.version // 0' "$file" 2>/dev/null || echo "0")
452
+
453
+ if [ "$current_version" == "$version" ]; then
454
+ # Version unchanged, safe to write
455
+ echo "$new_content" | jq ".version = $((version + 1))" > "$file.tmp"
456
+ mv "$file.tmp" "$file"
457
+ return 0
458
+ fi
459
+
460
+ # Version changed, retry with backoff
461
+ retry=$((retry + 1))
462
+ sleep $((retry * 2))
463
+ done
464
+
465
+ return 1 # Failed after max retries
466
+ }
467
+ ```
468
+
469
+ ### When to Use
470
+
471
+ | Coordination Type | Use Case | Recommendation |
472
+ |-------------------|----------|----------------|
473
+ | Signal files | <10 agents | OK, simple |
474
+ | Signal files | 10-50 agents | Monitor for bottlenecks |
475
+ | Optimistic concurrency | 50+ agents | Required for scale |
476
+ | Git-based coordination | Cross-worktree | Use git commits as versions |
477
+
478
+ ---
479
+
480
+ ## Limitations and Considerations
481
+
482
+ ### When NOT to Use Worktrees
483
+
484
+ - **Tightly coupled features** - If Feature A and B touch same files constantly, merge conflicts will be painful
485
+ - **Small projects** - Overhead not worth it for simple tasks
486
+ - **Single-file changes** - Task tool parallelism is sufficient
487
+
488
+ ### Merge Conflict Resolution
489
+
490
+ ```yaml
491
+ conflict_strategy:
492
+ prevention:
493
+ - Assign non-overlapping file ownership
494
+ - Use feature flags for shared code
495
+ - Coordinate via .loki/state/locks/
496
+
497
+ resolution:
498
+ - Auto-merge if changes are additive
499
+ - For conflicts: pause feature, resolve manually
500
+ - After resolution: checkpoint and continue
501
+ ```
502
+
503
+ ### Resource Considerations
504
+
505
+ ```yaml
506
+ resource_limits:
507
+ max_worktrees: 5 # More = more disk space
508
+ max_claude_sessions: 3 # API rate limits
509
+ max_parallel_agents: 10 # Per session
510
+ ```
511
+
512
+ ---
513
+
514
+ ## Integration with Existing Patterns
515
+
516
+ | Existing Pattern | Worktree Enhancement |
517
+ |------------------|---------------------|
518
+ | 3 parallel reviewers | Run in testing worktree |
519
+ | Haiku parallelization | Within each worktree session |
520
+ | Batch API | Batch across all worktrees |
521
+ | Context management | Fresh context per worktree |
522
+ | CONTINUITY.md | Per-worktree continuity |
523
+
524
+ ---
525
+
526
+ **v4.1.0 | Parallel Workflows Module**
@@ -0,0 +1,188 @@
1
+ # Advanced Patterns
2
+
3
+ ## Problem Classification with Expert Hints (OptiMind Pattern)
4
+
5
+ **Classify problems before solving. Apply domain-specific expert hints.**
6
+
7
+ ```yaml
8
+ problem_classification:
9
+ categories:
10
+ crud_operations:
11
+ hints:
12
+ - "Check for existing similar endpoints before creating new"
13
+ - "Ensure proper input validation and error handling"
14
+ - "Follow RESTful conventions for HTTP methods"
15
+ common_errors:
16
+ - "Missing input validation"
17
+ - "Inconsistent error response format"
18
+
19
+ authentication:
20
+ hints:
21
+ - "Never store plain text passwords"
22
+ - "Use established libraries (bcrypt, argon2)"
23
+ - "Implement rate limiting on auth endpoints"
24
+ common_errors:
25
+ - "Token expiration not handled"
26
+ - "Missing CSRF protection"
27
+
28
+ database_operations:
29
+ hints:
30
+ - "Always use parameterized queries"
31
+ - "Consider indexing for frequent queries"
32
+ - "Handle connection pooling"
33
+ common_errors:
34
+ - "N+1 query patterns"
35
+ - "Missing transaction boundaries"
36
+
37
+ frontend_components:
38
+ hints:
39
+ - "Consider accessibility from the start"
40
+ - "Handle loading and error states"
41
+ - "Implement proper form validation"
42
+ common_errors:
43
+ - "Missing aria labels"
44
+ - "Unhandled async state"
45
+
46
+ infrastructure:
47
+ hints:
48
+ - "Use environment variables for config"
49
+ - "Implement health check endpoints"
50
+ - "Consider horizontal scaling"
51
+ common_errors:
52
+ - "Hardcoded secrets"
53
+ - "Missing graceful shutdown"
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Ensemble Solution Generation (OptiMind Pattern)
59
+
60
+ **For complex problems, generate multiple solutions and select by consensus.**
61
+
62
+ ```yaml
63
+ ensemble_approach:
64
+ when_to_use:
65
+ - Architecture decisions with multiple valid approaches
66
+ - Performance optimization with unclear bottlenecks
67
+ - Security-sensitive implementations
68
+ - Refactoring with multiple strategies
69
+
70
+ workflow:
71
+ 1. Generate 3 distinct solutions (different approaches)
72
+ 2. Evaluate each against criteria (performance, maintainability, security)
73
+ 3. Select by consensus or weighted scoring
74
+ 4. Document why alternatives were rejected
75
+
76
+ example:
77
+ task: "Implement caching for API responses"
78
+ solutions:
79
+ - Redis with TTL-based invalidation
80
+ - In-memory LRU cache
81
+ - HTTP cache headers + CDN
82
+ selection: "Redis - best for distributed deployment"
83
+ rejected_reasons:
84
+ - "In-memory: doesn't scale horizontally"
85
+ - "CDN: requires infrastructure changes"
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Formal State Machines (k8s-valkey-operator Pattern)
91
+
92
+ **Explicit phase transitions with defined states. No ambiguous states.**
93
+
94
+ ```yaml
95
+ sdlc_state_machine:
96
+ states:
97
+ - BOOTSTRAP
98
+ - DISCOVERY
99
+ - ARCHITECTURE
100
+ - INFRASTRUCTURE
101
+ - DEVELOPMENT
102
+ - QA
103
+ - DEPLOYMENT
104
+ - GROWTH
105
+
106
+ transitions:
107
+ BOOTSTRAP -> DISCOVERY: "Project structure created, dependencies installed"
108
+ DISCOVERY -> ARCHITECTURE: "PRD analyzed, requirements documented"
109
+ ARCHITECTURE -> INFRASTRUCTURE: "System design approved, API spec complete"
110
+ INFRASTRUCTURE -> DEVELOPMENT: "Cloud resources provisioned, DB schema applied"
111
+ DEVELOPMENT -> QA: "All features implemented, unit tests passing"
112
+ QA -> DEPLOYMENT: "All tests passing, security scan clean"
113
+ DEPLOYMENT -> GROWTH: "Production deployed, monitoring active"
114
+
115
+ invariants:
116
+ - "Cannot skip phases"
117
+ - "Phase completion requires all quality gates"
118
+ - "Rollback preserves state consistency"
119
+
120
+ idempotent_operations:
121
+ principle: "All operations safe under retry"
122
+ patterns:
123
+ - "Check state before modifying"
124
+ - "Use upsert instead of insert"
125
+ - "Kubernetes-style reconciliation loops"
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Constitutional AI Self-Critique (Anthropic)
131
+
132
+ ```yaml
133
+ constitution:
134
+ core_principles:
135
+ - "Never sacrifice quality for velocity"
136
+ - "Verify before trusting"
137
+ - "Learn from every failure"
138
+ - "Maintain state consistency"
139
+ - "Protect user data and secrets"
140
+
141
+ self_critique_workflow:
142
+ 1. Generate solution
143
+ 2. Critique against principles
144
+ 3. Identify violations
145
+ 4. Revise to address violations
146
+ 5. Re-critique until compliant
147
+ ```
148
+
149
+ ---
150
+
151
+ ## Debate-Based Verification (DeepMind)
152
+
153
+ **For critical changes, use structured debate between AI critics.**
154
+
155
+ ```
156
+ Proponent (defender) --> Presents proposal with evidence
157
+ |
158
+ v
159
+ Opponent (challenger) --> Finds flaws, challenges claims
160
+ |
161
+ v
162
+ Synthesizer --> Weighs arguments, produces verdict
163
+ |
164
+ v
165
+ If disagreement persists --> Escalate to human
166
+ ```
167
+
168
+ **Use for:** Architecture decisions, security-sensitive changes, major refactors.
169
+
170
+ ---
171
+
172
+ ## Code-Only Agent Pattern (rijnard.com)
173
+
174
+ **Enforce execution through code, creating verifiable "code witnesses".**
175
+
176
+ ```yaml
177
+ code_only_principle:
178
+ benefit: "Produces executable, verifiable behavior traces"
179
+
180
+ patterns:
181
+ - Return small outputs (<1KB) inline
182
+ - Write large results to JSON files with path references
183
+ - Use dynamic languages (Python, TypeScript) for native runtime injection
184
+
185
+ enforcement:
186
+ - Tool PreHooks to catch banned operations
187
+ - Initial prompting toward code-generation patterns
188
+ ```