oficina / base Public

Plan: files in Ask, slice 1 (web)

Human

Prompt

Write the slice 1 implementation plan, task by task with tests first, with exact files and gates; Equipo ships first and Base checks the capability before showing the paperclip.

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

Task-by-task plan for slice 1: the relay, send, state and events, the thread, the composer, browser tests, copy review, and the order after Equipo.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev bc1e4de9e4cd05992cd609ed2c677c90037834bc parent cd785dc
1 file changed, +352 −0
  • docs/superpowers/plans/2026-11-26-ask-attachments-slice1.md +352 −0

CI passed — run details

CI log
=== build ===
CGO_ENABLED=0 go build ./...
=== vet ===
go vet ./...
=== fmt-check ===
=== staticcheck ===
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./...
=== govulncheck ===
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./...
No vulnerabilities found.
=== gitleaks ===
1:55PM INF Unknown SCM platform. Use --platform to include links in findings. host=amadan.net
1:55PM INF 1 commits scanned.
1:55PM INF scanned ~2523501 bytes (2.52 MB) in 237ms
1:55PM INF no leaks found
=== budget ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size
budget size: 22 directories within budget
=== script-test ===
scripts/prepare-apps_test.sh
ok   releases lookup failure stops before ship
ok   app owned elsewhere stops the script
ok   apps listing failure stops before create
ok   ambiguous release dir is refused
ok   explicit version resolves the ambiguity
ok   releases match is exact, not substring
ok   shipped version is only promoted, existing app not created
ok   fresh account creates, ships, promotes to edge, enables
ok   failing promote stops the script
ok   ship is retried while uploads are rate limited
all passed
hack/fonts_test.sh
fonts_test: ok
=== test ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -count=1 ./...

receipt: test step 6.783s against a 60s target (the gate's other steps are not in this figure)
receipt: 16 packages ran, 0 cached, 6 without tests, 0 failed
receipt: slow package 6.01s amadan.net/oficina/base/internal/webtest
receipt: slow package 610ms amadan.net/oficina/base/internal/issuer
receipt: slow package 576ms amadan.net/oficina/base/internal/operations
receipt: slow package 175ms amadan.net/oficina/base/internal/consumer
receipt: slow package 160ms amadan.net/oficina/base/internal/web
receipt: slow test 1.51s amadan.net/oficina/base/internal/webtest TestHomeDoesNotWaitOnAStalledSnapshot
receipt: slow test 1.08s amadan.net/oficina/base/internal/webtest TestAskZoneIsToldOnce
receipt: slow test 510ms amadan.net/oficina/base/internal/operations TestOperationsRefusals
receipt: slow test 380ms amadan.net/oficina/base/internal/issuer TestAuthorizeSignsForInstalledApp
receipt: slow test 220ms amadan.net/oficina/base/internal/webtest TestAskZoneAgainOnANewConnection
=== native ===
strings: copy review's strings.json is not here (git-ignored); its comparison skipped
strings: 119 in the catalog, 116 used
worktree-lib_test: ok
diff --git a/docs/superpowers/plans/2026-11-26-ask-attachments-slice1.md b/docs/superpowers/plans/2026-11-26-ask-attachments-slice1.md
new file mode 100644
index 0000000..f6c6bb7
--- /dev/null
+++ b/docs/superpowers/plans/2026-11-26-ask-attachments-slice1.md
@@ -0,0 +1,352 @@
+# Files in Ask, slice 1 (web): Implementation Plan
+
+> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
+
+**Goal:** On the web, the person attaches files to a message in Ask: with
+the paperclip, by pasting or by dropping. They see each file upload as a
+chip, and send. Their files show in the thread as thumbnails and pills, and
+the Assistant reads them.
+
+**Spec:** `docs/superpowers/specs/2026-11-26-ask-attachments-design.md`
+(rulings R1 to R8, decisions D1 to D4, sections 2.1 and 3). Equipo's half:
+`oficina/equipo` `docs/superpowers/specs/2026-11-26-assistant-attachments-design.md`
+and its plan of the same name as this one.
+
+**Branch:** `design/ask-attachments` holds the spec and this plan. Build on
+`feat/ask-attachments`, from `origin/main` (`0a6e8bc` when this was
+written).
+
+**Order between the repos:**
+
+- Equipo's slice 1 ships to production first.
+- This branch can be built and tested at any time against the fake
+ (`internal/equipo/equipotest`), which learns Equipo's new contract in
+ Task 1.
+- It merges and deploys only once production Equipo answers `attachments`
+ in the Assistant's snapshot (Task 11).
+- The paperclip shows only when that field is true (D3). An older Equipo
+ never sends the field, so Base offers nothing until it does.
+
+**Gates for every task:** a failing test first, observed failing for the
+right reason. Then:
+
+- `make test` (or the one package with `-run`, through the Make
+ toolchain, `GOTOOLCHAIN=go1.26.11`);
+- `make vet fmt-check staticcheck budget`;
+- the browser tasks also run `make browser` with `RASTRILLO_CHROME` set
+ (Chromium path: see memory "Base review gates"), at least
+ `-run 'TestAsk'`.
+
+`make ci` and the full `make browser` run before hand-over (Task 10).
+
+## Plan decisions
+
+- **P1. Base keeps no bytes (R1).**
+ - Uploads are read into memory up to 10 MiB plus 1 byte, because
+ Equipo's `ReadUpload` wants a known length. They go on with
+ `Content-Length`, and nothing is written to disk.
+ - At most 4 uploads run at once for the whole process (a semaphore).
+ The fifth waits up to 10 s, then gets `503` with `Retry-After: 2`.
+ - Downloads stream through `io.Copy` and are never buffered.
+- **P2. New client calls, not `call`.** `call` caps answers at 4 MiB and
+ times out after 20 s. `Upload` gets 60 s, and `OpenAttachment` returns
+ the `*http.Response` for the handler to stream. It is bounded by the
+ request's context and by a 60 s header timeout.
+- **P3. Base sets its own headers on downloads.** It keeps Equipo's
+ `Content-Type` and `Content-Disposition`, which are already sniffed and
+ inline only for images. It always adds:
+ - `X-Content-Type-Options: nosniff`;
+ - `Content-Security-Policy: default-src 'none'; img-src 'self'; style-src 'unsafe-inline'; sandbox`;
+ - `Cache-Control: private, max-age=3600`.
+- **P4. Thumbnails come from Base's origin,** at
+ `/ask/attachments/{id}/preview`, so the page CSP (`img-src 'self' data:`)
+ needs no change. A chip shows its thumbnail once the upload answers.
+ Until then it shows a file mark, never a `blob:` URL, which the CSP
+ would refuse.
+- **P5. The attach script is its own module,**
+ `internal/look/static/ask-attach.js`. It is imported by `ask.js`, so
+ `ask.js` (2,160 lines) only grows by the hooks. It follows Equipo's
+ `chat-attach.js`: XHR for upload progress, one upload per file at once,
+ and the server's word final.
+- **P6. The no-script page shows files but can't attach (R4).**
+ - `chat.html` draws thumbnails as links to the full image, and pills as
+ download links. The paperclip and chips exist only when the script
+ adds them.
+ - `POST /ask/messages` with `attachments` works without script too, but
+ nothing without script sends it.
+- **P7. Equipo IDs only.** A client never sees an Equipo URL. Message
+ JSON carries `attachments` (`id`, `kind`, `name`, `media_type`, `size`,
+ `width`, `height`), and each client builds `/ask/attachments/{id}`.
+ `/ask/attachments/{id}` checks that the ID looks like `at_[a-z0-9]{8,60}`
+ before calling Equipo.
+- **P8. Text may be empty with files.**
+ - `askSend` accepts an empty `text` when at least one `attachments` is
+ present.
+ - `ask.js`'s submit drops its `field.value.trim()` early return in that
+ case, and the textarea loses `required` once script runs. It stays
+ `required` without script.
+- **P9. The native apps keep working, with no attach UI (slice 2).** They
+ decode `attachments` and show a person bubble's files as one plain line
+ of names under the text, so a files-only message is never an empty
+ bubble.
+
+## File map
+
+| File | Change |
+|---|---|
+| `internal/equipo/chat.go` | `Attachment`; `Message.Attachments`; `Snapshot.Attachments`; `Send(…, files)`; `Upload`; `OpenAttachment` |
+| `internal/equipo/equipo_test.go` | the client's new calls |
+| `internal/equipo/equipotest/chat.go` | the fake: uploads, reads, send with files, the snapshot flag, `FilesReady(bool)` |
+| `internal/web/ask.go` | routes; `askView.Files`; `/ask/state` `attachments` |
+| `internal/web/ask_files.go` | new: `askUpload`, `askAttachment` |
+| `internal/web/ask_relay.go` | `askBearer` split (no form parse for raw bodies); `askSend` with files; `project()` keeps files; turn reasons |
+| `internal/web/templates/partials/chat.html` | the files row in person bubbles; the paperclip slot; data words for the script |
+| `internal/look/static/ask.js` | hooks: send with files, files-only submit, files in `addMessage` |
+| `internal/look/static/ask-attach.js` | new: paperclip, picker, paste, drop, chips, progress, refusals, viewer |
+| `internal/look/static/app.css` | chips, drop outline, files row, viewer sheet; light and dark |
+| `internal/webtest/ask_files_test.go` | new |
+| `internal/web/relay_internal_test.go` | `project()` keeps files |
+| `internal/browsertest/attach_test.go` | new |
+| `internal/browsertest/testdata/attach/` | `note.md`, `shot.png`, `big.bin` (made at run time, not committed), `photo.heic` header |
+| `docs/api/base-native-v1.md` | `/ask/state` and message `attachments`; the two new routes |
+| `internal/webtest/ask_native_contract_test.go` | pins the new fields |
+| `native/apple/Sources/BaseKit/API/Models.swift`, `Ask/Thread.swift` | decode `attachments`; the names line (P9) |
+| `docs/copy-pending.md` | Review 10 rows |
+
+## Task 1: the Equipo client and its fake learn files
+
+- [ ] **Test first** (`internal/equipo/equipo_test.go`, against
+ `equipotest`):
+ - `Upload` sends the bytes, `Content-Type`, an RFC 5987
+ `Content-Disposition`, the bearer and an `Idempotency-Key`, and
+ returns the `Attachment`.
+ - It maps `413 attachment_too_large`, `415 attachment_type`,
+ `415 attachment_heic`, `413 attachment_pixels` and
+ `409 attachment_limit` to an `*Error` with that `Code`.
+ - `Send` with two IDs posts `attachments` in order. With none it posts
+ no `attachments` key, so the body is byte-identical to today's.
+ - `OpenAttachment(…, preview)` returns the response unread, with the
+ status and headers. A 404 is `ErrNotFound`.
+ - A snapshot with `"attachments": true` decodes into
+ `Snapshot.Attachments`, and messages decode their `attachments`.
+- [ ] Implement in `chat.go`. Add a `do` helper beside `call` for raw
+ bodies and streamed answers. Leave `call` as it is.
+- [ ] Fake (`equipotest/chat.go`):
+ - `POST /api/v1/attachments`: per bearer, sniffs PNG and text, and
+ refuses over 10 MiB, `image/heic` and a sixth unsent file.
+ - `GET /api/v1/attachments/{id}[/preview]`: per bearer, 404 for another
+ person's file.
+ - `send` accepts `attachments`: they must be the bearer's and unsent,
+ there may be at most 5, and empty text is fine with files. It checks
+ the key replay against the files too. It refuses with
+ `409 runner_too_old` when `FilesReady(false)`.
+ - `snapshot` says `attachments` from `FilesReady`, false by default.
+ - `HoldNextUpload()` holds one upload, as `HoldNextSnapshot` holds a
+ snapshot.
+ - The message and events carry the files.
+- [ ] Gate: `make test`, `vet`, `fmt-check`, `staticcheck`.
+
+## Task 2: `POST /ask/attachments`
+
+- [ ] **Test first** (`internal/webtest/ask_files_test.go`):
+ - A member's upload reaches the fake with their bearer, name and type.
+ The answer is `201` with the attachment JSON and `Cache-Control:
+ no-store`.
+ - 10 MiB plus 1 byte is `413 {"code":"attachment_too_large"}`, and the
+ fake sees no call.
+ - Each Equipo refusal passes through as `code`, with Equipo's status.
+ - Each Ask state that isn't ready gives `409 {"state": …}`, as the other
+ writes do: not connected, reconnect, no runner.
+ - A cross-site `Origin` is refused by CSRF.
+ - Signed out, a JSON request is `401` and a page request a redirect.
+ - With the fake held, a fifth concurrent upload waits, then gets `503`
+ with `Retry-After`.
+ - A `401` from Equipo drops the link, as `askDone` does.
+- [ ] Implement `ask_files.go`. Split `askBearer` into the state check and
+ the form parse, so a raw body is never parsed as a form. Mount the route
+ in `askRoutes`.
+- [ ] Gate: `make test`.
+
+## Task 3: `GET /ask/attachments/{id}` and `/preview`
+
+- [ ] **Test first:**
+ - An image streams with Equipo's type, `inline`, and the P3 headers.
+ A text file is an `attachment` download.
+ - A 9 MiB file streams to the end. The test reads the body as it comes,
+ and Base never holds it all (checked with a fake that writes slowly).
+ - Another member's ID is `404`, and so is an ID not matching
+ `at_[a-z0-9]{8,60}`, with no Equipo call.
+ - Not connected is `404`, never a redirect inside an `<img>`.
+ - `HEAD` works.
+- [ ] Implement `askAttachment(preview bool)` in `ask_files.go`.
+- [ ] Gate: `make test`.
+
+## Task 4: sending with files
+
+- [ ] **Test first** (`ask_files_test.go`, and `TestAskFormsCarryKeys` and
+ `TestAskSendRelaysWithBearer` extended):
+ - Form `text` plus two `attachments` fields relay in order.
+ - `attachments` alone, with empty `text`, sends.
+ - Six are `422`, as are a malformed ID and an empty message with no
+ files.
+ - `409 runner_too_old` from Equipo gives the `oldrunner` state, as
+ today.
+ - A plain text send is unchanged (the fake sees no `attachments` key).
+- [ ] Implement in `askSend`.
+- [ ] Gate: `make test`.
+
+## Task 5: state, events and the capability
+
+- [ ] **Test first:**
+ - `relay_internal_test.go`: a `message` event's `attachments` survive
+ `project()`, with only P7's fields. An `equipo` URL in an extra field
+ never comes through.
+ - `webtest`: `/ask/state` carries messages' `attachments`, and
+ `"attachments": true` only when the fake says so.
+ `TestAskEventsRelay` carries a message with files.
+ - The native contract test pins the new fields and routes.
+- [ ] Implement in `chat.go` (types), `ask.go` (`askView.Files`, the state
+ JSON) and `ask_relay.go` (`project()`).
+- [ ] Write it into `docs/api/base-native-v1.md`.
+- [ ] Gate: `make test`.
+
+## Task 6: files in the thread, drawn by the server
+
+- [ ] **Test first** (`webtest`, scripts off):
+ - A person message with an image and a CSV draws a files row: an
+ `<a href="/ask/attachments/{id}">` around
+ `<img src="/ask/attachments/{id}/preview" alt="{name}" width height>`,
+ and a pill `<a href="/ask/attachments/{id}" download>` with the name
+ and the size in the member's locale ("1.2 MB", "820 KB").
+ - A files-only message draws no empty text paragraph.
+ - The page says no word "Equipo" (`TestAskNamesNoEquipo` still passes).
+ - The page CSP is unchanged.
+- [ ] Implement in `chat.html`, with a size helper in the template funcs,
+ and add the CSS in `app.css` (light and dark).
+- [ ] Gate: `make test`.
+
+## Task 7: the composer, with script
+
+- [ ] **Test first, browser** (`internal/browsertest/attach_test.go`, with
+ `askBase`, `openPanel` and `FilesReady(true)`):
+ - **The paperclip.** It shows in the panel and on the Ask page. With
+ `FilesReady(false)` it isn't there, and neither drop nor paste
+ attaches.
+ - **The picker.** Setting two files on the hidden input through CDP
+ (`DOM.setFileInputFiles`) makes two chips, each reaching "done". The
+ image chip then shows its thumbnail from `/ask/attachments/…/preview`.
+ - **Paste.** A `ClipboardEvent` whose `DataTransfer` holds a PNG `File`
+ attaches it, and the field's text is unchanged. A paste of HTML only
+ still goes through `pasteMarkdown`: the paste tests pass unchanged.
+ - **Drop.** A `DragEvent` sequence (`dragenter`, `dragover`, `drop`)
+ with a `File` attaches it. The drop outline shows during the drag and
+ goes after.
+ - **Progress and Remove.** With the fake holding the upload
+ (`HoldNextUpload`), the chip shows the uploading word and a progress
+ ring with `aria-valuenow`. Remove takes the chip away, and the upload
+ is never sent with the message.
+ - **Refusals.**
+ - A file over 10 MiB is refused on the chip with no request.
+ - A sixth file is refused on the chip.
+ - A `.heic` is refused on the chip with no request.
+ - Equipo's `415 attachment_type` shows its words on the chip.
+ - **Send.**
+ - With chips still uploading, Send waits, then sends once with the
+ IDs in chip order.
+ - Files with no text send.
+ - The chips clear on success. On a failure they stay, with the
+ existing "That didn't send. Try again."
+ - **The thread.** The sent message shows thumbnails and pills from the
+ `message` event, as the server draws them. Clicking a thumbnail opens
+ the viewer sheet: the full image, Close, and Escape to close.
+ - **The CSP.** The console shows no CSP violation through the whole test
+ (`harness` console capture).
+ - **Mobile width.** The chips scroll sideways and the paperclip keeps a
+ 44 px target. Take a screenshot to `BASE_BROWSER_ARTIFACTS`.
+- [ ] Implement `ask-attach.js` and the `ask.js` hooks:
+ - `post()` appends `attachments`, so the key's signature includes them.
+ - The files-only submit (P8).
+ - `addMessage` draws the files row, sharing the server's markup.
+ - The words come from `data-*` attributes on the composer, written by
+ `chat.html`, so the strings live in the template, as the review
+ expects.
+- [ ] Gate: `make test` and `make browser` (`-run 'TestAsk'`).
+
+## Task 8: turn failures in words
+
+- [ ] **Test first** (browser and webtest): a failed turn with reason
+ `attachment_unavailable` shows its line in the status. So does
+ `runner_storage_full`. Any other reason keeps "That didn't get an
+ answer. Try again."
+- [ ] Implement in `ask.js` `setTurn` and in the no-script status line in
+ `ask.go`.
+- [ ] Gate: `make test` and `make browser` (`-run 'TestAsk'`).
+
+## Task 9: the native apps show files as a line (P9)
+
+- [ ] **Test first** (BaseKit tests):
+ - A message JSON with `attachments` decodes.
+ - A person bubble with files and text shows the names line under the
+ text, and a files-only one shows only the names.
+ - An unknown `kind` still decodes.
+- [ ] Implement in `Models.swift` and `Thread.swift`. Add the one string,
+ the names line's accessibility label, to `Localizable.xcstrings`.
+- [ ] Gate: `make native-check`.
+
+## Task 10: copy review, gates, hand-over
+
+- [ ] Add Review 10's rows to `docs/copy-pending.md` and run the
+ copy-review skill (`paulca/agent-skills` `copy-review`,
+ `serve.sh`) for Luna's review. Check `result.json` before running it
+ again. Draft strings follow. They reuse Equipo's approved words where
+ they fit, and never name Equipo:
+
+ | Where | Text |
+ |---|---|
+ | Paperclip, label and tooltip | Attach files |
+ | Drop outline | Drop files to attach them |
+ | Chip, uploading | Uploading… |
+ | Chip, Remove (label) | Remove {name} |
+ | Chip, failed | Couldn't upload. Try again. |
+ | Chip, sixth file | At most 5 files in one message. |
+ | Refusal, too large | That file is over 10 MB. |
+ | Refusal, type | Ask takes images (PNG, JPEG, WebP, GIF) and text, Markdown, CSV, JSON and PDF files. |
+ | Refusal, HEIC | HEIC photos can't be read yet. Share it as a JPEG and try again. |
+ | Refusal, pixels | That image is too large: at most 12,000 pixels on a side and 40 megapixels. |
+ | Refusal, too many waiting | Too many files are waiting to send. Send or remove some first. |
+ | Refusal, busy (503) | Too many uploads at once. Try again in a moment. |
+ | Thread, files row (label) | Attached files |
+ | Thread, pill (label) | {name}, {size}. Download |
+ | Viewer, Close | Close (approved) |
+ | Turn failed, file missing | A file didn't arrive whole. Attach it again. |
+ | Turn failed, no room | There's no room left for these files. Try fewer or smaller ones. |
+ | Native, names line (label) | Attached: {names} |
+
+- [ ] Run `make ci`, and the full `make browser` with
+ `BASE_BROWSER_ARTIFACTS`. Put the outputs in the report. Known failures
+ on main are listed in memory "Base review gates".
+- [ ] Get an independent review (Fable, else Codex Astra, with a
+ self-contained prompt). Fix what it finds and push.
+
+## Task 11 (controller): merge and deploy, after Equipo
+
+- [ ] Wait for Equipo's Task 13: production Equipo is live, and Paul's
+ snapshot says `attachments: true`.
+- [ ] Get Paul's approval of Review 10, then merge `feat/ask-attachments`
+ to `main` on the hub.
+- [ ] Deploy Base (the usual `make release` and carlos deploy). Then
+ `curl /api/version` and restart if needed (memory "Calls gates report
+ false green").
+- [ ] Check it live, as Paul:
+ - Attach a screenshot and a `.md` and ask about both. Ask about the
+ `.md` again two messages later.
+ - Paste an image.
+ - Open the thumbnail.
+ - Check that the console shows no CSP errors.
+- [ ] Tell Paul.
+
+## Not in this plan
+
+- The native attach UI (slice 2), and reading PDFs (slice 3).
+- Files for jobs (R6), removing a file (R2), sealing the bytes (R8), and
+ files into Oficina apps (R7).