KeiSeiKit-1.0/_primitives/_rust
Parfii-bot 6672ae48e7 feat(wave20): kei-cortex daemon + cortex-ui — local HTTP + TypeScript web UI
49 crates, 876 tests green (+17 kei-cortex + 10 cortex-ui TS, was 859).

## kei-cortex — local HTTP daemon (Rust)

Axum-based server on :9797 exposing read-only cortex state (ledger,
pet, memory) as JSON for browser UI consumption. Bearer token auth.
CORS for https://keisei.app. Binds 127.0.0.1 only.

### Endpoints

- GET  /healthz — unauthenticated liveness
- GET  /api/v1/cortex/summary — total_dnas + active_pets + recent_sessions
- GET  /api/v1/cortex/pet/:user_id — pet manifest
- POST /api/v1/cortex/pet/:user_id/interaction — log chat
- GET  /api/v1/cortex/ledger/recent?limit=N — recent agent runs
- GET  /api/v1/cortex/memory/search?user_id=X&pet_name=Y&q=... — recall

### Security

- Token at ~/.keisei/cortex.token (32-byte hex, chmod 600 atomic via
  OpenOptions mode 0o600)
- tower-http CorsLayer with configured allow_origin
- tokio::task::spawn_blocking for rusqlite reads
- All non-healthz routes protected by Bearer middleware

### Constructor Pattern

14 files, largest 137 LOC. All functions ≤30 LOC. Split: auth / config
/ error / state / routes + 5 handlers (health/summary/pet/ledger/memory).

17 tests: token roundtrip + chmod 600 (cfg unix) + 401/403/healthz +
summary shape + pet 404 + pet parse + interaction 201 + CORS preflight
+ ledger limit + empty ledger.

## cortex-ui — Svelte 5 + TypeScript + Vite

Static web app, build to dist/ (~500 KB incl sourcemaps, 64 KB minified
JS+CSS), deployable to https://keisei.app/cortex/. Connects to local
kei-cortex daemon via fetch.

### Features

- Setup wizard (first run): daemon URL + token paste, saved to
  localStorage (origin-scoped)
- Dashboard: summary cards + nav
- PetEditor: view pet.toml fields (identity/voice/edge/forbidden)
- LedgerStream: recent agent runs, auto-refresh 5s
- MemorySearch: query form + results list
- Hash-based routing (no server needed)
- Dark-mode via prefers-color-scheme
- URL-param override: ?daemon=URL&token=T for one-click setup

### Stack choice

Svelte 5 for minimal runtime (~2 KB). TypeScript strict inherits
_ts_packages/tsconfig.base.json. Vite for dev + build. vitest for unit
tests (10 passing: api header/error, config precedence/overrides).

## User flow

Non-dev:
1. Install keisei, run `kei-cortex serve`
2. Open https://keisei.app/cortex
3. Paste daemon URL + token from ~/.keisei/cortex.token
4. View dashboard, edit pet, search memory — all local data, zero cloud

Power user (self-host):
1. `cd _ts_packages/packages/cortex-ui && npm run build`
2. Serve dist/ from localhost OR deploy anywhere
3. Point to own daemon URL

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 01:50:21 +08:00
..
firewall-diff feat(primitives): 2 Rust verification cubes 2026-04-21 21:00:01 +08:00
kei-agent-runtime refactor(wave17): cleanup — kei-shared SSoT + MEDIUM audit residuals + docs drift 2026-04-23 20:34:43 +08:00
kei-artifact Merge feat/v0.16.1-polish — dynamic schema + mode matrix Phase 3.6 2026-04-22 15:13:05 +08:00
kei-atom-discovery feat(wave14): 5 bio-inspired primitives + phase2 cleanup + substrate dogfood 2026-04-23 17:19:25 +08:00
kei-auth sanitize: remove patent-metadata from main tree (Tier 1+2+3) 2026-04-23 19:20:16 +08:00
kei-brain-view feat(wave16): 5 parallel agents — ledger v6 + prune dedupe + brain-view clusters + fork-watch hook + three-role pipeline 2026-04-23 18:53:58 +08:00
kei-cache feat(r2): new kei-cache crate — deterministic result cache 2026-04-23 05:55:13 +08:00
kei-capability feat(e2): kei-capability fork subcommand + lineage stamping 2026-04-23 10:21:45 +08:00
kei-changelog feat(primitives): kei-docs-scaffold shell + kei-changelog Rust 2026-04-21 21:01:28 +08:00
kei-chat-store feat(a): Store::open multi-schema — kei-chat-store sessions fully engine-owned 2026-04-23 14:27:15 +08:00
kei-conflict-scan feat(primitives): 4 Rust crates for deep-sleep — conflict-scan, refactor-engine, graph-check, store 2026-04-22 08:28:22 +08:00
kei-content-store feat(w12a): sister re-migration — content-store campaigns promoted to engine 2026-04-23 14:44:31 +08:00
kei-cortex feat(wave20): kei-cortex daemon + cortex-ui — local HTTP + TypeScript web UI 2026-04-24 01:50:21 +08:00
kei-crossdomain feat(a): Store::open multi-schema — kei-chat-store sessions fully engine-owned 2026-04-23 14:27:15 +08:00
kei-curator chore(rust): misc schema/main refactor in 8 crates (assorted CP splits) 2026-04-22 13:36:17 +08:00
kei-diff feat(wave13): kei-diff + kei-scheduler + kei-watch primitives 2026-04-23 15:51:42 +08:00
kei-discover feat(wave14): 5 bio-inspired primitives + phase2 cleanup + substrate dogfood 2026-04-23 17:19:25 +08:00
kei-dna-index refactor(wave17): cleanup — kei-shared SSoT + MEDIUM audit residuals + docs drift 2026-04-23 20:34:43 +08:00
kei-entity-store refactor(wave17): cleanup — kei-shared SSoT + MEDIUM audit residuals + docs drift 2026-04-23 20:34:43 +08:00
kei-forge feat(stream-f): kei-forge pure-Rust templating — eliminate shell-out 2026-04-23 01:21:00 +08:00
kei-fork fix(wave18): 8 HIGH audit findings closed + three-role pipeline actually built 2026-04-23 20:54:59 +08:00
kei-graph-check feat(primitives): 4 Rust crates for deep-sleep — conflict-scan, refactor-engine, graph-check, store 2026-04-22 08:28:22 +08:00
kei-hibernate feat(wave14): 5 bio-inspired primitives + phase2 cleanup + substrate dogfood 2026-04-23 17:19:25 +08:00
kei-ledger fix(ledger): DNA UNIQUE constraint + v5 migration (HIGH audit) 2026-04-23 15:45:43 +08:00
kei-ledger-sign fix(wave18): 8 HIGH audit findings closed + three-role pipeline actually built 2026-04-23 20:54:59 +08:00
kei-memory sanitize: remove patent-metadata from main tree (Tier 1+2+3) 2026-04-23 19:20:16 +08:00
kei-migrate feat(primitives): kei-migrate Rust universal migration runner 2026-04-21 20:35:29 +08:00
kei-pet feat(wave19): kei-pet Day 2 — 8 pet gaps closed via substrate dogfood 2026-04-24 00:37:24 +08:00
kei-pipe feat(wave14): 5 bio-inspired primitives + phase2 cleanup + substrate dogfood 2026-04-23 17:19:25 +08:00
kei-provision sanitize: remove patent-metadata from main tree (Tier 1+2+3) 2026-04-23 19:20:16 +08:00
kei-prune feat(wave14): 5 bio-inspired primitives + phase2 cleanup + substrate dogfood 2026-04-23 17:19:25 +08:00
kei-refactor-engine fix(kei-refactor-engine): retract 'git apply-ready' claim (F1 RELEASE BLOCKER) 2026-04-22 13:36:17 +08:00
kei-replay feat(w9e): NEW kei-replay crate — reconstruct spawn from DNA 2026-04-23 13:34:16 +08:00
kei-router chore(rust): misc schema/main refactor in 8 crates (assorted CP splits) 2026-04-22 13:36:17 +08:00
kei-runtime fix(p1-integration): validate.rs allows _schemas/fragments $ref + drop additionalProperties on fragment-composed atom schemas 2026-04-23 04:53:26 +08:00
kei-sage feat(a): Store::open multi-schema — kei-chat-store sessions fully engine-owned 2026-04-23 14:27:15 +08:00
kei-scheduler feat(wave13): kei-diff + kei-scheduler + kei-watch primitives 2026-04-23 15:51:42 +08:00
kei-search-core chore(rust): misc schema/main refactor in 8 crates (assorted CP splits) 2026-04-22 13:36:17 +08:00
kei-shared refactor(wave17): cleanup — kei-shared SSoT + MEDIUM audit residuals + docs drift 2026-04-23 20:34:43 +08:00
kei-social-store feat(w12a): sister re-migration — content-store campaigns promoted to engine 2026-04-23 14:44:31 +08:00
kei-spawn fix(wave18): 8 HIGH audit findings closed + three-role pipeline actually built 2026-04-23 20:54:59 +08:00
kei-store refactor(v0.22): kei-store AsyncBackend trait + shared tokio runtime (Track B) 2026-04-22 21:06:50 +08:00
kei-task feat(a): Store::open multi-schema — kei-chat-store sessions fully engine-owned 2026-04-23 14:27:15 +08:00
kei-watch feat(wave13): kei-diff + kei-scheduler + kei-watch primitives 2026-04-23 15:51:42 +08:00
keisei fix(tests): repair 2 missing closing braces from v0.22 Track-A↔Track-C merge 2026-04-22 21:16:22 +08:00
mock-render refactor(mock-render): split main.rs 227 LOC into 4 cubes (F5a Constructor Pattern) 2026-04-22 13:36:17 +08:00
ssh-check feat(primitives): 2 Rust verification cubes 2026-04-21 21:00:01 +08:00
tokens-sync feat(primitives): 3 Rust cubes — mock-render, visual-diff, tokens-sync 2026-04-21 21:07:45 +08:00
visual-diff feat(primitives): 3 Rust cubes — mock-render, visual-diff, tokens-sync 2026-04-21 21:07:45 +08:00
.gitignore feat(primitives): 2 Rust verification cubes 2026-04-21 21:00:01 +08:00
Cargo.lock feat(wave20): kei-cortex daemon + cortex-ui — local HTTP + TypeScript web UI 2026-04-24 01:50:21 +08:00
Cargo.toml feat(wave20): kei-cortex daemon + cortex-ui — local HTTP + TypeScript web UI 2026-04-24 01:50:21 +08:00