Files
pbakaus_impeccable/crates/live/src/live_status.rs
T
Paul BakausandClaude Fable 5.1 0547ed6a63 reorg C: the open Rust runtime joins this repo as one Cargo workspace
The engine no longer lives in a separate repo. `crates/` is a snapshot of the
open crates (foundation, core, common, context, live, hook, skills, comp,
comp-verbs, html, browser, detect, cli) plus `Cargo.lock`, taken as a git
archive of the engine repo at the commit that finished the boundary split.
None of that repo's history comes with it, and none of it should: the closed
half stays private.

The closed half is the rule engine. It ships as a prebuilt native archive per
target, `libimpeccable_detector.a`, published as a `detector-v<X>` GitHub
Release on this repo. `crates/core/build.rs` resolves and links it three ways:
`IMPECCABLE_DETECTOR_LIB=<dir>` for a local detector build, else the
`~/.impeccable/detector/<version>/<target>/` cache, else a download verified
against its `.sha256` sidecar. `crates/core` is a thin shim over a three-symbol
C ABI; nothing above it knows the boundary exists.

What changed versus the engine repo copy:

- Every crate manifest moves from `license-file.workspace` to
  `license.workspace` (this workspace declares Apache-2.0), and the workspace
  gains the `postcard` dependency the boundary encoding needs.
- The launcher contract test reads `skill/scripts/impeccable{,.cmd}` instead of
  a sibling `launcher/` dir, and `engine_binary` downloads from
  `github.com/pbakaus/impeccable/releases/download/engine-v<version>/` instead
  of the retired dist repo. No oracle golden carried the old URL, so no
  re-recording was owed.
- The tests that hunted for a public repo through `IMPECCABLE_PUBLIC_REPO`,
  `../impeccable-second` or a hardcoded home directory now resolve the root as
  `CARGO_MANIFEST_DIR/../..`, because they are in it. The env var stays as an
  override for an out-of-tree checkout.
- The in-page bundle (`detect-antipatterns-browser.js`, 2 MB of generated wasm
  glue) is no longer tracked. `crates/core/build.rs` resolves it beside the
  archive, hands the path to `impeccable_core::browser::IN_PAGE_BUNDLE_JS`, and
  live mode serves that. `scripts/check-detector-release.mjs` now requires it
  and its `.sha256` in a detector release.
- The live crate embeds `skill/scripts/live-browser*.js` and
  `modern-screenshot.umd.js` directly rather than through vendored copies, so
  the binary and the installed skill cannot drift.
- `crates/browser/assets/` (an unused second copy of the bundle) is gone.
- `tests/lib/engine-bin.mjs` also accepts `target/release/impeccable`, so a
  plain `cargo build --release -p impeccable` is enough to run `bun run test`.

Verified with the archive from a local detector build: `cargo test --workspace`
267 pass, oracle 795 pass / 0 fail / 0 missing, `bun run build` clean, the
default suite green, and the launcher's `engine-probe` handshake answering
through `skill/scripts/impeccable`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vau2X53xGTjjTCXWMVBoNY
2026-09-01 15:31:26 -07:00

147 lines
4.8 KiB
Rust

//! JS: live-status.mjs -> `impeccable live-status`. Durable recovery status,
//! with or without a running helper server.
use crate::live_resume::{
manual_apply_resume_hint, mount_failure_action, render_summary, self_cmd,
};
use crate::paths::read_live_server_info;
use crate::roots::enter_live_root;
use crate::server::fetch_status;
use crate::session::create_live_session_store;
use crate::util::{json_pretty, println};
use impeccable_common::Io;
use serde_json::{json, Map, Value};
pub fn run(args: &[String], io: &mut Io) -> i32 {
let mut argv: Vec<String> = args.to_vec();
if let Err(code) = enter_live_root(&mut argv, io) {
return code;
}
status_cli(io)
}
fn status_cli(io: &mut Io) -> i32 {
let cwd = io.cwd.to_string_lossy().into_owned();
let env = io.env.clone();
let info = read_live_server_info(&cwd, &env).map(|(i, _)| i);
let server: Option<Value> = info
.as_ref()
.and_then(|i| match (i.port, i.token.as_deref()) {
(Some(p), Some(t)) => fetch_status(p, t),
(Some(p), None) => fetch_status(p, "undefined"),
_ => None,
});
let store = create_live_session_store(&cwd, &env, None);
let active: Vec<Value> = store
.list_active_sessions()
.into_iter()
.map(Value::Object)
.collect();
let manual_apply = find_pending_manual_apply(server.as_ref(), &active);
let sessions: Vec<Value> = server
.as_ref()
.and_then(|s| s.get("activeSessions"))
.and_then(|a| a.as_array())
.cloned()
.unwrap_or(active);
let render_failure = sessions
.iter()
.find(|s| s.get("renderState").and_then(|r| r.as_str()) == Some("failed"))
.cloned();
let live_server = server.as_ref().map(|s| {
json!({
"status": s.get("status").cloned().unwrap_or(Value::Null),
"port": s.get("port").cloned().unwrap_or(Value::Null),
"connectedClients": s.get("connectedClients").cloned().unwrap_or(Value::Null),
"agentPolling": s.get("agentPolling").cloned().unwrap_or(Value::Null),
"pendingEvents": s.get("pendingEvents").cloned().unwrap_or(Value::Null),
})
});
// JSON.stringify drops undefined members: strip absent keys.
let live_server = live_server.map(|mut v| {
if let (Some(obj), Some(src)) = (
v.as_object_mut(),
server.as_ref().and_then(|s| s.as_object()),
) {
for k in [
"status",
"port",
"connectedClients",
"agentPolling",
"pendingEvents",
] {
if !src.contains_key(k) {
obj.shift_remove(k);
}
}
}
v
});
let render: Vec<Value> = sessions
.iter()
.map(|s| {
let mut m = Map::new();
m.insert("id".into(), s.get("id").cloned().unwrap_or(Value::Null));
for (k, v) in render_summary(s.as_object()) {
m.insert(k, v);
}
Value::Object(m)
})
.collect();
let hint = recovery_hint(
server.is_some(),
manual_apply.as_ref(),
render_failure.as_ref(),
&self_cmd(io),
);
let payload = json!({
"liveServer": live_server.unwrap_or(Value::Null),
"activeSessions": sessions,
"render": render,
"recoveryHint": hint,
});
println(io, &json_pretty(&payload));
0
}
fn recovery_hint(
server_up: bool,
manual_apply: Option<&Value>,
render_failure: Option<&Value>,
self_cmd: &str,
) -> Value {
if let Some(m) = manual_apply {
return Value::String(manual_apply_resume_hint(m.as_object(), self_cmd));
}
if let Some(r) = render_failure {
return mount_failure_action(r.as_object(), self_cmd)
.map(Value::String)
.unwrap_or(Value::Null);
}
if server_up {
return json!(format!("Run {} live-poll to continue pending work, or {} live-complete --id <session> after manual cleanup.", self_cmd, self_cmd));
}
json!(format!(
"Start {} live-server to requeue pending durable events, then run {} live-poll.",
self_cmd, self_cmd
))
}
fn find_pending_manual_apply(server: Option<&Value>, active: &[Value]) -> Option<Value> {
if let Some(events) = server
.and_then(|s| s.get("pendingEvents"))
.and_then(|p| p.as_array())
{
if let Some(e) = events
.iter()
.find(|e| e.get("type").and_then(|t| t.as_str()) == Some("manual_edit_apply"))
{
return Some(e.clone());
}
}
active
.iter()
.map(|s| s.get("pendingEvent").cloned().unwrap_or(Value::Null))
.find(|e| e.get("type").and_then(|t| t.as_str()) == Some("manual_edit_apply"))
}