AGENTS.md — Aquila build contract

Read this before touching anything. It is the interface contract between workstreams. Rationale for every choice lives in DECISIONS.md. Work plan lives in PLAN.md.

Ground rules for all agents

  1. Stay in your directory. You own one workstream. Do not edit files outside it unless the orchestrator explicitly asks. Shared files (README.md, DECISIONS.md, PLAN.md, root package.json, scripts/, .github/) belong to the orchestrator.
  2. The interfaces in §2 are frozen. If you need a change, say so in your delivery notes — do not change both sides silently.
  3. Nothing runs in the deklo k3s cluster. Plain Docker Compose only. Resource budget: the whole stack fits in 8GB (deploy/compose.yml enforces per-container limits).
  4. Resource discipline: Python 3.11 slim images; no Chromium/Playwright/Electron anywhere; idle bot target ≤250MB RAM. One dep that adds 300MB is a bug.
  5. Safety posture (D008): bots detect → summarize → draft. They never send email, pay, file, or act on the owner's behalf. Do not build features that violate this.
  6. No secrets in git. Env files only (.env, gitignored), with .env.example committed.
  7. Every delivery = branch ws/<name> → tests/smoke evidence in the delivery notes → orchestrator review → merge. Append decisions (yours and reversals) to DECISIONS.md via the orchestrator — propose entries in your summary.
  8. Language: code and docs in English. All user-facing copy is English only — classy, plain, never Hinglish (D035). Personas write in English. Tests must not pin copy strings verbatim where avoidable (see docs/agent-improvements.md L04).
  9. Skills are part of the contract: experts exist via installed skills (~/.claude/skills/: superpowers + anthropic sets). Use verification-before-completion before any "done" claim, systematic-debugging for failures, requesting/receiving-code-review for reviews.
  10. The improvement loop is mandatory: every significant mistake gets an entry in docs/agent-improvements.md via /retro; briefs and rules evolve from evidence, not vibes.

§1 Repo map & ownership

Path Workstream Stack
core/ WS1 Python 3.11, FastAPI, uvicorn, APScheduler, SQLite (FTS5), httpx, imapclient
gateway/ WS2 LiteLLM proxy (container), thin FastAPI admin for keys/budgets
manager/ WS3 Python 3.11, FastAPI, Jinja2, docker SDK, psycopg/SQLite for control-plane state
channels/telegram/ WS4 Python 3.11, FastAPI, python-telegram-bot (or raw Bot API via httpx)
deploy/ orchestrator docker-compose, Caddy, relay runbook, k8s mapping notes
site/, brand/, docs/ WS5 static HTML/CSS/JS, marked for MD→HTML in scripts/build.mjs
e2e/ orchestrator pytest + httpx smoke tests, density harness

§2 Frozen interfaces

2.1 core/ ↔ gateway/ (LLM)

2.2 core/ (bot runtime HTTP API, port 8080)

Endpoint Method Behavior
/health GET {status:"ok", bot_id, uptime_s, memory_mb}
/persona GET/PUT read/replace persona.md content (PUT is orchestrator/admin only)
/chat POST body {message, channel, user_ref} → SSE stream of {delta} chunks, then {done:true, usage}
/routine/{name}/run POST force-run a routine (used by tests and manager debugging)
/routines GET list configured routines with next-fire times

2.3 manager/ (control plane, port 8090)

2.4 channels/telegram/ (port 8091)

2.5 Data & state

§3 Workstream briefs

WS1 — core (bot runtime)

Deliver: core/Dockerfile (python:3.11-slim, ≤180MB image), core/app/*, core/personas/ with vega.md, nova.md, pulsar.md, sirius.md (baseline), tool layer: web_search (SearXNG at SEARXNG_URL), web_fetch (httpx + readability-ish extraction), imap_read (imapclient; env IMAP_HOST/USER/PASSWORD, read-only mailbox access), calculator. Routines: APScheduler, cron strings from persona front-matter (routines: block), all times IST by default (Asia/Kolkata). Memory: recent transcript + FTS5 recall injected into system prompt (token-budgeted ≤2k tokens). Tests: core/tests/ pytest (persona load, memory round-trip, SSE chat against a mock OpenAI-compatible server, routine parsing).

WS2 — gateway

Deliver: LiteLLM config.yaml with model alias aquila-default; upstreams from env: OPENCODE_GO_API_BASE/OPENCODE_GO_API_KEY (auto-detect placeholder until orchestrator fills), fallback OPENROUTER_API_KEY free models list; gateway/admin.py (FastAPI): create/revoke virtual keys, set per-bot ₹ budget (BOT_BUDGET_INR default 200), read spend (/spend, /spend/summary), /health. Persist keys+budgets in gateway/data/gateway.db (SQLite). On budget exhaustion return 429 as per §2.1. Tests: key lifecycle, budget math, spend parsing. Runs inside compose at gateway:4000.

WS3 — manager + microsites

Deliver: manager/app/* FastAPI, SQLite schema (users, bots, otp_challenges, sessions), Docker SDK provisioning (spawn core/ image as aquila-bot-<id> with env+volume+limits 256MB/0.25CPU, only attachable to the aquila compose network), Jinja templates: welcome, workspace (bot list, chat debug, cost), admin minimal. No JS build step; vanilla JS + fetch for SSE chat. Tests: OTP lifecycle (mocked telegram), bot CRUD with mocked docker client, host-routing unit tests.

WS4 — telegram

Deliver: channels/telegram/app.py FastAPI webhook + polling fallback (TELEGRAM_MODE=webhook|poll), OTP contact-share flow per §2.4, chat routing to manager, /internal/send, QR payload generation (deep link https://t.me/<bot>?start=verify_<nonce>), friendly Hinglish copy. Tests: nonce parsing, contact-share verification logic, routing with mocked manager.

WS5 — site + docs

Deliver: site/index.html (night-sky homepage: hero "The eagle that works while you sleep", how-it-works, 3 personas showcase, pricing ₹250/₹299/₹499 tiers placeholder, FAQ, footer), docs/*.md rendered at /docs by scripts/build.mjs (pages: plan, decisions, killer-apps, economics, demo-script, comparisons index), brand/tokens.css (night-sky palette: deep navy grounds, star-white, eagle-gold accent) + brand/BRAND.md, /docs index nav. Self-contained pages, no CDN except Google Fonts. npm run verify + npm run build clean.

WS6 — orchestrator (main session)

Owns: deploy/ (compose stack, Caddy configs, relay runbook, k8s mapping notes), e2e/ (smoke + density harness), economics report, demo script, reviews/merges, DECISIONS.md upkeep, final demo.

§4 Conventions

§5 Definition of done (per workstream)