Documentation

Docs / Reference

ADR 0037 — Tauri command syntax cache

Status: Accepted (delegated review, 2026-11-01)

Context

T015c links Tauri invoke calls in TypeScript to Rust command functions. The T015c1 census (kftray at e3116e0c: 115 commands, one generate_handler! with 115 entries, four builder bindings) found three gaps in the existing Rust cache. Command attributes are not cached: the extractor keeps only #[path] on modules and a #[cfg( prefix test. Macro invocations are skipped, so generate_handler! entries have no structure, spans or hashes. The cfg-gated if/else that rebinds kftray's builder is cached as an opaque if_expression with text only. The TypeScript side needs no new capture: every invoke field T015c2 needs is already in the client caches.

Options considered

Decision

Add Tauri *TauriSyntax (json:",omitempty") to facts.Facts, beside the Rust syntax, with Version 1, Commands, Handlers and Flows as described in Tauri commands. Files without a record keep byte-identical payloads; a payload of another version, or a structurally incomplete one (empty required kinds, a handler reference out of range), is a cache miss, as for the router payload (ADR 0035). The aggregate extractor version becomes extractors-25; contract v1, the store interface and schema are unchanged.

Capture filters are the cheapest syntactic tests that keep every real target: a function attribute whose last path segment is command (or a single identifier aliased by a file use to such a path, or either inside cfg_attr, nested cfg_attr included), and a macro whose last path segment is generate_handler. Every qualifying attribute of a function is recorded, so a Tauri attribute next to poise's is not lost; cfg_attr predicates are normalized to LF and the predicates of nested levels joined, outermost first, in one flat all(p1, p2, ..). A command's Cfg covers #[cfg(..)] and a cfg_attr applying cfg(..) at any nesting depth. Proof stays with the Rust resolver at link time: each attribute and handler records the RustFacts scope index the resolver uses, so T015c2 rejects clap's and poise's command attributes by resolution, never by text.

Handlers parse the macro input grammar #![..]* (#[..]* path),* ,? from the token tree; anything else gets an invalid reason and no entries. Entries keep the span and hash of the path alone. Chains keep every method from the root outward, including methods after invoke_handler, because only the last invoke_handler on a builder counts. A chain never drops a method silently: parentheses are transparent, ? and .await inside the chain are passed through and mark it incomplete, and a root that is not a call or identifier marks it incomplete. Each handler context records what consumes its chain's value (Use: statement, let, assign, tail, return, argument, other; other is incomplete; assign only for a plain identifier target, a field, deref or index target is other), because a tail, return or argument value may receive a later invoke_handler that replaces this one; T015c2 may treat only statement, let and assign chains as final. An invoke_handler method whose argument is not a captured handler is marked Uncaptured, so a replacement is never invisible. Flows exist for functions that contain a captured handler and record Calls: every identifier-rooted chain in the function that calls invoke_handler, captured or not, with its Use. They keep the let and assignment bindings reachable from those roots, with the tail chain of every branch of if, match and block values, a completeness flag, Cfg (also inherited from a cfg-gated enclosing statement or block) and Conditional (the binding is not in the body's top-level statement list), and Shadows: the flow names that a parameter, closure parameter, if let / while let / match arm / match guard / for pattern or destructuring let may bind at a root site (wide scopes, over-inclusive names, following the router payload's Shadows), plus every flow name that appears as an identifier in a macro invocation's token tree in the function body (a macro may rebind it). T015c2 treats an incomplete chain or a shadowed flow name as unproven, never as a registry; it treats a let or assign binding's handler as final only if no later call in Calls, captured or not, applies to it, and a Conditional binding as a possible, never a definite, rebinding.

Consequences

The kftray payload carries exactly the census rows: 115 commands (one attribute each), one handler with 115 entries (context use let, chain complete) and one flow with four bindings and one call; the Shadows and Conditional values are reported in the T015c1 summary (Revision 2). No other corpus has a record. The fixture testdata/fixtures/tauri-command-syntax has a payload-only golden, independent assertions, a CRLF check (the index also normalizes line endings in scan) and shared backend round-trip coverage; Postgres runs only in CI. No nodes, edges, diagnostics, identities or existing payload fields change. T015c2 adds command and invoke nodes and links from this payload.

Known gaps

Review notes (delegated review, 2026-11-01)

Report a problem with this pageSource: docs/adr/0037-tauri-command-syntax-cache.md