docs: commit the per-directory AGENTS.md knowledge-base files (admin/lib/shell)
This commit is contained in:
1 parent
cd705d20fa
commit
7be367303b
3 files changed
+93
No files matched your search
@@ -0,0 +1,31 @@
|
||||
# src/admin - Seed / Setup Panel
|
||||
|
||||
Distinct domain: the standalone `/admin` screen (non-resident-facing) that seeds in-world starting configuration into the Event Log once per demo. `seedEvents.ts` is the biggest single module here and is pure (no IndexedDB).
|
||||
|
||||
## WHERE TO LOOK
|
||||
| Task | File | Notes |
|
||||
|------|------|-------|
|
||||
| Validate form -> payload | `seedEvents.ts` | `validateSeedInput` returns a typed `{valid, payload|error}`; pure, no side effects |
|
||||
| Resource categories | `seedEvents.ts` | `RESOURCE_TYPES = power/water/food/cooling`; categories: population, resource, baseline |
|
||||
| Demo fixture + idempotency | `seedEvents.ts` | `HOLLOW_DEMO_FIXTURE`, `buildDemoFixturePayloads`, `DEMO_FIXTURE_MARKER`, `hasDemoFixtureBeenLoaded` |
|
||||
| Panel UI + submit/demo load | `AdminSeedPanel.tsx` | appends each `seed.*` payload via `eventlog.append()`; "Load Hollow demo" checks the marker first |
|
||||
|
||||
Two entry paths: a validated single manual submit, and the one-click demo-fixture load. The panel is reachable only at the standalone `/admin` route - it is outside the `ShellLayout` frame, so no wallet card renders there.
|
||||
|
||||
The demo fixture is versioned by `DEMO_FIXTURE_MARKER.fixtureId` (`hollow-demo-v1`); bump that id when the fixture content changes so a re-load is allowed instead of being short-circuited as already-loaded.
|
||||
|
||||
Emitted event payload types:
|
||||
- `seed.population` `{ value }`
|
||||
- `seed.resource.<power|water|food|cooling>` `{ resource, value }`
|
||||
- `seed.baseline` `{ channel, value }`
|
||||
- `seed.demo.loaded` `{ fixtureId }` (idempotency marker)
|
||||
|
||||
## CONVENTIONS (beyond root)
|
||||
- Numeric fields are validated as finite, in-range numbers before a payload is built - string form inputs are parsed, not trusted.
|
||||
- `seedEvents.ts` only decides well-formedness and builds payloads; appending is the component's job through the shared `eventlog.append()` path.
|
||||
- Demo-load idempotency is enforced by appending `DEMO_FIXTURE_MARKER` and short-circuiting on `hasDemoFixtureBeenLoaded(existing)` - not by a flag outside the log.
|
||||
|
||||
## ANTI-PATTERNS (beyond root)
|
||||
- Invalid input (e.g. a negative population) must return the typed `{valid:false, error}` and append NOTHING - never a partial or best-effort event.
|
||||
- Seed events carry STARTING configuration only (population / resource pools / baseline readings) - never an outcome/result metric (draft D11).
|
||||
- No bypass/unsigned write: seed and demo events go through the same signed `append()` as everything else.
|
||||
@@ -0,0 +1,31 @@
|
||||
# src/lib - Domain Core
|
||||
|
||||
High-complexity, high-centrality module: the identity/crypto/ledger foundation every other layer replays over. No React, no UI here.
|
||||
|
||||
## WHERE TO LOOK
|
||||
| Task | File | Notes |
|
||||
|------|------|-------|
|
||||
| DB tables & schema versions | `db.ts` | Dexie `CommonsDatabase`; v1 `identity`, v2 adds `eventLog` (`++id, lamportTs`) |
|
||||
| Keypair / sign / verify | `identity.ts` | one row `id:"local"`; `init()` is idempotent; `sign`/`getPublicKey` throw `IdentityMissingError` |
|
||||
| Append / read events | `eventlog.ts` | `append()` signs + assigns next lamportTs; `appendEntry()` re-verifies a foreign entry before persist |
|
||||
| Balances & credit limits | `ledger.ts` | `computeBalances()` folds `wallet.issue`/`wallet.transfer`; unknown payloads ignored |
|
||||
| Replay ordering | `ledger.ts` | `sortForReplay`: lamportTs asc, then authorPubkey bytes, then signature bytes |
|
||||
| Double-spend merge | `ledgerConflicts.ts` | `mergeReplicas`: earlier lamportTs wins; equal lamportTs -> `UnresolvedLamportTieError` |
|
||||
| Credit limits / rejections | `ledger.ts` | `LedgerOptions.creditLimits` per account + `defaultCreditLimit` (floor 0); breaches land in `LedgerState.rejected`, not applied |
|
||||
| Ranged / full read | `eventlog.ts` | `readAll()` vs `readRange(start, end)` (inclusive), both lamportTs-ordered |
|
||||
|
||||
There is no barrel/index here - import each module by its path (`./ledger`, `./eventlog`, ...).
|
||||
|
||||
## DATA FLOW
|
||||
`identity` (keypair) -> `eventlog.append` (sign over canonical `{payload, lamportTs}`) -> `ledger.computeBalances` / `ledgerConflicts.mergeReplicas` (pure replay). `db` sits under identity + eventlog only.
|
||||
|
||||
## CONVENTIONS (beyond root)
|
||||
- `init()` returns the existing identity if one is stored and only generates on a truly empty DB - callers may call it freely (see `useActiveAccountId`).
|
||||
- The signature covers the canonical message `JSON({payload, lamportTs})` - never sign payload alone.
|
||||
- `nextLamportTs()` = last stored `lamportTs` + 1 (0 if empty); strictly increasing per append.
|
||||
- Balances are never persisted - always recomputed by replay. `ledgerConflicts` builds directly on `computeBalances`, not a parallel reducer.
|
||||
|
||||
## ANTI-PATTERNS (beyond root)
|
||||
- Do NOT wrap an `await`ed `sign()` inside `db.transaction()` - Dexie auto-commits when its sync job queue drains, committing before the write. `append()` documents this.
|
||||
- Do NOT add an update/delete/mutate method to `eventlog` - the append-only surface is deliberate.
|
||||
- Do NOT silently pick a winner on an equal-lamportTs double-spend tie - throw `UnresolvedLamportTieError`.
|
||||
@@ -0,0 +1,31 @@
|
||||
# src/shell - Mini-App Launcher Shell
|
||||
|
||||
Distinct domain (largest UI surface): the persistent navigation/identity/wallet frame that mini-apps mount inside. Navigation + rendering only - no mini-app business logic (draft D5).
|
||||
|
||||
## WHERE TO LOOK
|
||||
| Task | File | Notes |
|
||||
|------|------|-------|
|
||||
| Tile list (13 mini-apps) | `miniappRegistry.ts` | single source of truth; id + emoji icon + label |
|
||||
| Home grid render | `HomeGrid.tsx` / `HomePage.tsx` | grid maps the registry; `HomePage` wires nav to `/miniapp/:id` |
|
||||
| id -> mounted component | `MiniappOutlet.tsx` + `miniappComponents.tsx` | map lookup, `NotFoundMiniapp` fallback; placeholders until `src/miniapps/*` exist |
|
||||
| Persistent frame | `ShellLayout.tsx` | renders `WalletCard` + back link + `<Outlet/>` across navigation |
|
||||
| Wallet card | `WalletCard.tsx` | `balanceOf(computeBalances(entries))` + `walletHistoryFor` for the active account |
|
||||
| Account id | `accountId.ts` / `useActiveAccountId.ts` | `init()` identity -> `toAccountId` (hex pubkey) |
|
||||
| Live event feed | `useEventLogEntries.ts` | Dexie `liveQuery(readAll)` for reactive updates |
|
||||
| Per-account history | `walletHistory.ts` | classifies issued/sent/received, reverse-chronological |
|
||||
| History list render | `TransactionHistory.tsx` | presentational; consumes `walletHistoryFor` output |
|
||||
| Unknown-route screen | `NotFoundMiniapp.tsx` | shown for an unregistered `/miniapp/:id` or a `*` route |
|
||||
|
||||
Each component has a co-located `*.module.css`; `ShellLayout` hides the back-link on the home route (`pathname === "/"`).
|
||||
|
||||
Route shape (from `src/AppRoutes.tsx`): `index` -> `HomePage`, `miniapp/:miniappId` -> `MiniappOutlet` (reads the param via `useParams`), `*` -> `NotFoundMiniapp`, all nested under `ShellLayout` so the wallet card stays mounted across navigation.
|
||||
|
||||
## CONVENTIONS (beyond root)
|
||||
- Reactivity comes from Dexie `liveQuery` wrapped in a hook (`useEventLogEntries`), not manual refetch; identity bootstrap lives in `useActiveAccountId` (handles unmount via a `cancelled` flag).
|
||||
- Components read ledger/history through `src/lib` functions - they never recompute balances inline beyond calling them.
|
||||
- Before identity resolves, `WalletCard` shows `--` and an empty history rather than a fabricated `0` (account id is `undefined` until `init()` returns).
|
||||
|
||||
## ANTI-PATTERNS (beyond root)
|
||||
- `HomeGrid.tsx` and `miniappRegistry.ts` must import ZERO `src/miniapps/*` modules - `importGraph.test.ts` fails the build if an import leaks in.
|
||||
- Do NOT hard-code a per-mini-app branch in the router/registry; add an entry to `miniappRegistry` and let the map drive it.
|
||||
- Do NOT unmount/remount the wallet card per navigation - its persistence across routes is the shell's core guarantee.
|
||||
Reference in new issue
Block a user