Skip to content

Latest commit

 

History

History
539 lines (449 loc) · 23.9 KB

integration.md

File metadata and controls

539 lines (449 loc) · 23.9 KB

Integrating an Indie Box app with indie-feedback-loop

This guide is for the developer of an Indie Box app. It explains the two things an app can use, and how to set each one up:

  1. Feedback to issues. The app sends a person's report to the feedback judge. The judge decides whether it is a bug, a feature request or general feedback. It checks bugs and features against the app's code and files the ones that hold up as issues in the app's repository; general feedback goes to a shared feedback repository. Each filed issue can also be added to a tracking board (a GitHub Project).
  2. Issues to pull requests. When a maintainer adds the label implement-agent to an issue, the app repository's GitHub Actions run the implementation agent. It writes a test that reproduces the problem, fixes the code, proves the fix, and opens a draft pull request for a person to review.

The two parts are independent. An app can send feedback without using the implementation agent, and the agent works on any issue, including ones a person wrote by hand.

indie-chat is the reference app: its "Send feedback" form, its .indie-feedback-loop.yml and its test kit are working examples of everything below.


Part 1: Sending feedback to the judge

What you need

  • The judge's URL, for example https://feedback.example.com/feedback.
  • The shared secret (FEEDBACK_SECRET on the judge). Every app uses the same one.
  • Your app's registry id: the id of your app in the Indie Box registry (registry/registry.json.in in brainbot-com/indie-box), for example indie-chat or crefo-chat. The judge uses it to find your repository. See Registering the app.

The request

Send the report from your app's server, never directly from the browser: the secret must not reach the browser, and the fields that identify the sender must come from your server's session, not from what a browser sends.

POST /feedback
Host: feedback.example.com
Authorization: Bearer <FEEDBACK_SECRET>
Content-Type: application/json
{
  "version": 1,
  "app": "indie-chat",
  "id": "fb_0123456789abcdef",
  "sentAt": "2026-11-18T14:05:00Z",
  "deployment": "indie.chat",
  "commit": "c791a21",
  "sender": { "email": "person@example.com", "role": "member" },
  "report": {
    "what": "Test works for my own endpoint, but every chat message gets 401.",
    "expected": "Chat should use the key I entered."
  },
  "images": ["data:image/png;base64,iVBORw0KGgo..."],
  "video": "data:video/quicktime;base64,AAAAFGZ0eXBxdCAg...",
  "context": {
    "view": "agent", "agentName": "Writer", "appName": null, "appTemplate": null,
    "workspace": "General", "lang": "en", "theme": "dark",
    "userAgent": "Mozilla/5.0 ...", "viewport": "1440x900", "path": "/indie.chat.html"
  }
}

The fields

Field Required Filled in by Rule
version yes your server Always 1.
app yes your server Your registry id: lowercase letters, digits and -, at most 64 characters.
id yes your server fb_ followed by 16 lowercase hex characters, new for every report. The judge ignores a second report with an id it has already seen.
sentAt yes your server The time of sending, ISO 8601 (new Date().toISOString()).
deployment yes your server A human-readable name of this installation (for example the brand name), at most 200 characters.
commit yes your server The commit the running app was built from (letters, digits, ., _, -, at most 80 characters), or dev if unknown. The judge checks out this commit; with dev it reads the default branch.
sender yes your server email (at most 254 characters) and role (at most 20) of the signed-in person. Shown only in the footer of the GitHub issue, never to the model.
report.what yes the person What went wrong, 1 to 5,000 characters.
report.expected no the person What they expected instead, at most 5,000 characters.
images no the person At most 3 screenshots as data URLs (data:image/png, image/jpeg or image/webp, base64), each at most 2 MB after decoding. The judge's model looks at them. They are kept on the judge, not uploaded to GitHub.
video no the person One screen recording as a data URL: data:video/mp4, video/quicktime (MOV, what macOS records) or video/webm, base64, at most 25 MB after decoding. Its first bytes must match its type (ftyp at byte 4 for MP4 and MOV, 1A 45 DF A3 for WebM). The model cannot play video, so the judge takes at most 12 still frames from the first 3 minutes (where the picture changes, plus the first and last moment) and shows those, named by their time. The video and the frames are kept on the judge, not uploaded to GitHub.
context no your app Where the person was. Only the keys shown above are kept, each cut to 300 characters; other keys are dropped. All are optional.

Keep the whole body under 40 MB (a 25 MB video is about 34 MB as base64).

The answers

Status Body Meaning
202 { "id": "fb_..." } Queued. The judge works through reports one at a time; a verdict takes 1 to 3 minutes.
200 { "id": "fb_...", "duplicate": true } A report with this id was already received. Nothing new happens.
400 { "error": "..." } The payload is invalid, or app is not in the registry (unknown app "..."). Do not retry the same payload.
401 { "error": "unauthorized" } Wrong or missing secret.
413 { "error": "too large" } The body is over 40 MB.
503 { "error": "the app registry is unavailable, try again later" } The judge could not read the registry. Try again later.

The judge sends nothing back later. What happens to the report is visible in GitHub: a valid report becomes an issue with the label validated-feedback. Reports that are invalid, unclear or duplicates stay on the judge (DATA_DIR/reports/<id>/verdict.json).

GET /health answers { "ok": true, "queued": 0, "busy": false, "dryRun": false }.

Trying it with curl

curl -s https://feedback.example.com/feedback \
  -H "Authorization: Bearer $FEEDBACK_SECRET" \
  -H 'Content-Type: application/json' \
  -d '{
    "version": 1, "app": "indie-chat",
    "id": "fb_'"$(openssl rand -hex 8)"'",
    "sentAt": "'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'",
    "deployment": "test", "commit": "dev",
    "sender": { "email": "me@example.com", "role": "owner" },
    "report": { "what": "Describe a real problem here." }
  }'

A server-side example (Node)

This is the shape of indie-chat's POST /api/feedback (server.js, feedbackPayload), reduced to the essentials. The browser sends only what the person typed, the screenshots, the recording and the context; the server adds the rest.

import crypto from 'node:crypto';

const FEEDBACK_URL = process.env.FEEDBACK_WEBHOOK_URL;      // the judge's /feedback
const FEEDBACK_SECRET = process.env.FEEDBACK_WEBHOOK_SECRET;
const APP_ID = process.env.FEEDBACK_APP_ID || 'my-app';     // your registry id
const COMMIT = process.env.APP_COMMIT || 'dev';             // set at build time

app.post('/api/feedback', requireAuth, rateLimitPerUser, async (req, res) => {
  const { what, expected, images = [], video, context = {} } = req.body || {};
  if (typeof what !== 'string' || !what.trim()) return res.status(400).json({ error: 'Please say what went wrong.' });
  // validate lengths, images and the video here with the same limits as the table above

  const payload = {
    version: 1,
    app: APP_ID,
    id: 'fb_' + crypto.randomBytes(8).toString('hex'),
    sentAt: new Date().toISOString(),
    deployment: 'My App',
    commit: COMMIT,
    sender: { email: req.user.email, role: req.user.role },   // from the session, never from the browser
    report: { what: what.trim(), expected: (expected || '').trim() },
    images,
    ...(video ? { video } : {}),
    context,
  };
  const r = await fetch(FEEDBACK_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + FEEDBACK_SECRET },
    body: JSON.stringify(payload),
    signal: AbortSignal.timeout(60000),   // a report with a video takes longer to send
  }).catch(() => null);
  if (!r || !r.ok) return res.status(502).json({ error: 'The report could not be delivered. Please try again later.' });
  res.json({ ok: true, id: payload.id });
});

Recommendations:

  • Hide the form when FEEDBACK_WEBHOOK_URL is not set.
  • Accepting a video: give the feedback route a JSON body limit of about 40 MB (only that route), and ask people to record only the app's window, because a recording can show other windows and tabs.
  • Send a video only to a judge that accepts it: an older judge refuses any body over 10 MB. Update the judge first, then the apps.
  • Limit how often one person can send (indie-chat allows 5 per 10 minutes).
  • Tell the person on the form what is sent: their text, screenshots, recording, email and role, the page they were on, the app version, their browser and language.
  • Send once. If the judge does not answer with 2xx, tell the person to try again rather than retrying silently.

For indie-chat itself, three settings do all of this:

FEEDBACK_WEBHOOK_URL=https://feedback.example.com/feedback
FEEDBACK_WEBHOOK_SECRET=<the shared secret>
FEEDBACK_APP_ID=indie-chat        # a rebranded deployment sets its own id

Registering the app

The judge finds the repository for app in this order:

  1. The override file on the judge (APPS_OVERRIDE), a JSON object such as { "my-app": { "repo": "owner/my-app" } }. Use it for testing on a fork, or for an app that is not in the registry yet.
  2. The Indie Box registry: the entry with "id": "my-app" in registry/registry.json.in, and its source.repo. An app that is published to Indie Boxes is normally already there.

The judge's GitHub token must be able to read that repository and create issues in it. For a fine-grained token, add the repository to the token (Contents: read, Issues: read and write). The token also needs Contents: read on brainbot-com/indie-box to read the registry.

Apps built on another app. If your app's Dockerfile builds FROM the image of another registry app (for example FROM ghcr.io/brainbot-com/indie-chat), the judge also reads that app's code. If the cause of a problem is in the base app, the issue is filed in the base app's repository instead of yours. Nothing needs to be configured for this.


Part 2: Using the implementation agent in an app repository

What it does

When a maintainer adds the label implement-agent to an issue, a workflow in the app repository runs the indie-feedback-loop action. All work happens in the app repository's GitHub Actions, using its secrets and its Actions minutes.

It works on bugs and on feature requests (the label feature) the same way: for a bug the test reproduces the problem, for a feature request it checks the requested behaviour and fails because the feature is missing. Adding the label is the maintainer's decision to have the issue implemented.

Read the issue's acceptance criteria and "Scope" before adding the label: the agent implements exactly those, nothing more. If the request should also apply somewhere the issue does not name (for example agent chats as well as plain chats), edit the issue first.

  1. Check first (Claude Sonnet, read-only): is the problem still in the current code (or the feature still missing), is the issue clear enough to act on, and is it a safe change for one pull request? If any answer is no, the run stops and comments on the issue. Nothing is written.
  2. Implement (Claude Opus): write a test that reproduces the problem (or checks the requested feature), confirm the test fails, change the code, run the checks.
  3. Prove (the workflow itself, not the model):
    • no protected path was changed, and at least one new test file exists;
    • the new test fails on the code without the change;
    • the new test passes with the change;
    • the repository's checks and its whole test suite pass.
  4. Independent check (Claude Sonnet): does the test exercise the problem as reported (or the requested feature), is every acceptance criterion met, and does the change contain no file that is not part of it (a helper script or probe left behind)?
  5. One retry with the failure details, if step 3 or 4 fails.
  6. End to end (optional, see End-to-end tests): the repository's own tests against real services, run by the workflow with the secrets your configuration names.
  7. Proven: one commit on the branch implement/issue-<n> and a draft pull request that carries the proof. Not proven: a comment on the issue saying why, and nothing is pushed.

The issue text is treated as untrusted input. The model can use file tools and only the commands your .indie-feedback-loop.yml lists. It cannot push, cannot call GitHub, and the subscription token is removed from the environment of the commands it runs.

Step 1: Add .indie-feedback-loop.yml

Put this file at the root of the app repository. The full reference with comments is contract/indie-feedback-loop.yml.

# What the agents read first to understand the architecture.
docs: [CLAUDE.md]

setup:
  node: "22"            # a Node version (actions/setup-node); 22 is always installed
  # python: "3.12"      # actions/setup-python
  # uv: true            # astral-sh/setup-uv
  # pnpm: true          # corepack enable
  run:                  # commands that prepare the repo, in order
    - npm ci

# Must pass with the fix. The agent may run them as well.
checks:
  - npm run check

tests:
  run: npm test                 # the whole suite (required)
  one: node --test {file}       # one test file; {file} is replaced (required)
  dir: test/                    # where a new regression test goes (required)
  example: test/server.test.mjs # a test that shows how this repo tests (recommended)

# The agent must not change these. A change there is refused.
# Always protected as well: .github/, .env*, .indie-feedback-loop.yml
protected:
  - "**/package-lock.json"

Rules for the fields:

  • tests.run, tests.one and tests.dir are required. Without them the agent cannot prove a fix, so the run stops and comments on the issue.
  • Put {file} at the end of tests.one. The agent is allowed to run exactly that command with any file, and the rule is built from the part before {file}.
  • Each command must be a single line without backticks or $(...).
  • A new regression test must be a file in tests.dir whose name contains test or spec (for example test/issue-12.test.mjs or tests/test_issue_12.py).
  • During the proof, every change outside tests.dir is temporarily removed. Helpers the test needs must therefore already exist in the repository or be added inside tests.dir.

Examples for other stacks:

# Python with uv and pytest
docs: [README.md]
setup:
  python: "3.12"
  uv: true
  run: [uv sync]
checks: [uv run ruff check .]
tests:
  run: uv run pytest -q
  one: uv run pytest -q {file}
  dir: tests/
# TypeScript with pnpm and vitest
docs: [CLAUDE.md]
setup:
  node: "22"
  pnpm: true
  run: [pnpm install --frozen-lockfile]
checks: [pnpm typecheck]
tests:
  run: pnpm vitest run
  one: pnpm vitest run {file}
  dir: test/
protected: ["pnpm-lock.yaml"]

End-to-end tests

The proof in step 3 runs against stand-ins, so it cannot catch a problem that only the real service shows (for example a provider that rejects a request parameter). For that, a repository can add its own end-to-end tests against real services:

e2e:
  run: [npm run e2e]             # one or more commands
  secrets: [E2E_ANTHROPIC_KEY]   # Actions secrets of the repo, by name
  dir: e2e/                      # where the tests live
  required: true                 # false: report a failure but still open the PR

How the workflow treats them:

  • They run after the proof and the independent check, and only for a proven fix, in a separate step. Only the secrets named in e2e.secrets are in that step's environment; the model never sees them.
  • A secret named there that the repository does not have counts as a failure, not as a skipped check.
  • Their output goes into the pull request or the issue comment with every secret value replaced by [secret:NAME].
  • e2e.dir is protected: the agent cannot change these tests, and it cannot run them. People write and own them, because they run with real credentials.
  • If required is true (the default) and they fail, there is no pull request. Without an e2e section the pull request says "End to end: not checked".

Use a separate key with low limits for these tests, not a personal one. The caller workflow must pass the repository's secrets to the action (secrets: ${{ toJSON(secrets) }}, see Step 3); the action only reads the names you list.

Step 2: Give the agent a test it can copy

The agent writes a test that reproduces the reported problem. It does that much better when the repository already has one test that shows how to start the app and fake its outside dependencies. Name that test in tests.example.

indie-chat's example (test/helpers/server.mjs and test/server.test.mjs):

  • startServer({ env }) boots the real server on a free port, in a throwaway data folder, with one owner account and without the developer's .env;
  • startModel({ respond }) starts a stand-in OpenAI-compatible model on localhost that records every request and can answer with any status;
  • srv.login(), srv.api(path, { token, body }) and srv.chat(token, body) call the server the way the app does.

Tests must not use real external services or secrets. Use stand-ins like these.

Step 3: Add the workflow

Copy examples/caller.yml to .github/workflows/implement.yml and replace COMMIT with the full commit hash of indie-feedback-loop you want to run:

name: Implement issue

on:
  issues:
    types: [labeled]

permissions:
  contents: write
  pull-requests: write
  issues: write

jobs:
  implement:
    if: github.event.label.name == 'implement-agent' && !github.event.issue.pull_request
    runs-on: ubuntu-latest
    timeout-minutes: 90
    concurrency:
      group: implement-${{ github.event.issue.number }}
      cancel-in-progress: true
    steps:
      - uses: brainbot-com/indie-feedback-loop/.github/actions/implement@<full commit hash>
        with:
          issue: ${{ github.event.issue.number }}
          claude-code-oauth-token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
          github-token: ${{ github.token }}
          # for the end-to-end check: only the names in e2e.secrets are used
          secrets: ${{ toJSON(secrets) }}

Workflows that run on issues events are read from the default branch, so this file must be merged there before a label can start a run.

Step 4: Configure the repository

  1. Secret CLAUDE_CODE_OAUTH_TOKEN: run claude setup-token on your machine (it opens a browser sign-in and prints a token valid for one year), then:
    gh secret set CLAUDE_CODE_OAUTH_TOKEN -R <owner>/<repo>
    The agent's model use counts against that subscription's limits.
  2. Workflow permissions: Settings → Actions → General → Workflow permissions: "Read and write permissions", and tick "Allow GitHub Actions to create and approve pull requests". Or:
    gh api -X PUT repos/<owner>/<repo>/actions/permissions/workflow \
      -f default_workflow_permissions=write -F can_approve_pull_request_reviews=true
  3. Labels (bug usually exists already):
    gh label create implement-agent -R <owner>/<repo> --color 5319e7 \
      --description "Have the implementation agent open a draft PR"
    gh label create validated-feedback -R <owner>/<repo> --color 0e8a16
    gh label create feature -R <owner>/<repo> --color 1d76db
    The shared feedback repository needs validated-feedback and feedback.
  4. Forks: GitHub turns Actions and Issues off on a fork. Turn both on in the fork's settings.
  5. The tracking board (optional): the agent moves the issue's card to In Progress when it starts, and to In Review (a draft pull request was opened) or Blocked when it ends. The Actions GITHUB_TOKEN cannot change projects, so:
    • Create an environment feedback-board (Settings → Environments), with "Deployment branches: Selected branches → main" and no required reviewers. A label event runs the workflow from the default branch, so the agent can read the environment; a workflow on any other branch cannot.
    • Put the credential in it: the secret PROJECT_TOKEN (a classic token with only the project scope), or the variable BOARD_APP_ID and the secret BOARD_APP_KEY of a GitHub App with Projects read and write and Issues read, installed on the repository.
    • In implement.yml: environment: feedback-board on the job, and the inputs project-owner, project-number and project-token (or board-app-id and board-app-key), as in examples/caller.yml.
    • Protect the default branch (reviewed pull requests, CODEOWNERS for .github/), so nobody adds a workflow that reads the credential unreviewed. A failure to update the board is a warning in the run's log and never fails the run.

Step 5: Run it

gh issue edit <n> -R <owner>/<repo> --add-label implement-agent
gh run watch -R <owner>/<repo>

Only people who can add labels (triage or write access) can start a run. Adding the label again re-runs the agent and updates the same branch and pull request.

Reading the result

The run always ends with a comment on the issue, or a draft pull request.

Comment on the issue Meaning What to do
"opened a draft pull request with a proven change: #m" Proven. Review the pull request; its body shows the proof table and each acceptance criterion.
"checked this issue before implementing it and stopped" The check before implementing said no. The comment shows which question failed and why. Fix the issue text (or close the issue if the problem is gone) and add the label again.
"could not prove the change after 2 attempt(s)" The proof or the independent check failed twice. The comment shows the failing step and its output. Read the reasons; clarify the issue or fix it by hand.
"made no change" The agent changed nothing, usually because it could not reproduce the problem. Read the agent's explanation in the comment.
"did not finish" / "stopped with an error" Claude Code failed (for example the subscription's limit was reached) or a setup step failed. Open the run link in the comment.
"needs a valid .indie-feedback-loop.yml" The file is missing or invalid; the reason is in the comment. Fix the file on the default branch.

Updating indie-feedback-loop

The workflow is pinned to one commit of indie-feedback-loop. To use a newer version, replace the hash in .github/workflows/implement.yml with the new commit's full hash and merge that change.


Checklist

Feedback:

  • The app's registry id is known, and the judge can resolve it (registry or override).
  • The judge's token can read the app repository and create issues in it.
  • The app's server sends the payload with the shared secret and fills in app, id, sentAt, deployment, commit and sender itself.

Implementation agent:

  • .indie-feedback-loop.yml at the root, with tests.run, tests.one (ending in {file}) and tests.dir.
  • An example test that shows how to start the app with stand-ins.
  • .github/workflows/implement.yml on the default branch, pinned to an indie-feedback-loop commit.
  • Secret CLAUDE_CODE_OAUTH_TOKEN.
  • Workflow permissions: read and write, and pull requests allowed.
  • Labels implement-agent, validated-feedback and feature (and bug).
  • Optional board: the feedback-board environment (main only) with its credential, and the project-* inputs in implement.yml.