Architecture
System architecture, layers, and project graph.
Contract for the Trestle Avalonia / .NET 10 suite (app/Trestle.slnx). It satisfies docs/SPEC.md and docs/operations/data-note.md.
Synthesis decision
Four runners (opus, fable, sonnet, haiku) drew whole shapes independently. A judge from another model family (opus) scored them: C1 28/30, C3 24, C2 21, C4 20. I read all four designs end to end and checked three of the judge’s claims against the code (below). I take C1 as the base.
All four agreed on the core, so it is settled:
- immutable workbook; one flat table of topics by id;
- every edit is data that carries its new ids; undo swaps snapshots, no inverse commands;
- unknown fields and zip entries are kept and written back;
- layout makes a display list that the screen and exports share;
- an agent turn works on a private copy that the person accepts or rejects.
Why C1:
- A person can keep editing during an agent turn. The agent builds a private
Draftand returns aChange. Accept replays it on the current workbook. C2 and C3 show the agent’s preview asCurrent, and a save writesCurrent, so a save followed by Reject leaves rejected edits in the file (verified:candidate-2/.../Editor.csline 23 andWorkspace.SaveAsync). C4 is safe but blocks the person for the whole turn. - Lossless save by overlay. On save the codec clones the original JSON object and overwrites only the keys it owns. Unknown keys, their order and unknown nested fields survive without a list.
- Full F01–F30 table and facets for later features.
What changed from C1 (grafts and fixes)
| # | Change | Source | Why |
|---|---|---|---|
| 1 | Architecture test that reflects over every Edit subtype and fails when Workbook.Apply has no arm for it. Remove the false “CS8509 fails the build” claim. |
C4 | Edit is an open record, so the compiler cannot prove exhaustiveness, and Editing/Apply.cs ends with _ => throw (verified). |
| 2 | Derive the highlight of changed topics from reference equality between two workbooks (WorkbookDiff.Between). Delete Edit.Touches. |
C3 | Touches defaults to [] and nothing overrides it (verified), so the highlight is empty. |
| 3 | At Accept, mark the proposal stale when any topic it touches differs between proposal.Start and Session.Current. |
C4 idea, judge | SetFacet replaces a whole value, so an Accept can overwrite a marker the person added during the turn. |
| 4 | ControlPoint is a per-point union (Offset(x,y) or Polar(angle,amount)). Replace ControlPoints.Offsets/Polar. |
C2 | One file can mix the two forms (SPEC 4.4). |
| 5 | One pure key-to-Change table (Intents.Resolve) for the canvas and the outliner. |
C3 | F05, F23: one path from a key press to an edit. |
| 6 | Trestle.Scene becomes its own pure project. Each scene item carries the Target it stands for. |
C3 | Keeps SkiaSharp out of scene building; one source of hit testing. |
| 7 | ReadLimits (entry count, uncompressed size). Opened.Diagnostics lists what the reader kept without understanding. SaveOptions.LegacyEntries (keep or drop content.xml). |
C4, C3 | Zip-bomb guard; honest reporting; Xmind 8 shows stale content from an old content.xml. |
| 8 | Agent policy in structure: web and topic links only, title length cap, cap on topics added per turn. | C3, C4 | Text injected through a map cannot make the agent write a file link. |
| 9 | Test plan is one line per behaviour, taken from C2’s RoundTripTests.cs. |
C2 | Replace C2’s “person edit refused during a turn” with the replay case. |
| 10 | Named owner for theme import and export. | C2, C3 | C1 left F19 to an App slice. |
| 11 | Move Markdown, TXT and OPML export out of the Skia-referencing project into a pure Trestle.Export. |
judge | Small layering fix. |
Not taken:
- C3’s reflection-derived agent tool list. It leaks
NewIdandSheetinto the model’s schemas, puts an agent attribute in the Model layer and cannot giveSetFoldedbothfoldandunfoldnames. Keep C1’sAgentTools.All. - C2 and C3’s “block the person during a turn”.
- C3’s one Skia drawer for the screen. Keep C1’s three painters over one
Sceneand one text measurer, so the canvas can use Avalonia drawing. The one measurer is what keeps line breaks equal.
Project map (app/Trestle.slnx, 11 source projects + 10 test/host projects)
Trestle.App (Avalonia.Desktop) Program, App, MainWindow, desktop dialogs, Live/ (MCP live socket), Platform/
Trestle.Browser (Avalonia.Browser, WASM) BrowserApp, WASM platform seams, single-pass BrowserExporter, InvariantGlobalization
Trestle.Views (Avalonia; UI thread) MainView, Shell, Canvas, Outliner, FormatPanel, Search, Sheets, AgentChat, Notes, Cloud/Pairing UI
Trestle.Render (SkiaSharp, HarfBuzz) SkiaPainter, SvgWriter, SkiaTextMeasurer, MapExport (PNG, JPEG, PDF, SVG)
Trestle.Layout (pure) LayoutEngine, ITextMeasurer, IBranchLayout x4, Navigator, SceneGraph (Scene, SceneItem, SceneBuilder, hit testing)
Trestle.Agent (HttpClient, Polly) MapAgent, ToolSession, AgentTools, AgentPolicy, LiteLLM adapter
Trestle.Mcp (stdio MCP server) MapServer, MapPaths: Claude Code edits .xmind files with the agent's tools
Trestle.Document (pure; layers 1 + 2) Model/, Editing/, Files/ (internal), Queries/, Export/ (Markdown, TXT, OPML)
Trestle.Protocol (pure, no references) HTTP & SignalR DTOs shared by service and clients, error codes, ProtocolVersion
Trestle.Service (ASP.NET Core, EF Core) Multi-tenant cloud service: PostgreSQL 18 + forced RLS (trestle_app), AES-256-GCM DataProtection keys,
Siftarr-pattern local auth (/setup, /login, /join, /devices, /get-app), SignalR live co-editing (/hubs/map),
IMeterFactory OTel telemetry, ProblemDetails, OpenAPI (/openapi/v1.json)
Trestle.Cloud (SignalR.Client, OIDC) Cloud client: HTTP API client, SignalR live sync (MapLink), device pairing, offline journal & merge
Dependencies point down only: Layout and Agent reference only Document; Mcp references only Document and Agent; Protocol references nothing; Service references Protocol, Document, Render, and Agent, and nothing references Service; Cloud references Protocol and Document; Render references Layout; Views references Render, Agent, and Cloud; App and Browser are thin heads over Views. Trestle.Architecture.Tests enforces the project graph and package allowlist on every build.
Rules that every worker follows
IDocumentSession.Commit(Change)is the only way to change a document:EditorSessionfor a file,SharedSessionfor a shared map (cloud-store 4.2, slice 21).OpenDocumentholds either. Nothing else builds a changedWorkbook.- Format and model share one assembly so the residue stays
internal. Nothing inFiles/leaks a JSON type. - A save writes the snapshot that was handed to it, never
Currentafter an await.MarkSaved(snapshot, path)keeps later edits dirty. - The agent never holds a reference to the session or to
XmindFile. - Map text reaches the model only as
MapData. Instructions are constants. - A new topic feature is one facet file and one codec. A new layout is one
IBranchLayoutfile and one registry line. - Round-trip test first: no edit code before
XmindFile.ReadandWritepass all 39 sample files.
Decisions (John, 2026-10-29)
- Windows secret source: John left it to me.
ISecretSourcehas two implementations. Linux:get-secret litellm master-key, read by exit code. Windows: Windows Credential Manager (an entry namedxmind-clone/litellm), read through the OS API. No file, and no secret on a command line. If neither source has the key, the agent panel says so and stays off. Revisit when the Windows boot is used. - Thumbnail: regenerate on every save (
MapExport.Thumbnail). - Legacy
content.xml: drop on save (SaveOptions.LegacyEntries = Dropis the default). - Duplicate topic ids: re-key on read, and report each re-key in
Opened.Diagnostics. Topic links that pointed at a duplicate follow the first topic with that id. - Layout tolerance (confirmed by John on 2026-10-30): each box centre is within 5% of the node size of Xmind 27.01’s box centre, and no boxes overlap. The node size is the larger side of Xmind’s topic-node box (for an underline topic, the title and the line). One unit of slack covers the display scale. Our fonts are not Xmind’s, so
ReferenceLayoutTestsmeasures two errors apart:- Layout error, asserted. The layout gets Xmind’s own box sizes from the reference files and must place every compared topic within the tolerance. This measures the gaps, the balance and the alignment.
- End-to-end error, reported. The layout uses
SkiaTextMeasurerand the system font. The test prints the error per file and the width ratio (ours to Xmind’s) per role. It asserts nothing about them. - The rules and the measurements behind each constant are in
docs/milestones/milestone-2/tune-43-report.md.
- Threat model and severity (2026-10-29): the app opens files the person chose: maps saved by Xmind, files from other tools, and files damaged in transit or on disk.
- Realistic input: Xmind’s own files, valid zips from other writers, and truncated or bit-damaged files. The app never crashes, never hangs and never loses data silently. A damaged file gives an error that names the problem.
- Forged input: a file crafted so that its fields disagree, such as a zip header that lies. The app never crashes, never hangs and stays within
ReadLimits. A silent mis-read of a forged file is acceptable. - Grade a finding by impact times likelihood under this model. High: a crash, a hang or data loss on realistic input, or a crash, a hang or unbounded memory on forged input. Medium: a wrong result on realistic input that the person can see or work around. Low: everything else, including any mis-read that needs forged input.
- A milestone gets one independent review and one fix round. After that, only a high finding reopens it. Medium and low findings become issues for the next milestone.
Solution baseline
app/Trestle.slnx holds the 11 source projects under app/src/ and 10 test/host projects under app/tests/. It builds on .NET 10 with Avalonia 12.1.4, SkiaSharp 4.151.5, Vogen 8.0.7, ErrorOr 2.1.1, and TUnit 1.76.0, pinned centrally in app/Directory.Packages.props with NuGet lock files (--locked-mode) and TreatWarningsAsErrors=true. app/tests/Trestle.Architecture.Tests enforces the project graph, package allowlists, Edit exhaustiveness, and wall-clock rules.
Known risk: Avalonia 12 carries its own SkiaSharp. Trestle.Render pins SkiaSharp 4.151.5 for exports. Check that the two do not clash when Avalonia.Desktop is added to Trestle.App.
Milestone 1: first build step
Implement XmindFile.Read/Write with Residue and Overlay for sheets and topics. Run the round-trip test over the 36 templates (read from $XMIND_TEMPLATES), the 2019 map and the generated feature files. Add the architecture tests for the project graph and for the Edit subtypes. No edit code until this passes.