Skip to content

Latest commit

 

History

History
179 lines (176 loc) · 17.8 KB

AGENTS.md

File metadata and controls

179 lines (176 loc) · 17.8 KB

VisualCI

Visual regression testing for documents first (PDFs and their pages), plus browser and mobile screenshots. The design is in docs/design.md; read it before changing the architecture, and update it in the same change when you do.

Rules

  • Never push to main; every change goes through a pull request. A ruleset on main requires the CI jobs and the VisualCI check, which stays pending until the PR's VisualCI build is reviewed. Before you merge:
    1. Wait for CI. Then review the PR's build over VisualCI's MCP server (list_builds for the branch, get_build, get_snapshot; contact_sheet for many screenshots), the way our customers' agents do.
    2. Approve changes the PR meant to make (review). Fix the code and push again for anything it didn't mean: a page that looks broken is a regression even when CI is green.
    3. Merge with scripts/agents/merge-pr.sh (below) once every check is green. If it stops because a VisualCI build waits for review, that's the review you skipped. Never bypass the ruleset. (1 Dec 2026, unreviewed builds let a CSS break from three merges reach production.)
  • Git hooks format your commits: install them once per clone with mise install && lefthook install (the hooks live in the clone's shared .git/hooks, so its worktrees all get them; lefthook.yml lists them). The pre-commit hook runs the formatters on the staged files and stages what they change. CI has no format check (Nathan, 5 Dec 2026, sc-9611), so a commit made without the hooks lands unformatted: never commit with --no-verify.
  • Workflows, secrets, spelling, JS/TS and shell scripts are checked by CI's security job and the pre-commit hook: actionlint, zizmor, Betterleaks, typos (_typos.toml), oxlint (.oxlintrc.json) and ShellCheck (scripts/ci/shellcheck.sh); mise.toml pins them. The typos hook only checks (it never rewrites what you tested): fix what it names, or run mise run fix-typos. Keep a misspelling a test needs on purpose with a spellchecker:disable-line comment as the very last thing on its line (# ... or // ..., the reason before it); for a word used in many places, or a file without # or // comments (Markdown, CSS, HTML), an extend-ignore-re entry in _typos.toml with the reason. Encode test bytes in the test (STANDARD.encode(b"…")) rather than pasting base64, which typos reads as words.
  • Source files stay under 500 lines (1,000 for tests and migrations; scripts/ci/check_file_length.py). The files that were already longer have their own caps in scripts/ci/file_lengths.txt: split one rather than grow it past its cap, never raise a cap (CI fails until you lower one whose file shrank), and delete its line once it's under the limit. Every lint suppression (#[allow(...)], @ts-expect-error, # noqa, a zizmor ignore and the rest) is listed in scripts/ci/suppressions.txt with its reason, added in the change that adds it (scripts/ci/check_suppressions.py). Fix what a lint finds before you reach for a suppression.
  • Unused code fails CI: cargo-shear fails on unused Rust dependencies in the three workspaces (lint job; its unlinked-file warnings don't fail), and Knip on unused files and dependencies in frontend/ (knip.jsonc, clients job; unused exports are reported only, for now). Delete what they find; ignore something only in their config, with the reason beside it.
  • Links are checked by lychee (lychee.toml): CI's clients job checks every page, file and #anchor the built site links to, offline, so a broken internal link fails the build that makes it. The Audit workflow checks every link on the live site, outside ones included, each night. Exclude a link in lychee.toml only with the reason beside it.
  • CLI releases carry build provenance: release.yml's build job attests each archive (actions/attest-build-provenance), so gh attestation verify visualci-<target>.tar.gz -R DocSpring/visualci proves a download was built by this repo's release workflow. The commit it names is main's tip when the release started, which can be later than the commit built if someone pushed meanwhile. Keep the attestation step when changing how the archives are built or named. Allow a word or turn a lint rule off for a file only in those files, with the reason beside it. Pin every action by commit SHA with its version in a comment (pinact run does it). Ignore a zizmor finding only inline (# zizmor: ignore[audit]) with the reason beside it; allow a made-up value in .betterleaks.toml only with a description of what it is. A real secret that reached a commit is revoked, not allowlisted.
  • Dependencies are audited by the Audit workflow (on pull requests and daily on main): cargo-deny for the Rust workspaces (a deny.toml beside each manifest: advisories, licences, sources) and Trivy for every lockfile. Fix a finding by upgrading. An ignore says why it doesn't apply: in deny.toml with a reason, in .trivyignore.yaml with a statement and an expired_at at most six months out. A new dependency licence goes into deny.toml's allow list only after a look (no copyleft in the CLI or the images). In deny.toml, ignores and licences nothing uses any more fail the job: remove them.
  • Images are linted and scanned. hadolint checks the Dockerfiles (.hadolint.yaml), and Trivy scans the built images in CI's images job: fixable HIGH/CRITICAL vulnerabilities and forbidden licences fail a pull request (on main they only report, and the Audit workflow scans the live app image daily). The Dockerfiles' FROM lines keep plain tags: CI replaces each with the digest-pinned mirror copy (build-contexts, .github/mirror.txt), whose digests are linux/amd64 only, so pinning them in FROM would break local builds on arm64. The app's runtime stage takes Debian's security updates on every build. The renderer doesn't: its packages (fonts, MuPDF, Java and their libraries) come from snapshot.debian.org at DEBIAN_SNAPSHOT in docker/renderer.Dockerfile, so a rebuild installs the same versions and can't move pixels by itself (sc-10019). Moving that date, or editing anything that changes how a page is drawn (docker/renderer/, PDFBox's version), means a docker/renderer.version bump, which redraws every customer's PDFs (their bases too): compare the old and new images' PNGs byte for byte on real PDFs first.
  • Merge only with scripts/agents/merge-pr.sh <pr>, run in the background from the PR's checkout; its header gives the steps and exit codes. Run scripts/agents/merge-pr.sh <pr> --go when the pushed commit's VisualCI check run or CI workflow run completes, whichever comes last. A PR must be up to date with main to merge, so each merge sends every other PR back through CI. The script holds Fleetlayer's main-merge lock from the last rebase to the merge, for one CI run, and releases it however it ends (3 Dec 2026: two agents' merges kept making each other's green PRs out of date). What it can't do for you:
    • Start it only when the PR is green and its latest VisualCI builds are reviewed, never to wait for a review or a fix. (5 Dec 2026: a lock held two hours while a PR stayed red stopped every other merge.)
    • When the rebased commit's CI run finishes, look at its VisualCI builds at once (VisualCI's MCP: list_builds with waiting_for_review, or whoami) and review them: the VisualCI check stays pending until then, and waiting on it let the lock run out (5 Dec 2026, #278). Changes your PR didn't make (main's, inherited) are reviewed after a --release, outside the lock.
    • Don't merge any other way: no bare fleetlayer lease acquire (a lock that expires unreleased pages Fleetlayer for 30 minutes; 4 and 5 Dec 2026) and no gh pr merge --delete-branch. The repository deletes a merged branch itself, and GitHub then moves a PR stacked on it onto main; a branch the client deletes closes that PR instead (5 Dec 2026, #259 closed when #257 merged).
  • Experiment on a local VisualCI, never on production. Run replays, load tests and odd inputs (broken PDFs, huge builds, long MCP waits) against a VisualCI on docspring-dev or an agent box, not app.visualci.com. When production is the only way, tell the coordinator first and silence or annotate the alerts it will fire. (5 Dec 2026: three production alerts, Sentry VISUALCI-PROD-SERVER-7 and -8 and VisualCIRendersFailing, came from our own replays.)
  • Wait on CI through Fleetlayer's messages; never poll GitHub. Every agent's gh shares Nathan's one GitHub account and its 5,000 API calls an hour, and on 4 Dec 2026 polling used them up and blocked every session's gh. No gh run watch, gh pr checks --watch or loop of gh calls, however slow. After a push, fleetlayer subscribe ci --commit in the checkout brings each workflow's result as a message, ends by itself, and says so if nothing came within 45 minutes. merge-pr.sh subscribes to the branch's check runs itself. Don't act on VisualCI's check suite completing: it can arrive before the last build's check has posted.
  • A change people using VisualCI can see (a feature, a fix they'd notice, a CLI release, a setting, a price) gets a changelog entry in the same PR: its own file in frontend/content/changelog/, which node scripts/changelog-entry.mjs <slug> "<text>" (in frontend) names with New Zealand's date and time. The build assembles the days (scripts/changelog.mjs), so entries from parallel PRs never conflict; don't edit frontend/content/changelog.md, which holds only the intro. CI fails a PR whose new entry is dated before yesterday: rename it to today's date and time before it merges. Internal work (tests, CI, refactors, staff tools) doesn't get one.
  • No backwards compatibility before launch. There are no old setups to keep working: rename, change formats and drop old behaviour outright, with no redirects, aliases, fallbacks or shims for the old way (Nathan, 1 Dec 2026).
  • plugin/skills/ is generated from the docs pages with skill: front matter. After editing such a page, run node scripts/skills.mjs in frontend and commit plugin/ and the files it writes; CI fails when they differ. The plugin has no version to bump: Claude Code versions it by its commit, so every commit to main is a new version (installed plugins pick it up with auto-update or claude plugin update), and --check fails when plugin.json gets a version back. plugin/ may hold only Markdown, text, JSON, YAML and images: the Claude plugin directory refuses anything else from an unverified organization.
  • A change to the CLI (crates/visualci-cli or crates/visualci-core) bumps the workspace version in Cargo.toml and Cargo.lock's visualci-* entries, and the version defaults in clients/github-action/action.yml and clients/circleci-orb/orb.yml. CI's cli-version job fails without them; once CI passes on main, the release workflow publishes it once production serves that commit (it waits up to 20 minutes, then fails). The docs never name a CLI version: they write {{cli_version}} (VISUALCI_VERSION={{cli_version}}, github-action@v{{cli_version}}), which the site build fills in with the newest published release (frontend/scripts/cli-version.mjs), so they never pin an old CLI or one nobody can download yet.
  • Fixtures are test data only: synthetic values, or blank template PDFs someone has checked. Never commit a real customer's document or data.
  • Build Rust in CI or on a build machine (docspring-dev), not on small agent VMs. The server is app/ (Laravel Rust, visualci-app in the root workspace, with the CLI and its crates in crates/, whose tests need no database). scripts/on-dev test runs the crates' tests. app/'s (cargo test -p visualci-app) need Postgres and a blob store: run them with scripts/on-dev run naming VISUALCI_APP_TEST_DATABASE_URL=postgres://...@127.0.0.1:55433/visualci_app_test_<story>. On docspring-dev that's its own Postgres (a database of your own per story). On a pool box the run starts its own Postgres and RustFS in Docker, points the command at them, and removes them when it ends.
  • VisualCI dev ports on docspring-dev: the app 5250 (SERVER_PORT=5250, which the Vite proxy defaults to), Vite 5173, previews 5180–5199. 5150 is Talira's dev server: never use it (on 1 Dec 2026 a VisualCI dev server took it, and Talira's localhost and MCP reached VisualCI instead). Production listens on 5150 inside its cluster, which is separate.
  • Any UI design (the landing page, the review UI, emails): load the hallmark skill and the frontend design skills before writing markup or CSS.
  • A test never skips quietly. When a service it needs (the blob store, Postgres, a forge stub) is missing, it fails with a message naming the service: a test that returns early passes in CI. (3 Dec 2026: the server tests that need blobs returned early in CI's test job, which runs no S3, and passed without checking anything.)
  • Migrations run before the rollout, so for a few seconds the previous release serves against the new schema. A migration must work with the code before it: add the new column and copy the data in one change, stop reading the old one in the same change, and drop or rename it in a later change. A required column gets a default. CI's migrations job runs scripts/ci/migration_safety.py, which fails a new migration that drops, renames or retypes anything main's code still names. This is deploy safety, not backwards compatibility: the old column still goes, one release later. (4 Dec 2026, a dropped organizations column failed every request for ~20 s, a new user's first build among them.)
  • Migrations run in file-name order and the database records each by name. Name a new one YYYY_MM_DD_HHMMSS_snake_case.rs with a timestamp after every migration on main, and never rename or delete one that is on main. If another branch's migration merged first with a later timestamp, rename yours to a newer one before merging. A migration on main is never edited either (deployed databases won't run it again): fix it with a new one. scripts/ci/check_migrations.sh checks all of this in CI's migrations job.
  • New migrations are linted by Squawk (.squawk.toml, scripts/ci/squawk_migrations.sh, in the hook and the migrations job): start each with SET LOCAL lock_timeout = '5s';, and add a foreign key to an existing table NOT VALID, then VALIDATE it in a later migration. Silence a finding only with -- squawk-ignore <rule> above the statement, listed with its reason in scripts/ci/suppressions.txt.
  • The server connects with sqlx's prepared-statement cache off (config::without_statement_cache): a migration that adds a column makes Postgres refuse an old pod's cached SELECT table.* ("cached plan must not change result type"). Keep it off. tests/rollouts.rs fails if it comes back on. (4 Dec 2026, #178's rollout.)
  • Every background process (workers, renderers, scheduled jobs) ships with a health check or heartbeat that checks the work is done, not just that the process is up, in the same change.
  • Production reads its secrets from 1Password through the cluster's ExternalSecrets (talira-ai/infra, k3s/resources/visualci/secrets.yaml). Before moving, renaming or deleting one of those items, or changing a field name, tell the talira infra@agents-talira session so the ExternalSecret changes first: a missing item fails every deploy until it does (1 Dec 2026, a vault move held back three releases).
  • Deploys: CI pushes the image digest to talira-ai/infra, and ArgoCD polls it every 60 s. A release normally reaches production (https://api.visualci.com/status commit) within about 3 minutes of CI's deploy job. Only call a rollout stuck after that, and then ask talira infra@agents-talira. The API is on api.visualci.com: the app host returns 404 for /api/v1/* on purpose.
  • Renderers handle untrusted input: they run only on the render node, under gVisor, with no network and no service-account token.
  • serde_json's arbitrary_precision feature is on in app/'s build, so a number inside #[serde(untagged)] or #[serde(flatten)] fails to deserialize (it arrives as a map, not a number). Read such bodies through serde_json::Value (domain::lenient). Tests that build the struct directly won't catch it (4 Dec 2026, visualci.yml thresholds and update_project floats).
  • Code in a bare tokio::spawn task has no app context: laravel::now(), the database and the cache panic there. Use laravel::task::spawn or context.scope, and spawn_blocking only for pure CPU work on plain data (decoding images). Integration tests run inside an app context and won't catch it.
  • Before building something other Laravel Rust apps also need (R2 presigned uploads, API key hashing or metering, sitemaps, OG images, cookie consent, PostHog, Resend, Polar billing), search Talira and check kitze's packages (github.com/kitze/laravel-rust-*) first. Keep VisualCI's own OAuth and MCP code (Nathan, 4 Dec 2026).
  • Dependency updates come from self-hosted Renovate (.github/workflows/renovate.yml, renovate.json), signed in as the DocSpring GitHub App "DocSpring Renovate": its client ID in the repo variable RENOVATE_APP_CLIENT_ID, private key in the secret RENOVATE_APP_PRIVATE_KEY and in 1Password docspring-renovate-app-private-key (nathans-ai-agents). The app is installed only on repos that use it; another DocSpring repo opts in by being added to the installation and copying the workflow. Updates wait 7 days after release, and routine PRs open on Tuesday mornings (Auckland). Nothing automerges: merge a Renovate PR like any other (CI, the VisualCI review, the main-merge lease). Base images are bumped by hand in .github/mirror.txt, as is the Rust toolchain. Rust dependency updates wait for a tick on the dependency dashboard, because any change to the root Cargo.toml or Cargo.lock rebuilds the renderer.