KeiSeiKit-1.0/_primitives
Denis Parfionovich d1467b8611 feat(kei-pet): Day 1 — persona manifest parse + validate + overlay + Ed25519 identity
First crate of the Pet UI v1 line (feat/pet-ui-v1 branch). Ships:

## Schema (src/schema.rs — 213 LOC)
Strongly-typed `PetManifest` covering:
- identity (pet_name, user_name, addressing, languages)
- voice (tone primary/secondary, humor style + frequency)
- edge (profanity, directness, initiative)
- appearance (base_shape, size, colours, eyes, expression, accessories)
- room (theme, lighting, decor, time_sync)
- privacy (public_profile, publish_allowed, share_dreams, share_garden)
- interests[] (topic, depth, freshness, vault_path, last_refresh)
- routines[] (kind, schedule, template, enabled)
- forbidden (topics, tone_patterns)
- meta (schema version, timestamps, tune_count)

All enums serde-renamed to kebab-case for TOML-native feel.

## Validation (src/validate.rs — 180 LOC)
19-rule validator (R1–R19 per earlier spec). Errors **accumulate** — single
validate() call surfaces every issue, not just the first. Covers:
- schema version (R1)
- name bounds (R2, R2)
- languages ISO-639-1 (R4)
- tone_secondary cardinality + no-primary-dup (R6)
- profanity/language consistency (R10)
- interest topic slug-safety (R12)
- interest/forbidden contradiction (R14)
- schedule grammar: HH:MM, dow-HH:MM, every-Nh, no-commit-for-Nh,
  N-errors-in-N-calls (R16)
- empty-string guards (R18)
- ISO-8601 timestamps (R19)
- hex-colour sanity on appearance

## Overlay rendering (src/overlay.rs — 128 LOC)
Pure function `system_prompt(&PetManifest) -> String`. Deterministic — same
manifest → same bytes. Used as prompt-prefix by the runtime at spawn time.

## Identity (src/identity.rs — 117 LOC incl. 5 unit tests)
Standard Ed25519 (RFC 8032) via ed25519-dalek. `user_id` = first 16 hex
chars of blake3(public_key) — deterministic, 64-bit, URL-safe. Hex-string
API for cross-boundary verify. No proprietary crypto, no matrix math.

## CLI (src/bin/kei-pet.rs — 110 LOC)
- `kei-pet validate <path>` — parse + run R1–R19
- `kei-pet show <path>`     — print rendered overlay
- `kei-pet identity new`    — generate + store ~/.keisei/identity.key (0600)
- `kei-pet identity show`   — print public key + user_id
- `kei-pet tune` stub (Day 2 — /pet-tune skill lands full implementation)

## Tests
- 23/23 integration (tests/validation_tests.rs) — one rejector per rule +
  accept cases for examples/minimal.toml and examples/full.toml + overlay
  smoke + multi-error accumulation guard
- 5/5 unit (identity module) — keypair roundtrip, user_id determinism,
  sign/verify, hex API boundary
- cargo test -p kei-pet --release: all green

## Examples
- examples/minimal.toml — smallest valid manifest
- examples/full.toml    — every optional section populated

## Scope boundary (enforced by in-file doc comment in lib.rs)
NO imports, references, or conceptual mentions of sibling research-grade
IP. Identity is standard Ed25519. Cache/projection is standard CQRS. This
crate ships as a clean MIT-licensable unit of the KeiSeiKit public surface.

Day 2: /pet-setup 7-phase wizard skill that drives this crate via the CLI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 21:29:13 +08:00
..
_rust feat(kei-pet): Day 1 — persona manifest parse + validate + overlay + Ed25519 identity 2026-04-23 21:29:13 +08:00
templates fix: remove genesis-scan from public kit (internal tool, Bundle-only) 2026-04-22 14:11:22 +08:00
design-scrape.sh feat(primitives): 5 shell primitives — design-scrape, live-preview, figma-tokens, frontend-inspect, screenshot-decode 2026-04-21 21:07:45 +08:00
figma-tokens.sh feat(primitives): 5 shell primitives — design-scrape, live-preview, figma-tokens, frontend-inspect, screenshot-decode 2026-04-21 21:07:45 +08:00
frontend-inspect.sh feat(primitives): 5 shell primitives — design-scrape, live-preview, figma-tokens, frontend-inspect, screenshot-decode 2026-04-21 21:07:45 +08:00
harden-base.sh feat(primitives): 3 shell provisioning + hardening 2026-04-21 20:59:38 +08:00
kei-ci-lint.sh feat(primitives): kei-ci-lint workflow YAML validator 2026-04-21 20:56:24 +08:00
kei-docs-scaffold.sh feat(primitives): kei-docs-scaffold shell + kei-changelog Rust 2026-04-21 21:01:28 +08:00
kei-sleep-queue.sh fix: remove genesis-scan from public kit (internal tool, Bundle-only) 2026-04-22 14:11:22 +08:00
kei-sleep-setup.sh feat(primitives): kei-sleep-setup wizard + kei-sleep-sync helper + trigger template 2026-04-22 01:34:42 +08:00
kei-sleep-sync.sh feat(primitives): kei-sleep-setup wizard + kei-sleep-sync helper + trigger template 2026-04-22 01:34:42 +08:00
live-preview.sh feat(primitives): 5 shell primitives — design-scrape, live-preview, figma-tokens, frontend-inspect, screenshot-decode 2026-04-21 21:07:45 +08:00
log-ship.sh feat(primitives): metrics-scrape + log-ship shell primitives 2026-04-21 20:41:17 +08:00
MANIFEST.toml feat(p-install): register 8 new crates in MANIFEST.toml + profile selection 2026-04-23 14:26:11 +08:00
metrics-scrape.sh feat(primitives): metrics-scrape + log-ship shell primitives 2026-04-21 20:41:17 +08:00
provision-hetzner.sh feat(convergence/u3): kei-provision Rust crate — unify hetzner+vultr provisioners 2026-04-23 03:43:40 +08:00
provision-vultr.sh feat(convergence/u3): kei-provision Rust crate — unify hetzner+vultr provisioners 2026-04-23 03:43:40 +08:00
README.md sanitize: remove patent-metadata from main tree (Tier 1+2+3) 2026-04-23 19:20:16 +08:00
screenshot-decode.sh feat(primitives): 5 shell primitives — design-scrape, live-preview, figma-tokens, frontend-inspect, screenshot-decode 2026-04-21 21:07:45 +08:00
tomd.sh sanitize: remove patent-metadata from main tree (Tier 1+2+3) 2026-04-23 19:20:16 +08:00

_primitives — first-class building blocks

_primitives/ holds standalone utilities that agents, hooks, and skills (including /compose-solution) depend on. Unlike _blocks/ (behavioral markdown) or _manifests/ (agent TOML), primitives are executable shell programs installed at $HOME/.claude/agents/_primitives/ by install.sh.

Current primitives

Primitive Purpose Invocation
tomd.sh Universal non-native-format → markdown converter (PDF, DOCX, XLSX, PPTX, CSV, images, code). ~/.claude/agents/_primitives/tomd.sh <file>

tomd.sh is a first-class primitive. Universal non-native-format → markdown converter with configurable cache directory (KEISEI_TOMD_CACHE) and KeiSeiKit-style error tags ([tomd]).

Hook integration

hooks/tomd-preread.sh is a PreToolUse(Read) hook that auto-redirects Claude to the converted markdown when a Read targets .docx / .doc / .xlsx / .pptx / .csv. Cached under $KEISEI_TOMD_CACHE (default /tmp/keisei-tomd-cache).

/compose-solution discovery

Phase 3 prior-art sweep greps _primitives/ alongside _blocks/, _manifests/, skills/, _bridges/, hooks/. If a user task involves file-format parsing, the meta-composer surfaces tomd automatically — reuse over rewrite (RULE "No Patching").