oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

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