hisab-whatsapp
AGENTS.md9 starsChanged 3 months agoMITView on GitHub
A ledger you text: WhatsApp (or a terminal) → a tool-calling agent with exactly six tools → a plain-text hledger ledger in markdown, every write under hledger check --strict. This file is the canonical instructions for any coding agent (Claude Code reads it through CLAUDE.md; Codex and others read it directly). It is a router and a fact sheet, not a knowledge base: the README explains the product, the code explains itself, the skills explain the process, and the rules…
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,266 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository10 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- brainstormSkill
- create-planSkill
- file-an-issueSkill
- grill-meSkill
- implementSkill
- open-prSkill
- refine-approachSkill
- reviewSkill
- to-specSkill
The file
We split this AGENTS.md into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 57
Six tools, nothing else: No shell, no free file access, no network beyond the model, transcription and WhatsApp.
- Very specific: line 108
Never run docker compose against a real person's ledger during development.
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Hisab on WhatsApp — agent guide
A ledger you text: WhatsApp (or a terminal) → a tool-calling agent with exactly six tools → a plain-text hledger ledger in markdown, every write under hledger check --strict. This file is the canonical instructions for any coding agent (Claude Code reads it through CLAUDE.md; Codex and others read it directly). It is a router and a fact sheet, not a knowledge base: the README explains the product, the code explains itself, the skills explain the process, and the rules hold the conventions.
Read in this order
- This file — how to work here and the repo facts.
ARCHITECTURE.md— the bird's-eye view: one message's path, components, state, invariants, failure paths.docs/INDEX.md— the progressive-disclosure root for every artifact; each directory has its ownINDEX.md..agents/rules/— conventions for code in this repo, one file per topic. Read the rules for the area you touch; each file'spaths:frontmatter says which area that is. Claude Code loads them automatically through the.claude/rulessymlink.errors.md— failures are codes inhisab/errors.py, never exception text
- The code, starting from the file the task names.
Docs follow the Open Knowledge Format: markdown, a small YAML frontmatter with type, an INDEX.md per directory, plain links as the graph.
Repo map
hisab/
loop.py main loop: WhatsApp long-poll → setup or agent → reply; --stdin terminal mode; dedup by message id, offset after batch
agent.py the system prompt (SYSTEM) and the raw tool-calling loop on any OpenAI-compatible endpoint; retries with backoff
tools.py the SIX tools: append_entry, undo_last, report, learn_rule, read_accounts, add_account — schemas + execution
ledger.py hledger on markdown: quarter files, append under strict check with rollback, undo by entry number, reports, rules, periodic rules, settings
setup.py the setup conversation: the first answer sets the language, then eight numbered questions (n/8) incl. the account holder name, personal or shop; writes accounts/rules/hisab.md/settings.json from templates/
i18n.py every fixed user-facing string in en / ur, plus the model's reply-shape line per language
errors.py THE error-code registry: every failure reply (chat) and runner lastError (portal) is a code; classify → log → reply
clock.py the one clock: every "today", quota month and export name in config `timezone`, never the container's UTC
store.py runtime state: offset, messages.jsonl (keyed by WhatsApp id), entry-number map, setup state, rolling window
wa.py thin adapter over the pinned wa-agent package, which owns the transport (poll, download, typing, send with
chunking, document send, the per-method rate limiter with its fixed 60s window, 429 backoff) and transcription
(voice notes → text, OpenRouter or Gemini, provider/model/key/language from config). The adapter maps config
whatsapp.rate_limits onto wa-agent, maps every wa-agent failure code to a Hisab code, maps transcription codes
and an `[inaudible]` transcript to `transcription_failed`, flattens Obsidian wikilinks, logs 409 as
another-poller conflict, and inbound() is the one reader of the platform's message dict
archive.py export-ledger's ZIP builder: canonical markdown only, never state/secrets/media
config.py config.yaml + .env (secrets only from the environment); the WhatsApp token is read from
WHATSAPP_AGENT_TOKEN, else WHATSAPP_TOKEN (the old name) with a note to rename it
templates/ personal.md, shop.md charts of accounts; rules.md, rules_shop.md keyword → account (English + Roman Urdu)
sample-vault/ a kiryana store, two weeks, FAKE numbers — regenerated by tests/make_sample.py, never edited by hand
runner/ hosted mode only: Firestore reconciler, one hisab.loop subprocess per tenant; verify.py matches the portal's
nonce against a pending tenant's messages.jsonl, reconcile.py admits and parks tenants, lifecycle.py revokes
(stop, move the ledger to inactive/, delete the ciphertext) and sweeps inactive ledgers after 30 days,
activity.py computes the portal's Connected rows from the worker's files — see runner/README.md
landing/ hosted mode only: the static Next.js landing page + portal (phone auth, sealed-box key submit) — see landing/README.md
firestore.rules owner-scoped client writes on tenants/{uid}: five client fields only, never status/creatorId — tests/rules/ proves it
tests/ smoke.py (no-network regression, THE check) · make_sample.py · demo_terminal.sh (terminal demo on a copy of the sample)
check_endpoint.py (validate a key) · check_receipts.py (model direction check, by hand) · bakeoff.sh (compare models) · check_landing.py (run by smoke) · rules/ (firestore.rules tests)
examples/ config.openrouter.yaml, config.gemini.yaml, runner-config.openrouter.yaml — copied into the gitignored configs
showcase/ README images: the cover and real-agent screenshots — check every screenshot for personal data before committing
docs/ lifecycle artifacts, INDEX.md at every level (see below); docs/INDEX.md also routes to every README outside docs/
ARCHITECTURE.md bird's-eye view — read after this file
Makefile (`make help`) · Dockerfile · docker-compose.yml · docker-compose.runner*.yml · config.example.yaml · .env.exampleNon-negotiables
- Six tools, nothing else. No shell, no free file access, no network beyond the model, transcription and WhatsApp. A feature that needs a seventh tool needs a conversation first.
- Every ledger write goes through
Ledger.appendunderhledger check --strict; a rejected block rolls back. Entry numbers come only fromnext_entry_number; undo is by number. - Transport invariants: skip a message id already in the store; advance the offset only after the batch; chunk replies under 3,500 chars.
- Failures are codes. No exception text, HTTP body, hledger banner or provider name ever reaches a user. Raise or classify to a code in
hisab/errors.py, log the detail to stderr, reply witherrors.reply. A new failure is oneCODESrow plus itsen/urstrings. See.agents/rules/errors.md. - Language: any new user-facing string lives in
i18n.pyin bothenandur— never Roman Urdu; users may chat in it and the model answers in kind (MODEL_LANG["en"]). Model replies stay one line; shapes per language are inMODEL_LANG. - Ledger conventions the Obsidian dashboard reads: alphabetic commodities (
PKR,USD, never$), transfers as three postings with a bareequity:transfer, recurring items and budgets as~ monthlyrules, rates asPlines. - Privacy. Nothing from the author's personal ledger, vault, VPS, tokens or WhatsApp id enters this repo, an issue, a PR or a doc.
.env,config.yaml,vault/,data/,scratch-*are gitignored and never read into a document. - Never touch
.env,config.yamlor anything undervault/from a skill. - Hosted mode: the runner alone talks to Firestore and alone writes
status/creatorId/lastError; the worker alone talks to WhatsApp.lastErrorholds a portal code fromhisab/errors.py, never a sentence — the portal renders it in English and Urdu.runner-data/,runner/config.yamlandlanding/.env.localare gitignored likevault/.
Commands
| What | Command |
| The check (run before calling anything done) | python3 tests/smoke.py |
| Regenerate the sample ledger | python3 tests/make_sample.py |
Terminal demo on a copy of the sample (needs a model key in .env) | bash tests/demo_terminal.sh |
| Validate a pasted key: model, tools, transcription | python3 tests/check_endpoint.py [--audio note.ogg] |
Check by hand that the model reads a receipt's direction (needs a key and the fixtures in tests/fixtures/receipts/; SKIP without them; never part of the check) | python3 tests/check_receipts.py [--holder "Name"] |
| Compare a model on the fixed demo script | bash tests/bakeoff.sh <model-id> |
| Switch endpoint | cp examples/config.openrouter.yaml config.yaml or examples/config.gemini.yaml |
| Validate the sponsor config before a demo | python3 tests/check_endpoint.py --config config-dev.yaml |
| Terminal mode on the configured ledger | python3 -m hisab.loop --stdin |
| Container | docker compose up -d --build (or make selfhost) · docker compose logs -f |
| Strict check on any ledger | hledger -f <dir>/hisab.md check --strict |
| Hosted mode, the full local loop (Gemini + emulators + runner + portal at :3031) | make up (then make down / make down-v) — see runner/README.md |
| Hosted mode, the dev profile (OpenRouter + the dedicated dev Firebase project) | make dev — fails fast until the project is provisioned |
| Firestore rules as owner and attacker (throwaway emulator) | make rules-test |
Docker, and which ledger is mounted
The container runs python -m hisab.loop and polls the WhatsApp agent whose token is in .env. It reads the config file selected by HISAB_CONFIG (default ./config.yaml, Gemini) and mounts one ledger folder at /app/vault, selected the same way by HISAB_VAULT (default ./vault). State (offset, messages.jsonl, media) lives in the named volume hisab-data, not in the ledger folder.
| Task | Command |
Run against the personal test ledger ./vault | docker compose up -d --build |
| Run against the sample kiryana ledger (the dashboard demo) | HISAB_VAULT=./sample-vault docker compose up -d --build |
| Run against any other folder | HISAB_VAULT=/path/to/folder docker compose up -d --build — an empty folder means the first message triggers setup |
| Run the sponsor demo (OpenRouter, sample ledger) | HISAB_CONFIG=./config-dev.yaml HISAB_VAULT=./sample-vault docker compose up -d --build |
| Watch messages and turn times | docker compose logs -f |
| Restart after a code or config change | the same up -d --build line you started with |
| Stop, keep state | docker compose down |
Stop and wipe the store: the offset, the message ↔ entry map and the setup state, so reply-to-undo on older messages breaks and an unfinished setup starts over (setup restarts from zero only when the ledger folder has no hisab.md or accounts.md) | docker compose down -v |
| Read files inside the container | docker compose exec -T hisab sh -c 'ls /app/vault; cat /app/data/messages.jsonl' |
Rules for agents:
--buildafter any change underhisab/,templates/orrequirements.txt; the image copies the code, it is not a bind mount.- One container per WhatsApp token. Two pollers on the same agent fight over the cursor (HTTP 409). A second agent needs its own compose project name and its own
.env. - Entries from the phone write into whatever
HISAB_VAULTpoints at. After testing on./sample-vault, either keep the entries or runpython3 tests/make_sample.pyto regenerate the committed sample; never hand-edit it. config.yamlis the local, gitignored config the container reads by default.HISAB_CONFIGselects a different gitignored config file for the compose mount (default./config.yaml); switching the selection never overwritesconfig.yaml, which stays the Gemini rollback. Switch endpoints inconfig.yamlitself by copying fromexamples/(config.openrouter.yaml,config.gemini.yaml) and restarting; validate any config file, includingconfig-dev.yaml, withpython3 tests/check_endpoint.py --config <file>first.down -valso deletes the entry-number ↔ message-id map, so reply-to-undo on messages from before the wipe will say the message is not on record. Expected.- Never run
docker composeagainst a real person's ledger during development; use./vault,./sample-vaultor a scratch copy.
How we work — the lifecycle
Skills live in .agents/skills/ (.claude/skills is a symlink to it); rules live in .agents/rules/ (.claude/rules is a symlink to it). Put a new convention in its own rule file with a paths: frontmatter and list it under "Read in this order"; never create a real .claude/rules/ directory, because other agents would not see it. Each arrow is a human gate: finish, summarise, offer the next skill by name, wait.
A /brainstorm → /grill-me → /to-spec → /file-an-issue → /create-plan → /implement → /review → /open-pr
B <GitHub issue> → (/grill-me if the WHAT is contested) → /create-plan → /implement → /review → /open-prSmall, low-risk work may skip stages; say which and why. One slug travels every stage (GH-<N>-<topic> once an issue exists). Tickets are GitHub issues, never local files. The full contract, including who owns each board transition: .agents/skills/README.md.
Artifacts: docs/brainstorm/ · docs/specs/ · docs/exec-plans/{backlog,active,completed,superseded} · docs/feat-checklist/. Each directory gets its INDEX.md from the first skill that writes there.
Repo facts (read by the skills)
repo: mhmzdev/hisab-whatsapp
trunk: main # PRs target this; never push to it directly
issues_repo: mhmzdev/hisab-whatsapp
project_board: 1 # owner mhmzdev — "Hisab Engineering"
board_fields:
Status: [Todo, In progress, Done]
Priority: [P0, P1, P2]
Team: [Engineering, Product, Design, Marketing]
check: "python3 tests/smoke.py"
labels: read with `gh label list --repo mhmzdev/hisab-whatsapp`; apply only what exists, none is fine
branch: "GH-<N>-<kebab-topic>" # or <kebab-topic> without an issue
pr:
base: main
body: fixed sections — Why · Change Summary · Major Impact · Linked Issue · Test Plan · Deploy prerequisites (when needed)
attribution: keep # commits and PR bodies carry the Claude trailer and session link, as in git log
docs:
brainstorm: docs/brainstorm
specs: docs/specs
exec_plans: docs/exec-plans
feat_checklist: docs/feat-checklistVocabulary: entry (one transaction, numbered n:), posting (one line of it), ledger (the folder: hisab.md, accounts.md, rules.md, quarter files, settings.json), tool (one of six), store (messages.jsonl and friends), setup (the first conversation), template (a chart of accounts), language (en / ur; set by the first setup answer, changed by /lang), demo agent (the WhatsApp agent used for testing, separate from any personal one).
Origin
Extracted from a personal system the author has run since September 2026 (a bash relay to Claude Code over a private vault). This repo is the public, API-level rewrite. The transport now lives in a separate repo, whatsapp-agent-cli, published on PyPI as wa-agent (import wa_agent); Hisab is its first product and runs on it since #57 (hisab/wa.py is the adapter). The relay, first planned as whatsapp-agent-relay for the hackathon, is that repo's next release, wa-agent relay.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

