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>
9.5 KiB
Coucou Cloud
A Cloudflare Worker that runs the Mochis while the Mac is off, in a sandbox on Claude Managed Agents. What a Mochi made — a review, a reply on an issue, a draft PR — waits in Coucou until you click, or an Autonomous Mochi does it itself.
V0: your own Anthropic API key. Each session runs on the subscriber's own key, so Anthropic bills them directly. Coucou never pays for or resells Claude usage. See "Conditions d'Anthropic" in the Cloud spec.
Which Mochis, started by what
| Mochi | Starts on | Makes |
|---|---|---|
| PR Reviewer | a new PR (pull_request) |
a review, posted as a comment |
| Issue Triage | a new issue (issues.opened) |
a reply on the issue |
| Night Shift | its schedule (the oldest open issue with its label), or the label being added when it has no schedule | a draft PR with Closes #n |
| CI Fixer | a failed run on the default branch (workflow_run) |
a draft PR |
| Deps & Security | its schedule | a draft PR |
| Release Prep | a click on the Mac (POST /v1/mochis/:id/run) |
a draft PR |
| Ship Log | its schedule (the week's commits) | a text, nothing to post |
| Prod Watch | every 15 minutes, no AI, no session | a run when an address goes down or comes back |
Memory Gardener stays on the Mac: it works from your memory, which never leaves it. Schedules ("daily 01:30", "weekly mon 03:00"…) run in the time zone the Mac sends.
How a run goes
- Something starts it (above). Once per item — the PR's head commit, the issue, the CI run, the slot — and no more than the Mochi's runs a day.
- An agent and an environment are made once in the user's Anthropic organization. The session gets the repository cloned on the right commit (read-only, a token for that repository only), the prompt, and a spend ceiling.
- Every minute, the cron collects the finished sessions: cost, model calls, the final report. A Mochi that changes files is then asked to run the pack script (uploaded once to the user's organization, mounted in the sandbox): it writes every changed file to the session's outputs, where the Worker downloads them. Nothing is committed or pushed from the sandbox. A session still running after 30 minutes (60 for one that changes files) is stopped.
POST /v1/runs/:id/apply(your click in Coucou) posts the review or the reply, or makes the draft PR with GitHub's API — blobs, a tree on the commit it started from, a commit, a newmochi/…branch — as the Coucou Cloud app. Nothing touches the default branch, and nothing is posted without the click (or the Autonomous level).
What it keeps (D1)
- Your GitHub id and login.
- The hash of the token your Mac uses.
- Your Anthropic key, sealed with AES-GCM using a Worker secret.
- Your Cloud Mochis.
- Each run's result.
It never keeps your code: the repository is cloned inside Anthropic's sandbox,
not here. It keeps no logs (observability off).
Deploy (once)
In order: the Worker first (the GitHub App needs its address), then the
webhook secret, the app, its key, and the Mac. From this folder, on a Mac
(pbcopy and brain are Mac commands; on Linux, wl-copy or xclip do the
clipboard part).
- The Worker, on Cloudflare:
npm install npx wrangler login npx wrangler d1 create coucou-cloud # its database_id goes in wrangler.toml npm run db:init npx wrangler deploy # prints https://coucou-cloud.<you>.workers.dev openssl rand -base64 32 | npx wrangler secret put KEY_ENCRYPTION_KEY - The webhook secret. This command makes it, sends it to Cloudflare and
leaves it in the clipboard for step 3, without printing it:
Paste it into the app right away (step 3). Clipboard managers and Universal Clipboard can keep it, so clear it afterwards. Running the command again is fine as long as the secret that ends up in the app comes from the last run.
S=$(openssl rand -hex 32); printf %s "$S" | pbcopy; printf %s "$S" | npx wrangler secret put GITHUB_WEBHOOK_SECRET; unset S - The GitHub App: github.com → Settings → Developer settings → GitHub Apps → New.
- Name: "Coucou Cloud". Homepage: the repo URL.
- Webhook URL:
https://coucou-cloud.<you>.workers.dev/github/webhook. Webhook secret: paste it (Cmd+V). Afterwards,pbcopy < /dev/nullclears the clipboard. - Permissions:
- Repository → Pull requests: Read and write (reviews, the draft PRs);
- Contents: Read and write (the draft PRs' branches; the sandbox only ever gets read);
- Issues: Read and write (Night Shift and Issue Triage read them, the reply is posted);
- Actions: Read-only (CI Fixer reads the failed logs);
- Metadata: Read-only.
- Events: Pull request, Issues, Workflow run.
- Enable Device Flow, so the Mac can sign in.
- "Where can this GitHub App be installed?": Any account.
- Create it, and put its App ID in
GITHUB_APP_IDinwrangler.toml. Note its Client ID for step 6.
- The app's private key. On the app's page: Credentials → Key pairs →
New key. A
<app>.<date>.private-key.pemfile downloads. It goes to Cloudflare in PKCS#8, which WebCrypto reads, with no intermediate file. The command only takes a key downloaded in the last 30 minutes, says which one, and deletes it only if both conversion and upload worked. It runs in a subshell, sopipefailandfdon't stay in your terminal:Then deploy again, so the App ID is taken:( set -o pipefail; f=$(find ~/Downloads -maxdepth 1 -name '*private-key.pem' -mmin -30 | head -1); [ -n "$f" ] || { echo "No private key downloaded in ~/Downloads in the last 30 minutes"; exit 1; }; echo "Key: $f"; openssl pkcs8 -topk8 -nocrypt -in "$f" | npx wrangler secret put GITHUB_APP_PRIVATE_KEY && rm "$f" )npx wrangler deploy. - Install the app on the repositories the Mochis should watch. Check it: the app's Advanced tab lists the deliveries, with a green tick when the Worker took them. A 401 means the two webhook secrets differ: run step 2 again, paste the new secret into the app (General → Webhook → Change secret), then Redeliver the failed delivery to see the tick.
- The Mac.
brain cloud keysends the Anthropic API key stored bybrain mochi key, so that one comes first:The next pull request is reviewed in the Cloud.brain mochi key brain cloud login --url https://coucou-cloud.<you>.workers.dev --client-id <Client ID> brain cloud key brain cloud add pr-reviewerbrain cloud runslists it a minute or two later.
Billing (Stripe)
Without STRIPE_SECRET_KEY, billing is off and every signed-in user may run in the Cloud (development).
With it, a user's Mochis run in the Cloud only with an active subscription, or when their GitHub login
is in COMP_LOGINS (wrangler.toml).
The offers live in src/billing.ts (PLANS); the app shows what GET /v1/plans says. Today only
Cloud · your key ($9/month, the AI on the user's own Anthropic key) can be bought; Solo, Pro and Max
are listed as coming. Stripe direct, under the VAT franchise: no VAT, and every invoice carries
INVOICE_FOOTER (« TVA non applicable, article 293 B du CGI »). STRIPE_TAX = "1" turns Stripe Tax on.
Once per mode, test first, then live, from cloud/. Best with a restricted key (rk_…, Developers › API keys ›
Create restricted key) allowed only: Customers, Checkout Sessions, Customer portal, Subscriptions (read),
Products, Prices, Webhook Endpoints (write for the rest).
- The secret key, typed, never in a file:
npx wrangler secret put STRIPE_SECRET_KEY - The same key for the setup script, without echo:
read -rs STRIPE_SECRET_KEY && export STRIPE_SECRET_KEY - The price, the customer portal and the webhook; its signing secret goes straight to the Worker:
node scripts/stripe-setup.mjs https://coucou-cloud.<you>.workers.dev | npx wrangler secret put STRIPE_WEBHOOK_SECRET unset STRIPE_SECRET_KEY, thennpx wrangler deploy
In the Stripe Dashboard, once: the business name, address and SIRET under Settings › Business (they go on every invoice), and Settings › Customer emails › « Successful payments » so receipts are sent.
API (for the Mac)
| Route | Body | Answer |
|---|---|---|
POST /v1/login |
{ github_token }, a user token from the app's device flow |
{ token, login, installations } |
PUT /v1/anthropic-key |
{ key, language } |
checked against Anthropic, then sealed |
PUT /v1/mochis |
{ tz, mochis: [{ id, name, repo: "owner/name", trigger, kind, tools, schedule, label, urls, instructions, model, budget_cents, per_day, enabled, autonomous }] } |
replaces the user's Cloud Mochis (as many as the offer allows) |
POST /v1/mochis/:id/run |
the run started, or { nothing: true } |
|
GET /v1/runs?since=ISO |
{ runs: [...] }, newest first, with proposal, proposal_state, trigger, item_url |
|
POST /v1/runs/:id/apply |
{ url } of the review, the reply or the draft PR |
|
POST /v1/runs/:id/discard |
Every /v1/ route except login takes Authorization: Bearer <token>.
Code
src/index.ts: routes and the cron.src/engine.ts: start, collect, apply.src/github.ts: GitHub calls.src/crypto.ts: webhook signature, app JWT, sealing.
The prompt and the Managed Agents requests come from the brain
(brain/src/prompt-core.ts, brain/src/cloud-core.ts). A review is written
the same way on the Mac (brain cloud try) and in the Cloud.
Tests: npm test. They use SQLite in memory for D1 and a fake fetch for
GitHub and Anthropic.