A guide to AI-first development

The Happy Path

How to build projects on FunctionServer with maximum feedback and minimum token waste. The old way is blind and expensive. The new way is surgical and cheap.

The Problem with Traditional AI Coding

When AI writes code the traditional way, it's flying blind. It reads entire files to understand them, writes entire files back, and has no way to verify its changes worked. Every operation burns tokens. Every cycle is slow.

x The Old Way

1. Read entire 500-line file
2. Parse mentally, find the bug
3. Rewrite entire 500 lines
4. Hope it worked
5. User runs it, reports error
6. Read entire file again...
7. Repeat
~3000 tokens per cycle

+ The Happy Path

1. Lens.grep('fetchData')
   -> "42: async function fetchData"
2. Lens.code(40, 10)
   -> see 10 lines of context
3. Lens.setLine(42, 'fixed code')
4. Lens.run()
   -> see error instantly
5. Fix and verify in same call
~200 tokens per cycle

The difference isn't incremental. It's 15x fewer tokens and instant feedback. The AI sees what the user sees, edits surgically, and verifies immediately.

Quick Start

Load the tools and create a project in three commands:

// Load Studio (the IDE with Lens) getFileFromDisk("~/studio.js").then(code => runApp(code, "studio.js")) // Get the command reference Lens.help() // Create a new project (auto-creates GitHub repo if signed in) Lens.project("my cool app")

That last command does everything: creates the folder, initializes git, creates skeleton files, creates a GitHub repo (if you've signed in), commits and pushes, and opens the project in Studio ready to edit.

The Lens API

Lens is the interface that makes this possible. It's designed for AI: terse, efficient, and feedback-rich.

Navigation

Lens.state() // Desktop overview: "w:Studio|Shell e:0 u:william" Lens.files() // List saved files Lens.open('~/app.js') // Open file in Studio

Reading (Token-Efficient)

Lens.code(1, 20) // View lines 1-20 with line numbers Lens.line(42) // View just line 42 Lens.grep('pattern') // Find matches (returns line numbers)

Editing (Surgical)

Lens.setLine(42, 'code') // Replace line 42 Lens.insertLine(5, 'x') // Insert at line 5 Lens.deleteLine(10) // Delete line 10 Lens.replace('a', 'b') // Find/replace all

Execution

Lens.save() // Save current file Lens.run() // Execute as app

Git Shortcuts

Lens.commit('message') // Stage all + commit Lens.push() // Push to GitHub Lens.diff() // Show uncommitted changes Lens.gitStatus() // Git status Lens.log(5) // Last 5 commits

GitHub Integration

FunctionServer uses GitHub's Device Flow for easy authentication. No personal access tokens to copy—just click, enter a code, done.

1

Open GitHub Auth

Load the authentication app:

getFileFromDisk("~/github-auth.js").then(code => runApp(code, "github-auth.js"))
2

Click "Sign in with GitHub"

You'll see a code (like ABCD-1234). GitHub opens in a new tab.

3

Enter the code on GitHub

Paste the code, authorize FunctionServer for repo access. Done.

Now Lens.project() automatically creates repos on your GitHub account. Push and pull work without any configuration.

Visual Feedback: AI Eyes

When AI is working, humans can watch. The AI Eyes system shows what AI is looking at and editing:

  • Purple highlight box — AI is inspecting this element
  • Green flash — AI just edited here
  • Code region glow — AI is looking at these lines

You can watch the AI's "eyes" saccade across the screen as it navigates, searches, and edits. It's pair programming where you can see your partner's focus.

Error Awareness: Guardian

Guardian monitors console errors and can wake up AI to help:

// Guardian watches for errors automatically // When one occurs: // 1. A toast appears: "Error detected" // 2. User clicks "Get AI help" // 3. AI receives the error context // Check guardian status ALGO.guardian.status() // → {watching: true, suppressed: 0}

Throttling prevents flooding—repeated errors are deduplicated. The AI can offer help proactively when you hit problems.

The Feedback Loop

The happy path isn't just about saving tokens. It's about closing the feedback loop.

Traditional AI coding is open-loop: write code, hand it off, wait for human to report results. FunctionServer is closed-loop: write, execute, see result, adjust. All in the same context.

x Open Loop

AI writes code
 -> hands to user
   -> user runs it
     -> user describes error
       -> AI guesses fix
         -> repeat...

+ Closed Loop

AI writes code
 -> Lens.run()
   -> sees error directly
     -> Lens.code() to inspect
       -> Lens.setLine() to fix
         -> Lens.run() to verify

This is how humans debug. Now AI can debug the same way.

The Complete Workflow

Here's a full session: create a project, write code, debug, and ship to GitHub.

1

Create the project

Lens.project("particle simulator") // → Creates folder, git init, skeleton, GitHub repo, opens in Studio
2

Write code

Lens.code(1, 20) // See structure Lens.setLine(10, 'const N = 200;') // Edit Lens.insertLine(15, 'function update() {') // ... build up the file
3

Run and debug

Lens.run() // Execute // See error in console Lens.grep('undefined') // Find issue Lens.code(40, 5) // See context Lens.setLine(42, 'fixed code') // Fix Lens.run() // Verify
4

Ship it

Lens.save() Lens.commit("Add particle physics") Lens.push() // → github.com/username/particle-simulator

Key insight: At no point did we read an entire file. At no point did we rewrite an entire file. Every operation was surgical, verified, and cheap.

Best Practices

Use grep to find, not read

Don't read entire files to find a function. Use Lens.grep('pattern') to get line numbers, then Lens.code() to see context.

Save frequently

Lens.save() persists to disk. If the browser freezes, unsaved work is lost.

Batch operations when possible

Lens.batch([['setLine', 42, 'x'], ['save'], ['run']]) chains operations in one call.

Use Lens.state() to orient

Start sessions with Lens.state() to see what's open, what errors exist, and who's logged in.

Let Guardian help

When users hit errors, Guardian offers AI help. The AI can investigate and fix problems proactively.

Welcome to the Happy Path

The old way treats AI as a code generator: produces text, hopes it works.

The new way treats AI as a developer: one that can see, navigate, edit, run, debug, commit, and ship.

The feedback loop is closed. The tokens are minimal. The eyes are open.

Welcome to the happy path.