11 Commits

Author SHA1 Message Date
fece777954 fix(scripts): start-individually.sh silently disabled audit-log mirroring; docs(readme): README's service table/diagram was stuck at phase-1 (6 of 11 services)
scripts/start-individually.sh (the committed box-contention workaround
used across rounds 6-16) plainly `source .env`'d without run-demo.sh's
already-established AUDIT_LOG_ADDR fallback, so ledger-core always saw
AUDIT_LOG_ADDR="" and silently disabled its own AuditMirror on every run
started this way. Reproduced live via `ration audit-check` (every tenant
showed real ledger entries against 0 audit entries), fixed with the same
fallback run-demo.sh already uses, re-verified live end to end (seed ->
simulate-deposit --late -> agent grant -> audit-check OK, counts matching
-> verify-chain intact).

README.md's architecture diagram and Services table were last touched at
the very first scaffold commit and never updated across 16 rounds of real
feature work since — they still described a 6-service system (wal,
ledger-core, gateway, agent, tui, cli) while the repo has grown to 11
real services (adding auth, tenant-registry, card-issuance,
webhook-ingestion, audit-log, plus the Go/Rust SDKs), none of which
appeared anywhere in the judge-facing entry point to this repo.
2026-10-29 15:05:04 +03:00
972f70f6b9 feat(tui): add an interactive issue-card/adjust-limit form — Cards tab was read-only
PLAN-2026-10-23-DEEP.md's own "Remaining" note for the Cards tab was
still true: no in-TUI IssueCard/AdjustCardLimit form, CLI/API only.
Round 7 closed the CLI half of this gap; this closes the TUI half.

- New modal (services/tui/internal/model/cardform.go,
  internal/view/cardform.go): press `n` on the Cards tab to issue a
  card (tenant picker defaulting to the selected row's owner,
  cardholder/limit/interval/currency fields), `a` to adjust an
  existing card's limit (pre-filled from the selected row). Submits
  via two new client.Clients methods (IssueCard/AdjustCardLimit) that
  call the same gateway RPCs the CLI's `ration card` commands use.
  On success the form closes and triggers an immediate refresh; on
  failure (validation or a real RPC rejection) it stays open with the
  error shown and prior input preserved, so the operator can fix and
  retry without re-entering everything.
- Real bug found live, not by reading code: the field-typing handler
  only ever appended msg.Runes[0], assuming one KeyMsg per keystroke.
  bubbletea's input reader batches consecutive printable bytes read
  in one syscall into a single KeyMsg carrying multiple runes — typing
  (or pasting) a cardholder name arrived as one such batched message,
  so every character after the first was silently dropped. Fixed to
  append every rune in the batch; re-verified with multi-character
  names/limits typing correctly.

Verified live against the real bare-metal 7-service stack (audit-log,
ledger-core, auth, tenant-registry, card-issuance, webhook-ingestion,
gateway — started individually with inter-service delays, the same
round-6/7-documented workaround for this shared box's sibling-agent
load), driven through a real pty via tmux send-keys (not code reading):
seeded 3 tenants, opened the issue-card form, picked a tenant, typed
cardholder "Jane Operator", limit 250000, interval daily, submitted —
card appeared in the Cards tab and in `ration status`'s independent
CLI output (card_7816bf..., ACTIVE, $2,500.00, daily). Opened
adjust-limit on that card, backspaced/retyped the limit to 500000,
submitted — `ration status` confirmed $5,000.00 and the correct new
Held balance. Checked both error paths live: empty cardholder is
rejected client-side before any RPC; a limit request exceeding the
tenant's real reserve-floor headroom returns the actual
card-issuance rejection into the still-open form. `go build`/`go vet`/
`go test ./...` clean for services/tui; full `make build` (Rust+Go+SDK)
clean.

Also added scripts/start-individually.sh, a reusable version of the
manual individual-service-startup workaround rounds 6/7's build logs
already documented ad hoc for this box's contention — same PID-file
format as run-demo.sh, so scripts/stop-demo.sh tears it down too
(verified: it did).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-29 08:49:56 +03:00
92370eba5e feat(sdk,cli): self-serve API keys for Go SDK callers; fix(infra): docker-compose's missing AUTH_GRPC_ADDR/AUTH_ADDR broke every service but ledger-core
sdk/go/ration had no way to attach a credential, so its own README/doc.go
"Typical use" example was rejected with codes.Unauthenticated against any
default-config gateway (RATION_GATEWAY_REQUIRE_TENANT_AUTH defaults to
true) — nothing in this repo even called auth.IssueAPIKey before this.
Adds ration.WithAPIKey/WithBearerToken dial options (mirroring every
internal services/*/internal/authclient package's own interceptor
pattern) and a new `ration apikey issue` CLI command that actually mints
one via auth.IssueAPIKey. Verified live against a real running
auth+gateway+ledger-core+tenant-registry+card-issuance+webhook-ingestion
stack: no credential -> Unauthenticated, bad credential -> Unauthenticated
"invalid credential: not found", real minted credential -> IssueCard
succeeds end to end.

Also found, live, by actually running `docker compose up --build` for
real (not by reading code): gateway, card-issuance, tenant-registry,
webhook-ingestion, and agent all crash-looped forever in a plain
`docker compose up --build` — every one of them mints an operator JWT
from auth at startup and os.Exit(1)s if that fails, and none of their
compose service blocks set the env var each one's own config actually
reads (AUTH_GRPC_ADDR for all but gateway, which uniquely reads
AUTH_ADDR). Only ledger-core had this fixed previously (round 2). This
meant the entire containerized stack was non-functional end to end, not
just ledger-core's corner of it. Fixed all five; re-verified by tearing
the whole stack down and bringing it back up from scratch, seeding
tenants via `docker compose run --rm cli seed`, minting a real API key
via `docker compose run --rm cli apikey issue`, and issuing a card via
the Go SDK against the real containerized gateway on localhost:7002.

Also fixed a separate real bug in scripts/run-demo.sh's .env loader,
found live the same way: `IFS='=' read -r key value` silently drops a
single trailing IFS character, truncating any .env value ending in
exactly one '=' by one character — which is *every* `openssl rand
-base64 32` key (the exact command this repo's own docs recommend for
RATION_LEDGER_ENCRYPTION_KEY/AUTH_JWT_SIGNING_KEY), since a 32-byte
input always base64-encodes with exactly one padding '='. Reproduced
live: a real generated key crashed ledger-core at startup with
InvalidBase64(InvalidPadding) on a plain scripts/run-demo.sh run.
Switched to parameter-expansion splitting on the first '=' only;
re-verified the full run-demo.sh -> seed -> status cycle with a real
generated key, confirmed ledger.wal/ledger.db are genuine ciphertext
under the correct, untruncated key.

cargo test/go test/go vet all still pass (pre-existing, unrelated:
sdk/rust/ration-client's own #[cfg(test)] FakeGateway fixture doesn't
implement a newer Gateway trait method and fails to compile under
`cargo test` — a test-fixture-only gap, left alone per standing no-new-
test-work policy; production cargo build is unaffected).
2026-10-28 21:10:09 +03:00
231c37cab9 docs: round-2 build log, RUNBOOK encryption section, demo recording script
Documents a6aad08/83916f8 in BUILD-LOG-2026-10-23.md's "Round 2 of 3"
section (SQLite column encryption + the two live bugs found closing it
out), adds a RUNBOOK.md entry for RATION_LEDGER_ENCRYPTION_KEY now that
it covers both the WAL and SQLite columns, and adds
scripts/record-demo.sh — narrates docs/DEMO-SCRIPT.md's exact sequence
with real pacing, built to be captured with `asciinema rec demo.cast -c
scripts/record-demo.sh` for the hackathon submission's video
walkthrough. Also ignores demo-video/, the gitignored output directory
that script's rendered .mp4/.cast land in (never source, never
committed).
2026-10-28 02:18:36 +03:00
9dca6d1e2a feat(infra): automate dev-CA leaf cert rotation
infra/dev-ca/generate-dev-ca.sh's own header names this gap: 1-year
leaf certs with no rotation story short of regenerating (and
redistributing) the entire CA by hand.

Add scripts/rotate-dev-ca.sh plus a new client,
services/auth/cmd/issue-service-cert, for auth.proto's IssueServiceCert
RPC: point a running auth instance's AUTH_CA_CERT_FILE/AUTH_CA_KEY_FILE
at the same static dev CA every service's *_MTLS_CA_FILE already
trusts, and the rotation script generates a fresh keypair+CSR per
service and gets back a leaf signed against that identical root — no
new CA to redistribute, only the one service whose leaf just rotated
needs restarting to pick it up.

Verified live end-to-end: generated a CA, started auth against it,
rotated all 10 service identities, confirmed the new leaf's serial
changed, its key matches its cert, and `openssl verify -CAfile` passes
against the untouched original CA.
2026-10-23 19:10:29 +03:00
f909885563 fix(audit-log): mirror deposit-received credits into the audit chain
MarkDepositReceived's ledger credit — the only path by which a deposit's
money becomes spendable headroom — was never mirrored into audit-log,
unlike ApplyEntry's credits and RecordAgentDecision. The claim that
"every money move is mirrored" (README, docs/SUBMISSION.md) didn't
actually hold for it.

Ledger::mark_deposit_received_with_entry now returns the credit
LedgerEntryRecord it produces (mark_deposit_received keeps its original
signature, delegating to the new method and dropping the entry, so
existing callers/tests are unchanged); grpc.rs's MarkDepositReceived
handler mirrors it into audit-log exactly like ApplyEntry's handler
already does.

Also wires audit-log into scripts/run-demo.sh (the bare-metal demo path
every judge following README's Quickstart/docs/DEMO-SCRIPT.md actually
runs) — it was only ever started via docker-compose, so the headline
"audit trail is the point" claim and the standalone verify-chain tool
were never exercised end to end by the documented demo flow. Verified
live: after a seed + simulate-deposit + agent-decision run, verify-chain
now reports real records (6, matching the 6 live Append RPCs audit-log's
own metrics counted) and correctly flags a single flipped byte as a
broken chain at the right sequence.
2026-10-22 02:19:21 +03:00
521d6176c4 feat(ration): REST/JSON facade over gateway, final phase-2 doc updates
Phase 2 section 7 (the other half, alongside sdk/go/ration and
sdk/rust/ration-client already pushed in c5297e4/8215fb8): a hand-rolled
internal/httpapi on services/gateway translating JSON <-> the gRPC source
of truth (cards, deposits, bridge funding, activity), documented as a
convenience facade over gRPC, not a parallel implementation. Also folds in
the remaining phase-2 doc updates (ARCHITECTURE/RUNBOOK/THREAT-MODEL/
AIRWALLEX-SETUP/SUBMISSION, ADR 0003/0004) and docker-compose/Makefile/
.env.example wiring from the resumed phase-2 workflow's final agents.

Verified: go build/vet/test clean across all 10 services + both new SDKs,
`make build && make test` clean end to end (C WAL, Rust ledger-core + the
new Rust SDK, every Go module including sdk/go/ration).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 12:56:58 +03:00
13abc31645 feat(ration): observability, infra-as-code, security hardening, and test depth
Phase 2 sections 2-6 and 8 of docs/SCALE-EXPANSION.md:

- pkg/telemetry + pkg/metrics: OpenTelemetry trace propagation and
  Prometheus metrics across every service hop (CLI -> agent -> gateway ->
  card-issuance/tenant-registry/auth -> ledger-core), tracing added to
  ledger-core itself via services/ledger-core/src/telemetry.rs.
- infra/: otel-collector + Prometheus + Grafana docker-compose stack, a
  Terraform ECS Fargate module + dev/staging/prod envs (plan-only, no
  apply — real AWS spend is an owner action), and a dev-only mTLS CA
  (infra/dev-ca) wired through pkg/mtls + services/ledger-core/src/mtls.rs.
- services/audit-log (from the prior commit) gets its async mirror writer
  in services/ledger-core/src/audit_mirror.rs, and services/gateway gets
  a per-tenant token-bucket rate limiter (internal/ratelimit).
- Test depth: a Rust proptest suite proving concurrent ApplyEntry never
  breaches the reserve floor (tests/apply_entry_proptest.rs, passing), a Go
  fuzz seed corpus for the policy envelope (rules_fuzz_test.go), a libFuzzer
  harness for the C WAL frame parser (services/wal/fuzz, deliberately not
  wired into `make test` per its own Makefile comment - needs a
  libFuzzer-bundled clang), and a real chaos test
  (scripts/chaos/kill-ledger-mid-write.sh) that SIGKILLs ledger-core
  mid-write under concurrent load and verifies via ListEntries that
  nothing was lost or double-applied.
- docs/formal/ledger.tla: a TLA+ spec of the ledger state machine (balance
  >= reserve_floor safety, HOLD-eventually-resolves liveness) plus a TLC
  model config - not run through TLC in this pass, that's a precise
  documented TODO, not faked.
- docs/adr/0001-0004, docs/RUNBOOK.md, docs/SLO.md, docs/THREAT-MODEL.md.

Verified: `make build && make test` clean (C WAL, Rust incl. the new
proptest suite, all 10 Go modules) from a cold target.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 12:25:58 +03:00
77324a7b50 feat(ration): split gateway into auth/tenant-registry/card-issuance/webhook-ingestion
Phase 2 service decomposition per docs/SCALE-EXPANSION.md section 1: extracts
internal/{airwallex,bridge,card,tenant,httpserver} out of the monolithic
gateway into four independently deployable gRPC services (each own go.mod,
Dockerfile, and tests), with gateway now a thin BFF that fans out through new
cardissuanceclient/webhookeventsclient gRPC clients. gateway.proto's external
surface is unchanged — agent/tui/cli still talk to gateway exactly as before.

Verified: all 10 go.work modules build and `go test ./...` passes across
every one, including the new gateway client packages against the live split
services (via `make build && make test`).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 12:25:41 +03:00
2b686594a3 feat: Ration phase 1 — full polyglot build for Airwallex Starter Kit 5
Six services, independently built then integrated:
- services/wal (C): crash-safe write-ahead log, CRC32-checksummed
  frames, torn-write recovery via truncate-to-last-valid-frame.
- services/ledger-core (Rust): double-entry ledger over the C WAL via
  FFI, reserve-floor enforcement BEFORE any WAL write, idempotent
  ApplyEntry, full LedgerCore gRPC service.
- services/gateway (Go): Airwallex Issuing/Global-Accounts client
  (mock mode default, live mode ready), the actual rationing math
  (reserve floor, 60% bridge cap, 24h velocity cap, partial-over-decline).
- services/agent (Go): deterministic hard-rule policy envelope computed
  BEFORE any LLM call; Claude only decides within that pre-approved
  envelope; every decision audit-logged even when the LLM call fails.
- services/tui (Go, Bubble Tea) + services/cli (Go, cobra): the only
  UI — no web frontend, per explicit direction.

Integration found and fixed three real bugs, not just compile errors:
- proto regen collision shadowing checked-in pkg/pb packages
- ledger-core/gateway address-variable mismatch (stack would never
  actually connect on default config)
- the big one: MarkDepositReceived never credited the ledger, so every
  tenant's balance was permanently stuck at 0 and bridge-funding could
  only ever decline — the core agentic-rationing feature could never
  produce a real grant. Fixed at the ledger level with idempotent
  mark-and-credit in one WAL frame, covered by 3 new tests.

End-to-end verified live, reproducibly: seed -> simulate a late deposit
-> agent grants a partial bridge with a computed rationale -> second
grant correctly declines once the 24h velocity cap engages. Verified
independently by the orchestrator too: 'make build' and 'make test'
both clean (Rust: 29 tests; Go: all packages; C: WAL test suite).

Airwallex sandbox credentials still pending organizer approval —
tracked as an owner blocker in docs/AIRWALLEX-SETUP.md, not a code gap.
2026-10-19 03:04:13 +03:00
e551182092 chore: scaffold Ration — proto contracts, architecture + agent-design docs, Airwallex blocker doc 2026-10-19 02:06:21 +03:00