Rules and code
What every agent reads before it works, and what code enforces: the Rulebook, the policy, the catalog of allowed changes, the coding guidelines, the code map and the project profile.
๐ Read-only copy of main at 4c3ef2b7, refreshed by every Live Patrol (27 Oct 12:55 UTC). These files change only through a merge request; agents can never change the Rulebook, the policy or the code map.
Coding guidelines: link shortener
Written by the owner for people and for Vallum's agents. Everything specific to this codebase lives here (and in vallum/project.yaml); Vallum's skills only hold role know-how. Read this and CODEMAP.md before planning, writing, reviewing or fixing anything. Protected path.
What the product is
Small businesses create short links (https://โฆ/r/<code>) for campaigns. Visitors follow them; owners create, read and delete links through a small JSON API protected by an API key. Redirects are the feature everything depends on (Core tier); link management is Standard; new extras start Experimental.
Architecture
- FastAPI app in
app/.app/main.pyonly builds the app and discovers features: every module inapp/features/that exposesrouter = APIRouter()is mounted automatically. Never editmain.pyfor a feature. - Storage (
app/store.py): Firestore in the cloud and in CI (emulator), memory in unit tests. Use only:store.create(code, url)(raisesLinkExistsif the code is taken),store.get(code)(dict orNone),store.delete(code)(bool). Reach it asrequest.app.state.store. A link is{code, url, created_at}. - API key (
app/security.py): write routes adddependencies=[Depends(require_api_key)]. - Kill switches (
app/flags.py): every route of a new feature addsDepends(flags.require("<flag>")). - Headers: middleware adds
X-RevisionandX-Routeto every response; don't set them yourself. - Redirect route:
GET /r/{code}inapp/features/redirect.pyserves any stored code, so features that create links with chosen codes (for example custom aliases) never need to touch the redirect module.
How to add a feature
- New module
app/features/<module>.pywithrouter = APIRouter(); one module per feature. - Validate request bodies with pydantic models and
field_validator(a bad body answers 422). Duplicates answer 409. A code in the path that doesn't fit the code format, or doesn't exist, answers 404, never 422 (likeGET /r/{code}andGET /p/{code}). URLs must behttp://orhttps://, at most 2048 characters, with a host, and no whitespace or control characters (copy the validator inapp/features/links.py). - Codes and aliases: letters, digits and dashes only, 1โ64 characters,
fullmatch. Never end a path segment you invent with the letterzat the top level (Cloud Run reserves paths like/healthz). - Return the same public link shape as
links.py:{code, url, short_url, created_at}. - Tests in
tests/test_<module>.pyusing theclientfixture fromtests/conftest.pyand the header{"X-API-Key": "test-key"}; include the flag-off case (expect 404) in the tests. It is never a promise: the promise checker can't switch flags (code tests kill switches itself). - Feature Card in
promises/features/<issue>-<feature>.yaml(seepromises/features/base-links.yaml).
Promise examples that fit this app
- id: alias-redirects
says: "A custom alias sends people to the right page"
steps:
- "POST /api/aliases {url: 'https://example.com/{rand}', alias: 'promo-{rand}'} -> 201"
- "GET /r/promo-{rand} -> 302 https://example.com/{rand}"
where: [mr, drive, live]
severity: blocker
- id: alias-create-fast
says: "95% of alias creations finish in under 300 ms"
measure: "p95(latency, route='POST /api/aliases') < 300ms"
where: [mr, drive, live]
severity: majorSpeed limits by tier here: Core 150 ms, Standard 300 ms, Experimental 500 ms (p95). Error rates: Core under 0.1%, Standard under 0.5%, Experimental under 1%. Popular links are tagged popular == 1 in measurements.
Never
- Edit
app/main.py,app/store.py,app/security.py, another feature's module, or anything protected (vallum/,.gitlab-ci.yml,.gitlab/duo/,skills/,docs/vallum/GUIDELINES.md,AGENTS.md,CODEOWNERS,promises/service.yaml,promises/learned/). - Log visitor IP addresses or read
vallum_secretsfrom a feature. - Do slow work on the redirect path; anything per-click must stay fast for popular links.