Docs

How a recount works

You invite a prospect. They connect their data read-only from the tool they use today. Recount matches it to your data model, turns it into events in time order, and replays them through your product's real logic in a sandbox account your app makes. Your product reports what it would have done. Code compares that with what really happened and builds a report where every number opens the records behind it. Then it keeps running on new data for the live days, and the buyer can make it real with one click.

recount.json

Describes your data and what your product does. Your app serves it at GET /api/recount/manifest (the SDK does this for you).

{
  "version": 1,
  "product": "Ledgerly",
  "pitch": "Chases late invoices for you",
  "entities": {
    "invoice": { "label": "Invoices", "fields": {
      "customer_id": { "type": "string" },
      "amount":      { "type": "money" },
      "due_at":      { "type": "date", "planned": true },
      "paid_at":     { "type": "date", "optional": true }
    } },
    "customer": { "label": "Customers", "fields": {
      "name":  { "type": "string", "personal": true },
      "email": { "type": "email",  "personal": true }
    } }
  },
  "events":  [ { "type": "invoice.created", "entity": "invoice", "description": "An invoice was sent" },
               { "type": "invoice.paid",    "entity": "invoice", "description": "The customer paid" } ],
  "outputs": [ { "type": "reminder.sent", "entity": "invoice", "description": "A reminder went out" } ],
  "tick": "1d",
  "rules": [ ... ],
  "estimates": [ ... ]
}
  • Field types: string, number, money, date, datetime, email, boolean.
  • personal: names, emails, phones, addresses. Masked by default for the buyer.
  • planned: a date set in advance on purpose (a due date). Any other date later than its event is treated as a leak of the future and stops the match.
  • tick: "1d" or "1h" sends clock ticks so time-based logic runs on quiet days; "none" sends none.

Rules and estimates

How a win is counted. Computed by code from what really happened (events) and what your product said it would have done (outputs).

  • lead_time: your product acted on a record (first output) before the real world did (first actual event). Counts, average days earlier, total money.
  • missed: your product acted on a record that, in reality, nobody handled.
  • automated: how many times your product did something a person would otherwise do.
{ "id": "never_chased", "kind": "missed", "label": "Overdue invoices nobody chased",
  "entity": "invoice", "output": "reminder.sent", "actual": "reminder.logged", "money": "amount" }

Estimates are a fact times an assumption you state. They're always labeled as estimates, show their formula, and the buyer can change the assumption on their report.

{ "id": "hours_saved", "label": "Time saved writing reminders", "from": "reminders_written",
  "metric": "count", "op": "times", "result": "hours",
  "assumption": { "name": "Minutes per reminder", "unit": "min", "default": 6, "min": 1, "max": 30 } }

The handler

import { recountHandler } from "@recount/sdk/server";
import manifest from "../recount.json";

export const recount = recountHandler({
  manifest,
  start: async ({ runId, buyer }) => ({ sandboxId: await createSandbox(runId, buyer.company) }),
  handleBatch: async (ctx, events) => {
    const state = await loadSandbox(ctx.sandboxId);
    for (const e of ctx.walk(events)) applyEvent(state, e, ctx.now, {
      remind: (inv) => ctx.output("reminder.sent", { entity: "invoice", id: inv.id }),
    });
    pending.set(ctx.sandboxId, state);
  },
  lastBatch: (sandboxId) => db.lastBatch(sandboxId),
  saveBatch: (sandboxId, batch) => db.saveStateAndBatch(sandboxId, pending.get(sandboxId), batch),
  destroy: ({ sandboxId }) => deleteSandbox(sandboxId),
  promote: async ({ sandboxId, buyer, fetchExport }) => ({ accountUrl: await makeReal(sandboxId, buyer, await fetchExport()) }),
  onWebhook: (e) => console.log(e.event),
});

// app/api/recount/[...path]/route.ts
export const { GET, POST } = recount.handler;

Use handle(ctx, event) for one event at a time, or handleBatch to load your state once per batch. Store the last batch with the sandbox (lastBatch/saveBatch) so a retried batch gets the same answer without running twice.

The three rules of a recount

  1. Use ctx.now, never the real clock. Your product may only know what was known at that moment.
  2. Never act for real. No emails, payments or calls to other systems: call ctx.output(type, record, data). Outputs not listed in recount.json are refused, and outputs timed outside their batch are refused.
  3. Stay in the sandbox made by start, and delete it in destroy.

Connecting the buyer's data

Buyers can upload CSV, Excel or JSON exports, or connect Google Sheets (a view-only link), Stripe (a restricted read key), HubSpot (a private app token with read scopes) or any REST API (address, one key header, and the paths to read).

Every connector goes through one fetch function that only makes GET requests, only to that connector's hosts, never to private or local addresses, with timeouts, size caps and row caps per plan. Paging (page numbers, cursors, next links) is followed.

The match

Code profiles the buyer's tables (types, date formats, decimal marks, keys, links between tables). The AI sees that profile and a few sample rows with personal data swapped for made-up values, and writes a mapping spec from a small set of steps. Code runs the spec on every row, checks it (columns exist, dates state their format, no date from the future rides along early), and sends problems back to the AI for up to two fixes. The buyer reviews real rows next to the events they became, and picks per field: send, mask or keep back.

The report

Facts come from your rules and open their records. Estimates show their formula. Patterns are suggested by the AI and kept only if code finds them true. The summary is written by the AI from the computed findings; any sentence with a number code didn't compute is removed. The method section says what was replayed, what was hidden and why, and what wasn't counted.

Live days and making it real

After the replay, the run keeps going for your live days (Settings → Runs): connected sources are pulled every hour, new events and the daily ticks go to your sandbox, and the report updates. Uploaded files can be replaced with a newer export.

"Make it real" calls your promote hook with a signed export link (10 minutes, this run only) holding the buyer's current records, unmasked, because they asked for it. Return the address of their new account. Recount also posts a signed run.converted webhook to /api/recount/webhook.

Privacy

  • The buyer agrees to a plain consent text before anything is connected; the exact text is kept with a hash.
  • Raw rows, events, outputs and source keys are stored encrypted (AES-256-GCM).
  • The AI never sees real names, emails, phones or addresses, and never sees all rows.
  • Masked fields reach your product as stable tokens; kept-back fields never leave Recount.
  • Data is deleted your retention days after a run ends (max 30), or right away when the buyer presses Delete everything.
  • You see counts and the report, never the buyer's raw rows.

Security and the protocol

Every call between Recount and your app is signed both ways with your project secret (HMAC-SHA256 over timestamp and body, 5-minute window).

GET  /api/recount/manifest
POST /api/recount/start    { runId, test, buyer: { company } }              → { sandboxId }
POST /api/recount/events   { runId, sandboxId, seq, phase, events[] }        → { seq, outputs[] }
POST /api/recount/finish   { runId, sandboxId }                              → { ok }
POST /api/recount/promote  { runId, sandboxId, buyer, exportUrl }           → { accountUrl }
POST /api/recount/destroy  { runId, sandboxId }                              → { ok }
POST /api/recount/webhook  { event, ... }                                    → { ok }
Headers: X-Recount-Timestamp, X-Recount-Signature = hex HMAC-SHA256("<timestamp>.<body>", secret)