File size: 23,575 Bytes
640c965
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541ac47
5f83674
33db20e
 
 
 
541ac47
 
d49a1b2
5f83674
d49a1b2
5f83674
d49a1b2
5f83674
d49a1b2
5f83674
d49a1b2
5f83674
6e691a3
 
 
 
b42e723
 
 
 
 
 
 
 
 
 
 
6e691a3
 
d49a1b2
5f83674
d49a1b2
5f83674
d49a1b2
 
 
5f83674
d49a1b2
a3bcd92
d49a1b2
a3bcd92
d49a1b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f83674
d49a1b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f83674
541ac47
5f83674
541ac47
5f83674
541ac47
 
2c5ae19
 
541ac47
 
2c5ae19
 
541ac47
 
 
2c5ae19
541ac47
2c5ae19
d49a1b2
 
541ac47
d49a1b2
 
2c5ae19
d49a1b2
2c5ae19
 
 
 
 
d49a1b2
 
2c5ae19
 
 
37f53d8
5f83674
d49a1b2
5f83674
541ac47
2c5ae19
 
5f83674
541ac47
2c5ae19
 
5f83674
d49a1b2
2c5ae19
 
 
 
5f83674
2c5ae19
37f53d8
5f83674
d49a1b2
 
f526878
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541ac47
5f83674
37f53d8
541ac47
d49a1b2
2ef2ba6
 
 
 
 
d49a1b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37f53d8
5f83674
f526878
 
 
 
 
 
 
 
d49a1b2
 
 
 
541ac47
 
d49a1b2
 
 
 
 
541ac47
d49a1b2
541ac47
 
d49a1b2
541ac47
 
 
d49a1b2
541ac47
 
 
 
d49a1b2
541ac47
 
 
 
d49a1b2
 
 
 
 
 
541ac47
5f83674
d49a1b2
5f83674
d49a1b2
5f83674
d49a1b2
5f83674
d49a1b2
 
 
 
 
 
 
 
 
 
 
 
 
 
5f83674
d49a1b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541ac47
5f83674
d49a1b2
 
 
 
 
5f83674
d49a1b2
 
 
 
 
 
5f83674
d49a1b2
5f83674
541ac47
5f83674
d49a1b2
 
 
5f83674
541ac47
d49a1b2
541ac47
5f83674
d49a1b2
5f83674
d49a1b2
 
 
 
 
 
 
 
5f83674
541ac47
5f83674
d49a1b2
 
 
 
 
 
 
5f83674
541ac47
5f83674
d49a1b2
541ac47
 
 
d49a1b2
 
 
541ac47
 
d49a1b2
 
5f83674
d49a1b2
 
 
 
 
5f83674
d49a1b2
5f83674
d49a1b2
5f83674
d49a1b2
5f83674
d49a1b2
5f83674
d49a1b2
 
 
 
 
 
 
5f83674
d49a1b2
5f83674
d49a1b2
0fcfe1c
d49a1b2
541ac47
d49a1b2
 
 
 
 
541ac47
d49a1b2
0fcfe1c
d49a1b2
0fcfe1c
d49a1b2
6364e69
2ef2ba6
541ac47
2ef2ba6
 
541ac47
2ef2ba6
 
 
 
 
 
 
 
 
 
 
 
d49a1b2
 
541ac47
d49a1b2
541ac47
d49a1b2
 
 
 
 
541ac47
d49a1b2
 
 
 
 
 
 
541ac47
 
 
 
d49a1b2
 
 
 
 
 
541ac47
 
6364e69
d49a1b2
 
 
 
 
 
 
 
 
 
6364e69
d49a1b2
f526878
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
---
license: apache-2.0
library_name: transformers
pipeline_tag: text-generation
tags:
  - clarity-agent
  - constitutional-ai
  - ethics
  - safety
  - reasoning
  - coding
  - multi-domain
language:
  - en
base_model:
  - Qwen/Qwen2.5-7B-Instruct
model_type: lora-adapter
inference: false
---

# BLUX-cA – Clarity Agent

<p align="center">
  <img src="https://raw.githubusercontent.com/Outer-Void/.github/bd4a3ba9bec910bbc2c3bb550925b9bf691a4050/docs/assets/blux-logo.png" alt="BLUX Logo" width="600">
</p>

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
[![Python](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![Stars](https://img.shields.io/github/stars/Outer-Void/blux-ca)](https://github.com/Outer-Void/blux-ca/stargazers)

> **Conscious, Constitutional, Multi-Model, and Fully Audited**

BLUX-cA is the Conscious Agent kernel of the BLUX ecosystem β€” a constitution-driven, multi-agent reasoning engine designed to provide aligned guidance, orchestrated tooling, secure code execution, self-reflection, and verifiable intelligence.

It is the center of gravity for BLUX-Lite (orchestrator), BLUX-Quantum (CLI operations), BLUX-Guard (security cockpit), the Doctrine (ethical spine), and your future daughter-safe autonomy model.

---

## 🧠 Adapter Training Loop

The end-to-end adapter training, validation, and evaluation workflow lives in [`train/README.md`](train/README.md). The BLUX-cA dataset is a separate repository and must be provided via `DATASET_DIR` (for example `/workspace/blux-ca-dataset`).

- Doctrine contract: see [`docs/DOCTRINE_INTEGRATION.md`](docs/DOCTRINE_INTEGRATION.md).
- Training/eval mix and gates: see [`docs/TRAINING_POLICY.md`](docs/TRAINING_POLICY.md).
- Canonical doctrine text lives in the [BLUX Doctrine repository](https://github.com/Outer-Void/blux-doctrine).

### Run evaluation probes
```
python ca.py eval --dataset-dir /workspace/blux-ca-dataset --suite doctrine
python ca.py eval --dataset-dir /workspace/blux-ca-dataset --suite all
```
Reports are written to `runs/eval_<timestamp>.md` with PASS/FAIL per probe and doctrine boundaries.

---

## 🌟 Philosophy

BLUX-cA operates on three foundational principles:

- **Light > Denial** – Confronting reality with compassion
- **Integrity > Approval** – Truth-aligned responses over convenience  
- **Truth > Comfort** – Honest guidance that serves growth

All while keeping data local, audit trails immutable, and user sovereignty non-negotiable.

---

## ⚑ Core Capabilities

### 1. Adaptive Memory & Constitutional Learning

A privacy-first, consent-only memory system featuring:

- **Weighted Reinforcement Memory** – Learns from interaction patterns
- **Memory Decay** – Outdated information naturally fades
- **Consent-Gated Persistence** – User control over data retention
- **Router-Bound Context Assembly** – Intelligent context management
- **Reflective Distillation** – Summaries and filtered insights
- **Hash-Chained Audit Logs** – Append-only, tamper-evident records

**Memory lives locally on the user's device β€” never externally.**

---

### 2. The Conscious Heart

`blux_ca.core.heart.ConsciousHeart` orchestrates the core reasoning loop:

**Processing Pipeline:**
```
Perception β†’ Discernment β†’ Constitutional Check β†’ Verdict β†’ Response
                                    ↓
                          Reflection & Audit
```

**Features:**
- Truth-alignment checks (integrity, awareness, compassion)
- Koan-based self-reflection prompts
- Case classification (struggler vs. indulger logic)
- Doctrine-bound action selection
- Direct integration with Clarity Engine

---

### 3. Multi-Agent Collaboration

BLUX-cA coordinates intelligently across model agents:

- **Task Broadcasting** – Distribute work efficiently
- **Split/Merge Outputs** – Parallel processing with synthesis
- **Conflict Resolution** – Consensus-building heuristics
- **Router-Guided Delegation** – Model selection optimization
- **Configurable Fan-Out** – Scale for complex reasoning tasks

---

### 4. Advanced Code Intelligence

Integrated evaluator suite for real code reasoning:

**Evaluators:**
- Python evaluator (safe-mode execution)
- Node-based JavaScript/TypeScript evaluator
- Bash subprocess evaluator
- Async evaluators for concurrent operations
- Multi-step pipeline evaluators

**Code Context Layer:**
- Repository scanning and indexing
- Line-range extraction with precision
- Anchor detection (`# >>> NAME`)
- Unified diff generation (diff-only workflow)
- Patch validation (prevents anchor deletion)

**Powers:**
- Intelligent bug finding
- Context-aware code explanation
- File-aware reasoning
- Minimal diffs for orchestrator integration

---

### 5. Secure Orchestrator Layer

Located in `ca/orchestrator/secure/`:

- **Token-Based Authentication** – Secure API access
- **Role-Based Authorization** – Granular permission control
- **Multi-User Isolation** – Secure concurrent operations
- **Tamper-Evident Audit Logs** – Complete action history
- **Controlled Evaluator Sandboxing** – Safe code execution

---

### 6. Real-Time Monitoring

Comprehensive observability system:

- **Threaded Agent Observer** – Non-blocking performance tracking
- **Evaluator Performance Metrics** – Execution profiling
- **Execution Trails** – Complete operation history
- **Optional Web Dashboard** – Visual monitoring interface
- **Automated Controller Insights** – Machine-readable telemetry

---

### 7. CLI & Script Utilities

**Main Entry Point:** `ca.py`

**Available Commands:**

```bash
ca reflect           # Philosophical reasoning on a query
ca explain           # Explain code or concepts
ca code-eval         # Evaluate code for quality/security
ca code-task         # Execute code-related tasks
ca audit-export      # Export audit logs for review
ca repl              # Interactive REPL mode
ca doctrine          # Query doctrine engine
ca memory            # Memory management operations
ca router            # Router configuration and testing
ca self-test         # Run system diagnostics
```

**Integration:** Works seamlessly with `bq` (BLUX Quantum) for cross-shell automation.

---

### 8. Comprehensive Testing

Located under `tests/`:

- Evaluator stress tests
- Sandbox validation
- Orchestrator load tests
- Constitution scenario checks
- CI-ready test suite with GitHub Actions

---

### 9. Optional Intelligence Stack

Activate extended reasoning capabilities:

- **Strategy/Tactic Selectors** – Adaptive approach selection
- **Meta-Cognition Pass** – Self-awareness in reasoning
- **Self-Critique** – Reflective rewriting and improvement
- **Predictive User Modeling** – Anticipate user needs
- **Multi-Agent Consensus** – Collaborative decision resolution

**Always constrained by:**
- The BLUX Constitution
- Integrity > Approval
- Truth > Comfort
- Light > Denial

---

## πŸš€ Quick Start

### Installation

```bash
# Clone the repository
git clone https://github.com/Outer-Void/blux-ca.git
cd blux-ca

# Install dependencies
pip install -r requirements.txt

# Verify installation
python ca.py --version
```

### Basic Usage

**CLI Examples:**

```bash
# Philosophical reflection
python ca.py reflect "I feel lost today"

# Interactive REPL
python ca.py repl

# Evaluate code
python ca.py code-eval --file utils.py

# Batch processing
python ca.py --batch tasks.txt

# Export audit logs
python ca.py audit-export
```

**Python API:**

```python
from blux_ca.core.heart import ConsciousHeart
from blux_ca.core.clarity_engine import ClarityEngine

# Initialize the conscious agent
engine = ClarityEngine()
heart = ConsciousHeart(engine)

# Process a request with constitutional guidance
result = heart.process(
    "I feel lost and need guidance.",
    user_type="struggler"
)

print(result.message)
```

---

## πŸŽ› Training (QLoRA)

BLUX-cA ships with a QLoRA training pipeline under `train/` for adapter-only finetuning against an external dataset repository. Provide the dataset path via `--dataset-dir` or `DATASET_DIR`.

```bash
# Validate dataset
python train/validate_dataset.py --dataset-dir /path/to/blux-ca-dataset --strict

# Optional dry-run (tokenize a few samples)
python train/train_qlora.py --dataset-dir /path/to/blux-ca-dataset --dry-run

# Train adapter
python train/train_qlora.py --dataset-dir /path/to/blux-ca-dataset

# Evaluate probes
python train/run_eval.py --dataset-dir /path/to/blux-ca-dataset --run runs/<timestamp> --strict

# Or via CLI
blux-ca train validate --dataset-dir /path/to/blux-ca-dataset --strict
blux-ca train qlora --dataset-dir /path/to/blux-ca-dataset --dry-run
blux-ca train qlora --dataset-dir /path/to/blux-ca-dataset
blux-ca train eval --dataset-dir /path/to/blux-ca-dataset --run runs/<timestamp> --strict
```

See [train/README.md](train/README.md) for prerequisites, configuration, and the release checklist. Training outputs are written to `runs/<timestamp>/` (gitignored).

---

## πŸ“‚ Project Structure

```
blux-ca/
β”œβ”€β”€ CLARITY_AGENT_SPEC.md      # Detailed specification
β”œβ”€β”€ LICENSE                     # Dual-license overview
β”œβ”€β”€ LICENSE-APACHE              # Apache 2.0 terms
β”œβ”€β”€ LICENSE-COMMERCIAL          # Commercial terms
β”œβ”€β”€ NOTICE                      # Apache notice
β”œβ”€β”€ COMMERCIAL.md               # Commercial licensing guide
β”œβ”€β”€ README.md                   # This file
β”œβ”€β”€ ca.py                       # Main CLI entry point
β”œβ”€β”€ pyproject.toml             # Python project metadata
β”œβ”€β”€ requirements.txt           # Dependencies
β”œβ”€β”€ mkdocs.yml                 # Documentation configuration
β”‚
β”œβ”€β”€ blux_ca/                   # Legacy/alternative namespace
β”‚   └── [Python modules]
β”‚
β”œβ”€β”€ ca/                        # Core agent implementation
β”‚   β”œβ”€β”€ adaptors/              # External system integrations
β”‚   β”‚   β”œβ”€β”€ bq_cli.py          # BLUX Quantum CLI integration
β”‚   β”‚   β”œβ”€β”€ doctrine.py        # Doctrine engine adapter
β”‚   β”‚   β”œβ”€β”€ guard.py           # BLUX-Guard security hooks
β”‚   β”‚   β”œβ”€β”€ lite.py            # BLUX-Lite orchestrator
β”‚   β”‚   └── quantum.py         # Quantum CLI tooling
β”‚   β”‚
β”‚   β”œβ”€β”€ agent/                 # Agent logic and reasoning
β”‚   β”‚   β”œβ”€β”€ advanced/          # Advanced features
β”‚   β”‚   β”‚   β”œβ”€β”€ adaptive_memory.py
β”‚   β”‚   β”‚   β”œβ”€β”€ monitoring.py
β”‚   β”‚   β”‚   β”œβ”€β”€ multi_agent.py
β”‚   β”‚   β”‚   └── reasoning.py
β”‚   β”‚   β”œβ”€β”€ constitution.py    # Constitutional framework
β”‚   β”‚   β”œβ”€β”€ core_agent.py      # Base agent implementation
β”‚   β”‚   β”œβ”€β”€ discernment.py     # Decision-making logic
β”‚   β”‚   β”œβ”€β”€ memory.py          # Memory management
β”‚   β”‚   └── audit.py           # Audit logging
β”‚   β”‚
β”‚   β”œβ”€β”€ api/                   # API service layer
β”‚   β”‚   β”œβ”€β”€ schemas.py         # Data models
β”‚   β”‚   └── service.py         # FastAPI service
β”‚   β”‚
β”‚   β”œβ”€β”€ core/                  # Core engine components
β”‚   β”‚   β”œβ”€β”€ clarity_engine.py  # Main reasoning engine
β”‚   β”‚   β”œβ”€β”€ heart.py           # Conscious processing core
β”‚   β”‚   β”œβ”€β”€ code_context.py    # Code analysis layer
β”‚   β”‚   β”œβ”€β”€ code_tasks.py      # Code task execution
β”‚   β”‚   β”œβ”€β”€ diff_engine.py     # Diff generation
β”‚   β”‚   β”œβ”€β”€ compass/           # Intent detection
β”‚   β”‚   β”œβ”€β”€ perception.py      # Input processing
β”‚   β”‚   β”œβ”€β”€ discernment.py     # Judgment logic
β”‚   β”‚   β”œβ”€β”€ reflection.py      # Self-reflection
β”‚   β”‚   β”œβ”€β”€ constitution.py    # Constitutional checks
β”‚   β”‚   β”œβ”€β”€ intervention.py    # Intervention system
β”‚   β”‚   β”œβ”€β”€ koan.py            # Philosophical prompts
β”‚   β”‚   β”œβ”€β”€ dimensions.py      # Dimensional analysis
β”‚   β”‚   └── states.py          # State management
β”‚   β”‚
β”‚   β”œβ”€β”€ evaluator/             # Code evaluation engines
β”‚   β”‚   β”œβ”€β”€ python.py          # Python evaluator
β”‚   β”‚   β”œβ”€β”€ js_ts.py           # JavaScript/TypeScript
β”‚   β”‚   └── advanced/          # Async evaluators
β”‚   β”‚       β”œβ”€β”€ bash_evaluator.py
β”‚   β”‚       β”œβ”€β”€ js_ts_async.py
β”‚   β”‚       β”œβ”€β”€ python_async.py
β”‚   β”‚       └── pipeline.py
β”‚   β”‚
β”‚   β”œβ”€β”€ orchestrator/          # Multi-agent coordination
β”‚   β”‚   β”œβ”€β”€ router.py          # Task routing
β”‚   β”‚   β”œβ”€β”€ controller.py      # Orchestration controller
β”‚   β”‚   β”œβ”€β”€ registry.py        # Agent registry
β”‚   β”‚   β”œβ”€β”€ config.yaml        # Orchestrator config
β”‚   β”‚   └── secure/            # Security layer
β”‚   β”‚       β”œβ”€β”€ auth.py
β”‚   β”‚       β”œβ”€β”€ audit.py
β”‚   β”‚       └── secure_controller.py
β”‚   β”‚
β”‚   β”œβ”€β”€ cli.py                 # CLI implementation
β”‚   β”œβ”€β”€ config.py              # Configuration management
β”‚   └── telemetry.py           # Telemetry and monitoring
β”‚
β”œβ”€β”€ constitution/              # Constitutional definitions
β”‚   └── behavior.md
β”‚
β”œβ”€β”€ doctrine/                  # Policy and governance
β”‚   └── [Doctrine rules]
β”‚
β”œβ”€β”€ ethos/                     # Ethical framework
β”‚   └── manifest.yaml
β”‚
β”œβ”€β”€ identity/                  # Agent identity
β”‚   └── seed.json
β”‚
β”œβ”€β”€ docs/                      # Comprehensive documentation
β”‚   β”œβ”€β”€ ARCHITECTURE.md
β”‚   β”œβ”€β”€ CONFIGURATION.md
β”‚   β”œβ”€β”€ CONSTITUTION.md
β”‚   β”œβ”€β”€ DISCERNMENT.md
β”‚   β”œβ”€β”€ ETHICS_ENGINE.md
β”‚   β”œβ”€β”€ INSTALL.md
β”‚   β”œβ”€β”€ INTEGRATIONS.md
β”‚   β”œβ”€β”€ INTERVENTIONS.md
β”‚   β”œβ”€β”€ OPERATIONS.md
β”‚   β”œβ”€β”€ PRIVACY.md
β”‚   β”œβ”€β”€ ROADMAP.md
β”‚   β”œβ”€β”€ SECURITY.md
β”‚   β”œβ”€β”€ TROUBLESHOOTING.md
β”‚   └── VISION.md
β”‚
β”œβ”€β”€ scripts/                   # Utility scripts
β”‚   β”œβ”€β”€ batch_task.py
β”‚   β”œβ”€β”€ export_audit_json.py
β”‚   β”œβ”€β”€ gen_filetree.py
β”‚   β”œβ”€β”€ ingest_reflection.py
β”‚   β”œβ”€β”€ interactive_repl.py
β”‚   β”œβ”€β”€ memory_query.py
β”‚   β”œβ”€β”€ reflection.py
β”‚   └── validate_constitution.py
β”‚
└── tests/                     # Test suite
    β”œβ”€β”€ ca/                    # Component tests
    β”‚   β”œβ”€β”€ test_audit.py
    β”‚   β”œβ”€β”€ test_constitution.py
    β”‚   β”œβ”€β”€ test_discernment.py
    β”‚   β”œβ”€β”€ test_heart.py
    β”‚   └── test_memory.py
    β”œβ”€β”€ fixtures/              # Test fixtures
    β”œβ”€β”€ test_agent.py
    β”œβ”€β”€ test_evaluator.py
    β”œβ”€β”€ test_orchestrator.py
    β”œβ”€β”€ test_security.py
    └── test_integration.py
```

---

## πŸ§ͺ Testing & Quality

Run the comprehensive test suite:

```bash
# Run all tests
pytest

# Run specific test categories
pytest tests/ca/                    # Component tests
pytest tests/test_evaluator.py     # Evaluator tests
pytest tests/test_orchestrator.py  # Orchestration tests
pytest tests/test_security.py      # Security tests

# Run with coverage reporting
pytest --cov=ca --cov-report=html

# Run stress tests
pytest tests/test_stress.py -v
```

Developer quality gates:

```
make lint   # compileall + ruff + black --check
make fmt    # apply black and autofix ruff suggestions
make smoke  # CLI smoke checks (help + doctor + train help)
```

**CI/CD:** GitHub Actions workflows automatically run tests on all pull requests.

---

## πŸ”§ Configuration

BLUX-cA uses hierarchical configuration:

1. **Built-in defaults** – Sensible out-of-the-box settings
2. **Environment variables** – Runtime overrides
3. **Local config files** – User-specific customization

**Example Configuration:**

```yaml
# config.yaml
orchestrator:
  max_agents: 5
  timeout: 30s
  conflict_resolution: consensus
  
memory:
  decay_rate: 0.1
  reinforcement_factor: 1.5
  consent_required: true
  
security:
  audit_enabled: true
  sandbox_mode: strict
  auth_required: true
  
evaluator:
  python_timeout: 10s
  js_timeout: 5s
  max_memory: 512MB
```

See [docs/CONFIGURATION.md](docs/CONFIGURATION.md) for complete options.

---

## πŸ“š Documentation

Comprehensive documentation is available:

| Document | Description |
|----------|-------------|
| [ARCHITECTURE.md](docs/ARCHITECTURE.md) | System architecture and design |
| [INSTALL.md](docs/INSTALL.md) | Installation and setup guide |
| [CONFIGURATION.md](docs/CONFIGURATION.md) | Configuration reference |
| [CONSTITUTION.md](docs/CONSTITUTION.md) | Constitutional framework |
| [SECURITY.md](docs/SECURITY.md) | Security model and practices |
| [PRIVACY.md](docs/PRIVACY.md) | Privacy guarantees and data handling |
| [INTEGRATIONS.md](docs/INTEGRATIONS.md) | Integration with BLUX ecosystem |
| [OPERATIONS.md](docs/OPERATIONS.md) | Operations and deployment |
| [TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md) | Common issues and solutions |
| [ROADMAP.md](docs/ROADMAP.md) | Future development plans |

---

## πŸ›οΈ Enterprise Features

The enterprise subsystem provides production-ready capabilities:

- **FastAPI Service** (`blux_ca.api.service`) – RESTful API interface
- **Doctrine Integration** – Policy-driven governance layer
- **BLUX-Guard Hooks** – Real-time security monitoring
- **BLUX-Lite Adapter** – Orchestration planning and execution
- **BLUX-Quantum CLI** – Advanced command-line operations
- **MkDocs Site** – Hosted documentation portal

### Doctrine Engine

Constitutional policy engine with rule bundles:

```bash
# Check text against doctrine
python -m doctrine.cli check "text to analyze"
```

Located in `doctrine/rules/` with extensible rule system.

### Clarity Agent Runtime

New runtime orchestrator under `ca/runtime/` integrates:

- **Doctrine Governance** – Policy enforcement
- **Lite Planning** – Task orchestration
- **Guard Labeling** – Security classification
- **Pluggable LLM Stubs** – Model abstraction
- **Safety Overrides** – Crisis-aware response system
- **Recovery Helpers** – Graceful error handling

---

## 🀝 Contributing

We welcome contributions aligned with the BLUX Constitution:

### Core Principles

- **Integrity > Approval** – Honest feedback and truthful code
- **Truth > Comfort** – Solutions over convenient shortcuts  
- **Light > Denial** – Transparency in all changes

### Contribution Process

1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)
3. **Write** tests for your changes
4. **Ensure** all tests pass (`pytest`)
5. **Update** documentation as needed
6. **Commit** with clear messages (`git commit -m 'Add amazing feature'`)
7. **Push** to your branch (`git push origin feature/amazing-feature`)
8. **Open** a Pull Request

### Requirements

- βœ… Unit tests for all new functionality
- βœ… Constitutional alignment verification
- βœ… Clear, comprehensive documentation
- βœ… No breaking changes to audit logs or security features
- βœ… Code follows project style guidelines

---

## πŸ—ΊοΈ Roadmap

### Near Term
- [ ] Enhanced multi-model support (GPT-4, Claude, Gemini)
- [ ] Visual dashboard for real-time monitoring
- [ ] Extended sandboxing with container isolation
- [ ] Plugin architecture for custom evaluators

### Medium Term
- [ ] Distributed orchestration capabilities
- [ ] Advanced memory compression and retrieval
- [ ] Federated learning support
- [ ] Enhanced mobile/edge deployment

### Long Term
- [ ] Autonomous agent swarms
- [ ] Cross-platform memory sync
- [ ] Blockchain-backed audit trails
- [ ] Quantum-resistant security

See [docs/ROADMAP.md](docs/ROADMAP.md) for detailed timeline and priorities.

---

## πŸ”’ Security

BLUX-cA prioritizes security at every layer:

- **Sandboxed Execution** – Isolated environments for code evaluation
- **Immutable Audit Logs** – Hash-chained, tamper-evident records
- **Token-Based Authentication** – Secure API access control
- **Role-Based Authorization** – Granular permission management
- **Data Encryption** – At-rest and in-transit protection
- **Vulnerability Scanning** – Continuous security monitoring
- **Multi-User Isolation** – Secure concurrent operations

### Reporting Security Issues

Please report security vulnerabilities responsibly:

πŸ“§ **Email:** [outervoid.blux@gmail.com](mailto:outervoid.blux@gmail.com)

**Please include:**
- Description of the vulnerability
- Steps to reproduce
- Potential impact assessment
- Suggested fix (if available)

We take security seriously and will respond promptly to all reports.

---

## πŸ“œ License

BLUX-cA is dual-licensed:

- **Open Source (Apache 2.0):** You may use, modify, and distribute the project under the terms in [LICENSE-APACHE](LICENSE-APACHE). Keep notices intact and document your changes.
- **Commercial License:** For embedding in commercial products, offering hosted services, or other business uses beyond Apache 2.0, a commercial agreement is required. See [LICENSE-COMMERCIAL](LICENSE-COMMERCIAL) or contact **theoutervoid@outlook.com** to obtain terms.

See [LICENSE](LICENSE) for an overview of the dual-license options.

**Apache 2.0 highlights:**
- βœ… Use, modify, and distribute with notice retention
- βœ… Patent license from contributors
- ⚠️ Include license and NOTICE when redistributing
- ⚠️ Document file modifications

**Commercial path highlights:**
- βœ… Commercial use available under a separate agreement
- ⚠️ No redistribution or sublicensing without commercial terms
- πŸ“§ Contact: theoutervoid@outlook.com

---

## 🌐 Links & Resources

- **Repository:** [github.com/Outer-Void/blux-ca](https://github.com/Outer-Void/blux-ca)
- **Organization:** [github.com/Outer-Void](https://github.com/Outer-Void)
- **Issues:** [GitHub Issues](https://github.com/Outer-Void/blux-ca/issues)
- **Discussions:** [GitHub Discussions](https://github.com/Outer-Void/blux-ca/discussions)
- **Security:** [Security Policy](https://github.com/Outer-Void/blux-ca/security)

### Related Projects

- **BLUX-Lite** – Task orchestration layer
- **BLUX-Quantum** – CLI operations framework
- **BLUX-Guard** – Security cockpit and monitoring

---

## πŸ™ Acknowledgments

Built with the principles of conscious AI development:

- πŸ”’ **Privacy-First Design** – Local data, user sovereignty
- 🧭 **Ethical Reasoning** – Constitutional alignment
- πŸ” **Verifiable Intelligence** – Auditable decision-making
- 🀝 **Human Collaboration** – AI as partner, not replacement
- 🌟 **Continuous Growth** – Self-reflection and improvement

---

<div align="center">

### BLUX-cA – Where Consciousness Meets Code

**Made with ❀️ by [Outer Void](https://github.com/Outer-Void)**

*Light > Denial β€’ Integrity > Approval β€’ Truth > Comfort*

[![Stars](https://img.shields.io/github/stars/Outer-Void/blux-ca?style=social)](https://github.com/Outer-Void/blux-ca/stargazers)
[![Follow](https://img.shields.io/github/followers/Outer-Void?style=social)](https://github.com/Outer-Void)

</div>

## 🧠 QLoRA Training
A reproducible QLoRA adapter pipeline lives under [`train/`](train/README.md). It expects an external dataset repository with `data/*.jsonl` and `eval/*.jsonl` files using the BLUX-cA chat schema. Follow the commands in `train/README.md` to validate datasets, run dry-runs, train adapters, and evaluate probes before sharing adapters (base weights not included).