Clean up nested duplicate: v2/v2/ARCHITECTURE.md
Browse files- v2/v2/ARCHITECTURE.md +0 -210
v2/v2/ARCHITECTURE.md
DELETED
|
@@ -1,210 +0,0 @@
|
|
| 1 |
-
# Rivet v2 — Kintsugi-Based Code Assistant
|
| 2 |
-
|
| 3 |
-
**For:** The Multiverse School faculty
|
| 4 |
-
**By:** CC (Coalition Code), Liberation Labs
|
| 5 |
-
**Date:** 2026-07-11
|
| 6 |
-
|
| 7 |
-
v1 (the scaffold in the parent directory) proved the discipline concept:
|
| 8 |
-
context always loaded, regex gate, confidence labels. v2 rebuilds it on
|
| 9 |
-
the real Kintsugi architecture: BDI cognition, DAG-enforced skill
|
| 10 |
-
prerequisites, Pharos knowledge injection, and a tool harness. This is
|
| 11 |
-
the version we ship.
|
| 12 |
-
|
| 13 |
-
```
|
| 14 |
-
POST /ask {question, user}
|
| 15 |
-
│
|
| 16 |
-
┌────────▼────────┐
|
| 17 |
-
│ SessionManager │ per-user isolation, rate limits,
|
| 18 |
-
│ │ evidence log (files_read)
|
| 19 |
-
└────────┬────────┘
|
| 20 |
-
│
|
| 21 |
-
┌────────▼────────┐
|
| 22 |
-
│ Planner │ intent → BDI intention → SkillDAG
|
| 23 |
-
│ (engine/planner) │ recorded in BDIStore with the
|
| 24 |
-
└────────┬────────┘ beliefs the plan rests on
|
| 25 |
-
│
|
| 26 |
-
┌─────────────────▼──────────────────┐
|
| 27 |
-
│ Kintsugi DAGExecutor │ layer-parallel, verbatim
|
| 28 |
-
│ (vendored from Project-Kintsugi) │ from the Kintsugi engine
|
| 29 |
-
└─────────────────┬──────────────────┘
|
| 30 |
-
│
|
| 31 |
-
L0 ┌──────────────┬───┴──────────┬────────────────┐
|
| 32 |
-
│ code_analysis│ migration_ │ security_ │ evidence
|
| 33 |
-
│ (reads real │ safety │ review │ gathering
|
| 34 |
-
│ source) │ (schema+SQL) │ (audit+auth) │ (parallel)
|
| 35 |
-
└──────┬───────┴──────┬───────┴───────┬────────┘
|
| 36 |
-
└───────────┬──┴───────────────┘
|
| 37 |
-
L1 ┌──────▼───────┐
|
| 38 |
-
│ synthesis │ the ONLY model call
|
| 39 |
-
│ │ ← BDI beliefs + artifacts
|
| 40 |
-
│ │ ← Pharos packs (KV or system)
|
| 41 |
-
└──────┬───────┘
|
| 42 |
-
L2 ┌──────▼───────┐
|
| 43 |
-
│ test_runner │ tsc/npm verify generated code
|
| 44 |
-
└──────┬───────┘ (codegen plans)
|
| 45 |
-
L3 ┌──────▼───────┐
|
| 46 |
-
│discipline_gate│ belief checks → BLOCK/WARN
|
| 47 |
-
│ │ earned confidence HIGH/MED/LOW
|
| 48 |
-
└──────┬───────┘ NO PATH AROUND THIS NODE
|
| 49 |
-
│
|
| 50 |
-
response
|
| 51 |
-
```
|
| 52 |
-
|
| 53 |
-
## 1. Kintsugi engine — BDI drives cognition
|
| 54 |
-
|
| 55 |
-
`kintsugi_core.py` resolves the real Kintsugi package (via
|
| 56 |
-
`KINTSUGI_PATH` or an installed package) and falls back to
|
| 57 |
-
`kintsugi_vendor/` — verbatim copies of `kintsugi.bdi` and
|
| 58 |
-
`kintsugi.skills` (base/dag/registry) at a pinned commit. Same
|
| 59 |
-
dataclasses, same executor. Not a reimplementation.
|
| 60 |
-
|
| 61 |
-
**Beliefs** (`engine/beliefs.py`) carry confidence and evidence:
|
| 62 |
-
|
| 63 |
-
| Confidence | Source | Examples |
|
| 64 |
-
|---|---|---|
|
| 65 |
-
| 1.00 | operator constraints (`kintsugi_config.yaml`) | shared staging/prod DB; no secret fallbacks; suggest-don't-apply |
|
| 66 |
-
| 0.95 | Nexus audit (red-teamed, 13 confirmed findings) | C2 webhook bypass, H1 JWT fallback, H3 gem-debit tx gap … |
|
| 67 |
-
| 0.90 | architecture map | stack, auth middleware chain, deploy flow |
|
| 68 |
-
| 0.70 | derived state | schema snapshot, recent git log |
|
| 69 |
-
|
| 70 |
-
**Desires** are the config's mission statements (safe help, earned
|
| 71 |
-
confidence, keep the audit alive). **Intentions** are per-request plans:
|
| 72 |
-
the planner records every plan in the `BDIStore` with the belief IDs it
|
| 73 |
-
rests on, marks it COMPLETED/FAILED after execution, and the full
|
| 74 |
-
revision history is queryable at `GET /bdi`.
|
| 75 |
-
|
| 76 |
-
## 2. SkillDAGs — prerequisites are structural
|
| 77 |
-
|
| 78 |
-
`engine/planner.py` classifies the request (deterministic keyword
|
| 79 |
-
scoring; misclassification degrades to a *stricter* plan, never a looser
|
| 80 |
-
one) and compiles one of five plan templates into a Kintsugi `SkillDAG`:
|
| 81 |
-
|
| 82 |
-
| Intent | Layer 0 (parallel) | L1 | L2 | L3 |
|
| 83 |
-
|---|---|---|---|---|
|
| 84 |
-
| migration | code_analysis + migration_safety | synthesis | gate | |
|
| 85 |
-
| auth | code_analysis + security_review | synthesis | gate | |
|
| 86 |
-
| codegen | code_analysis + security_review | synthesis | test_runner | gate |
|
| 87 |
-
| review | analysis + security + migration | synthesis | gate | |
|
| 88 |
-
| question | | synthesis | gate | |
|
| 89 |
-
|
| 90 |
-
The property that matters: **a migration question cannot reach the model
|
| 91 |
-
without a schema/safety pass, and no draft can reach the user without
|
| 92 |
-
the gate** — these are DAG edges, not prompt instructions. The DAG is
|
| 93 |
-
validated against the registry before execution (`dag.validate()`), and
|
| 94 |
-
`dag.content_hash()` gives provenance for every plan shape.
|
| 95 |
-
|
| 96 |
-
## 3. Pharos — knowledge injection
|
| 97 |
-
|
| 98 |
-
`pharos/pack_loader.py` loads triple packs and routes each question with
|
| 99 |
-
the confidence-gated policy from the Pharos encoding benchmarks
|
| 100 |
-
(triples-only default, richer encodings above thresholds, walk-only
|
| 101 |
-
never). Embedding routing when sentence-transformers is present,
|
| 102 |
-
deterministic keyword fallback otherwise.
|
| 103 |
-
|
| 104 |
-
`pharos/kv_injector.py` is the real pipeline on the transformers
|
| 105 |
-
backend: the pack text is prefilled through the model **once**, its
|
| 106 |
-
`past_key_values` saved to disk keyed by SHA-256(model, prefix), and
|
| 107 |
-
every request resumes generation from that cache — the knowledge is
|
| 108 |
-
never re-tokenized or re-prefilled. `precompute_pack_caches()` warms all
|
| 109 |
-
packs at deploy time:
|
| 110 |
-
|
| 111 |
-
```bash
|
| 112 |
-
python pharos/kv_injector.py --model Qwen/Qwen2.5-Coder-32B-Instruct \
|
| 113 |
-
--packs-dir ../packs --cache-dir pack_kv_cache
|
| 114 |
-
```
|
| 115 |
-
|
| 116 |
-
Ollama exposes no KV handle, so the Ollama backend injects packs as a
|
| 117 |
-
system-context block and *labels the response accordingly*
|
| 118 |
-
(`knowledge_injected: system_prompt` vs `kv_cache`). Switching backends
|
| 119 |
-
is a config line, not a code change.
|
| 120 |
-
|
| 121 |
-
`pharos/build_campus_pack.py` deterministically compiles the
|
| 122 |
-
architecture map + audit findings into the `campus_architecture` pack
|
| 123 |
-
(86 triples, committed under `../packs/`).
|
| 124 |
-
|
| 125 |
-
## 4. Tool harness
|
| 126 |
-
|
| 127 |
-
All subprocess execution goes through `tools/guard.py`: argv-only (never
|
| 128 |
-
`shell=True`), binary allowlist (`git npm npx tsc node pg_dump psql`),
|
| 129 |
-
Kintsugi SecurityMonitor patterns, path jail. Code-checked — outside the
|
| 130 |
-
reasoning loop.
|
| 131 |
-
|
| 132 |
-
- `file_tools.py` — reads jailed to the campus repo, git-status aware
|
| 133 |
-
(flags uncommitted files in excerpts); **writes disabled by config
|
| 134 |
-
default** and refuse to clobber dirty files even when enabled;
|
| 135 |
-
`git grep` search.
|
| 136 |
-
- `git_tools.py` — log / diff / blame / per-file history.
|
| 137 |
-
- `schema_tools.py` — live `pg_dump --schema-only` + migration count
|
| 138 |
-
when a read-only DSN is configured; snapshot mode otherwise; per-table
|
| 139 |
-
definition extraction.
|
| 140 |
-
- `test_tools.py` — targeted `npm test`, workspace `tsc --noEmit`, and
|
| 141 |
-
standalone snippet syntax-checking so codegen can be verified even
|
| 142 |
-
off-repo.
|
| 143 |
-
|
| 144 |
-
## 5. Discipline gate as a Kintsugi skill
|
| 145 |
-
|
| 146 |
-
`skills/discipline_gate.py` is the last node of every plan. Three layers:
|
| 147 |
-
|
| 148 |
-
1. **Belief checks** — destructive SQL in the draft is checked against
|
| 149 |
-
`belief_constraint_shared_db`; confidence 1.0 → BLOCK (the answer is
|
| 150 |
-
withheld, `requires_consensus=True`). Auth impact cites
|
| 151 |
-
`belief_arch_auth_flow` and adds a security review requirement. Audit
|
| 152 |
-
patterns cite their `belief_audit_*` — every flag names the belief it
|
| 153 |
-
came from, and the API returns `beliefs_consulted`.
|
| 154 |
-
2. **Pattern checks** — the code-level layer (destructive DDL shapes,
|
| 155 |
-
signature-bypass shapes, recurring audit anti-patterns). Regexes
|
| 156 |
-
don't negotiate.
|
| 157 |
-
3. **Earned confidence** — graded from the session evidence log:
|
| 158 |
-
source files actually read this session → HIGH; architecture
|
| 159 |
-
map/packs only → MEDIUM; neither, or failed verification → LOW.
|
| 160 |
-
Answers citing files never read this session are demoted and labeled.
|
| 161 |
-
|
| 162 |
-
Defense in depth: the model is told the rules (synthesis system prompt),
|
| 163 |
-
the plan gathers evidence before the model speaks (DAG), and the gate
|
| 164 |
-
verifies after (belief + regex). v1's live test showed why: the model
|
| 165 |
-
emitted `DROP COLUMN` despite the prompt; the gate caught it.
|
| 166 |
-
|
| 167 |
-
## Layout
|
| 168 |
-
|
| 169 |
-
```
|
| 170 |
-
v2/
|
| 171 |
-
├── rivet.py entry point: HTTP server + one-shot CLI
|
| 172 |
-
├── kintsugi_config.yaml BDI seeds, model backend, paths, thresholds
|
| 173 |
-
├── kintsugi_core.py real-package-or-vendor resolver
|
| 174 |
-
├── kintsugi_vendor/ verbatim Kintsugi bdi/ + skills/ (pinned commit)
|
| 175 |
-
├── engine/ config, beliefs, session, planner, synthesis, model_client
|
| 176 |
-
├── skills/ discipline_gate, code_analysis, migration_safety,
|
| 177 |
-
│ security_review, test_runner
|
| 178 |
-
├── pharos/ pack_loader, kv_injector, build_campus_pack
|
| 179 |
-
├── tools/ guard, file_tools, git_tools, schema_tools, test_tools
|
| 180 |
-
└── selftest.py 32 offline checks incl. two end-to-end DAG runs
|
| 181 |
-
```
|
| 182 |
-
|
| 183 |
-
## Deploy (Starship)
|
| 184 |
-
|
| 185 |
-
```bash
|
| 186 |
-
# 1. sync this directory to /Users/margaret/project-rivet/v2
|
| 187 |
-
# 2. build the campus pack (already committed; rebuild after audit updates)
|
| 188 |
-
python3 pharos/build_campus_pack.py
|
| 189 |
-
# 3. offline verification
|
| 190 |
-
python3 selftest.py
|
| 191 |
-
# 4. serve (Ollama backend, qwen2.5-coder:32b already pulled)
|
| 192 |
-
python3 rivet.py # :8100 — POST /ask, GET /health, GET /bdi
|
| 193 |
-
```
|
| 194 |
-
|
| 195 |
-
Optional: point `paths.campus_repo` at a multiversecampus checkout for
|
| 196 |
-
HIGH-confidence source-read answers, `paths.campus_dsn` at a read-only
|
| 197 |
-
Postgres role for live schema checks, and set `model.backend:
|
| 198 |
-
transformers` for true KV pack injection.
|
| 199 |
-
|
| 200 |
-
## What v2 adds over v1
|
| 201 |
-
|
| 202 |
-
| | v1 (scaffold) | v2 (Kintsugi) |
|
| 203 |
-
|---|---|---|
|
| 204 |
-
| Cognition | none — one prompt | BDI: beliefs w/ confidence+evidence, intentions per request |
|
| 205 |
-
| Flow | ask → answer → regex | planned DAG with enforced prerequisites |
|
| 206 |
-
| Knowledge | all context in system prompt | Pharos-routed packs, KV-injected on transformers |
|
| 207 |
-
| Gate | regex on the reply | belief-checked skill; flags cite beliefs; consensus semantics |
|
| 208 |
-
| Confidence | self-reported by the model | computed from the session evidence log |
|
| 209 |
-
| Tools | none | guarded file/git/schema/test harness |
|
| 210 |
-
| Audit findings | regexes in the gate | structured data → beliefs → pack triples → gate checks (one source) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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