cmp-inspector
v0.9.1Compose Multiplatform UI as structured JSON for agents: trees, tokens, previews, diffs.
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
inspect_tree Inspect Compose tree
Load the enriched Compose semantics tree (hierarchy + geometry + resolved design tokens) as JSON, plus a compact summary { nodeCount, taggedCount, tokenizedCount }. With source {kind:'live'} this reads the RUNNING app's current screen (real data + nav state) on every call. Options: `testTag` returns only that node's subtree; format:'wireframe' returns the (sub)tree as a deterministic SVG wireframe instead of raw JSON (footprint nodes as rects, tokenized nodes highlighted with a resolved-values chip, clickable nodes with a distinct outline, testTags as mono labels — SVG is structured text, sa…
| Parameter | Type | Description |
|---|---|---|
a11yOverlay | boolean | wireframe only: overlay accessibility-audit violations in a danger style. |
format | string | Default 'json'. 'wireframe' renders the (sub)tree as a deterministic SVG wireframe. |
includeLayoutGaps | boolean | Add `layoutGaps`: spacing between consecutive tagged siblings, tree-wide. |
maxDepth | integer | wireframe only: only draw nodes up to this depth (root = 0). |
out | string | wireframe only: also write the SVG to this path. |
scale | number | wireframe only: explicit px scale (default fits width to ~740). |
source | Where the tree comes from. Omit to use (in order): legacy treePath, the connect_live session default, $CMP_INSPECTOR_LIVE (host:port), $CMP_INSPECTOR_TREE (file). | |
testTag | string | Return only the subtree rooted at the node with this testTag. |
treePath | string | LEGACY (kept for compatibility): path to a tree JSON produced by the inspector harness. Prefer `source`. Defaults to $CMP_INSPECTOR_TREE. |
connect_live Connect to a running app's live inspector (self-healing)
Tier 1 handshake, SELF-HEALING: ensures a device/emulator is attached, ensures the `adb forward tcp:<port> tcp:<port>` exists (creating it — the debug-only inspector server binds loopback on the device), then GETs /inspect/health. If health is dead it LAUNCHES the debug app (applicationId parsed from the project — composeApp/build.gradle.kts / create-cmp.json — never hardcoded; pass `projectDir` when the server's cwd is not the app repo, or `appId` to skip resolution) and re-polls with bounded backoff. On a `device offline`-class adb error (a stale adb server transport — the client say…
| Parameter | Type | Description |
|---|---|---|
appId | string | Explicit applicationId (skips resolution from the project). |
clearState | boolean | With relaunch: also `pm clear` — pristine app data (Room DBs, prefs, first-run state). |
port | integer | Inspector port (default 9500). |
projectDir | string | App repo root, for applicationId resolution when the app must be launched (default: cwd). |
relaunch | boolean | Force a verified relaunch (force-stop + launch, proven by processStartedAtMs advancing). |
serial | string | adb device serial (when several devices are attached). |
runtime_crashes Fetch persisted crashes from the running app, with cause attribution
GET /inspect/crashes on the running app (current boot + previous ones; the on-device handler chains to whatever handler was installed before it — it never swallows the crash). Each crash is attributed: its stack frames are intersected with recently-edited files (git status + git diff in `projectDir`, default cwd) to produce a verdict — 'likely-caused-by-recent-edit' (with the matching frame(s) as evidence) or 'no-recent-edit-implicated'. Returns { crashes:[{timestamp,exception,message,frames,attribution}], changedFilesConsidered }. Requires connect_live.
| Parameter | Type | Description |
|---|---|---|
port | integer | Inspector port (default: the connect_live session port, else 9500). |
projectDir | string | App repo root for git-based attribution (default: cwd). |
since | string | ISO timestamp — only crashes at/after this instant. |
runtime_logs Fetch recent device logs for the running app (adb logcat)
Shells `adb shell pidof <appId>` (appId resolved from the live inspector's GET /inspect/health) then `adb logcat -v threadtime --pid=<pid> -d` and returns STRUCTURED, BOUNDED entries — never a log firehose: default limit 200, max 2000, newest-first tail. Optional `level` keeps that severity and above (adb's own ordering); `since` (ISO timestamp) keeps entries at/after it. No on-device log capture — v1 is adb-only, so it needs a device/emulator attached and adb on PATH; errors are actionable (no device, no process running, adb missing).
| Parameter | Type | Description |
|---|---|---|
level | string | Minimum severity (that level and above). |
limit | integer | Max entries returned, newest-first (default 200, max 2000). |
port | integer | Inspector port (default: the connect_live session port, else 9500). |
serial | string | adb device serial (when several devices are attached). |
since | string | ISO timestamp — only entries at/after this instant. |
db_query Read rows from one SQLite table (read-only, bounded)
GET /inspect/db?table=<name>&limit=<n> on the running app — assert PERSISTED state in the live tier. `table` must be a real table name (the app's Room schema JSONs and @Entity classes are in-repo) — the device validates it strictly against `sqlite_master` before ever touching a query, so an unknown name 404s rather than running arbitrary SQL. Rows are capped by `limit` (device-side default/max apply regardless of what's requested). Returns { table, columns, rows, rowCount }. Requires connect_live.
| Parameter | Type | Description |
|---|---|---|
table * | string | Exact table name (see the app's Room schema JSONs / @Entity classes). |
limit | integer | Row cap (device-side default/max still apply). |
port | integer | Inspector port (default: the connect_live session port, else 9500). |
render_screen Render the screen as pixels (path-only, for the human)
Pixel preview with a PATH-ONLY contract: returns { path, width, height, sizeBytes, displayHint } parsed from the PNG header — NEVER the image bytes/base64 (pixels flow to the human, structure flows to the AI). Sources: `projectDir` (+ optional `screen` id, default 'shell') renders a REAL screen of a create-cmp app headlessly — through the resident preview daemon when one is running (~1s warm) else via its generated `:composeApp:renderScreens` task — no device/emulator — and also returns `treePath` (the structural twin), `previewsDir`, and `via` ('daemon'|'gradle'); `source:{kind:'live'…
| Parameter | Type | Description |
|---|---|---|
harness | boolean | Run the create-cmp checkout's DEMO harness (bundled SampleScreen) to produce the PNG first. |
harnessDir | string | Harness project directory (default: the create-cmp checkout's inspector/harness). |
out | string | Where to write a live capture (default: a temp file). Ignored for pngPath/harness. |
pngPath | string | Path to an existing PNG (e.g. the harness's out/screen.png). |
projectDir | string | Root of a create-cmp app: runs its generated `:composeApp:renderScreens` task (tier 0, real screens from inspector/PreviewRegistry.kt) and reads the PNG + tree it wrote. |
screen | string | Registry id to render with projectDir (default 'shell'; e.g. 'home', a tab slug). |
source | object | Tier 1: capture the RUNNING app's screen via GET /inspect/screenshot. |
preview Start the live preview gallery (watch + render + serve)
AI-native previews of a create-cmp app's REAL screens with NO device, emulator, or manual Gradle: starts (or reuses) a resident service that renders every screen in inspector/PreviewRegistry.kt headlessly, serves a LIVE gallery for the human at a local URL (pixels + wireframe + a11y per screen; the page reloads itself via SSE after every re-render), and watches composeApp/src so every save re-renders automatically. Returns { url, screens:[{id, nodes, tokenized, tagged, a11yPass, tree, png}], version, changedLastRender } — give the human the url (open it for them if you can); assert on the re…
| Parameter | Type | Description |
|---|---|---|
projectDir * | string | Root of the create-cmp app (the directory containing composeApp/). |
hot | boolean | Phase 2 (default true): boot the resident preview daemon under Compose Hot Reload (hotRunDesktop --mainClass=<pkg>.inspector.PreviewDaemonKt --auto) so warm saves re-render in seconds; falls back to t… |
port | integer | First port to try for the gallery server (default 9600, probes upward). |
preview_stop Stop the live preview gallery
Stops the resident preview service started by `preview` (file watcher + gallery server). Returns the final status. The Gradle daemon it used stays warm (that's desirable).
preview_status Preview status — optionally WAIT for the next render
The agent's post-edit feedback call. Without arguments: returns the preview service's current status (mode, version, rendering, lastError/lastErrorSource, lastActivity, changedLastRender, per-screen summaries incl. lastChangedVersion, and `renderer` — the render PIPELINE's own health: {lastOutcome:'ok'|'failed'|'never', lastSuccessAt, lastAttemptAt, consecutiveFailures}, tracked independently of lastError so a later, unrelated compile message can never mask a dead renderer. renderer.lastOutcome:'failed' means every render since lastSuccessAt has failed outright (Gradle/daemon call itself thr…
| Parameter | Type | Description |
|---|---|---|
timeoutMs | integer | waitForRender timeout (default 120000; result carries timedOut:true on expiry). |
waitForRender | boolean | Block until the next render/compile outcome instead of returning immediately. |
approval_status Governed-artifact approval status — optionally WAIT for a decision
The human-approval half of the console (VERIFICATION-LAYER-DESIGN.md §4): every governed artifact's live status (design system, architecture+structure, exemplar feature, exemplar spec, per-feature specs — the same §1 ordered walk the Approvals tab shows), via the PROJECT'S OWN qa/lib/approvals.mjs (never forked here). Structure only — no HTML; the tab is for the human, this tool is for you. Without waitForDecision: the current snapshot {available, statuses:[{id,label,status,hash,storedHash,approvedAt,fileCount,missing,resolvable}]}. With waitForDecision:true: BLOCKS — same shape as pre…
| Parameter | Type | Description |
|---|---|---|
timeoutMs | integer | waitForDecision timeout (default 120000; result carries timedOut:true on expiry). |
waitForDecision | boolean | Block until any governed artifact's approval status changes instead of returning immediately. |
review_comments Console comment ledger — optionally WAIT for a new comment
The human-comment half of the console (VERIFICATION-LAYER-DESIGN.md §7.3: 'pixels flow to the human, structure flows to the AI, judgment flows back through comments'): the full comment ledger, via the PROJECT'S OWN qa/lib/comments.mjs (never forked here) — target (screen/element/spec-line/design-system/architecture/general, rendered readably in the console's Comments tab), text, author, createdAt, status, resolution. Without waitForComment: the current snapshot {available, schema, comments}. With waitForComment:true: BLOCKS — same shape as approval_status's waitForDecision — until a NEW…
| Parameter | Type | Description |
|---|---|---|
status | string | Filter the snapshot to one status. |
timeoutMs | integer | waitForComment timeout (default 120000; result carries timedOut:true on expiry). |
waitForComment | boolean | Block until a new comment lands instead of returning immediately. |
resolve_comment Resolve a console comment (the agent closes the loop)
Marks a comment resolved via the project's own qa/lib/comments.mjs, recording author 'agent' and `note` (what you actually did about it — update the spec/plan/code FIRST, then resolve; the console never edits code itself, per §4's principle, so this is the only way a comment closes). Returns {ok:true, comment} or {ok:false, reason} — the library's refusal verbatim (unknown id, already resolved). The console's Comments tab then shows the resolution + note. Requires a running preview service (call preview{projectDir} first).
| Parameter | Type | Description |
|---|---|---|
id * | string | Comment id (see review_comments). |
note * | string | What you did in response to the comment. |
snapshot_variant Stash the current renders as a named design-language candidate
GENESIS-FLOW-DESIGN.md §2 'Design-language candidates (variants)': copies the CURRENT preview render (every screen's screen.png from the last completed render) plus design-system.json into composeApp/build/previews/variants/<name>/, REPLACING that variant if one with the same name already exists. Returns { name, screens, designSystemStashed, dir }. `name` must match [a-z0-9-]+ (lowercase letters, digits, hyphens) — anything else is refused, not sanitized. Typical loop: edit Tokens.kt, preview_status{waitForRender:true}, snapshot_variant{name:'warmer'}, repeat per candidate token set, then t…
| Parameter | Type | Description |
|---|---|---|
name * | string | Candidate name, e.g. 'warmer' or 'rounded-v2' — used as the variant's directory name. |
preview_diff Diff a screen across the last two renders (one-call verified edit)
The verified dev loop with ZERO bookkeeping: the preview service already retains the previous generation of every screen's tree, so this diffs a screen's LAST render against its CURRENT one — no pre-edit snapshot needed. Returns { changes, regressions:{drift, driftChecked, a11y}, verdict: 'proven-clean' | 'changed-with-regressions' | 'no-change' } (drift is checked against the previews dir's design-system.json when present). Typical loop: edit → preview_status{waitForRender:true} → preview_diff{screen:<a changed id>}. For a baseline that must survive sessions, the lane's golden trees (qa…
| Parameter | Type | Description |
|---|---|---|
screen * | string | Registry screen id (see preview_status screens[].id). |
minTouchTargetPx | number | a11y touch-target minimum (default 48). |
tolerancePx | number | Bounds-move tolerance in px (default 1). |