Technical brief / Developer Tools

Building a .NET 8 desktop app with Photino and two coding agents.

Published
Reading time
8 minutes
Topics
dotnet / desktop-apps / ai-agents

What happened

OKF Todo is a free, open-source desktop task manager published by dalby.md. Its first commit was on 26 June 2026; by 2 December 2026 the repository had about 300 commits. Claude Code and Codex wrote all of the code, and Søren Dalby tested and committed every change. Both agents read the same instruction file, AGENTS.md: plain Markdown in the repository root that states how to build, test and change the code, and which rules must never be broken. These coding agents write the code. They are a different role from the AI assistant that uses the finished app, described below, even when the same tool fills both.

The app targets .NET 8 on Windows. Photino.NET 3.2 provides the window. Inside it sits a web view: a browser component that an application embeds to display HTML, without the address bar and tabs of a full browser. On Windows, Photino uses WebView2, the Edge engine that ships with the system. The interface is static HTML, CSS and jQuery (a small JavaScript helper library), with no npm and no bundler. Data lives in a single SQLite file, accessed through EF Core 8. Figures as of 2 December 2026 (project file):

Application C#, excluding migrations about 10,900 lines
Test C# in three test projects about 10,100 lines
Test methods 108 unit and service, 48 browser UI, 7 installed contract (all three are described below)
Installers Inno Setup (a classic setup.exe) and MSIX (the Microsoft Store package format)

One executable, three ways in

The same Okf-Todo.exe starts in one of three modes, chosen by a command-line switch (Program.cs):

  • no switch: the desktop window;
  • --mcp: a local server for the Model Context Protocol (MCP), a standard way for AI assistants to call functions an application offers. An assistant such as Claude Code starts the program and exchanges JSON messages with it through its standard input and output, so no network port is involved. Here "server" means that local process, not a web server;
  • --okf-command: the program reads one JSON command from standard input, runs it and exits. It is meant for scripts and assistants that follow the app's command reference, which ships with the app as part of its Open Knowledge Format (OKF) files: plain-text descriptions of the database and commands, written for an AI to read.

All three call the same C# service classes, so the same validation runs and the same task history is written whichever way a change arrives. The brief on safe AI write access looks at why that matters.

How the window talks to .NET

The page in the window and the C# code talk in two ways.

  • Files. Photino.NET.Server, a small companion package, runs a static file server on http://localhost:<port> that serves the wwwroot folder. The web view loads the HTML, CSS and JavaScript from it like any web page. The file server only hands out these fixed files; it knows nothing about tasks.
  • Messages. Everything that reads or changes data goes through Photino's message channel instead: JavaScript passes a string to the .NET side, and .NET can send one back. OKF Todo sends JSON with a message type such as task.update, the data, and an id so the answer can be matched to the request. One C# class, BridgeMessageHandler, receives every message, calls the right service and replies.

Images inside task bodies are stored in SQLite, so the page cannot load them as files. The page refers to them with addresses such as app://image/42, and C# registers a handler for the app:// prefix that reads the image from the database. The project records its main design choices in short documents called architecture decision records (ADRs), and the first of them keeps data operations out of the file server on purpose: it serves files, nothing else.

A call sequence between the page JavaScript, the C# handlers and the services with SQLite. The page sends a task.update message with a messageId through the Photino message channel. BridgeMessageHandler passes it to the task service, which validates the change, saves it and writes task history, and the handler replies with the result and the same messageId, so the page can match the answer to its request. Images in task bodies use addresses such as app://image/42: the app:// handler reads the image from SQLite and returns it to the page, without going through the file server.

What broke: startup

The commit log for 7 July 2026 reads "tiny mce startup issues", "startup issues" and "startup now works but is slow" (TinyMCE is the rich-text editor in the task form). The window sometimes opened blank. The startup order that came out of it is now a fixed rule in AGENTS.md:

PhotinoServer
    .CreateStaticFileServer(args, out string baseUrl)
    .RunAsync();

string readinessUrl = $"{baseUrl}/index.html";
WaitForStaticFileServerAsync(readinessUrl, startupLogger).GetAwaiter().GetResult();

string appUrl = $"{readinessUrl}?v={DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
// ... build the PhotinoWindow and register handlers ...
window.Load(appUrl);

The app starts the file server, then WaitForStaticFileServerAsync (not shown) requests index.html up to 20 times, each with a two-second timeout, until the server answers. This check is the readiness probe. Only then does the app load the window. The ?v= timestamp gives every start a new address, so the web view cannot show a cached copy of an earlier page.

The rule also tells the agents how to read a blank window from the log, which records each request:

  • no successful request for index.html: the file server was not ready;
  • the probe succeeded, but no request for index.html?v=… followed: the web view never started loading the page;
  • the files loaded, but no message reached C#: the problem is in the JavaScript or the message channel.

A call sequence between the C# program, the local file server and the WebView2 web view. The program applies database migrations, starts the file server and requests index.html until the server answers 200 OK, the readiness probe. Only then does it tell the web view to load index.html with a ?v= timestamp. The web view requests that address from the file server, receives the HTML, CSS and JavaScript, and the page sends its first bridge message to the program. Numbered marks show the three log checks for a blank window: no 200 to the probe means the file server was not ready; no request with ?v= means the web view never loaded the page; no message means the problem is in the JavaScript or the message channel.

A later fix came from a reported problem: a scrollbar sat off screen because the saved window size was larger than the monitor. The app now moves a restored window onto the display it overlaps most, with tests for a disconnected monitor and for a monitor placed to the left of or above the main one, where Windows gives the monitor's position as negative numbers (implementation plan).

Three test projects, three boundaries

  • Unit and service tests use xUnit, the common .NET test framework, and run the service classes against temporary SQLite databases.
  • Browser UI tests (description) use Playwright, a library that drives a real browser from code. They load the real wwwroot files in Edge. Before the page starts, the test adds a small script in place of Photino's message channel, which passes each message to the real BridgeMessageHandler, working on a temporary database. One click often starts several requests: the title appears at once, and the editor, checklist and history follow. A test that checks the page after the first visible change can run ahead of the rest, and then fails whenever the machine is busy. The JavaScript now counts the work in progress, such as requests still waiting for an answer, task loads and saves, and sets data-app-idle="true" on <body> when that count is zero. Tests wait for the attribute before checking anything.
  • Installed contract tests (decision) check the program's contract: the promises the installed program makes to AI assistants and scripts, such as which commands it accepts and what they write to the database, using only what the installer put on disk. They reference no project from the source code; they start the installed Okf-Todo.exe in MCP or command mode against a fresh temporary database and check the result in SQLite.

Data safety rules

A user's tasks must survive every upgrade, even when a new version needs a different database layout. On 25 July 2026, for example, tasks could be starred and moved to a trash bin, so the tasks table needed new columns in every existing database.

EF Core, the .NET library OKF Todo uses to read and write SQLite, handles this with migrations: small, numbered steps stored in the source code, such as "add the columns for stars and the trash bin". Each database file keeps a list of the steps it has already had, in a table named __EFMigrationsHistory. When OKF Todo starts, before it reads any data, it runs the steps missing from that list, so a database from any earlier version is brought up to date and keeps its tasks (migrations decision).

EF Core also has a shortcut, EnsureCreated(), which creates all tables as they look in the current code but no __EFMigrationsHistory table, so the database has no record of any step. On the next upgrade, EF Core would see no steps recorded, try to run them all from the first one, and fail because the tables already exist. The user's database could then no longer be upgraded. That is why the application must never call it, and Microsoft's EF Core documentation warns against combining the two.

Installers must never contain or touch a user database. A shared packaging check, run by both the Inno Setup and the MSIX builds, fails the build if the files to be packaged include a database file, recognised by its name or by the text SQLite format 3 at the start of the file.

Why it matters

Photino sits between the usual choices. Electron also uses web files but ships its own copy of Chromium with every app; MAUI and WPF, Microsoft's own frameworks for desktop interfaces, normally use XAML, Microsoft's interface markup, rather than HTML. With Photino the app ships no browser engine, and the interface is plain web files that a coding agent can edit and a browser test can load. The cost is that the startup order, the message format and the test setup are yours to design; the framework does not provide them.

For agent-written code, the two kinds of safeguard differ in strength. A written rule such as "never call EnsureCreated()" still depends on someone noticing a break in review. A check that runs, such as the packaging check or a test that starts the installed executable, fails without anyone having to notice, and a test against the installed program catches code that works only when run from the source tree.

AI Disclosure

Researched and drafted with AI assistance, then reviewed by Søren Dalby. Sources are linked; errors may remain, and corrections are welcome.

Sources