Skip to Content
🚀 Legit SDK Alpha preview – help shape it on Discord here.
DocumentationConcepts04 - In action

The Chat App

Eating our own “dogfood”

To really understand how the Legit SDK should work in a real project, we build an example project. This helps us to shape the SDK by understanding developer needs and validates insights.

“To arrive at abstraction, it is always necessary to begin with a concrete reality.”
— Pablo Picasso


Picasso Abstraction

Why a Chat App?

A chat app is familiar to many developers and users, making it a relatable way to explore AI co-creation. By giving it write abilities via the Model Context Protocol  (MCP), we enable end users to collaborate on local files alongside AI agents.

The problem: AI working on local files is messy — no versioning, no provenance, no rollback. Every “Edit with AI” button is effectively Russian roulette, which makes this the perfect playground for our SDK.


AI meme

The Solution

To let the AI go crazy without doing harm we want to give each message thread a sandbox, they should be able to read and write files as needed without destroying the work of the user or interfere with the context of other threads.

You may guessed it - it should operate in a separate branch.

Creating a Sandbox Branch

When you utilize LegitFS you can simply create a branch using mkdir in the branches folder. All that happens in the background not visible by the end user.

// Create a branch as a Sandbox for the AI await legitFs.mkDir(".legit/branches/my-new-thread"); // The MCP just writes to a file startWordMcp(inFolder: ".legit/branches/my-new-thread")

The MCP’s used work on files anyway - we just need to point it to the corresponding folder.

All changes done by the MCP are automatically tracked in Legit. But commits alone aren’t enough — we also need intent.

Tracking Intent

Every message, user prompt, tool call, or AI reasoning is stored in a parallel operations branch:

chat.onMessage = function(message) { // Store the intent in the operations branch await legitFs.writeFile(".legit/branches/my-new-thread/.legit/operation", message); };
  • Changes branch → what was changed
  • Operations branch → why it was changed, including prompts, reasoning, and context

Branches remain connected but separate, keeping history clean and intent transparent.

Operations Branch

Legit Chat in action

cgat Abstraction

Takeaway

Legit gives app builders real benefits:

  • Give your end user control over AI writes
  • Use a simple and maintainable FS API
  • Have one generalized control system for any kind of app data
Last updated on