# KAE Tool Audit — 2026-07-19

**Requested by:** Kabamba  
**Audited by:** Claude (Sonnet 4.6)  
**Register:** `surface` (internal reference)  
**Status:** Complete

---

## System Structure at a Glance

```
Kujenga11/
├── Systems/            ← All business content (clients, guardians, playbooks, library)
├── KAE/                ← Kujenga Autonomy Engine — Node.js daemon, PM2-managed
├── .claude/            ← Claude Code harness — hooks, settings, skills
├── Knowledge/          ← LEGBA knowledge ingest working set
├── KAE-Visualizations/ ← Architecture diagrams
└── CLAUDE.md           ← AI operating handbook
```

| Area | Count |
|---|---|
| Active client folders | 26 |
| Guardian folders | 19 |
| Playbook folders | 10 |
| Libraries | 2 (OGUN + LEGBA) |
| Session handoff documents | 50+ |
| **Total tools audited** | **87** |

**Clients:** 1818-INVESTMENTS · AFRIKAFEST · AFW · AON-FUELS · AVES · BIZ-CASH-FRANCHISE · CIBUS-FARMS · COME-TASTE-AFRICA · DBIA · ELEVATE-HER · EUSCHOOL · HELLOHI · HIGHGROUNDS-BLVD · KUJENGA-DIGITAL · LIMITLESS-HORISON · MIPFA · MPHO-GROUP · NTALO · ONEDB · PHEPISA · PP-AFRICA · SAMW · SMOOTH-FUELS · TECSA · TSHEPISO-BRANDING · UNIVERSITY-LIMPOPO

**Guardians:** GAIA (sovereign) · APOLLO (memory) · POSEIDON (pipeline) · HADES (engagement reset) · HERMES (channel) · MINERVA (constraint) · MAAT (contract gate) · YEMOJA (team integrity) · OYA (financial flags) · SANGO (marketing review) · OSHOSI (sales review) · AETHER (brand voice) · DEMETER (process integrity) · ESHU (intake gate) · ELEUTHIA (client lifecycle) · ARTEMIS (campaign activation) · HEPHAESTUS (digital infrastructure) · ANANSI (learning)

---

## Cost Key

| Badge | Meaning |
|---|---|
| `Negligible` | Pure JS/SQL logic — no I/O, no API calls |
| `Low` | Reads a few files or writes SQLite |
| `Medium` | Reads many files, runs git, or sends/receives small data |
| `High` | Spawns Chromium, makes LLM API calls, or transfers files over network |

---

## Layer 1 — Hooks (`.claude/hooks/`) — 28 files

Every file save in this repo passes through up to 11 pre-checks and 1 post-router dispatching to 15 sub-handlers. A single `Write` call can touch up to 28 hook code paths.

### Session-Start (fires once per session open)

| Tool | Lines | Purpose | Cost |
|---|---|---|---|
| `mandatory-reads.js` | 57 | Injects OS-critical files into every session context from `mandatory-reads.json` | Low |
| `kae-status.js` | 131 | Builds situational awareness — MEMORY.md, tasks, last session log, git status, PM2 status (1h cooldown) | Medium |

### UserPromptSubmit (fires on every prompt)

| Tool | Lines | Purpose | Cost |
|---|---|---|---|
| `session-brief.js` | 165 | Injects KAE SESSION BRIEF — overdue tasks + due content (1h cooldown) | Medium |
| `context-bridge.js` | 281 | Saves/restores session state across compaction events. WRITE at 600KB; INJECT when context shrinks below 60% of write-size | Medium |

### PreToolUse Write/Edit (fires before every file save)

| Tool | Lines | Purpose | Blocking | Cost |
|---|---|---|---|---|
| `kae-guard.js` | 90 | Counts writes to `Systems/` in rolling 10-min window; stops KAE (`pm2 stop kae`) at 3+ to prevent runaway API spend | No (stops KAE, not the write) | Low |
| `contract-threshold-gate.js` | 134 | MAAT: blocks delivery/finance writes when no signed contract is on file for the client | Hard block | Low |
| `process-registration-gate.js` | 104 | DEMETER: new tools/hooks must appear in the registry before they land | Warn | Low |
| `brand-foundation-gate.js` | 169 | Hard-blocks design-surface files (HTML/CSS) when client has no `ogun-config.json` or brand reference | Hard block on design | Low |
| `brief-prerequisite-gate.js` | 117 | DEMETER: no campaign assets without a LEZA brief/audit on file | Warn | Low |
| `spec-first-gate.js` | 177 | HEPHAESTUS: complex client builds must have a `.spec.md` before code starts | Warn | Low |
| `kdacm-phase-foundation-gate.js` | 269 | Blocks digital builds when Phase 1 narrative foundation (story, messaging, content matrix) is absent from `Brand/` | Hard block | Low–Medium |
| `research-freshness-gate.js` | 106 | MINERVA: time-sensitive research must carry a freshness marker before supporting a public claim | Warn | Low |
| `content-payload-completeness-gate.js` | 143 | HERMES: blocks content reviews when the post body is missing or too thin | Hard block | Low |
| `design-smell-gate.js` | 85 | Hard-blocks banned CSS/color patterns (dark blue, neon, glassmorphism, non-Kujenga hex values) before they reach any file | Hard block | **Negligible** |

### PreToolUse Bash

| Tool | Lines | Purpose | Cost |
|---|---|---|---|
| `image-gen-preflight.js` | 113 | Fires before every Bash call; injects `IMAGE-GEN-IMPROVEMENTS.md` creative rules when the command references image-gen | Low |

### PostToolUse Write/Edit — Router + Sub-handlers

| Tool | Lines | Purpose | Cost |
|---|---|---|---|
| `post-write-router.js` | 74 | Single fan-out router — replaced 15 separate processes with 1. All sub-handlers run in the same process | Low–Medium |
| `tasks-data-gate.js` | 230 | tasks.json/projects.json completeness — owner gaps, open work without date windows | Low |
| `team-profile-gate.js` | 124 | YEMOJA: team profile structural completeness | Low |
| `campaign-quality-gate.js` | 188 | Merged: readiness, proof claim, review clearance, opportunity discipline | Low |
| `finance-state-gate.js` | 140 | OYA: payment status, commission ownership, rate visibility in finance files | Low |
| `hades-resolution-date-gate.js` | 127 | HADES: every review record must have a next-check date | Low |
| `offer-viability-gate.js` | 141 | Service/offer files must name resources, delivery system, and commercial proof | Low |
| `documentation-gate.js` | 167 | Enforces file header blocks, function doc-comments, Status+Owner metadata | Low |
| `client-lifecycle-gate.js` | 159 | ESHU/ELEUTHIA: clients need intake records and visible lifecycle stage | Low |
| `owner-assignment-gate.js` | 141 | YEMOJA: no task without a named owner traceable to a real Team profile | Low |
| `poseidon-flag-response-gate.js` | 124 | POSEIDON: every flag must have a response within 24 hours | Low |
| `review-clearance-gate.js` | 102 | HERMES: no live-bound content without explicit approval markers | Low |
| `proof-claim-gate.js` | 118 | SANGO/AETHER: public claims must point at evidence in truth-ledger.md | Low |
| `task-completeness-gate.js` | 183 | Tasks must have dates, scope, state, action plan, and success criteria | Low |
| `amendment-validate.js` | 70 | Validates GAIA amendment files against schema at authoring time | Negligible |
| `opportunity-discipline-gate.js` | 114 | OSHOSI: opportunities need a champion; closed deals need autopsy | Low |

### SessionEnd (fires on every session close)

| Tool | Lines | Purpose | Cost |
|---|---|---|---|
| `gaia-pack-sync.js` | 55 | Thin SessionEnd wrapper — triggers the GAIA pack sync and writes live-system-changes.md/html | Medium |
| `session-close.js` | 147 | Restarts KAE if the build-stop guard parked it; injects session-close checklist into Claude | Low |

---

## Layer 2 — KAE Scripts (`KAE/scripts/`) — 26 files

| Tool | Schedule / Trigger | Lines | Complexity | Cost |
|---|---|---|---|---|
| `morning-brief.js` | Daily 05:30 SAST (Task Scheduler) | 278 | High | Medium |
| `evening-brief.js` | Daily 18:00 SAST (Task Scheduler) | 313 | High | Medium |
| `poseidon-data-feed.js` | Sat + Sun 09:00 SAST | 266 | High | Medium |
| `context-bridge.js` | Every prompt | 281 | High | Medium |
| `session-brief.js` | First prompt each hour | 165 | Medium | Medium |
| `tasks-check.js` | After tasks.json edits + manual | 194 | Medium | Low |
| `gaia-field-intel-archive.js` | Daily 03:00 SAST + manual | 254 | High | Medium |
| `guardian-state-archive.js` | Manual (session-close protocol) | 188 | Medium | Low |
| `validate-models.js` | Every KAE restart (non-blocking) | 180 | Medium | **High** (LLM calls) |
| `push-post-to-buffer.js` | Manual per post | 92 | Low–Medium | **High** (FTP + Buffer API) |
| `generate-linkedin-preview-pdf.js` | Manual | 171 | Medium | **High** (headless browser) |
| `generate-proposals-pdf.js` | Manual | 135 | Medium | **High** (headless browser) |
| `amendments.js` | Manual (human-in-the-loop) | 171 | Medium | Low |
| `assemble-ghn-patterns.js` | Manual on pattern changes | 95 | Low | Low |
| `deploy-ftp.js` | Manual per deploy | 127 | Medium | **High** (FTP transfer) |
| `repair-pattern-confidence.js` | Manual (emergency after outage) | 53 | Low | Low |
| `requeue-failed.js` | Manual (emergency after outage) | 41 | Low | Negligible |
| `scaffold-clients.js` | Manual (client onboarding) | 139 | Medium | Low |
| `validate-manifests.js` | Manual on guardian changes | 67 | Low | Low |
| `ogun-usage.js` | Manual (new-client onboarding) | 123 | Medium | Low |
| `codebase-roster-close.js` | Manual (session-close) | 104 | Medium | Low |
| `extract-archive.py` | Manual per document | Medium (Python) | — | Low–Medium |
| `restart.js` | Manual | 48 | Low | Low |
| `platform-detect.js` | Imported as library | 22 | Low | Negligible |
| `verify-skill-tables.js` | Manual (diagnostic) | 31 | Low | Negligible |
| `register-*.ps1` (×2) | One-time machine setup | ~30 each | Low | Low |

---

## Layer 3 — KAE Monitors (`KAE/monitors/`) — 12 files

All started by `KAE/index.js` on boot when `KAE_ROLE=full` or `server`.

| Monitor | Schedule | Lines | Cost |
|---|---|---|---|
| `health-check.js` | Boot + cron | 124 | Low |
| `backup.js` | 02:30 SAST daily + boot | 84 | Low–Medium |
| `content-alert.js` | 05:30 SAST daily + boot | 237 | Medium |
| `project-gate.js` | 06:00 SAST daily + boot | 27 | Low |
| `project-closeout.js` | 06:15 SAST daily + boot | 25 | Low |
| `amendment-review.js` | Daily | 90 | Low |
| `field-intel-archive.js` | 03:00 SAST daily | 31 | Medium |
| `quality-scorer.js` | Weekly | 93 | Low |
| `json-export.js` | Nightly | 49 | Low |
| `poseidon-monitor.js` | Weekly/periodic | 195 | **High** (LLM call) |
| `client-monitors.js` | Monday 07:15 SAST + others | 166 | Medium |
| `demeter-check.js` | Every 12 hours + boot | 23 | Low |

---

## Layer 4 — GHN / Routing (`KAE/ghn/`) — 5 files

Fires on every file-change event detected by the file watcher.

| Tool | Lines | Purpose | Cost |
|---|---|---|---|
| `router.js` | 138 | Main event router — receives file events, calls `findRoute()`, runs plane sequencing, dispatches guardians | Low–High (varies by route) |
| `core.js` | 252 | Pattern store API (SQLite). `findRoute()`, tie-breaker, `updatePatternUse()` | Low |
| `plane-check.js` | 107 | Ubuntu World Pantheon sequencing — co-dispatches ESHU/MAAT when capability/runtime guardians fire without them | Negligible |
| `learning-loop.js` | 186 | Pattern learning — accumulates observations; promotes at 80% success over 3 occurrences | Low |
| `plane-manifest.json` | — | Authoritative 8-plane membership document (read once at boot) | Negligible |

---

## Layer 5 — Evolution Engine (`KAE/evolution/`) — 10 files

| Tool | Lines | Purpose | Cost |
|---|---|---|---|
| `batch-submitter.js` | 81 | Submits guardian outputs to Anthropic Batch API hourly | **High** |
| `batch-poller.js` | 124 | Polls Batch API for results; calls outcome-extractor on completion | **High** |
| `outcome-extractor.js` | 106 | LLM-based field intelligence extraction per guardian output. `FIELD_INTEL_BLOCKED` regex suppresses infra-error spam | **High** |
| `amendment-proposer.js` | 107 | Drafts amendment proposals via LLM when evidence threshold is reached | **High** |
| `amendment-writer.js` | 127 | Applies human-approved amendments to guardian instruction files | Low–Medium |
| `evidence-store.js` | 100 | Accumulates field observations in SQLite; triggers proposer at threshold (3 observations, 80% confidence) | Low |
| `evolution-queue.js` | 75 | SQLite queue — enqueue/read/mark guardian outputs for batch processing | Low |
| `field-writer.js` | 46 | Appends field intelligence to `## Field Intelligence` sections | Low |
| `resolve-instruction-path.js` | 63 | Repairs model-returned instruction paths that drop the `Instructions/` folder segment | Negligible |
| `amendment-schema.js` | 96 | Canonical schema + validator for amendment files | Negligible |

---

## Layer 6 — OGUN Library Tools (`Systems/Library/OGUN/Tools/`) — 13 tools

| Tool | Language | Lines | Purpose | Cost |
|---|---|---|---|---|
| `image-gen/generate.js` | Node.js | 250 | LinkedIn social cards from HTML templates + brand config via Puppeteer | **High** |
| `html-to-pdf/html-to-pdf.js` | Node.js | 148 | A4 HTML → print-ready PDF. `--portrait` flag | **High** |
| `gaia-pack-sync/gaia-pack-sync.js` | Node.js | 478 | Generates live-system-changes.md/html from git working tree (called every session close) | Medium |
| `enforcement-audit/enforcement-audit.js` | Node.js | 156 | Audits which Kujenga doctrine rules are code-enforced vs prose-only | Low |
| `send-email/send-email.js` | Node.js | 40 | SMTP email with optional attachment via Kujenga Digital mail server | **High** |
| `screenshot-url/screenshot-url.js` | Node.js | 68 | Headless Chrome screenshot of any URL (local dev or public) | **High** |
| `nightly-push/nightly-push.ps1` | PowerShell | 69 | Auto-discovers all git repos; pushes committed-but-unpushed work at 01:00 nightly | Medium |
| `image-bank-organise/image-bank-organise.js` | Node.js | 214 | Renames and copies campaign images using `bg-[context].ext` convention | Low–Medium |
| `vecteezy/search.js` | Node.js | 88 | Vecteezy API — search royalty-free photos/vectors | Medium |
| `vecteezy/download.js` | Node.js | 91 | Vecteezy API — download by resource ID | Medium |
| `vecteezy/account.js` | Node.js | 61 | Vecteezy API — check quotas and license usage | Low |
| `backfill-post-metadata.js` | Node.js | 153 | One-time utility: backfills HERMES metadata headers into legacy post files | Low |
| `pptx/` (4 Python modules) | Python | ~200 | Reusable PPTX layout + component library for client build scripts | Negligible (library) |

---

## Layer 7 — LEGBA Gateway (`Systems/Library/LEGBA/`) — 8 files

| Tool | Lines | Purpose | Cost |
|---|---|---|---|
| `legba-mcp.js` (local stdio) | 38 | MCP gateway for Claude Code on this machine | Low |
| `legba-http.js` (VPS HTTP/SSE) | 755 | Remote MCP gateway at `legba.kujengadigital.co.za` for remote seats | Low (network I/O) |
| `lib/tools.js` | 868 | All 15 LEGBA tool implementations: `read_doc`, `list_clients`, `tasks_list`, `get_client`, `get_guardian_status`, `invoke_minerva`, `kuji_render`, `perplexity_search`, `oxylabs_search`, etc. | Low–**High** per tool |
| `rpc-core.js` | 81 | Shared JSON-RPC dispatcher for both stdio and HTTP transports | Negligible |
| `legba-seat.js` | 82 | Creates/lists/revokes access tokens for the HTTP gateway | Negligible |
| `check-health.js` (VPS) | 129 | Checks LEGBA uptime every 5 minutes; writes uptime log | Low |
| `backup-state.js` (VPS) | 104 | Nightly LEGBA state backup on VPS | Low |
| `deploy-public-surfaces.js` (VPS) | 103 | Copies domain surfaces to public folders; syncs favicon/manifest | Low |

---

## Layer 8 — Internal Engines (`KAE/ogun/`, `KAE/loop/`, `KAE/sync/`)

| Tool | Lines | Purpose | Cost |
|---|---|---|---|
| `ogun/skill-engine.js` | 653 | OGUN Skill Engine — loads skill steps from SQLite per request; most complex internal engine | Low |
| `loop/discovery.js` | 277 | GAIA loop Phase 1 — scores tasks + post backlog + evolution alerts against strategic goals; writes ranked discovery backlog | Medium |
| `loop/goal-store.js` | 110 | SQLite CRUD for strategic goals that discovery.js scores against | Negligible |
| `loop/seed-gaia-loop.js` | 193 | Seeds initial GAIA loop config + goals into SQLite (one-time setup) | Low |
| `loop/seed-goals.js` | 104 | Seeds canonical strategic goal set (one-time or on reset) | Negligible |
| `sync/systems-sync.js` | 50 | Synchronises Systems/ state with KAE during migration/multi-machine setup | Low–Medium |

---

## Layer 9 — Client-Specific Build Scripts

| Script | Client | Language | Purpose |
|---|---|---|---|
| `generate-orientation.js` | ANANSI/Playbooks | Node.js | Role-specific staff onboarding orientation generator |
| `build-pptx-report.py` | DBIA | Python | PPTX report template (python-pptx) |
| `md-to-html-dbia.js` | DBIA | Node.js | Converts DBIA markdown to branded HTML |
| `send-email.ps1` | DBIA | PowerShell | DBIA-specific email sender |
| `build-aem-brief.py` | DBIA/AEM | Python | 6-slide PPTX brief using OGUN pptx library |

---

## Invocation Frequency Summary

| Frequency | Tools |
|---|---|
| Every prompt | `context-bridge.js` |
| Every Write/Edit | `kae-guard.js` · `contract-threshold-gate.js` · `process-registration-gate.js` · `brand-foundation-gate.js` · `brief-prerequisite-gate.js` · `spec-first-gate.js` · `kdacm-phase-foundation-gate.js` · `research-freshness-gate.js` · `content-payload-completeness-gate.js` · `design-smell-gate.js` · `post-write-router.js` (+ 15 sub-handlers) |
| Every Bash call | `image-gen-preflight.js` (injects only on image-gen runs) |
| Every file-change event | `router.js` · `core.js` · `plane-check.js` · `learning-loop.js` |
| Every session open | `mandatory-reads.js` · `kae-status.js` |
| First prompt each hour | `session-brief.js` |
| Every session close | `gaia-pack-sync.js` · `session-close.js` |
| Every KAE boot | `validate-models.js` (detached) · `health-check.js` · `backup.js` · `content-alert.js` · `project-gate.js` · `project-closeout.js` · `demeter-check.js` |
| Daily 03:00 SAST | `field-intel-archive.js` |
| Daily 05:30 SAST | `morning-brief.js` · `content-alert.js` monitor |
| Daily 06:00 SAST | `project-gate.js` |
| Daily 06:15 SAST | `project-closeout.js` |
| Daily 18:00 SAST | `evening-brief.js` |
| Daily 02:30 SAST | `backup.js` |
| Every 12 hours | `demeter-check.js` |
| Nightly 01:00 | `nightly-push.ps1` |
| Every 5 min (VPS) | `check-health.js` |
| Nightly 02:25 (VPS) | `backup-state.js` |
| Sat + Sun 09:00 SAST | `poseidon-data-feed.js` |
| Hourly (evolution) | `batch-submitter.js` · `batch-poller.js` |
| Weekly/periodic | `quality-scorer.js` · `poseidon-monitor.js` |
| Manual only | `amendments.js` · `requeue-failed.js` · `repair-pattern-confidence.js` · `scaffold-clients.js` · `deploy-ftp.js` · `push-post-to-buffer.js` · `assemble-ghn-patterns.js` · `validate-manifests.js` · `extract-archive.py` · `legba-seat.js` · `deploy-public-surfaces.js` · all OGUN build tools |

---

## Cost Profile by Layer

| Layer | Highest-cost tools | Cost driver |
|---|---|---|
| Evolution engine | `batch-submitter`, `batch-poller`, `outcome-extractor`, `amendment-proposer` | Direct Anthropic API spend — fires per guardian run |
| KAE monitors | `poseidon-monitor` | One LLM call per weekly run |
| KAE scripts | `validate-models`, `generate-*-pdf`, `push-post-to-buffer` | LLM calls on boot; headless browser per PDF |
| OGUN tools | `image-gen`, `html-to-pdf`, `screenshot-url` | Chromium per invocation |
| LEGBA tools | `perplexity_search`, `oxylabs_search`, `invoke_minerva` | External API call per invocation |
| Hook lattice | None individually high | Very high frequency — fires on every file write |
| GHN routing | None | SQLite only — effectively free |

---

*Read next: `tool-audit-2026-07-19.html` — interactive version with cost filtering*  
*Back to index: `index.html`*
