diff --git a/epiphany-core/src/bin/epiphany-daemon-supervisor.rs b/epiphany-core/src/bin/epiphany-daemon-supervisor.rs index e0b1c37c..8ec41027 100644 --- a/epiphany-core/src/bin/epiphany-daemon-supervisor.rs +++ b/epiphany-core/src/bin/epiphany-daemon-supervisor.rs @@ -14,6 +14,7 @@ use epiphany_core::EpiphanyCultMeshManagedServicePolicyEntry; use epiphany_core::EpiphanyCultMeshSwarmBrakeEntry; use epiphany_core::EpiphanyCultMeshDaemonStatusEntry; use epiphany_core::EpiphanyLocalVerseContext; +use epiphany_core::EpiphanyProcessObservation as ProcessObservation; use epiphany_core::EpiphanyServiceExecutionAuditReport; use epiphany_core::epiphany_cluster_service_execution_audit_report; use epiphany_core::epiphany_cultmesh_daemon_poke_intent_from_status; @@ -24,6 +25,7 @@ use epiphany_core::load_epiphany_cultmesh_daemon_service_lifecycle_receipts; use epiphany_core::load_epiphany_cultmesh_managed_service_policy; use epiphany_core::load_epiphany_cultmesh_managed_service_policies; use epiphany_core::load_epiphany_cultmesh_swarm_brake; +use epiphany_core::observe_native_process as observe_process; use epiphany_core::query_epiphany_local_verse_context; use epiphany_core::seed_epiphany_local_verse_context; use epiphany_core::write_epiphany_cultmesh_daemon_poke_intent; @@ -573,66 +575,6 @@ fn managed_service_reconcile(mut args: Args) -> Result<()> { service_launch(args) } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum ProcessObservation { - Alive, - Dead, - Missing, -} - -impl ProcessObservation { - fn label(self) -> &'static str { - match self { - Self::Alive => "alive", - Self::Dead => "dead", - Self::Missing => "missing", - } - } -} - -#[cfg(windows)] -fn observe_process(process_id: u32) -> Result { - use windows_sys::Win32::Foundation::CloseHandle; - use windows_sys::Win32::System::Threading::{ - GetExitCodeProcess, OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION, - }; - const STILL_ACTIVE: u32 = 259; - unsafe { - let handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, process_id); - if handle.is_null() { - return Ok(ProcessObservation::Dead); - } - let mut exit_code = 0_u32; - let read = GetExitCodeProcess(handle, &mut exit_code); - CloseHandle(handle); - if read == 0 { - anyhow::bail!("failed to inspect managed service process {process_id}"); - } - Ok(if exit_code == STILL_ACTIVE { - ProcessObservation::Alive - } else { - ProcessObservation::Dead - }) - } -} - -#[cfg(unix)] -fn observe_process(process_id: u32) -> Result { - let result = unsafe { libc::kill(process_id as i32, 0) }; - if result == 0 { - Ok(ProcessObservation::Alive) - } else { - let error = std::io::Error::last_os_error(); - if error.raw_os_error() == Some(libc::ESRCH) { - Ok(ProcessObservation::Dead) - } else if error.raw_os_error() == Some(libc::EPERM) { - Ok(ProcessObservation::Alive) - } else { - Err(error.into()) - } - } -} - fn service_runbook(args: Args) -> Result<()> { seed_epiphany_local_verse_context( &args.store, diff --git a/epiphany-core/src/bin/epiphany-verse-query.rs b/epiphany-core/src/bin/epiphany-verse-query.rs index 4b5bb616..2f5302a7 100644 --- a/epiphany-core/src/bin/epiphany-verse-query.rs +++ b/epiphany-core/src/bin/epiphany-verse-query.rs @@ -20,6 +20,7 @@ use epiphany_core::EpiphanyCultMeshClusterTopologyEntry; use epiphany_core::EpiphanyCultMeshDaemonPokeReceiptEntry; use epiphany_core::EpiphanyCultMeshDaemonRestartPolicyEntry; use epiphany_core::EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry; +use epiphany_core::EpiphanyCultMeshManagedServicePolicyEntry; use epiphany_core::EpiphanyCultMeshDaemonStatusEntry; use epiphany_core::EpiphanyCultMeshDaemonToolCapabilityEntry; use epiphany_core::EpiphanyCultMeshEveSurfaceStateEntry; @@ -60,6 +61,7 @@ use epiphany_core::load_epiphany_cultmesh_cluster_topology; use epiphany_core::load_epiphany_cultmesh_daemon_liveness; use epiphany_core::load_epiphany_cultmesh_daemon_restart_policy_directory; use epiphany_core::load_epiphany_cultmesh_daemon_service_lifecycle_receipts; +use epiphany_core::load_epiphany_cultmesh_managed_service_policies; use epiphany_core::load_epiphany_cultmesh_daemon_tool_directory; use epiphany_core::load_epiphany_cultmesh_eve_surface_directory; use epiphany_core::load_epiphany_cultmesh_repo_work_map_entries; @@ -90,6 +92,7 @@ use epiphany_core::load_latest_epiphany_cultmesh_repo_work_public_proof; use epiphany_core::load_latest_epiphany_cultmesh_repo_work_readiness; use epiphany_core::load_latest_epiphany_cultmesh_repo_work_readiness_review; use epiphany_core::open_epiphany_cultmesh_node; +use epiphany_core::observe_native_process; use epiphany_core::query_epiphany_local_verse_context; use epiphany_core::seed_epiphany_local_verse_context; use epiphany_core::write_epiphany_cultmesh_agent_state_soa_summary; @@ -386,6 +389,21 @@ fn run_cli() -> Result<()> { }))? ); } + "managed-services" | "gjallar-managed-services" | "idunn-services" => { + let report = managed_service_sight_report(&args.store, &args.runtime_id)?; + println!("{}", serde_json::to_string_pretty(&json!({ + "schemaVersion": "epiphany.cultmesh.managed_service_sight.v0", + "status": report.status, + "owner": "Gjallar", + "lifecycleOwner": "Idunn", + "serviceCount": report.rows.len(), + "aliveCount": report.alive_count, + "attentionCount": report.attention_count, + "rows": report.rows, + "tuiRows": report.tui_rows, + "privateStateExposed": false, + }))?); + } "tools" | "tool-directory" => { seed_epiphany_local_verse_context( &args.store, @@ -4393,6 +4411,117 @@ struct DaemonToolDirectoryReport { host_attention_count: usize, } +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +struct ManagedServiceSightReport { + status: String, + alive_count: usize, + attention_count: usize, + rows: Vec, + tui_rows: Vec, +} + +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +struct ManagedServiceSightRow { + service_id: String, + owner_daemon_id: String, + enabled: bool, + restart_mode: String, + process_observation: String, + process_id: Option, + lifecycle_receipt_id: Option, + lifecycle_status: Option, + last_pulse_status: Option, + last_pulse_iteration: Option, + last_pulse_artifact: Option, + private_state_exposed: bool, +} + +fn managed_service_sight_report( + store: &std::path::Path, + runtime_id: &str, +) -> Result { + let policies = load_epiphany_cultmesh_managed_service_policies(store, runtime_id.to_string())?; + let lifecycle = load_epiphany_cultmesh_daemon_service_lifecycle_receipts( + store, + runtime_id.to_string(), + )?; + let mut rows = Vec::new(); + for policy in policies { + let latest = lifecycle + .iter() + .filter(|receipt| receipt.service_id == policy.service_id) + .max_by(|left, right| left.started_at_utc.cmp(&right.started_at_utc)); + let process_id = latest.and_then(|receipt| receipt.process_id); + let process_observation = process_id + .map(observe_native_process) + .transpose()? + .map(|observation| observation.label().to_string()) + .unwrap_or_else(|| "missing".to_string()); + let pulse = compact_last_service_pulse(&policy); + rows.push(ManagedServiceSightRow { + service_id: policy.service_id, + owner_daemon_id: policy.owner_daemon_id, + enabled: policy.enabled, + restart_mode: policy.restart_mode, + process_observation, + process_id, + lifecycle_receipt_id: latest.map(|receipt| receipt.receipt_id.clone()), + lifecycle_status: latest.map(|receipt| receipt.status.clone()), + last_pulse_status: pulse.as_ref().and_then(|value| value["status"].as_str()).map(str::to_string), + last_pulse_iteration: pulse.as_ref().and_then(|value| value["iteration"].as_u64()), + last_pulse_artifact: pulse + .as_ref() + .and_then(|value| value["routineArtifact"].as_str()) + .map(str::to_string), + private_state_exposed: false, + }); + } + rows.sort_by(|left, right| left.service_id.cmp(&right.service_id)); + let alive_count = rows + .iter() + .filter(|row| row.process_observation == "alive") + .count(); + let attention_count = rows + .iter() + .filter(|row| row.enabled && row.process_observation != "alive") + .count(); + let tui_rows = rows + .iter() + .map(|row| { + format!( + "{} | service={} | owner={} | desired={} | restart={} | observed={} | pid={} | lifecycle={} | pulse={} | iteration={} | private=false", + if row.enabled && row.process_observation == "alive" { "READY" } else { "ATTN" }, + row.service_id, + row.owner_daemon_id, + if row.enabled { "enabled" } else { "disabled" }, + row.restart_mode, + row.process_observation, + row.process_id.map(|value| value.to_string()).unwrap_or_else(|| "none".to_string()), + row.lifecycle_receipt_id.as_deref().unwrap_or("none"), + row.last_pulse_status.as_deref().unwrap_or("none"), + row.last_pulse_iteration.map(|value| value.to_string()).unwrap_or_else(|| "none".to_string()), + ) + }) + .collect(); + Ok(ManagedServiceSightReport { + status: if attention_count == 0 { "ready" } else { "attention" }.to_string(), + alive_count, + attention_count, + rows, + tui_rows, + }) +} + +fn compact_last_service_pulse(policy: &EpiphanyCultMeshManagedServicePolicyEntry) -> Option { + let text = fs::read_to_string(&policy.stdout_artifact).ok()?; + text.lines() + .rev() + .filter_map(|line| serde_json::from_str::(line).ok()) + .find(|value| value["schemaVersion"] == "epiphany.heartbeat.serve_pulse.v0") +} + struct DaemonRestartPolicyDirectoryReport { status: String, lifecycle_owner: String, diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 97d5d36f..9804c530 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -23,6 +23,7 @@ mod persona_memory_cache; mod persona_turn; mod promotion; mod prompt_context; +mod process_observation; mod proposal; mod retrieval; mod runtime_spine; @@ -671,6 +672,8 @@ pub use modeling_gateway::RepoWorkMapEntry; pub use modeling_gateway::RepoWorkModelingFinding; pub use modeling_gateway::RepoWorkModelingRequest; pub use modeling_gateway::RepoWorkModelingRoute; +pub use process_observation::EpiphanyProcessObservation; +pub use process_observation::observe_native_process; pub use organ_dependencies::EPIPHANY_LAUNCH_ORGAN_CONTRACT_SCHEMA_VERSION; pub use organ_dependencies::EPIPHANY_ORGAN_DEPENDENCY_SCHEMA_VERSION; pub use organ_dependencies::EPIPHANY_STANDING_ORGANS; diff --git a/epiphany-core/src/process_observation.rs b/epiphany-core/src/process_observation.rs new file mode 100644 index 00000000..de0f214e --- /dev/null +++ b/epiphany-core/src/process_observation.rs @@ -0,0 +1,61 @@ +use anyhow::Result; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum EpiphanyProcessObservation { + Alive, + Dead, + Missing, +} + +impl EpiphanyProcessObservation { + pub fn label(self) -> &'static str { + match self { + Self::Alive => "alive", + Self::Dead => "dead", + Self::Missing => "missing", + } + } +} + +#[cfg(windows)] +pub fn observe_native_process(process_id: u32) -> Result { + use windows_sys::Win32::Foundation::CloseHandle; + use windows_sys::Win32::System::Threading::{ + GetExitCodeProcess, OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION, + }; + const STILL_ACTIVE: u32 = 259; + unsafe { + let handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, process_id); + if handle.is_null() { + return Ok(EpiphanyProcessObservation::Dead); + } + let mut exit_code = 0_u32; + let read = GetExitCodeProcess(handle, &mut exit_code); + CloseHandle(handle); + if read == 0 { + anyhow::bail!("failed to inspect managed service process {process_id}"); + } + Ok(if exit_code == STILL_ACTIVE { + EpiphanyProcessObservation::Alive + } else { + EpiphanyProcessObservation::Dead + }) + } +} + +#[cfg(unix)] +pub fn observe_native_process(process_id: u32) -> Result { + let result = unsafe { libc::kill(process_id as i32, 0) }; + if result == 0 { + Ok(EpiphanyProcessObservation::Alive) + } else { + let error = std::io::Error::last_os_error(); + if error.raw_os_error() == Some(libc::ESRCH) { + Ok(EpiphanyProcessObservation::Dead) + } else if error.raw_os_error() == Some(libc::EPERM) { + Ok(EpiphanyProcessObservation::Alive) + } else { + Err(error.into()) + } + } +} diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 4bb2b73a..bd65b0c9 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -398,6 +398,16 @@ death the next pulse launched PID `40532` under unique receipt `daemon-service-lifecycle-receipt-idunn-managed-heartbeat-launch-1783859054234`. The next boundary is Gjallar/Eve sight over managed service desired/observed state. +That first sight boundary is now implemented. `observe_native_process` moved +from the supervisor binary into a shared narrow core organ. Query aliases +`managed-services`, `gjallar-managed-services`, and `idunn-services` join typed +service policy with latest lifecycle history and native observation, then read +only the compact heartbeat serve pulse line from the sealed stdout artifact. +Live row PID `25236` transitioned from `READY/alive` to `ATTN/dead` while +retaining pulse `completed`, iteration `1`, and lifecycle receipt +`daemon-service-lifecycle-receipt-idunn-managed-heartbeat-launch-1783859373793`. +No command args or routine payloads are projected. Next merge these rows into +the main Gjallar/Eve composition rather than keeping a specialist query only. 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/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 6da637f9..3f2ed4fd 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -2241,6 +2241,17 @@ unique receipt The same heartbeat store survived and no child remains running. Next expose compact managed-service policy/lifecycle/process rows through Gjallar/Eve so operators can see Idunn physiology without invoking the supervisor CLI. +The specialist Gjallar sight is landed. Native PID observation is shared from +`epiphany-core::process_observation`; `epiphany-verse-query +gjallar-managed-services` projects policy, latest lifecycle, live/dead/missing, +PID, and compact last heartbeat pulse fields with no command args or routine +payloads. In live root +`C:\Users\Meta\AppData\Local\Temp\epiphany-idunn-unattended-3394ecfaa03f41d8935f9fb70411ca75`, +PID `25236` first rendered READY/alive with pulse completed and later ATTN/dead +after forced termination, using lifecycle receipt +`daemon-service-lifecycle-receipt-idunn-managed-heartbeat-launch-1783859373793`. +No child remains. Next lower this row family into the main Gjallar/Eve +composition graph and its advertised command/readback surface. ## Immediate Re-entry Instruction diff --git a/notes/perfect-machine-audit-roadmap.md b/notes/perfect-machine-audit-roadmap.md index 3bcf8078..8a137c6e 100644 --- a/notes/perfect-machine-audit-roadmap.md +++ b/notes/perfect-machine-audit-roadmap.md @@ -171,6 +171,15 @@ Idunn pulse restarted it from the same store with a distinct PID and immutable lifecycle receipt. The next gap is inspectability: publish compact managed service desired/observed rows through Gjallar/Eve without opening command payloads or routine artifacts. +The first sight organ is landed as `epiphany-verse-query +gjallar-managed-services`. Native process observation now lives in a shared +core module used by both Idunn reconciliation and Gjallar projection. Rows show +desired enabled/restart mode, observed alive/dead/missing, PID, latest immutable +lifecycle receipt, compact last heartbeat pulse status/iteration/artifact, and +the private-state seal. Live proof transitioned the same row from READY/alive +to ATTN/dead after a forced process death without exposing command args or +routine payloads. Next lower this typed row family into the main Gjallar/Eve +composition graph. ### Forbidden writers diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index a9a943af..6c7a1bcb 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index ea7ae01a..1f8ed4a7 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: Make Idunn managed-service physiology visible through the organism's interface layer. Add compact Gjallar/Eve managed-service rows from typed policy plus latest lifecycle plus native process observation, showing desired enabled/restart mode, observed alive/dead/missing, last receipt, heartbeat pulse artifact/status, and private-state seal without exposing command arguments or routine payloads. + next_action: Lower the proven managed-service sight rows into the main Gjallar/Eve composition graph. Reuse the typed `gjallar-managed-services` projection, advertise the readback/Idunn reconcile command through provider-owned Eve state, include READY/ATTN rows in global sight without duplicating policy, and prove browser/TUI lowering sees heartbeat alive/dead transitions with no command args, routine payloads, or private state.