Files
LouisandClaude 3a7eaba620 Coucou Cloud: every ready-made Mochi but the Memory Gardener (#1248)
The Cloud ran only PR Reviewer. It now runs what each Mochi needs:
- GitHub events: new PR (PR Reviewer), new issue (Issue Triage), an issue
  labelled for an unscheduled Night Shift, a failed run on the default
  branch (CI Fixer, its failed logs in the prompt);
- schedules in the user's time zone, once per slot (Night Shift takes the
  oldest labelled issue it hasn't worked on, Deps & Security, Ship Log from
  the week's commits);
- a click on the Mac (POST /v1/mochis/:id/run: Release Prep, or any of them now);
- Prod Watch every 15 minutes, no AI, a run only when an address changes.

A Mochi that changes files is asked, once its report is written, to run a
pack script mounted in the sandbox: the changed files go to the session's
outputs and the Worker keeps them until the click, which makes the draft PR
with GitHub's API (blobs, tree, commit, a mochi/ branch, the PR). Nothing is
pushed from the sandbox, which keeps read-only tokens; each GitHub token asks
only what its step needs. Issue Triage's reply is posted on the issue.

Mac: brain 0.9.1 sends kind, tools, schedule, label, addresses, runs a day
and the time zone; a Cloud Mochi no longer runs on the Mac's schedule, Run
now goes to the Cloud, turning one on or off reaches the Cloud, and Cloud
runs keep their link and what started them. The Cloud page lists Prod Watch
and says why a Mochi stays on the Mac.


Claude-Session: https://claude.ai/code/session_01LJm3SRL9k3gBPaVtfPhwcT

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-01 15:22:48 +00:00

101 lines
3.2 KiB
SQL

-- Coucou Cloud. `npm run db:init` once, after `wrangler d1 create coucou-cloud`.
-- A Coucou user: who they are on GitHub, the hash of the token their Mac uses, their Anthropic key (encrypted).
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
github_id INTEGER NOT NULL UNIQUE,
login TEXT NOT NULL,
token_hash TEXT UNIQUE,
anthropic_key TEXT,
language TEXT NOT NULL DEFAULT 'fr',
created_at TEXT NOT NULL,
-- Stripe (billing.ts): the customer, the offer, its state and when it renews
stripe_customer_id TEXT,
plan TEXT,
plan_status TEXT,
plan_renews_at TEXT,
plan_cancels INTEGER
);
-- Where the GitHub App is installed, and by whom.
CREATE TABLE IF NOT EXISTS installations (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
account TEXT NOT NULL
);
-- The Mochis a user turned on in the Cloud (sent by their Mac).
CREATE TABLE IF NOT EXISTS mochis (
user_id INTEGER NOT NULL,
id TEXT NOT NULL,
name TEXT NOT NULL,
repo TEXT NOT NULL,
trigger TEXT NOT NULL,
instructions TEXT NOT NULL,
model TEXT NOT NULL,
budget_cents INTEGER NOT NULL,
enabled INTEGER NOT NULL,
-- 1: it does it on its own (posts the review or the reply, opens the draft PR), no click
autonomous INTEGER NOT NULL DEFAULT 0,
-- repo (works in a copy of the repo), brief (Ship Log), watch (Prod Watch)
kind TEXT NOT NULL DEFAULT 'repo',
-- write: its changes become a draft PR · read: it only reads
tools TEXT NOT NULL DEFAULT 'read',
-- "daily 01:30", "weekly mon 03:00"… or "manual", in tz
schedule TEXT NOT NULL DEFAULT 'manual',
-- Night Shift: the label of the issues it picks
label TEXT NOT NULL DEFAULT 'mochi',
-- Prod Watch: its addresses (JSON)
urls TEXT NOT NULL DEFAULT '[]',
tz TEXT NOT NULL DEFAULT 'UTC',
-- runs a day at most
per_day INTEGER NOT NULL DEFAULT 10,
PRIMARY KEY (user_id, id)
);
-- Agent and environment ids made in the user's Anthropic organization, kept to be reused.
CREATE TABLE IF NOT EXISTS ids (
user_id INTEGER NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
PRIMARY KEY (user_id, key)
);
-- Each run: its session, what it cost, what it wrote, and the proposal waiting for a click.
CREATE TABLE IF NOT EXISTS runs (
id TEXT PRIMARY KEY,
user_id INTEGER NOT NULL,
mochi_id TEXT NOT NULL,
repo TEXT NOT NULL,
item_type TEXT NOT NULL,
item_number INTEGER,
item_title TEXT,
sha TEXT,
session_id TEXT,
status TEXT NOT NULL,
started_at TEXT NOT NULL,
finished_at TEXT,
cost_usd REAL,
turns INTEGER,
active_seconds REAL,
text TEXT,
proposal TEXT,
proposal_state TEXT,
proposal_url TEXT,
-- 1: done (or tried) on its own, by an autonomous Mochi
auto INTEGER,
error TEXT,
-- github, schedule, manual, watch
trigger TEXT,
item_url TEXT,
-- the commit it started on and the default branch: a draft PR is made on them
base_sha TEXT,
base_ref TEXT,
-- a Mochi that changes files: the report while it packs, then its changes until the click
report TEXT,
changes TEXT,
UNIQUE (user_id, mochi_id, repo, item_number, sha)
);
CREATE INDEX IF NOT EXISTS runs_status ON runs (status);
CREATE INDEX IF NOT EXISTS runs_user ON runs (user_id, started_at);