Add it when you need it

FreeAgent

Mirrors each organisation’s FreeAgent company (UK accounting) into your app, for pages, agents, analytics and the plugins you build on top. An admin approves it once, over OAuth.

Installing it

zsh — your app
pnpm plugin add https://github.com/rocketflare-dev/rocketflare-plugins.git@freeagent-v3.17.0 --subdir plugins/freeagentpnpm plugin add https://github.com/rocketflare-dev/rocketflare-plugins.git@freeagent-v3.17.0 --subdir plugins/freeagent --apply
The first prints the plan and stops; the second writes it.

Then generate and run its migration — pnpm db:generate --name plugin-freeagent-3.17.0 and pnpm db:migrate — and do the handful of steps the plan lists that a plugin may not do for you.

What it adds

  • A connection per organisation — Settings → FreeAgent: one company each, approved once over OAuth, with its tokens stored sealed. A refused refresh token marks the connection as needing to be reconnected.
  • Incremental sync — hourly, after connecting and on Sync now: bank accounts, transactions, explanations, categories, contacts, bills and invoices. The first sync reaches back about 400 days.
  • A FreeAgent page — unexplained transactions and invoices, with an overdue filter. Every member can see it; owners and admins connect, disconnect and sync.
  • Agent tools — five that read the mirror, and two that write: freeagent_explain_transaction and freeagent_create_bill, offered only to admins and waiting for a person to approve each call.
  • A service API and an extension — other plugins explain transactions, attach receipts and create bills through exported functions, and hear about every sync through freeagent:sync-listeners.
  • Analytics cubes — when the analytics plugin is installed: spend and income by month and category, unexplained count and amount, outstanding and overdue. Inert without it.
  • Nine tables — a connection, a sync state and seven mirror tables, all with row-level security, and money stored as numeric.
  • Commands and a skill — rocketflare freeagent status and sync, and /freeagent, which walks through registering the app, secrets, connecting and troubleshooting.

Releases

  1. 3.17.0 2026-11-28

    FreeAgent stops for an organisation that turned it off (kit 0.48.0's kill switch), including when another plugin calls its service API, and pnpm plugin check no longer warns about it. The plugin needs kit 0.48.0 or later. Porting note.

  2. 3.16.0 2026-11-28

    The sync cron runs hourly, at 18 * * * *, instead of every 30 minutes (*/30 * * * *). Porting note.

  3. 3.15.0 2026-11-28

    FreeAgent's tools answer egress and readsContent, so pnpm plugin check no longer warns about them, and the plugin needs kit 0.47.0 or later. Porting note.

  4. 3.14.0 2026-11-22

    FreeAgent's pager reads a single-quoted rel='next', so a mirrored list no longer stops after 100 rows; a full resync re-reads what it missed, and tools register under tools (kit 0.41.0) (#38). Porting note.

  5. 3.13.3 2026-11-22

    No change to freeagent: this release carries the global-search and connectors test changes, and every plugin in this repository ships at one version. Porting note.

9 older releases
  1. 3.13.2 2026-11-21

    The freeagent manifest now carries a one-line description, which the kit's pnpm plugin list --available prints in place of the README's opening line. Porting note.

  2. 3.13.1 2026-11-21

    No change to freeagent: this release exists because the repository released analytics and every plugin here ships at the repository's version. Porting note.

  3. 3.13.0 2026-11-20

    No change to freeagent's behaviour: this release exists because the repository released analytics and every plugin here ships at the repository's version, and it carries one test-only lint fix. Porting note.

  4. 3.9.0 2026-11-09

    FreeAgent write tools now follow the requester's manage permission, and the OAuth callback re-reads the admin who started it. Porting note.

  5. 3.8.2 2026-11-08

    freeagent typechecks on kit 0.25.0 and later again: its two schema-parsing helpers named zod 3's z.ZodTypeDef, which zod 4 (the kit's from 0.25.0) does not have. Porting note.

  6. 3.8.1 2026-11-03

    No change to freeagent. This release exists because analytics scopes GET /api/analytics/facts/status to the caller's organisation, and every plugin here ships at the repository's version. Porting note.

  7. 3.8.0 2026-11-03

    No change to freeagent. This release exists because analytics moves to drizzle-cube 0.12.2 and compiles on React 19 with React Router 7, and every plugin here ships at the repository's version. Porting note.

  8. 3.7.0 2026-10-24

    No code change to freeagent. The duplicated docs/plugins/freeagent/upgrades/ copy inside the plugin directory, left there by pnpm plugin export in 3.6.0, is removed. Porting note.

  9. 3.6.0 2026-10-24

    First release of freeagent: an organisation connects its FreeAgent company over OAuth, and its books are mirrored every 30 minutes for pages, agents, analytics and other plugins. Porting note.

From the README

Synced from the plugin's README — the plugin's own documentation, kept in step with its repository.

An admin approves your FreeAgent app once, over OAuth. Every hour the plugin syncs the company’s bank accounts, bank transactions, explanations, categories, contacts, bills and invoices into tenant-scoped freeagent_* tables, incrementally. Agents read that mirror and can propose an explanation or a bill for a person to approve. Other plugins — a receipts matcher, say — explain transactions and attach receipts through an exported service API, and hear about every sync through the freeagent:sync-listeners extension.

What it adds

AreaWhat you get
ConnectionOne FreeAgent company per organisation. OAuth approval through POST /api/freeagent/connect and the public callback /api/hooks/freeagent/callback (signed state). Refresh and access tokens stored sealed. A refused refresh token marks the connection needs reconnecting
Syncfreeagent.sync, queued hourly (18 * * * *) per connected organisation, after connecting, and by Sync now. Incremental by updated_since, paged, across every bank account. The first sync reaches back about 400 days for transactions
ClientOne typed wrapper: always X-Api-Version: 2026-09-01, token refresh 2 minutes before expiry (single-flight), bounded back-off on 429 Retry-After, Link pagination, typed FreeAgentError, and the token never sent off the FreeAgent API host
UISettings → FreeAgent: connect, reconnect, disconnect, environment, company, last sync, errors, Sync now. FreeAgent page: unexplained transactions and invoices (overdue filter)
Agent toolsRead: freeagent_company, freeagent_search_transactions, freeagent_list_categories, freeagent_list_invoices, freeagent_list_bills. Write, approval required: freeagent_explain_transaction, freeagent_create_bill, offered only to a requester holding manage FreeAgent (owner, admin), and only in agent runs, where the approval gate applies. Chat never offers them. None offered until the organisation is connected
Service APIfreeagentClientFor, explainTransaction, attachToExplanation, deleteExplanation, createBill, listUnexplainedTransactions — each write updates the mirror row it touched, and each answers 404 domain_unavailable while FreeAgent is turned off for the organisation
Extensionfreeagent:sync-listeners: a plugin contributes { id, onSync(summary, ctx) }, called after every successful sync
AnalyticsWhen the analytics plugin is installed: cubes FreeAgentTransactions, FreeAgentExplanations (+ FreeAgentCategories), FreeAgentInvoices, FreeAgentBills — spend and income by month and category, unexplained count and amount, outstanding and overdue. Inert without analytics
Datafreeagent_connections, freeagent_sync_state and seven mirror tables, all with row-level security; money as numeric
CLIrocketflare freeagent status and rocketflare freeagent sync
Skill/freeagent: registering the app (sandbox and production), secrets, connecting, verifying, troubleshooting

Requirements

  • Rocketflare kit 0.48.0 or later (tools answer egress; the cron is a perTenantTask and the service API is definePublic, so both stop where an organisation turned FreeAgent off).
  • A FreeAgent app registered at dev.freeagent.com with the redirect URI {APP_URL}/api/hooks/freeagent/callback.
  • OAUTH_ENCRYPTION_KEY (the kit’s bootstrap sets it) and the kit’s JOBS_QUEUE.

Install

pnpm plugin add https://github.com/rocketflare-dev/rocketflare-plugins.git@freeagent-v3.17.0 --subdir plugins/freeagent
pnpm plugin add https://github.com/rocketflare-dev/rocketflare-plugins.git@freeagent-v3.17.0 --subdir plugins/freeagent --apply
pnpm db:generate --name plugin-freeagent-<version> && pnpm db:migrate

Then set the three keys — FREEAGENT_CLIENT_ID, FREEAGENT_CLIENT_SECRET, FREEAGENT_ENVIRONMENT (sandbox | production, unset means sandbox) — in apps/web/.dev.vars locally and with wrangler secret put deployed. All three are declared as secrets so no toml edit is needed; the environment is not sensitive and may go under [vars] in both tomls instead. pnpm provision cloudflare <env> writes the 18 * * * * cron. Run /freeagent for the walk-through.

Building on it

import { freeagentExtensions } from '@rocketflare/shared/plugins/freeagent/index'
import {
  attachToExplanation,
  explainTransaction,
  type FreeAgentSyncListener,
  listUnexplainedTransactions,
} from '@/plugins/freeagent'

const rematch: FreeAgentSyncListener = {
  id: 'receipts',
  async onSync(summary, ctx) {
    await ctx.enqueue({ type: 'receipts.match', payload: { tenantId: summary.tenantId } })
  },
}

// in a job:
const open = await listUnexplainedTransactions(ctx, tenantId, { from: '2026-04-06' })
const explanation = await explainTransaction(ctx, tenantId, {
  bankTransactionUrl: open[0].url,
  categoryUrl, // from freeagent_categories
  grossValue: open[0].unexplainedAmount, // signed like the transaction
  datedOn: open[0].datedOn,
  description: 'Train ticket',
})
await attachToExplanation(ctx, tenantId, explanation.url, {
  bytes, filename: 'receipt.pdf', contentType: 'application/pdf',
})

export const receiptsServer = {
  // …
  extensions: freeagentExtensions({ syncListeners: [rematch] }),
}

Declare requires: { plugins: ["freeagent"] } in your plugin.json. Writes throw FreeAgentError; branch on err.code (needs_reconnect, rate_limited, validation, …).

Who sees what

Every member can see the FreeAgent page and the mirrored books, and their agent runs get the read tools. Owners and admins connect, disconnect and sync, and only their runs are offered the two write tools — each call still waits for a person to approve it.

Known gaps

  • One FreeAgent company per organisation; no accountancy-practice (multi-client) API.
  • Polling only (FreeAgent has no webhooks): changes appear within the hour, or on Sync now. Hourly rather than faster because each tick reads Postgres, and a sub-hourly one keeps a Neon compute awake.
  • The first sync mirrors about 400 days of transactions and explanations; older history is not fetched.
  • A deleted contact, bill or invoice stays in the mirror (FreeAgent’s updated_since does not report deletions). Explanations deleted in FreeAgent are reconciled through their transaction.
  • No per-user rate-limit budgeting beyond the bounded 429 back-off; a very large first sync may span several queue retries.
  • Disconnecting deletes the mirror as well as the tokens.