@fiberfx/devtools
v4.1.1
Published
Native Mercury DevTools, the Mercury Inspector: a development-only collector over Hypergraph's public inspect (./connect), with bounded, detached protocol-2 records of scoped work, a headless recorder for screen tests (./test), a review-desk export, and i
Readme
@fiberfx/devtools: the Mercury Inspector
Development-only inspection of a Mercury app's Hypergraph, on protocol 2. One collector, three surfaces: a dock in
the page, a headless recorder for screen tests, and a review-desk export. It reads only Hypergraph's public surface
(@fiberfx/hypergraph/inspect, watch, a scoped getState) and never writes the app's graph, calls an event or
writes a store.
Attach: mx dev --inspect
mx dev --inspect # or "inspect": true in the app's mx.jsonmx dev puts the Inspector's attach before the app's entry, so it observes declarations before any model evaluates,
and mounts the dock (Ctrl/⌘+Shift+I). The app must resolve @fiberfx/devtools like its other members (a require and
a replace by directory in its mx.mod, or a workspace that has it); mx dev refuses otherwise and says so. A forked
scope joins with one dev-only line, a no-op without the Inspector:
const release = globalThis.__MERCURY_INSPECTOR__?.registerScope({ id: "taskdesk", scope });
// …in the cleanup, beside dispose(scope):
release?.();The collector: @fiberfx/devtools/connect
import { connect } from "@fiberfx/devtools/connect";
const session = connect({ appId: "taskdesk" }); // one session per app id
session.observeDeclarations(); // before the model loads: declarations are never replayed
const release = session.registerScope({ id: "desk", label: "taskdesk", scope, stores: { draft: $draft } });
session.records(); // detached protocol-2 records, oldest first
session.detach(); // every subscription released; idempotent- Records.
unit.declared/unit.new(with a module from the sid),unit.observed,unit.skipped,unit.error,unit.reset(with Hypergraph's owndescribetext),effect.perform/effect.settle,store.snapshot,generation.commit,capture.gap. Each carriesgen,cause,txand its scope label. - Transactions. A call from outside is a root; the updates it caused join its transaction (
tx) bycause. - Exact scopes. One subscription per registered scope; global work only through
registerGlobal. - Bounded at scale. 2,000 records, 1,000 per scope (a noisy window evicts its own history, not a quiet one's), 4 MiB of previews, 32 scopes, 512 scope–store pairs; counters name every eviction and drop.
- Safe previews. Primitives as text, an Error as its message, anything else opaque unless
previewPolicy.projectreturns plain data.
Screen tests: @fiberfx/devtools/test
import { recordSession } from "@fiberfx/devtools/test";
const s = recordSession({ scope, label: "taskdesk", stores: { decisions: $decisions } });
// …render and interact…
s.updates("draft"); // observed updates of a unit (by id, or its last segment)
s.causeChain("draft"); // from the root call to the unit's last update
s.snapshots("decisions"); // a registered store followed by its registry key
s.transactions(); s.declared(); s.resets(); s.errors(); s.lines();
s.detach(); // s.handles is 0 afterwardsA refused registration throws and leaves nothing behind.
Review desk: exportReview
session.exportReview({ tx } | { unit, scope? } | { seqs, scope? }) returns a serializable
mercury-inspector-review/1 payload: scope (or mixed with every scope listed), gen, unit, transaction,
up to 50 records, omitted, a summary within 280 characters for a note's human text, capturedAt, and a
plain-text brief. The evidence travels beside a review note; it never replaces the note's own words. A reader of
saved exports checks them against REVIEW_SCHEMA, REVIEW_RECORDS and REVIEW_SUMMARY_CHARS rather than copies of
them, from @fiberfx/devtools/review: that entry reaches the protocol and nothing of the live collector, so a
production reader can import it (./connect re-exports the same names for a page that has a session).
The dock: @fiberfx/devtools/panel
mountInspectorDock(session) (what mx dev --inspect uses) or mountDevtoolsPanel(element, session). Views:
Timeline, Transactions (by cause, indented), Units (by module), Stores, Session. Copy for review copies an
export and reports success only after the clipboard took it; otherwise it shows the evidence as selectable text.
Escape and Close close it; text only, never markup.
The dock wears the page's theme class (dark-theme or light-theme) and follows it as it changes. It reads it from
<html>, or, when the theme sits on an inner element, from the element a page names with
<meta name="mercury-inspector-theme-from" content=".practice">; mountInspectorDock(session, { themeFrom }) takes
an element or a selector directly. A selector is looked up again as the page changes, so an element that mounts after
the dock, or is replaced, is followed; until one matches, the dock follows <html> (with one console note).
Commands
| Command | Covers |
|---|---|
| mx test --root devtools (from fiberfx/) | The collector, recorder, export and dock rows, in headless Chromium against the real Hypergraph |
| Native library build | mx build --package: every public entry built, peers external, declarations generated, mx.sum kept. No Node build tooling here |
Limits. Declarations are seen from attachment only (Hypergraph has no replay). Until H1's compiler names units,
events show run-time ids. Hypergraph has no public ./hmr yet, so the reset row runs through an injected engine.
