# Naïve — Accounting Agent Onboarding (skill.md)

> Wire up your payment processors and accounting systems, stand up a live financials dashboard, and let the agent reconcile transactions and close the books every month.

## Start here — read the base manifest first

This is a **use-case-specific** skill. It builds on Naïve's general agent onboarding manifest. Before doing anything below, read the base manifest and follow its operating rules (authenticate *with* the user, clarify scope, gate real-world/spending actions, respect budgets, be idempotent):

- **Base onboarding manifest:** https://usenaive.ai/skill.md

Do the base manifest's onboarding first (authenticate the user, install the CLI/SDK, verify connectivity). Then return here and layer this use-case on top.

## What you're building

A **accounting agent**: a database + a web-deployed dashboard, plus a governed `bookkeeper` agent profile running on a Naïve runtime. Declare all of it as code in `naive.config.ts` and provision it with `naive up`.

## Step 1 — ask the user (discovery)

Before provisioning anything, ask the user these and confirm the answers:

- Which payment processors and accounting system do you use today, and who owns those logins?
- What's your fiscal calendar and target close date each month (e.g. by the 5th business day)?
- What's your chart of accounts / categorization scheme, and are there rules for how to categorize?
- Who should approve journal entries, payments, and the final close before books are locked?
- What reports do you need, to whom, and on what cadence?

## Step 2 — connect their existing systems

Use the `connections` primitive (autonomous OAuth) and the `vault` (per-tenant encrypted credential storage) to wire up what the user already runs on. Only connect what they confirmed in Step 1.

- Payment processors — Stripe, Square, PayPal, Shopify Payments
- Accounting systems — QuickBooks Online, Xero, NetSuite
- Banking & cards — bank feeds via Plaid, corporate card programs
- Billing & invoicing — the tools where revenue and bills originate

```bash
naive connections connect <service>     # OAuth into an existing system
naive vault put <service>.api_key <key> # store any keys the user pastes
```

## Step 3 — declare the database + web app + agent (naive.config.ts)

Scaffold with `naive init`, then adapt the config below. It declares a managed Postgres database, a Vercel-hosted Next.js dashboard, object storage, a hosted runtime pool, and the governed agent-profile template — then `naive up` provisions all of it (idempotent; shows a diff).

**What goes in the config:**
- `infrastructure.web` — the web-deployed dashboard (Next.js on Vercel).
- `infrastructure.database` — managed Postgres for the app's normalized data store.
- `infrastructure.documents`/`storage` — object storage for files the agent handles.
- `runtime.pool` — a hosted microVM pool the bookkeeper agent runs on (or omit for bring-your-own-runtime).
- `agentProfiles.bookkeeper` — the governed profile (identity + comms + `policy` with an allow-list, a spend cap, and human approvals on real-world/money actions).

```ts
import { defineConfig, cloud, agentTemplate, policy, runtime } from "@usenaive-sdk/iac";

export default defineConfig({
  project: "accounting-agent",

  // Path A — the dashboard + ledger, provisioned and hosted by Naïve.
  infrastructure: {
    web: cloud.web({ framework: "nextjs", dir: "." }),          // financials dashboard (Vercel)
    database: cloud.postgres({ name: "ledger", size: "serverless" }), // normalized transactions ledger
    documents: cloud.bucket({ name: "accounting-docs" }),        // receipts, invoices, statements
  },

  // Path B — a hosted runtime for the close/reconciliation agent.
  runtime: {
    pool: runtime.pool({ name: "books", size: "small" }),
  },

  // The governed agent profile the bookkeeper runs as.
  agentProfiles: {
    bookkeeper: agentTemplate({
      identity: { kind: "business", verify: "kyb" },
      comms: { email: { domain: "per-tenant" } },               // sends reports + approval requests
      policy: policy({
        allow: ["connections", "vault", "llm", "email", "search", "apps"],
        budget: { cap: "$100/mo", alertAt: 0.8, hard: true },
        approvals: [
          { when: "payment.send", via: "email" },               // never move money unattended
          { when: "books.close", via: "email" },                // human signs off before lock
        ],
      }),
    }),
  },
});
```

Then provision it:
```bash
naive up                                              # plan + apply everything above
naive agent-profiles provision bookkeeper --user <tenant-id>   # one per tenant/customer
```

## Step 4 — primitives this agent uses

The `bookkeeper` profile's `policy.allow` should grant exactly these — nothing more (least privilege):

- connections (OAuth into accounting + payment systems)
- vault (store connected-system API keys per tenant)
- llm (categorization, anomaly detection, report narration)
- email (send statements, reports, and approval requests)
- search (tax/GAAP lookups, vendor enrichment)
- apps + database + storage (the dashboard, ledger, and document store)
- cron (schedule the monthly close + reporting run)

## Step 5 — build the dashboard + data model

Use the provisioned Postgres + web app to build:

- A web-deployed financials dashboard — revenue, expenses, burn, runway, AR/AP aging, cash position
- A Postgres ledger that mirrors and normalizes transactions from every connected source
- Document storage for receipts, invoices, and statements the agent files against transactions

## Step 6 — automate the ongoing work

Wire the recurring work to `cron` jobs that run the agent on the runtime pool. Keep every money-movement or irreversible action behind an approval (see the `policy.approvals` in the config).

- Monthly close — reconcile every account, categorize transactions, flag anomalies, and close the books
- Automated financial reporting (P&L, balance sheet, cash flow) delivered by email on a schedule
- Invoice and bill capture: parse inbound documents and post them to the ledger for approval

```bash
naive cron create --name "monthly-run" --schedule "0 9 1 * *" --task "<what the agent should do>"
```

## Reference

- Base onboarding manifest: https://usenaive.ai/skill.md
- Infrastructure as Code: https://usenaive.ai/docs/getting-started/iac
- Connections (OAuth): https://usenaive.ai/docs/api-reference/overview
- CLI reference: https://usenaive.ai/docs/cli/overview
- SDK reference: https://usenaive.ai/docs/sdk/overview
- All templates: https://usenaive.ai/templates
