mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-21 10:36:27 +03:00
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
107 lines
4.1 KiB
Rust
107 lines
4.1 KiB
Rust
//! Helper-server touchpoints the shared model needs before the server itself
|
|
//! (`live-server`) exists: the identity probe roots resolution runs against a
|
|
//! recorded server, the `/status` and `/poll` calls status/complete make, and
|
|
//! the detached spawn the boot performs.
|
|
|
|
use crate::paths::read_live_server_info;
|
|
use crate::util::Env;
|
|
use serde_json::Value;
|
|
use std::time::{Duration, Instant};
|
|
|
|
/// JS: the `node -e` one-liner in roots.mjs `hasLiveServer`: authenticated
|
|
/// `GET /status?token=` on 127.0.0.1 answering 200 within `timeout_ms`.
|
|
/// Reimplemented natively (no Node spawn).
|
|
pub fn probe_status(port: u16, token: &str, timeout_ms: u64) -> bool {
|
|
let url = format!(
|
|
"http://127.0.0.1:{}/status?token={}",
|
|
port,
|
|
crate::util::encode_uri_component(token)
|
|
);
|
|
let agent = ureq::AgentBuilder::new()
|
|
.timeout_connect(Duration::from_millis(timeout_ms))
|
|
.timeout(Duration::from_millis(timeout_ms))
|
|
.build();
|
|
match agent.get(&url).call() {
|
|
Ok(res) => res.status() == 200,
|
|
Err(_) => false,
|
|
}
|
|
}
|
|
|
|
/// JS: `fetch('http://localhost:PORT/status?token=TOKEN')` then `res.json()`;
|
|
/// None on any failure or non-2xx.
|
|
pub fn fetch_status(port: i64, token: &str) -> Option<Value> {
|
|
let url = format!("http://localhost:{}/status?token={}", port, token);
|
|
let res = ureq::get(&url).call().ok()?;
|
|
if !(200..300).contains(&res.status()) {
|
|
return None;
|
|
}
|
|
res.into_json::<Value>().ok()
|
|
}
|
|
|
|
/// JS: `fetch('http://localhost:PORT/poll', { method: 'POST', body })` then
|
|
/// `res.json()`; None on any failure or non-2xx.
|
|
pub fn post_poll(port: i64, body: &Value) -> Option<Value> {
|
|
let url = format!("http://localhost:{}/poll", port);
|
|
let res = ureq::post(&url)
|
|
.set("Content-Type", "application/json")
|
|
.send_string(&serde_json::to_string(body).unwrap_or_default())
|
|
.ok()?;
|
|
if !(200..300).contains(&res.status()) {
|
|
return None;
|
|
}
|
|
res.into_json::<Value>().ok()
|
|
}
|
|
|
|
/// JS: `runScript('live-server.mjs', ['--background'])` from live.mjs: spawn
|
|
/// the helper detached and return the `{pid, port, token}` record it prints.
|
|
pub fn spawn_detached(cwd: &str, env: &Env) -> Option<Value> {
|
|
spawn_detached_with_args(cwd, env, &[])
|
|
}
|
|
|
|
/// JS: the `--background` branch of live-server.mjs: spawn
|
|
/// `<self> live-server <args>` detached (setsid on unix, DETACHED_PROCESS on
|
|
/// windows) with ignored stdio, then wait up to 10 s for a `server.json`
|
|
/// written by a pid other than ours and return its record.
|
|
pub fn spawn_detached_with_args(cwd: &str, env: &Env, child_args: &[String]) -> Option<Value> {
|
|
let exe = std::env::current_exe().ok()?;
|
|
let mut cmd = std::process::Command::new(&exe);
|
|
cmd.arg("live-server")
|
|
.args(child_args)
|
|
.current_dir(cwd)
|
|
.env_clear()
|
|
.envs(env)
|
|
.stdin(std::process::Stdio::null())
|
|
.stdout(std::process::Stdio::null())
|
|
.stderr(std::process::Stdio::null());
|
|
impeccable_common::proc::detach(&mut cmd);
|
|
let mut child = cmd.spawn().ok()?;
|
|
let own_pid = std::process::id() as i64;
|
|
let deadline = Instant::now() + Duration::from_secs(10);
|
|
let mut result: Option<Value> = None;
|
|
while Instant::now() < deadline {
|
|
if let Some((info, _)) = read_live_server_info(cwd, env) {
|
|
if info.pid != Some(own_pid) {
|
|
result = Some(info.raw);
|
|
break;
|
|
}
|
|
}
|
|
// A child that already exited cannot become ready.
|
|
if let Ok(Some(_)) = child.try_wait() {
|
|
if read_live_server_info(cwd, env).is_none() {
|
|
std::thread::sleep(Duration::from_millis(5));
|
|
if let Some((info, _)) = read_live_server_info(cwd, env) {
|
|
if info.pid != Some(own_pid) {
|
|
result = Some(info.raw);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
std::thread::sleep(Duration::from_millis(5));
|
|
}
|
|
// Detach: never wait on the server (JS `child.unref()`); reap it if it
|
|
// has already exited so no zombie lingers while we finish.
|
|
let _ = child.try_wait();
|
|
result
|
|
}
|