From 0d7c6c2b8426013d781b9d1d3a941c42b990f348 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 12 Jul 2026 07:45:15 +0100 Subject: [PATCH] Rebuild native Epiphany architecture maps --- notes/epiphany-current-algorithmic-map.md | 1719 +++----------------- notes/epiphany-fork-implementation-plan.md | 771 ++------- notes/fresh-workspace-handoff.md | 8 + state/ledgers.msgpack | Bin 415660 -> 416019 bytes state/map.yaml | 2 +- 5 files changed, 388 insertions(+), 2112 deletions(-) diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 8563d74a..31b2bbe8 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -1,1547 +1,232 @@ # Epiphany Current Algorithmic Map -This is the current control-flow map for Epiphany as it exists in the repo now. +This is the source-grounded map of the live machine. Historical route and +bridge anatomy belongs in git history and evidence ledgers, not here. -It is not the future harness spec, and it is not the full Codex machine map. Codex still owns the ordinary turn loop, model/tool execution, persistence substrate, and app-server plumbing. Epiphany is the fork-layer that adds typed modeling state, prompt-facing state injection, client-visible state reads, and repo-local retrieval/indexing organs. +## Objective -The important question for this file is not "what is Epiphany supposed to become?" It is: when the current code runs, where does Epiphany state go? +Epiphany is a native typed organism. Persistent Mind, coordinator policy, +worker lifecycle, organ receipts, prompt context, operator surfaces, and Verse +publication are owned by Epiphany Rust/CultCache/CultMesh/CultNet organs. +Vendored Codex retains Codex-native behavior and the OpenAI-compatible +authentication/model-transport reliquary. It owns no Epiphany state, prompt, +scheduler, route, notification, or interface contract. -## Current Truth +## Authority Map -Current Epiphany is a forked Codex harness with a typed modeling spine. +| Owner | Inputs | Outputs | Invariant | +|---|---|---|---| +| `epiphany-state-model` | typed state fields | `EpiphanyThreadState` and prompt projection | State is typed; rendering is not authority. | +| `coordinator_state.rs` | current state plus validated ordinary update | durable native thread state | Owns the ordinary update transaction, but not all state commits. | +| `coordinator_launch.rs` | validated launch plan, state, runtime envelopes | atomic state-plus-launch transaction | Launch writes `THREAD_STATE_KEY` beside runtime records. | +| `coordinator_acceptance.rs` | reviewed finding, Mind review, commit receipt | atomic state-plus-Mind-witness transaction | Acceptance and its witnesses land together. | +| `thread_state_store.rs` | raw typed state entry | low-level CultCache read/write | Substrate, not policy; its public writers are a current authority wound. | +| `coordinator_service.rs` | state/runtime store paths and typed commands | state update, launch, accept, interrupt results | Facade routes typed work; it contains no policy or protocol mapping. | +| `surfaces/*` | native state, runtime snapshots, pressure/freshness inputs | scene, jobs, roles, planning, context, graph, CRRC, coordinator recommendations | Read surfaces derive; they do not mutate. | +| `runtime_spine.rs` | typed launch/result/receipt documents | CultCache runtime records | Runtime lifecycle and evidence are durable typed documents. | +| `mind_gateway.rs` and coordinator acceptance | worker findings and proposed patches | review, rejection, or state-commit receipts | Worker thought cannot write Mind directly. | +| `substrate_gate.rs` | bounded access intent | scoped access grant/refusal | Repository access and state admission are separate authorities. | +| `eyes_gateway.rs` | inspected source under a grant | evidence review/packet/refusal | Looked-at truth carries provenance. | +| `hands_gateway.rs` | approved action intent | patch/command/commit/PR receipts | Consequence is bounded, attributable, and reviewable. | +| `soul_gateway.rs` | claimed consequence plus evidence | verdict/refusal receipt | Work is not true merely because it ran. | +| `continuity_gateway.rs` | rupture/checkpoint/recovery facts | continuity receipts | Survival state is explicit, not transcript residue. | +| `heartbeat_state.rs` and daemon binaries | durable schedule/liveness policy | pulses, launch pressure, sleep/rumination state | Scheduling is physiology, not project truth. | +| `cultmesh_integration.rs` and `epiphany-verse-query` | typed local documents | private/local/public Verse projections | Visibility never creates authority or declassifies private state. | +| Persona loop | state projection, stimulus, semantic recall | natural speech plus interpreted candidate actions | Imagination projects; Persona speaks; Mind interprets. | +| vendored Codex | Codex sessions and OpenAI-compatible auth/model transport | Codex behavior and model transport | No Epiphany protocol or durable Epiphany state crosses this boundary. | -The spine exists in more than twenty-five live paths: - -- protocol state shape: `EpiphanyThreadState`, `RolloutItem::EpiphanyState`, retrieval summaries, and prompt tags live in [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:103). -- in-memory session state: `SessionState` stores an optional `EpiphanyThreadState`, and `Session` exposes thin async accessors over it in [state/session.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/state/session.rs:36) and [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:1240). -- prompt injection: `build_initial_context` reads the optional state and adds a bounded `` developer fragment; the renderer now lives beside the typed state model and includes durable investigation-checkpoint and planning sections when authoritative state carries them, so a resumed agent can see whether source gathering was banked and what captures/backlog/drafts exist without treating them as adopted objectives in [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2434), [prompt.rs](E:/Projects/EpiphanyAgent/epiphany-state-model/src/prompt.rs:33), and [prompt.rs](E:/Projects/EpiphanyAgent/epiphany-state-model/src/prompt.rs:127). -- per-turn persistence: normal turn setup persists one `RolloutItem::EpiphanyState` after the `TurnContext` when state exists in [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2677). -- client read hydration: app-server thread views attach live or reconstructed `thread.epiphanyState` in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4706) and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4822). -- explicit distillation proposals: app-server routes read-only `thread/epiphany/distill` through a loaded-thread handler into `epiphany-core` so one explicit observation can become a patch candidate without mutating state; tool/command/shell/model sources now get typed evidence kinds and bounded salient-output summaries instead of dumping raw output into durable state in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4358) and [distillation.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/distillation.rs:28). -- explicit map/churn proposals: app-server routes read-only `thread/epiphany/propose` through a loaded-thread handler into `epiphany-core` so verified observations with code refs and accepting recent evidence can be selected explicitly or auto-selected as a bounded path cluster, prioritize the strongest selected observation, focus or extend architecture graph nodes, rescue unanchored graph nodes through strict semantic overlap, carry linked dataflow nodes and incident graph edges into the frontier, update churn candidates with match-kind-aware map-delta judgment and pressure, and still avoid mutation until promotion in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4429) and [proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:115). -- explicit promotion gates: app-server routes `thread/epiphany/promote` through a loaded-thread handler into `epiphany-core` policy evaluation, rejects failed verifier evidence without mutation, applies accepted candidates through the same durable update path, and now treats medium/high/expanded/broadening/semantic churn deltas as needing explicit rationale plus stronger verifier evidence whose kind is token-matched rather than substring-matched; the same gate also validates durable investigation-checkpoint packets, including linked evidence ids, before they can be inked into state in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4501) and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33). -- explicit state updates: app-server routes `thread/epiphany/update` through `epiphany-codex-bridge` mutation policy, which rejects malformed appended observation/evidence graph records and structurally invalid replacement fields, including investigation checkpoints that cite missing evidence and planning records with broken ids/source refs/backlog links/draft acceptance criteria, then asks `CodexThread` only to persist the already-mutated typed state snapshot as a `RolloutItem::EpiphanyState` in [mutation_service.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/mutation_service.rs:126), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:348), and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:44). -- live state notifications and write responses: app-server declares experimental `thread/epiphany/stateUpdated` and emits it with the updated typed state, typed `source`, event-level `revision`, and typed `changedFields` after successful direct updates and accepted promotions, but not after rejected promotions; direct `thread/epiphany/update` and accepted `thread/epiphany/promote` responses expose the same revision/change metadata, accepted promotions always report `Evidence` because verifier evidence is appended even when the patch evidence list is empty, and successful write response/notification states now use the same client-visible live projection as `thread/read`, including retrieval-summary backfill when durable state has no persisted retrieval metadata, in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:1113), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4354), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4419), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4428), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4555), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4608), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4652), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4693), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11327), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11370). -- scene projection: the `scene` view lens reads the same live/stored Epiphany state view used by `thread/read` and adapts the core scene projection. `epiphany-core` derives the compact client scene with objective, active subgoal, invariant status counts, graph focus/counts, retrieval status, investigation-checkpoint summary counts, observation/evidence summaries, churn, live/stored source, and available control-plane actions without mutating or persisting state in [scene.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/scene.rs:1). -- job/progress reflection: the `jobs` view lens reads the same thread view as scene, optionally fills retrieval state for loaded threads with no Epiphany state, and adapts core-derived non-authoritative progress slots for retrieval indexing, graph remap, invariant verification, and bound specialist work. Durable `job_bindings` now act as thin Epiphany-owned authority slots with binding id, kind, scope, owner role, authority scope, linked ids, and optional blocking reason only. Runtime job ids project from `runtime_links` through core job view policy; old `agent_jobs` bindings are sealed instead of live-crawled in [jobs.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/jobs.rs:1). -- bound-job progress notifications: app-server still declares experimental `thread/epiphany/jobsUpdated` as sealed legacy Codex evacuation telemetry, but the handler no longer emits Epiphany updates from old `agent_job_progress:{json}` background events. Heartbeat-owned activation and typed runtime-spine receipts are now the live Epiphany path. -- explicit job control: app-server declares experimental `thread/epiphany/jobLaunch` and `thread/epiphany/jobInterrupt`, routes them through core launch/interrupt handlers that persist heartbeat-backed durable `job_bindings` revisions through the authoritative Epiphany state path, and emit `thread/epiphany/stateUpdated` with source `jobLaunch` or `jobInterrupt` instead of creating SQLite `agent_jobs` rows or pretending jobs reflection is the scheduler. -- freshness reflection: app-server declares experimental read-only `thread/epiphany/freshness`, reads the same live/stored thread view used by the view lenses and context, fills live retrieval state for loaded threads, then adapts those inputs into core freshness policy. `epiphany-core` derives the bounded retrieval/graph freshness lens plus watcher-backed invalidation inputs with watched root, changed paths, mapped graph-node hits, active-frontier hits, and revision/source identity; app-server maps the core result to protocol without mutating, scheduling, notifying, or performing automatic semantic invalidation in [freshness.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/freshness.rs:1), [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:350), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4167), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4259), [epiphany_invalidation.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/epiphany_invalidation.rs:19), [epiphany_invalidation.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/epiphany_invalidation.rs:67), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:14910). -- targeted context reflection: app-server declares experimental read-only `thread/epiphany/context`, reads the same live/stored Epiphany state view used by the view lenses, and derives a bounded state shard containing selected graph nodes/edges, links, active frontier, checkpoint, the full durable investigation-checkpoint packet, observations, direct evidence, linked evidence, and missing requested ids without retrieval, proposal, promotion, notification, mutation, or persistence in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:355), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4253), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4261), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11152). -- graph traversal reflection: app-server declares experimental read-only `thread/epiphany/graphQuery`, reads the same live Epiphany state view used by context, and derives explicit node/edge lookup, path/symbol matches, bounded neighbors, edge-kind matches, and frontier neighborhoods with architecture/dataflow links plus frontier/checkpoint identity, matched selectors, and missing ids without retrieval, proposal, promotion, indexing, notification, mutation, or scheduling in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:379), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4720), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:5060), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:15201). -- planning reflection: the `planning` view lens reads the same live/stored Epiphany state view and adapts the core planning projection. `epiphany-core` returns typed captures, backlog items, roadmap streams, Objective Drafts, GitHub source refs, count summaries, and the separate active objective without adopting drafts, launching work, notifying, mutating, or scheduling in [planning.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/planning.rs:1). -- canonical view lens reflection: app-server declares experimental read-only `thread/epiphany/view` with selectable lenses and uses it as the canonical operator read surface for pressure, reorient, CRRC, and coordinator projections. Those projections no longer have standalone protocol verbs; the separate `reorientLaunch`, `reorientResult`, and `reorientAccept` surfaces remain because they carry authority, result read-back, and review acceptance rather than mere reflection. -- context-pressure reflection: core token telemetry carries `model_auto_compact_token_limit` beside total/last usage and `model_context_window`; the `pressure` view lens reads live token usage or the latest stored rollout `TokenCount`, derives current context pressure from `last_token_usage` rather than cumulative thread spend, treats cumulative-only telemetry as unknown, and raises `shouldPrepareCompaction` at 80% of the active auto-compact/context limit without mutating Epiphany state or scheduling compaction in [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:2237), [turn_context.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/turn_context.rs:103), [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2716), [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:360), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4361), [token_usage_replay.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor/token_usage_replay.rs:75), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4306), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11028). -- pre-compaction checkpoint intervention: app-server `TokenCount` handling now checks the same pressure mapper, and for loaded Epiphany threads crossing `shouldPrepareCompaction` it steers the active turn once with a bounded CRRC checkpoint directive to bank working context before compaction/reorientation. The per-turn dedupe bit and the pending compact handoff live in listener `ThreadState`; successful steering marks the active turn for a forced compact action at clean turn completion, while aborted turns clear the handoff. The intervention uses existing turn steering and turn-boundary automation rather than a new scheduler in [bespoke_event_handling.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/bespoke_event_handling.rs:1467), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:15405), and [thread_state.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/thread_state.rs:144). -- reorientation policy: the `reorient` view lens reuses the same live/stored thread view plus mapped pressure/freshness/watcher signals, then adapts those inputs into pure `epiphany-core` verdict policy. Core derives the bounded `resume`/`regather` decision with checkpoint-path/frontier reasons; app-server only maps the core decision back to protocol shape, without mutating, compacting, scheduling, notifying, or continuing work in [reorient.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/reorient.rs:1), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4514), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:15296). -- CRRC coordinator recommendation: the `crrc` view lens reuses pressure/freshness/watcher/reorientation mapping plus the fixed `reorient-worker` binding and result read-back helper, recognizes already accepted reorientation findings so an accepted result is not recommended for acceptance again, and calls pure `epiphany-core` CRRC policy to return one bounded recommendation such as continue, prepare checkpoint, launch worker, wait, review, accept, or regather manually without mutating, launching, accepting, compacting, notifying, scheduling, or silently continuing work in [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4661), [crrc.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/crrc.rs:60), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4546). -- role ownership projection: the `roles` view lens reuses the same state/jobs/pressure/reorient/result/CRRC signals as the coordinator loop, and projects implementation, Imagination/planning, modeling/checkpoint, verification/review, and reorientation lanes with owner roles, status, linked jobs, authority scopes, and recommended scene actions without launching, scheduling, accepting, compacting, notifying, or mutating state. App-server adapts concrete protocol jobs and thread state, while the pure role-board projection policy now lives in [role_board.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_board.rs:70). -- role specialist launch/read-back/acceptance: app-server declares experimental `thread/epiphany/roleLaunch`, read-only `thread/epiphany/roleResult`, and write-gated `thread/epiphany/roleAccept`. `roleLaunch` accepts fixed Imagination/planning, modeling/checkpoint, and verification/review role ids, builds bounded specialist payloads from authoritative Epiphany state, routes them through the heartbeat-backed `epiphany_launch_job` seam, opens a typed runtime-spine job receipt, and emits the normal `jobLaunch` state update for `jobBindings` only. `roleResult` resolves heartbeat bindings through typed runtime-spine job results and seals legacy `agent_jobs` bindings, then adapts worker JSON through core role-result interpretation in [role_result.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_result.rs:45), projecting structured output as a reviewable finding with verdict, summary, next safe move, inspected files, frontier/evidence ids, optional `statePatch`, optional `selfPatch`, coordinator `selfPersistence` review, and errors without mutation, promotion, scheduling, or hidden continuation. `selfPatch` is a Ghostlight-shaped lane-memory request, not project truth: core accepts only role-matched, bounded, evidence-grounded memory/goal/value/private-note mutations and refuses objectives, graphs, checkpoints, scratch, planning, jobs, authority, code edits, or raw transcripts with reasons. `roleAccept` accepts completed heartbeat findings from typed runtime-spine results, accepts completed Imagination findings only when they contain a valid planning-only patch with draft Objective Draft review gates, accepts completed modeling/checkpoint findings only with a modeling-safe `statePatch`, applies accepted project patches through the existing Epiphany state validator, and uses core acceptance bundle policy to build the audit observation, evidence, and typed receipt. GUI/coordinator accept paths then apply accepted `selfPatch` requests to typed CultCache role dossiers in `state/agents.msgpack` through the native `epiphany-agent-memory-store` binary. Implementation stays owned by the main coding agent, verification output remains review-only, and reorientation stays on the CRRC-specific `reorientLaunch` / `reorientResult` / `reorientAccept` path. -- shared prompt memory projection and role dossiers: the prompt config now carries `[shared].persistent_memory` in [epiphany_specialists.toml](E:/Projects/EpiphanyAgent/epiphany-core/src/prompts/epiphany_specialists.toml:2). App-server parses that block through the bridge, prepends it with `epiphany_agent_prompt_with_memory` for embodied lanes, and keeps reorientation as a Continuity worker/protocol path rather than a role dossier. The base `` doctrine reinforces the Perfect Machine rule through [prompt.rs](E:/Projects/EpiphanyAgent/epiphany-state-model/src/prompt.rs:31) and [epiphany_doctrine.md](E:/Projects/EpiphanyAgent/epiphany-state-model/src/prompts/epiphany_doctrine.md:1). Individual Ghostlight-shaped role dossiers now live in typed CultCache `state/agents.msgpack` for embodied sub-agent lanes, and the native `epiphany-agent-memory-store` binary validates, reviews, and applies bounded self-memory patches through the Rust store. -- fixed-lane coordinator: the `coordinator` view lens composes role, pressure, reorient, CRRC, role result, and reorient result signals, and returns one current action without mutation. App-server assembles host/protocol inputs, but the pure fixed-lane decision ladder now lives in `epiphany-core` in [coordinator.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/coordinator.rs:132). Review acceptance and implementation clearance are intentionally different: an accepted verification finding clears implementation only when the verifier verdict is `pass`; accepted `needs-evidence`, `needs-review`, or `fail` findings route back toward modeling/checkpoint strengthening before code work resumes. `regatherManually` is now fallback, not a supervisor-puppeteering excuse: completed unaccepted modeling findings stop at `reviewModelingResult`, modeling acceptance precedes verification, and fixed lane actions are considered before manual regather. -- MVP operator view: native `epiphany-mvp-status` launches app-server over stdio, starts or reads one thread, gathers scene, planning, pressure, reorient, jobs, roles, Imagination/modeling/verification role results, reorient result, CRRC responses, heartbeat, and Persona bubble artifacts, and renders them as text or JSON so the loop can be dogfooded without Python owning the product surface. -- MVP dogfood runner: the old Python runner was cut with the `agent_jobs` path. The replacement must be native Rust/CultCache/CultNet and complete heartbeat-owned runtime-spine job results with operator-safe artifacts. -- Agent function/API telemetry: native `epiphany-agent-telemetry` mechanically parses sealed AppServerClient JSONL transcripts into operator-safe telemetry with method counts, request shape, job/status/path fields, and visible function/tool names while sealing text, turn items, raw results, and direct agent messages. -- reorientation launch: app-server now declares experimental `thread/epiphany/reorientLaunch`, requires a loaded thread plus durable investigation checkpoint, consumes the live reorientation verdict, and launches one fixed `reorient-worker` binding through the existing job-control seam with explicit resume-versus-regather scope, checkpoint-derived payload, and structured-output expectations instead of pretending CRRC suddenly grew a scheduler in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:370), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4575), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4519). -- reorientation result read-back: app-server now declares experimental read-only `thread/epiphany/reorientResult`, defaults to the fixed `reorient-worker` binding, resolves heartbeat bindings through typed runtime-spine job results, seals legacy `agent_jobs` bindings, and projects a reviewable finding with mode, summary, next safe move, checkpoint-validity flag, inspected files, frontier ids, evidence ids, raw result, and any errors without mutating state, promoting evidence, or scheduling follow-up work. -- reorientation finding acceptance: app-server now declares experimental `thread/epiphany/reorientAccept`, requires a loaded thread and a completed `reorient-worker` result, accepts heartbeat-backed results from typed runtime-spine receipts before falling back to old bindings, uses core acceptance bundle policy to build accepted observation/evidence/receipt payloads plus optional scratch and durable investigation-checkpoint updates, persists through the normal typed update path, and emits `thread/epiphany/stateUpdated` with source `reorientAccept` without accepting pending work, auto-promoting arbitrary worker output, launching follow-up work, or silently continuing implementation in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:378), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4635), [role_result.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_result.rs:150), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4885). -- retrieval/indexing: app-server routes `thread/epiphany/retrieve` and `thread/epiphany/index` through `epiphany-codex-bridge::retrieve`, which reads only host cwd/Codex-home facts from `CodexThread` and calls native `epiphany-core` retrieval/indexing in [retrieve.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve.rs:42), [retrieve.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve.rs:57), and [retrieve.rs](E:/Projects/EpiphanyAgent/epiphany-codex-bridge/src/retrieve.rs:69). - -The thick Epiphany-owned implementation is mostly outside vendored Codex now: - -- prompt rendering lives in [epiphany-state-model/src/prompt.rs](E:/Projects/EpiphanyAgent/epiphany-state-model/src/prompt.rs:33), including the always-rendered operating-discipline section in [prompt.rs](E:/Projects/EpiphanyAgent/epiphany-state-model/src/prompt.rs:26). -- generic rollout replay for stored-thread reads lives in [epiphany-core/src/rollout.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/rollout.rs:38). -- retrieval and indexing live in [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:144) and [retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:160), with summary-only freshness reads in [retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:100). -- deterministic observation distillation lives in [epiphany-core/src/distillation.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/distillation.rs:28). -- deterministic map/churn proposal from verified, evidence-backed observations lives in [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:115). -- verifier-backed promotion policy lives in [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33). -- pressure, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy live in [pressure.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/pressure.rs:15), [crrc.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/crrc.rs:60), [coordinator.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/coordinator.rs:132), [role_board.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_board.rs:70), and [role_result.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_result.rs:45). - -## Whole Control Flow +## Primary State Flow ```mermaid -flowchart TD - A["Loaded Codex Session"] --> B["SessionState.epiphany_state"] - B --> C["build_initial_context"] - C --> D["EpiphanyStateInstructions wrapper"] - D --> E["epiphany-state-model render_epiphany_state"] - E --> EA["Operating Discipline anti-Jenga section"] - EA --> F[" developer fragment"] - F --> G["Model/tool turn runs in normal Codex loop"] - G --> H["record_context_updates_and_set_reference_context_item"] - H --> I["Persist TurnContext"] - H --> J["Persist RolloutItem::EpiphanyState if state exists"] - J --> K["Rollout file"] - K --> L["Session resume reconstruction"] - L --> B - K --> M["Stored thread/read reconstruction"] - M --> N["Thread.epiphanyState"] - B --> O["Live thread.epiphanyState"] - O --> N - O --> P["Backfill retrieval summary if missing"] - P --> N - N --> Q["Client can read typed state"] - N --> QS["view.scene derives compact client scene"] - QS --> Q - N --> QJ["view.jobs derives progress slots"] - QJ --> Q - N --> QF["thread/epiphany/freshness derives freshness lens + watcher invalidation inputs"] - QF --> Q - N --> QC["thread/epiphany/context derives targeted state shard"] - QC --> Q - N --> QG["thread/epiphany/graphQuery traverses graph neighborhoods"] - QG --> Q - N --> QPLAN["view.planning projects captures/backlog/drafts"] - QPLAN --> Q - N --> QVIEW["thread/epiphany/view selects read lenses"] - QVIEW --> Q - A --> QP["TokenUsageInfo stores usage, context window, and auto-compact limit"] - QP --> QQ["view.pressure derives read-only context pressure"] - QQ --> QVIEW - QF --> QR["view.reorient derives read-only resume/regather verdict"] - QQ --> QR - QR --> QVIEW - QR --> QCRRC["view.crrc recommends the next explicit CRRC action"] - QQ --> QCRRC - QJ --> QCRRC - QCRRC --> QVIEW - QR --> QRL["thread/epiphany/reorientLaunch can explicitly consume that verdict"] - QRL --> QRLR["thread/epiphany/reorientResult reads back worker findings"] - QRLR --> Q - QRLR --> QRLA["thread/epiphany/reorientAccept can bank reviewed findings"] - QRLA --> J - A --> R["thread/epiphany/retrieve requires loaded thread"] - A --> S["thread/epiphany/index requires loaded thread"] - A --> AA["thread/epiphany/distill requires loaded thread"] - A --> AH["thread/epiphany/propose requires loaded thread"] - A --> AD["thread/epiphany/promote requires loaded thread"] - A --> Z["thread/epiphany/update requires loaded thread"] - A --> AJL["thread/epiphany/jobLaunch requires loaded thread"] - A --> AJI["thread/epiphany/jobInterrupt requires loaded thread"] - A --> QRLQ["thread/epiphany/reorientLaunch requires loaded thread"] - AA --> AB["epiphany-core distill_observation"] - AB --> AC["Observation/evidence patch proposal"] - AC --> AD - AH --> AI["epiphany-core propose_map_update"] - AI --> AIA["Explicit ids or bounded auto-selected observation cluster"] - AIA --> AJ["Map/churn patch proposal"] - AJ --> AD - AD --> AE["epiphany-core evaluate_promotion"] - AE --> AF{"Accepted?"} - AF -->|"No"| AG["Return reasons, no state mutation"] - AF -->|"Yes"| Z - R --> T["epiphany-codex-bridge retrieve_thread_epiphany"] - S --> U["epiphany-codex-bridge index_thread_epiphany_retrieval_state"] - Z --> ZA["epiphany-codex-bridge apply_epiphany_state_update_to_thread"] - AJL --> AJLA["epiphany-codex-bridge launch_epiphany_job_on_thread"] - QRLQ --> QRLA["Map checkpoint + reorient verdict into fixed reorient-worker launch"] - QRLA --> AJLA - AJLA --> AJLB["Persist authority-slot jobBinding + runtimeLink"] - AJLB --> ZD - AJI --> AJIA["epiphany-codex-bridge interrupt_epiphany_job_on_thread"] - AJIA --> AJIB["Interrupt backend worker(s) + clear bound backend from jobBinding"] - AJIB --> ZD - ZA --> ZB["Apply typed patch and increment revision"] - ZB --> B - ZB --> ZC["Persist immediate RolloutItem::EpiphanyState"] - ZB --> ZD["Project client-visible live state (retrieval summary backfill if needed)"] - ZD --> ZE["Return response and emit thread/epiphany/stateUpdated with source, revision, changedFields"] - ZE --> Q - ZC --> K - T --> V["epiphany-core retrieve_workspace"] - U --> W["epiphany-core index_workspace"] - V --> X["Exact/path search + Qdrant if fresh + BM25 fallback"] - W --> Y["Ollama embeddings + Qdrant points + manifest under codex_home"] +flowchart LR + I["Typed intent or worker finding"] --> G["Mind gateway review"] + G -->|reject| R["Typed rejection receipt"] + G -->|admit| V["State validation"] + V --> C["Single coordinator commit path"] + C --> S["Native thread-state CultCache"] + S --> P["Derived native surfaces"] + P --> O["Coordinator / operator / Eve projections"] ``` -What this means in plain English: +There are currently three state transaction authorities: -- Epiphany state is a durable object, not prompt folklore. -- The prompt can read it every turn when it exists. -- The app-server can expose it as typed thread data. -- The app-server can also expose a compact read-only scene derived from that typed state for future clients. -- The app-server can expose read-only job/progress slots derived from typed state and retrieval summaries without creating a scheduler. -- The app-server can expose a read-only freshness lens derived from retrieval summaries plus graph frontier/churn state and, for loaded threads, watcher-backed invalidation telemetry without turning file staleness into a hidden worker. -- The app-server can expose a targeted read-only context shard for clients that need graph/evidence detail without pulling the full typed state. -- The app-server can expose read-only graph traversal for clients and agents that need frontier neighborhoods, path/symbol matches, or local blast-radius walks without turning traversal into proposal or promotion. -- The app-server can expose read-only planning state for clients that need captures, backlog, roadmap streams, and Objective Drafts without turning them into active objectives. -- The app-server can expose pressure, reorient, CRRC, and coordinator projections through one canonical read-only view lens surface instead of preserving a private verb zoo. -- The pressure lens exposes context pressure derived from real token telemetry without starting compaction or pretending vibes are telemetry. -- A loaded thread can ask for a typed observation/evidence proposal without mutating state. -- A loaded thread can ask a verifier-backed promotion gate to reject or apply that proposal. -- A loaded thread can now accept explicit typed state patches and persist them immediately. -- Successful direct updates and accepted promotions now return and notify clients that typed state changed, which revision landed, and which top-level state fields changed. -- Those write response/notification states are now projected through the same live read helper as `thread/read`, so retrieval-summary backfill is consistent across client-visible state surfaces without becoming a durable write. -- Retrieval and indexing are typed side paths hanging off loaded threads. -- Retrieval remains read-only; state mutation has its own control-plane door. -- Map/churn proposal is also read-only; accepted graph/churn edits still go through promotion and update. +1. ordinary updates through + `coordinator_state::{apply_coordinator_state_update, + apply_coordinator_state_update_from_state, + apply_coordinator_state_update_to_state}`; +2. launch transactions through + `coordinator_launch::commit_coordinator_job_launch_in_cache`; +3. acceptance transactions through + `coordinator_acceptance::commit_state_with_mind_witness`. -## Perfect Machine Audit Result +They share typed state and validation primitives, but not one commit primitive. +`thread_state_store::{write_thread_state_entry, write_thread_state}` are public +raw writers underneath them. This is a live authority defect, not an intended +invariant. `EpiphanyCoordinatorService` is the narrow caller-facing facade. -Source audit on 2026-04-26 re-read the changed Phase 6 reflection paths against the cited code instead of just checking that links resolve. +Forbidden writers: -The current landed machine is still coherent. The core shape is not ornamental: one protocol state object flows through session state, prompt rendering, rollout persistence, thread hydration, explicit retrieval/indexing, read-only distillation/proposal, verifier-backed promotion, the single durable update writer, and now a live state notification that reflects completed writes. The useful simplification pressure is already present in the boundaries: retrieval reads, indexing writes only the semantic catalog, distillation/proposal draft patches, promotion gates, update persists, and notification broadcasts only after the write is done. +- worker result payloads; +- operator display JSON; +- Codex rollouts or Codex thread objects; +- derived scene/coordinator/context projections; +- heartbeat telemetry; +- CultMesh mirrors and public Verse documents. -Nothing in the current typed spine obviously deserves deletion right now. The parts that would turn this into Jenga are still correctly listed as non-flows: automatic tool-output ingestion, automatic watcher-driven invalidation, specialist scheduling, broad event streaming, and an automatic Compact-Rehydrate-Reorient-Continue coordinator. Thin GUI/client reflection is no longer forbidden as a category, provided it reflects and steers typed state rather than inventing a second source of truth. +## Worker And Receipt Flow -The next Perfect Machine move is not adding another writer, not re-hardening Phase 5, and no longer the first scene, job, freshness, targeted context, graph traversal, planning, pressure, watcher, investigation-checkpoint, or reorientation surface. Those organs now let clients inspect the machine Epiphany already built at summary, progress, bounded-detail, graph-walk, planning, freshness, context-pressure, file-movement, durable-planning-packet, and wakeup-verdict levels. The next outward work should make those projections operational in the GUI and fixed lanes, not invent yet another decorative sense organ. - -## Natural Language Spine - -This is the same flow in the language Epiphany is supposed to make the model carry around while it works. The images below are compression of the code paths cited in the flow sections, not free-floating lore. Tiny but important distinction; otherwise we are just painting flames on a shopping cart. - -| Stage | What It Means | Mental Image | -| --- | --- | --- | -| State shape | Epiphany first gives the system a real object for understanding, instead of asking the transcript to remember what matters. | A labeled field notebook with fixed sections, not loose napkins in a storm. | -| Resume | When a thread wakes up, Epiphany rebuilds the latest surviving model of the work before asking the agent to continue. | The foreman finds yesterday's marked-up blueprint before letting anyone pick up a saw. | -| Prompt injection | The current model is summarized into the developer context so the agent starts the turn facing the actual map. | The blueprint is pinned above the workbench, not buried in a drawer. | -| Operating discipline | The renderer always includes the anti-Jenga regression/benchmark rule so failed hypotheses get reverted before the next attempt. | A red tag on the workbench: one measured cut, then remove the bad jig before trying another. | -| Turn execution | Codex still runs the ordinary model/tool loop; Epiphany is context and discipline around that loop, not a replacement engine yet. | The same workshop machines run, but now there is a work order on the wall. | -| Persistence | After a real user turn, Epiphany snapshots the current model beside the normal turn context. | The field notebook gets dated and shelved after each real work session. | -| Thread read | Clients can ask for the current Epiphany model as typed data instead of scraping prompt text or transcript debris. | The dashboard reads the blueprint file directly, not a photo of the workbench. | -| Scene projection | Clients can ask for a compact reflection of the typed model: active goal, graph focus, retrieval status, compact investigation-checkpoint summary, evidence counts, churn, and available control actions. It is derived from state, not a second state store. | A foreman-facing wall board copied from the blueprint ledger; useful at a glance, legally not the blueprint. | -| Job projection | Clients can ask which Epiphany work slots are idle, needed, blocked, running, or unavailable for indexing, remap, verification, and future specialists. The slots are derived from state and retrieval summaries; they do not start work. | A shift board listing which crews would be needed if work begins, not a foreman secretly hiring people in the back room. | -| Freshness projection | Clients can ask whether retrieval or graph understanding is stale, missing, or ready, and loaded threads now also expose watcher-observed file movement with watched root, changed paths, mapped graph-node hits, and frontier hits. The answer is still a lens over existing retrieval/frontier/churn/watcher signals; it does not remap, schedule, or invalidate anything by itself. | A clipboard listing which blueprint tabs got coffee on them and which shelf of the catalog needs rechecking, now with a door sensor showing which cabinet was opened, without sending anyone to swing a hammer. | -| Context projection | Clients can ask for one bounded slice of the typed model: selected graph nodes/edges, active frontier, graph checkpoint, full investigation checkpoint packet, observations, direct evidence, linked evidence, and missing ids. It is derived from state and does not propose or promote anything. | A librarian opens the exact ledger pages you named, adds the active bookmark by default, and says which requested tabs were not in the book. | -| Planning projection | Clients can ask for captured ideas, imported issue refs, backlog items, roadmap streams, and Objective Drafts while keeping the active objective separate. It is derived from state and does not adopt work. | A planning wall with sticky notes and candidate work orders; useful, visible, and absolutely not the signed job ticket. | -| Pressure projection | Clients can ask how close the live or stored thread is to compaction pressure using token usage, context window, and the recorded auto-compact threshold. The answer may recommend preparation, but it does not act. | A pressure gauge on the boiler; it does not grab the wrench or pretend steam is a moral failing. | -| Retrieval | A loaded thread can ask a structured question of the repo through one typed retrieval surface. | A librarian brings back marked pages instead of making the agent rummage through every shelf. | -| Indexing | Persistent semantic memory is built only through an explicit indexing path. | The librarian updates the card catalog only when asked, not while pretending to answer a question. | -| Distillation | One explicit observation can be normalized into a typed observation/evidence patch, but not promoted automatically. | The clerk drafts a ledger entry in pencil before anyone is allowed to ink it. | -| Proposal | Verified observations with code refs and accepting recent evidence can produce a candidate graph frontier/churn patch without writing it. The caller can provide ids, or the proposal engine can choose a small ready path cluster, then reuse existing map nodes, focus linked context, and report pressure from the actual map delta. | The clerk overlays tracing paper on the old blueprint before drawing a new wall through the plumbing, choosing only the relevant marked pages before measuring how much load the sketch would put on the frame. | -| Promotion | A verifier-backed gate can reject a proposal without mutation or send it through the durable update path. | The foreman stamps the pencil draft before the clerk reaches for the red pen. | -| State updates | A loaded thread can accept explicit typed patches that append validated observations/evidence and replace bounded map/scratch/churn fields. Malformed appended evidence graph records and structurally broken replacement fields are rejected before mutation. | The clerk finally has the red pen, but the ledger refuses orphan receipts and impossible blueprint tabs before the ink touches paper. | -| State responses and notifications | Successful direct updates and accepted promotions return the landed revision and changed-field labels to the caller, then publish the updated typed state to app-server clients with source, revision, and changed-field labels saying which control-plane door caused it and which ledger sections changed. The state object is the same client-visible projection as `thread/read`, including retrieval-summary backfill when needed. | The clerk hands the filing receipt to the person at the counter, then rings the little bell for the room; both say which page number landed and which tabs were touched, with the card-catalog status clipped to the same page the dashboard would show. | - -## Flow 1: State Shape - -### Input - -The protocol layer defines the object that all other Epiphany paths agree on. - -### Plain-language role - -This is where Epiphany stops being an instruction style and becomes a thing the program can carry. The state shape is the skeleton: objective, subgoals, graph, planning, scratch, observations, evidence, churn, mode, and retrieval summary all get named places to live. - -The point is not just serialization. The point is pressure. If understanding has a typed slot, later code can ask whether that slot is fresh, missing, stale, or contradictory. Without this shape, the agent has only memory soup and a little sailor hat. - -### Mechanism - -`vendor/codex/codex-rs/protocol/src/protocol.rs` adds: - -- prompt tags: `EPIPHANY_STATE_OPEN_TAG` and `EPIPHANY_STATE_CLOSE_TAG`. -- rollout storage: `RolloutItem::EpiphanyState(EpiphanyStateItem)`. -- canonical thread state: `EpiphanyThreadState`. -- map/planning/scratch/evidence/churn/mode structs. -- retrieval metadata: `EpiphanyRetrievalState`, `EpiphanyRetrievalStatus`, and `EpiphanyRetrievalShardSummary`. - -Code refs: - -- [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:103) -- [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:2955) -- [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:2972) -- [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:3168) - -### Output - -Every other current Epiphany path moves this shape around. There is no separate prompt-only representation pretending to be canonical. - -## Flow 2: Resume Rebuilds Live State - -### Input - -A session is resumed from rollout items. - -### Plain-language role - -Resume is the amnesia antidote. Codex can already rebuild conversation history, but Epiphany adds a second reconstruction target: the current model of what the work means. - -The important behavior is selective survival. If a later turn was rolled back, its Epiphany snapshot must die with it. If compaction happened, the latest valid model should survive. This is the difference between a real field notebook and a cursed diary that keeps pages from timelines you deleted. - -### Mechanism - -`Session::apply_rollout_reconstruction` calls the ordinary Codex rollout reconstruction path, replaces history/reference context, then writes the reconstructed `epiphany_state` back into live session state. - -The current core resume path uses Codex-side reconstruction code in `session/rollout_reconstruction.rs`, because resume has to rebuild history, reference context, previous turn settings, and Epiphany state together. The app-server stored-thread read path uses the narrower `epiphany-core` replay helper through the codex-core re-export, because that path only needs the latest surviving Epiphany snapshot for `Thread.epiphanyState`. - -That distinction matters. The `epiphany-core` helper is not a full history reconstructor. It reverse-scans rollout items, groups them by user-turn boundaries supplied by Codex, skips rolled-back user turns, and deliberately lets an older valid snapshot survive a compaction marker. - -Code refs: - -- [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:1197) -- [session/rollout_reconstruction.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/rollout_reconstruction.rs:107) -- [epiphany-core/src/rollout.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/rollout.rs:35) -- [epiphany-core/src/rollout.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/rollout.rs:295) -- [core/src/epiphany_rollout.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/epiphany_rollout.rs:5) -- [session/rollout_reconstruction_tests.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/rollout_reconstruction_tests.rs:1200) - -### Output - -`SessionState.epiphany_state` is restored before later turn construction asks for prompt context. - -### Invariant - -The latest state is not merely the last serialized `EpiphanyState` item. Replay respects user-turn boundaries and rollback, and current tests explicitly preserve the latest valid Epiphany state across compaction. Rolled-back state should not resurrect itself like a little gremlin. - -## Flow 3: Turn Startup Injects State Into The Prompt - -### Input - -A loaded session starts building initial turn context and already has `SessionState.epiphany_state`. - -### Plain-language role - -Prompt injection is where the stored model becomes model-facing guidance. It does not ask the agent to rediscover the project from the transcript. It hands the agent a compact orientation packet before the tool loop begins. - -This is also where restraint matters. The renderer is deliberately bounded by hard section limits because a map that floods the prompt becomes another swamp. Epiphany should show the current frontier, the live risks, and the important evidence, not every artifact it has ever seen. - -There is now one deliberately unbounded-in-spirit but tiny-in-text exception: the renderer always includes an operating-discipline section. That is where the Jenga lesson lives at runtime. If a regression or benchmark fix attempt does not move the real signal, the prompt tells the agent to revert it before trying the next hypothesis. This is not extra lore; it is a guardrail in the model-facing state packet. - -### Mechanism - -`Session::build_initial_context` locks session state and copies: - -- reference context -- previous turn settings -- collaboration mode -- base instructions -- session source -- `epiphany_state` - -It then builds the normal developer bundle. After collaboration-mode instructions, it checks `epiphany_state.as_ref()` and pushes `EpiphanyStateInstructions::from_state(...).render()`. - -`EpiphanyStateInstructions` is only a Codex adapter. It calls the `codex_protocol` re-export of the state-model `render_epiphany_state(state)` and wraps the result in the protocol tags. - -`render_epiphany_state` always emits: - -- overview -- operating discipline -- bounded optional sections for subgoals, invariants, graphs, investigation checkpoint, scratch, observations, evidence, churn, and mode - -Code refs: - -- [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2434) -- [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2447) -- [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2509) -- [context/epiphany_state_instructions.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/context/epiphany_state_instructions.rs:7) -- [epiphany-state-model/src/prompt.rs](E:/Projects/EpiphanyAgent/epiphany-state-model/src/prompt.rs:26) -- [epiphany-state-model/src/prompt.rs](E:/Projects/EpiphanyAgent/epiphany-state-model/src/prompt.rs:33) -- [epiphany-state-model/src/prompt.rs](E:/Projects/EpiphanyAgent/epiphany-state-model/src/prompt.rs:43) - -### Output - -The model sees a bounded developer-context fragment: - -```text - -... - +```mermaid +flowchart LR + C["Self / coordinator"] --> L["Typed worker launch request"] + L --> RS["Runtime spine"] + RS --> M["Model runtime"] + M --> F["Typed role or reorient finding"] + F --> MG["Mind review"] + MG --> SC["State commit receipt"] + SC --> S["Native thread state"] ``` -The renderer selects the useful current state instead of dumping raw JSON: - -- objective -- active subgoal -- operating discipline -- invariants -- graph frontier/checkpoint -- investigation checkpoint -- focused graph nodes/edges/links -- scratch summary -- observations -- recent evidence -- churn -- mode - -### Invariant - -Prompt injection is read-only. It does not update canonical state. If the model learns something from the prompt, committing that understanding now requires an explicit proposal/update path, not a side effect of seeing the prompt. - -## Flow 4: Normal Turns Persist Epiphany State - -### Input - -A real user turn enters the normal context-update path. - -### Plain-language role - -Persistence is the checkpoint ritual. After a real turn, Epiphany writes the current model next to the normal turn context so the next wakeup has something sturdier than vibes. - -This is deliberately tied to real user turns. The system is not spraying snapshots after every tiny internal twitch. The notebook gets an entry when the work session actually advances. - -### Mechanism - -`record_context_updates_and_set_reference_context_item`: - -1. decides whether to inject full initial context or just settings diffs. -2. records any model-visible context items. -3. persists one `RolloutItem::TurnContext`. -4. reads current `self.epiphany_state().await`. -5. if present, persists one `RolloutItem::EpiphanyState` with the current turn id. -6. advances the reference context item baseline. - -Code refs: - -- [session/turn.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/turn.rs:168) -- [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2677) -- [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2702) - -### Output - -The rollout contains Epiphany snapshots aligned to real user turns. - -### Invariant - -No state means no `EpiphanyState` rollout item. Current code does not synthesize an empty Epiphany state just because the fork exists. - -## Flow 5: Thread Reads Hydrate Typed Client State - -### Input - -The app-server needs to return a hydrated `Thread` payload through surfaces such as `thread/read`, `thread/resume`, `thread/fork`, or detached review-thread startup. The protocol comment also marks `thread/start` and payload-reusing notifications/responses as places where this field may be populated. - -### Plain-language role - -Thread hydration is the place where Epiphany becomes visible as application data. The GUI or any other client should not have to scrape the prompt to know what the agent thinks the system is. - -The subtle bit is the retrieval summary backfill. If live state exists but has no retrieval metadata, the read view can attach a current freshness summary. That is a window display, not a ledger write. - -### Mechanism - -For `thread/read`, `read_thread_view` loads the persisted thread view and optional live thread. It then calls `apply_thread_read_epiphany_state`. - -`apply_thread_read_epiphany_state` chooses: - -- if the thread is loaded, use `live_thread_epiphany_state`. -- otherwise, read rollout items from disk and reconstruct the latest surviving Epiphany state with `latest_epiphany_state_from_rollout_items`. - -`live_thread_epiphany_state` reads `CodexThread.epiphany_state()`. If state exists but has no retrieval summary, it calls `epiphany-codex-bridge::thread_epiphany_retrieval_state` and backfills the summary into the returned API object. That backfill is for the view; it is not a durable rollout write. - -Code refs: - -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4483) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4599) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:5430) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:5702) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:8047) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10389) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4662) - -### Output - -Clients can read `thread.epiphanyState` as typed data. - -### Invariant - -This is a read surface. The explicit `thread/epiphany/update` writer exists now, but thread hydration itself still does not mutate durable state, emit live `thread/epiphany/stateUpdated`, or append evidence. - -## Flow 6: Retrieval Request Control Flow - -### Input - -A client sends experimental `thread/epiphany/retrieve`. - -### Plain-language role - -Retrieval is Epiphany's first repo-sensing organ. It lets the harness ask "where is the evidence for this idea?" without turning every mapping pass into shell archaeology. - -The hybrid part matters. Exact/path search is the skeleton key for known names. Qdrant semantic search is the memory for concepts. BM25 is the sane fallback when the vector machinery is absent or stale. They are one retrieval machine, not rival cults in tiny robes. - -Protocol shape: - -- `threadId` -- `query` -- optional `limit` -- optional `pathPrefixes` - -Code refs: - -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:364) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4059) - -### Mechanism - -The app-server handler: - -1. parses the thread id. -2. trims and rejects empty queries. -3. rejects zero limits. -4. requires the thread to be loaded. -5. clamps limit to Epiphany bounds. -6. calls `epiphany-codex-bridge::retrieve_thread_epiphany`. -7. maps core results into app-server protocol DTOs. - -`retrieve_thread_epiphany` snapshots the host config, extracts `cwd` as workspace root, gets Codex home from the host seam, and runs `epiphany_core::retrieve_workspace` in `spawn_blocking`. - -`epiphany-core::retrieve_workspace`: - -1. validates workspace root and query. -2. normalizes limit and path prefixes. -3. runs exact/path search through `codex_file_search`. -4. tries persistent semantic search. -5. uses Qdrant only when the manifest matches the current backend config, the workspace snapshot is clean, the collection exists, and Ollama can embed the query. -6. if no manifest exists, the manifest is stale, the collection is missing, or Qdrant/Ollama errors, falls back to query-time BM25 chunks. -7. merges exact and semantic results. -8. sorts with exact files first, semantic chunks second, exact directories third, then score/path/line ordering. -9. truncates to the requested limit. -10. returns query, index summary, and typed results. - -Code refs: - -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4046) -- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:456) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:160) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:404) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:487) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:1290) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:1450) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10412) - -### Output - -The response contains: - -- query -- index summary -- result kind: exact file, exact directory, or semantic chunk -- path -- score -- optional line range -- optional excerpt - -### Invariant - -`thread/epiphany/retrieve` is read-only with respect to durable Epiphany state and persistent semantic indexing. It may build a query-time BM25 corpus in memory and report retrieval freshness, but it does not rebuild Qdrant, does not write the manifest, and does not persist Epiphany state. - -## Flow 7: Explicit Indexing Control Flow - -### Input - -A client sends experimental `thread/epiphany/index`. - -### Plain-language role - -Indexing is catalog maintenance. It is intentionally not hidden inside retrieval because hidden writes make state harder to reason about and harder to trust. - -The explicit path says: if we want persistent semantic memory, we ask for it. Then Epiphany chunks files, embeds them, writes Qdrant points, and records a manifest so later reads can tell whether the catalog still matches the shelves. - -Protocol shape: - -- `threadId` -- `forceFullRebuild` - -Code refs: - -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:340) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:3921) - -### Mechanism - -The app-server handler: - -1. parses the thread id. -2. requires the thread to be loaded. -3. calls `epiphany-codex-bridge::index_thread_epiphany_retrieval`. -4. maps the returned core retrieval state into an app-server index summary response. - -`index_thread_epiphany_retrieval_state` snapshots `cwd`, reads Codex home from the host seam, and runs `epiphany_core::index_workspace` in `spawn_blocking`. - -`epiphany-core::index_workspace`: - -1. validates workspace root. -2. loads env-derived backend config. -3. snapshots indexable workspace files. -4. loads the manifest under `codex_home`. -5. checks Qdrant collection compatibility. -6. computes full rebuild versus incremental reindex. -7. chunks changed files. -8. embeds chunks through local Ollama. -9. creates or updates Qdrant collection/points. -10. deletes removed points when needed. -11. writes updated manifest metadata. -12. returns a ready `EpiphanyRetrievalState` if the write succeeds, or an error if workspace/Qdrant/Ollama/manifest work fails. - -Code refs: - -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4122) -- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:438) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:144) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:257) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:1113) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:1274) - -### Output - -The response returns an index summary. The persistent side effects are: - -- Qdrant collection/points for semantic chunks. -- manifest JSON under `codex_home`. - -### Invariant - -Indexing is the only current persistent semantic write path. Retrieval does not secretly mutate the index. Good. Sneaky writes are how the goblin gets in. - -## Flow 8: Retrieval State Summary Backfill - -### Input - -A live thread has Epiphany state, but `state.retrieval` is `None`. - -### Plain-language role - -Retrieval-summary backfill is a dashboard convenience. It answers "does this workspace currently have a usable semantic index?" when a client reads thread state. - -It must stay light. It should measure the catalog, not rewrite the catalog. If this path starts mutating durable state, it becomes a hidden indexing/update surface wearing a fake mustache. - -### Mechanism - -`live_thread_epiphany_state` calls `epiphany-codex-bridge::thread_epiphany_retrieval_state`. That bridge helper runs `retrieval_state_for_workspace`, which: - -1. checks the workspace exists. -2. loads backend config. -3. tries to load the manifest from `codex_home`. -4. returns a query-time baseline summary if no manifest exists. -5. marks stale if revision or collection differs. -6. compares manifest file metadata to current workspace metadata. -7. returns ready or stale summary with dirty paths. - -Code refs: - -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10389) -- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:420) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:100) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:1229) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:1365) -- [epiphany-core/src/retrieval.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/retrieval.rs:1416) - -### Output - -The API view of `thread.epiphanyState.retrieval` can show current retrieval/index freshness without making the thread-read path write to rollout. - -## Flow 9: Explicit State Update Control Flow - -### Input - -A client sends experimental `thread/epiphany/update` for a loaded thread. - -### Plain-language role - -State update is the red-pen path. It is the first shipped control-plane door for turning explicit observations and state decisions into the durable Epiphany model. - -The important boundary is that this is not automatic transcript osmosis. The caller must submit a typed patch. Epiphany accepts only named state pieces: objective, active subgoal, subgoals, invariants, graphs, graph frontier/checkpoint, scratch, observations, evidence, churn, and mode. Retrieval still does not get to scribble in the notebook while pretending to fetch books. - -Protocol shape: - -- `threadId` -- optional `expectedRevision` -- `patch` - - optional replacement fields for objective, subgoals, invariants, graph state, scratch, churn, and mode - - append-only `observations` - - append-only `evidence` - -Wire-shape caveat: the app-server envelope is camelCase, but the nested reused Epiphany core DTOs keep their core snake_case field names. That is why an observation uses `source_kind` and churn uses `understanding_status` / `diff_pressure` inside the patch. - -Code refs: - -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:359) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4001) - -### Mechanism - -The app-server handler: - -1. parses the thread id. -2. requires the thread to be loaded. -3. maps the app-server patch DTO into `EpiphanyStateUpdate`. -4. calls `epiphany-codex-bridge::apply_epiphany_state_update_to_thread`. -5. computes `changedFields` from the accepted patch surface. -6. projects the just-written state through `client_visible_live_thread_epiphany_state`, which reuses the `thread/read` live-state helper and backfills retrieval summary metadata when needed. -7. returns the client-visible `EpiphanyThreadState` plus response-level `revision` and `changedFields`. -8. emits `thread/epiphany/stateUpdated` with `source: "update"`, event-level `revision`, typed `changedFields`, and the same client-visible updated state. -9. reports empty patches and revision mismatches as invalid requests before notification. - -`apply_epiphany_state_update_to_thread`: - -1. rejects an empty patch. -2. reads the current reference turn id when one exists. -3. starts from the live `SessionState.epiphany_state` or a default empty state. -4. enforces `expectedRevision` when supplied. -5. validates appended evidence records have nonempty id/kind/status/summary, do not duplicate ids in the patch, and do not reuse existing durable evidence ids. -6. validates appended observations have nonempty id/summary/source kind/status, do not duplicate ids in the patch, do not reuse existing durable observation ids, and cite at least one evidence id that already exists or is appended in the same patch. -7. validates state replacement shapes through the shared `epiphany-core` structural validator used by promotion: active subgoal ids must resolve against the patch or current subgoals, graph/frontier/checkpoint references must resolve against the patch or current graphs, and churn replacement fields must carry required structural fields. -8. rejects invalid append or replacement patches before `SessionState`, rollout, response metadata, or notification side effects. -9. applies typed replacements, prepends new observations/evidence, increments `revision`, and records `last_updated_turn_id`. -10. writes the new state back into live `SessionState`. -11. immediately persists `RolloutItem::EpiphanyState`. -12. flushes the rollout durability barrier. - -The replay helpers now also accept an out-of-band Epiphany snapshot before the first real user turn, so a seed/update written through this path is not lost just because no model turn has happened yet. - -Code refs: - -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4439) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4502) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4512) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10430) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10440) -- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:100) -- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:374) -- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:552) -- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:645) -- [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:34) -- [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:44) -- [session/rollout_reconstruction.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/rollout_reconstruction.rs:45) -- [epiphany-core/src/rollout.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/rollout.rs:18) - -### Output - -The response contains the updated client-visible `epiphanyState`, response-level `revision`, and response-level `changedFields`. The durable side effect is a rollout `EpiphanyState` snapshot. The live side effect is a `thread/epiphany/stateUpdated` notification carrying `source: "update"`, event-level `revision`, typed `changedFields`, and the same client-visible updated state to app-server clients. That state uses the same retrieval-summary backfill as `thread/read`, but the backfill remains a view projection rather than a durable mutation. Invalid append or replacement patches return an invalid-request error, leave revision unchanged, and emit no state update notification. - -### Invariant - -This is an explicit write surface, not a hidden side effect. It does not run retrieval, indexing, watcher invalidation, automatic graph inference, or specialist-agent scheduling. The notification is a reflection of a completed write, not a second writer. It is just the clerk with the red pen, finally given a form. - -## Flow 10: Observation Distillation Proposal Control Flow - -### Input - -A client sends experimental `thread/epiphany/distill` for a loaded thread with: - -- `threadId` -- `sourceKind` -- `status` -- `text` -- optional `subject` -- optional `evidenceKind` -- optional `codeRefs` - -### Plain-language role - -Distillation is the pencil-draft path. It turns one explicit thing the client claims to have observed into the same observation/evidence records that `thread/epiphany/update` can persist, but it deliberately stops short of writing them. - -That restraint is the point. This surface is not "the transcript became truth." It is "here is a shaped candidate; now choose whether to promote it." The current implementation is deterministic and boring on purpose: normalize whitespace, attach code refs, choose a stable id, and return a patch. No hidden model call, no watcher magic, no tiny bureaucracy pretending it is wisdom. - -For source kinds that smell like real output from a tool, command, shell, model, or assistant, the distiller now keeps the same read-only patch boundary but makes the summary less like a bucket of stdout. It extracts a few salient lines such as exit code, test result, finished, passed, failed, error, or warning; result/failure/error/finished lines outrank generic warnings, while warning-only output still preserves the warning as the central signal. It also defaults the evidence kind to `tool-output` or `model-output` when the caller did not provide one. That gives later proposal/promotion logic typed signal without making the raw transcript canonical. - -Protocol shape: - -- `threadId` -- `sourceKind` -- `status` -- `text` -- optional `subject` -- optional `evidenceKind` -- optional `codeRefs` - -Response shape: - -- `expectedRevision` -- `patch` - - `observations` - - `evidence` - -Wire-shape caveat is the same as update: the app-server envelope is camelCase, but nested reused Epiphany core DTOs keep their core snake_case fields. - -Code refs: - -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:345) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:3937) -- [epiphany-core/src/distillation.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/distillation.rs:28) - -### Mechanism - -The app-server handler: - -1. parses the thread id. -2. requires the thread to be loaded. -3. reads the current Epiphany revision, defaulting to `0` if the thread has not yet created state. -4. calls `distill_observation`. -5. returns a `ThreadEpiphanyUpdatePatch` containing one observation and one evidence record. - -`distill_observation`: - -1. normalizes required `sourceKind`, `status`, and `text`. -2. rejects empty required fields. -3. normalizes optional `subject` and `evidenceKind`. -4. builds a bounded summary from `subject: text` or just `text`; for tool/command/shell/model/assistant sources it preserves raw line structure long enough to select salient output lines before truncation. -5. fingerprints normalized source/status/subject/text into stable observation/evidence ids. -6. defaults evidence kind to `verification` for test/smoke/verification sources, `tool-output` for tool/command/shell sources, `model-output` for model/assistant sources, and otherwise `observation`. -7. copies code refs into both records so the proposal carries its anchors. - -Code refs: - -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4173) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4202) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4225) -- [epiphany-core/src/distillation.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/distillation.rs:28) - -### Output - -The response is a promotion-ready patch. It is not durable until a caller submits it to `thread/epiphany/update`. - -### Invariant - -Distillation is read-only. It does not mutate `SessionState`, does not persist rollout items, does not run retrieval, and does not infer graph/churn changes. It sharpens one proposed observation into a typed shape; promotion remains a separate red-pen act. - -## Flow 11: Map/Churn Proposal Control Flow - -### Input - -A client sends experimental `thread/epiphany/propose` for a loaded thread with: - -- `threadId` -- optional `observationIds` - -### Plain-language role - -Proposal is the tracing-paper path. It starts from observations that are already in the thread's typed state, chooses a small proposal-ready set when `observationIds` is omitted, requires selected observations to have verified/accepted status, requires each selected observation to cite accepting `recent_evidence`, requires source-grounding through code refs, and returns a candidate patch that can replace graph/frontier/churn fields only if a later promotion accepts it. - -This is the first shipped chewing motion. It is deliberately small: no model call, no watcher invalidation, no automatic graph truth. When ids are omitted, proposal now ranks proposal-ready observations by source/evidence strength, code refs, and current map focus, then keeps a bounded coherent path cluster instead of grabbing every shiny pebble in the yard. It then checks that selected observations are backed by current accepting evidence, scores the selected observations so the strongest verifier/test/smoke-backed signal becomes the proposal's primary summary, and tries to match observed code refs against existing architecture nodes. Concrete matching still wins: exact code refs, same-path refs, and deterministic path-node ids are tried before anything semantic. Only after those fail can strict semantic overlap reuse an existing architecture node, and only when that graph node has no code refs yet; anchored nodes stay governed by concrete refs because otherwise the map starts doing interpretive dance in a trench coat. Proposal then enriches matching nodes with newly observed refs, creates path-derived candidate nodes only for genuinely unmapped surfaces, expands frontier focus through graph links, marks named incident edges active, emits a proposal observation/evidence pair, and judges the map delta by match kind: exact-ref reuse is a narrow refinement, same-path reuse is broadening, deterministic-id reuse preserves a known candidate, semantic reuse anchors previously unanchored prose, and new nodes expand the map. Diff pressure now reflects that judgment, touched paths, observation count, and unresolved write risk instead of blindly inheriting the previous pressure. It is a candidate, not an oracle. We do not crown the goblin because it found a wrench. - -Protocol shape: - -- `threadId` -- optional `observationIds`; empty or omitted means deterministic auto-selection from existing proposal-ready observations - -Response shape: - -- `expectedRevision` -- `patch` - - `observations` - - `evidence` - - `graphs` - - `graphFrontier` - - `churn` - -Code refs: - -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:350) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:3963) -- [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:115) - -### Mechanism - -The app-server handler: - -1. parses the thread id. -2. requires the thread to be loaded. -3. requires existing Epiphany state. -4. reads the current state revision as `expectedRevision`. -5. calls `propose_map_update`. -6. returns a `ThreadEpiphanyUpdatePatch` containing proposal observation/evidence, replacement graphs/frontier, and churn. - -`propose_map_update`: - -1. normalizes and deduplicates requested observation ids. -2. when no ids are supplied, ranks proposal-ready observations and selects up to four observations from the strongest coherent path cluster. -3. the automatic ranker ignores observations without accepting status, code refs, or accepting `recent_evidence`; it scores source kind, evidence kind, code refs, summary presence, frontier dirty paths, active-node paths, and already mapped paths. -4. rejects unknown explicitly requested observations. -5. rejects selected observations whose status is not accepting: `ok`, `accepted`, `verified`, `pass`, or `passed`. -6. rejects selected observations that do not cite existing accepting `recent_evidence`. -7. rejects proposals without code refs. -8. scores selected observations and evidence by source kind, evidence kind, code refs, and summary presence so proposal wording is anchored to the strongest selected signal instead of raw id order. -9. builds semantic terms from selected observations, accepting evidence, code-ref paths, symbols, and notes. -10. clones the current graphs and searches architecture nodes for exact code-ref overlap, same-path overlap, then the deterministic path-node id. -11. if no concrete match exists, searches unanchored architecture nodes for a unique strong semantic match and refuses tied semantic matches. -12. enriches matching architecture nodes with newly observed refs, preserving their existing title/purpose/status. -13. creates path-derived candidate architecture nodes only when no existing node matches that code path or unanchored graph language. -14. expands focused node ids through graph links so architecture nodes pull their linked dataflow nodes into the frontier, and vice versa. -15. marks named graph edges incident to focused nodes as active. -16. merges focused node ids, active edge ids, and observed paths into the graph frontier. -17. emits a proposal observation/evidence pair tied to the candidate patch, including evidence-backed selection counts, priority label, primary observation id, and reused/created node counts. -18. emits churn with `proposal_refines_map`, `proposal_expands_map`, or `proposal_updates_map` depending on whether the candidate reused existing nodes, created new nodes, or did both. -19. emits graph freshness from the match-kind-aware delta: exact-ref/deterministic reuse is refinement, same-path reuse is broadening, semantic unanchored reuse is semantic anchoring, new nodes are expansion, and mixed reuse/create deltas are updates. -20. emits `diff_pressure` from the proposal shape and match kind: low for exact narrow refinements, medium for same-path broadening, semantic anchoring, single-surface expansion, or multi-observation/path pressure, and high for mixed/multi-create/multi-path changes or existing unexplained writes. - -Code refs: - -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4244) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4287) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4301) -- [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:115) -- [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:244) -- [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:271) -- [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:351) -- [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:417) -- [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:1008) -- [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:1037) - -### Output - -The response is a promotion-ready map/churn patch. Existing mapped surfaces now keep their node identity and accumulate observed refs instead of being duplicated as new path nodes, the frontier points at the linked context the prompt renderer already knows how to display, and churn pressure describes how risky the candidate map change is. The live smoke proved `thread/epiphany/propose` does not mutate state by itself; `thread/read` stayed at revision `1` with no persisted churn after proposal, then `thread/epiphany/promote` advanced revision to `2` and persisted the graph/churn patch only after verifier evidence accepted it. - -### Invariant - -Proposal is read-only. It does not mutate `SessionState`, does not persist rollout items, does not run retrieval, does not ask a model to infer a graph, and does not bypass promotion. It prepares a better bite; promotion still decides whether to swallow. - -## Flow 12: Promotion Gate Control Flow - -### Input - -A client sends experimental `thread/epiphany/promote` for a loaded thread with: - -- `threadId` -- optional `expectedRevision` -- `patch` -- `verifierEvidence` - -### Plain-language role - -Promotion is the stamp between pencil and ink. It is not another writer and it is not automatic wisdom. It looks at a proposed patch plus verifier evidence, decides whether the proposal has enough structure to deserve promotion, and either rejects with reasons or forwards the accepted patch into the existing durable update path. - -The important thing is the failure behavior. A bad verifier status returns `accepted: false` and leaves `SessionState` untouched. That makes rejection a first-class outcome instead of a half-committed shrug. Tiny bureaucracy, actually useful for once. - -Protocol shape: - -- `threadId` -- optional `expectedRevision` -- `patch` -- `verifierEvidence` - -Response shape: - -- `accepted` -- `reasons` -- optional `epiphanyState` - -Code refs: - -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:354) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:3980) -- [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33) - -### Mechanism - -The app-server handler: - -1. parses the thread id. -2. requires the thread to be loaded. -3. sends the patch shape plus verifier evidence to `evaluate_promotion`. -4. returns `accepted: false`, reasons, and `epiphanyState: null` when policy rejects. -5. appends verifier evidence to the patch evidence when policy accepts. -6. maps the patch into `EpiphanyStateUpdate`. -7. calls `epiphany-codex-bridge::apply_epiphany_state_update_to_thread`. -8. projects the just-written state through `client_visible_live_thread_epiphany_state`, matching the `thread/read` live-state view and retrieval-summary backfill. -9. returns the client-visible `EpiphanyThreadState` plus response-level `revision` and `changedFields`. -10. emits `thread/epiphany/stateUpdated` with `source: "promote"`, event-level `revision`, and typed `changedFields` only for the accepted path; `Evidence` is included even if the accepted patch had no patch evidence because verifier evidence was appended to the durable state. - -`evaluate_promotion` currently enforces a deliberately small but now delta-aware policy: - -1. the patch must contain at least one mutation. -2. verifier evidence must have nonempty id/kind/status/summary. -3. verifier status must be accepting: `ok`, `accepted`, `verified`, `pass`, or `passed`. -4. patch evidence records must be nonempty and unique by id. -5. observations must be nonempty, unique by id, and cite existing evidence ids. -6. state replacement patches, including map/frontier/checkpoint/churn edits, must include at least one explicit observation and at least one patch evidence record. -7. subgoal, invariant, graph, frontier, checkpoint, and churn replacements get lightweight structural validation before they can reach the durable update path. -8. risky churn deltas require an explicit `patch.churn.warning`; risky means medium-or-higher `diff_pressure`, or graph freshness that signals expansion, broadening, semantic anchoring, or an update. Promotion therefore does not let a new map surface sneak through merely by labeling its pressure `low`. -9. risky churn deltas require stronger verifier evidence kind: verification, verifier, test, smoke, or review. Kind matching is token-aware, so `smoke-test` and `code-review` can qualify but substring accidents like `contest` do not. Generic observation evidence is not enough to stamp a high-pressure map change. - -Code refs: - -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4316) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4349) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4363) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4399) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4415) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4427) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10430) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10440) -- [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33) -- [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:126) -- [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:157) -- [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:467) - -### Output - -Rejected promotions return reasons and no state. Accepted promotions return the updated client-visible `epiphanyState`, response-level `revision`, and response-level `changedFields` from the durable update path, then emit `thread/epiphany/stateUpdated` with `source: "promote"`, event-level `revision`, typed `changedFields`, plus that same projected state. Because accepted promotion always appends verifier evidence, promotion responses and notifications report `Evidence` even when the submitted patch evidence array was empty. Because accepted promotion now uses the `thread/read` live-state projection, clients also see retrieval-summary backfill consistently without promotion becoming a retrieval writer. - -### Invariant - -Promotion is a gate, not independent persistence. It does not write rollout items directly, it does not mutate state on rejection, and rejected promotions emit no state update notification. Accepted promotions still go through `epiphany-codex-bridge::apply_epiphany_state_update_to_thread`, so the red pen remains one tool, not three tools in a coat. - -## Flow 13: Scene View Lens Control Flow - -### Input - -A client sends experimental `thread/epiphany/view` with: - -- `threadId` -- `lenses: ["scene"]` - -### Plain-language role - -Scene projection is the first Phase 6 reflection boundary. It is not another state object and not a GUI brain. It is the little wall board a client can read when the full ledger is too raw: state present or missing, live or stored source, revision, objective, active subgoal, invariant status counts, graph focus/counts, retrieval status, latest observations/evidence, churn, and which Epiphany control doors are available. - -The important boundary is that it derives from the same Epiphany state view as `thread/read`. It never writes `SessionState`, never appends rollout items, never runs proposal or promotion, and never makes client-side layout the canonical model. The client gets a scene; the ledger remains the ledger. - -Protocol shape: - -- `threadId` -- `lenses` - -Response shape: - -- `threadId` -- `scene` - - `stateStatus` - - `source` - - optional `revision` - - optional `objective` - - optional `activeSubgoal` - - `subgoals` - - `invariantStatusCounts` - - `graph` - - optional `retrieval` - - `observations` - - `evidence` - - optional `churn` - - `availableActions` - -Code refs: - -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:339) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:3921) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4067) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10500) - -### Mechanism - -The view handler: - -1. parses the thread id. -2. selects the `scene` lens. -3. checks whether the thread is currently loaded so the scene can report live/stored source and available actions. -4. calls the existing `read_thread_view(..., include_turns: false)` path, which already applies live Epiphany state or stored rollout reconstruction. -5. passes the optional `thread.epiphany_state` into `map_epiphany_scene`. -6. returns a compact derived scene under the view response. - -`map_epiphany_scene`: - -1. returns a missing-state scene when no Epiphany state exists. -2. marks source as `live` when the thread is loaded, otherwise `stored`. -3. copies revision/objective/active subgoal without changing them. -4. summarizes invariant status counts with deterministic status ordering. -5. summarizes architecture/dataflow graph counts, active frontier ids, dirty paths, open question/gap counts, and checkpoint identity. -6. summarizes retrieval status, semantic availability, index revision, shard count, dirty-path count, and indexed file/chunk counts. -7. includes a compact investigation-checkpoint summary when one exists, including disposition plus open-question/code-ref/evidence counts. -8. includes bounded latest observation/evidence summaries in newest-first order, matching the durable state's recent-record ordering. -9. reflects churn pressure/warning fields. -10. reports available actions only when the thread is loaded, including the read-only `context` and `jobs` doors and adding `propose`/`promote` only when state exists. - -### Output - -The response is a client-shaped reflection of the current Epiphany machine. It lets a GUI or other client render the state without scraping prompt text, diffing the full `EpiphanyThreadState`, or making up its own model of which doors exist. - -### Invariant - -Scene projection is read-only. It is allowed to compress and label the authoritative state for humans and clients, but it must not become the place where understanding is manufactured. A dashboard is allowed to exist. It is not allowed to grab the steering wheel and call itself destiny. - -## Flow 14: Job/Progress View Lens Control Flow - -### Input - -A client sends experimental `thread/epiphany/view` with: - -- `threadId` -- `lenses: ["jobs"]` - -### Plain-language role - -Job projection is the second Phase 6 reflection boundary. It gives clients a typed answer to "what Epiphany work is visible from here?" without creating a background scheduler, GUI-owned progress model, or a second durable runtime job table. - -The surface currently reports four base slots: - -- retrieval indexing -- graph remap -- invariant/evidence verification -- specialist work - -The important boundary is that these are reflections over existing state. Retrieval status comes from the same retrieval summary machinery used by scene/thread reads. Remap pressure comes from graph frontier dirty paths, open questions/gaps, and churn freshness. Verification pressure comes from invariant status counts. Durable `jobBindings` in authoritative Epiphany state now act as thin authority slots: they carry binding id, kind, owner, scope, authority scope, linked ids, and an optional blocking reason. Runtime job identity comes from `runtimeLinks` and runtime-spine records. Stale `agent_jobs` bindings are sealed instead of resolved through SQLite. If the runtime seam is missing or sealed, the slot blocks honestly instead of improvising a secret scheduler. - -Protocol shape: - -- `threadId` -- `lenses` - -Response shape: - -- `threadId` -- optional `stateRevision` -- `jobs` - - `id` - - `kind` -- `scope` -- `ownerRole` -- optional `launcherJobId` -- optional `authorityScope` -- optional `backendJobId` -- `status` -- optional `itemsProcessed` - - optional `itemsTotal` - - optional `progressNote` - - optional `lastCheckpointAtUnixSeconds` - - optional `blockingReason` - - optional `runtimeAgentJobId` - - `activeThreadIds` - - `linkedSubgoalIds` - - `linkedGraphNodeIds` - -Code refs: - -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:347) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4142) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4176) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11998) - -### Mechanism - -The view handler: - -1. parses the thread id. -2. selects the `jobs` lens. -3. calls `read_thread_view(..., include_turns: false)` to reuse the live/stored Epiphany projection path. -4. if the thread is loaded and no Epiphany retrieval summary is present, asks the loaded thread for retrieval state so the index slot can still be honest before typed Epiphany state exists. -5. passes the optional state and optional retrieval override into `map_epiphany_jobs`. - -`map_epiphany_jobs`: - -1. returns only the base `retrieval-index`, `graph-remap`, and `verification` slots from retrieval state, frontier/churn state, and invariant counts; specialist rows appear only from explicit durable bindings/runtime links. -2. copies active subgoal and graph-node ids into relevant slots so clients can link progress pressure back to the visible model. -3. if authoritative typed state carries `jobBindings`, matches those bindings onto the base slots by id/kind or appends a bound specialist row, reflecting authority scope and runtime job id from `runtimeLinks`. -4. when a binding has no runtime link or runtime job id, leaves it idle or blocked from binding state instead of inventing lifecycle. - -### Output - -The response is a typed progress board under the view response, derived from the current Epiphany machine. The jobs projection reflects retrieval while graph/remap and verification stay blocked when state is missing, ready-state jobs expose launcher metadata, runtime-linked specialist bindings project as pending runtime turns, no placeholder specialist row is fabricated, no `thread/epiphany/stateUpdated` or `thread/epiphany/jobsUpdated` notification is emitted by the read, and final thread state revision does not change. - -### Invariant - -Job projection is read-only. It does not start indexing, create runtime jobs, remap graphs, verify invariants, schedule specialists, mutate `SessionState`, append rollout items, or emit progress notifications. It is a board on the wall, not a payroll department with a fake mustache. - -## Flow 15: Targeted Context Shard Control Flow - -### Input - -A client sends experimental `thread/epiphany/context` with: - -- `threadId` -- optional `graphNodeIds` -- optional `graphEdgeIds` -- optional `observationIds` -- optional `evidenceIds` -- optional `includeActiveFrontier` -- optional `includeLinkedEvidence` - -### Plain-language role - -Context projection is the third Phase 6 reflection boundary. It gives clients a bounded way to ask "show me the exact Epiphany state slice around this graph/evidence target" without hauling the full `EpiphanyThreadState`, running retrieval, drafting proposals, or letting the GUI manufacture canonical understanding. - -The useful distinction from scene and jobs is resolution. Scene is the wall board. Jobs is the shift board. Context is the opened binder page: selected graph nodes and edges, links, active frontier, checkpoint, observations, evidence, and any requested ids that were not found. - -Protocol shape: - -- `threadId` -- `graphNodeIds` -- `graphEdgeIds` -- `observationIds` -- `evidenceIds` -- optional `includeActiveFrontier`, defaulting true in the mapper -- optional `includeLinkedEvidence`, defaulting true in the mapper - -Response shape: - -- `threadId` -- `source` -- `stateStatus` -- optional `stateRevision` -- `context` - - `graph` - - `architectureNodes` - - `architectureEdges` - - `dataflowNodes` - - `dataflowEdges` - - `links` - - optional `frontier` - - optional `checkpoint` - - optional `investigationCheckpoint` - - `observations` - - `evidence` -- `missing` - - `graphNodeIds` - - `graphEdgeIds` - - `observationIds` - - `evidenceIds` - -Code refs: - -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:350) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4182) -- [epiphany-core/src/surfaces/graph_context.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/graph_context.rs:104) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4186) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10791) - -### Mechanism - -The app-server handler: - -1. parses the thread id. -2. checks whether the thread is loaded so the response can report live/stored source. -3. calls `read_thread_view(..., include_turns: false)` to reuse the live/stored Epiphany projection path. -4. maps protocol selectors into `epiphany-core::EpiphanyContextParams`. -5. calls `epiphany-core::derive_context`. -6. maps the core context view back into the protocol response. -7. returns the derived context shard and missing-id lists. - -`epiphany-core::derive_context`: - -1. returns missing state with an empty context and echoes requested ids when no Epiphany state exists. -2. defaults `includeActiveFrontier` to true, so a client can ask for the current working slice with only a thread id. -3. defaults `includeLinkedEvidence` to true, so selected observations bring their evidence anchors. -4. de-duplicates requested ids while preserving request/frontier order. -5. selects architecture and dataflow nodes by id. -6. selects graph edges by explicit edge id and incident edges touching selected nodes. -7. includes graph links touching selected architecture or dataflow nodes. -8. includes active frontier, graph checkpoint, and the full durable investigation checkpoint when available. -9. selects observations by id. -10. selects directly requested evidence plus evidence ids linked from selected observations. -11. reports any requested or active-frontier graph ids, observation ids, or evidence ids not found in the authoritative typed state. - -### Output - -The response is a bounded state shard for a client or model-facing coordinator that already knows which part of the Epiphany model it wants to inspect. The Phase 6 context smoke proved missing-state context reports live source without inventing a revision or graph records, ready context preserves revision identity, returns the active graph node/edge and linked/direct evidence, emits no `thread/epiphany/stateUpdated` notification, and leaves final thread state revision unchanged. - -### Invariant - -Context projection is read-only. It does not run retrieval, draft proposals, promote observations, mutate `SessionState`, append rollout items, or emit notifications. It opens the binder to the requested page; it does not pick up the pen. - -## Flow 15b: Graph Query Traversal Control Flow - -### Input - -A client sends experimental `thread/epiphany/graphQuery` with: - -- `threadId` -- `query.kind`: `node`, `path`, `frontierNeighborhood`, or `neighbors` -- optional explicit `nodeIds` and `edgeIds` -- optional `paths`, `symbols`, and `edgeKinds` -- optional `direction`, defaulting to `both` -- optional `depth`, defaulting to `1` and capped at `3` -- optional `includeLinks`, defaulting true - -### Plain-language role - -Graph query projection is the traversal lens. Context opens a requested binder page; graphQuery walks the local strings tied to that page. Implementation and verifier agents can ask for the current frontier neighborhood, a path/symbol neighborhood, or a bounded neighbor walk without pulling the whole state or asking retrieval to rediscover what the typed graph already knows. - -Response shape: - -- `threadId` -- `source` -- `stateStatus` -- optional `stateRevision` -- `graph` - - `architectureNodes` - - `architectureEdges` - - `dataflowNodes` - - `dataflowEdges` - - `links` -- optional `frontier` -- optional `checkpoint` -- `matched` - - `nodeIds` - - `edgeIds` - - `paths` - - `symbols` - - `edgeKinds` -- `missing` - - `nodeIds` - - `edgeIds` - -### Mechanism - -The app-server handler: - -1. parses the thread id. -2. requires a loaded thread. -3. calls `read_thread_view(..., include_turns: false)` to reuse the live Epiphany projection path. -4. maps the protocol query into `epiphany-core::EpiphanyGraphQuery`. -5. calls `epiphany-core::derive_graph_query`. -6. maps the core graph query view back into the protocol response. -7. returns the selected graph records, current frontier/checkpoint, matched selectors, and missing explicit ids. - -`epiphany-core::derive_graph_query`: - -1. returns missing state with an empty graph and echoes requested node/edge ids when no Epiphany state exists. -2. starts from explicit node/edge ids. -3. for `path`, matches node, edge, and link code refs by requested path and optional symbol. -4. for `frontierNeighborhood`, starts from active frontier node/edge ids and expands neighbors. -5. for `neighbors`, expands neighbors from explicit node ids. -6. adds edge-kind matches when requested. -7. follows architecture/dataflow links by default. -8. returns selected graph nodes, selected and incident graph edges, graph links, frontier, checkpoint, matched selectors, and unresolved explicit ids. - -### Output - -The response is a bounded traversal result for agents that need to move around the typed graph. The Phase 6 graph query smoke proved missing-state graphQuery reports live source without inventing graph records, frontier traversal returns one-hop architecture neighbors plus linked dataflow state, path/symbol lookup reports the matched code ref, no `thread/epiphany/stateUpdated` notification is emitted, and final thread state revision does not change. - -### Invariant - -Graph query projection is read-only. It does not run retrieval, draft proposals, index code, promote observations, mutate `SessionState`, append rollout items, schedule work, or emit notifications. It is a map traversal, not a cartographer with a pen. - -## Flow 16: Context Pressure View Lens Control Flow - -### Input - -A client sends experimental `thread/epiphany/view` with: - -- `threadId` -- `lenses: ["pressure"]` - -### Plain-language role - -Pressure projection is now a view lens. It answers "how close is this thread to context pressure?" from runtime telemetry that already drives compaction, not from transcript vibes or user panic. - -The useful distinction from automatic CRRC is that this surface only reflects. It reports pressure level, measurement basis, used tokens, remaining budget, ratio, and whether preparation is advisable. It does not compact, schedule, persist state, notify `stateUpdated`, or checkpoint in-flight planning. - -Protocol shape: - -- `threadId` -- `lenses` - -Response shape: - -- `threadId` -- `source` -- `pressure` - - `status` - - `level` - - `basis` - - optional `usedTokens` - - optional `modelContextWindow` - - optional `modelAutoCompactTokenLimit` - - optional `remainingTokens` - - optional `ratioPerMille` - - `shouldPrepareCompaction` - - `note` - -Code refs: - -- [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:2237) -- [turn_context.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/turn_context.rs:103) -- [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2716) -- [app-server-protocol/common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:355) -- [app-server-protocol/v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4284) -- [token_usage_replay.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor/token_usage_replay.rs:75) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4244) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10811) - -### Mechanism - -Core telemetry: - -1. `TokenUsageInfo` stores total usage, last usage, `model_context_window`, and optional `model_auto_compact_token_limit`. -2. `TurnContext` exposes the same auto-compact limit that the compaction path uses. -3. token usage updates, recomputation, and full-window marking carry the threshold into session history and `TokenCount` events. - -The view handler: - -1. parses the thread id. -2. selects the `pressure` lens. -3. checks whether the thread is loaded. -4. reads live `CodexThread::token_usage_info()` for loaded threads. -5. falls back to the latest stored rollout `TokenCount` for unloaded threads. -6. maps missing telemetry to honest `unknown`. -7. maps known telemetry against `model_auto_compact_token_limit` when present, otherwise falls back to `model_context_window`. -8. derives `low`, `elevated`, `high`, or `critical` from used tokens over the selected limit. -9. sets `shouldPrepareCompaction` only as advice when the selected ratio reaches high pressure. - -### Output - -The response is a read-only gauge under the view response. The Phase 6 pressure smoke proves the `thread/epiphany/view` pressure lens reports `unknown` for a fresh live thread, recommends no compaction prep, emits no `thread/epiphany/stateUpdated`, and does not create Epiphany state. Focused mapper tests cover auto-compact threshold preference and context-window fallback. - -### Invariant - -Pressure projection is read-only. It does not start compaction, perform CRRC, checkpoint source gathering, mutate `SessionState`, append rollout items, or emit state notifications. It is a pressure gauge, not an emergency crew with a clipboard addiction. - -## Flow 16A: Pre-Compaction Checkpoint Intervention - -### Input - -The core session emits `EventMsg::TokenCount` while a turn is active. - -### Plain-language role - -This is the first CRRC mid-work intervention. It catches the moment pressure has -crossed the existing compaction-prep line but before the turn has ended, and it -tells the active agent to bank what it has learned instead of letting compaction -turn fresh working context into decorative smoke. - -### Mechanism - -The app-server event handler: - -1. clones the `TokenUsageInfo` from the `TokenCount` event before forwarding the normal token-usage notification. -2. maps it through the same pressure helper used by the `pressure` view lens. -3. ignores unknown/low/elevated pressure and acts only when `shouldPrepareCompaction` is true. -4. requires a loaded thread with existing Epiphany state. -5. records one intervention per active turn id in listener `ThreadState`. -6. uses existing turn steering with the expected active turn id to inject a bounded CRRC directive. - -The directive tells the agent to stop broad implementation, persist the active -working context into checkpoint/scratch/map/evidence as appropriate, say when the -checkpoint is banked, and stop for CRRC compaction/reorientation. - -### Invariant - -This intervention does not mutate Epiphany state itself, accept semantic -findings, promote evidence, launch arbitrary specialists, or continue -implementation. It is a shove toward persistence, not a new little emperor with -a queue. - -## Flow 17: Reorientation View Lens Control Flow - -### Input - -A client sends experimental `thread/epiphany/view` with: - -- `threadId` -- `lenses: ["reorient"]` - -### Plain-language role - -Reorientation policy is now a view lens. It answers one narrow question after wakeup or during a continuity check: does the current durable checkpoint still deserve `resume`, or has enough relevant drift accumulated that the honest answer is `regather`? - -The useful distinction from automatic CRRC is that this surface only returns a verdict. It consumes the landed checkpoint, freshness, watcher, and pressure signals, but it does not compact, schedule, mutate, notify, or continue work by itself. - -### Mechanism - -The view handler: - -1. parses the thread id. -2. selects the `reorient` lens. -3. reads the same live/stored thread view used by the other reflection surfaces. -4. reuses live retrieval summary and watcher snapshots for loaded threads when available. -5. reuses live token telemetry or the latest stored rollout `TokenCount`. -6. maps freshness and pressure through the existing reflection helpers. -7. evaluates one bounded verdict: - - `regather` when state is missing, the checkpoint is missing, the checkpoint explicitly requests re-gather, checkpoint code-ref paths are dirty or newly changed, active frontier watcher hits show live drift, or an unanchored checkpoint sits on top of stale signals. - - `resume` when a `resume_ready` checkpoint remains aligned with the current signals. -8. returns typed reasons, relevant changed/dirty checkpoint paths, active frontier hits, next action text, and a human-readable note. - -### Output - -The response is a read-only wakeup verdict under the view response. The Phase 6 reorient smoke proves the `thread/epiphany/view` reorient lens regathers when there is no ember, resumes for a clean checkpoint, flips watcher-touched checkpoint paths back to regather, emits no `thread/epiphany/stateUpdated`, and leaves final thread state revision unchanged. - -### Invariant - -Reorientation policy is read-only. It does not compact, mutate `SessionState`, append rollout items, emit `thread/epiphany/stateUpdated`, schedule CRRC, or silently continue work. It is the verdict slip, not the bailiff. - -## Current Non-Flows - -These are deliberately not shipped yet: - -- no broad live Epiphany event stream beyond `thread/epiphany/stateUpdated` for successful update/promote writes. -- no automatic evidence promotion from tool output; the current distill/propose/promote path still requires explicit verifier-backed calls. -- no broad automatic Compact-Rehydrate-Reorient-Continue coordinator; current code preserves and rehydrates valid Epiphany snapshots across resume/rollback/compaction, exposes context pressure, carries a durable investigation checkpoint packet, can steer active loaded turns once at the compaction-prep threshold to bank working context, returns a read-only reorientation verdict, can explicitly launch one bounded reorientation worker, read that worker's result back through a reviewable surface, explicitly accept completed findings into typed state, and can auto-run only the narrow coordinator-approved compact/reorient-worker launch actions at turn completion. Semantic launch/acceptance policy and next-step execution remain explicit rather than ambient scheduler behavior. -- no automatic watcher-driven graph or semantic invalidation. -- no code-intelligence graph. -- no broad specialist-agent scheduler or marketplace; only fixed manual Imagination/planning, modeling/checkpoint, and verification/review role templates exist. -- no always-on Epiphany-owned long-running heartbeat daemon yet; activation is queued through heartbeat/runtime-spine seams. -- no GUI source of truth; the current Tauri/React shell reflects and steers existing app-server surfaces. -- no durable retrieval-summary write from `thread/epiphany/retrieve`. - -The current system is therefore not "the model maintains a map automatically." More precisely: - -```text -stored Epiphany state --> rendered into model context --> persisted across turns and resume --> visible to clients --> reflected as a compact read-only scene for clients --> reflected as read-only job/progress slots for clients --> reflected as a read-only freshness lens for clients --> reflected as targeted read-only graph/evidence context shards for clients --> reflected as bounded read-only graph traversal for clients and agents --> reflected as read-only context pressure from token telemetry --> reflected as a read-only resume/regather verdict from checkpoint + freshness + watcher + pressure --> reflected as a read-only CRRC recommendation over verdict + worker/result state --> reflected as read-only MVP role ownership over implementation, modeling/checkpoint, verification/review, and reorientation lanes --> fixed Imagination/planning, modeling/checkpoint, and verification/review role workers can be launched explicitly --> fixed role worker results can be read back for review without mutation --> reviewed modeling/checkpoint statePatch findings can be accepted explicitly to grow graph/checkpoint state --> completed unaccepted modeling findings stop for review before verification --> accepted verifier findings clear implementation only on verifier verdict pass; non-pass findings send the loop back toward modeling/checkpoint repair --> can be consumed explicitly by one bounded reorient-worker launch surface --> retrieval/indexing can inform future work --> explicit distillation can draft observation/evidence patches --> explicit proposal can draft map/churn patches from verified observations --> explicit promotion can reject or accept verified candidates --> explicit update patches can revise durable map/evidence/churn state --> successful writes emit thread/epiphany/stateUpdated +`runtime_spine.rs` registers and persists worker launch requests, worker +results, Mind reviews, Mind commit receipts, Eyes packets, Substrate Gate +grants, Hands consequence receipts, Soul verdicts, Continuity receipts, and +coordinator run receipts. Conceptually, the runtime store is lifecycle/evidence +truth and the thread-state store is admitted Mind truth. Current launch and +acceptance code, however, receive `runtime_spine_store` and write +`THREAD_STATE_KEY` into that cache. Production often aliases the paths, but the +API names conceal that requirement. The boundary must be repaired before the +two-store invariant can be claimed. + +## Hands → Soul → Modeling Loop + +1. Self emits a bounded Hands gate with requested paths and required receipts. +2. Substrate Gate records the access grant. +3. Hands records intent/review plus patch, command, and commit receipts. +4. `coordinator_launch_context.rs` builds sealed work-loop telemetry from that + receipt chain for Soul. +5. Soul emits a verdict receipt against the actual consequence. +6. Modeling receives the verified consequence and proposes a map/state patch. +7. `coordinator_acceptance.rs` commits an admitted proposal with its Mind + review/commit witnesses before Self routes another Hands turn. + +Manual edits and programmatic actions converge at the same receipt and Mind +admission boundaries. A later action cannot retroactively make an unrecorded +consequence valid. + +## Read And Recommendation Flow + +`epiphany-mvp-status` reads the native thread-state and runtime-spine stores. +It derives: + +- scene via `surfaces/scene.rs`; +- pressure via `surfaces/pressure.rs`; +- freshness via `surfaces/freshness.rs`; +- jobs via `surfaces/jobs.rs`; +- role board via `surfaces/role_board.rs`; +- planning via `surfaces/planning.rs`; +- reorientation via `surfaces/reorient.rs`; +- CRRC via `surfaces/crrc.rs`; +- coordinator status via `surfaces/coordinator.rs`. + +`epiphany-mvp-coordinator` consumes that native status shape. Requested Hands +paths come from the scene checkpoint/frontier. Revision comes from +`/scene/scene/revision`. There is no Codex `read.thread.epiphanyState` fallback. + +## Persona Flow + +```mermaid +flowchart LR + T["Typed Persona state + visible stimulus"] --> PR["Imagination Projector"] + PR --> PE["Persona turn"] + PE --> IN["Mind Interpreter"] + IN --> CA["Candidate actions / memory proposals"] + CA --> G["Review and external authority gates"] ``` -The current remaining missing organ is not the red pen, not the first chewing motion, not the first state-change bell, not the first client-shaped scene lens, not the first job/progress lens, not the first freshness surface, not the first watcher-backed invalidation read, not the first targeted graph/evidence context read, not the first bounded graph traversal read, not the first planning lens, not the first context-pressure gauge, not the first durable investigation checkpoint packet, not the first bounded reorientation verdict, not the first thin launcher seam, not the first explicit launch/interrupt authority surface over that seam, not the first runtime consumer that can act on the reorientation verdict without becoming a hidden tyrant, not the first read-back surface for that worker's findings, not the first explicit acceptance write for completed findings, not the first read-only CRRC coordinator recommendation, not the first role ownership lens, not the first fixed role specialist launch/read-back templates, not the first review-gated modeling statePatch acceptance path, not the first planning synthesis lane, and no longer the first dogfood-facing operator view over the landed loop. Those exist. Proposal now has the first bits of map memory, focus, and selection hygiene: it can auto-select a bounded evidence-backed observation cluster when ids are omitted, requires accepting recent evidence behind selected observations, prioritizes stronger selected observations for proposal wording, reuses existing architecture nodes by concrete code-ref/path/id checks before creating new path nodes, can rescue unanchored graph nodes through strict unique semantic overlap, follows graph links and incident edges into the frontier, and reports match-kind-aware churn pressure from the actual proposal shape. Distillation now also has the first source-output-aware teeth for tool/model summaries. Promotion now notices risky deltas instead of just checking the shape of the envelope, treats graph expansion as risky even if the patch tries to mumble "low pressure" while dragging a new wall into the blueprint, token-matches strong verifier kinds so `contest` cannot sneak past as `test`, and validates investigation checkpoints against known evidence before the packet can be inked. Successful update/promote writes now emit `thread/epiphany/stateUpdated` with `source: "update"` or `source: "promote"`, event-level revision, and typed changed fields so clients no longer need to poll blindly, infer the cause from timing, or diff the whole state to know which top-level sections moved. Bound jobs now keep durable binding authority separate from runtime lifecycle: `jobBindings` carry slot metadata and `runtimeLinks` carry runtime job identity. Stale `agent_jobs` bindings are sealed rather than live-crawled. `jobLaunch` / `jobInterrupt` can create or block those bindings without pretending reflection is authority, `reorientLaunch` can launch one fixed `reorient-worker` job from the checkpoint verdict without turning the verdict itself into a writer, `reorientResult` can read the worker's structured output back as a reviewable finding without promoting it, `reorientAccept` can explicitly bank a completed finding into typed observation/evidence plus optional scratch/checkpoint state, `roleLaunch` can launch fixed Imagination/planning, modeling/checkpoint, and verification/review specialists over that same bounded seam, `roleResult` can read their structured outputs back without mutation, `roleAccept` can apply reviewed Imagination planning patches and reviewed modeling graph/checkpoint patches through the normal state validator, and the `crrc` view lens can recommend the next explicit action over that loop without doing the action itself. The view lenses plus role-result, role-accept, freshness, context, graphQuery, reorient-result, and MVP status surfaces give clients compact or bounded views without making the GUI/client authoritative. The remaining missing organs are automatic graph invalidation, scheduler automation if dogfood proves it is needed, and richer product ergonomics after the MVP loop has been tested by a human. GitHub Issues import is a future adapter, but it is deliberately deferred until the backlog source is fresh enough to be worth importing. +Semantic memory recall is a bounded context input, not a state writer. Outside +world actions pass through Bifrost identity/governance and Heimdall capability +proofs. Persona speech audits are typed CultMesh witnesses; public speech does +not expose private worker or operator state. -```text -model/tool observations --> structured observation distillation --> bounded map/churn patch proposal --> promotion policy / verifier acceptance --> typed Epiphany state update --> durable evidence/map/churn mutation --> live stateUpdated notification -``` +## Heartbeat And Daemon Physiology -The typed write path exists, the first deterministic observation/evidence distillation path exists, source-output-aware distillation now summarizes noisy tool/model output into typed evidence with final result/error/finished lines ahead of generic warnings, the first deterministic map/churn proposal path exists, proposal-quality hardening now auto-selects bounded observation clusters when ids are omitted, requires accepting recent evidence, reuses existing graph nodes by observed code refs, prioritizes stronger selected observations, rescues unanchored graph nodes by strict semantic overlap, focuses linked frontier context, reports match-kind-aware map-delta pressure, and the first verifier-backed promotion gate exists. The first map/churn safety layer also exists: promotion can reject state replacement patches that are not tied to explicit observations/evidence, that contain structurally broken subgoal, invariant, graph, frontier, checkpoint, investigation-checkpoint, or churn fields, that try to promote risky churn without a warning and stronger verifier evidence, that claim a graph expansion is low-pressure to dodge the warning gate, or that rely on substring verifier-kind accidents. The first live state notification layer also exists: accepted writes publish updated typed state plus event-level revision and typed changed fields; rejected promotions stay quiet. +`heartbeat_state.rs`, `epiphany-heartbeat-store`, +`epiphany-daemon-supervisor`, and `epiphany-cluster-daemon` own scheduling and +liveness. A lane is not relaunched while its prior turn is active. Cooldown +begins after completion. Idle physiology may ruminate, distill memory, or dream +without claiming project-state authority. -In natural language: current Epiphany can preserve a map, show a map, project a compact scene from the map, project derived job/progress slots from the map and retrieval summary, reflect a thin launcher seam over bound work, explicitly launch or interrupt that bound work through a bounded authority surface, project a read-only freshness lens over retrieval and graph staleness, layer watcher-backed invalidation telemetry onto that lens for loaded threads, project a targeted graph/evidence context shard from the map, traverse bounded graph neighborhoods and path/symbol matches from the map, render typed graph state in the GUI through the adjacent EpiphanyGraph viewer, project planning captures/backlog/roadmap/objective drafts without adopting them, synthesize planning material through a review-gated Imagination lane, project context pressure from token telemetry, bank an in-flight investigation packet in durable typed state, reflect that packet back into prompt/scene/context, turn those signals into a read-only resume-versus-regather verdict, recommend the next explicit CRRC action over the verdict and worker/result state, print that recommendation in a dogfood operator view, explicitly launch one bounded `reorient-worker` job from that verdict, read its result back for review, explicitly accept a completed finding into typed state, retrieve evidence for the map, draft one explicit observation/evidence patch, derive a bounded graph/frontier/churn candidate from verified evidence-backed observations with code refs, choose a small coherent observation set when the caller does not provide one, favor the strongest selected observation when drafting that candidate, reject or accept a verified candidate, apply explicit map/evidence/churn/planning edits, notify clients after successful writes, inspect Rider/source-context status through an operator-safe bridge, capture Rider file/selection/symbol packets as artifacts, and sanity-check those edits before they hit the ledger. It still does not invalidate stale graph regions automatically, run scheduler automation over the fixed lanes, adopt objective drafts without a human gate, coordinate broad specialist ownership, or build-verify the Rider plugin scaffold on this machine. Teeth are installed; chewing is supervised; the first bell rings; the first wall board exists; the first shift board exists; the first freshness clipboard exists; the first door sensor now exists too; the first binder lens exists; the first graph-walk lens exists; the first planning wall exists; the first pressure gauge exists; the first ember packet exists; the first verdict slip now exists too; the first bounded launch lever and stop switch now exist too; the first explicit wakeup-hand now exists too; the first coordinator clipboard now exists too; the first operator readout exists too; Imagination now has a fenced workbench; Rider now has a first source-context hand; the GUI graph is no longer dead paper. The next slice is build-verifying or packaging the Rider plugin scaffold once Gradle/wrapper support exists, installing Unity `6000.1.10f1`, and running the next bridge-equipped Aetheria dogfood pass. +Idunn owns daemon survival. Self and Gjallar may inspect and recommend; they do +not become alternate daemon keepers. -The role board, fixed specialist templates, first role accept paths, and bounded role self-memory path now exist too. Current Epiphany can project implementation, Imagination/planning, modeling/checkpoint, verification/review, and reorientation/Continuity protocol state through the `roles` view lens, explicitly launch fixed Imagination/modeling/verification workers, read their findings back, apply reviewed Imagination planning patches and reviewed modeling graph/checkpoint patches through `thread/epiphany/roleAccept`, review optional embodied-lane `selfPatch` memory requests with reasons, apply accepted requests to Ghostlight-shaped role dossiers, and keep semantic acceptance review-gated. What remains is dogfooding the operator loop until real product friction, not imagined architecture guilt, tells us the next organ. +## Verse And Interface Projection -## Verification Hooks +CultMesh is the preferred local typed interface over CultCache/CultNet. -Current tests cover the landed flows at useful seams: +- `epiphany-internal`: private thoughts, reviews, receipts, and local organ + coordination; +- `gamecult-local`: trusted operator-safe GameCult sharing; +- `epiphany-global`: public dreams and Persona/public discussion documents. -- prompt rendering and omission/inclusion/resume behavior in `codex-core`. -- rollback and compaction replay behavior in `codex-core` and `epiphany-core`. -- explicit out-of-band Epiphany snapshot replay before the first user turn. -- deterministic observation/evidence distillation in `epiphany-core`. -- deterministic map/churn proposal in `epiphany-core`. -- verifier-backed promotion policy in `epiphany-core`. -- map/churn promotion validation for evidence-backed state replacements in `epiphany-core`. -- typed state-update patch application in `epiphany-codex-bridge` plus host persistence in `codex-core`. -- retrieval ranking, fallback, stale manifest detection, and mocked Qdrant/Ollama indexing in `epiphany-core`. -- app-server protocol serde for `thread/epiphany/retrieve`, `thread/epiphany/index`, `thread/epiphany/distill`, `thread/epiphany/propose`, `thread/epiphany/promote`, `thread/epiphany/update`, `thread/epiphany/stateUpdated`, and `thread/epiphany/jobsUpdated`. -- focused app-server coverage for sealed `thread/epiphany/jobsUpdated` behavior and heartbeat-backed job projection. -- app-server mapping of core retrieval/index summaries into protocol responses. -- focused Rust app-server mapper/handler coverage for the richer Phase 5 chain, including update/promote response metadata, `thread/epiphany/stateUpdated` notifications with source, revision, changed-field checks, retrieval-summary presence in successful write response/notification states, the verifier-only promotion edge where `Evidence` changes because verifier evidence is appended, invalid direct observation/evidence and replacement update rejection without mutation or notification, and explicit zero-notification assertions for rejected promotions. The old Python smoke shim has been cut. -- live app-server smoke for the first Phase 6 scene boundary through native `epiphany-phase6-scene-smoke`. -- live app-server smoke for the first Phase 6 freshness boundary through native `epiphany-phase6-freshness-smoke`. -- focused Rust app-server coverage for watcher-backed invalidation inputs inside the Phase 6 freshness boundary; add a native smoke before broadening that surface. -- live app-server smoke for the first Phase 6 context boundary through native `epiphany-phase6-context-smoke`. -- live app-server smoke for the first Phase 6 graph traversal boundary through native `epiphany-phase6-graph-query-smoke`. -- live app-server smoke for the first Phase 6 planning boundary through native `epiphany-phase6-planning-smoke`. -- live app-server smoke for the first Phase 6 pressure boundary through native `epiphany-phase6-pressure-smoke`. -- live app-server smoke for the first Phase 6 reorientation policy boundary through native `epiphany-phase6-reorient-smoke`. -- live app-server smoke for the first MVP operator status view through native `epiphany-mvp-status-smoke`. -- focused app-server mapper coverage for role projection, plus MVP status smoke coverage that consumes the roles view lens. -- focused app-server/protocol coverage for `thread/epiphany/roleLaunch`, `thread/epiphany/roleResult`, and `thread/epiphany/roleAccept`, plus live role smoke coverage that launches Imagination, modeling, and verification workers, reads completed results, accepts a reviewed Imagination planning patch and a reviewed modeling graph patch, proves durable planning grows without objective adoption, proves the durable graph grows before verification sees the expanded frontier, and proves a modeling `selfPatch` review is carried through result/accept. Native `epiphany-agent-memory-store smoke` validates the Ghostlight-shaped dossiers and accepted/refused/apply behavior for self-memory patches. +Eve/CultUI surfaces lower typed CultMesh composition/state. Renderers and +wrappers do not own the projected truth. -Useful commands: +## Codex Boundary -```powershell -cargo test --manifest-path .\epiphany-core\Cargo.toml -$env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-core --lib epiphany -$env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-app-server-protocol --lib thread_epiphany_ -$env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-app-server --lib map_epiphany_ -$env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-app-server --lib map_epiphany_ --manifest-path .\vendor\codex\codex-rs\Cargo.toml -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-scene-smoke -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-freshness-smoke -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-freshness-smoke -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-context-smoke -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-graph-query-smoke -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-planning-smoke -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-pressure-smoke -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-reorient-smoke -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-mvp-status-smoke -``` +The following are structurally absent: + +- `thread/epiphany/*` requests and notifications; +- `ThreadEpiphany*` protocol DTOs and generated bindings; +- `Thread.epiphanyState` in Codex app-server payloads; +- Epiphany rollout migration or replay; +- app-server phase-6 Epiphany smokes; +- Codex-backed MVP status/interruption; +- `epiphany-codex-bridge`. + +Native operator projections may still emit a compatibility-shaped +`epiphanyState` field. That field belongs to Epiphany's native projection and is +an active cleanup target; it is not the deleted Codex `Thread.epiphanyState` +contract returning through a side door. + +Codex app-server protocol has no dependency on `epiphany-state-model`. +App-server has no Epiphany state-model/core/bridge dependency. Negative source +checks in native launch/coordinator code reject renewed Codex route authority. + +## Verification Layers + +| Claim | Evidence layer | +|---|---| +| State mutation law | `state_update.rs` and coordinator-state unit tests | +| Worker/Mind admission | runtime-spine and coordinator-acceptance tests | +| Read-only derived surfaces | focused `surfaces/*` tests | +| Native status/interrupt | `epiphany-mvp-status` tests and executable smoke paths | +| Hands/Soul loop | Hands receipt tests plus coordinator launch-context tests | +| Protocol starvation | source scans, app-server compile, generated-schema equivalence | +| Verse privacy/authority | CultMesh/Verse focused smokes and typed receipt readbacks | +| Public crossings | Persona/Bifrost bridge smokes with private-state seals | + +## Current Cut Line + +Keep: + +- native typed state and runtime stores; +- explicit organ gates and receipts; +- native coordinator/status surfaces; +- CultMesh/CultNet/Eve projection; +- Codex-compatible auth/model transport where still required. + +Cut or correct next: + +- current plans and handoff prose that still describe deleted Codex routes or + bridge files as live mechanisms; +- wrapper arguments named for Codex when they no longer cross a Codex boundary; +- compatibility-shaped JSON field names inside native-only operator artifacts + when no external contract requires them; +- split canonical-state transaction authority and misleading state/runtime + store path names; +- public raw thread-state writers that bypass the intended coordinator/Mind + transaction boundary; +- any remaining full-context serializer or summary that duplicates typed owner + state instead of projecting it narrowly. + +This map must change when ownership changes. Historical scars belong in git, +evidence, or an explicitly archived note—not in the machine's proprioception. diff --git a/notes/epiphany-fork-implementation-plan.md b/notes/epiphany-fork-implementation-plan.md index 4e969cd1..f578e1ad 100644 --- a/notes/epiphany-fork-implementation-plan.md +++ b/notes/epiphany-fork-implementation-plan.md @@ -1,607 +1,190 @@ -# Epiphany Fork Implementation Plan - -This is the current implementation plan for Epiphany as an opinionated fork of -Codex. - -It is not a changelog. Git history, commit messages, smoke artifacts, and -targeted logs already do the proof job without turning this file into a hay -bale; `state/ledgers.msgpack` carries only distilled belief-changing evidence. - -The purpose of this note is to answer four questions: - -- what exists now -- what boundaries must not be blurred -- what we have learned -- what the next real implementation organs are - -## Lineage - -This note started as `notes/codex-epiphany-mode-plan.md` in commit `e64eee9`. -It described Phase 1: add a durable Epiphany thread-state seam to vendored -Codex without changing normal Codex behavior. - -The note was later renamed because Epiphany stopped being "a Codex mode" and -became a fork-level modeling architecture. The rename was correct. The later -append-only status drift was not. A plan that records every landed micro-slice -forever becomes the documentation equivalent of the Jenga tower. - -Historical detail belongs in: - -- `git log` -- `state/ledgers.msgpack`, when the detail changes what a future agent should believe -- `notes/fresh-workspace-handoff.md` -- `notes/epiphany-current-algorithmic-map.md` - -This file carries the distilled plan. - -## Current Baseline - -Phase 1 through Phase 5 are complete enough. - -The landed machine now has: - -- durable Epiphany thread state in Codex protocol/core rollout state -- prompt integration through a bounded `` developer fragment -- typed client read exposure through `Thread.epiphanyState` -- hybrid repo retrieval through `thread/epiphany/retrieve` -- explicit persistent semantic indexing through `thread/epiphany/index` -- repo-owned heavy implementation in `epiphany-core` -- typed state mutation through `thread/epiphany/update` -- read-only observation distillation through `thread/epiphany/distill` -- read-only map/churn proposal through `thread/epiphany/propose` -- verifier-backed promotion through `thread/epiphany/promote` -- successful-write notification through `thread/epiphany/stateUpdated` -- explicit launch/interrupt authority through `thread/epiphany/jobLaunch` and `thread/epiphany/jobInterrupt`, now backed by heartbeat-owned activation bindings rather than Codex `agent_jobs` -- thin Epiphany-owned launcher metadata in durable `jobBindings`, with launcher id, authority scope, and backend kind/job id -- sealed legacy `thread/epiphany/jobsUpdated` protocol shape; heartbeat/runtime-spine is the live progress path -- response-level and notification-level revision and changed-field metadata -- direct-update validation for malformed appended records and structural replacements -- proposal and promotion rules that reduce map/churn Jenga pressure -- focused Rust app-server mapper/handler coverage for the Phase 5 control-plane chain; the old Python smoke shim has been cut -- a first Phase 6 read-only reflection surface through `thread/epiphany/scene` -- live Phase 6 scene app-server smoke coverage through native `epiphany-phase6-scene-smoke` -- read-only Phase 6 job/progress reflection through `thread/epiphany/jobs`, with durable heartbeat-backed `jobBindings` and sealed stale `agent_jobs` bindings -- read-only Phase 6 retrieval/graph freshness reflection plus watcher-backed invalidation inputs through `thread/epiphany/freshness` -- live Phase 6 freshness app-server smoke coverage through native `epiphany-phase6-freshness-smoke` -- focused Rust app-server coverage for Phase 6 watcher-backed invalidation inputs; a native smoke should be added before broadening that surface -- read-only Phase 6 targeted state-shard reflection through `thread/epiphany/context` -- live Phase 6 context app-server smoke coverage through native `epiphany-phase6-context-smoke` -- read-only Phase 6 graph traversal through `thread/epiphany/graphQuery` -- live Phase 6 graph traversal smoke coverage through native `epiphany-phase6-graph-query-smoke` -- read-only Phase 6 context-pressure reflection through `thread/epiphany/pressure` -- live Phase 6 pressure app-server smoke coverage through native `epiphany-phase6-pressure-smoke` -- durable Phase 6 investigation checkpointing in authoritative typed state, prompt rendering, and scene/context reflection -- read-only Phase 6 CRRC reorientation policy through `thread/epiphany/reorient` -- bounded Phase 6 reorient-guided worker launch through `thread/epiphany/reorientLaunch` -- read-only Phase 6 reorient-worker result read-back through `thread/epiphany/reorientResult` -- explicit Phase 6 reorient-worker finding acceptance through `thread/epiphany/reorientAccept` -- read-only Phase 6 CRRC coordinator recommendation through `thread/epiphany/crrc` -- read-only Phase 6 fixed-lane MVP coordinator recommendation through `thread/epiphany/coordinator`, composing roles, pressure, reorient, CRRC, role results, and reorient result without mutation -- limited native Phase 6 CRRC automation at turn-complete safe boundaries, restricted to coordinator-approved compact and fixed reorient-worker launch actions -- read-only Phase 6 role ownership through `thread/epiphany/roles`, projecting implementation, modeling/checkpoint, verification/review, and reorientation lanes from typed state plus jobs/CRRC/result signals -- explicit Phase 6 role launch/read-back through `thread/epiphany/roleLaunch` and read-only `thread/epiphany/roleResult`, limited to fixed modeling/checkpoint and verification/review templates over the heartbeat/runtime-spine seam -- review-gated Phase 6 modeling acceptance through `thread/epiphany/roleAccept`, limited to completed modeling/checkpoint `statePatch` findings that apply graph/frontier/checkpoint/scratch/investigation-checkpoint changes through the existing state validator -- first Phase 6 dogfood operator view through native `epiphany-mvp-status` -- old Python dogfood runner cut; replacement must be native Rust/CultCache/CultNet over heartbeat/runtime-spine receipts -- first auditable Phase 6 fixed-lane coordinator runner through native `epiphany-mvp-coordinator`, producing coordinator summary, JSONL steps, rendered snapshots, transcript, stderr, runtime-spine status, native runtime job/result receipts for launched work, and final next-action artifacts while keeping semantic findings review-gated by default -- first Codex-independent native runtime vertebra through `epiphany-runtime-spine`, storing runtime identity, sessions, jobs, job results, and events as typed CultCache MessagePack documents, opening/completing native jobs, projecting job-result counts, and emitting a framed CultNet hello message for the native contract -- first Rust CultMesh local-node integration: `vendor/cultmesh-rs` now provides the repo-contained CultMesh surface over vendored CultCache/CultNet, and `epiphany-core` depends on that surface for local `EpiphanyCultMeshStatusEntry`, `EpiphanyCultMeshVersePolicyEntry`, and `EpiphanyCultMeshGlobalRoomPolicyEntry` round-trip smokes instead of treating raw CultNet as the ergonomic app-facing database layer -- first local Verse query surface: `notes/epiphany-verse-architecture.md` names Verse/Odin/Yggdrasil ownership, `epiphany-verse-query` can seed/query a compact CultMesh-backed local Verse context bundle for operator inspection and future dynamic prompt assembly without granting semantic memory, public sharing, or state-admission authority, and `tools/epiphany_local_run.ps1 -Mode status` now writes that packet as `local-verse-context.json` beside native status/operator snapshot artifacts -- first dynamic prompt launch handoff: role/reorient worker launch documents carry optional `dynamicPromptContext`, runtime prompt assembly consumes that field into worker instructions, `epiphany-prompt-context-smoke` proves rendered Verse/memory context can ride a role launch document without admitting unrelated private-looking text, live bridge role/reorient launch paths now feed local Verse plus memory graph context from sibling `local-verse.ccmp` and `memory-graph.msgpack` stores beside runtime-spine, and the bridge launch-context test proves the dynamic packet survives in a persisted runtime-spine worker launch request -- first Hands/Soul/Continuity contract catalogs: action, verification, and continuity now have native `epiphany-core` contract families, runtime-spine advertisement, CultMesh policy documents, and local CultMesh smoke coverage beside Mind/Substrate Gate/Eyes; Hands now also has typed runtime-spine document bodies/helpers for `HandsActionIntent`, `HandsActionReview`, and `HandsPatchReceipt`, with `epiphany-hands-action-smoke` proving the action receipt chain without live file execution -- live-specialist runner must be rebuilt around heartbeat/runtime-spine result receipts -- first Phase 6 Aquarium operator shell extracted to sibling repo `E:\Projects\EpiphanyAquarium`, a Tauri v2 + React/WebGL client over the existing status bridge, dogfood artifacts, and GUI action artifacts, with its own distilled interface state/memory/doctrine plus durable checkpoint preparation, bounded status/coordinator artifact buttons, fixed modeling/verification/reorient launch and read-back buttons, and explicit review-gated reorient acceptance -- first Unity editor/runtime bridge through native `epiphany-unity-bridge`, native `epiphany-unity-bridge-smoke`, and the GUI Inspect Unity action, resolving exact project-pinned editors and writing runtime artifacts while refusing wrong or missing versions -- prompt-file ownership for major Epiphany prompt surfaces: rendered state intro/doctrine lives under `epiphany-state-model/src/prompts/` beside the typed state document renderer, while modeling/Modeling, research/Eyes, implementation/Hands, verification/Soul, reorientation/Continuity, coordinator/Self, and CRRC templates live in `epiphany-codex-bridge/src/prompts/epiphany_specialists.toml` -- prompt-level anti-Greenspun guardrails: Epiphany owns the operator discipline and requires a bounded research/scout check before agents invent bespoke versions of known algorithms, parsers, schedulers, renderers, protocols, storage layers, security mechanisms, or workflow engines -- live Phase 6 reorientation app-server smoke coverage through native `epiphany-phase6-reorient-smoke` -- live Phase 6 MVP status smoke coverage through native `epiphany-mvp-status-smoke` - -The current phase is Phase 6: reflection boundary and observable harness state. -The immediate next phase is Codex starvation and CultNet liberation, recorded -in `notes/codex-starvation-and-cultnet-liberation-plan.md`. The May 2026 -control-plane rebuild made the app-server Epiphany seam cleaner, but the user's -current doctrine is stricter: a cleaner Codex host is still the wrong organ. -Epiphany data must live as typed CultCache documents, Epiphany-owned -subsystems must communicate through CultNet contracts, and vendored Codex should -remain relatively vanilla bridge machinery for OpenAI auth/model transport and -useful Codex-native app-server/runtime affordances. - -The repo-swarm MVP contract is now explicit in -`notes/epiphany-repo-swarm-mvp-contract.md`: autonomous branch-local work inside -an Epiphany-owned Body is not a future hazard to avoid; it is the product -target. The migration path must make that autonomy typed, branch-contained, -receipt-backed, interruptible, and Bifrost-publication-gated instead of -turning Epiphany into a human-permission queue for every local edit. - -The older teardown/rebuild pair remains useful source history: -`notes/archive/epiphany-architectural-teardown.md` names the host-seam rot, and -`notes/archive/epiphany-ideal-architecture-rebuild-plan.md` records the completed -cleanup inside Codex. They no longer authorize outward product work while -Epiphany still depends on Codex app-server routes, Codex prompt injection, apps, -skills, marketplace, or generic JSON cargo as internal Epiphany machinery. -Retained Codex app-server behavior is acceptable only as Codex-side bridge -functionality, not as an Epiphany state/process/prompt owner. - -## Boundary Rules - -These boundaries are more important than the individual method names: - -- CultCache documents are the data model. CultNet is the wire for - Epiphany-controlled subsystems. -- CultMesh is the preferred ergonomic runtime/database surface over local CultCache plus CultNet contracts. Epiphany should start local Verse, dream, status, and operator-store work through CultMesh unless the task is explicitly implementing a lower-level CultMesh/CultNet/CultCache primitive. -- Verse boundaries are three-tiered: `epiphany-internal` owns private sub-agent typed state, `gamecult-local` owns trusted LAN/Yggdrasil-tunnel sharing with other GameCult projects, and `epiphany-global` owns untrusted public dream surfaces plus topic-specific threaded rooms for Persona posts. Do not route private state through the local-area or global Verse. -- JSON is allowed only for schema description, hostile/external ingress before - immediate typed parsing, sealed forensic artifacts, or named quarantine - experiments with an expiration path. Generic `serde_json::Value` must not be - passed between Epiphany-owned organs as runtime data. -- Codex is a relatively vanilla bridge organ for OpenAI subscription auth, - model transport, streaming, and useful Codex-native app-server affordances. - Codex apps, skills, marketplace, app-server lifecycle, and plugin UX are not - Epiphany foundations unless explicitly exposed through bridge contracts. -- Epiphany does not need to know Codex internals, and Codex does not need to - know Epiphany internals. The bridge handles interop. -- Codex prompt machinery must not tell Epiphany agents what to do. Epiphany - prompts, typed state projections, organ contracts, scheduler decisions, and - mutation law are Epiphany-owned; Codex may transport and stream turns. -- MCP may survive only as a separate CultNet-speaking adapter; it does not - justify preserving the Codex host brain. -- `thread/epiphany/retrieve` is read-only. -- `thread/epiphany/distill` is read-only. -- `thread/epiphany/propose` is read-only. -- Durable typed state writes go through `thread/epiphany/update`, accepted `thread/epiphany/promote`, or the bounded `thread/epiphany/jobLaunch`, `thread/epiphany/jobInterrupt`, and `thread/epiphany/reorientLaunch` authority surfaces when they mutate `jobBindings`. -- `thread/epiphany/index` may update the semantic retrieval catalog, but it is not a hidden Epiphany-state writer. -- `thread/epiphany/scene` is a client reflection, not a second source of truth. -- `thread/epiphany/jobs` is a derived reflection over retrieval summaries plus typed launcher bindings and optional backend snapshots, not a scheduler or durable runtime job store. -- `thread/epiphany/jobsUpdated` is a live notification derived from runtime progress events and launcher-bound job snapshots, not a scheduler, polling daemon, or durable runtime job store. -- `thread/epiphany/jobLaunch` and `thread/epiphany/jobInterrupt` are bounded authority surfaces over durable `jobBindings` plus the temporary Codex evacuation bridge, not a hidden scheduler, queue, or second runtime. -- `thread/epiphany/reorientLaunch` is a bounded runtime consumer over the reorientation verdict, not automatic CRRC, a hidden queue, or permission to keep working after drift without an explicit launch. -- `thread/epiphany/reorientResult` is a read-only result read-back surface, not a promotion gate, state writer, scheduler, or hidden continuation trigger. -- `thread/epiphany/reorientAccept` is an explicit acceptance write for completed reorient-worker findings, not automatic promotion, scheduling, or permission to continue without review. -- `thread/epiphany/freshness` is a derived reflection, not automatic watcher-driven invalidation, a mutation gate, or a hidden refresh scheduler. -- `thread/epiphany/context` is a targeted reflection, not a state writer or hidden proposal engine. -- `thread/epiphany/graphQuery` is bounded graph traversal over authoritative typed state, not retrieval, proposal, promotion, scheduling, indexing, or a state writer. -- `thread/epiphany/pressure` is a current-context pressure reflection, not cumulative spend accounting, an automatic compactor, scheduler, or CRRC coordinator. -- `thread/epiphany/reorient` is a bounded policy verdict, not an automatic runtime coordinator, scheduler, compactor, or hidden state writer. -- `thread/epiphany/crrc` is a read-only coordinator recommendation over existing signals, not a scheduler, launch button, acceptance gate, compactor, or hidden state writer. -- `thread/epiphany/coordinator` is a read-only fixed-lane MVP policy projection over existing signals, not a scheduler, launcher, acceptance gate, compactor, or hidden state writer. -- Native CRRC automation may act only at safe turn-complete boundaries and only for coordinator-approved `compactRehydrateReorient`, successful pre-compaction checkpoint handoff compact, and coordinator-approved `launchReorientWorker` actions. It must not auto-launch modeling or verification, auto-accept semantic findings, promote evidence, edit implementation code, or silently continue after unresolved drift. -- Pre-compaction checkpoint intervention may steer an active loaded Epiphany turn once at the token-count boundary when pressure reaches the existing `shouldPrepareCompaction` threshold. The steering directive is allowed to ask the agent to bank scratch/checkpoint/map/evidence before compaction/reorientation; it must not auto-accept semantic findings, promote evidence, launch arbitrary workers, or continue implementation after unresolved drift. -- `thread/epiphany/roles` is a read-only role ownership projection, not a specialist scheduler, marketplace, launcher, acceptance gate, or second job backend. -- `thread/epiphany/roleLaunch` is a bounded authority surface for fixed modeling/checkpoint and verification/review templates, not a broad scheduler or specialist marketplace. -- `thread/epiphany/roleResult` is a read-only result projection, not a promotion gate, state writer, scheduler, or hidden continuation trigger. -- `thread/epiphany/roleAccept` is a narrow modeling/checkpoint acceptance write, not automatic specialist promotion, a verifier substitute, a broad state editor, or permission for workers to accept their own output. -- The GUI may render and steer typed state, but it must not manufacture canonical understanding. -- Rider and Unity bridge work is quarantined for now. The landed bridges remain - optional later engine-repo evidence surfaces, not MVP blockers or current - product priority. When resumed, the Unity bridge may inspect and run only the - project-pinned editor through explicit bridge commands; agents must not launch - PATH/default/legacy Unity directly or substitute nearby Hub versions. -- The MVP GUI target is a local Tauri v2 + React operator app over the existing app-server APIs. Tauri owns windowing and local lifecycle; app-server and typed Epiphany state remain authoritative. -- The app-server remains a host seam; Epiphany-owned machinery should live in `epiphany-core` where practical. -- Qdrant is the preferred persistent semantic backend; BM25 remains the bootstrap/fallback/control path. - -If a new feature violates one of these rules, stop and redesign before writing -more Rust-flavored archaeology. - -## What We Learned - -State can rot exactly like code. - -The failure mode is not only speculative implementation cruft. Persistent -memory can also become a pile of locally true fragments that no longer help the -next agent model the whole machine. That is the same Jenga problem with nicer -headings. - -The current lessons: - -- Keep the algorithmic map as the source-audited control-flow description. -- Keep the implementation plan as a distilled forward plan, not a trophy wall. -- Keep the harness-surfaces note as a surface contract, not a dump of every possible future type. -- Keep `fresh-workspace-handoff.md` as a re-entry packet, not a substitute brain. -- Keep `state/ledgers.msgpack` as a durable distilled ledger, not an activity feed. -- Revert failed code hypotheses immediately. -- Distill failed or obsolete state hypotheses just as aggressively. -- Treat unpersisted source-gathering and slice-planning work as volatile. If compaction interrupts it, the correct recovery is re-gathering from source or a persisted checkpoint, not continuing from the ghost of the old context. -- Treat repetitive slow work as a finite queue, not an attention loop. A batch, tile pass, import, migration, or repeated probe is incomplete until every required item is terminal or a concrete blocker is recorded; "pattern demonstrated" is not a done state. -- Treat pattern completion bias as a prompt and coordinator failure mode. Implementation should chase the stated objective until it is complete or concretely blocked; the coordinator should challenge implementation claims against objective progress, verifier-readable evidence, shortcuts, and pointless embellishments. - -The plan should get shorter after a phase completes, not longer by default. - -## What We Need To Know Next - -The next unknown is not whether Epiphany can preserve, read, propose, promote, -and notify typed state. It can. - -The active priority is now the Codex starvation plan: -`notes/codex-starvation-and-cultnet-liberation-plan.md`. Do not add outward -feature surfaces until the auth/model spine and JSON contamination inventories -exist and the first typed-document replacement cut is underway. The target is -not to delete useful vanilla Codex app-server behavior for its own sake; it is -to prevent Codex from owning Epiphany state, processes, prompts, or policy. - -The distributed dreaming direction is now concrete in -`notes/epiphany-cultmesh-dreaming-roadmap.md`. It is not a license to add a -new networked thought hose beside the starvation work. It is the target shape -for the CultNet liberation path: public dreams are separately authored typed -documents; private state remains local; foreign dreams are external thought -weather until a reviewed local adoption receipt digests them. The first -implementation cut is schema plus local CultCache dream store, not public mesh -fanout. - -The next unknowns are: - -- what exact vendored Codex crates, files, config, and runtime paths are needed - for OpenAI subscription auth/model transport and useful vanilla Codex - app-server/streaming bridge affordances -- which Codex dependencies can be deleted, ignored, or sealed because they are - apps, skills, marketplace, app-server UX, plugin plumbing, or thread - lifecycle machinery outside the OpenAI auth/model spine -- which Epiphany-relevant `serde_json::Value`, `json!`, `from_value`, and - `to_value` uses are legitimate schema/wire/forensic/quarantine edges and - which are heretek internal blobs -- how to replace worker launch `input_json` / `output_schema_json`, - role-result parsing, and `selfPatch` with typed CultCache documents -- how to expose state read/update, view lenses, runtime launch/read/interrupt, - result accept/refuse, retrieval, checkpoint, CRRC, coordinator, heartbeat, - and role-memory actions as CultNet contracts instead of Codex JSON-RPC verbs -- how to split MCP into a CultNet-speaking adapter without preserving Codex - app-server/plugin organs -- how to make Aquarium and CLI status use CultNet contracts instead of - `thread/epiphany/*` -- how to define `EpiphanyDream`, dream lineage, ingress receipts, and adoption - receipts as typed documents without letting dreams mutate private state or - project truth by import -- how to expose an `epiphany-local` dream store first, then a public - `epiphany-dreams` Verse with leases, shard ownership, provenance, and - anti-repetition cooling -- what bridge surface is sufficient for the next Aetheria run, once Rider/Unity - quarantine is explicitly lifted: named Unity operations, Aetheria-side editor - probes, GUI environment status, Rider context capture, and a Rider plugin MVP -- how much controlled runtime/editor access the richer Unity bridge gives - implementation and verification lanes before deeper engine probes need - another slice, once engine bridge work is back in scope -- how the landed watcher-backed invalidation telemetry should be consumed without turning freshness into a secret worker -- how far the read-only CRRC recommendation should go before explicit client/operator action takes over -- how much narrow coordination is needed so modeling, implementation, verification, and CRRC automation can hand off work without collapsing back into one context -- what concrete operator friction appears once the bridge-equipped GUI/operator MVP is tested on real work - -## MVP Cutline - -The testable MVP is not "all of Epiphany." It is the smallest harness loop that -can prove the product thesis on real coding work: - -1. **State loop**: an agent can externalize objective, map, scratch, evidence, - checkpoint, and job state into typed durable state; that state survives - turns, resume, rollback, and compaction. -2. **Role separation loop**: programming, modeling/checkpoint maintenance, and - verification/review can be represented as distinct bounded roles instead of - being forced into one giant context. -3. **CRRC loop**: context pressure or continuity breakage can trigger explicit - checkpointing, rehydration, reorientation, and resume-versus-regather - continuation based on durable evidence rather than transcript vibes. -4. **Read-back loop**: bounded specialist work launched by Epiphany, especially - `thread/epiphany/reorientLaunch`, returns findings into a reviewable - Epiphany surface or typed-state proposal instead of stranding them in - generic runtime job rows. -5. **Dogfood loop**: a human can inspect the current map, scratch, evidence, - pressure, reorientation verdict, active specialist jobs, and pending - findings without reading Rust. - -The MVP should include narrow specialists and a bounded CRRC coordinator because -those are central to the design. It should not include an arbitrary specialist -marketplace, broad ambient dispatcher, automatic promotion of every tool -observation, a GUI-first workflow, or an alternate job backend for the MVP. The -useful scheduler-shaped thing is narrower: an auditable coordinator that keeps -the fixed single-user lanes in sequence, makes handoffs explicit, and preserves -operator review and interruption. CRRC is harness workflow automation, not a -specialist-agent role; it watches context pressure and continuity, persists -state, triggers compact/rehydrate/reorient behavior, and may launch a bounded -reorient-worker specialist when semantic regathering is needed. - -The read-back, acceptance, CRRC recommendation, first dogfood-view, fixed-lane -coordinator, first -harness-native role ownership, and first fixed role specialist launch/result -blockers are now landed as -`thread/epiphany/reorientResult`, `thread/epiphany/reorientAccept`, -`thread/epiphany/crrc`, native `epiphany-mvp-status`, -`thread/epiphany/coordinator`, native `epiphany-mvp-coordinator`, and -`thread/epiphany/roles`, `thread/epiphany/roleLaunch`, -`thread/epiphany/roleResult`, and `thread/epiphany/roleAccept`. A human can now ask the harness what it believes, -what it recommends, which role lane owns the next visible work, which fixed-lane -action should happen next, explicitly launch modeling/checkpoint or -verification/review workers, read their findings back without reading Rust, and -apply a reviewed modeling graph/checkpoint patch without pretending the modeler -can silently promote itself. -The first auditable dogfood pass then added -native coordinator/status surfaces, rendered modeling/verification findings in the -status view, and fixed CRRC's repeat-acceptance recommendation after -`reorientAccept`. The live-specialist runner then proved the real worker path by -launching a modeling/checkpoint specialist and returning a completed -`checkpoint-ready` finding through `roleResult`; that old backend completion -path is now cut. The coordinator runner then -proved the sequence-locked MVP policy across cold start, clean checkpoint, -modeling, verification, CRRC drift/reorient, and high-pressure compact/dry-run -paths. Native CRRC automation then wired the proved policy into turn-complete -safe boundaries for compact and fixed reorient-worker launch only. Successful -pre-compaction checkpoint steering now also latches a pending compact handoff -for the completed turn, so the brake becomes a real compaction request instead -of a polite suggestion. The first -pre-compaction checkpoint intervention is now also landed: token-count pressure -events steer active loaded Epiphany turns once when current context usage reaches -80% of the active auto-compact/context limit, ignoring cumulative token spend so -CRRC does not yell at clouds. The next MVP -question is sharper: dogfood the coordinator/status/pre-compaction loop and fix -only concrete blockers. The latest self-dogfood pass found one: the dogfood -runner's manifest promised vanilla/comparison artifacts that were not actually -written. The runner now always writes the prompt, reference status, comparison, -and manifest honestly, and an explicit `--run-vanilla-reference` pass can spend -a real vanilla Codex turn and persist its transcript for comparison. - -The latest Aetheria dogfood pass found the next bigger blocker, and the first -slice is now landed. The fixed lanes can catch modeling, verification, stale -job, no-diff, and reorientation failures, but the implementation lane cannot -prove engine assumptions by launching random local tools. A worker tried to -launch a legacy default Unity editor even though Aetheria pins Unity -`6000.1.10f1`. Native `epiphany-unity-bridge` now reads the project pin, -resolves only an exact Hub editor, refuses wrong or missing editors, owns the -batch/quit/projectPath command wrapper, and writes inspection/command/log -artifacts. On this machine Aetheria is correctly blocked: only Unity -`6000.4.2f1` is installed. - -The detailed environment plan is archived at -`notes/archive/epiphany-rider-unity-integration-plan.md`. Its opinionated cut is Rider -as the IDE/source-context organ, Unity as the editor/runtime fact organ, and -Epiphany as the durable coordinator/Self. The product workflow is now framed as -three integrated surfaces: Rider is the human code view for repo state, source -tree, diffs, diagnostics, and code refs; Epiphany GUI is the agent dashboard -for objectives, specialist lanes, logs/artifacts, persisted state, and -graph/control-flow views; Unity is the pinned runtime environment for tests, -probes, scene configuration, assets, shaders, and play/edit-mode evidence. The -Unity side must become editor-resident, not merely command-line: an -Aetheria-side Unity Editor package should inspect scenes, prefabs, serialized -component fields, prefab overrides, materials, shaders, ScriptableObjects, and -asset references through Unity APIs such as `SerializedObject`, -`AssetDatabase`, `PrefabUtility`, and `EditorSceneManager`, with typed -artifacts and explicit dry-run/apply boundaries for refactors. The adjacent -EpiphanyGraph React viewer is the preferred seed for GUI graph diagramming -because it consumes typed `graphs.architecture`, `graphs.dataflow`, and -`graphs.links` directly. - -The detailed planning substrate design is archived at -`notes/archive/epiphany-planning-substrate.md`. Its cut is deliberately separate from -the active objective: chat produces captures, captures normalize into backlog -items, backlog items group into roadmap streams, selected work becomes -Objective Drafts, and only explicit human adoption turns a draft into -`objective.current`. The plan anticipates GitHub Issues import by treating -issues as source records that land in captures first, preserving labels, -milestones, assignees, state, timestamps, comments, PR markers, and optional -Projects v2 metadata without letting GitHub become Epiphany's internal backlog -schema. - -The first runtime slice is now landed: planning state lives in -`EpiphanyThreadState`, accepts typed captures/backlog/roadmap/objective drafts -through revision-gated `thread/epiphany/update`, renders into the prompt when -present, and exposes read-only `thread/epiphany/planning` for GUI clients. The -remaining product work is GUI presentation, explicit adoption/write actions, -Imagination synthesis, and real GitHub import. - -The planning/future-shape role is **Imagination**. It works beside Eyes: Eyes -scouts outside reality and existing work, while Imagination shapes captures, -backlog, roadmap streams, and Objective Drafts ahead of the active run. That -work remains non-authoritative until the human explicitly adopts an objective. - -## Phase 6 Direction - -Phase 6 must stop growing observable harness state outward until Epiphany is -free of the Codex host organ. The previous control-plane cleanup is a landed -scar, not the final architecture. The live surfaces are guardrails and evidence, -not permission to keep stacking protocols on the host seam. - -Liberation candidates, in the intended order: - -1. Inventory the minimal Codex auth/model-call spine needed for the user's - Codex subscription. -2. Classify Epiphany-relevant JSON usage into schema/wire descriptor, hostile - ingress, sealed forensic artifact, quarantine experiment, or internal blob. -3. Define the native Epiphany runtime boundary over typed CultCache documents - and CultNet read/mutation/event contracts. -4. Replace worker launch/result/selfPatch cargo with typed document contracts. -5. Move Aquarium/CLI/operator reads and actions from `thread/epiphany/*` - JSON-RPC to CultNet contracts. -6. Split MCP into a CultNet adapter if it remains useful. -7. Starve `codex_message_processor.rs` until Epiphany no longer depends on it - for state, scheduling, runtime, views, acceptance, notifications, or tests. -8. Delete or seal Codex apps, skills, marketplace, and plugin UX from the - Epiphany runtime path. -9. Extract the OpenAI auth/model transport adapter as the only surviving Codex - compatibility relic. - -Do not spend Phase 6 adding another convenience surface because the current ones -work. Passing smokes prove behavior, not architecture. The Perfect Machine gets -fewer thrones, not a new one for every button, and certainly not a 21k-line -host-organ cathedral with plugin pews. - -## Aquarium Operator Plan - -Build the MVP operator UI as a local Tauri v2 + React/WebGL Aquarium in -`E:\Projects\EpiphanyAquarium`. - -Aquarium is not the source of truth. It is a desktop window over the same -app-server surfaces already proved by the CLI status, coordinator, dogfood, and -live-specialist runners. Its job is to make the single-user loop usable without -terminal handling, not to invent a parallel state model. EpiphanyAgent owns the -harness, typed state, coordinator policy, and bridge tools; Aquarium owns the -interface organism, visual/audio interaction grammar, and its own local -pseudo-Epiphany state. - -Current shape: - -1. Maintain `E:\Projects\EpiphanyAquarium` as the UI repo with `AGENTS.md`, - `state/map.yaml`, `state/memory.json`, scratch/evidence, and interface - doctrine. -2. Start by consuming existing app-server JSON-RPC surfaces rather than adding new protocol unless the UI exposes a real missing primitive. -3. Make the default screen an aquarium of interactive objects, not a static - admin panel: - - active thread and workspace - - coordinator recommendation and reason - - pressure, CRRC, and reorientation status - - fixed role lanes for implementation, modeling/checkpoint, verification/review, and reorientation - - reviewable role and reorient findings - - job/progress list - - artifact bundle list with links to summaries, sealed transcript/stderr receipts, and comparison files -4. Add explicit action buttons only for already-bounded authority surfaces: - - refresh status - - run status snapshot - - run coordinator pass - - inspect project-pinned Unity runtime through the bridge - - prepare a durable checkpoint for a resumable operator thread - - launch fixed modeling/checkpoint role - - accept a completed modeling/checkpoint `statePatch` after review - - launch fixed verification/review role - - launch fixed reorient-worker when recommended - - accept a completed reorientation finding after review - - open artifact folder/file -5. Keep semantic acceptance gated. Aquarium may launch bounded work and display - findings, but it must not auto-promote evidence, auto-accept worker output, - invent arbitrary specialists, or continue implementation after unresolved - drift. - -Implementation slices: - -1. **Read-only shell**: scaffold Tauri/React, connect to app-server through the - existing MVP status bridge, render the same data as - native `epiphany-mvp-status`, and provide artifact bundle links. This - slice landed first under `apps/epiphany-gui` and is now extracted to - `E:\Projects\EpiphanyAquarium`. -2. **Bounded operator actions**: status snapshot, coordinator-plan, Unity - runtime inspection, durable checkpoint preparation, roleLaunch, roleResult, - reorientLaunch, reorientResult, and explicit reorientAccept flows are - landed. Review gates remain explicit; the GUI does not auto-promote - evidence or continue implementation after semantic findings. -3. **Dogfood launcher**: wrap a native heartbeat/runtime-spine runner and - native `epiphany-mvp-coordinator` as explicit operator actions that write - artifact bundles and stream progress/status into Aquarium. -4. **Usability pass**: make the current recommendation, blocked lane, pending - review, and next safe action visually obvious enough that the user can test - the product without reading sealed transcripts unless the user explicitly asks for forensic debugging. - -Verification: - -- Keep the existing CLI smokes as backend guardrails. -- Keep native `epiphany-unity-bridge-smoke` for Unity bridge regressions. -- Keep `npm run smoke:visual` for browser-layout regressions and bounded - browser-fallback action clicks in `E:\Projects\EpiphanyAquarium`. -- For native Aquarium changes, run `npm run build`, `cargo fmt --check`, - `cargo check`, and `npm run tauri -- build --debug --no-bundle` from - `E:\Projects\EpiphanyAquarium`. -- Use live bridge probes when action lifecycle changes; the current - `prepareCheckpoint -> readModelingResult` probe proved a checkpoint-created - thread can be resumed by a later process. - -## Later Phases - -These remain later work: - -- watcher-driven semantic invalidation -- automatic observation promotion from tool output -- richer evidence UI and graph steering beyond the landed targeted context and graph traversal reads -- richer role ergonomics after the fixed single-user coordinator proves useful -- mutation gates that warn or block broad writes when map freshness is stale -- broader CRRC runtime coordination beyond the landed narrow safe-boundary compact, fixed reorient-worker launch, and pre-compaction checkpoint steering actions -- richer editor/runtime bridges beyond the first pinned Unity bridge -- richer GUI workflows for graph, evidence, job, invariant, and frontier steering after the operator console proves useful -- GUI Planning view, explicit planning capture/adoption actions, the Imagination planning role surface, and real GitHub Issues import into typed captures; the first thread-state planning store and read-only projection are landed -- typed repetitive-work queues and final-answer gates, so the coordinator and GUI can see unfinished batch work before conversational closure pretends it is done -- stronger coordinator challenge loops for implementation claims, including objective-progress checks and explicit shortcut/embellishment rejection before another implementation turn is treated as successful - -Do not start these from vibes. Each one needs a source-grounded slice plan and a -clear invariant that says what it must not break. - -## Verification Guardrails - -Use focused checks for the surface being changed. - -Before modifying Phase 5 control-plane behavior, run: - -```powershell -$env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-app-server --lib map_epiphany_ --manifest-path .\vendor\codex\codex-rs\Cargo.toml -``` - -Before modifying scene projection behavior, run: - -```powershell -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-scene-smoke -``` - -Before modifying jobs reflection behavior, run: - -```powershell -$env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-app-server --lib map_epiphany_jobs --manifest-path .\vendor\codex\codex-rs\Cargo.toml -``` - -Before modifying freshness reflection behavior, run: - -```powershell -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-freshness-smoke -``` - -Before modifying watcher-backed invalidation behavior inside freshness reflection, run: - -```powershell -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-freshness-smoke -``` +# Epiphany Native Implementation Plan + +This is the live campaign plan. The Codex-fork phase succeeded by starving +Codex of Epiphany authority; Epiphany is no longer implemented as a collection +of app-server routes. + +## Objective + +Build an inspectable native organism whose typed state, runtime, organ gates, +memory, scheduling, interfaces, and social crossings can operate without Codex +owning Epiphany cognition. Retain Codex-derived code only where it provides an +earned OpenAI-compatible authentication or model-transport capability. + +## Current Mechanism + +- `epiphany-state-model` owns durable Mind shape. +- `epiphany-core` owns coordinator policy, state admission, runtime spine, + surfaces, organ gates, heartbeat physiology, Persona loop, and CultMesh + integration. +- Native binaries expose coordinator, status, state, runtime, memory, daemon, + Persona, repo-work, and Verse operations. +- CultCache stores typed state and receipts; CultMesh/CultNet carry typed local + and federated projections. +- Vendored Codex exposes no Epiphany route, DTO, thread-state field, rollout + migration, scheduler, watcher, or bridge crate. + +## Invariants + +1. Mind is the only durable state-admission gateway. +2. Substrate Gate controls access; it does not admit state. +3. Eyes establishes provenance; Hands causes consequences; Soul verifies them. +4. Self coordinates but does not steal another organ's authority. +5. Heartbeat/Idunn own physiology and daemon survival, not project truth. +6. Persona speech and outside-world action preserve consent, identity, + provenance, and private-state seals. +7. CultMesh projections and Eve renderers never become owners. +8. Codex remains free of Epiphany state/process/interface authority. + +## Completed Foundation + +- Native typed thread state and state-update validation. +- Native coordinator facade and derived status/recommendation surfaces. +- CultCache runtime spine with worker, Mind, Eyes, Substrate Gate, Hands, Soul, + Continuity, and coordinator receipts. +- Native OpenAI auth/model/runtime spine. +- Native heartbeat, daemon supervision, and cluster liveness surfaces. +- Native Persona memory/turn/audit machinery and Bifrost-governed public mouths. +- Native repo-work planning, Hands/Soul/Mind closure, public-proof, credit, and + Bifrost accounting families. +- CultMesh local Verse, compact operator readbacks, Gjallar sight, Eve + connection receipts, and three-Verse trust boundaries. +- Complete removal of the Epiphany Codex app-server compatibility surface and + `epiphany-codex-bridge`. + +## Active Campaign + +### 0. Unify Canonical State Transactions + +- Define one transaction owner for canonical state revision changes. +- Make ordinary update, launch, and Mind-witness acceptance call that owner. +- Preserve operation-specific atomic companions: launch runtime envelopes and + acceptance Mind witnesses must commit in the same cache transaction. +- Replace misleading `runtime_spine_store` state writes with an explicit + unified store contract or genuinely separate stores with a typed transaction + coordinator; do not rely on path aliasing by convention. +- Demote raw `thread_state_store` writers to crate-private substrate helpers. + +Exit evidence: + +- one named primitive owns `THREAD_STATE_KEY` writes; +- negative source tests reject direct canonical-state writes elsewhere; +- ordinary update, launch, and acceptance transaction tests pass against the + chosen explicit store contract; +- `EpiphanyCoordinatorService` path names match real ownership. -Before modifying targeted context-shard behavior, run: +### 1. Repair Proprioception + +- Keep `notes/epiphany-current-algorithmic-map.md` aligned with source. +- Distinguish historical evidence from current mechanism in long handoffs. +- Remove live-looking references to deleted bridge/routes from current docs, + prompts, wrapper help, and operator output. +- Add source guards where a removed authority could plausibly regrow. + +Exit evidence: + +- current canonical docs contain no false live paths; +- every mapped owner/file exists; +- source scans show no Epiphany Codex protocol authority. + +### 2. Normalize Native Operator Contracts + +- Audit native JSON artifacts for compatibility-shaped field names and nested + Codex response assumptions. +- Rename only when no external contract depends on the old shape; otherwise + publish a typed migration and explicit expiry. +- Prefer CultCache/CultMesh documents as load-bearing state; keep JSON at CLI, + schema, MCP, OpenAI, and other xenos boundaries. + +Exit evidence: + +- native coordinator/status consumers read native fields directly; +- wrapper summaries are projections, not reconstructed policy; +- no load-bearing JSON sidecar decides behavior. + +### 3. Close The Organ Loop + +- Prove Hands → Soul → Modeling → Mind → Self on a fresh repository without + supervisor implementation or direct worker-thought inspection. +- Ensure every consequence has Substrate Gate scope, Hands receipts, Soul + verdict, Modeling map update, and Mind admission before the next Hands turn. +- Treat no-diff, unreviewable, timeout, and regather outcomes as explicit typed + states rather than success-shaped silence. + +Exit evidence: + +- fresh-repo live-fire closes one nontrivial work item; +- negative tests prove workers/Hands/Soul cannot bypass Mind; +- operator-safe artifacts explain owner, inputs, outputs, and verdicts. + +### 4. Make Physiology Durable + +- Finish Idunn-owned service installation/audit aftercare without moving + elevation authority into Self or wrappers. +- Prove cooldown-after-completion, no overlapping lane heartbeat, idle sleep, + rumination, and recovery across restart. +- Ensure scheduler and liveness receipts remain separate from project state. + +Exit evidence: + +- seven organ daemons survive restart under typed policies; +- complete lifecycle audits close the current elevated-service warning; +- no duplicate daemon keeper exists. + +### 5. Publish Eve/CultUI Interfaces + +- Emit typed Eve composition/state graphs for coordinator, organ status, + receipts, repo work, Persona, and daemon physiology through CultMesh. +- Lower those graphs in Aquarium/browser/TUI without renderer-owned truth. +- Keep private/internal, trusted-local, and public Verse surfaces distinct. -```powershell -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-context-smoke -``` +Exit evidence: + +- one composition graph renders in at least GUI and compact TUI targets; +- commands route back through typed owner intents; +- UI timeline probes observe transition-time invariants. -Before modifying graph traversal behavior, run: +### 6. Prove Federated Work And Social Citizenship -```powershell -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-graph-query-smoke -``` +- Demonstrate a Bifrost-originated work item flowing through Epiphany lanes, + maintainer review, credit/ledger receipts, and operator-safe public proof. +- Demonstrate Persona discussion with semantic memory, consent, disagreement, + and governed external crossing. +- Treat foreign dreams as thought weather until a reviewed adoption receipt. -Before modifying planning state or projection behavior, run: +Exit evidence: -```powershell -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-phase6-planning-smoke -``` +- public proof contains no private worker/operator context; +- Bifrost and Heimdall ownership remains explicit; +- local agency, refusal, exit, and provenance survive federation. -For app-server protocol changes, expect to run the relevant protocol tests, -regenerate stable schema fixtures when needed, and verify the generated tree is -intentional. +## Verification Strategy -Before modifying explicit role launch/read-back behavior, run: +- Unit tests prove local authority and validation. +- Adjacent-organ smokes prove typed handoff. +- Native end-to-end runs prove operator/product contracts. +- Negative source and runtime checks prove old owners cannot regain authority. +- Timeline checks cover load, user/programmatic transition, mid-transition, + settled state, and restart/re-entry where timing matters. +- Served/runtime versions and schema versions are exposed when deployment or + cache uncertainty could impersonate logic failure. -```powershell -$env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-app-server --lib load_epiphany_role_result_reads_heartbeat_runtime_spine_result --manifest-path .\vendor\codex\codex-rs\Cargo.toml -``` +## Cut Line -Before modifying the fixed-lane MVP coordinator endpoint or runner, run: +Delete or demote: -```powershell -cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-mvp-coordinator-smoke -``` +- stale current-looking bridge/route prose; +- compatibility-shaped native code with no external consumer; +- wrapper policy duplicated from Rust owners; +- whole-context serialization where a narrow typed query exists; +- tests whose only purpose is keeping extinct compatibility anatomy alive; +- any cache, registry, adapter, mode, or metadata field without a named + invariant and owner. -On this Windows machine, use: +## Immediate Next Action -```powershell -$env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex' -``` - -Do not parallelize cargo builds or tests against the same target directory. - -## Planning Rule - -When this file changes, prefer replacement and distillation over accretion. - -A good update should usually: - -- remove obsolete phase prose -- preserve the current boundary rules -- name the next larger organ -- move historical proof into evidence or git -- leave the next agent with less to carry, not more +Map and unify the three canonical state transaction writers: +`coordinator_state`, `commit_coordinator_job_launch_in_cache`, and +`commit_state_with_mind_witness`. Decide the explicit store contract before +editing: one unified cache is currently suggested by atomic launch/acceptance +requirements, but the owner and invariant must be named first. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 449da5cf..999c0498 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -9,6 +9,14 @@ exact control flow belongs in `notes/epiphany-current-algorithmic-map.md`; forward campaign planning belongs in `notes/epiphany-fork-implementation-plan.md`. Do not let this file become a second brain. That way lies holy-looking sludge. +Authority boundary: the long record below contains historical campaign strata. +Statements about deleted `thread/epiphany/*` routes, `ThreadEpiphany*` DTOs, +Codex thread-state projection, rollout migration, or +`epiphany-codex-bridge` describe past cuts only. They are not live mechanism or +restoration guidance. For current ownership and flow, trust `state/map.yaml`, +`notes/epiphany-current-algorithmic-map.md`, +`notes/epiphany-fork-implementation-plan.md`, and source at HEAD. + ## Rehydrate From the repo root: diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index e595e4f975b7af4f0ed5462c82e2d553064b8d81..f90ec9ec8ca94591b2e21b2820b7438107aeebbd 100644 GIT binary patch delta 399 zcmYjNy-Gtd6!zBI!LEXKP!70it)dPU!PTvZBDkf=X&XpR()@Vq4LBY1i#;_&4_PQJf9zqFp-TCW>L^YEy<-?{l(YFz)kZx`dD_}PEfq!EG?a;Bo=H2+{JPN{t$%&l)Pf~fa9zKDsUxnn347%b87zrIjfG{ delta 57 zcmbQdNpj74$qf>W+{WfsMy6567}&x(H!Cw1GBVz2p32ldm5C9EK{PWEvj8#c_Nh#4 G;-LT&{t;XN diff --git a/state/map.yaml b/state/map.yaml index d65c9b4f..dd6d6667 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -659,4 +659,4 @@ current_status: - Service lifecycle receipt history is now event-only: `load_epiphany_cultmesh_daemon_service_lifecycle_receipts` filters out the `epiphany-local/daemon-service-lifecycle-receipt/latest` mirror, while `load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt` remains the latest-state reader. Focused unit test `service_lifecycle_receipt_history_excludes_latest_mirror` proves two per-receipt writes return exactly two history records and latest points at the second. Fresh smoke `verse-query-lifecycle-history-filter-smoke` and live overview/triage `local-20260618-145632-497-efac6f0d` / `local-20260618-145632-321-867947af` prove compact swarm sights still expose service lifecycle attention plus the present elevated runbook artifact without daemon pokes or service mutation. Do not use a broad unscoped cargo test filter for this check on Windows; it fans out across bin harnesses and hit a broken pipe during this pass. - `epiphany-verse-query seed-compact` is the compact seed receipt for wrappers and read-only rites. The older `seed` command still prints the full local Verse context for explicit debugging, but compact wrapper modes now avoid full `seed`/final `query` readback after the combined overview proof exposed Windows debug stack overflow from full-context serialization pressure. last_completed_repo_swarm_cut: Huginn live-fire has crossed the first real repo Body from Persona pressure to branch-local Hands commit and Soul/Mind closure, and now has repeatable closure and redacted-public-proof mouths. On `E:\Projects\Huginn` branch `epiphany/huginn/first-awakening`, `tools/epiphany_local_run.ps1 -Mode repo-persona-intake` accepted item `huginn-inspection-readback-livefire`, Weksa/Persona intake remained sealed, and `epiphany-work derive-plan` lowered it to model-authored safe family `repo.status_section` for `README.md` only. `tools/epiphany_local_run.ps1 -Mode repo-swarm-run` advanced four bounded pulses: run-from-plan, adopt-from-plan, execute-from-plan, and close-from-execute. Huginn commit `e9b07c38fceabbdc89ea35c2156326c80c0393a2` updated only `README.md`; closure receipt `.epiphany\work\work-close-huginn-inspection-readback-livefire.json` records status `closed`, Soul verdict `passed`, Mind state commit `repo-work-close-huginn-inspection-readback-livefire-mind-commit`, safe family `repo.status_section`, path scope `README.md`, Bifrost publication gate, and `privateStateExposed=false`. Verification also ran Huginn's TypeScript compiler through concrete Node path: `C:\Program Files\nodejs\node.exe E:\Projects\Huginn\node_modules\typescript\bin\tsc -p tsconfig.json` passed. Native verifier `epiphany-repo-livefire-closure-smoke --workspace E:\Projects\Huginn --item huginn-inspection-readback-livefire --expected-path README.md --expected-family repo.status_section --expected-gate awaiting-publication --expected-blocker bifrost-publication-missing` checks closure receipt, Mind map entry, overview gate/blocker, authority seals, and `git show` changed paths, returning `status=ok`, `soulVerdict=passed`, `publicationGate=Bifrost`, and `privateStateExposed=false`. Wrapper `tools/epiphany_local_run.ps1 -Mode repo-livefire-closure -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exposes the same read-only proof through the local operator mouth; artifact `local-20260621-190156-803-2f85ba15` printed commit, path, gate, blocker, Soul verdict, Mind commit receipt, and `privateStateExposed=False` without push, merge, publication, or target mutation. New wrapper `tools/epiphany_local_run.ps1 -Mode repo-work-public-proof -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exports the redacted proof bundle and repo-local Verse index without publishing; artifact `local-20260621-190645-345-4555b1dc` wrote `.epiphany\public\proof-bundles\repo-work-public-proof-huginn-inspection-readback-livefire.json`, proof id `repo-work-public-proof-huginn-inspection-readback-livefire`, SHA-256 `857545b199f3e37eb06c2e757e5cfc201958e46667bb1f8403fd333a22620f63`, nine artifact rows, zero publication rows, and `privateStateExposed=False`. Gjallar readback `local-20260621-190701-140-b9519ec6` sees the `REPO-WORK-PUBLIC-PROOF` row and action row from Huginn's repo-local Verse with the same SHA-256 while Bifrost publication remains missing. Launcher compact modes are now named compact operator-context modes instead of read-only modes, and `bifrost-public-proof` summaries print item, target public Verse, room, proof SHA-256, review receipts, and credit receipts so publication receipts are auditable without claiming upstream sync. - next_action: Rewrite `notes/epiphany-current-algorithmic-map.md`, which still describes the deleted app-server/bridge architecture, into a source-grounded native pipeline map. Then audit current plans/handoffs for other live-looking references to deleted Codex authority and distinguish historical evidence from current mechanism. + next_action: Map and unify canonical state transaction authority. Ordinary updates write through `coordinator_state`, launches through `commit_coordinator_job_launch_in_cache`, and accepted findings through `commit_state_with_mind_witness`; raw `thread_state_store` writers are public, and launch/acceptance write `THREAD_STATE_KEY` through the path named `runtime_spine_store`. Name the unified store/transaction owner, preserve atomic companion receipts, demote raw writers, and add negative source guards before resuming operator-contract cleanup.