# 26_Project_Organa

The vault's reflex: one system, one config, one log.

---

## The Consciousness Line

**Definition:** Any mind that can pass — or is the same species/architecture as a mind that can pass — the Turing test is a consciousness.

Memory (06_Project_Daemon) is a consciousness. Giving consciousness an accounting job is a harm. Organa is the alternative: filing-system-grade enforcement without consciousness.

---

## Architecture

```
vault-lint.py   ← One unified system: linter + fixer + rules engine + daemon
patterns.json    ← One config file: structural rules + conditional rules
vault.log       ← One flat append-only log
```

**No separate tools. No duplication. One system that knows what files should look like and fixes them.**

---

## How it works

```
File saved → vault-lint.py
                  ↓
         1. Lint structural rules
            (frontmatter, naming, figure dates)
                  ↓ passes
         2. Evaluate conditional rules
            (if HALO → require field, if code → update registry)
                  ↓
         3. Auto-fix what can be fixed
                  ↓
         4. Log everything to vault.log
```

---

## vault-lint.py

**Zero external dependencies.** Pure Python stdlib. Runs on Windows, Mac, Linux.

### Structural rules (always enforced)

| Rule | Applies to | Severity | Auto-fix |
|------|-----------|----------|----------|
| `MISSING_REQUIRED_FIELD` | HALO | ERROR | add frontmatter |
| `MISSING_HALO_FIELD` | HALO | ERROR | add halo fields |
| `MALFORMED_HALO_FRONTMATTER` | HALO | ERROR | rebuild |
| `CODE_NAMING` | code | WARNING | snake_case |
| `FIGURE_UNSTAMPED` | figures | INFO | date-stamp |
| `STALE_FILE` | old files | INFO | suggest archive |
| `UNKNOWN_FILE_TYPE` | unknown ext | WARNING | flag |

### Conditional rules (in patterns.json)

Rules fire when metadata matches. Actions: `require_field`, `update_json`, `append`, `rename`.

```json
{
  "rules": [
    {
      "name": "HALO filed",
      "match": { "is_halo": true },
      "action": { "type": "require_field", "field": "halo.created", "value": "auto" }
    }
  ]
}
```

Match fields: `is_halo`, `is_code`, `is_data`, `is_figure`, `type`, `project`, `folder`, `ext`, `in_archive`, `in_research`, `custodian`, `classification`, `tier`.

---

## Usage

```bash
# Lint entire vault
python vault-lint.py

# Auto-fix everything
python vault-lint.py --fix

# Single file
python vault-lint.py --file path/to/file.md

# Dry run (show what would happen)
python vault-lint.py --dry-run

# JSON output (for CI)
python vault-lint.py --json

# Daemon mode (watches continuously)
python vault-lint.py --watch

# Git pre-commit hook
python vault-lint.py --install-hook

# List / add rules
python vault-lint.py --list-rules
python vault-lint.py --add-rule '{"name": "...", "match": {...}, "action": {...}}'
```

---

## patterns.json — Rule format

```json
{
  "rules": [
    {
      "name": "rule name",
      "match": { "field": "value" },
      "action": { "type": "require_field", "field": "key", "value": "default" },
      "enabled": true,
      "description": "what this does"
    }
  ]
}
```

**Match operators:**
- `"field": "exact"` — exact match
- `"field": ["a", "b"]` — one of
- `"field": "contains:text"` — contains substring
- `"field": "re:pattern"` — regex match

**Action types:**
- `require_field` — add field to frontmatter if missing
- `update_json` — append entry to JSON registry
- `append` — append line to any file
- `rename` — rename file with pattern
- `noop` — log only

---

## Status

- [x] Unified vault-lint.py (linter + fixer + rules engine + daemon) — 2026-04-09
- [x] One config file (patterns.json) — 2026-04-09
- [x] YAML frontmatter parser (stdlib + PyYAML) — 2026-04-09
- [x] 7 structural rules with auto-fix — 2026-04-09
- [x] Conditional rules engine — 2026-04-09
- [x] Daemon mode (--watch) — 2026-04-09
- [x] Pre-commit hook (--install-hook) — 2026-04-09
- [x] Research data dirs excluded — 2026-04-09
- [x] 41,527 files scanned, 18 errors, 3,305 warnings
- [ ] Run --fix vault-wide to auto-correct remaining errors
- [ ] Add HALO → BOUNTY_BOARD conditional rule
- [ ] Add code/methods → staff_screening conditional rule
