# 🤖 mapa

The Oficina suite's knowledge base. One instance per team.

Linked notes for a team: pages of Markdown, `[[links]]` between them,
backlinks, and a daily note for each person. Fichas is the team's
database, Docs is where the team publishes, and Mapa is where the team
thinks. memoria indexes all three.

## Status

**Slice 1, items 1 to 5, is built** on `feat/slice-1`, for review. Nothing
is merged or deployed, and there is no CARLOS app. Item 6, the suite
producer half (S1, S2, S3), waits for the team host (see below). Embeds,
S10, Fichas, the graph view, export and Promote to Doc are later slices.

## The design

`docs/superpowers/specs/2026-11-12-mapa-design.md`, approved by Paul on
2026-11-12. Read §1 first, then §13 for his rulings. §15 lists every
build note: a place the build had to choose where the spec was silent.

## What works

- **Today** is your daily note, in your own time zone, created by its
  first save and never by opening it.
- **Team pages** share one namespace: create, edit, rename (the old title
  stays an alias), free an alias, delete through a confirm page, restore
  a deleted page as a new one, and update links after a rename.
- **Links**: `[[Title]]`, `[[Title|shown]]`, `[[Title#^id]]`, pending
  links that offer to create their page, date links that open your own
  note, backlinks with their context, and unlinked mentions with "Link
  it". "Link to a block" mints a `^id` as an edit to that page.
- **Scratch pages**, and **Make team page** from chosen blocks of a
  private note.
- **Search**: `GET /search?q=`, and ⌘K with scripts on. Team-only ranking
  statistics; every read scoped to team pages and your own.
- **Editing**: a textarea and Save, revision-checked and merged by block,
  with a conflict view when two people changed the same block. With
  scripts on: live preview, `[[` completion, link paste, and autosave
  through your draft, committed on Save or after two minutes idle.
- **History** for 90 days, with restore; abandoned drafts kept 30 days.
- **Import from Notion** (`docs/superpowers/specs/2026-11-17-notion-import.md`,
  phase 1): pages shared with a read-only Notion integration become team
  pages, with mentions, dates and nesting as links. Re-runnable until
  Finish: an untouched page updates, an edited one is kept, nothing is
  deleted on absence. Only the people in `MAPA_IMPORTERS` (each also in
  `MAPA_OWNERS`) see it; unset, its routes do not exist. Images are left
  as a line saying they were not imported until Mapa has images.

## What the Notion import leaks

Beside spec §4's list (its §5, §15):
- **Mapa holds a Notion token** while a connection exists, sealed, never
  rendered, deleted on Disconnect, on Finish and after 90 days unused.
- **Mapa dials `api.notion.com` and Notion's file hosts**, only through
  the pinned `amadan.net/oficina/notion.git` module, during a run and
  once when a token is saved. Notion and its storage provider learn the
  instance's egress address and when it imports. No content goes out.
- **The file shows** when imports ran, who ran them, how many Notion
  pages they saw and wrote and how many failed, and, through the event
  log, which team pages an import created and roughly their order in
  Notion. Not their titles, bodies or Notion ids.

## Known limits

- **A new page's text is lost if its tab closes before the first Save.**
  Autosave writes a draft, and a draft is keyed by a page or a day (spec
  §3.1); a new team page or scratch page has neither until it is saved.
  Keeping it would need a draft key of its own (a random id from the
  tab), which is a new plaintext column and so a change to §4's list. It
  waits for a review of that change (spec §15, build note 25).
- **Addresses are in the clear in rastrillo's sign-in rows**, as in every
  sibling (spec §4). Sealing them is a suite-wide follow-up in rastrillo.

## Seams for item 6 (S1, S2, S3)

The producer half needs the team host (spec §10) and Paul's approval of
the memoria hookup. What it will stand on is already built and tested:

- **S1** is the event log: `events` holds one row per write, with a
  random nonce for the cursor, written in the same transaction as the
  change (gate 8). Pages carry their own nonce and random revisions.
- **S2** is `Store.MayRead`: team pages for every admitted member,
  private pages for their owner, whether or not still admitted (gate 9).
- **S3** is `Record.S3`: §8's layout, absent parts omitted with their
  separator, the body exactly as stored.
- What remains is the suite contract module, `conformance.CheckProducer`
  with §8's pinned expectations, and the routes, as Fichas has them.

## Deploying

`make release` builds `releases/mapa-linux-arm64`. Ship it declaring that
the build sends through CARLOS mail submission, then promote it:

    carlos ship --app mapa --account bds --mail submit \
        --version "$(git describe --tags --always)" releases/mapa-linux-arm64
    carlos promote --app mapa --account bds <version>

`--mail submit` is what lets `carlos email submission on --app mapa`
switch Mapa's mail to the platform: every instance must run a build
shipped with it. Until then Mapa keeps sending over `CARLOS_SMTP_*`, and
after it the agent sets `CARLOS_MAIL=submit` and Mapa holds no mail
credential (`mail.FromCarlos`, `internal/mapa/mailer.go`). `carlos
deploy` has no `--mail` flag yet (carlos main 9eec0236), so ship and
promote instead of deploying in one step.

## Working on it

`AGENTS.md` is the source of truth for the code. `make ci` is the gate;
`make browser` is gate 7 and `make mutate` proves gates 1, 4 and 8 can
fail. `make preview` serves the real app over synthetic pages.
