I run a small business on a dashboard I wrote myself. It runs on a PC in my room — no server bill, no managed database — and an AI agent edits it almost every day.

That setup broke in interesting ways. Every guardrail below exists because something went wrong first. After two months, these five are the ones I would put in on day one if I started again.

1. Split "deciding" from "touching"

src/lib/tasks-core.ts decides. pure functions, no fs, no fetch, no clock src/lib/store.ts touches. reads and writes files src/app/api/tasks/route.ts connects the two 

A pure function takes the current time as an argument instead of calling Date.now(). That sounds like a style preference until you hand the code to an agent.

Two things change:

Tests stop needing setup. No mocks, no temp directories — a decision function is called with values and checked against values.

You can scope what the agent sees. "Fix this decision function" is a much smaller blast radius than "fix this file that also writes to disk and calls three APIs". Most of my accidents stopped happening when the file an agent opened could not delete anything.

2. JSON files are fine as a database — if you handle three failure modes

I never set up Postgres for this. At my size, running it is the work. Files you can read with your eyes, diff in git and fix by hand are worth more than query features I do not use.

But three things will bite you:

A half-written file after a crash. Write to a temp path, then rename. Rename is atomic: the file is either the old content or the new one, never a truncated mix.

const tmp = `${file}.tmp-${process.pid}`; await fs.writeFile(tmp, JSON.stringify(value, null, 2), "utf8"); await fs.rename(tmp, file); 

Unreadable JSON taking the screen down. Never throw on read. Return the fallback and let the page render with one row missing.

try { return JSON.parse(await fs.readFile(path, "utf8")) as T; } catch { return fallback; } 

Losing the data to a git mistake. What a bad command destroys is never the code — it is the data you accumulated. Copy it outside the repository on a schedule, keeping generations.

That last one is not theoretical. A deploy script an agent wrote created a worktree, symlinked node_modules into it, and cleaned up with git worktree remove --force. Git for Windows follows junctions and deletes recursively, so it emptied the main checkout's node_modules. Recovery took 13 seconds (pnpm install --frozen-lockfile) only because the lockfile was committed. If that cleanup had pointed at my data directory, 13 seconds would have been 13 days.

3. One approval path, not two

Approvals arrive from two places here: a button on the dashboard, and a reply in a chat app. For a while each had its own logic. Then the chat path kept a rule the button had dropped, and the two disagreed about what "no answer" meant.

Both go through one pure function now:

export function nextAction(a: Approval | null, config: ApprovalConfig, nowMs: number): Next { if (!a) return { kind: "wait", untilMs: 0 }; if (a.decision === "ok") return { kind: "run", via: "human" }; if (a.decision === "ng") return { kind: "skip", via: "human" }; const deadline = a.askedMs + config.waitMin * 60_000; if (nowMs < deadline) return { kind: "wait", untilMs: deadline }; return config.silentDefault === "publish" ? { kind: "run", via: "silent" } : { kind: "skip", via: "silent" }; } 

Two entry points with two sets of rules means one of them is quietly out of date. You will not find out from a test. You will find out from the behaviour that surprised you.

4. Decide in advance what happens when nobody answers

This is the line that made the automation actually usable.

An approval that waits forever is an automation that stops getting used, because you are not watching most of the time. So every approval carries a wait window and a default:

  • reversible things (publishing a draft): no answer → do it
  • things that move money or leave the building: no answer → skip it

The distinction I settled on is not "important vs unimportant". It is can I undo this myself in a minute. If yes, let it run. If no, make it undoable first, then let it run.

5. Only what passes the gate ships

types → tests → build → swap the running app 

Nothing swaps unless all three pass. Before this existed, I read diffs. I am slower and less consistent than tsc.

There is one more line, and it is in the file I hand to the agent:

If it fails, fix it. If you cannot, report the failure as it is and stop. Do not claim success.

I added it after being told a build was done when it was failing. Models will narrate progress if nothing contradicts them. A gate contradicts them.

The thing I did not expect

I assumed the hard part of AI-assisted work would be code quality. It was not. The code was mostly fine.

The hard part was the gap between "the draft is ready" and "it is live" — the two minutes of copying, checking and clicking that I did by hand. The agent made the long part short and left the annoying part untouched, so finished work piled up unpublished for a month.

What fixed it was not a better prompt. It was treating publication as part of the loop, with an approval step and a default action attached.

If you want the skeleton rather than the story, I packaged the parts that are not specific to my business — the decision/IO split, the JSON store with those three guards, the approval logic, the backup and gate scripts, the Windows Task Scheduler registration, and the rules file I hand to the agent. Tests included, runs in 15 minutes.

Happy to answer anything in the comments — especially if you have hit a different failure mode. I would rather add a sixth guardrail from your accident than from mine.

Want this for your own shop or company?

The ops panel in this post connects to a POS, rolls up sales, food cost, labour and ordering, and pushes a summary to my phone every morning. It runs every day for two restaurants overseas.

How it works, and what it costs: https://opspanel-ai.github.io/ops-panel/?lang=en&utm_source=devto