oficina / memoria Public

Clone
git clone https://amadan.net/oficina/memoria

Plain git — no account needed to clone.

Download

Download this file

1# πŸ€– memoria
2
3The Oficina suite's memory. One instance per team.
4
5This file is binding. Where it disagrees with a general skill, this file
6wins. Where it disagrees with the design spec, the spec wins and this file
7is wrong β€” fix it in the same commit.
8
9**The design:** `docs/superpowers/specs/2026-09-03-memoria-design.md`. Its
10Β§1 is the settled-decisions table, Β§1.2–§1.11 record what ten independent
11reviews changed. Don't relitigate a settled decision in a drive-by.
12
13---
14
15## The one rule
16
17> **memoria never speaks a passage without asking whoever owns it whether
18> this person may see it, right now.**
19
20Sibling content: the sibling decides, per person, per query (Β§4.1).
21Content with no other owner β€” Notion, Drive, mail, uploads β€” memoria owns
22outright and says so (Β§4.2).
23
24The second rule is Sheets': **the bucket never holds a readable passage.**
25Chunks, titles and headings are sealed. So is the index, which is why it
26lives in memory and nowhere else: FTS5 keeps term postings in plaintext.
27
28---
29
30## Two rules this app has already broken once each
31
32**A guard you have never seen fail is a guard written to pass.** Three of
33the first five gates here could not fail for the thing they named β€” one
34grepped `main.go` for `os.Exit` near a variable and a neighbouring error
35path supplied it; one checked for the string `"result"`, which is a
36substring of `"0 results"`; one scanned a directory the index was not in.
37Two more named a test that had been renamed away. **After writing any
38gate, break the thing it guards, watch it go red, revert.** Do it per
39path, not per file, and say in the test comment what you mutated and when.
40
41**And do not choose your own mutations.** Gate 17 shipped with three, each
42verified red; a reviewer then tried five ordinary chi idioms and every one
43passed green, including a route that served a *declared* path outside the
44session gate. Three green mutations picked by the author prove the author
45is consistent, not that the gate works β€” they are the cases already
46defended against while writing it. **Have someone who did not write the
47gate pick the mutations.** Β§Review's argument, one level down. (Β§1.9.)
48
49**Assert the state, not the copy β€” and if your own mutation cannot reach
50a guard, the guard is the finding.** Both of these were learnt on the same
51afternoon, from the two mutations out of twenty that survived while
52building Β§4.1's policy layer (2026-09-06).
53
54`Outcome.Record` filing the silent `NOT_VISIBLE` rulings alongside the
55loud ones rendered an identical page β€” nothing prints them β€” while
56quietly accumulating a per-app count of passages the reader may not see,
57one switch arm or debug print from being the leak Β§4.1 forbids. The test
58read `Lines()` and could not tell the two apart; the test that catches it
59reads the struct.
60
61And `scatter`'s short-slice fallback could not be reached by any fixture,
62because the function above it is total. Changing that fallback from
63`UNKNOWN` to `VISIBLE` left the suite green. A defence nothing can reach
64is the same object as a guard written to pass, whatever the intent β€” so
65either make it reachable (extract it, call it directly, as `scatter` now
66is) or delete it. Leaving it in place with a comment is the third option
67and it is the one that ships broken.
68
69**A count that fails is not a count of zero.** `chunkCount` returned 0 on
70error, and the page then told the reader "so this is a real absence rather
71than an empty index" β€” the codebase's own worst failure shape, asserted on
72the line written to prevent it. Anything that cannot be determined says
73so; it never renders as a confident zero.
74
75---
76
77## Mechanical rules
78
79**Data**
80- **Never `scope.Owned` or `scope.OwnedBy`.** Both are single-column
81 equality on `user_id`, and memoria's documents and chunks are
82 team-shared. Applied to them a list returns only the creator's rows and
83 fails as a plausible empty list, not as an error. (The scaffold's
84 AGENTS.md said the opposite; it was wrong for this app.)
85- A row that isn't yours **404s, never 403s**.
86- Scope `tx`, never the outer handle, inside transactions.
87- Never bind a request body onto a GORM model. Explicit `map[string]any`
88 plus a `.Select` allowlist.
89- Migrations are additive-only. New code over an old DB is always safe.
90- **No document content, title, heading, snippet or query text in any log
91 line, error string or metric label.** `carlos logs` is platform-held
92 storage we cannot grep. Gate 4 enforces it; it was missing once, and
93 what it found when written was that we were logging sign-in links.
94- **A model provider's response body is content too.** An OpenAI-compatible
95 4xx can echo the input that caused it, so the provider's error path is a
96 content path. Never log one verbatim β€” status and a fixed string. Gate 31
97 (spec Β§10); nothing calls a provider before slice 2, so this lands with
98 the first call and not after it.
99- **An ADDITION to derived state is made after the transaction commits,
100 under `context.WithoutCancel`.** A client closing the tab must not
101 leave the index disagreeing with the database.
102- **A REMOVAL from derived state is made before it**, and `Store.Delete`
103 carries the argument. The two orders fail in opposite directions:
104 indexing early can leave the index holding passages the database does
105 not have, which is a citation to text that is not there; un-indexing
106 early can only leave a stored document unfindable until the next boot,
107 which the app says out loud. Where they disagree, the order that cannot
108 produce a live citation wins. Delete was written the other way and did
109 produce one β€” found by a code review, 2026-09-04.
110- **A hit is not a citation until the database says the passage is still
111 there.** `Store.Search` drops any hit whose chunk row is gone. Ordering
112 makes the divergence rare; only this makes it harmless, and it is what
113 makes `ErrIndexLag`'s sentence true β€” without it, "stored but not
114 findable" was said about a document whose previous revision was still
115 answering searches.
116
117**The suite contract**
118- **Read the route out of the module, never out of memory.** `RouteS3` is
119 `/suite/s3` and the item id is a **path segment** β€”
120 `/suite/s3/{item_id}?revision=` β€” which the constant's own line says and
121 the conformance harness fires. Written as `?item_id=` it 404s against
122 every conforming sibling, and memoria reads a 404 as "not team-visible,
123 or gone". `url.PathEscape`, not `QueryEscape`: a space is `%20` in a
124 path and `+` in a query.
125- **A cap on a response has to be detectable, not just applied.** S1 and
126 S2 get that free β€” truncated JSON does not parse. An S3 body is
127 plaintext, so read one byte past the cap and error on it, or a large
128 document is silently indexed as its own first 2 MiB.
129- A sibling document's coordinate is `(sealed item id, sibling revision)`.
130 **`Document.Revision` is memoria's own counter and is not it**, and
131 `ExternalID` is a one-way fingerprint that cannot be asked about.
132
133**Sealing**
134- `internal/memoria/seal` is the only encryption surface. One HKDF purpose
135 per kind of thing sealed.
136- **A content hash is not a coordinate.** `external_id` was a bare
137 SHA-256 of the body, which let anyone with the bucket confirm the team
138 held a document they already had. Identifiers derived from plaintext are
139 keyed (`seal.Fingerprint`) or they are content.
140
141**Frontend**
142- No build step. Every affordance works scriptless.
143- **Colours are tokens, never literals**, so light and dark resolve
144 through `theme.css`. Gate: `TestNoColourLiteralsInAppCSS`.
145- **`layout.html` must link `theme.css`.** `tokens.css` defines eleven
146 tokens, none of them colours; without the theme every colour resolves to
147 `initial` and whole shorthand declarations go invalid β€” rules vanish
148 rather than the page going grey. **The v0.17.0-era scaffold omitted this
149 link**, which is how the rule was learnt; `rastrillo new` on v0.23.0
150 emits both, verified 2026-09-05. The rule stays because the failure is
151 silent, not because the scaffold still causes it β€” and `rastrillo doctor`
152 now checks the vendored files this app copies.
153- The attribute grammar (`rst-btn="primary compact"`), never the class
154 spelling. Utilities stay classes.
155- **The design system has a vocabulary, and a word outside it renders as
156 nothing.** `rst-callout="danger"` styles nothing: tokens.css carries the
157 tone in `data-tone`, so a value on the attribute itself matches the base
158 selector and no tone. Every flash in this app rendered untoned for
159 months and **three tests pinned it there**, written from the same guess
160 as the markup. Grep the stylesheet for the attribute before writing it.
161 Gate: `TestEveryTemplateAttributeIsInTheDesignSystem`, which checks
162 names *and* whether a value is one anything selects on.
163- **Spacing is on the scale, and a stack spaces the page** (Paul,
164 2026-11-22; Fiesta's DESIGN.md, "The stack"). `<main>` is
165 `rst-stack`, and so is any region holding blocks of its own (a
166 form, a section, the results); `rst-section` opens a section and
167 `rst-actions` is a row of buttons. No hand margins between a page's
168 blocks; every other margin, padding and gap is a `var(--rst-sp-N)`,
169 or carries `/* spacing-allow: why */` for real geometry. `make
170 spacing` (in `make ci`) reads static/; `TestEveryScreenKeepsTheRhythm`
171 (`make browser`) runs Fiesta's rhythm audit over the screens in its
172 list, in the states that change their blocks. A new screen or state
173 goes in that list, and a new region of Memoria's own with an rst-
174 name goes in `rhythmRegions`, because the audit does not walk into
175 rst- names it does not know. Field rules are `form[rst-stack]`,
176 never a bare `[rst-stack]`, which since `<main>` is one reaches every
177 field on every page.
178- **Look at the page.** `tools/drive` serves the app with sign-in off so a
179 browser can see it. It found three bugs in its first run that the whole
180 Go suite passed over β€” a heading trail rendering as "β€Ί Revenue", a
181 snippet repeating its own heading, and a submit button floating over the
182 textarea. A template test proves markup exists, not that it renders.
183 It then found two more in the sources page the day that page was built:
184 a warning-toned callout containing the words "No refusal anomaly",
185 because one flag carried two unrelated states; and a warning on every
186 row of every freshly-woken instance, because "not polled yet" is the
187 ordinary state of a wake. Neither changes a string a test looks for.
188 **If you add a section to a page, add it to drive too** β€” the section
189 that is not seeded is the section nobody sees.
190
191**rastrillo**
192- **rastrillo is `amadan.net/rastrillo/rastrillo`.** The old path,
193 `github.com/carlosframework/rastrillo`, stops at v0.23.0: code importing
194 it gets no fix, and its own checks cannot tell (Memoria zoomed iOS on
195 every tap for a month that way). `TestNoPreMoveRastrillo` allows one
196 import of it, native.go's second sessions handle for rastrillo/native's
197 server, until that server moves; `native_exchange_test.go` proves the
198 bridge. The app itself reads sessions through `a.sess`, the new
199 package. The CLI is a go.mod `tool`: `go tool rastrillo …`, never a
200 `rastrillo` from PATH.
201- **`rastrillo doctor` refuses while native.go needs the old path**
202 (above): it compares nothing. Until rastrillo/native's server moves,
203 a rastrillo bump is done by hand: `go run ./tools/vendorassets`
204 (tokens.css, which `TestVendoredAssetsMatchTheLibrary` pins), `go run
205 ./scripts/writeestilo` (theme, chrome, busy files, after an estilo
206 bump), `go tool rastrillo migrate-templates -write
207 ./internal/memoria/templates` (the localizer-first syntax; check the
208 rendered pages are unchanged), and `make credits`. Never `doctor --fix`
209 once it does run without reading what it adds: at 29e4491 it
210 overwrote rastrillo.js with the old shim (whose busy rule fights
211 estilo's busy.js) and added select.js, datetime.js and calendar.js,
212 which no page links; `TestBusyFilesAreEstilos` and
213 `TestNoUnusedRastrilloScriptsOnDisk` say so. Memoria has no
214 manifest/app.toml and no gen/: the English pack is linked in
215 serving.go (rastrillo refuses to start a language with no pack).
216- **The CSP is rastrillo's default, which refuses inline style
217 attributes** (fb806a2). Nothing Memoria serves standalone carries one;
218 `TestNoPageCarriesAStyleAttribute` reads every page's markup and `make
219 browser`'s `TestPagesRenderUnderTheProductionCSP` watches for
220 violations in Chromium. Draw with attributes and memoria.css, never
221 `style=`; `memoria.ServeOptions` says why there is no policy of our own.
222 The one exception is the native kit's approval page, whose inline
223 `<style>` is allowed by hash on `/native/authorize` alone;
224 `TestNativeApprovalStyleIsTheHashedOne` re-hashes it, so a native bump
225 that changes its CSS fails CI rather than shipping it unstyled.
226- **A field styled with `font: inherit` under a selector heavier than a
227 bare `input`** loses tokens.css's 16px-on-touch rule, and iOS zooms on
228 tap. Restate `font-size: max(1rem, 1em)` for it under `(pointer:
229 coarse)`, as memoria.css does for `form[rst-stack]`'s fields.
230 `TestNoZoomOnTap` (`make browser`) measures every field.
231
232**Auth**
233- **Sign-in is the smart door** (Home spec `2026-11-19-smart-door.md`,
234 step 6; home/connect `MIGRATING.md`), as in Docs, Sheets, Slides,
235 Calendar and Calls. `signin.go` draws rastrillo's screen
236 (`SigninScreen` + `SigninOneWay`) inside estilo's door
237 (`estilo-signin-screen`), in rastrillo's approved words; only the
238 refusal and the removal are Memoria's. Every door is drawn signed out.
239 With Home, `/signin` is connect's `SigninDoor` (Continue with Oficina
240 ID), `/signin/local` the email-only door and `/signin/oficina` the
241 exchange, all three behind `signin_admission.go`'s probe of
242 `requireSession`, which judges web sign-ins only (an emailed link,
243 Keymail, a Home sign-in), reads any 5xx as undecided (never a
244 refusal), and ends nothing itself: `offboard` skips its sign-out under
245 the probe, and the door ends what it refuses. A Home link that cannot
246 be read is a no-store 503, never a 404 a probe would read as a refusal.
247 Oficina ID is remembered in `MintHomeSession`, for a session the
248 strict probe admits, with connect's resolved address and nothing
249 carried over. `POST /auth/begin` is `beginSignin` (return_to off
250 Begin's form, into return.go's memory, even on a parse error; a post
251 without one forgets the kept page) around `beginGuard` (gate 33: a
252 stranger gets rastrillo's `AnswerAsSent`, Begin's own Sent without the
253 mail, so the answer is the same down to the attempt cookie). Every
254 landing spends the kept page before it answers; Forget and Sign out
255 clear it; `/signed-out` is never kept. `/signed-out` answers in both
256 modes, with "Forget me on this device", chained to Oficina ID's own
257 Forget with Home. In team mode connect needs `Admit` beside `HomeOnly`
258 and `Unlinked` (`teamAdmit`), and the member choice is mounted at
259 `/account/home/choose`.
260- `requireSession` **fails closed**. The test seam is `AppForTest`, named
261 so it cannot be reached by accident, and two gates hold both ends. An
262 earlier version failed open and justified it with a test that did not
263 exist.
264- The app refuses to start without a DEK, an instance key, owners, and
265 either SMTP or an explicit `MEMORIA_ALLOW_LOGGED_MAIL=1` β€” because
266 without SMTP rastrillo logs the magic link, and that link is a live
267 credential in storage we cannot delete. **In team mode** (the five
268 `MEMORIA_TEAM_*`, spec Β§4.3 "Roster team mode") the owners list is
269 optional and admits a local sign-in only; the roster decides everything
270 else, on every request.
271- **Team mode: ask `a.teamMode()`, never `a.team != nil`.** A configured
272 instance whose runtime is missing must refuse, not fall back to the
273 owners list. A person-made write goes through `Store.guard`/`guarded`
274 inside its own transaction; the instance's own work (a connector run, a
275 sibling poll) is `systemWrite`, and a write with neither is refused. A
276 list asks `teamReaches` before it is built and `teamPartial` after.
277
278**Deploys**
279- One binary, `CGO_ENABLED=0`, cgo-free SQLite.
280- `carlos deploy`, never `carlos ship`. Flags before the binary path.
281 Until `carlos deploy` takes `--mail`, the exception is mail
282 submission: `carlos ship --mail submit`, then `carlos promote`
283 (README, Deploying), because every instance of a switched app must
284 run a build shipped with the flag.
285- `make release`, never a bare `go build`, or `/api/version` reports `dev`
286 forever. Poll the process, not `X-Carlos-Version`.
287
288---
289
290## Review
291
292Every spec and every branch is reviewed by a model that did not write it,
293before it is approved or merged, and the reviewing model is recorded.
294**Seventeen passes so far, on two strands that ran in parallel and are
295counted together here because they are one project.** Spec drafts 1–3 by
296GPT Sol and Fable; draft 4 by Fable 5.1; draft 5 by a reviewer **whose
297attribution is disputed** β€” it named itself as the model that wrote the
298draft, so that pass may not satisfy this rule at all. The slice-0 code by
299Fable, the drag-and-drop branch by Fable 5.1, and five on the suite strand:
300the Β§8.3 provider amendment, Β§8.4's shape, gate 17 with the live-key
301verification, the doctrine adoption, and an adversarial mutation pass on
302the sign-in dial gate (gate 33 since the merge renumbered it). Slice 1's
303S1/S3 clients, Β§4.1's policy layer and Β§6.5's fan-out by Fable 5.1
304(2026-09-06): twenty-two mutations, eleven survived. The roster, the poll
305loop and the warm-up by Fable 5.1 (2026-09-07): twelve mutations, seven
306survived, and five of its ten probes found live defects rather than gate
307gaps. The breaker and the sources page by Fable 5.1 (2026-09-07):
308nineteen, thirteen survived, three live defects.
309
310**Every one returned REQUEST CHANGES.** The most useful have been the ones
311aimed at tests rather than prose. The provider review found a rule broken
312in the paragraph that stated it, twice, and a fourth gate that could not
313have gone red (Β§1.7); the next found a product ruling argued from two
314misread sections of this same spec (Β§1.8); the next mutation-tested a gate
315its author had already mutation-tested and broke it five more ways (Β§1.9);
316the adoption review found a rule invented while citing the section that
317forbade it, plus eight contradictions in sections the commit never opened
318(Β§1.10); and the gate-27 pass found **two live bypasses in shipped code**,
319not mutations. The drag-and-drop review found two more the same way β€” by
320re-running the mutations their author claimed to have run, rather than
321taking the claim. The slice-1 review found two more, and the first is the
322worst kind: `Content` fired S3 at `?item_id=`, and the module declares
323the route as `/suite/s3/{item_id}?revision=` on the line that names the
324constant. Against a conforming sibling every fetch would have 404'd, read
325as "not team-visible, or gone" β€” the plausible empty list on the one call
326that fills the corpus β€” and Β§8.1's S3 breaker would then have reported a
327permissions anomaly for a routing bug. **The test pinned the wrong shape
328too**, which is why it was green: an author's fixture is written from the
329same wrong model as the code, so it cannot be the thing that catches it.
330The next review found the same failure again in a different field: suite
331hosts are `<team>.<app>`, this repo's own documented example had them
332reversed, every fixture copied the example, and nothing checked β€” so the
333roster accepted an address every call would then be refused for, before
334dialling, forever, with a page blaming a healthy app.
335
336**The pattern is one failure wearing several coats:** the writer checks
337their work against their own model of it rather than against the thing.
338Open the section you are citing. Open the constant you are calling. Run
339the mutation you did not think of.
340
341**A test written from the same model as the code is part of the code.**
342It cannot catch a wrong assumption; it records one. The S3 route, gate
34323's bounds, the sixth disposition born silent, the swapped host labels β€”
344each had a test, each test agreed with the bug. What found them was
345somebody who had read the module and the spec instead.
346
347**Grepping for a string is not reading a selector β€” or a route, or a
348constant.** The callout tone was got wrong three times: `rst-callout=
349"danger"`, then `[rst-callout] data-tone=`, and only then the
350`rst-tone` the stylesheet actually pairs with the attribute spelling.
351The second attempt was the commit that described fixing the first, and
352its tests passed because `data-tone="negative"` *is* in the stylesheet β€”
353inside the class selector standing next to the one needed. A check that
354greps will confirm any spelling that appears anywhere in the file. Read
355the selector, the route declaration, the constant.
356
357**The section you did not open is where the fix already was.** Β§8.1's
358breaker clause was amended here on a real observation and a wrong
359remedy; Β§13 already carried the correct one, three thousand lines down,
360and it was not opened. The amendment was made in the course of fixing
361another instance of exactly this. **Before amending a section, grep the
362spec for what it governs** β€” the open-items list is where the last
363person left the answer.
364
365**A gate over source text proves a call is spelled, never that it is
366reached.** The `cmd/` wiring gate walks the AST for a call expression, and
367a reviewer defeated it twice in ordinary Go: `app.UseAuth(a)` inside a
368closure nobody invoked, and the sibling wiring behind `if len(apps) > 1`
369so a one-sibling instance ran unwired. Both read as present. The answer is
370not a cleverer walk β€” that is a race against however the next person
371writes it β€” but to **leave nothing in `main` worth getting wrong**: move
372the logic into a function with tests and let the gate watch for one call
373disappearing. `WireSiblings` is that shape.
374
375**And an absence gate needs its presence half even when the absence is
376the point.** "PolledAt was not set after a failed poll" passed against a
377Poll that never set it at all; the test only ever failed on page one, so
378neither half of the real behaviour was pinned. Assert the thing happens
379before asserting when it must not.
380When you retire something, grep for it by name β€” the sections you did not
381open are where an adoption commit goes wrong, because a rewritten section
382has been read twice and an untouched dependant never.
383
384**Review a merge against both parents, never against the result.** The
385merge review found more than the four passes before it combined, and it
386found it by diffing the merge against each side rather than reading what
387came out. Reading the output cannot tell you what is missing, and a merge
388is the one change whose defects are all absences (Β§1.11).
389
390**And a reviewer's self-reported model id is not evidence.** Record what
391was dispatched and what came back, and record the disagreement when they
392differ β€” twice now they have.
393
394---
395
396## Authorship
397
398πŸ€– / πŸ‘¨ markers, `Co-Authored-By` trailers. AI is a guest with a name tag:
399opt-in, disclosed, and every path works with it switched off β€” which in
400slice 0 means the whole product does.
401
402## Work in a worktree, and catch main up first
403
404Take a worktree for the work. Do not work in the shared checkout.
405
406 git -C <repo> fetch origin
407 git -C <repo> worktree add ../<repo>-<task> -b <branch> origin/main
408
409Both halves matter, for different reasons.
410
411**The worktree**, because several sessions share this machine and some
412share this repository, and a checkout has one HEAD, one index and one
413working tree between all of them. A branch switch under somebody else's
414uncommitted work destroys it with nothing on screen to say so, and two
415sessions editing the same paths disagree quietly instead of conflicting
416loudly. A worktree gives the work its own HEAD and its own files, and
417costs a directory.
418
419**From `origin/main`, after a fetch** β€” not from whatever the checkout
420happens to be sitting on. A branch cut from a stale main is a merge
421conflict scheduled for later, against files somebody else has renamed in
422the meantime. A branch cut from another task's branch is worse: it
423carries that task's commits into yours, where they are reviewed as
424though you wrote them, and the two can only be separated by hand.
425
426Remove it when the work has landed β€” `git worktree remove` β€” so that
427`git worktree list` keeps saying something true.
428
429Written down because of 2026-09-17, in `meet`. The shared checkout was
430sitting on one task's branch while holding a *different* task's feature
431uncommitted on disk β€” some four hundred lines, a new migration among
432them β€” put there by a session nobody else knew was working in that tree.
433Two other sessions were meanwhile coordinating over the same checkout by
434asking each other not to touch it, which is the arrangement a worktree
435makes unnecessary. Nothing was lost. Nothing about the arrangement would
436have said so if it had been, and by then the same feature existed twice,
437once on each side of a rename, because the two sessions had branched
438from different starting points.
439