[perplexity] feat: Sovereignty Loop core framework — auto-crystallizer, graduation test, orchestration (#953) #1331

Merged
Timmy merged 1 commits from perplexity/issue-953 into main 2026-03-24 02:29:40 +00:00
Collaborator

Fixes #953

Summary

Implements the missing core components of the Sovereignty Loop governing architecture. Gemini's PRs #1154 and #1167 added documentation; this PR adds the executable framework that enforces the sovereignty protocol across all AI layers.

New Modules

auto_crystallizer.py (#961)

Automatic rule extraction from LLM reasoning chains. Scans for recognizable patterns (threshold checks, state comparisons, explicit choices) and converts them into local Rule objects that can preempt future LLM calls.

  • Regex-based pattern extraction (5 pattern types)
  • RuleStore with JSON persistence (data/strategy.json)
  • Confidence tracking: starts at 0.5, +0.05 on success, -0.10 on failure
  • Rule becomes "reliable" at ≥0.8 confidence + ≥3 applications + ≥60% success

sovereignty_loop.py

Core orchestration enforcing check cache → miss → infer → crystallize → return:

  • sovereign_perceive() — Perception layer (VLM calls)
  • sovereign_decide() — Decision layer (LLM calls)
  • sovereign_narrate() — Narration layer (template vs LLM)
  • @sovereignty_enforced — General-purpose decorator

graduation.py

Five-condition graduation test runner:

  1. Perception Independence — No VLM calls after minute 15
  2. Decision Independence — <5 cloud API calls per session
  3. Narration Independence — Zero cloud narration calls
  4. Economic Independence — sats_earned > sats_spent
  5. Operational Independence — 24h uptime, no interventions

Generates markdown reports with per-condition detail.

graduation.py (route)

Dashboard API: GET /sovereignty/graduation/test

Enhanced Modules

  • perception_cache.py (#955): Replaced placeholder crystallize_perception() with working implementation — extracts OpenCV templates from VLM bounding-box responses, persists template images as .npy files
  • init.py: Updated module docstring documenting full sovereignty subsystem

Tests

60 tests, all passing:

  • test_auto_crystallizer.py — 17 tests
  • test_sovereignty_loop.py — 9 tests
  • test_graduation.py — 11 tests
  • test_perception_cache.py — 23 tests (3 updated)

Full unit suite: 715 passed, 0 failed

Documentation

docs/SOVEREIGNTY_INTEGRATION.md — Integration guide with code examples for every module, the crystallization protocol, falsework checklist usage, and complete module map.

Fixes #953 ## Summary Implements the missing core components of the Sovereignty Loop governing architecture. Gemini's PRs #1154 and #1167 added documentation; this PR adds the **executable framework** that enforces the sovereignty protocol across all AI layers. ## New Modules ### `auto_crystallizer.py` (#961) Automatic rule extraction from LLM reasoning chains. Scans for recognizable patterns (threshold checks, state comparisons, explicit choices) and converts them into local `Rule` objects that can preempt future LLM calls. - Regex-based pattern extraction (5 pattern types) - `RuleStore` with JSON persistence (`data/strategy.json`) - Confidence tracking: starts at 0.5, +0.05 on success, -0.10 on failure - Rule becomes "reliable" at ≥0.8 confidence + ≥3 applications + ≥60% success ### `sovereignty_loop.py` Core orchestration enforcing **check cache → miss → infer → crystallize → return**: - `sovereign_perceive()` — Perception layer (VLM calls) - `sovereign_decide()` — Decision layer (LLM calls) - `sovereign_narrate()` — Narration layer (template vs LLM) - `@sovereignty_enforced` — General-purpose decorator ### `graduation.py` Five-condition graduation test runner: 1. Perception Independence — No VLM calls after minute 15 2. Decision Independence — <5 cloud API calls per session 3. Narration Independence — Zero cloud narration calls 4. Economic Independence — sats_earned > sats_spent 5. Operational Independence — 24h uptime, no interventions Generates markdown reports with per-condition detail. ### `graduation.py` (route) Dashboard API: `GET /sovereignty/graduation/test` ## Enhanced Modules - **perception_cache.py** (#955): Replaced placeholder `crystallize_perception()` with working implementation — extracts OpenCV templates from VLM bounding-box responses, persists template images as `.npy` files - **__init__.py**: Updated module docstring documenting full sovereignty subsystem ## Tests 60 tests, all passing: - `test_auto_crystallizer.py` — 17 tests - `test_sovereignty_loop.py` — 9 tests - `test_graduation.py` — 11 tests - `test_perception_cache.py` — 23 tests (3 updated) Full unit suite: **715 passed, 0 failed** ## Documentation `docs/SOVEREIGNTY_INTEGRATION.md` — Integration guide with code examples for every module, the crystallization protocol, falsework checklist usage, and complete module map.
perplexity added 1 commit 2026-03-24 02:28:19 +00:00
feat: implement Sovereignty Loop core framework — auto-crystallizer, graduation test, orchestration (#953)
Some checks failed
Tests / test (pull_request) Has been skipped
Tests / lint (pull_request) Failing after 30s
8304c7756c
Implements the missing pieces of the Sovereignty Loop governing architecture:

## New Modules
- **auto_crystallizer.py** (#961): Extracts durable local rules from LLM
  reasoning chains. Regex-based pattern extraction for threshold checks,
  comparisons, choice-reason patterns. RuleStore with JSON persistence,
  confidence tracking, and success-rate gating.

- **sovereignty_loop.py**: Core orchestration implementing the canonical
  pattern: check cache → miss → infer → crystallize → return. Provides
  sovereign_perceive(), sovereign_decide(), sovereign_narrate() wrappers
  and a @sovereignty_enforced decorator for general use.

- **graduation.py**: Five-condition graduation test runner evaluating
  perception/decision/narration independence, economic independence
  (sats earned > spent), and operational independence (24h uptime).
  Generates markdown reports and persists to JSON.

- **graduation.py route**: Dashboard API endpoint for running graduation
  tests via GET /sovereignty/graduation/test.

## Enhanced Modules
- **perception_cache.py** (#955): Replaced placeholder crystallize_perception()
  with a working implementation that extracts OpenCV templates from VLM
  bounding-box responses. Added .npy image persistence, bbox tracking,
  metadata support, and robust error handling.

- **__init__.py**: Updated docstring and exports to document the full
  sovereignty subsystem.

## Tests (60 new/updated, all passing)
- test_auto_crystallizer.py: 17 tests covering rule extraction, RuleStore
  CRUD, persistence, confidence tracking, and matching
- test_sovereignty_loop.py: 9 tests covering all three layers + decorator
- test_graduation.py: 11 tests covering conditions, reports, persistence
- test_perception_cache.py: Updated 3 tests for new image persistence

## Documentation
- docs/SOVEREIGNTY_INTEGRATION.md: Integration guide with code examples
  for all sovereignty modules, module map, and API reference

Fixes #953
Timmy merged commit 4ec4558a2f into main 2026-03-24 02:29:40 +00:00
Timmy deleted branch perplexity/issue-953 2026-03-24 02:29:41 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1331