1
0
Fork 0
polaris-task-force/docs/backups/pre-agents-split-20261009/collections-AGENTS.md
Z8MB1E b28708c590 docs(agents): split domain guidance into nested AGENTS.md files
Move 19 domain sections out of the root guide into per-directory
AGENTS.md files that OpenCode v2 injects lazily when an agent reads
each subtree. The always-loaded root drops from 121KB to ~30KB and
gains a domain index table with never-miss invariants. Original root
and pre-merge sub-guides are preserved under
docs/backups/pre-agents-split-20261009/ for restoration.

Note: also carries the pre-existing uncommitted wiki-section edits to
the root AGENTS.md, preserved verbatim in src/lib/wiki/AGENTS.md.
2026-10-09 15:46:36 -04:00

96 lines
5.8 KiB
Markdown

# AGENTS.md — Payload Collections
> **Parent**: `../../AGENTS.md` — commands, RBAC basics, Payload CMS config.
## Overview
55 files (~54 collections) across 15 domain groups. Access control defined in `src/permissions/index.ts` (~880 lines, permission registry across groups). RBAC check: `hasPermission(payload, user, "collection:action")`.
## Structure
```
collections/
Media.ts # Image uploads (public read; used by wiki image upload)
Shims.ts # Global: audience-targeted content (admin-only)
Announcements.ts # Banner/modal/dialog/toast announcements (admin-authored, client-evaluated)
users/ 11 files # Users (auth), Ranks, Profiles (incl. minigame stats), Awards,
# Qualifications, Assignments, AssignmentTransfers, Experience,
# Evaluations, Roles (dynamic RBAC), UserNotifications
intelligence/ 5 files # Missions, MissionAttendances, MissionRoleSignups,
# MissionMapMarkers (planning-map markers), Campaigns, Factions, Technologies
logistics/ 5 files # Structures (staffing defaults), Resources, Assets, Vehicles, Shipments
banking/ 3 files # BankAccounts, BankTransactions, LedgerEntries
market/ 2 files # MarketListings, MarketNegotiations
locker/ 2 files # LockerStorages, Loadouts
game/ 9 files # GameRules (global, currency + staffing flags), GameStructures,
# GameVehicles, GameNpcs, GameHardResources, GameEventLogs,
# NpcStaffing, LaborClassifications (+ shared staffingFields.ts factory)
server/ 5 files # MissionFiles, ModLists, GameServers, ArmaCommands, ArmaSyncEvents
world/ 5 files # Maps (basemap config), MapRoads/MapZones/ResourceNodes (map features), NarrativeEvents
projects/ 4 files # Projects, Labels, Releases, Sprints (Jira-like)
tickets/ 2 files # Tickets (Lexical rich text; `archived` hides from all front-ends, admin panel only), TicketVotes
wiki/ 3 files # WikiPages, WikiRevisions, WikiTemplates
story/ 3 files # StoryBeats (Chronicle chapters), StoryBeatStates (read markers/reactions),
# Voiceovers (audio narration uploads for the Chronicle, attached to beats)
```
## Key relationships
```
Users ──┬── Profiles ──┬── Qualifications
│ ├── Awards
│ ├── Assignments ── Ranks
│ ├── AssignmentTransfers
│ └── Experience
├── UserNotifications
├── Evaluations
└── BankAccounts ── BankTransactions ── LedgerEntries
GameStructures ── Structures (template) ── Resources/Assets/Vehicles
GameStructures ── NpcStaffing ── LaborClassifications
GameVehicles ── Vehicles (template)
GameNpcs ── MarketListings ── MarketNegotiations
MissionAttendances ── Missions ── Campaigns
MissionMapMarkers ── Missions (removed by Missions beforeDelete)
```
## Access control pattern
Collections define `access` at field + document level using helpers from `src/utils/access-control/`:
- `isRole(role)` — single role check
- `hasRoles(roles[])` — any-of role check
- `hasPermission(payload, user, "collection:action")` — full RBAC (cached 30s)
- `hasLogisticsQualification()` / `hasIntelligenceQualification()` — queries Profiles
Admin group access: `developer` only for destructive operations, `admin` for read/write.
Permission tiers and panel gates:
- `system:admin-access` ("Superuser Tier" label) = functional superuser tier: final approval states (`approvalStatusFieldAccess`), Users admin page, read-all notifications. Only built-in `admin` + superuser roles hold it; NEVER grant to division roles.
- Admin panel ENTRY: Users collection `access.admin` uses `canAccessAdminPanel` (superuser OR any `admin:<slug>:manage`). Per-page sidebar visibility: `requireAdminPageAccess` (`<slug>:read` + `admin:<slug>:manage`). Two gates, do not collapse them.
- Payload 3 field-level `access` returning `false` on update silently drops the field (no 403, success toast); the document saves with the previous value. Loud rejection or hidden options require a `beforeChange` hook or custom admin field component.
## Hooks with side effects
- `Structures` `beforeChange`: emits `structure:resize`; blueprint "Staffing Defaults" group via `staffingFields.ts`
- `GameStructures` `afterChange`: emits storage edit events; `beforeChange` copies blueprint staffing defaults on create
- `Users` `afterChange`: maintains profile sync
- `BankTransactions` `beforeValidate`: auto-generates `transactionNumber`
- `MarketNegotiations`: patience meter enforcement
## Where to look
| Task | Path |
|------|------|
| Add a new collection | Create `<Name>.ts` here, register in `src/payload.config.ts` |
| Add RBAC permission | `src/permissions/index.ts` (add to group + add check) |
| Modify collection access | `<collection>/access.ts` or inline in collection file |
| Add field hook | Inline in collection definition (beforeChange/afterChange) |
| Relationship graph | See key relationships above; Payload manages FK constraints |
## Anti-patterns
- **NEVER** edit `src/payload-types.ts` or `src/payload-generated-schema.ts` — run `bun run generate:types` instead
- **NEVER** add `access` functions that call `payload.auth()` without handling the null user case
- **NEVER** use `payload.create` in `afterChange` hooks without checking for infinite loops
- **NEVER** mix `overrideAccess: true` without a permission check — always gate behind RBAC first