| 1 | # Native composer attachments |
| 2 | |
| 3 | Branch: `native/attachments`, in its own physical-TMPDIR worktree, based on |
| 4 | `origin/main` at `2950f604`, then rebased before its first push onto landed main |
| 5 | `4024216e` (including the stopped-work release follow-up). String catalogs |
| 6 | were regenerated from the union of both slices' reviewed keys; both debug |
| 7 | fixture entry points and the landed stopped-work behavior were retained. |
| 8 | |
| 9 | ## Behavior |
| 10 | |
| 11 | The conversation composer accepts up to five attachments. On iPhone, the |
| 12 | plus menu offers Photos (PhotosPicker), Camera, Files, and Paste. PhotosPicker |
| 13 | does not request full-library access. HEIC/HEIF photos convert to JPEG with |
| 14 | orientation applied and source metadata omitted. Mac clipboard TIFF images |
| 15 | also convert to JPEG. Mac supports image/file paste and drag-and-drop through |
| 16 | the AppKit composer. Area capture is omitted as agreed with the controller: |
| 17 | a permission-free area capture path was not established; ScreenCaptureKit |
| 18 | capture requires Screen Recording permission. |
| 19 | |
| 20 | The source file is checked before upload: at most 10 MiB, 12,000 pixels per |
| 21 | side, and 40 megapixels. These constants are POST /attachments' published v1 |
| 22 | contract and `internal/attach/attach.go`; /capabilities does not publish |
| 23 | configurable attachment limits. Converted JPEG bytes are checked again. |
| 24 | Files are read with a maximum byte count; image dimensions are read before |
| 25 | raster conversion. |
| 26 | |
| 27 | Each item has upload progress, failure, retry, and remove. Failed and uploading |
| 28 | items block sending. Removing an item prevents a late response from restoring |
| 29 | it. Sending carries the uploaded ids in /messages, including attachment-only |
| 30 | messages. The session keeps attachment metadata with a pending outgoing |
| 31 | message; retry keeps its ids and idempotency key. Signing out clears the draft. |
| 32 | |
| 33 | Sent bubbles fetch thumbnails through authenticated /attachments/{id}/preview |
| 34 | reads. Tapping opens the original through /attachments/{id}, full screen on |
| 35 | iPhone and in a sheet on Mac. Images, text files, and PDFs have native previews. |
| 36 | The transport remains ephemeral, without cookie storage or redirects, including |
| 37 | the upload delegate. No server route changed. |
| 38 | |
| 39 | Share extension, recent-screenshot offers, area capture, and task-thread |
| 40 | attachments are outside this slice. |
| 41 | |
| 42 | ## Copy |
| 43 | |
| 44 | The web's chat.attach.* and api.attachment_* entries are copied into the |
| 45 | catalog byte-identically, except the existing %s to %@ native format conversion. |
| 46 | team.close is the existing reviewed web word. Parity covers these namespaces. |
| 47 | |
| 48 | The five native-only entries were approved by Luna through the controller on |
| 49 | 2026-11-25: |
| 50 | |
| 51 | | Key | Value | Use | |
| 52 | | --- | --- | --- | |
| 53 | | native.attach.photos | Photos | Picker menu | |
| 54 | | native.attach.camera | Camera | Picker menu | |
| 55 | | native.attach.files | Files | Picker menu | |
| 56 | | native.attach.paste | Paste | Picker menu | |
| 57 | | native.attach.camera_usage | Use your camera to take a photo to attach to your message. | Camera purpose string | |
| 58 | |
| 59 | Approval is recorded beside the menu labels and Info.plist source in |
| 60 | project.yml. Fixture message text is illustrative user content, not runtime |
| 61 | interface copy. No further copy questions. |
| 62 | |
| 63 | ## Test-first evidence |
| 64 | |
| 65 | `swift test --package-path native/apple --filter AttachmentTests` first |
| 66 | failed because AttachmentLimits, AttachmentFile, AttachmentDraft and attachment |
| 67 | API methods were absent. The initial tests covered byte/pixel/type limits, |
| 68 | HEIC conversion, upload headers, message attachment ids, image delivery to a |
| 69 | fake Coordinator, failed upload retry, removal, and the send gate. |
| 70 | |
| 71 | The expanded `swift test --package-path native/apple --filter Attachment` |
| 72 | passed 10 tests in three suites. It also covers reservation of all five slots |
| 73 | while uploading, an invalid image never reaching the upload endpoint, late |
| 74 | completion after removal, duplicate ids, clearing the draft after send and |
| 75 | sign-out, and the Mac paste/drop entry point. |
| 76 | |
| 77 | A real loopback HTTP server test exercises URLSession's raw upload and progress |
| 78 | delegate. The server resolves the submitted message ids to uploaded image |
| 79 | bytes before exposing the fake Coordinator's received image; the test compares |
| 80 | those bytes with the source image. The server binds only 127.0.0.1 and is |
| 81 | terminated after the test. |
| 82 | |
| 83 | The actual Coordinator already converts attachments to Claude image content |
| 84 | and Codex localImage input, covered by |
| 85 | `internal/headless/attachments_test.go:TestHeadlessAttachments`. The local |
| 86 | command `GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/headless -run |
| 87 | TestHeadlessAttachments -count=1` could not build on macOS because |
| 88 | `internal/toolproxy/stdio.go` uses Linux `unix.O_PATH`. Linux hub CI remains |
| 89 | the gate for those server tests. |
| 90 | |
| 91 | ## Mutations |
| 92 | |
| 93 | `python3 "$TMPDIR/attachments-mutations.py"` ran the focused |
| 94 | `swift test --package-path native/apple --filter Attachment` suite for each |
| 95 | mutation, required a failed assertion or thrown test error, and restored each |
| 96 | source file in a finally block. All 13 mutations were caught: |
| 97 | |
| 98 | | Deliberately broken behavior | Result | |
| 99 | | --- | --- | |
| 100 | | Byte limit removed | Caught | |
| 101 | | Side-length limit removed | Caught | |
| 102 | | Pixel-count limit removed | Caught | |
| 103 | | Dimension validation before upload removed | Caught | |
| 104 | | HEIC result advertised as HEIC instead of JPEG | Caught | |
| 105 | | Five-item draft limit removed | Caught | |
| 106 | | Uploading/failed items allowed to send | Caught | |
| 107 | | Remove keeps the item | Caught | |
| 108 | | Retry never uploads | Caught | |
| 109 | | Message attachment ids omitted | Caught | |
| 110 | | Upload bearer omitted | Caught | |
| 111 | | Uploaded bytes replaced with an empty body | Caught | |
| 112 | | Mac image paste/drop entry point disabled | Caught | |
| 113 | |
| 114 | The first remove mutator produced invalid Swift; it was not counted. It was |
| 115 | corrected to a compiling no-op remove and the assertions then failed. |
| 116 | |
| 117 | Initial full native gate passed: 217 tests in 28 suites, one existing known |
| 118 | issue, 125 parity strings, Mac build and iPhone Simulator build. Final gate |
| 119 | and Linux CI are recorded with the final branch SHA. |
| 120 | |
| 121 | Native captures are under |
| 122 | `polish-audit/equipo-daily-driver/site/build/slice2/`: |
| 123 | `iphone-composer.png`, `iphone-sent.png`, and `mac-drop.png`. |
| 124 | The debug fixtures use the production composer, message views and API client |
| 125 | with a fake transport. The Mac capture enters the same pasteboard handler as |
| 126 | performDragOperation. No real account or screenshot permission is used. |
| 127 | |
| 128 | ## Final contract check |
| 129 | |
| 130 | The rebased native gate passed 244 tests in 31 suites, the existing known issue, |
| 131 | 221 parity strings and both builds. A final comparison with attach.Inspect then |
| 132 | found that native's initial text-extension list was narrower than the server: |
| 133 | the server also accepts extensionless UTF-8 files and source files. A new |
| 134 | `textDetectionMatchesServerInsteadOfRestrictingExtensions` test failed first. |
| 135 | Native now uses the server's UTF-8/control-character rule, excludes misleading |
| 136 | image/PDF suffixes from text fallback, and advertises JSON only when valid. |
| 137 | |
| 138 | `swift test --package-path native/apple --filter Attachment` then passed |
| 139 | 11 tests across three suites. Four further mutations, run by |
| 140 | `python3 "$TMPDIR/attachments-text-mutations.py"`, each failed assertions and |
| 141 | were restored: wrong fallback media type, removed control-character check, |
| 142 | removed image-suffix check, and removed JSON validity check. Total: 17 caught |
| 143 | mutations. This contract correction adds no copy. |
| 144 | |
| 145 | ## Screenshot review polish |
| 146 | |
| 147 | The failed-upload sentence stays byte-identical. Its duplicate text button is |
| 148 | now an arrow.clockwise icon beside remove, with a 44 by 44 point tap target and |
| 149 | the reviewed read.retry accessibility label. Sent bubbles align the thumbnail |
| 150 | tiles, filenames and message text to the same leading edge inside normal |
| 151 | padding. An adaptive grid wraps when space is limited. The debug fixture now |
| 152 | includes a portrait screenshot and a synthetic landscape JPEG to check mixed |
| 153 | aspect ratios. Both fit side by side in the captured iPhone and Mac bubbles. |
| 154 | |
| 155 | All three requested screenshots were recaptured from this branch and inspected. |
| 156 | The Mac capture uses day appearance. Final `native/scripts/check-native.sh` |
| 157 | passed: 245 tests in 31 suites, one existing known issue, 221 parity strings, |
| 158 | zero reference failures, and Mac plus iPhone Simulator builds. No server files |
| 159 | changed. No new copy was added by these polish fixes. |
| 160 | |
| 161 | ## Fable review follow-up |
| 162 | |
| 163 | Review of 69e059bc requested three P2 corrections and associated P3 polish. |
| 164 | Slice 3 was paused before editing code. This follow-up remains on the published |
| 165 | native/attachments branch, with new commits and no rebase. |
| 166 | |
| 167 | Image preparation now matches chat-attach.js: JPEG quality 0.85, long edge |
| 168 | 2560, orientation applied and transparency flattened onto white. HEIC/HEIF |
| 169 | and TIFF are converted; other oversized images, including WebP, are converted; |
| 170 | GIFs retain the web's exception. ImageIO creates only a bounded thumbnail, |
| 171 | on the background preparation task. The server's 10 MiB/12000 px/40 MP limits |
| 172 | apply to the upload. Local file reads use a separate 128 MiB input bound so |
| 173 | large compressed photographs can be resized before the upload check. |
| 174 | |
| 175 | The new generated 8064 by 6048 HEIC test failed first with AttachmentFailure |
| 176 | pixels. The large WebP fixture is a generated solid-colour 4096 by 2048 image |
| 177 | (encoded with cwebp); both now become bounded JPEGs. The HEIC metadata test |
| 178 | sets GPS and a private EXIF comment, verifies their removal, and checks a |
| 179 | 90-degree orientation transform. A small injected output limit tests the |
| 180 | size check after conversion independently of compression ratios. |
| 181 | |
| 182 | Mac drag tests now send synthetic NSDraggingInfo through draggingEntered, |
| 183 | draggingUpdated, prepareForDragOperation and performDragOperation. They first |
| 184 | failed for PNG/TIFF at the update and prepare stages. All four stages now |
| 185 | accept supported image/file/promise types and refuse web URLs. Promised files |
| 186 | are received through NSFilePromiseReceiver into a mode-0700 temporary directory, |
| 187 | read inside its coordinated callback, and removed. The draft retains the bytes |
| 188 | for retry; the directory is removed when its readers release it. A receiver |
| 189 | fixture verifies delivery and cleanup. Folders are refused before a draft item |
| 190 | is created, using api.attachment_type. |
| 191 | |
| 192 | Removing an item and clearing a draft cancel the owned upload tasks. The |
| 193 | cancellation test first failed with the original non-cancelling implementation. |
| 194 | Thumbnail and original-preview image decoding also move to detached tasks, |
| 195 | with 512/4096 pixel bounds and a cancellation check before updating UI state. |
| 196 | |
| 197 | The iPhone keeps the reviewed Paste menu item and accepts the system paste |
| 198 | prompt, as explicitly permitted by the review. This choice keeps the attachment |
| 199 | sources together in the menu. No new runtime copy is introduced. |
| 200 | |
| 201 | `swift test --package-path native/apple --filter Attachment` passed 25 tests |
| 202 | across four suites after the review fixes. The updated loopback HTTP test also |
| 203 | rejects a 307 upload redirect and a response exceeding the per-request cap. |
| 204 | |
| 205 | `python3 "$TMPDIR/attachments-review-mutations.py"` independently broke each |
| 206 | of these 22 behaviors; each run failed an assertion or threw a test error and |
| 207 | the source was restored in a finally block: |
| 208 | |
| 209 | | Mutation | Result | |
| 210 | | --- | --- | |
| 211 | | Source metadata retained in converted JPEG | Caught | |
| 212 | | Orientation transform disabled | Caught | |
| 213 | | Attachment read bearer omitted | Caught | |
| 214 | | Upload delegate follows redirect | Caught | |
| 215 | | Transport response cap removed | Caught | |
| 216 | | Attachment client response cap removed | Caught | |
| 217 | | Composer canSend guard removed | Caught | |
| 218 | | Lost-project retry drops attachment ids | Caught | |
| 219 | | Task-thread send accepts attachments | Caught | |
| 220 | | Retry allowed while already uploading | Caught | |
| 221 | | Late progress overwrites a ready item | Caught | |
| 222 | | Retry generation check removed | Caught | |
| 223 | | Server attachment codes use generic copy | Caught | |
| 224 | | Bounded-file read size check removed | Caught | |
| 225 | | Converted output size check removed | Caught | |
| 226 | | Empty data accepted | Caught | |
| 227 | | Mac pasteboard accepts web URLs | Caught | |
| 228 | | Removal does not cancel the upload | Caught | |
| 229 | | Full-size conversion instead of 2560 thumbnail | Caught | |
| 230 | | Large WebP skips JPEG conversion | Caught | |
| 231 | | draggingUpdated refuses image data | Caught | |
| 232 | | prepareForDragOperation refuses image data | Caught | |
| 233 | |
| 234 | These are in addition to the original 17 mutations. Test scaffolding compile |
| 235 | errors were corrected before running the mutations; no compiler failure is |
| 236 | counted as a caught mutation. |
| 237 | |
| 238 | The capture exercise found a further iPhone presentation defect: PhotosPicker |
| 239 | inside the transient Menu closed without opening its picker. The menu now |
| 240 | sets a binding for a photosPicker modifier on the stable parent. The retained |
| 241 | AttachmentSourceUITests test taps Attach, opens Photos, and requires the |
| 242 | system Photos navigation bar. It uses the real app with its debug transport. |
| 243 | The first capture harness showed the missing picker; the corrected capture |
| 244 | shows Private Access to Photos, without requesting full-library access. |
| 245 | |
| 246 | General desktop automation lacked Accessibility permission and the standalone |
| 247 | Mac XCTest runner could not start an automation session. No permissions were |
| 248 | changed. The Mac screenshot fixture now runs all four drag destination methods |
| 249 | with synthetic NSDraggingInfo before capturing, matching the regression test; |
| 250 | it is not claimed as a physical mouse-drag capture. |
| 251 | |
| 252 | Final verification: `native/scripts/check-native.sh` passed 259 tests in 32 |
| 253 | suites (one pre-existing known issue), 221 parity strings, zero dead-reference |
| 254 | failures, and both platform builds. Adding an explicit capture scheme initially |
| 255 | hid XcodeGen's automatic EquipoPhone scheme; the app's original build scheme |
| 256 | is now explicit too, and the full gate was rerun successfully. |
| 257 | |
| 258 | `xcodebuild -project EquipoPhone.xcodeproj -scheme AttachmentSources |
| 259 | -destination 'platform=iOS Simulator,id=C86CAA29-B99C-40AB-84C4-DF7C74926904' |
| 260 | -derivedDataPath ../build/Phone CODE_SIGNING_ALLOWED=NO test` passed its retained |
| 261 | UI test. Its XCTest screenshots were exported with `xcresulttool export |
| 262 | attachments`, inspected, and saved as `iphone-add-menu.png` and |
| 263 | `iphone-photos-picker.png` beside the refreshed `mac-drop.png` in slice2. |
| 264 | The Photos picker explicitly shows Oficina Equipo can access only selected |
| 265 | items. Its Location Included system label describes the selected source; |
| 266 | converted images drop metadata and the server strips location on every upload. |
| 267 | |
| 268 | ## Security-scoped Files follow-up, 2026-11-26 |
| 269 | |
| 270 | Fable's delta review found that the immediate folder check ran before iPhone |
| 271 | fileImporter URLs entered security-scoped access. The draft now checks file |
| 272 | metadata inside a balanced access window, before creating an item. Local URLs |
| 273 | whose startAccessingSecurityScopedResource returns false remain supported. |
| 274 | The later bounded read retains its own balanced access window. Folders still |
| 275 | produce api.attachment_type immediately and never become retryable items. |
| 276 | |
| 277 | A fake resolver rejects metadata reads unless access is active. With the old |
| 278 | ordering, `swift test --package-path native/apple --filter |
| 279 | AttachmentFollowupTests` failed with three assertions: the file was refused |
| 280 | and the access sequence was wrong for both files and folders. With the fix, |
| 281 | both paths observe start, metadata, stop, and the file reaches the fake server. |
| 282 | |
| 283 | The Mac composer delegates ordinary text drags to NSTextView in all four |
| 284 | callbacks. A real NSTextView baseline and synthetic NSDraggingInfo exercise |
| 285 | entry, update, preparation and insertion; the original code failed six |
| 286 | assertions, including actual text insertion. The controller clarified that |
| 287 | web URLs must also insert as plain text, not be blocked. The URL drop test |
| 288 | first failed five assertions against the explicit URL refusal. Both URL drops |
| 289 | and actual NSTextView paste now insert the URL as text, with no draft item or |
| 290 | upload request. PNG/TIFF, file URLs and file promises retain the attachment |
| 291 | path. The paste test preserves and restores the system clipboard in memory |
| 292 | within one synchronous scope; no clipboard contents are logged. |
| 293 | |
| 294 | Additional tests distinguish cancellation after preparation from the item's |
| 295 | identity check, cancel every upload on clear, enforce 10 MiB for an image that |
| 296 | is not resized, inspect the flattened JPEG's pixel color, reject a promised |
| 297 | file outside its private directory, and require per-file deletion while a |
| 298 | promise reader still holds the directory alive. This last test cannot pass |
| 299 | merely because directory deinit eventually removes everything. |
| 300 | |
| 301 | `swift test --package-path native/apple --filter |
| 302 | 'AttachmentFollowupTests|MacAttachmentTests'` passed 13 tests in two suites. |
| 303 | No new runtime copy or server changes are included. |
| 304 | |
| 305 | `python3 "$TMPDIR/attachments-followup-mutations.py"` mutates one guard at a |
| 306 | time, runs the two suites above, requires a built test binary and an assertion |
| 307 | failure, then restores the source in a finally block. Its cases are: |
| 308 | |
| 309 | | Mutation | Expected regression | |
| 310 | | --- | --- | |
| 311 | | Metadata before scoped access | Selected file refused; wrong access order | |
| 312 | | clear does not cancel uploads | Both server operations remain active | |
| 313 | | Cancellation check after preparation removed | Cancelled preparation uploads | |
| 314 | | Unresized-image byte limit removed | Oversized PNG accepted | |
| 315 | | White canvas fill removed | Transparent pixels become black | |
| 316 | | Promise directory containment removed | Outside file enters draft | |
| 317 | | Per-file promise removal removed | Delivered file remains during other reads | |
| 318 | | Text draggingEntered refuses fallback | Entry differs from NSTextView | |
| 319 | | Text draggingUpdated refuses fallback | Update differs from NSTextView | |
| 320 | | Text prepareForDragOperation refuses fallback | Preparation refused | |
| 321 | | Text performDragOperation refuses fallback | Text never inserted | |
| 322 | | File-URL-only pasteboard filter removed | Web URL becomes an attachment instead of text | |
| 323 | |
| 324 | All 12 mutations were caught. After the URL behavior clarification, case 12 |
| 325 | was replaced with removal of the file-URL-only filter and rerun using |
| 326 | `python3 "$TMPDIR/attachments-followup-mutations.py" 12`; it failed the URL |
| 327 | text/attachment assertions. The other 11 mutations and their tests were |
| 328 | unchanged. No compiler failure was counted as a caught mutation. |
| 329 | |
| 330 | Final `native/scripts/check-native.sh` passed after the URL clarification: |
| 331 | 268 tests in 33 suites, one pre-existing known issue, 221 byte-identical parity |
| 332 | strings, zero dead-reference failures, and successful Mac and iPhone Simulator |
| 333 | builds. The exact mutation script, failure logs and final gate log are retained |
| 334 | with the slice2 evidence as `scoped-verification-evidence.tar.gz` and |
| 335 | `scoped-native-gate.log`. |
| 336 | |