mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-21 02:26:31 +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
67 lines
2.4 KiB
Rust
67 lines
2.4 KiB
Rust
//! JS: lib/artifact-schema.mjs
|
|
|
|
use once_cell::sync::Lazy;
|
|
use regex::Regex;
|
|
|
|
pub const PRODUCT_SCHEMA_VERSION: i64 = 1;
|
|
pub const DESIGN_SIDECAR_SCHEMA_VERSION: i64 = 2;
|
|
pub const PRODUCT_V4_SECTIONS: [&str; 4] = ["Positioning", "Operating Context", "Evidence on Hand", "Product Principles"];
|
|
pub const PRODUCT_DEPRECATED_SECTIONS: [(&str, &str); 1] = [(
|
|
"Register",
|
|
"v4 replaced the brand/product register axis with the four visitor modes (Persuade, Operate, Read, Experience), which are chosen per surface and persisted in that surface's brief. Nothing reads `## Register` any more.",
|
|
)];
|
|
|
|
static PRODUCT_STAMP_RE: Lazy<Regex> =
|
|
Lazy::new(|| Regex::new(r"(?im)^[ \t]*<!--[ \t]*impeccable:product-schema[ \t]+(\d+)[ \t]*-->[ \t]*$").unwrap());
|
|
|
|
pub fn product_stamp_line(version: i64) -> String {
|
|
format!("<!-- impeccable:product-schema {} -->", version)
|
|
}
|
|
|
|
/// JS: readProductSchemaVersion
|
|
pub fn read_product_schema_version(markdown: &str) -> Option<i64> {
|
|
let m = PRODUCT_STAMP_RE.captures(markdown)?;
|
|
// parseInt of digits: may overflow -> JS gives a big float; treat as integer if parses
|
|
m[1].parse::<i64>().ok()
|
|
}
|
|
|
|
/// JS: stampProductSchema
|
|
pub fn stamp_product_schema(markdown: &str, version: i64) -> String {
|
|
let line = product_stamp_line(version);
|
|
if PRODUCT_STAMP_RE.is_match(markdown) {
|
|
// JS: replace first match only (no g flag)
|
|
return PRODUCT_STAMP_RE.replacen(markdown, 1, line.as_str()).into_owned();
|
|
}
|
|
let mut lines: Vec<String> = markdown.split('\n').map(|s| s.to_string()).collect();
|
|
let heading = lines.iter().position(|l| is_h1(l));
|
|
match heading {
|
|
None => format!("{}\n\n{}", line, markdown.trim_start_matches('\n')),
|
|
Some(i) => {
|
|
lines.insert(i + 1, String::new());
|
|
lines.insert(i + 2, line);
|
|
lines.join("\n")
|
|
}
|
|
}
|
|
}
|
|
|
|
fn is_h1(l: &str) -> bool {
|
|
// /^#\s+\S/
|
|
let Some(rest) = l.strip_prefix('#') else { return false };
|
|
let trimmed = rest.trim_start_matches(|c: char| c.is_whitespace());
|
|
trimmed.len() < rest.len() && !trimmed.is_empty()
|
|
}
|
|
|
|
/// JS: readSidecarSchemaVersion
|
|
pub fn read_sidecar_schema_version(sidecar: Option<&serde_json::Value>) -> Option<i64> {
|
|
let v = sidecar?.as_object()?.get("schemaVersion")?;
|
|
if let Some(i) = v.as_i64() {
|
|
return Some(i);
|
|
}
|
|
if let Some(f) = v.as_f64() {
|
|
if f.fract() == 0.0 && f.is_finite() {
|
|
return Some(f as i64);
|
|
}
|
|
}
|
|
None
|
|
}
|