| 1 | # Files in Ask, slice 1 (web): Implementation Plan |
| 2 | |
| 3 | > **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. |
| 4 | |
| 5 | **Goal:** On the web, the person attaches files to a message in Ask, with |
| 6 | the paperclip, by pasting or by dropping. They watch each file upload as a |
| 7 | chip, and send. Their files show in the thread as thumbnails and pills, and |
| 8 | the Assistant reads them. |
| 9 | |
| 10 | **Spec:** `docs/superpowers/specs/2026-11-26-ask-attachments-design.md`: |
| 11 | rulings R1 to R8, decisions D1 to D8, and sections 2.1 and 3. Equipo's |
| 12 | half is `oficina/equipo` |
| 13 | `docs/superpowers/specs/2026-11-26-assistant-attachments-design.md`, with a |
| 14 | plan of the same name as this one. |
| 15 | |
| 16 | **Review:** this revision answers Fable's plan review of 2026-11-26: B1 to |
| 17 | B6, and the cheap nits. Fable's re-review approved it with two edits, B7 |
| 18 | (P11) and B8 (P12), folded in here with the Base nits it took (P1, P3, |
| 19 | P10, P11). |
| 20 | |
| 21 | **Branch:** `design/ask-attachments` holds the spec and this plan, and the |
| 22 | build goes on the same branch (the controller's call, 2026-11-26), from |
| 23 | `origin/main` `0a6e8bc`. |
| 24 | |
| 25 | **Order between the repos:** |
| 26 | |
| 27 | - **Equipo first.** Equipo's slice 1 ships to production first. |
| 28 | - **Building here.** This branch can be built and tested at any time |
| 29 | against the fake (`internal/equipo/equipotest`), which learns Equipo's |
| 30 | new contract in Task 1. |
| 31 | - **Merging here.** It merges and deploys only once production Equipo |
| 32 | answers `can_attach` in the Assistant's snapshot (Task 12). |
| 33 | - **The paperclip waits too.** It shows only when `can_attach` is true |
| 34 | (D3). An older Equipo never sends the field, so Base offers nothing until |
| 35 | it does. |
| 36 | |
| 37 | **Gates for every task:** |
| 38 | |
| 39 | - Write a failing test first, and watch it fail for the right reason. |
| 40 | - Then run `make test`, or the one package with `-run` through the Make |
| 41 | toolchain (`GOTOOLCHAIN=go1.26.11`). |
| 42 | - Then run `make vet fmt-check staticcheck budget`. |
| 43 | - The browser tasks also run `make browser` with `RASTRILLO_CHROME` set, |
| 44 | at least `-run 'TestAsk'`. See memory "Base review gates" for the |
| 45 | Chromium path. |
| 46 | - `make ci` and the full `make browser` run before hand-over (Task 11). |
| 47 | |
| 48 | ## Plan decisions |
| 49 | |
| 50 | - **P1. Base keeps no bytes (R1), and its bounds hold** (Fable B3). |
| 51 | - **The order.** `askUpload` first checks the declared `Content-Length` |
| 52 | (over 10 MiB is `413` at once). Then it takes a slot from a |
| 53 | process-wide semaphore of 4. Only then does it read the body. |
| 54 | - **The read.** It reads under `http.ResponseController.SetReadDeadline` |
| 55 | of 60 s, into memory, to at most 10 MiB plus 1 byte. A stalled body |
| 56 | fails at the deadline and gives its slot back. Peak memory is about |
| 57 | 4 × 10 MiB. |
| 58 | - **No deadline, no read** (Fable nit). If `SetReadDeadline` fails (a |
| 59 | middleware that wraps the writer without `Unwrap`), the upload is |
| 60 | logged and refused `503` before the body is read, never read without |
| 61 | a deadline. The webtest goes through the whole router, so it would |
| 62 | catch such a middleware. |
| 63 | - **A client gone mid-flight** (Fable nit). The relay to Equipo runs on |
| 64 | a context that outlives the request (`context.WithoutCancel`, 60 s), |
| 65 | so an upload Equipo takes is never half-known. If the page has gone |
| 66 | (Remove aborted the XHR) by the time Equipo answers, Base deletes the |
| 67 | upload at once. |
| 68 | - **Waiting.** A request that waits more than 10 s for a slot is `503` |
| 69 | with `Retry-After: 2`. |
| 70 | - **The page.** `ask-attach.js` uploads two files at a time, and retries |
| 71 | a `503` after `Retry-After` by itself, up to 5 times. |
| 72 | - **Sending on.** The body goes to Equipo with `Content-Length`, because |
| 73 | Equipo's `ReadUpload` wants a known length. Nothing is written to disk. |
| 74 | - **Downloads** stream through `io.Copy`, and are never buffered. |
| 75 | - **P2. New client calls, not `call`.** `call` caps answers at 4 MiB and |
| 76 | times out after 20 s. |
| 77 | - `Upload` gets 60 s, and sends **no** `Idempotency-Key`: Equipo's upload |
| 78 | takes none (Fable nit). |
| 79 | - `OpenAttachment` returns the `*http.Response` for the handler to |
| 80 | stream. It is bounded by the request's context and a 60 s header |
| 81 | timeout. |
| 82 | - `DeleteAttachment` treats `204` and `404` as done. |
| 83 | - **P3. Base decides the download headers (D7, Fable B4).** |
| 84 | - **Inline.** Only `image/png`, `image/jpeg`, `image/webp` and |
| 85 | `image/gif`. |
| 86 | - **Download.** The other five types (PDF, text, Markdown, CSV, JSON). |
| 87 | Text types get `; charset=utf-8`. |
| 88 | - **Anything else** is `application/octet-stream`, as a download. |
| 89 | - **The name.** Base parses the file name out of Equipo's |
| 90 | `Content-Disposition` (`mime.ParseMediaType`, `filename`), the only |
| 91 | place a read gives it. Base then builds its own header from that name |
| 92 | with `mime.FormatMediaType` and its own disposition. Equipo's header |
| 93 | is never passed on. |
| 94 | - **Always.** |
| 95 | - `X-Content-Type-Options: nosniff`. |
| 96 | - `Content-Security-Policy: default-src 'none'; img-src 'self'; style-src 'unsafe-inline'; sandbox`. |
| 97 | - **Caching.** Previews are `Cache-Control: private, max-age=3600` with |
| 98 | `Vary: Cookie`. Originals are `Cache-Control: no-store`. |
| 99 | - **`/preview`** answers only for the four image types; anything else is |
| 100 | `404`. |
| 101 | - **Failures.** |
| 102 | - Equipo's error bodies never come through. |
| 103 | - A `401` drops the link, as `askDone` does, and answers `404`. |
| 104 | - A `5xx` or a timeout answers `502` with an empty body. |
| 105 | - **P4. Thumbnails come from Base's origin,** at |
| 106 | `/ask/attachments/{id}/preview`, so the page CSP (`img-src 'self' data:`) |
| 107 | is unchanged. A chip shows its thumbnail once the upload answers. Until |
| 108 | then it shows a file mark, never a `blob:` URL, which the CSP would |
| 109 | refuse. |
| 110 | - **P5. The attach script is its own module,** |
| 111 | `internal/look/static/ask-attach.js`, imported by `ask.js`. |
| 112 | - `ask.js` (2,160 lines) grows only by the hooks. |
| 113 | - It follows Equipo's `chat-attach.js`: XHR for progress, and the |
| 114 | server's word is final. |
| 115 | - **P6. The no-script page shows files but can't attach them (R4).** |
| 116 | - `chat.html` draws thumbnails as links to the full image, and pills as |
| 117 | download links. |
| 118 | - The paperclip and the chips exist only when the script adds them. |
| 119 | - **P7. Equipo IDs only.** A client never sees an Equipo URL. |
| 120 | - Message JSON carries `attachments` (`id`, `kind`, `name`, |
| 121 | `media_type`, `size`, `width`, `height`), and each client builds |
| 122 | `/ask/attachments/{id}`. |
| 123 | - IDs must match `at_[a-z0-9]{8,60}` before Equipo is called. |
| 124 | - **P8. Text may be empty with files.** |
| 125 | - `askSend` accepts an empty `text` when at least one `attachments` is |
| 126 | present. |
| 127 | - `ask.js`'s submit skips its `field.value.trim()` early return in that |
| 128 | case. |
| 129 | - The textarea loses `required` once script runs. It keeps `required` |
| 130 | without script. |
| 131 | - **P9. The installed native apps get a names line before the web ships.** |
| 132 | - They decode `attachments` and show a person bubble's files as one |
| 133 | plain line of names under the text, so a files-only message is never |
| 134 | an empty bubble. |
| 135 | - That build is released before or with the web (Task 12; Fable nit). |
| 136 | - **P10. Refused files never take Ask down (D5, Fable B1 and B2).** |
| 137 | - **Runner can't take files.** A send with files refused by Equipo's |
| 138 | `409 attachments_unavailable`, or `409 runner_too_old`, answers |
| 139 | `409 {"state":"ready","files":"unavailable"}`. |
| 140 | - The page keeps Ask ready, sets `can_attach` false (the paperclip |
| 141 | goes), keeps the chips, and marks them with the "can't be read right |
| 142 | now" line. |
| 143 | - The words stay in the field. Sending again without the chips works. |
| 144 | - **Stale upload.** Equipo's `422` on a send with files (an upload |
| 145 | expired, or already sent) answers `422 {"state":"ready","files":"stale"}`. |
| 146 | The page marks every chip "attach it again", and Remove clears them. |
| 147 | - **Only an attachment's `422` is stale** (Fable nit). Base checks the |
| 148 | text as Equipo does before relaying (valid UTF-8, no NUL, at most |
| 149 | 16 KiB after trimming) and the key's reserved prefixes (`reply:`, |
| 150 | `card:`, `handoff:`). Bad text is Base's own `422 {"state":"ready"}`, |
| 151 | with no `files`. So an Equipo `422` on a send with files can only be |
| 152 | the files. |
| 153 | - **Words alone.** A send with no files keeps today's mapping. |
| 154 | - **P11. Remove frees the upload (D6, Fable B6).** |
| 155 | - Remove calls `DELETE /ask/attachments/{id}` once the upload has an ID. |
| 156 | A Remove during the upload aborts the XHR, then deletes if an ID came |
| 157 | back. |
| 158 | - On `pagehide`, `navigator.sendBeacon` posts the unsent IDs to |
| 159 | `POST /ask/attachments/discard`. Base deletes each as best it can, and |
| 160 | always answers `204`. |
| 161 | - **Not a send in flight** (Fable B7). The beacon leaves out every ID |
| 162 | that is part of a send still on its way: the send links them, and a |
| 163 | delete racing it would lose the message. If that send fails after |
| 164 | all, the 24-hour drop takes them. |
| 165 | - **Back and forward** (Fable B7). A page kept in the back/forward cache |
| 166 | comes back with chips whose uploads the beacon deleted. On `pageshow` |
| 167 | with `persisted`, the page clears its chips. |
| 168 | - Chips don't survive a reload. |
| 169 | - **The words in the field** (Fable nit). Leaving the page drops the |
| 170 | chips and the words alike: a new page draws an empty composer, as |
| 171 | today (the field is `autocomplete="off"`, so the browser doesn't |
| 172 | restore it). The docked panel and the Ask page behave the same. The one |
| 173 | exception is the back/forward cache, which brings the whole page back: |
| 174 | the words are still there, and only the chips go, since their uploads |
| 175 | are gone. |
| 176 | - **P12. Paste (D8, Fable B5 and B8).** On `paste`, with files on the |
| 177 | clipboard: |
| 178 | - **Words win** only when there are real words: `text/html` whose text |
| 179 | (parsed inertly, as `pasteMarkdown` does) has non-space characters, |
| 180 | or `text/plain` that is more than the files' own names (each line |
| 181 | trimmed, every line that is one of the files' names dropped, and |
| 182 | something left). Then the existing text path runs (`pasteMarkdown` or |
| 183 | plain), and nothing is attached. Word, Excel, Pages and Numbers land |
| 184 | here. |
| 185 | - **Otherwise the files are attached,** and the default is prevented, so |
| 186 | no name is typed into the field. |
| 187 | - **What B8 turned out to be** (checked 2026-11-26 in Chrome for Testing |
| 188 | 159 on macOS, with a real paste from the system pasteboard holding a |
| 189 | file as Finder's Copy writes it: its file URL and its name as plain |
| 190 | text). Chrome gives the page `types: ["Files"]` and no `text/plain`, |
| 191 | so "text wins" would not have stopped the file. But Chrome's own |
| 192 | default then types the file's name into the field, which this rule |
| 193 | prevents. A clipboard with text, HTML and an image (as Office writes) |
| 194 | gives all three, and the words win. Safari, and Finder's own Copy |
| 195 | (its automation was refused here), are still to check by hand in |
| 196 | Task 12; the narrowed rule covers a browser that does put the name in |
| 197 | `text/plain`. |
| 198 | - **P13. The flag is `can_attach`** (Fable nit), in Equipo's snapshot and |
| 199 | in `/ask/state`. Each message's list is `attachments`. |
| 200 | |
| 201 | ## File map |
| 202 | |
| 203 | | File | Change | |
| 204 | |---|---| |
| 205 | | `internal/equipo/chat.go` | `Attachment`; `Message.Attachments`; `Snapshot.CanAttach`; `Send(…, files)`; `Upload`; `OpenAttachment`; `DeleteAttachment`; `ErrAttachmentsUnavailable` | |
| 206 | | `internal/equipo/equipo_test.go` | the client's new calls | |
| 207 | | `internal/equipo/equipotest/chat.go` | the fake: upload, read, delete, send with files, `can_attach`, `FilesReady(bool)`, `HoldNextUpload`, `ExpireUploads`, `ServeHostile(type, disposition)` | |
| 208 | | `internal/web/ask.go` | routes; `askView.CanAttach`; `/ask/state` `can_attach`; status words for turn reasons | |
| 209 | | `internal/web/ask_files.go` | new: `askUpload`, `askAttachment`, `askDiscard`, `askDeleteAttachment`; the slot semaphore | |
| 210 | | `internal/web/ask_relay.go` | split `askBearer` so a raw body is never parsed as a form; `askSend` with files (P10); `project()` keeps files | |
| 211 | | `internal/web/templates/partials/chat.html` | the files row in person bubbles; the composer's `data-*` words | |
| 212 | | `internal/look/static/ask.js` | hooks: send with files, the files-only submit, files in `addMessage`, P10 answers, the paste hand-off (P12) | |
| 213 | | `internal/look/static/ask-attach.js` | new: paperclip, picker, paste, drop, chips, progress, queue of two, retry, Remove, beacon, viewer, announcements | |
| 214 | | `internal/look/static/app.css` | chips, drop outline, files row, viewer sheet; light and dark | |
| 215 | | `internal/webtest/ask_files_test.go` | new | |
| 216 | | `internal/web/relay_internal_test.go` | `project()` keeps files | |
| 217 | | `internal/browsertest/attach_test.go` | new | |
| 218 | | `internal/browsertest/testdata/attach/` | `note.md` and `shot.png`; big and HEIC files made at run time | |
| 219 | | `docs/api/base-native-v1.md` | `can_attach`, message `attachments`, the routes | |
| 220 | | `internal/webtest/ask_native_contract_test.go` | pins the new fields | |
| 221 | | `native/apple/Sources/BaseKit/API/Models.swift`, `Ask/Thread.swift` | decode `attachments`; the names line (P9) | |
| 222 | | `docs/copy-pending.md` | the next free review number (13 at the time of writing): the strings | |
| 223 | |
| 224 | ## Task 1: the Equipo client and its fake learn files |
| 225 | |
| 226 | - [ ] **Test first** (`internal/equipo/equipo_test.go`, against |
| 227 | `equipotest`): |
| 228 | - **`Upload`** sends the bytes, `Content-Type`, an RFC 5987 |
| 229 | `Content-Disposition` and the bearer, and no `Idempotency-Key`. It |
| 230 | returns the `Attachment`. |
| 231 | - **Refusals.** It maps `413 attachment_too_large`, |
| 232 | `415 attachment_type`, `415 attachment_heic`, `413 attachment_pixels` |
| 233 | and `409 attachment_limit` to an `*Error` with that `Code`. |
| 234 | - **`Send`** with two IDs posts `attachments` in order. With none, the |
| 235 | body is byte-identical to today's. A `409 attachments_unavailable` is |
| 236 | `ErrAttachmentsUnavailable`. |
| 237 | - **`OpenAttachment(…, preview)`** returns the response unread. A `404` |
| 238 | is `ErrNotFound`. |
| 239 | - **`DeleteAttachment`.** `204` and `404` are nil, and `409` is an |
| 240 | `*Error`. |
| 241 | - **Decoding.** `"can_attach": true` decodes into `Snapshot.CanAttach`, |
| 242 | and messages decode their `attachments`. |
| 243 | - [ ] **Implement** in `chat.go`, with a `do` helper beside `call` for raw |
| 244 | bodies and streamed answers. `call` is unchanged. |
| 245 | - [ ] **The fake** (`equipotest/chat.go`): |
| 246 | - **`POST /api/v1/attachments`** works per bearer. It sniffs PNG and |
| 247 | text, and refuses over 10 MiB, `image/heic`, and the 21st unsent file. |
| 248 | - **`GET /api/v1/attachments/{id}[/preview]`** works per bearer: another |
| 249 | person's file is `404`. `ServeHostile` makes it answer a set type and |
| 250 | disposition (`text/html` inline, `image/svg+xml`). |
| 251 | - **`DELETE /api/v1/attachments/{id}`.** Your own unsent upload is |
| 252 | `204`; a sent one is `409 attachment_sent`; an unknown one is `404`. |
| 253 | - **Send** accepts `attachments`: yours and unsent, at most 5, with empty |
| 254 | text allowed when there are files. A replayed key is checked against |
| 255 | the files too. |
| 256 | - `FilesReady(false)` refuses files with |
| 257 | `409 attachments_unavailable`. |
| 258 | - `ExpireUploads()` makes the next send with files `422`. |
| 259 | - **The snapshot** says `can_attach` from `FilesReady`, false by default. |
| 260 | - **Messages and events** carry the files. |
| 261 | - **`HoldNextUpload()`** holds one upload, as `HoldNextSnapshot` does. |
| 262 | - [ ] **Gate:** `make test vet fmt-check staticcheck`. |
| 263 | |
| 264 | ## Task 2: `POST /ask/attachments` (P1) |
| 265 | |
| 266 | - [ ] **Test first** (`internal/webtest/ask_files_test.go`): |
| 267 | - **A member's upload** reaches the fake with their bearer, name and |
| 268 | type. The answer is `201` with the JSON and `Cache-Control: no-store`. |
| 269 | - **Too big.** A declared length over 10 MiB is `413` before the body is |
| 270 | read. So is a body over 10 MiB sent with no length. The fake sees no |
| 271 | call in either case. |
| 272 | - **Equipo's refusals** come back as `code`, with Equipo's status. |
| 273 | - **Not ready.** Each Ask state that isn't ready is `409 {"state": …}`, |
| 274 | as for the other writes. |
| 275 | - **Other refusals.** |
| 276 | - A cross-site `Origin` is refused by CSRF. |
| 277 | - Signed out, JSON gets `401`. |
| 278 | - A `401` from Equipo drops the link. |
| 279 | - **A stalled body** (Fable B3): send headers and half a body, then |
| 280 | stop. Within the read deadline (set short in the test), the request |
| 281 | fails and its slot is free. Then four more uploads all succeed. The |
| 282 | test goes through the whole router, so a middleware that hides the |
| 283 | deadline fails it. |
| 284 | - **A client gone mid-flight** (nit): with the upload held in the fake, |
| 285 | the client gives up; once the fake answers, Base deletes the upload. |
| 286 | - **Busy.** With 4 uploads held in the fake, a fifth waits, then gets |
| 287 | `503` and `Retry-After`. |
| 288 | - **The slot comes first.** A test hook records the slot count when the |
| 289 | body read starts. It is never above 4 with 8 clients sending at once. |
| 290 | - [ ] **Implement:** |
| 291 | - write `ask_files.go`; |
| 292 | - split `askBearer` into the state check and the form parse; |
| 293 | - mount the route in `askRoutes`. |
| 294 | - [ ] **Gate:** `make test`. |
| 295 | |
| 296 | ## Task 3: `GET /ask/attachments/{id}` and `/preview` (P3) |
| 297 | |
| 298 | - [ ] **Test first:** |
| 299 | - **Inline images.** A PNG streams `inline` with P3's headers. A preview |
| 300 | has `max-age=3600` and `Vary: Cookie`, and an original has `no-store`. |
| 301 | - **Downloads.** A CSV is an `attachment`, with `text/csv; |
| 302 | charset=utf-8`. |
| 303 | - **Hostile upstream** (Fable B4): |
| 304 | - Equipo answering `text/html` with `inline` is served as a |
| 305 | download; |
| 306 | - `image/svg+xml` is served as an `application/octet-stream` |
| 307 | download; |
| 308 | - `/preview` for either is `404`. |
| 309 | - **Streaming.** A 9 MiB file streams to the end from a fake that writes |
| 310 | slowly, and the test reads as it comes. |
| 311 | - **`404`, with no Equipo call:** another member's ID, and an ID that |
| 312 | doesn't match `at_[a-z0-9]{8,60}`. |
| 313 | - **`404`, never a redirect:** when Ask isn't connected. |
| 314 | - **Upstream failures:** |
| 315 | - a `401` drops the link and answers `404`; |
| 316 | - a `500`, or a timeout, answers `502` with an empty body; |
| 317 | - Equipo's error body never comes through. |
| 318 | - **`HEAD`** works. |
| 319 | - [ ] **Implement:** `askAttachment(preview bool)` in `ask_files.go`. |
| 320 | - [ ] **Gate:** `make test`. |
| 321 | |
| 322 | ## Task 4: Remove and discard (P11, Fable B6) |
| 323 | |
| 324 | - [ ] **Test first:** |
| 325 | - **Remove.** `DELETE /ask/attachments/{id}` relays with the bearer and |
| 326 | answers `204`. Equipo's `404` is `204` too. Equipo's |
| 327 | `409 attachment_sent` is `409`. |
| 328 | - **The slot is free.** After 20 uploads and one Remove, a 21st upload |
| 329 | passes. |
| 330 | - **Discard.** `POST /ask/attachments/discard` takes up to 5 `id` |
| 331 | fields, deletes each, and answers `204` even when some fail. A |
| 332 | malformed ID is skipped. |
| 333 | - **CSRF** refuses a cross-site discard. A same-origin beacon (with |
| 334 | `Sec-Fetch-Site: same-origin`) passes. |
| 335 | - [ ] **Implement:** `askDeleteAttachment` and `askDiscard`. |
| 336 | - [ ] **Gate:** `make test`. |
| 337 | |
| 338 | ## Task 5: sending with files (P8, P10, Fable B1 and B2) |
| 339 | |
| 340 | - [ ] **Test first** (`ask_files_test.go`, and `TestAskFormsCarryKeys` and |
| 341 | `TestAskSendRelaysWithBearer` extended): |
| 342 | - **What sends.** `text` and two `attachments` relay in order. |
| 343 | `attachments` with empty `text` sends. |
| 344 | - **Base's own `422`s:** six files, a malformed ID, an empty message |
| 345 | with no files, and text with a NUL or bad UTF-8 beside files (no |
| 346 | `files` in the answer, and no call to Equipo). |
| 347 | - **`FilesReady(false)`.** A send with files is |
| 348 | `409 {"state":"ready","files":"unavailable"}`. Nothing in the link |
| 349 | changes, and the page's state stays `ready`. A words-only send right |
| 350 | after it is `201`. |
| 351 | - **`ExpireUploads()`.** A send with files is |
| 352 | `422 {"state":"ready","files":"stale"}`. |
| 353 | - **Words only, refused.** Equipo's `409 runner_too_old` is still the |
| 354 | `oldrunner` state, as today. |
| 355 | - **Plain text** is unchanged: the fake sees no `attachments` key. |
| 356 | - [ ] **Implement** in `askSend`. When files were sent, map |
| 357 | `ErrAttachmentsUnavailable`, `ErrRunnerTooOld` and Equipo's `422` |
| 358 | before `askDone`. |
| 359 | - [ ] **Gate:** `make test`. |
| 360 | |
| 361 | ## Task 6: state, events and `can_attach` |
| 362 | |
| 363 | - [ ] **Test first:** |
| 364 | - **`relay_internal_test.go`.** A `message` event's `attachments` |
| 365 | survive `project()`, with only P7's fields. An Equipo URL in an extra |
| 366 | field never comes through. |
| 367 | - **`webtest`.** `/ask/state` carries messages' `attachments`, and |
| 368 | `"can_attach": true` only when the fake says so. |
| 369 | `TestAskEventsRelay` carries a message with files. |
| 370 | - **The native contract test** pins the new fields and routes. |
| 371 | - [ ] **Implement** in `chat.go` (the types), `ask.go` (`askView.CanAttach` |
| 372 | and the state JSON) and `ask_relay.go` (`project()`). |
| 373 | - [ ] **Document** it in `docs/api/base-native-v1.md`. |
| 374 | - [ ] **Gate:** `make test`. |
| 375 | |
| 376 | ## Task 7: files in the thread, drawn by the server |
| 377 | |
| 378 | - [ ] **Test first** (`webtest`, scripts off). A person message with an |
| 379 | image and a CSV draws a files row: |
| 380 | - **The image.** An `<a href="/ask/attachments/{id}">` around |
| 381 | `<img src="/ask/attachments/{id}/preview" alt="{name}" width height>`. |
| 382 | - **The CSV.** A pill `<a href="/ask/attachments/{id}" download>` with |
| 383 | the name and the size in the member's locale ("1.2 MB", "820 KB"). |
| 384 | - **Files only.** A files-only message draws no empty text paragraph. |
| 385 | - **No Equipo.** `TestAskNamesNoEquipo` still passes. |
| 386 | - **The CSP** is unchanged. |
| 387 | - [ ] **Implement** in `chat.html`, with a size helper in the template funcs |
| 388 | (rastrillo locales), and the CSS in `app.css` (light and dark). |
| 389 | - [ ] **Gate:** `make test`. |
| 390 | |
| 391 | ## Task 8: the composer, with script |
| 392 | |
| 393 | - [ ] **Test first, browser** (`internal/browsertest/attach_test.go`, with |
| 394 | `askBase`, `openPanel` and `FilesReady(true)`): |
| 395 | - **The paperclip.** It shows in the panel and on the Ask page. With |
| 396 | `FilesReady(false)` it doesn't, and drop and paste attach nothing. |
| 397 | - **The picker.** Setting two files on the hidden input through CDP |
| 398 | (`DOM.setFileInputFiles`) makes two chips that reach "done". The image |
| 399 | chip then shows its thumbnail from `/ask/attachments/…/preview`. |
| 400 | - **A PDF.** Its chip shows "Ask can't read PDFs yet" (D4), and it still |
| 401 | sends. |
| 402 | - **Paste** (P12, Fable B5 and B8): |
| 403 | - a `DataTransfer` holding only a PNG `File` attaches it, and the field |
| 404 | is unchanged; |
| 405 | - one holding a PNG **and** `text/html` with a table pastes the table |
| 406 | as Markdown and attaches nothing; |
| 407 | - one holding a PNG and `text/plain` pastes the text and attaches |
| 408 | nothing; |
| 409 | - one holding a `.md` `File` and its own name as `text/plain` (a file |
| 410 | copied in the Finder, as a browser may hand it over) attaches the |
| 411 | file and types nothing; |
| 412 | - one holding a PNG and `text/html` with only `<img>` (Copy Image in |
| 413 | a browser) attaches it; |
| 414 | - the existing paste tests pass unchanged. |
| 415 | - **Drop.** `dragenter`, `dragover` and `drop` with a `File` attach it. |
| 416 | The outline shows during the drag and goes after. |
| 417 | - **Progress and Remove** (P11): |
| 418 | - with `HoldNextUpload`, the chip shows the uploading word and a |
| 419 | progress ring with `aria-valuenow`; |
| 420 | - Remove during the upload aborts it; |
| 421 | - Remove after it sends `DELETE` (seen in the fake); |
| 422 | - a removed file is never sent. |
| 423 | - **The queue** (Fable B3). Five files from one page reach the fake at |
| 424 | most two at a time, and all five finish. A fake `503` with |
| 425 | `Retry-After: 1` on the third is retried by itself and succeeds. |
| 426 | - **Refusals:** |
| 427 | - over 10 MiB, a sixth file, and a `.heic` are refused on the chip with |
| 428 | no request; |
| 429 | - `415 attachment_type` shows its words on the chip. |
| 430 | - **Send:** |
| 431 | - with chips uploading, Send waits, then sends once with the IDs in |
| 432 | chip order; |
| 433 | - files with no text send; |
| 434 | - the chips clear on success; |
| 435 | - a network failure keeps them, with "That didn't send. Try again." |
| 436 | - **Send refused** (P10, Fable B1 and B2): |
| 437 | - with `FilesReady` turned false after the paperclip showed, the send |
| 438 | gives the "can't be read right now" line on the chips; the paperclip |
| 439 | goes; Ask is not in its "needs an update" state; and Send after |
| 440 | Remove sends the words; |
| 441 | - with `ExpireUploads()`, the chips say "attach it again". |
| 442 | - **Beacon.** On `pagehide` with two unsent chips, the fake sees both |
| 443 | deleted. |
| 444 | - **A send in flight** (B7): with the send held in the fake, `pagehide` |
| 445 | deletes nothing, and the message lands with its files. |
| 446 | - **Back/forward** (B7): a `pageshow` with `persisted` clears the |
| 447 | chips, and the words stay. |
| 448 | - **The thread.** The sent message shows thumbnails and pills from the |
| 449 | `message` event, drawn like the server's. |
| 450 | - **The viewer.** |
| 451 | - Clicking a thumbnail opens the sheet with focus on Close. |
| 452 | - Escape closes it and focus returns to the thumbnail. |
| 453 | - Tab stays inside while it is open. |
| 454 | - **Announcements.** The live region says when an upload finishes and |
| 455 | when one is refused. |
| 456 | - **The CSP.** The console shows no CSP violation through the whole test |
| 457 | (the harness captures the console). |
| 458 | - **Mobile width.** The chips scroll sideways, and the paperclip has a |
| 459 | 44 px target. Take a screenshot to `BASE_BROWSER_ARTIFACTS`. |
| 460 | - [ ] **Implement:** |
| 461 | - write `ask-attach.js`; |
| 462 | - add the `ask.js` hooks: `post()` appends `attachments`, so the key's |
| 463 | signature includes them; the files-only submit; P10's answers; the |
| 464 | paste hand-off; `addMessage` drawing the files row with the server's |
| 465 | markup. |
| 466 | - The words come from `data-*` attributes on the composer, written by |
| 467 | `chat.html`. |
| 468 | - [ ] **Gate:** `make test` and `make browser` (`-run 'TestAsk'`). |
| 469 | |
| 470 | ## Task 9: turn failures in words (Fable B1) |
| 471 | |
| 472 | - [ ] **Test first** (browser and webtest): |
| 473 | - A failed turn with reason `attachment_unavailable`, |
| 474 | `runner_storage_full` or `runner_too_old` shows its own line in the |
| 475 | status. Without script, the status line shows it too. |
| 476 | - Any other reason keeps "That didn't get an answer. Try again." |
| 477 | - [ ] **Implement** in `ask.js` `setTurn`, and in the no-script status line |
| 478 | in `ask.go`. |
| 479 | - [ ] **Gate:** `make test` and `make browser` (`-run 'TestAsk'`). |
| 480 | |
| 481 | ## Task 10: the native apps show files as a line (P9) |
| 482 | |
| 483 | - [ ] **Test first** (BaseKit tests): |
| 484 | - A message JSON with `attachments` decodes, and so does one with an |
| 485 | unknown `kind`. |
| 486 | - A person bubble with files and text shows the names line under the |
| 487 | text. A files-only bubble shows only the names. |
| 488 | - [ ] **Implement** in `Models.swift` and `Thread.swift`. Add the names |
| 489 | line's accessibility label to `Localizable.xcstrings`. |
| 490 | - [ ] **Gate:** `make native-check`. |
| 491 | |
| 492 | ## Task 11: copy review, gates, hand-over |
| 493 | |
| 494 | - [ ] **Copy review.** Add the rows to `docs/copy-pending.md` under the |
| 495 | next free review number (13 at the time of writing; check again). Run |
| 496 | the copy-review skill (`paulca/agent-skills` `copy-review`, `serve.sh`) |
| 497 | for Luna's review, and check `result.json` before running it again. |
| 498 | These are drafts. They reuse Equipo's approved words where they fit, and |
| 499 | never name Equipo. Equipo's two new strings (its plan, P6) go in the same |
| 500 | review. |
| 501 | |
| 502 | | Where | Text | |
| 503 | |---|---| |
| 504 | | Paperclip, label and tooltip | Attach files | |
| 505 | | Drop outline | Drop files to attach them | |
| 506 | | Chip, uploading | Uploading… | |
| 507 | | Chip, Remove (label) | Remove {name} | |
| 508 | | Chip, failed | Couldn't upload. Try again. | |
| 509 | | Chip, sixth file | At most 5 files in one message. | |
| 510 | | Chip, PDF (D4) | Ask can't read PDFs yet. | |
| 511 | | Chip, files refused at send (P10) | Files can't be read right now. Remove them to send your message. | |
| 512 | | Chip, stale (P10) | This file has expired. Attach it again. | |
| 513 | | Refusal, too large | That file is over 10 MB. | |
| 514 | | Refusal, type | Ask takes images (PNG, JPEG, WebP, GIF) and text, Markdown, CSV, JSON and PDF files. | |
| 515 | | Refusal, HEIC | HEIC photos can't be read yet. Share it as a JPEG and try again. | |
| 516 | | Refusal, pixels | That image is too large: at most 12,000 pixels on a side and 40 megapixels. | |
| 517 | | Refusal, too many waiting | Too many files are waiting to send. Send or remove some first. | |
| 518 | | Refusal, busy (after retries) | Too many uploads at once. Try again in a moment. | |
| 519 | | Announcement, uploaded | {name} attached | |
| 520 | | Announcement, refused | {name} not attached: {reason} | |
| 521 | | Thread, files row (label) | Attached files | |
| 522 | | Thread, pill (label) | {name}, {size}. Download | |
| 523 | | Viewer, Close | Close (approved) | |
| 524 | | Turn failed, file missing | A file didn't arrive whole. Attach it again. | |
| 525 | | Turn failed, no room | There's no room left for these files. Try fewer or smaller ones. | |
| 526 | | Turn failed, runner too old | Files can't be read right now. Send it again without them. | |
| 527 | | Native, names line (label) | Attached: {names} | |
| 528 | |
| 529 | - [ ] **Gates.** Run `make ci`, and the full `make browser` with |
| 530 | `BASE_BROWSER_ARTIFACTS`. Put the outputs in the report. Known failures |
| 531 | on main are listed in memory "Base review gates". |
| 532 | - [ ] **Review.** Get an independent review (Fable, else Codex Astra, with a |
| 533 | self-contained prompt). Fix what it finds, and push. |
| 534 | |
| 535 | ## Task 12 (controller): merge and deploy, after Equipo |
| 536 | |
| 537 | - [ ] **Wait for Equipo.** Equipo's Task 14 is done: production Equipo is |
| 538 | live, and Paul's snapshot says `can_attach: true`. |
| 539 | - [ ] **Merge.** Paul approves the copy review. Then merge |
| 540 | `feat/ask-attachments` to `main` on the hub. |
| 541 | - [ ] **Native first.** Release the native build with Task 10 (Mac Sparkle |
| 542 | and TestFlight) before or with the web deploy (P9). |
| 543 | - [ ] **Deploy Base:** the usual `make release` and carlos deploy. Then |
| 544 | `curl /api/version`, and restart if it is needed (memory "Calls gates |
| 545 | report false green"). |
| 546 | - [ ] **Check it live, as Paul:** |
| 547 | - attach a screenshot and a `.md`, and ask about both; |
| 548 | - copy a file in the Finder and paste it, in Chrome and in Safari (B8); |
| 549 | - Copy Image in a browser and paste it (B8); |
| 550 | - two messages later, ask about the `.md` again; |
| 551 | - paste an image, and paste a table from Numbers; |
| 552 | - remove a chip; |
| 553 | - open the thumbnail; |
| 554 | - check that the console shows no CSP errors. |
| 555 | - [ ] **Tell Paul.** |
| 556 | |
| 557 | ## Not in this plan |
| 558 | |
| 559 | - The native attach UI (slice 2), and reading PDFs (slice 3). |
| 560 | - Files for jobs (R6), removing a sent file (R2), sealing the bytes (R8), |
| 561 | and files into Oficina apps (R7). |
| 562 | |