diff --git a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs index eb3e6d14..c4bb3a92 100644 --- a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs +++ b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs @@ -98,6 +98,29 @@ async fn main() -> Result<()> { "output": options.output, }))?; } + "tool-followup-turn" => { + let options = parse_tool_followup_turn_options(args.collect())?; + require_supported_provider(&options.provider)?; + let request = build_tool_followup_model_request( + &options.store_path, + &options.request_id, + &options.followup_request_id, + )?; + let output_last_message_path = options.output_last_message_path.clone(); + let provider = options.provider.clone(); + let runtime_options = options.into_runtime_options_for_model(&request); + let summary = + run_model_turn(&provider, runtime_options.clone(), request.clone()).await?; + if let Some(path) = output_last_message_path { + let text = assistant_text_from_model_events( + &runtime_options.store_path, + &request.request_id, + )?; + fs::write(&path, text) + .with_context(|| format!("failed to write {}", path.display()))?; + } + print_json(&summary)?; + } "smoke" => { let options = parse_smoke_options(args.collect())?; require_supported_provider(&options.provider)?; @@ -246,6 +269,42 @@ struct ToolFollowupCliOptions { output: PathBuf, } +struct ToolFollowupTurnCliOptions { + provider: String, + store_path: PathBuf, + codex_home: PathBuf, + request_id: String, + followup_request_id: String, + session_id: Option, + job_id: Option, + objective: Option, + default_model: Option, + output_last_message_path: Option, +} + +impl ToolFollowupTurnCliOptions { + fn into_runtime_options_for_model( + self, + request: &EpiphanyModelRequest, + ) -> EpiphanyOpenAiRuntimeOptions { + let openai_request = epiphany_openai_runtime::openai_request_from_model_request(request); + let mut options = default_options(self.store_path, self.codex_home, &openai_request); + if let Some(session_id) = self.session_id { + options.session_id = session_id; + } + if let Some(job_id) = self.job_id { + options.job_id = job_id; + } + if let Some(objective) = self.objective { + options.objective = objective; + } + if let Some(default_model) = self.default_model { + options.default_model = Some(default_model); + } + options + } +} + fn parse_model_turn_options(args: Vec) -> Result { let mut provider = DEFAULT_PROVIDER.to_string(); let mut store_path = PathBuf::from(DEFAULT_STORE); @@ -341,6 +400,55 @@ fn parse_tool_followup_options(args: Vec) -> Result) -> Result { + let mut provider = DEFAULT_PROVIDER.to_string(); + let mut store_path = PathBuf::from(DEFAULT_STORE); + let mut codex_home = default_codex_home()?; + let mut request_id = None; + let mut followup_request_id = None; + let mut session_id = None; + let mut job_id = None; + let mut objective = None; + let mut default_model = None; + let mut output_last_message_path = None; + let mut iter = args.into_iter(); + while let Some(arg) = iter.next() { + match arg.as_str() { + "--provider" => provider = next_value(&mut iter, "--provider")?, + "--store" => store_path = PathBuf::from(next_value(&mut iter, "--store")?), + "--codex-home" => codex_home = PathBuf::from(next_value(&mut iter, "--codex-home")?), + "--request-id" => request_id = Some(next_value(&mut iter, "--request-id")?), + "--followup-request-id" => { + followup_request_id = Some(next_value(&mut iter, "--followup-request-id")?) + } + "--session-id" => session_id = Some(next_value(&mut iter, "--session-id")?), + "--job-id" => job_id = Some(next_value(&mut iter, "--job-id")?), + "--objective" => objective = Some(next_value(&mut iter, "--objective")?), + "--default-model" => default_model = Some(next_value(&mut iter, "--default-model")?), + "--output-last-message" => { + output_last_message_path = Some(PathBuf::from(next_value( + &mut iter, + "--output-last-message", + )?)) + } + other => return Err(anyhow!("unknown tool-followup-turn argument: {other}")), + } + } + Ok(ToolFollowupTurnCliOptions { + provider, + store_path, + codex_home, + request_id: request_id.context("tool-followup-turn requires --request-id")?, + followup_request_id: followup_request_id + .unwrap_or_else(|| format!("tool-followup-{}", Uuid::new_v4())), + session_id, + job_id, + objective, + default_model, + output_last_message_path, + }) +} + fn parse_smoke_options(args: Vec) -> Result { let mut provider = DEFAULT_PROVIDER.to_string(); let mut store_path = PathBuf::from(format!( @@ -388,5 +496,5 @@ fn now() -> String { } fn usage() -> &'static str { - "usage: epiphany-model-runtime [--provider openai-codex] [--store path] [--codex-home path] [--request path] [--request-id id] [--followup-request-id id] [--output path] [--session-id id] [--job-id id] [--objective text] [--default-model model] [--output-last-message path]" + "usage: epiphany-model-runtime [--provider openai-codex] [--store path] [--codex-home path] [--request path] [--request-id id] [--followup-request-id id] [--output path] [--session-id id] [--job-id id] [--objective text] [--default-model model] [--output-last-message path]" } diff --git a/epiphany-openai-runtime/src/lib.rs b/epiphany-openai-runtime/src/lib.rs index c853510f..4e55b75f 100644 --- a/epiphany-openai-runtime/src/lib.rs +++ b/epiphany-openai-runtime/src/lib.rs @@ -180,6 +180,21 @@ pub async fn run_model_turn( Ok(summary) } +pub async fn run_tool_followup_model_turn( + provider: &str, + options: EpiphanyOpenAiRuntimeOptions, + original_request_id: &str, + followup_request_id: &str, +) -> Result { + require_openai_provider(provider)?; + let request = build_tool_followup_model_request( + &options.store_path, + original_request_id, + followup_request_id, + )?; + run_model_turn(provider, options, request).await +} + pub async fn run_worker_launch( options: EpiphanyWorkerRuntimeOptions, ) -> Result { diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 9ff221e8..3912e18c 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -40,7 +40,7 @@ remembers doctrine; the branch remembers the blade. - `epiphany-model-runtime` is the current provider-neutral executable boundary. It is built by the `epiphany-openai-runtime` crate for now and accepts `--provider openai-codex`; the old `epiphany-openai-runtime` binary, `--openai-runtime-bin`, and `openai-runtime` executor name survive only as compatibility aliases. Coordinator run mode, local wrapper run mode, and repo birth runner should call `--model-runtime-bin` plus `--model-provider`. The typed request/event/receipt contract is now provider-neutral in `epiphany-model-adapter` as `epiphany.model_request.v0`, `epiphany.model_stream_event.v0`, `epiphany.model_receipt.v0`, and `epiphany.model_adapter_status.v0`; OpenAI/Codex documents are adapter evidence behind that boundary, not scheduler/status/state authority. - Coordinator plan/run passes now emit `epiphany.coordinator_run_receipt.v0` into runtime-spine. `coordinator-summary.json` and `coordinator-steps.jsonl` remain useful operator artifacts, but the durable receipt of what the coordinator decided is typed CultCache/CultNet state. - The first tool/MCP contract surface exists in `epiphany-tool-adapter`: `epiphany.tool_capability.v0`, `epiphany.tool_invocation_intent.v0`, and `epiphany.tool_invocation_receipt.v0`. Runtime-spine advertises these as the Epiphany-facing tool boundary. `epiphany-model-runtime` now materializes complete MCP-shaped model tool calls as typed invocation intents, and `epiphany-tool-codex-mcp-spine` is the quarantined executing adapter: it consumes one typed invocation intent from the mixed runtime-spine CultCache store, calls user-declared Codex MCP through `codex-mcp`, and emits a typed invocation receipt. Raw MCP JSON remains protocol-edge cargo; Codex MCP is transport scaffolding, not Epiphany state, prompt, scheduler, or policy authority. -- Native status now exposes that quarantined bridge spine without granting it authority. `runtime_spine_status` counts tool invocation intents, receipts, and pending calls; `runtime_tool_invocation_statuses` derives read-only intent/receipt status rows; `epiphany-runtime-spine status` reports the counts; and `epiphany-mvp-status --runtime-store ` renders the latest tool calls under `tools`. This is operator visibility only. The model-runtime feedback seam is also now typed: MCP-shaped model tool calls preserve the original provider `call_id` plus source model request id, and `epiphany-model-runtime tool-followup` builds a provider-neutral follow-up `EpiphanyModelRequest` from completed typed tool receipts using the previous provider response id. Codex still executes the quarantined MCP edge; Epiphany owns the continuation request shape. +- Native status now exposes that quarantined bridge spine without granting it authority. `runtime_spine_status` counts tool invocation intents, receipts, and pending calls; `runtime_tool_invocation_statuses` derives read-only intent/receipt status rows; `epiphany-runtime-spine status` reports the counts; and `epiphany-mvp-status --runtime-store ` renders the latest tool calls under `tools`. This is operator visibility only. The model-runtime feedback seam is also now typed: MCP-shaped model tool calls preserve the original provider `call_id` plus source model request id; `epiphany-model-runtime tool-followup` builds a provider-neutral follow-up `EpiphanyModelRequest` from completed typed tool receipts using the previous provider response id; and `epiphany-model-runtime tool-followup-turn` derives and runs that continuation through the selected provider in one runtime-owned operation. Codex still executes the quarantined MCP edge; Epiphany owns the continuation request shape and invocation boundary. - The active foundation directive is now `notes/codex-starvation-and-cultnet-liberation-plan.md`. The previous Codex app-server control-plane rebuild made Epiphany less rotten inside Codex, but that is not the destination. Epiphany must become a native CultCache/CultMesh/CultNet runtime while remaining an honest modified Codex-derived backend for subscription auth/model use. Codex should remain relatively vanilla and keep doing Codex things, including useful app-server and streaming bridge affordances, but it must not own Epiphany state, processes, prompts, scheduler decisions, or policy. The bridge handles interop; Codex and Epiphany do not get to rummage around in each other's organs. - `notes/epiphany-cultmesh-dreaming-roadmap.md` is the new concrete design for distributed Epiphany dreaming. The invariant is hard: private state stays local; public dreams are separately authored typed documents distributed through CultMesh/CultNet; foreign dreams are thought weather until a reviewed local adoption receipt digests them. The first code slice should be dream schemas plus a local CultMesh-backed store, not public fanout. - CultMesh is now the preferred Rust abstraction for that local store work. The compile-time Rust substrate is repo-contained: `vendor/cultcache-rs`, `vendor/cultnet-rs`, and `vendor/cultmesh-rs`. The old `E:\Projects\CultLib\crates\*` dependency body is dead in this checkout and must not be revived by accident. Vendored CultCache reads/writes `cultcache.store.v1`, so `state/ledgers.msgpack` and `epiphany-state status` are aligned again. The first integrations are deliberately small: status, Verse policy, global room policy, organ contract policy, native operator status, native operator snapshots, and local operator run intent/receipt round-trip through CultMesh. Use `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-cultmesh-smoke`, `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-cultmesh-status -- smoke --store .\.epiphany-smoke\cultmesh\operator-status.ccmp --runtime-id epiphany-cultmesh-status-smoke`, `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-operator-snapshot -- smoke --store .\.epiphany-smoke\cultmesh\operator-snapshots.ccmp --runtime-id epiphany-operator-snapshot-smoke --snapshot-id smoke-status`, and `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-operator-run -- smoke --store .\.epiphany-smoke\cultmesh\operator-runs.ccmp --runtime-id epiphany-operator-run-smoke --run-id smoke-run` for the focused proofs. Future local dream/status/Verse work should start from CultMesh, not raw CultNet, unless the task is polishing the CultMesh internals themselves. Preserve the three Verse tiers: `epiphany-internal` for private sub-agent typed state, `gamecult-local` for trusted LAN/Yggdrasil-tunnel GameCult sharing, and `epiphany-global` for untrusted public dreams plus topic-specific threaded public rooms for Face posts. @@ -183,7 +183,7 @@ remembers doctrine; the branch remembers the blade. - The planning loop is now runtime-backed and operator-visible. Typed captures, backlog items, roadmap streams, Objective Drafts, and GitHub issue source refs live in `EpiphanyThreadState`, validate through revision-gated `thread/epiphany/update`, render into prompts when present, project read-only through the `planning` view lens, render in the GUI Planning panel, can be synthesized by the fixed Imagination/planning lane, and can be explicitly adopted through the artifacted `adoptObjectiveDraft` GUI action. Chat is deliberation, not an objective pipe; ideas and GitHub Issues remain planning state until explicit human adoption. - The bridge/dashboard slice is now landed far enough to test locally. Native `epiphany-rider-bridge` inspects Rider installation, solution, VCS, changed files, and captures file/selection/symbol context into `.epiphany-gui/rider` artifacts; Aquarium has Inspect Rider and renders Rider audit artifacts in Environment; Aquarium also embeds the adjacent EpiphanyGraph viewer over typed `graphs.architecture`, `graphs.dataflow`, and `graphs.links`. - A first Rider plugin scaffold lives under `integrations/rider`: tool window, Refresh status, and Send Context to Epiphany action. It shells through native `epiphany-rider-bridge` and does not own state. `gradle` is not installed on this machine, so the scaffold is not build-verified yet. -- Next real move: continue Codex starvation and native Epiphany ownership by making the coordinator/runtime loop consume the typed `tool-followup` request instead of requiring the operator to run the three commands manually. Quarantine Rider/Unity bridge work for now; those artifacts remain optional later environment evidence, not MVP blockers. Keep EpiphanyAgent focused on backend contracts, typed state, coordinator policy, heartbeat scheduling, Face guardrails, prompt-authority separation, and the ongoing purification from Python/JSON scaffolding into Rust/CultCache/CultMesh/CultNet organs. Resume repo birth/Aquarium/Rider/Unity work only when the user explicitly shifts priority back outward. GitHub Issues import is deferred until the backlog source is fresh enough to deserve Imagination's attention. +- Next real move: continue Codex starvation and native Epiphany ownership by letting the coordinator choose and invoke the `tool-followup-turn` primitive when pending tool receipts make continuation appropriate. Quarantine Rider/Unity bridge work for now; those artifacts remain optional later environment evidence, not MVP blockers. Keep EpiphanyAgent focused on backend contracts, typed state, coordinator policy, heartbeat scheduling, Face guardrails, prompt-authority separation, and the ongoing purification from Python/JSON scaffolding into Rust/CultCache/CultMesh/CultNet organs. Resume repo birth/Aquarium/Rider/Unity work only when the user explicitly shifts priority back outward. GitHub Issues import is deferred until the backlog source is fresh enough to deserve Imagination's attention. - The repo is an Epiphany fork of Codex, not a Codex preset. - `vendor/codex` is tracked directly, not a submodule. - `epiphany-core` owns the heavy Epiphany organs where practical. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index b8ed5242..671ed9c8 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index 5bd393b8..b616594d 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -72,7 +72,7 @@ active_subgoals: - Use `notes/epiphany-cultmesh-dreaming-roadmap.md` as the design authority for distributed Epiphany dreaming. Public dreams are separately authored typed documents distributed through CultMesh/CultNet; private state remains local and cannot be shared by flipping a visibility flag. Foreign dreams are external thought weather until a reviewed local adoption receipt digests them into memory, planning, doctrine, or governance. - CultMesh is now the preferred ergonomic Rust abstraction over CultCache and CultNet for Epiphany-owned local database surfaces. The Rust substrate is repo-contained under `vendor/cultcache-rs`, `vendor/cultnet-rs`, and `vendor/cultmesh-rs`; the old `E:\Projects\CultLib\crates\*` path is dead in this checkout and must not be reintroduced as a compile-time dependency. Future local Verse/dream/status work should start at CultMesh unless it is explicitly polishing CultMesh internals. Preserve the three-Verse boundary: `epiphany-internal` for private sub-agent typed state, `gamecult-local` for trusted LAN/Yggdrasil-tunnel GameCult project sharing, and `epiphany-global` for untrusted public dreams plus topic-specific threaded public rooms for Face posts. - The active priority is Codex starvation and CultNet liberation. Use `notes/codex-starvation-and-cultnet-liberation-plan.md` as the directive and `notes/codex-auth-spine-inventory.md` as the source-grounded keeper list for the retained OpenAI subscription auth/model transport bridge. Classify all Epiphany-relevant JSON contamination, define the native CultNet runtime boundary, keep worker launch/result/selfPatch cargo as typed documents, evacuate Epiphany operator/state/process authority from Codex JSON-RPC, wrap MCP's unavoidable JSON protocol edge in typed Epiphany intent/result/receipt documents, and keep cutting until Epiphany can run its own state and processes without `codex_message_processor.rs` except for bridge compatibility. - - The next Codex-starvation slice is automatic coordinator/runtime consumption of typed tool-result follow-up requests. The quarantined Codex MCP spine may execute typed tool intents and emit typed receipts, and the model runtime can now build a provider-neutral follow-up request from those receipts, but the coordinator still needs to own when that follow-up turn runs. Codex transports tool calls; it must not inject prompt doctrine or decide what Epiphany agents do with tool results. + - The next Codex-starvation slice is coordinator policy for typed tool-result follow-up turns. The quarantined Codex MCP spine may execute typed tool intents and emit typed receipts, and the model runtime can now build and run a provider-neutral follow-up turn from those receipts, but the coordinator still needs to own when that primitive is invoked. Codex transports tool calls; it must not inject prompt doctrine or decide what Epiphany agents do with tool results. - The May 2026 teardown/rebuild migration in `notes/epiphany-ideal-architecture-rebuild-plan.md` is closed unless a concrete regression reopens it. Preserve the new foundation: Epiphany view/coordinator policy lives in `epiphany-core`, runtime-spine owns job/result lifecycle identity through `runtime_links`, duplicate acceptance is receipt-keyed, public findings stay typed/sealed, view expansion requires a core contract, and app-server remains routing/adaptation rather than a second policy throne. - Treat Phase 5 update/distill/propose/promote/read/notification as complete enough unless a concrete regression appears. - Preserve read-only boundaries for retrieve, distill, propose, freshness, context, graphQuery, roleResult, reorientResult, and the canonical view lenses for scene, jobs, roles, planning, pressure, reorient, crrc, and coordinator. @@ -177,7 +177,7 @@ accepted_design: - Pre-compaction checkpoint intervention is now wired at token-count boundaries: when a loaded Epiphany thread crosses the existing `shouldPrepareCompaction` pressure threshold during an active turn, the harness steers the active agent once for that turn with a bounded CRRC directive to bank scratch/checkpoint/map/evidence before compaction/reorientation. A successful steer marks a turn-scoped pending compact handoff consumed at clean turn completion; this is banking the fire before the dark, not semantic acceptance, broad scheduling, or automatic implementation continuation. - Native `epiphany-mvp-status` is the first dogfood operator view: it starts or reads a thread through app-server and renders scene, planning, pressure, reorient, jobs, role result read-backs, reorient result, CRRC recommendation, heartbeat, Face bubbles, and MVP role lanes as text or machine output without becoming a state store. The old Python status module has been cut; native Rust/CultCache/CultNet surfaces are the product path. - Native status now exposes the quarantined tool/MCP spine as operator-visible read-only state. Runtime-spine counts typed tool invocation intents, receipts, and pending calls; `runtime_tool_invocation_statuses` derives intent/receipt status rows; `epiphany-runtime-spine status` prints the counts; and `epiphany-mvp-status --runtime-store ` renders a `tools` section without executing calls, accepting results, or letting Codex prompt machinery steer Epiphany agents. - - Model-tool feedback now has a typed continuation seam. `EpiphanyToolInvocationIntent` preserves the exact model `call_id` plus source model request id; provider-neutral and OpenAI request documents carry optional `previous_response_id`; the OpenAI Responses mapper emits that id as `previous_response_id`; and `epiphany-model-runtime tool-followup` builds a provider-neutral follow-up request from typed tool receipts. The manual smoke path is model-runtime smoke -> quarantined Codex MCP spine run -> model-runtime `tool-followup`; the next organ is coordinator ownership of that sequence. + - Model-tool feedback now has a typed continuation seam. `EpiphanyToolInvocationIntent` preserves the exact model `call_id` plus source model request id; provider-neutral and OpenAI request documents carry optional `previous_response_id`; the OpenAI Responses mapper emits that id as `previous_response_id`; `epiphany-model-runtime tool-followup` builds a provider-neutral follow-up request from typed tool receipts; and `epiphany-model-runtime tool-followup-turn` derives and runs that continuation through the selected provider in one runtime-owned call. The manual smoke path is model-runtime smoke -> quarantined Codex MCP spine run -> model-runtime `tool-followup`; the next organ is coordinator ownership of `tool-followup-turn`. - The `roles` view lens is the harness-native role ownership surface: it projects implementation, Imagination/planning, modeling/checkpoint, verification/review, and reorientation lanes from authoritative typed state, bound jobs, pressure/reorient/CRRC, and worker result status without launching, scheduling, accepting, compacting, or mutating state. - `thread/epiphany/roleLaunch` and `thread/epiphany/roleResult` are the first explicit role-scoped specialist templates: Imagination/planning, modeling/checkpoint, and verification/review launch through fixed heartbeat-backed bindings with typed runtime-spine receipts and can be read back as reviewable findings from typed runtime-spine job results, while implementation stays owned by the main coding agent and reorientation stays on the CRRC-specific launch/result path. - `thread/epiphany/roleAccept` is the first review-gated role finding acceptance path: it accepts completed heartbeat-backed findings from typed runtime-spine results, accepts Imagination/planning findings only when they return a valid planning-only `statePatch` with draft Objective Draft review gates, accepts completed modeling/checkpoint findings only with a modeling-safe `statePatch`, builds accepted evidence/observation/receipt bundles through `epiphany-core`, and rejects verification, implementation, reorientation, job binding, objective adoption, or broad authority fields. @@ -553,4 +553,4 @@ current_status: materializes complete MCP-shaped model tool calls as typed tool invocation intents, and the Codex MCP spine can consume those intents from the mixed runtime-spine store and emit typed success/failure receipts. - next_action: Continue Codex starvation and CultNet liberation by making the coordinator/runtime loop consume the typed tool-followup request path automatically, preserving Epiphany-owned continuation policy while Codex remains only auth/model/MCP transport. + next_action: Continue Codex starvation and CultNet liberation by teaching the coordinator when to invoke the typed `tool-followup-turn` runtime primitive, preserving Epiphany-owned continuation policy while Codex remains only auth/model/MCP transport.