# GHN Audit and Rebuild — 2026-07-19

## Why this session happened

The Ubuntu World Pantheon formalised seven planes above the existing guardian IDs.
That created a gap: the planes existed as doctrine but were not enforced anywhere in
code. Simultaneously, two live cost problems were confirmed:

1. **Batch API outage loop** — when the Anthropic Batch API returned null responses,
   the EVOLUTION engine was writing 40–80 Field Intelligence entries per day into GAIA
   instruction files. Each entry was consumed on every GAIA call at ~$0.15/call.
   `GAIA/Instructions/01-operational-cost-management.md` had grown to 880+ lines —
   90–94% of the Sonnet input budget was going to noise, not doctrine.

2. **Routing gaps** — several guardians (MINERVA RESEARCH/INTEL/PATH modes, SANGO,
   MAAT, YEMOJA) had either no routing patterns or patterns that never matched live
   files. New guardians added since the original GHN build had not been wired into the
   heuristic network at all.

This session audited every guardian against the plane registry, diagnosed each gap,
and implemented all seven improvement proposals (P0–P6).

---

## What was built

### P0 — EVOLUTION infra-topic gate
**File:** `KAE/evolution/outcome-extractor.js`

Added `FIELD_INTEL_BLOCKED` regex. Before any Field Intelligence observation is
written to a guardian instruction file, the section reference and note are tested
against:

```
/batch|retry|timeout|null result|response handling|error handling/i
```

If matched, the write is blocked with a console log and the entry is never created.
This is the root fix for the batch-error append loop. It prevents recurrence
regardless of future API outage patterns.

---

### P1 — Escalations/ watcher exclusion
**Status:** Already implemented — confirmed present in `IGNORE_PATTERNS` in
`KAE/watchers/file-watcher.js`. No action taken.

---

### P2 — Guardian self-registration
**New files:** `KAE/guardians/*/patterns.json` (17 files) + `KAE/scripts/assemble-ghn-patterns.js`

Before this pass, adding a new guardian required editing three separate files:
the guardian folder, `registry.js`, and `ghn-patterns.json`. The pattern seed file
was a single centralised document with no ownership.

Now every guardian owns its routing patterns in a local `patterns.json`. The
assembler merges all 17 files into the master seed on demand:

```
node KAE/scripts/assemble-ghn-patterns.js [--dry-run]
```

The assembler deduplicates by pattern ID (last-write wins). Guardians created from
this point forward only need a `patterns.json` in their folder — the rest of the
system picks them up automatically on the next assemble run.

---

### P3 — GHN tie-breaker
**File:** `KAE/ghn/core.js`

`findRoute()` previously used a simple `if (score > bestScore)` check. When two
patterns scored equally (common with broad file patterns like `*/Clients/*`), the
winner was whichever pattern appeared first in the array — entirely order-dependent.

The fix adds a two-level tie-breaker after an equal-score match:
1. Count how many `context_signals` the pattern shares with the event signals
   (specificity hit count). The more specific pattern wins.
2. If hit counts are also equal, fall back to base confidence value.

Routing is now deterministic regardless of pattern file ordering.

---

### P4 — Field Intelligence archival and purge
**New files:** `KAE/scripts/gaia-field-intel-archive.js` + `KAE/monitors/field-intel-archive.js`
**Modified:** `KAE/index.js`

The archival script:
- Scans all `Systems/Guardian/*/Instructions/*.md` for `## Field Intelligence` sections
- Collapses duplicate entries (same header line) to a single record with an occurrence count
- Entries older than 7 days → archived to `Systems/Guardian/APOLLO/field-intel-archive-YYYY-MM.md`
- Entries matching `INFRA_TOPIC_RE` → purged regardless of age (not archived — they have no methodology value)
- Handles files without the `<!-- KAE-MANAGED -->` marker via a fallback path
- `--dry-run` flag for safe previewing before any writes

**Run this session results:**
| File | Before | After |
|---|---|---|
| `GAIA/Instructions/01-operational-cost-management.md` | 880 lines | 113 lines |
| `GAIA/Instructions/03-kujenga-control-plane.md` | 58 infra-topic entries | 0 (fully purged) |
| All instruction files combined | ~400 entries | ~130 entries |

The monitor runs daily at 03:00 SAST via `node-cron`. It is wired into
`startServerRuntime()` in `KAE/index.js` — no manual scheduling needed.

---

### P5 — MINERVA routing gaps
**Modified:** `KAE/guardians/minerva/patterns.json` + `KAE/ghn/store/ghn-patterns.json`

MINERVA had one seeded pattern (`ghn_minerva_overview` — MAP mode via 00-overview.md
files). Its three other modes had no routing paths:

| Mode | Trigger signal | New pattern ID |
|---|---|---|
| RESEARCH | `hardwall_content` | `ghn_minerva_hardwall` (confidence 0.88) |
| INTEL | `intel_request` | `ghn_minerva_intel_request` (confidence 0.85) |
| MAP / PATH | `constraint_content` | `ghn_minerva_constraint` (confidence 0.80) |

MINERVA will now fire on client files containing hard-wall language, explicit intel
requests, or constraint/regulatory language — not only on 00-overview.md files.

---

### P6 — Ubuntu World Pantheon plane enforcement
**New files:** `KAE/ghn/plane-manifest.json` + `KAE/ghn/plane-check.js`
**Modified:** `KAE/ghn/router.js`

#### Plane manifest
`plane-manifest.json` is the authoritative membership document for all 8 planes:

| Plane | Guardians |
|---|---|
| sovereign | GAIA |
| memory | APOLLO |
| state | POSEIDON, HADES, ELEUTHIA, YEMOJA, OYA |
| access | ESHU, MINERVA |
| enforcement | DEMETER, MAAT |
| capability | AETHER, SANGO, OSHOSI, ARTEMIS |
| channel | HERMES |
| runtime | HEPHAESTUS |

#### Sequencing rules (3 active)
| Rule | Condition | Co-dispatched guardian |
|---|---|---|
| `intake_needs_access` | Capability plane guardian + `icp_content` signal | ESHU |
| `commercial_needs_contract` | Capability plane guardian + `contract_content` or `currency_over_threshold` | MAAT |
| `build_needs_contract` | Runtime plane guardian + `currency_over_threshold` | MAAT |

#### Runtime enforcement
`plane-check.js` exports `checkSequencing(guardians, signals)`. The router calls it
after `core.findRoute()`. If a sequencing rule is not satisfied, the missing guardian
is added to the dispatch list and logged:

```
[PLANE-CHECK] Co-dispatching ESHU (access plane — sequencing rule)
```

The router also logs which planes are active for every routing decision:

```
[GHN] CHANGE → [HERMES, SANGO, ESHU] mode=AUDIT confidence=90% planes=[channel, capability, access]
```

---

## Architectural meaning

After this pass the GHN is structurally complete for the current guardian roster:

1. **Every guardian has routing patterns** — no guardian is invisible to the network
2. **Routing is order-independent** — the tie-breaker ensures deterministic results
3. **Plane doctrine is enforced at runtime** — not just documented
4. **Field Intelligence is self-cleaning** — the daily cron keeps instruction files
   lean without manual intervention
5. **Adding a new guardian is now a one-file operation** — `patterns.json` in the
   guardian folder, then run the assembler

The EVOLUTION engine can now run cleanly even through API outages — the P0 gate means
infra errors can never reach instruction files again.

---

## KAE was shut down during this session

KAE was stopped (`pm2 stop kae`) before bulk writes to instruction files, then
restarted after commit. This is the correct procedure whenever a session writes to
more than 3 `Systems/` files. The build-stop guard hook enforces this automatically
if KAE is left running — but stopping it manually first avoids the automatic PM2 kill
mid-session.

**Pattern to remember:** Stop KAE → make changes → commit → restart KAE.

---

## Files changed — commit 9d7acaf

```
.CLAUDE/hooks/campaign-quality-gate.js    (M) — Partner intel path exclusion
.CLAUDE/hooks/hook-helpers.js             (M) — isPartnerIntelPath() added
.CLAUDE/hooks/offer-viability-gate.js     (M) — Partner intel path exclusion
KAE/evolution/outcome-extractor.js        (M) — P0 FIELD_INTEL_BLOCKED gate
KAE/ghn/core.js                           (M) — P3 tie-breaker
KAE/ghn/plane-check.js                    (A) — P6 plane enforcement module
KAE/ghn/plane-manifest.json               (A) — P6 8-plane membership + 3 sequencing rules
KAE/ghn/router.js                         (M) — P6 co-dispatch + plane logging
KAE/ghn/store/ghn-patterns.json           (M) — P5 MINERVA patterns + P2 v3 meta
KAE/guardians/*/patterns.json             (A) — P2 17 guardian self-registration files
KAE/index.js                              (M) — P4 field-intel-archive monitor wired
KAE/monitors/field-intel-archive.js       (A) — P4 daily 03:00 SAST cron
KAE/scripts/assemble-ghn-patterns.js      (A) — P2 assembler
KAE/scripts/gaia-field-intel-archive.js   (A) — P4 archival + purge script
Systems/Guardian/APOLLO/field-intel-archive-2026-07.md  (A) — first archive entries
Systems/Guardian/GAIA/Instructions/01-operational-cost-management.md  (M) — 880→113 lines
Systems/Guardian/GAIA/Instructions/02-financial-awareness.md          (M) — old entries archived
Systems/Guardian/GAIA/Instructions/03-kujenga-control-plane.md        (M) — fully purged
Systems/Guardian/guardian-state.md        (M) — session close update
```

## Read next

- `live-system-changes.md` — current working tree state
- `methodology-enforcement-pass-2026-07-19.md` — hook enforcement pass (same day)
- `KAE/ghn/plane-manifest.json` — canonical plane membership
- `KAE/scripts/gaia-field-intel-archive.js` — run with `--dry-run` to preview field intel state
