| 1 | # Slice 7: Send to Equipo and recent screenshots |
| 2 | |
| 3 | Approved by the controller at d6839992; implementation authorized. Original plan follows. Branch `native/share`, from fetched `origin/main` |
| 4 | `602b91fe`. No implementation or signing changes made. Scope follows the approved |
| 5 | daily-driver audit, gap 9 and build-order item 7, and `1-report-a-bug.html`. |
| 6 | No server or runner-protocol change is proposed. |
| 7 | |
| 8 | ## Signing and the portal |
| 9 | |
| 10 | Add an iPhone `EquipoShareExtension`, bundle ID `works.oficina.equipo.share`, |
| 11 | extension point `com.apple.share-services`. Follow `native/ios/project.yml`'s |
| 12 | Activity target: embed the `.appex`, match the app's version/build, give it its |
| 13 | own App ID and profile, and set `APPLICATION_EXTENSION_API_ONLY=YES`. |
| 14 | Activity currently uses `works.oficina.equipo.activity`, a separate App Store |
| 15 | profile, and no custom entitlements. Share needs keychain entitlements. |
| 16 | |
| 17 | Read-only checks with `agent-tools/equipo-tf/asc.py` and the Team Tito key on |
| 18 | 2026-11-26 returned 200 for bundle IDs, capabilities, profiles and certificates: |
| 19 | |
| 20 | | Existing item | Verified state | |
| 21 | | --- | --- | |
| 22 | | iPhone profile `Oficina Equipo iOS App Store 2026-11-21` | Active; expires 2027-09-13 | |
| 23 | | Activity profile `Oficina Equipo Activity iOS App Store 2026-11-20` | Active; expires 2027-09-13 | |
| 24 | | `Oficina Equipo macOS Developer ID` | Active; expires 2027-02-01 | |
| 25 | | Apple Distribution / Developer ID Application certificates | Present, with those respective expiry dates | |
| 26 | | `works.oficina.equipo.share` | Not registered | |
| 27 | |
| 28 | Decoded profile entitlements in memory: the iPhone and Activity profiles allow |
| 29 | `9U4A84C4WK.*` keychain groups. After approval, use the API to register the share |
| 30 | bundle (`POST /v1/bundleIds`), create/download its `IOS_APP_STORE` profile |
| 31 | (`POST /v1/profiles`) using the existing distribution certificate, and verify its |
| 32 | actual grants. Add its profile to the archive/export mapping in `testflight.sh` |
| 33 | and a new `OFICINA_SHARE_PROVISIONING_PROFILE` setting. Development-device builds |
| 34 | need the matching development profile; Simulator builds need no profile. |
| 35 | [Apple documents provisioning through the API](https://developer.apple.com/documentation/appstoreconnectapi), |
| 36 | including [profile creation](https://developer.apple.com/documentation/appstoreconnectapi/post-v1-profiles). |
| 37 | Read access was verified; no registration/profile POST was attempted in this |
| 38 | plan-only phase. |
| 39 | |
| 40 | The host already has `group.works.oficina` on iPhone and |
| 41 | `9U4A84C4WK.works.oficina` on Mac. **Do not add a shared filesystem container to |
| 42 | Share in this slice.** Foreground uploads and extension-private staging do not |
| 43 | need one. Keychain sharing is separate from App Group file access. This avoids |
| 44 | giving the extension the suite's shared files or needing a new portal group |
| 45 | assignment. A future background-upload handoff would need a shared container. |
| 46 | [Apple's extension guidance distinguishes these cases](https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html). |
| 47 | |
| 48 | **Paul's required portal work: none for this design.** Existing host and Activity |
| 49 | grants remain unchanged. API registration/profile generation is agent work after |
| 50 | approval. If Apple refuses a management write, report the actual refusal before |
| 51 | claiming a portal task is necessary. No certificate, profile, API token or private |
| 52 | key enters the repository. |
| 53 | |
| 54 | **Mac choice: Services, not another extension.** Register “Send to Equipo” in |
| 55 | `NSServices`, accepting text, URLs, file URLs and supported image pasteboard types. |
| 56 | It opens an Equipo compose sheet and requires Send. Paste/drop stay available. |
| 57 | It appears in Services/context menus, not the system Share menu. The provider |
| 58 | runs in the existing app, so its login-keychain access and Developer ID profile |
| 59 | stay unchanged; notarize the app normally at release. [Services registration](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/SysServices/Articles/providing.html). |
| 60 | |
| 61 | ## Authentication |
| 62 | |
| 63 | The audit's “credential is already in the App Group” shorthand is inaccurate: |
| 64 | `KeychainSecretStore` holds device accounts under service |
| 65 | `works.oficina.equipo.device`, currently using the host's default access group. |
| 66 | Give Share explicit access to `9U4A84C4WK.works.oficina.equipo` and the existing |
| 67 | `9U4A84C4WK.works.oficina.id` group. Use fixed service/group queries, never the |
| 68 | extension's bundle ID default. Keep the host's old group first, preserving saved |
| 69 | pairings. Reuse the existing device-only keychain accessibility; never export a |
| 70 | bearer into defaults, a file, a URL, a log or an extension result. |
| 71 | [Apple's keychain sharing model](https://developer.apple.com/documentation/security/sharing-access-to-keychain-items-among-a-collection-of-apps). |
| 72 | |
| 73 | The host writes a small active-share selection record to that keychain service: |
| 74 | origin, person/team identity and a selection generation. Share reads only that |
| 75 | selection and its account, not “the first saved account”. Check shared Oficina ID |
| 76 | identity/session presence too, so signing out in another suite app cannot leave |
| 77 | a locally forgotten identity usable here. Pairing accounts retain their existing |
| 78 | path. The extension does not pair, sign in, refresh credentials or change teams. |
| 79 | |
| 80 | Show the receiving person/team. Re-read selection, credential and expiry before |
| 81 | each upload and final POST; bind all results to the same generation/origin/person. |
| 82 | Sign-out, account change, keychain refusal and 401/403 stop the send, cancel work |
| 83 | and clear previews. The server remains the authority for membership and session |
| 84 | revocation. When signed out or expired, disable Send and explain that the person |
| 85 | must open Equipo, sign in, then share again. Do not force an unsupported app |
| 86 | switch from the extension or put sign-in UI inside it. |
| 87 | |
| 88 | ## Compose and bounded attachment handling |
| 89 | |
| 90 | - Use a small SwiftUI compose view in a share view controller: project chip, |
| 91 | message, attachment thumbnails, Cancel and Send. The default project is |
| 92 | “Equipo will choose”; a picker uses `GET /projects`'s `allowed` collection. |
| 93 | Send the chosen `project_id`, text and uploaded attachment IDs through the |
| 94 | existing `/messages` builder. No task-thread attachments. |
| 95 | - Enumerate host items with a bounded count. Activation rules advertise supported |
| 96 | images/files, URLs and text, never `TRUEPREDICATE`. Recheck types/counts at |
| 97 | runtime. URLs become literal editable message text; never fetch their pages or |
| 98 | run Safari preprocessing JavaScript. Reject folders and unsupported content |
| 99 | with the existing attachment words. Respect the 16 KiB message-text limit. |
| 100 | - Extract an extension-safe attachment/API/storage module rather than linking |
| 101 | the entire app session, event stream, Activity, notification or sign-in UI. |
| 102 | Reuse slice 2's rules: five files; 10 MiB upload each; final images at most |
| 103 | 12,000 pixels per side and 40 million pixels. `/capabilities` does not publish |
| 104 | configurable limits; these are the existing attachment contract. |
| 105 | - The existing `AttachmentFile.read` can allocate 128 MiB, so it cannot be the |
| 106 | extension's path. Add a shared file-backed preparation/upload path: |
| 107 | `NSItemProvider` file representations, scoped access before metadata reads, |
| 108 | bounded streaming copies into a private invocation directory, and |
| 109 | `CGImageSourceCreateWithURL` plus thumbnailing off the main actor. Copy provider |
| 110 | temporary files before their callback ends. Never request a full-size UIImage |
| 111 | or an unbounded Data representation; refuse providers without a safe bounded |
| 112 | representation. Keep the existing 128 MiB source-file cap on disk. |
| 113 | - Process one image at a time. Preserve the 2560-pixel long edge, JPEG quality |
| 114 | 0.85, HEIC/HEIF/TIFF conversion, orientation, white transparency backing, |
| 115 | metadata removal on conversion, and the existing GIF policy. Validate the |
| 116 | output again. Upload from a file; retain only small thumbnails, never five |
| 117 | original images. Treat about 120 MB as a risk budget, not a guaranteed iOS |
| 118 | allowance; measure peak resident memory on a signed device, targeting under |
| 119 | 80 MiB with five large inputs. |
| 120 | - In Share, stage locally until Send, then upload serially and POST the message. |
| 121 | Reuse per-item progress, retry, removal/cancellation, generation guards, |
| 122 | bearer attachment, redirect refusal and bounded response reads. Disable a |
| 123 | second Send and freeze the message during an attempt. Complete the extension |
| 124 | request only after the server acknowledges the message. |
| 125 | - Use the same immutable `PendingWrite` and idempotency key for retries. Journal |
| 126 | the final request (no credential) in protected, backup-excluded extension-private |
| 127 | storage before POST; an interrupted attempt can be explicitly retried under the |
| 128 | same verified person/origin, without generating another message. Never report |
| 129 | an uncertain response as success. Cancel/termination cancels network work; |
| 130 | remove staging on completion/cancel and sweep abandoned files at next entry. |
| 131 | Discard expired unresolved journals after 24 hours with an instruction to check |
| 132 | the conversation, not an automatic resend. Already uploaded unsent files use |
| 133 | the server's existing 24-hour cleanup and cap. |
| 134 | |
| 135 | ## The recent-screenshot offer |
| 136 | |
| 137 | **iPhone only; N = 5 minutes.** On the first composer + tap, show the one-time |
| 138 | explanation below, with Choose screenshots and the existing Not now. Choosing |
| 139 | calls `PHPhotoLibrary.requestAuthorization(for: .readWrite)`; Not now continues |
| 140 | to the ordinary attachment menu. Never request at launch, from Share, or merely |
| 141 | on entering Conversation. `.addOnly` cannot read screenshots. iOS controls the |
| 142 | system choices: we cannot force `.limited`, and must also handle full permission, |
| 143 | denial and restriction. Set `PHPhotoLibraryPreventAutomaticLimitedAccessAlert`. |
| 144 | [Apple's permission guidance](https://developer.apple.com/documentation/PhotoKit/delivering-an-enhanced-privacy-experience-in-your-photos-app). |
| 145 | |
| 146 | With permission, query only accessible, non-hidden screenshot assets created |
| 147 | between now minus five minutes and now, newest first, fetch limit one. Observe |
| 148 | library changes while the composer is active and recheck on foreground. Display |
| 149 | one small, dismissible chip; never add or upload it automatically. A chip tap |
| 150 | enters the ordinary attachment pipeline. Remember dismissed/added asset IDs for |
| 151 | their remaining eligibility window; recheck age and access on tap. Clear on |
| 152 | account change, background and revoked access; do not fetch cloud originals for |
| 153 | the offer. PhotosPicker, Camera, Files and Paste keep working without permission. |
| 154 | |
| 155 | Limited access does **not** automatically expose screenshots taken later. If the |
| 156 | latest screenshot is outside the person's selection, there is no chip. Keep |
| 157 | Choose screenshots in + to update the limited selection through |
| 158 | `presentLimitedLibraryPicker`; denial instead offers Open Settings. The normal |
| 159 | PhotosPicker can still attach an image without broad library access. |
| 160 | [Limited-library selection behaviour](https://developer.apple.com/documentation/photos/phphotolibrary/presentlimitedlibrarypicker(from:completionhandler:)). |
| 161 | |
| 162 | ## Copy proposed for Luna |
| 163 | |
| 164 | Luna approved the final copy on 2026-11-26. Final values are in the native catalog. The table below preserves the originally submitted proposals. Reuse the existing Send, Message, |
| 165 | Cancel, Not now, Try again, attachment errors and project-selection errors. |
| 166 | Import web `chat.connections.dismiss` (“Dismiss”) byte-identically for the chip's |
| 167 | close action, with parity coverage. |
| 168 | |
| 169 | | Key | Proposed value | Use | |
| 170 | | --- | --- | --- | |
| 171 | | `native.share.title` | Send to Equipo | Extension title/display name and Mac Service | |
| 172 | | `native.share.automatic` | Equipo will choose | Unselected project chip | |
| 173 | | `native.share.signed_out` | Open Equipo and sign in, then share this again. | No usable session | |
| 174 | | `native.share.unconfirmed` | Could not confirm this was sent. Try again. | Uncertain send; retry keeps the key | |
| 175 | | `native.share.check_conversation` | Open Equipo to check whether your message was sent. | Expired interrupted-send journal | |
| 176 | | `native.screenshot.offer` | Add the screenshot you just took | Chip action | |
| 177 | | `native.screenshot.permission_title` | Offer recent screenshots? | First + explanation | |
| 178 | | `native.screenshot.permission_detail` | Choose which photos Equipo can access. Recent screenshots can appear above your message. | Explanation before the system prompt | |
| 179 | | `native.screenshot.choose` | Choose screenshots | Request access or change limited selection | |
| 180 | | `native.screenshot.settings` | Open Settings | Explicit recovery after denial | |
| 181 | | `native.screenshot.usage` | Equipo uses photo access to offer recent screenshots for you to attach to a message. | `NSPhotoLibraryUsageDescription` | |
| 182 | |
| 183 | ## Tests and delivery |
| 184 | |
| 185 | Test-first, then mutate every authority, input-bound, cancellation, selection and |
| 186 | send guard. Keep the existing attachment regressions in the extracted module. |
| 187 | |
| 188 | | Lane | Coverage | |
| 189 | | --- | --- | |
| 190 | | Linux hub CI | Existing server/message/Coordinator image contracts; Python checks for activation rules, target embedding, entitlement/profile-variable wiring, catalog/parity and no credential files. No claim that Linux runs UIKit, PhotoKit or Security.framework. | |
| 191 | | Narrow native tests on Mac | Fake keychain/provider/clock/transport: fixed service/group, selected account, shared sign-out, 401/403, stale results, serial preparation, bounds and byte-identical transformations, URL-as-text, exact attachment IDs/project in POST, retries and interrupted-send replay. Mac Services dispatch into the compose model. Screenshot five-minute boundaries, permission timing, limited/unavailable assets, dismissal and no auto-upload. | |
| 192 | | Reused iPhone Simulator, filtered UI tests | Real host share sheet for image/file/text/URL, extension appearance and cancellation; first + prompt, limited selection, denial, chip and dismissal; light/dark and large Dynamic Type. A local fake server captures uploaded image bytes and the message's attachment IDs; the existing server contract separately proves Coordinator image delivery. | |
| 193 | | Signed iPhone / release smoke | Host-to-extension keychain access with distribution entitlements, existing-install pairings, cross-app sign-out, large HEIC/WebP memory, Photos screenshots, Files security scope and real limited-library behaviour. Simulator cannot prove signing or jetsam behaviour. Signed Mac Services launch with the existing Developer ID packaging. | |
| 194 | |
| 195 | No heavy job for this plan. During implementation, check load/swap and other heavy |
| 196 | jobs before each build/test/simulator run; wait above load 20 or with two other |
| 197 | heavy jobs. One job, four workers, narrow filters and bounded timeouts. No full |
| 198 | local gate script; full server gates run on hub CI. Reuse a simulator, close what |
| 199 | we start, and remove scratch. Future evidence goes in `site/build/slice7/` and a |
| 200 | controller report. Submit this note and draft copy before implementation. |
| 201 | |