# Slice 7: Send to Equipo and recent screenshots

Approved by the controller at d6839992; implementation authorized. Original plan follows. Branch `native/share`, from fetched `origin/main`
`602b91fe`. No implementation or signing changes made. Scope follows the approved
daily-driver audit, gap 9 and build-order item 7, and `1-report-a-bug.html`.
No server or runner-protocol change is proposed.

## Signing and the portal

Add an iPhone `EquipoShareExtension`, bundle ID `works.oficina.equipo.share`,
extension point `com.apple.share-services`. Follow `native/ios/project.yml`'s
Activity target: embed the `.appex`, match the app's version/build, give it its
own App ID and profile, and set `APPLICATION_EXTENSION_API_ONLY=YES`.
Activity currently uses `works.oficina.equipo.activity`, a separate App Store
profile, and no custom entitlements. Share needs keychain entitlements.

Read-only checks with `agent-tools/equipo-tf/asc.py` and the Team Tito key on
2026-11-26 returned 200 for bundle IDs, capabilities, profiles and certificates:

| Existing item | Verified state |
| --- | --- |
| iPhone profile `Oficina Equipo iOS App Store 2026-11-21` | Active; expires 2027-09-13 |
| Activity profile `Oficina Equipo Activity iOS App Store 2026-11-20` | Active; expires 2027-09-13 |
| `Oficina Equipo macOS Developer ID` | Active; expires 2027-02-01 |
| Apple Distribution / Developer ID Application certificates | Present, with those respective expiry dates |
| `works.oficina.equipo.share` | Not registered |

Decoded profile entitlements in memory: the iPhone and Activity profiles allow
`9U4A84C4WK.*` keychain groups. After approval, use the API to register the share
bundle (`POST /v1/bundleIds`), create/download its `IOS_APP_STORE` profile
(`POST /v1/profiles`) using the existing distribution certificate, and verify its
actual grants. Add its profile to the archive/export mapping in `testflight.sh`
and a new `OFICINA_SHARE_PROVISIONING_PROFILE` setting. Development-device builds
need the matching development profile; Simulator builds need no profile.
[Apple documents provisioning through the API](https://developer.apple.com/documentation/appstoreconnectapi),
including [profile creation](https://developer.apple.com/documentation/appstoreconnectapi/post-v1-profiles).
Read access was verified; no registration/profile POST was attempted in this
plan-only phase.

The host already has `group.works.oficina` on iPhone and
`9U4A84C4WK.works.oficina` on Mac. **Do not add a shared filesystem container to
Share in this slice.** Foreground uploads and extension-private staging do not
need one. Keychain sharing is separate from App Group file access. This avoids
giving the extension the suite's shared files or needing a new portal group
assignment. A future background-upload handoff would need a shared container.
[Apple's extension guidance distinguishes these cases](https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html).

**Paul's required portal work: none for this design.** Existing host and Activity
grants remain unchanged. API registration/profile generation is agent work after
approval. If Apple refuses a management write, report the actual refusal before
claiming a portal task is necessary. No certificate, profile, API token or private
key enters the repository.

**Mac choice: Services, not another extension.** Register “Send to Equipo” in
`NSServices`, accepting text, URLs, file URLs and supported image pasteboard types.
It opens an Equipo compose sheet and requires Send. Paste/drop stay available.
It appears in Services/context menus, not the system Share menu. The provider
runs in the existing app, so its login-keychain access and Developer ID profile
stay unchanged; notarize the app normally at release. [Services registration](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/SysServices/Articles/providing.html).

## Authentication

The audit's “credential is already in the App Group” shorthand is inaccurate:
`KeychainSecretStore` holds device accounts under service
`works.oficina.equipo.device`, currently using the host's default access group.
Give Share explicit access to `9U4A84C4WK.works.oficina.equipo` and the existing
`9U4A84C4WK.works.oficina.id` group. Use fixed service/group queries, never the
extension's bundle ID default. Keep the host's old group first, preserving saved
pairings. Reuse the existing device-only keychain accessibility; never export a
bearer into defaults, a file, a URL, a log or an extension result.
[Apple's keychain sharing model](https://developer.apple.com/documentation/security/sharing-access-to-keychain-items-among-a-collection-of-apps).

The host writes a small active-share selection record to that keychain service:
origin, person/team identity and a selection generation. Share reads only that
selection and its account, not “the first saved account”. Check shared Oficina ID
identity/session presence too, so signing out in another suite app cannot leave
a locally forgotten identity usable here. Pairing accounts retain their existing
path. The extension does not pair, sign in, refresh credentials or change teams.

Show the receiving person/team. Re-read selection, credential and expiry before
each upload and final POST; bind all results to the same generation/origin/person.
Sign-out, account change, keychain refusal and 401/403 stop the send, cancel work
and clear previews. The server remains the authority for membership and session
revocation. When signed out or expired, disable Send and explain that the person
must open Equipo, sign in, then share again. Do not force an unsupported app
switch from the extension or put sign-in UI inside it.

## Compose and bounded attachment handling

- Use a small SwiftUI compose view in a share view controller: project chip,
  message, attachment thumbnails, Cancel and Send. The default project is
  “Equipo will choose”; a picker uses `GET /projects`'s `allowed` collection.
  Send the chosen `project_id`, text and uploaded attachment IDs through the
  existing `/messages` builder. No task-thread attachments.
- Enumerate host items with a bounded count. Activation rules advertise supported
  images/files, URLs and text, never `TRUEPREDICATE`. Recheck types/counts at
  runtime. URLs become literal editable message text; never fetch their pages or
  run Safari preprocessing JavaScript. Reject folders and unsupported content
  with the existing attachment words. Respect the 16 KiB message-text limit.
- Extract an extension-safe attachment/API/storage module rather than linking
  the entire app session, event stream, Activity, notification or sign-in UI.
  Reuse slice 2's rules: five files; 10 MiB upload each; final images at most
  12,000 pixels per side and 40 million pixels. `/capabilities` does not publish
  configurable limits; these are the existing attachment contract.
- The existing `AttachmentFile.read` can allocate 128 MiB, so it cannot be the
  extension's path. Add a shared file-backed preparation/upload path:
  `NSItemProvider` file representations, scoped access before metadata reads,
  bounded streaming copies into a private invocation directory, and
  `CGImageSourceCreateWithURL` plus thumbnailing off the main actor. Copy provider
  temporary files before their callback ends. Never request a full-size UIImage
  or an unbounded Data representation; refuse providers without a safe bounded
  representation. Keep the existing 128 MiB source-file cap on disk.
- Process one image at a time. Preserve the 2560-pixel long edge, JPEG quality
  0.85, HEIC/HEIF/TIFF conversion, orientation, white transparency backing,
  metadata removal on conversion, and the existing GIF policy. Validate the
  output again. Upload from a file; retain only small thumbnails, never five
  original images. Treat about 120 MB as a risk budget, not a guaranteed iOS
  allowance; measure peak resident memory on a signed device, targeting under
  80 MiB with five large inputs.
- In Share, stage locally until Send, then upload serially and POST the message.
  Reuse per-item progress, retry, removal/cancellation, generation guards,
  bearer attachment, redirect refusal and bounded response reads. Disable a
  second Send and freeze the message during an attempt. Complete the extension
  request only after the server acknowledges the message.
- Use the same immutable `PendingWrite` and idempotency key for retries. Journal
  the final request (no credential) in protected, backup-excluded extension-private
  storage before POST; an interrupted attempt can be explicitly retried under the
  same verified person/origin, without generating another message. Never report
  an uncertain response as success. Cancel/termination cancels network work;
  remove staging on completion/cancel and sweep abandoned files at next entry.
  Discard expired unresolved journals after 24 hours with an instruction to check
  the conversation, not an automatic resend. Already uploaded unsent files use
  the server's existing 24-hour cleanup and cap.

## The recent-screenshot offer

**iPhone only; N = 5 minutes.** On the first composer ＋ tap, show the one-time
explanation below, with Choose screenshots and the existing Not now. Choosing
calls `PHPhotoLibrary.requestAuthorization(for: .readWrite)`; Not now continues
to the ordinary attachment menu. Never request at launch, from Share, or merely
on entering Conversation. `.addOnly` cannot read screenshots. iOS controls the
system choices: we cannot force `.limited`, and must also handle full permission,
denial and restriction. Set `PHPhotoLibraryPreventAutomaticLimitedAccessAlert`.
[Apple's permission guidance](https://developer.apple.com/documentation/PhotoKit/delivering-an-enhanced-privacy-experience-in-your-photos-app).

With permission, query only accessible, non-hidden screenshot assets created
between now minus five minutes and now, newest first, fetch limit one. Observe
library changes while the composer is active and recheck on foreground. Display
one small, dismissible chip; never add or upload it automatically. A chip tap
enters the ordinary attachment pipeline. Remember dismissed/added asset IDs for
their remaining eligibility window; recheck age and access on tap. Clear on
account change, background and revoked access; do not fetch cloud originals for
the offer. PhotosPicker, Camera, Files and Paste keep working without permission.

Limited access does **not** automatically expose screenshots taken later. If the
latest screenshot is outside the person's selection, there is no chip. Keep
Choose screenshots in ＋ to update the limited selection through
`presentLimitedLibraryPicker`; denial instead offers Open Settings. The normal
PhotosPicker can still attach an image without broad library access.
[Limited-library selection behaviour](https://developer.apple.com/documentation/photos/phphotolibrary/presentlimitedlibrarypicker(from:completionhandler:)).

## Copy proposed for Luna

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,
Cancel, Not now, Try again, attachment errors and project-selection errors.
Import web `chat.connections.dismiss` (“Dismiss”) byte-identically for the chip's
close action, with parity coverage.

| Key | Proposed value | Use |
| --- | --- | --- |
| `native.share.title` | Send to Equipo | Extension title/display name and Mac Service |
| `native.share.automatic` | Equipo will choose | Unselected project chip |
| `native.share.signed_out` | Open Equipo and sign in, then share this again. | No usable session |
| `native.share.unconfirmed` | Could not confirm this was sent. Try again. | Uncertain send; retry keeps the key |
| `native.share.check_conversation` | Open Equipo to check whether your message was sent. | Expired interrupted-send journal |
| `native.screenshot.offer` | Add the screenshot you just took | Chip action |
| `native.screenshot.permission_title` | Offer recent screenshots? | First ＋ explanation |
| `native.screenshot.permission_detail` | Choose which photos Equipo can access. Recent screenshots can appear above your message. | Explanation before the system prompt |
| `native.screenshot.choose` | Choose screenshots | Request access or change limited selection |
| `native.screenshot.settings` | Open Settings | Explicit recovery after denial |
| `native.screenshot.usage` | Equipo uses photo access to offer recent screenshots for you to attach to a message. | `NSPhotoLibraryUsageDescription` |

## Tests and delivery

Test-first, then mutate every authority, input-bound, cancellation, selection and
send guard. Keep the existing attachment regressions in the extracted module.

| Lane | Coverage |
| --- | --- |
| 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. |
| 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. |
| 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. |
| 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. |

No heavy job for this plan. During implementation, check load/swap and other heavy
jobs before each build/test/simulator run; wait above load 20 or with two other
heavy jobs. One job, four workers, narrow filters and bounded timeouts. No full
local gate script; full server gates run on hub CI. Reuse a simulator, close what
we start, and remove scratch. Future evidence goes in `site/build/slice7/` and a
controller report. Submit this note and draft copy before implementation.
