Skip to main content
Lightning Jar - Web Studio Lightning Jar Wordmark

What an Agent Needs From a Framework: Building OK Tuner in Foldkit

Watercolor illustration of a cat in a cowboy hat, plaid neckerchief and denim jacket playing an acoustic guitar

Much of the code we ship now is orchestrated by a developer, typed by an AI coding agent and read by a person. We suspected that changes what we should want from a front-end framework, so we built a small real product in one that claims to be made for this way of working, and kept notes. The framework is Foldkit, a TypeScript framework built on Effect and arranged like Elm. The product is OK Tuner, a free chromatic instrument tuner that runs in the browser. This is an evaluation and not an endorsement. We are not yet fully adopting Foldkit, and SvelteKit remains our default for content sites and for anything that leans on a server. What follows is what we built, where the architecture helped, and what it cost.

Why a Tuner

A tuner is small enough to finish, and its state is awkward in ways a to-do list is not. There is a microphone that has to be asked for, a permission the person can refuse, a device that can fail through nobody's choice, and a stream of readings arriving twenty times a second. We also had an original to port: the tuner in Stem Shovel, our music collaboration app, which is a 412-line Svelte component.

The first commit was on November 24, and the tuner was live the same day. Two days and 13 merged pull requests later it had routing, four pages pre-rendered at build time, error reporting, a privacy page and visit counts, and it was open to search engines. It runs Foldkit 0.170 on Effect 4, with TypeScript, Vite, Tailwind and Vitest, and it is deployed to Vercel. The site keeps its own list of what it is built with, and the source is on GitHub under the Apache 2.0 license.

What Changes When an Agent Writes the Code

An AI coding agent, Claude Code, wrote the code, and Kevin directed it. Each feature started from a short written design. Tests came first as a rule. The larger changes were reviewed by a second agent that came to the branch fresh, and Kevin approved every merge.

That way of working is the reason for the experiment. When a person types the code, a framework earns part of its place by how little there is to type. When an agent types it, the typing costs almost nothing, and the scarce thing is a person's attention at review. So we went looking for different properties: whether the result can be checked without running it by hand, whether there is one obvious place for each thing, and whether the compiler and the tests catch what a reviewer skims past. That was a thesis to test, and one small app is all the evidence this article has for it.

State Changes Are Tested Without a Browser

In Foldkit the whole state of the app is one value, the Model. Everything that happens is a Message. One pure function, update, takes the current Model and a Message and returns the next Model, along with any Commands for the runtime to carry out. Nothing about it needs a browser, so a Story test sends it Messages and looks at what comes back:

test('a refusal shows its reason, and pressing power again retries cleanly', () => {
  story(
    update,
    given(offModel),
    message(Message.ClickedPower()),
    message(
      Message.FailedAcquireMicrophone({
        failure: MicrophoneFailure.Refused(),
      }),
    ),
    model(next => {
      expect(next.tuner).toEqual(
        TunerState.Failed({ failure: MicrophoneFailure.Refused() }),
      )
    }),
    message(Message.ClickedPower()),
    model(next => {
      expect(next.tuner).toEqual(TunerState.Starting())
    }),
    message(Message.SucceededAcquireMicrophone()),
    model(next => {
      expect(next.tuner).toEqual(
        TunerState.Listening({
          level: 0,
          maybeReading: Option.none(),
          needleCents: 0,
          quietTicks: 0,
        }),
      )
    }),
  )
})

That test follows a person who refuses the microphone, sees why the tuner is off, allows it and presses the button again. There is no microphone in it, no permission prompt and no page. Most of the suite reads like this: 302 tests in 13 files, which run in about two seconds on our development machine. For a reviewer, tests of this kind are the quickest way to see what the agent believed the behavior should be, one step at a time.

A State That Makes No Sense Cannot Be Written

The tuner's power state is one union, shown here without its comments:

export const TunerState = defineTaggedUnion({
  Booting: {},
  Off: {},
  Starting: {},
  Listening: {
    level: Schema.Number,
    maybeReading: Schema.Option(Pitch),
    needleCents: Schema.Number,
    quietTicks: Schema.Number,
  },
  Failed: { failure: MicrophoneFailure },
})

There is no isOn flag beside an isStarting flag, so "starting and failed at once" has no spelling. The handler for the power button must say what a click means in every state, and it does not compile until it does:

ClickedPower: () => ({
  model: withTuner(
    model,
    TunerState.match(model.tuner, {
      Booting: booting => booting,
      Off: () => TunerState.Starting(),
      Starting: starting => starting,
      Listening: () => TunerState.Off(),
      Failed: () => TunerState.Starting(),
    }),
  ),
}),

Booting arrived on the second day, with prerendering. The views needed no change to be prerendered, because init and view were already pure functions that a build can run in Node. Then a review found that a press on the button before the script had loaded was lost. The first fix was a boolean, and Foldkit's conventions asked for a state in its place. Adding that fifth state was a compile error at every match in the app until each one had decided what booting meant there. Routes behaved the same way: a new page stopped the build until its title, its view and its effect on the tuner had been written. The agent gets its list of places to change from the compiler, and a reviewer does not have to wonder whether a match somewhere was missed.

Lifetimes Follow the Model

No code in the app opens or closes the microphone. The app declares which states require it, and the runtime acquires and releases it as the Model changes:

modelToMaybeRequirements: model =>
  TunerState.match(model.tuner, {
    Booting: () => Option.none(),
    Off: () => Option.none(),
    Starting: () => Option.some(null),
    Listening: () => Option.some(null),
    Failed: () => Option.none(),
  }),

When routing arrived, closing the microphone on leaving the tuner's page was a change to the Model and nothing else:

const enterRoute = (model: Model, nextRoute: AppRoute): Model =>
  modifyFields(model, {
    route: () => nextRoute,
    tuner: tuner =>
      AppRoute.match(nextRoute, {
        Tuner: () => tuner,
        HowTo: () => TunerState.Off(),
        BuiltWith: () => TunerState.Off(),
        Privacy: () => TunerState.Off(),
        NotFound: () => TunerState.Off(),
      }),
  })

We checked it in headless Chrome: the microphone track read live on the tuner's page and ended straight after a link was clicked. A forgotten cleanup is hard to catch in review because it is the absence of a line. Here there is no such line to forget.

Side Effects Are Data

Saving a preference and reporting an error are Commands: values that update returns and the runtime runs. This is the function that decides whether a microphone failure is reported to Sentry:

const failWith = (
  model: Model,
  failure: MicrophoneFailure,
): Update.Return<Model, Message> => ({
  model: withTuner(model, TunerState.Failed({ failure })),
  commands: MicrophoneFailure.match(failure, {
    Refused: () => [],
    Unsupported: () => [],
    Unexpected: ({ name, detail }) => [ReportProblem({ name, detail })],
  }),
})

A refusal is the person's own choice and is never reported. A fault is. Because the report is a value, a test asserts on it in one line, Command.expectExact(ReportProblem({ name: 'NotReadableError', detail: 'No microphone' })), and nothing is sent. The decision sits in update beside every other decision, and it shows in the DevTools history.

Help for the Agent Itself

Foldkit ships a conventions file written for agents, FOLDKIT.md, and a DevTools server that lets an agent read the running app's Model and Message history. It also suggests vendoring the framework's own repository into the project, pinned to the installed release. That last one mattered most to us. Foldkit is young, and Effect 4 renamed much of Effect 3, which we met when adopting Effect in Stem Shovel. A language model's memory of either is unreliable, so the agent checked each claim about the framework against the vendored source.

What It Cost

It is more code. OK Tuner has about 2,250 lines of application code and about 2,500 lines of tests, against a 412-line Svelte component. That is not like for like, because the component leans on shared modules and the port grew pages and error reporting the original gets from its app. The repository also carries more than 3,000 lines of comments, which is our doing: the project doubles as our team's Foldkit example, so it breaks Foldkit's own rule against comments that explain code.

Views are function calls and not markup. A heading is h.h2([h.Class('font-semibold text-slate-50')], [section.title]). Anyone who thinks in HTML will read it more slowly.

The script is large: about 507 kB, roughly 160 kB compressed, for a tuner. It was 398 kB before error reporting went in.

There are two things to learn, Foldkit and Effect, and Effect is the bigger one.

And it is young. Foldkit is pre-1.0 and marks its server rendering experimental. We met gaps. The runtime does not move focus or scroll on a page change, so a screen reader hears nothing until the app does both itself. A prerendered page cannot start from what the browser has saved, so a returning visitor can see the default tuning for a moment before their own. One test helper, Command.resolveAll, passes when a Command it lists was never returned, which left lines in three of our tests asserting nothing. The compiler's list has holes too: nothing asks for a new page to be added to the router's list or to the paths the build prerenders.

The tests did not catch everything either. The fresh reviews found a crash when site storage is blocked, the lost click before the script loads, and the silent page change. A real error report from the live site then found a source map fault that no review had. The architecture made a great deal checkable. Someone still had to check.

Where This Leaves Us

This is an interim report. We did not measure whether Foldkit is faster to build with, and we are not claiming it is better than SvelteKit in general. One tuner with no server data, no forms and no accounts cannot answer either question.

What we can say is narrower. For a client-side tool with real state, where an agent writes most of the code and a person has to trust it, the properties we went looking for were there: behavior stated in tests that run without a browser, one function where every decision lives, and a compiler that lists most of the places a change touches. We would consider Foldkit for that kind of work, and we would want to see it carry forms and server data before going further. For a content site, or anything that leans on a server, we would still reach for SvelteKit.

The repository holds about 80 more lessons in FINDINGS.md, each with the place in the code where it lives. If you are weighing the same question, start there, then tune a guitar.

headshot of Kevin Peckham
Kevin Peckham
Principal, Lightning Jar

Ask Eljay

Ask about the studio's work, research, packages, or writing. A few starters:

Answers come from this site's own content and link their sources. For anything that matters, email hello@lightningjar.com.