oficina / mapa Public

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

Plain git — no account needed to clone.

Download

Download this file

1# mapa
2
3The Oficina suite's team knowledge base. The design is
4`docs/superpowers/specs/2026-11-12-mapa-design.md`, approved by Paul on
52026-11-12; read it before changing behaviour here. Its §15 records every
6choice the build made where the spec was silent or ambiguous. A change that
7departs from the spec needs the same review it had.
8
9A [rastrillo](https://rastrillo.org) app on the current
10`amadan.net/rastrillo/rastrillo` path (never the frozen
11`github.com/carlosframework/rastrillo` one; `TestNoFrozenRastrilloImport`
12forbids it), styled with estilo. Read rastrillo's SKILL.md
13(`go list -m -f '{{.Dir}}' amadan.net/rastrillo/rastrillo`) before writing
14app code. Modelled on Fichas (the in-memory index fed by the event log, the
15seal, the plaintext gate) and Portero (the pins, `.amadan/ci`, the
16Makefile, estilo's files served straight from the module).
17
18## Layout
19
20- `cmd/mapa/` — `rastrillo.Resolve` + `Serve`, after `LoadConfig`.
21- `internal/mapa/`
22 - `config.go` — every refusal to boot, tested.
23 - `auth.go`, `auth_navigation.go`, `door.go` — magic-link sign-in with
24 the `MAPA_OWNERS` admission list, Docs' keymail continuation, estilo's
25 door.
26 - `models.go`, `migrations/` — spec §3.1. `seal/` — the only encryption.
27 - `store.go` — `Store.write`, the one way to write: it refuses to commit
28 a transaction that logged no event (gate 8). Draft writes
29 (`drafts.go`) and retention (`retention.go`) are the exemptions, by
30 name (§5).
31 - `pages.go`, `verbs.go`, `aliases.go`, `daily.go`, `share.go`,
32 `markers.go`, `commit.go`, `history.go` — the §3.4 and §5 verbs.
33 - `markup/` — Mapa's Markdown subset: §3.2's blocks, links, the safe
34 renderer and the three-way block merge.
35 - `locale/` — dates, times and numbers in the reader's locale (level-up
36 build note 85): `dates.json`, CLDR's date patterns for the offered
37 locales (`make locale-dates` writes it from Node's ICU), and
38 `format.go`, their interpreter; numbers are rastrillo's. `locales.go`
39 picks the reader's locale through rastrillo's middleware and clones
40 the templates per locale. Write every date or count a person reads
41 through it (`{{longDate}}`, `{{stamp}}`, `{{number L n}}`,
42 `viewer.Locale`, `scope.Locale`); store and link ISO dates only.
43 The reader's locale is their own (Settings, `settings_locale.go`,
44 sealed by `members_locale.go`), else their browser's Accept-Language
45 alone, else `MAPA_LOCALE`.
46 - `index.go`, `graph.go`, `views.go`, `mentions.go`, `postings.go`,
47 `search.go`, `rank.go`, `suggest.go` — the in-memory index, fed by
48 the event log and partitioned by scope (§6.2).
49 - `readrule.go`, `s3.go` — S2's rule and S3's layout, item 6's seams.
50 - The Notion import (`docs/superpowers/specs/2026-11-17-notion-import.md`,
51 phase 1): `import_*.go`, the only files that import
52 `amadan.net/oficina/notion.git`. `import_connect.go` (NotionAccess,
53 the fake in tests), `import_credential.go` (connect, disconnect,
54 finish, forget), `import_book.go` (bookkeeping, fenced to notion_*),
55 `import_run.go` and `import_job.go` (leases, Stop, resume, the
56 goroutine), `import_survey.go`, `import_set.go`, `import_titles.go`,
57 `import_write.go` (Survey and Write), `import_store.go`
58 (`ImportCreate`, `ImportUpdate`), `import_images.go`,
59 `import_images_store.go` and `import_images_place.go` (the image
60 step over Mapa images, and notion_images), `import_history.go`
61 (History's and the kicker's words), `import_handlers.go`,
62 `import_view.go`,
63 `import_report.go` and `templates/import*.html` (the screens).
64 - `notionmd/` — the import's mapper, Notion's block tree to Mapa's
65 Markdown, pure, checking its own output against `markup`. It never
66 imports the notion module: its tree is Mapa's own copy.
67 - `handlers_*.go`, `today.go`, `private.go`, `settings.go`,
68 `render.go`, `shell.go`, `templates/`, `static/` — the screens, and
69 estilo's files taken straight from the pinned module.
70 - The level-up's shell (`docs/superpowers/specs/2026-11-14-mapa-level-up.md`):
71 `frame.go`, `menus.go`, `side.go` and `templates/frame.html` build
72 estilo's stacked bar, the menus and the sidebar with its rail;
73 `around.go` (the one scoped accessor every new read path uses),
74 `mapview.go`, `calendar.go` and `static/links.*` are the Links panel,
75 its map, the week and the month; `pins.go` and `recent.go` are the
76 sidebar's own lists; `lastedit.go` is the kicker's "Edited by".
77 `mapa.js` is the editor's and ⌘K's script layer, `links.js` the
78 panel's and `history.js` the History panel's; `frame.css`, `links.css`,
79 `history.css` and `palette.css` style them. `versions.go`, `diff.go`,
80 `diff_words.go` and `history_view.go` are the History panel's list,
81 summaries and word diff (level-up §4.5); `typeddate.go` and
82 `snippet.go` are ⌘K's typed dates and marked snippets.
83 Phase 2's server half: `autosave.go` and `handlers_autosave.go` are
84 the editor's autosave, its merge reply, `rebase` and `commit=1`;
85 `firstscratch.go` a new scratch page's single-flight first commit
86 (D12); `island.go` the editor's JSON island and `/links/resolve`;
87 `markup/settle.go` the byte-preserving `Settle`.
88- `editor/` — the page editor (level-up spec §6): `markup.mjs`, a
89 line-for-line port of `markup/`'s parser; `schema.mjs`, whose `toDOM`
90 is the server's HTML; and the bundle build, whose output
91 (`internal/mapa/static/editor.<hash>.js`) is committed. Gate L4
92 (`parity.test.mjs`) holds both to `markup/testdata/golden.json`, which
93 Go writes from the corpus beside it. Change the renderer, the parser
94 or the schema together, then `make golden` and commit the result.
95 `serialize.mjs` writes the document back as Markdown, re-emitting
96 untouched blocks and seams from `fidelity.mjs`'s side table (§6.4),
97 which also holds the settle plugin (reparse, marker and list rules),
98 rebuild and `prepareSave`; `clipboard.mjs` is §6.6's copy and paste.
99 Gates L1–L3 (`fidelity.test.mjs`) run over the same corpus; L3 writes
100 `markup/testdata/editor.json` (`make editor-golden`), which Go parses
101 in `editor_test.go`.
102 The editor on the page: `page.mjs` reads the island and mounts on the
103 `<article>`; `saver.mjs` is §6.5's autosave, commit, rebase, leaving
104 and closing (`adapter.mjs` is its view of the editor); `conflict.mjs`
105 the inline choice; `resolutions.mjs` and `chipview.mjs` the chips'
106 states; `keys.mjs`, `commands.mjs` and `inputrules.mjs` the keys,
107 blocks and Markdown shortcuts; `suggest.mjs`, `slash.mjs` and
108 `combobox.mjs` the `[[` and `/` lists; `datepicker.mjs` the date
109 picker `/` → Date and Insert → Date… open, reading typed dates with
110 `typeddate.mjs`, a port of `typeddate.go` held to it by
111 `internal/mapa/testdata/typed_dates.json` (build note 83);
112 `dates.mjs` writes dates from the island's patterns, held to Go by
113 `locale/testdata/date_labels.json` and L4's `golden_locales.json`;
114 `bubble.mjs` the selection's
115 toolbar; `pagelink.mjs` its Page link and ⌘L (build note 81);
116 `anchors.mjs` the ¶; `tasks.mjs` the task boxes; `writearea.mjs` a
117 click on the page's empty area (build note 84); `maketeam.mjs` Make
118 team page from a selection; `accessory.mjs` the
119 phone's row; `notices.mjs` the bars and the lead's save status;
120 `title.mjs` the title renamed in place, shared with the header's
121 field (build note 78).
122 `saver.test.mjs` is L9's client half; in `internal/mapatest/`,
123 `editor_browser_test.go` holds L5 and L9 end to end,
124 `editor_typing_browser_test.go` the typing, and
125 `editor_access_browser_test.go` L10, with axe-core vendored in
126 `testdata/axe/`.
127 - Images (`docs/superpowers/specs/2026-11-17-mapa-images.md`, its §12
128 the build notes): `imagefile/` sniffs, limits and strips each format
129 without decoding pixels; `images.go` (types, limits, the blob
130 semaphore), `images_store.go` (upload, sealing, Put),
131 `images_read.go` (the read rule, serving bytes, copies, the
132 allowances), `images_attach.go` (`tx.commit`'s explicit attaching
133 and the `unreferenced_at` stamp), `images_copies.go` (Make team
134 page's and `draftToScratch`'s copies), `images_remove.go`,
135 `images_sweep.go`, `images_render.go` (drawing on page P),
136 `images_list.go`, `images_bucket.go` (the bucket's own Put),
137 `config_images.go`, `handlers_upload_read.go` (uploads read into
138 bounded memory, never to a temporary file), `bodies.go` (every body
139 bounded; multipart for upload routes only) and `handlers_images*.go`.
140 In `editor/`: `imagedom.mjs`, `imageview.mjs`, `upload.mjs` (its
141 queue gated by `upload.test.mjs`), `imagebubble.mjs`, `altinset.mjs`
142 (the ALT badge and the description field over the image, build
143 note I22).
144 - A team page's look (`docs/superpowers/specs/2026-11-22-mapa-columns-icons.md`,
145 §2–§4, phase 1): `looks.go` (the record's `icon` and `banner`, the
146 `styled` verb, `SetLook`), `looks_images.go` (which images a look
147 may name, and a removal taking its image out of the look),
148 `looks_render.go` (drawing icons wherever a title is, the band),
149 `looks_history.go` (History's words), `handlers_look.go` and
150 `templates/look.html` (POST and the scriptless page),
151 `emoji/` (Unicode's RGI list, vendored at 16.0, and the picker's
152 JSON, `emoji_route.go`), `images_cache.go` (the small-image cache,
153 served only after the read rule) and `static/look.js` (the picker,
154 uploads and Reposition). A record's references are its body's and
155 its look's images (`Record.images`); chips draw icons from their
156 resolution (`markup.ChipIcon`), never from a node attribute.
157 - Column layouts (the same spec, §1, phase 2): `markup/columns.go` (the
158 strict grammar of §1.1, fences as blocks with `Block.Column`,
159 `FenceLike`, `Grammar`, `renderLayout`) and `markup/merge_columns.go`
160 (`ValidLayouts`, the merge's layout rules, `alignKeys`,
161 `addedColumns`, `WholeOrInside`); `grammar.go` (`countedHere`, the
162 409 for a post counted by another grammar); `versions_columns.go`
163 (History's words). In `editor/`: `columns.mjs` (the commands),
164 `markup.mjs`'s port of the grammar, the schema's `columns` and
165 `column` nodes, fence pseudo-blocks in `serialize.mjs` (their
166 origins on the containers: `originAttr`), and `fidelity.mjs`'s
167 `fenceRule` (D16). `make pandoc-fixture` records Pandoc's reading
168 (`markup/testdata/pandoc.json`, COL12).
169 - Pages inside (the same spec, §5, §6.3, phase 3): `inside.go` (the
170 "In: [[P]]" relation, derived in the index's `within` map, and the
171 scoped `Inside`), `side_inside.go` (the Pinned rows' arrows, the
172 `mapa-open` cookie, `POST /view/open` and `GET /p/{id}/inside`),
173 `import_pins.go` (the import pins its roots once, marked in the
174 sealed coordinate). Pins hold up to 20 (`pins.go` still reads a
175 list sealed at 12).
176 - The importer's looks (the same spec, §6.1, §6.4, phase 4):
177 `import_looks.go` (a page's icon and cover prepared before its
178 write, under notion_images' pseudo-blocks `icon:` and `cover:`;
179 covers fetched only from Notion's file store and its cover gallery,
180 the one external path the notion module pins), and `ImportUpdate`'s
181 styled revision between the renamed and the edited.
182- `internal/mapatest/` — the gates of spec §11, from the outside.
183 `browser_test.go` is behind the `browser` tag.
184- `scripts/preview/`, `scripts/mutate/` — `make preview`, `make mutate`.
185
186## Rules Mapa holds hard
187
188- **Sealed at rest.** Titles, aliases, dates, bodies, drafts, addresses and
189 time zones are sealed. The plaintext columns are exactly §4's list:
190 `plaintext_test.go` reads the real schema, and the file scan signs in
191 for real and reads every byte on disk, WAL included (gate 4). The one
192 named exception is rastrillo's: a signed-in address in its own
193 `auth_links` and `auth_sessions` rows (spec §4), never in Mapa's tables.
194- **Every write logs an event**, in the same transaction (gate 8). Mapa is
195 never an actor: every event names a person.
196- **A GET never writes.** Not a member row, not a draft, not a daily note
197 (gate 10). A person's member row is created by their first write.
198- **Scope before traversal.** Every read of the in-memory index is team
199 pages plus the viewer's own private pages, and nothing anywhere counts
200 what the viewer cannot see (§3.3, §6.3, gate 1).
201- **A row you may not see is a 404**, never a 403.
202- **Mapa reaches the network in two places only:** Notion, through
203 `amadan.net/oficina/notion.git`, only from `import_*.go`, only during a
204 run (and the one verify call when a token is saved); and CARLOS's own
205 bucket, for images, from `images_bucket.go` and `config_images.go`. No
206 client, transport, dialler or resolver anywhere else in `internal/mapa`
207 or `cmd` (gate I8 names the two image files). Rastrillo's sign-in mail
208 lives in rastrillo.
209- **Screens work with JavaScript off**; destructive actions get their own
210 confirm page.
211- The gate is `make ci` (vet, gofmt, rastrillo's code budget, Fiesta's
212 spacing check, tests, migration check, and `make editor`: npm ci, the
213 bundle rebuilt with no drift, `node --test`), the same definition CI
214 runs. It needs `node` and `npm` on PATH. `make spacing` holds every
215 margin, padding and gap in `internal/mapa/static` to a
216 `var(--rst-sp-N)` step or a `/* spacing-allow: why */`, and `make
217 browser`'s rhythm audit holds the signed-in screens to the scale
218 (level-up build note 89). `CGO_ENABLED=0`
219 throughout. Use `make`, not bare `go test`: the Makefile pins the
220 toolchain. `make browser` is gate 7 and `make mutate` proves gates 1, 4
221 and 8 can fail, that a rename carries only drafts on its own base
222 (L9, level-up build note 79), that Recently edited filters team
223 pages inside its query (build note 80), the images' named risks
224 (`scripts/mutate/images.go`), and that the Notion import's gates I1
225 to I25 can (`MUTATE_GATES=I3,I13` runs a few).
226
227## Serving
228
229 MAPA_DEK=<base64 32 bytes> MAPA_INSTANCE_KEY=<secret> \
230 MAPA_OWNERS=ana@example.com MAPA_ALLOW_LOGGED_MAIL=1 \
231 ./mapa -addr 127.0.0.1:8834
232
233`MAPA_TIME_ZONE` is the team's default time zone (UTC if unset).
234`MAPA_LOCALE` is the team's locale, how dates and numbers are written
235for a browser that asks for none Mapa offers (en-IE if unset; one of
236`locale.Offered()`, spelt as CLDR does).
237`MAPA_IMPORTERS` names who may import from Notion, each also an owner;
238unset, the import does not exist.
239`HOME_DIRECTORY_ORIGIN` adds "All apps" to the account menu. `GET /healthz`
240and `GET /api/version` are the framework's. `make preview` serves the real
241app over synthetic pages, signed in, on loopback.
242
243## Known follow-ups
244
245- **estilo's `chrome` imports the frozen rastrillo path**, so `go.mod`
246 carries it indirectly. Mapa imports nothing from it.
247