cmp-inspector

v0.9.1
io.github.kvdm-co-pilot/cmp-inspector Checked 2 days ago Published 2 months ago

Compose 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…

ParameterTypeDescription
a11yOverlaybooleanwireframe only: overlay accessibility-audit violations in a danger style.
formatstringDefault 'json'. 'wireframe' renders the (sub)tree as a deterministic SVG wireframe.
includeLayoutGapsbooleanAdd `layoutGaps`: spacing between consecutive tagged siblings, tree-wide.
maxDepthintegerwireframe only: only draw nodes up to this depth (root = 0).
outstringwireframe only: also write the SVG to this path.
scalenumberwireframe only: explicit px scale (default fits width to ~740).
sourceWhere 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).
testTagstringReturn only the subtree rooted at the node with this testTag.
treePathstringLEGACY (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…

ParameterTypeDescription
appIdstringExplicit applicationId (skips resolution from the project).
clearStatebooleanWith relaunch: also `pm clear` — pristine app data (Room DBs, prefs, first-run state).
portintegerInspector port (default 9500).
projectDirstringApp repo root, for applicationId resolution when the app must be launched (default: cwd).
relaunchbooleanForce a verified relaunch (force-stop + launch, proven by processStartedAtMs advancing).
serialstringadb device serial (when several devices are attached).

navigate_and_inspect Tap the running app and re-inspect (the navigation primitive)

Drive the LIVE app one tap at a time, no pixels needed: resolves the tap point from the live tree (center of `testTag`'s bounds — or pass explicit root-relative `x`/`y` read from bounds), delivers it via the inspector's POST /inspect/tap (HTTP, not adb), waits `settleMs` for the UI to settle, then re-fetches the tree. Returns { tapped:{x,y,testTag?}, before:{tags,textSample,nodeCount}, after:{tags,textSample,nodeCount}, changed, route? } — assert the navigation structurally (old screen's tags gone, new content present). `route:{before,after}` (each a currentRoute string) is included ONLY w…

ParameterTypeDescription
portintegerInspector port (default: the connect_live session port, else 9500).
settleMsintegerHow long to wait after the tap before re-fetching the tree (default 1500ms).
testTagstringTap the center of this node's bounds (resolved from the live tree).
xnumberExplicit tap x in root-relative px (with `y`, instead of testTag).
ynumberExplicit tap y in root-relative px (with `x`, instead of testTag).

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.

ParameterTypeDescription
portintegerInspector port (default: the connect_live session port, else 9500).
projectDirstringApp repo root for git-based attribution (default: cwd).
sincestringISO 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).

ParameterTypeDescription
levelstringMinimum severity (that level and above).
limitintegerMax entries returned, newest-first (default 200, max 2000).
portintegerInspector port (default: the connect_live session port, else 9500).
serialstringadb device serial (when several devices are attached).
sincestringISO 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.

ParameterTypeDescription
table *stringExact table name (see the app's Room schema JSONs / @Entity classes).
limitintegerRow cap (device-side default/max still apply).
portintegerInspector 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'…

ParameterTypeDescription
harnessbooleanRun the create-cmp checkout's DEMO harness (bundled SampleScreen) to produce the PNG first.
harnessDirstringHarness project directory (default: the create-cmp checkout's inspector/harness).
outstringWhere to write a live capture (default: a temp file). Ignored for pngPath/harness.
pngPathstringPath to an existing PNG (e.g. the harness's out/screen.png).
projectDirstringRoot 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.
screenstringRegistry id to render with projectDir (default 'shell'; e.g. 'home', a tab slug).
sourceobjectTier 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…

ParameterTypeDescription
projectDir *stringRoot of the create-cmp app (the directory containing composeApp/).
hotbooleanPhase 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…
portintegerFirst 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…

ParameterTypeDescription
timeoutMsintegerwaitForRender timeout (default 120000; result carries timedOut:true on expiry).
waitForRenderbooleanBlock 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…

ParameterTypeDescription
timeoutMsintegerwaitForDecision timeout (default 120000; result carries timedOut:true on expiry).
waitForDecisionbooleanBlock 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…

ParameterTypeDescription
statusstringFilter the snapshot to one status.
timeoutMsintegerwaitForComment timeout (default 120000; result carries timedOut:true on expiry).
waitForCommentbooleanBlock 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).

ParameterTypeDescription
id *stringComment id (see review_comments).
note *stringWhat 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…

ParameterTypeDescription
name *stringCandidate 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…

ParameterTypeDescription
screen *stringRegistry screen id (see preview_status screens[].id).
minTouchTargetPxnumbera11y touch-target minimum (default 48).
tolerancePxnumberBounds-move tolerance in px (default 1).