oficina / sheets Public

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

Plain git — no account needed to clone.

Download

Download this file

1# πŸ€– Sheets
2
3A CARLOS spreadsheet. 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. Both files live here, so that is a
8rule this repository can actually keep.
9
10Where the design spec disagrees with the suite sharing doctrine
11(`oficina/suite`), the doctrine wins and **the spec is wrong β€” fix it by
12citing the ruling, not by restating it**. That cannot be one commit, because
13the doctrine is another repository; a cross-repository request goes through
14`amadan discuss` on the repo whose text must change.
15
16**The design:** `docs/superpowers/specs/2026-08-30-sheets-design.md`. Its
17Β§1 is the settled-decisions table: dated, attributed, with the rejected
18alternative beside each. Don't relitigate one in a drive-by.
19
20---
21
22## The one rule
23
24> **A sheet's contents are sealed at rest. The bucket never holds a
25> plaintext cell.**
26
27The instance holds the key while it runs, so the server *can* read a sheet
28it has open. That is a deliberate softening, not an accident, and the spec's
29Β§2 names every leak it produces. What the rule forbids absolutely is a
30plaintext value reaching the replicated SQLite file or object storage.
31
32A test greps raw SQLite bytes and bucket objects for plaintext from the
33first commit. `plaintextExempt` starts empty; any entry is dated, justified,
34and listed in the README.
35
36**We never claim "we can't read your data."** A compromised live host can
37read any open sheet. The README says so and the UI never implies otherwise.
38
39---
40
41## Review β€” RULED 2026-08-30 by Paul
42
43**Every spec and every branch is reviewed by the highest-capability model
44available before it is approved or merged.**
45
46Not the model that happened to write it, and not whichever model the
47session started on. Cheaper models draft; the most capable one available
48reviews. A review by a weaker model than the author is not a review.
49
50Mechanically:
51
52- **Specs** β€” a review pass before the spec is presented for human approval,
53 and again after any material change to a settled decision.
54- **Branches** β€” a review pass before the PR is opened, and again after any
55 force-push that changes more than a rebase.
56- **Record which model reviewed**, in the PR body or the spec's status line.
57 A review nobody can attribute is a review nobody can check.
58
59**The highest-capability model is discovered, not hardcoded.** At the time
60of writing that is Opus; naming a model here without saying how to re-derive
61it is how this rule goes stale silently. The check is: what is the most
62capable model this session can actually reach right now. If a session cannot
63reach one at least as capable as the author's, it says so and waits rather
64than passing a weaker review off as done.
65
66This is a floor, not a ceiling β€” an extra pair of eyes, human or model, is
67always welcome on top.
68
69---
70
71## Shipping cadence β€” RULED 2026-08-30 by Paul
72
73**Everything happens on a worktree, on a branch.** Never directly on
74`main`, and never in the primary checkout.
75
761. **Worktree per session.** One isolated workspace per piece of work.
772. **Branch per piece of work**, cut from current `main`.
783. **Commit regularly and push to the branch.** Small commits that tell the
79 story, pushed as they land β€” not one heroic commit at the end. A branch
80 that only exists locally is work nobody can see or recover.
814. **Squash-merge to `main`** when, and only when, all three hold:
82 - the work is **done** β€” not "done except",
83 - it is **approved** β€” including the Β§Review pass by the
84 highest-capability model available,
85 - **CI is green** β€” actually green, checked, not assumed.
86
87Any one of the three missing means it does not merge. "CI was green
88before the last push" is not CI being green.
89
90Review happens on a **deployed canary**, never localhost. Shared hosts only
91ever run merged `main`.
92
93**Every branch gets a discussion, and that discussion IS the review
94record** β€” including which model reviewed it (Β§Review). A discussion
95survives a squash where a PR body does not. Tasks are a checklist, not a
96log: commentary belongs in the discussion.
97
98**A refusal gets surfaced in the discussion, never routed around.** Straight
99from amadan's own house rules, and the rule most likely to be quietly
100ignored.
101
102---
103
104## Intent before code
105
106CARLOS's first principle: the design doc precedes the build, and its
107decisions are taken. If one proves wrong, **stop and flag it** rather than
108quietly redesigning around it.
109
110Keep the spec's "Deliberately not built yet" table honest. Every deferred
111thing has a written trigger. A thing deferred without a trigger is a thing
112forgotten.
113
114---
115
116## Mechanical rules
117
118Rules here are enforced by tests, not by memory. If you find yourself
119relying on remembering one, make it a test instead.
120
121**Data**
122- **Never `scope.Owned` or `scope.OwnedBy` on a team-shared table.** Both
123 are single-column equality (`Owned` is literally `Where("user_id = ?")`),
124 and our sheets, tabs and cells are team-shared. Applied to them, a sheet
125 list returns **only the creator's rows** β€” it fails as a plausible empty
126 list, not as an error, which is the worst available failure shape and also
127 the default thing to reach for. Access goes through the hand-written
128 grants join. `scope.Owned` is still correct for genuinely per-user rows.
129- A row that isn't yours **404s, never 403s** β€” preserved by hand in the
130 grants join, and test-enforced by the two-user isolation suite.
131- Scope `tx`, never the outer handle, inside transactions, or the
132 one-connection writer pool deadlocks.
133- Never bind a request body onto a GORM model. Explicit `map[string]any`
134 plus a `.Select` allowlist.
135- Resolve the viewer through the app's `identity` and `actor` helpers. Local
136 sessions retain verified addresses; opt-in Home sessions contain opaque Home
137 subjects and must resolve through the shared connection to existing members.
138 Never create members from Home subjects or infer links from matching addresses.
139 Never use `sessions.UserID`: it does not resolve either identity shape.
140- Home links require independent fresh local and Home proofs plus confirmation.
141 Recheck existing admission and sheet grants on every Home request. Member IDs
142 are AUTOINCREMENT and must never be reassigned; any future deletion path must
143 remove the member's `home_identity_links` rows in the same transaction.
144- **Team mode is the one exception to "never create members from Home
145 subjects"** (Home `implementation/team-members.md` Part B). With
146 `SHEETS_TEAM_*` set, a Home subject the roster says is a Member *at that
147 moment* gets an addressless member (`teamstate.EnsureHomeMember`, from
148 connect's `Unlinked` hook in `team_home_only.go` only, behind
149 `teammode.Runtime.AdmitUnlinked`). That row is identity, never standing:
150 standing is the roster's answer on every request (`home/teammode`'s
151 `Access`, `team_access.go`), and **`members.team_role` is never read in team
152 mode** β€” reading it is how a removed owner kept access. Team configuration,
153 the marker, the roster runtime and the probe are `home/teammode`'s; do not
154 grow a private copy back. Without `SHEETS_TEAM_*`, every rule above stands
155 unchanged.
156- **In team mode every write is guarded inside its own transaction**
157 (`team_guard.go`, `store.Guard`): the handler's `roleFor` decides whether a
158 write may start, `teammode.Guard` re-checks standing before and after the
159 write, in the writer transaction, so a lease that lapses mid-write fails the
160 commit. A new write path takes `a.writeGuard` (or `a.memberGuard` for
161 create and import) and answers a refusal with `a.guardRefused`.
162 `TestTeamEveryWriteRouteRefusesALapseBeforeCommit` lists every write route;
163 add yours to it.
164- **A team-mode database stays in team mode.** `sheets_team_required` refuses
165 boot without team configuration or with a different binding. Do not
166 "fix" a refused boot by deleting it; the triggers refuse that anyway.
167- Migrations are additive-only. New code over an old DB is always safe.
168 Never delete data to update.
169- **Cell values are IEEE doubles end to end.** Currency is a number format,
170 not a type; `=A1*1.05` produces a double and XLSX stores a double.
171 Storing cents would round the evaluator's own output. The family's "a
172 float never touches an amount" rule binds **app-owned** amounts only β€”
173 billing, quotas, anything Sheets itself counts.
174- **No cell content, comment text, sheet title or tab name in any log line,
175 error string, job status message or metric label.** `carlos logs` is
176 platform-held storage we cannot grep. Errors carry coordinates and codes.
177
178**Frontend**
179- No build step. Jspreadsheet CE is vendored as a static asset, not fetched
180 from a CDN and not bundled.
181- **Both vendored stylesheets paint in literals, and every rule the app
182 can render must be restated in `sheets.css`.** `TestVendorPaintIsRestated`
183 holds the list and checks it in both directions β€” that each vendored
184 selector still exists (v5 renamed every `.jexcel` to `.jss_*` once
185 already) and that we restate it. Rules the app cannot render are named
186 in that test with a checkable reason, never silently dropped.
187 Two more guards sit beside it: no colour literal may appear in
188 `sheets.css` at all, and `sheets.css` must stay linked before the head
189 block that carries the vendored links.
190- **Restate at `> tbody > tr > td.foo`, never at the library's own
191 `.jss_worksheet .foo`.** Two independent reasons, and the second is the
192 one that bites: our grid-line rule is one specificity step higher than
193 the library's, *and* `sheet.html` links the vendored stylesheets into a
194 head block that `layout.html` renders after `sheets.css`, so the
195 library is later in source order and an equal-specificity restatement
196 loses on order alone. Ours must be strictly higher, never merely equal.
197 Written short, a restatement parses, uses a token, and paints nothing β€”
198 which is how the grid's selection outline went missing in dark for the
199 whole of the `core` branch.
200- **Write the attribute grammar: `rst-btn="primary compact"`, not
201 `class="rst-btn rst-btn--primary"`.** This reverses the earlier rule in
202 this file, which was written against v0.20.0 where the attribute
203 spelling genuinely did not exist. It landed in v0.21.0 and is complete
204 in the pinned v0.23.0: measured against
205 `$(go env GOMODCACHE)/github.com/carlosframework/rastrillo@v0.23.0/ui/tokens.css`,
206 every class selector has an attribute twin, and rastrillo enforces that
207 itself with `TestEveryClassSelectorHasAnAttributeTwin`. Both spellings
208 are specificity `(0,1,0)`, so pairing changes no cascade. The class
209 spelling is scheduled for removal before 1.0.
210 - The grammar: a bare attribute is the KIND (`rst-callout`); a token in
211 its value is a VARIANT, matched with `~=` so values compose like a
212 class list; a PART is its own flat attribute (`rst-callout-body`),
213 never a value.
214 - **Utilities stay classes.** Seven names are class-only by design, and
215 correctly so: `rst-grow`, `rst-mono`, `rst-sr-only`, `rst-m-hide`,
216 `rst-danger`, `rst-nm`, `rst-cell-mut`. An attribute says what a thing
217 *is*; a class says what is being applied to it.
218 - `rst-tone` pairs with `data-tone` rather than with a class.
219 - Adopt per screen, never per element β€” mixed spellings inside one
220 component match neither.
221- **rastrillo is `amadan.net/rastrillo/rastrillo`.** The old path,
222 `github.com/carlosframework/rastrillo`, stops at v0.23.0: code importing
223 it gets no fix, and its own checks cannot tell (Sheets zoomed iOS on
224 every tap for a month that way). `TestNoPreMoveRastrillo` allows one
225 import of it, native.go's bridge to rastrillo/native's server, until
226 that server moves. The CLI is pinned as a `tool` in go.mod: run it as
227 `go tool rastrillo …`, never a `rastrillo` from PATH.
228- **After `go tool rastrillo doctor --fix`, delete the scripts it adds**
229 (`static/rastrillo.js`, `select.js`, `datetime.js`, `calendar.js`).
230 Sheets serves estilo's shim and busy.js from memory and uses no other
231 rastrillo script; the shim doctor adds at this pin still carries the
232 old busy rule, which fights estilo's. `TestBusyRuleIsLinkedAndServed`
233 fails if one is left behind.
234- **Run `rastrillo doctor` on every rastrillo upgrade**, and
235 `rastrillo doctor --fix` to re-copy what drifted. `static/tokens.css` is
236 frozen at scaffold time while the partials it styles keep upgrading with
237 the module, so an app can run new markup against old CSS and see nothing
238 worse than a slightly wrong screen. `doctor` shipped in v0.22.0 (verified:
239 `rastrillo doctor --help` offers `-fix`, `-force`, `-theme`). It reports a
240 version mismatch as a mismatch rather than as drift and refuses `--fix`
241 across one, since copying newer assets into an app built against an older
242 framework manufactures the fault it is looking for. **So upgrade the
243 `doctor` binary alongside the module** β€” a `doctor` one release behind
244 compares against its own library copy and calls the upgrade you just did
245 the drift.
246 - **Until `native.go` moves off the pre-move module path, `doctor` refuses
247 to run here.** `go.mod` still requires `github.com/carlosframework/rastrillo`
248 v0.23.0 for the native server's sessions, and `doctor` stops at that
249 ("No files were compared"). Meanwhile `static/tokens.css` is re-copied
250 by hand from the pinned module's `ui.TokensCSS()` on every rastrillo
251 upgrade, and `TestSharedThemeAssetFingerprintAndCache` pins it to
252 those bytes. `doctor`'s template checks are blind meanwhile: read the
253 changelog's markup notes for each release yourself.
254- **Theme bytes come from the Estilo module pin.** There is no app-local
255 `static/theme.css` to copy. On framework upgrades, update the Estilo pin
256 to the same released `day` body and run the theme asset tests. Estilo's
257 byte-for-byte test and this app's `theme_assets_test.go` detect drift;
258 `rastrillo doctor` reports the absent theme as not compared. Its token
259 checks still apply. Do not recreate an embedded theme file that the
260 served filesystem would shadow. This matters at v0.23.0 because tokens
261 require `--rst-header-rule`; an older theme silently loses the rule.
262- Don't build on `.rst-page-header::after` β€” the rake line is retired in
263 favour of `--rst-header-rule` (rastrillo v0.23.0, design doc Β§6-v2.2).
264 It was retired because, built from the same parts in the same order, it
265 was indistinguishable from a determinate progress bar at 12%. The rule
266 is decorative and carries **no** contrast floor: it is deliberately
267 absent from rastrillo's contrast pair table, and a later pass must not
268 argue it up to 1.4.11's 3:1.
269- 300-line JS module cap, test-enforced, ratchet-down only. The vendored
270 Jspreadsheet blob is exempt and named as such; nothing we write is.
271- Every drag-only affordance has a menu equivalent.
272- **Light/dark is per person, not per document**, and must resolve before
273 first paint β€” cell fills resolve against the theme, so a late preference
274 repaints every coloured cell. Read it synchronously from a cookie, never
275 a fetch.
276
277**Deploys**
278- One binary, `CGO_ENABLED=0`, cgo-free SQLite. A cgo driver sneaking in is
279 a bug.
280- Review on a deployed canary, never localhost.
281- **Deploy with `carlos deploy`, never `carlos ship` on its own.** `ship`
282 publishes a release and stops there: the release sits unpromoted, no
283 channel points at it, and nothing serves it. `deploy` ships, promotes
284 and waits for the URL β€” one command, and it is the one that tells you
285 when it is actually live. (Paul, 2026-08-31.)
286 **Until `carlos deploy` takes `--mail`, the exception is mail
287 submission:** every build must be shipped with `--mail submit`, which
288 declares that it sends through CARLOS mail submission
289 (`mail.FromCarlos`, `LoadAuthEnv` in `internal/sheets/auth.go`, From
290 `$CARLOS_MAIL_FROM`). Until `carlos email submission on --app sheets`
291 runs, Sheets keeps sending over `CARLOS_SMTP_*`; after it the agent
292 sets `CARLOS_MAIL=submit`, Sheets holds no mail credential, and every
293 instance must run a build shipped with the flag. `carlos deploy` has
294 no `--mail` flag yet (carlos main 9eec0236), so ship and promote, then
295 poll `/api/version` as below: `carlos ship --app sheets --account
296 oficina --mail submit --version <v> --target linux-arm64
297 releases/sheets-linux-arm64`, then `carlos promote --app sheets
298 --account oficina <v>`. Once it ships, `carlos deploy --mail submit`
299 replaces both.
300- **Build shipping binaries with `make release`, never a bare `go build`.**
301 It stamps `rastrillo.BuildVersion` via `-ldflags -X` and refuses a dirty
302 tree. An unstamped binary reports `dev` from `/api/version` forever.
303- A 200 is not a deploy verification, and neither is `X-Carlos-Version`.
304 That header is the **router's adopted release**; it flips the moment the
305 promote lands and says nothing about which binary is running. `GET
306 /api/version` is served by the process itself. Check the process, not
307 the edge.
308- A promote is not a deploy. Until the process cycles, the old binary
309 serves β€” measured at over 90 seconds here on three consecutive deploys,
310 and about ten on another app, so poll rather than sample. A single early
311 read looks like a failed deploy; a single read against an unstamped
312 binary reports `dev` and looks like a successful one.
313- The two facts only disagree when the binary is stamped. Unstamped, they
314 are structurally incapable of disagreeing, so a check comparing them has
315 no failing case and proves nothing while passing.
316
317---
318
319## Authorship
320
321πŸ€– / πŸ‘¨ markers, `Co-Authored-By: Claude …` trailers, published prompt and
322carbon ledgers. AI is a guest with a name tag: opt-in, disclosed, and every
323path works with it switched off.
324
325## Work in a worktree, and catch main up first
326
327Take a worktree for the work. Do not work in the shared checkout.
328
329 git -C <repo> fetch origin
330 git -C <repo> worktree add ../<repo>-<task> -b <branch> origin/main
331
332Both halves matter, for different reasons.
333
334**The worktree**, because several sessions share this machine and some
335share this repository, and a checkout has one HEAD, one index and one
336working tree between all of them. A branch switch under somebody else's
337uncommitted work destroys it with nothing on screen to say so, and two
338sessions editing the same paths disagree quietly instead of conflicting
339loudly. A worktree gives the work its own HEAD and its own files, and
340costs a directory.
341
342**From `origin/main`, after a fetch** β€” not from whatever the checkout
343happens to be sitting on. A branch cut from a stale main is a merge
344conflict scheduled for later, against files somebody else has renamed in
345the meantime. A branch cut from another task's branch is worse: it
346carries that task's commits into yours, where they are reviewed as
347though you wrote them, and the two can only be separated by hand.
348
349Remove it when the work has landed β€” `git worktree remove` β€” so that
350`git worktree list` keeps saying something true.
351
352Written down because of 2026-09-17, in `meet`. The shared checkout was
353sitting on one task's branch while holding a *different* task's feature
354uncommitted on disk β€” some four hundred lines, a new migration among
355them β€” put there by a session nobody else knew was working in that tree.
356Two other sessions were meanwhile coordinating over the same checkout by
357asking each other not to touch it, which is the arrangement a worktree
358makes unnecessary. Nothing was lost. Nothing about the arrangement would
359have said so if it had been, and by then the same feature existed twice,
360once on each side of a rename, because the two sessions had branched
361from different starting points.
362