Skip to main content

C# Native toolkit

Ribbon tools, CLI, MCP and the optional built-in Agent share typed operations and a native execution host. The original architecture plan records the design history. Native tools work without an AI runtime; the project overview describes current scope.

src/RevitThyme.Core owns requests, results, target checks, the serialized queue, transaction orchestration and IPC contracts. It references no Autodesk assemblies or UI framework. RevitThyme.Addin supplies the native document adapter, ribbon, ExternalEvent and transaction implementation. RevitThyme.UI is a modeless WPF window using IOperationClient. RevitThyme.Cli is another client of those same operations; it contains no model-changing implementation.

Version 0.10.0 used protocol 8 and introduced qualified TimberFold inspection, retained preview/generation runs and reconciliation; see qualification. Version 0.11.0 uses protocol 13 and adds Home-aware background open, exact document/view activation, active-document save and clean close with explicit active-document handoff outside model transactions, with verified Completed outcomes and retained recovery. Active close requires an explicit already-open clean handoff target; last-document close to Home is rejected before side effects. GetOperation uses an independent process-verified pipe and the existing dispatcher history, so outcome polling does not wait for the ordinary native operation pipe. Native extraction and image export run inside captured Revit callbacks. Full extraction snapshots and image files remain private; the bridge returns bounded summaries and file metadata. Inspection and image export open no model transaction and never save the source, but their evidence-file writes use retained-request recovery and are declared in MCP annotations. All host/CLI/MCP clients must use the matching protocol.

ExportViewImage adds one IViewImageModel operation to the existing dispatcher. A fresh captured target and explicit view UniqueId select exactly one native view/sheet; SetOfViews avoids activation and caller-owned callbacks. The native adapter decodes/hashes the PNG and Core verifies unchanged before/after context. The MCP adapter reads and rehashes the retained file before returning an inline image, including on get_operation recovery. Original request retention, conflict checks and queued cancellation remain shared. No second scheduler, save operation, lifecycle operation or promotion mechanism is introduced.

RevitThyme.Mcp adapts the official SDK's stdio transport and schemas to those same Core requests. It serializes connection changes/calls and issues bounded, connection-local capture IDs. A rename requires captured process/start, session, open document identity, view UniqueId, revision and previous name. Generic reads and writes validate the same target. Revit events invalidate captures; reopening creates a new document identity. Parameter edits require exact prior raw values and parameter IDs, and share the native transaction wrapper with rename. Before/after native readback precedes group assimilation into one Undo item. Failures roll back; uncertain completion reports an unconfirmed outcome. Selection is separately verified UI state.

The bridge uses a session-specific Windows named pipe restricted to the current user's SID, rejects remote clients, verifies the server's OS process ID and uses size-bounded framed JSON. Upgrade add-in/CLI/MCP together. The dispatcher retains up to 4,096 outcomes per session, compares replay arguments by value and rejects conflicting IDs. get_operation reads that same retained history through a separate process-verified outcome pipe, without a new API callback or waiting for the original request's pipe. Cancellation prevents queued work from executing; running work finishes and retains its outcome. All model access runs in Revit API callbacks. Typed operations do not implicitly save or synchronize a model.

Parameter inspection and readback share ParameterInfo, including native shared status/GUID, built-in enum identity and HasValue. Updated clients request this response metadata through the existing bridge envelope's optional includeParameterIdentity flag. Older version-4 clients omit the flag and receive the original parameter shape, because their strict decoders reject unknown members. This projection happens only at response serialization; cached results, request equality, exact-ID edits and validation stay unchanged. Session discovery and the protocol version remain unchanged. Install updated Addin/CLI/MCP together; older hosts do not recognize the response flag.

Utilities implement IUtilityModel and IUtilityChange: Core checks captured identity, expected native range/room preview and transaction outcomes; Addin resolves Revit planes, finish-face references, tag bounds and native dimensions. Room plans are recomputed and compared by value before any write. The WPF/CLI/MCP adapters contain no duplicate model-editing implementation. Existing legacy ribbon panels are reused with distinct native command IDs.

ListDocuments uses IDocumentDiscoveryModel in the same native queue. Core validates the captured target, bounds metadata and pages, and fingerprints the selected native session plus the complete sorted visible inventory. Addin enumerates native documents and applies fixture visibility before returning records. Background membership or flag changes invalidate continuation without changing lifecycle revision behavior. MCP and CLI use the same operation; discovery never activates, saves or authorizes lifecycle actions. Retained read results remain point-in-time evidence.

Scope and compatibility​

The first build targets .NET 10 and Revit 2027. Revit 2027 uses .NET 10; a promise of Revit 2025+ support would need separate per-release builds and qualification. Local SDK references have CopyLocal disabled. Public builds never fetch or redistribute Autodesk binaries.

Roslyn compilation lives in Addin; Core validates captured targets, trust and request bounds without referencing Autodesk or Roslyn. Submissions load into collectible contexts sharing the native API assembly identity. Query rolls back; modify uses the existing native transaction wrapper, captures DocumentChanged IDs and assimilates one Undo. Results serialize inside the reversible group. Host launch opt-in plus caller trust are required. Full process privileges, cooperative budgets and limitations are documented in Dynamic execution. The independent Cabin Eval is compiled into the disposable test loader and never packaged with the product.

RevitThyme.Codex owns the JSON-RPC stdio process, correlated requests, server events, account/session/skill calls and turn lifecycle. It has no Autodesk or WPF dependency. The UI presents conversations, streamed replies, native tool results and approvals in a dockable pane. The add-in supplies an exact process/session binding. The Agent owns a separate Codex home, configuration, history and authentication; only its pinned MCP server is exposed. Codex handles inference, authentication and orchestration. See Agent.

External Codex still launches the same MCP directly. Optional visual planning, reflection discovery and the Exploration experiment remain deferred.

Superseded Rust, Electron and pyRevit implementation and earlier evidence live in legacy/pre-foundation. Existing installed bundles and private artifacts are preserved. That archive is outside the solution, CI and package allowlist; see migration.

Saved tool definitions​

Reusable Tool Builder stores individual trusted C# definitions in Core-managed private user data. MCP and CLI share definition validation, typed input binding, digest checks and storage. The Agent creates definitions through MCP because its ordinary shell and file-edit tools remain disabled. Saving source does not compile or qualify it.

Execution validates the in-memory definition digest and canonicalizes JSON inputs, then submits an expanded method body through the existing trusted query/modify operations. Tool definitions and concrete test assertions stay in Core-managed storage. A named test executes only its assertion as a rollback query. Protocol 14 adds native observation without a writable model transaction for structured result checks; captured-target and request recovery guards still apply. Managed test fixtures, version promotion, workflow construction and automatic repair remain separate capabilities.

Result-check boundary​

A result-check plan is declared before execution and identifies the native observations, expected comparisons and allowed model changes. Saved-tool orchestration runs configured checks after definite native success. Explicit verification can also check a retained operation for another caller. The native host provides authoritative operation recovery and readback; Core compares the structured observation and native added/modified/deleted IDs with the declared plan.

An operation outcome and a check report answer different questions. A committed operation remains Applied when a later check fails or cannot be confirmed. Check attribution includes the original operation and captured target, plan, definition and input identity. The check path does not resubmit edits, Undo, save or sync the document. Observation code runs without a writable model transaction, while retaining trusted C# full-process permissions and cooperative execution limits.