# Native stopped work

Branch: `native/stopped-work`, based on `origin/main` at `2950f604`.

## Behavior

- Native carries all 70 `work.reason.*` entries, the stopped lead, and the
  reviewed Needs you/held words. `check-parity.py` checks values and completeness.
- Stopped work leads with its finished time in the device's zone and the web's
  reason, including the web's `no_further_changes` distinction. Retry requires
  the creator and a terminated failed step. The 409 `not_retryable` answer uses
  `api.not_retryable` and the screen refreshes after the action.
- Run now retains its offer/revision contract. Resume resolves the held runner,
  local connection and provider against the person's connections and sends the
  observed `pause_revision`. Settings actions use the web's exact destinations.
- iPhone uses SFSafariViewController; Mac uses WebKit's native SwiftUI WebView
  in a sheet (macOS 26 minimum). Browser sessions persist independently of the
  API bearer. With no browser session, the site asks the person to sign in.
- Failed steps load their stored log on disclosure. The selectable monospaced
  view wraps by character on iPhone and scrolls horizontally on Mac, bounded
  to 200 lines and 32 KiB. Its height fits the content up to 180 points, then
  scrolls vertically. UIKit selection preserves the original log text. This is the same
  runner-redacted stored tail/output that the web uses; it never fetches a raw
  runner file or introduces a new endpoint.
- StepLog resolves the parent through `loadTask` and `taskView`, within the
  current-roster checked read transaction used by Task. Tasks remain team-visible.
  The controller confirmed this on 2026-11-25: the negative cases are an absent
  or unreadable parent and revoked membership, not a creator-only read rule.
- No new GET route: the existing `/api/v1/steps/{id}/log` perf record remains.
  The existing chat size exemption increases by the measured authorization and
  regression-test lines, with its reason updated.

## Copy

All web strings are copied unchanged (only `%s` becomes Foundation's `%@`).
`native.step.log_tail` = “Last lines of the log”, disclosure label: **approved
by Luna, 2026-11-25**, delivered by the controller in message
`9e9de3e8-cb73-4bfd-9e2b-0c04d16fe3dd`. Also marked at its view call site.
There are no open copy questions. No whole-log or Copy action was added.

## Test-first evidence

Before implementation:

```
swift test --package-path native/apple --filter StoppedWorkTests
```

Failed: `TaskPause.canRetry`, `StoppedReason`, and `StoppedWorkActions` did not
exist. The tests were written first for the reviewed words, local stop time,
creator/termination rules, Needs you leads and the 409 response.

```
GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/chat -run TestStepLogTaskVisibility -count=1
```

Failed: `missing_task` and `missing_project` each returned `private log` after
Task refused the parent. After implementation, all four cases passed.

```
swift test --package-path native/apple --filter 'StoppedWorkTests|PausedTests'
```

Passed initially: 16 tests, including request paths/bearer, Resume's exact connection and
pause revision, bounded log and retained redaction marker.

Final edge tests first failed (three issues) for optional triage.reason, a
step-less direction lead, and Retry on a blocked review. After correction,
`swift test --package-path native/apple --filter 'StoppedWorkTests|PausedTests'`
passed all 18 tests. The final full native gate passed 217 tests.

## Deliberate guard mutations

Each mutation was restored immediately after its targeted test failed.

| Mutation | Command | Result |
| --- | --- | --- |
| Ignore parent task and taskView errors in StepLog | Go command above | Failed `missing_task`, `missing_project`: leaked tail |
| Ignore CurrentPerson refusal in StepLog | Go command above | Failed `revoked_member`: leaked tail |
| Return wrong words for all reason codes | `swift test --package-path native/apple --filter StoppedWorkTests` | Failed 72 expectations, including every reviewed reason and stopped lead |
| Remove creator predicate from canRetry | Same Swift command | Failed non-creator retry assertion |
| Remove terminated predicate from canRetry | Same Swift command | Failed unterminated-step retry assertion |
| Return success for 409 not_retryable | Same Swift command | Failed reviewed conflict-message assertion |
| Remove log byte bound | Same Swift command | Failed 32 KiB assertion |
| Remove runner predicate from Resume matching | Same Swift command | Failed connection identity / request assertions |

## Gates and captures

- `native/scripts/check-native.sh`: passed string/schema/differential checks,
  217 Swift tests in 26 suites (one existing known issue), Mac build and iPhone
  Simulator build. Repeated after visual/UTF-8 refinements and the controller
  follow-up for character wrapping and content-sized log height. The recaptured
  iPhone stopped screen shows complete branch/error lines with no empty fixed
  log area; the Mac capture shows all four lines aligned at the top left.
- `GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make build`:
  Linux build plus the Make target's Darwin runner cross-build passed.
- `make fmt-check spacing budget migration-check` with the Go 1.26.11
  GOROOT/bin prepended to PATH: passed (budget after its measured adjustment).
- Staticcheck v0.7.0: installed as a host executable, then run with
  `GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 staticcheck
  -tags browser,perf,testbuild ./...`: passed. `make staticcheck` with GOOS set
  tries to execute a Linux tool on macOS, so the host tool is necessary.
- `make gitleaks`: passed, no leaks.
- Local `make build`, `make vet`, `make govulncheck`, `make test`, and `make perf`
  hit the existing macOS toolproxy `unix.O_PATH` build error. The broad test
  run also reported unavailable runner-install fixtures, a 15-minute thin
  runner test timeout, and browser failures because Chromium is absent (147
  browser tests failed). These are not treated as passes or suppressed; Linux
  hub CI is the gate. Perf's screen/boot tests themselves ran.
- Targeted Go authorization/paused tests passed after mutation restoration.

The isolated simulator is named `Equipo Stopped Work`. Both platforms use
`StoppedWorkFixture`, compiled only in Debug, with an in-memory account and
an offline transport at fixture.invalid. It never reads saved credentials,
contacts a server, or bypasses authentication. The Mac fixture disables its
updater so a previously downloaded published app cannot replace the debug
build during capture; normal app launches retain their updater. `EQUIPO_STOPPED_FIXTURE=stopped`
and `paused` select the two task states. Debug's stopped fixture expands the
real log disclosure so the capture includes the actual bounded log view.

Mac screen recording is unavailable on this host; the debug fixture captures
its own actual NSWindow content using AppKit's cacheDisplay. It does not render
another mockup or read another app. `EQUIPO_FIXTURE_CAPTURE` names the PNG path.

Screenshots are saved in the audit site's `build/slice1` directory:
`iphone-stopped.png`, `iphone-paused.png`, `mac-stopped.png`, `mac-paused.png`.
Post-commit `python3 scripts/runner-dead-references.py`: passed, 2,719 text
files, 3,228 matches, zero failures. Push uses the requested normal
`agent-tools/push.sh <worktree> "native stopped work" origin native/stopped-work`.
Hub verdict is read with
`AMADAN_HOME="$HOME/.amadan-claude-agent" amadan ci status oficina/equipo -branch
native/stopped-work -json` redirected to a scratch JSON file; the final handoff
reports that verdict. No merge, deploy or release.

## Fable review follow-up (2026-11-25)

The controller requested changes to `a0dbde6a`, before slice 2 proceeds.
Mac settings now use the default browser through `NSWorkspace.open`, with a
fixed-path allowlist and an injected-opener test. iPhone retains Safari; its
presentation is owned by the signed-in tab container, so a disappearing pause
cannot dismiss the page. This supersedes the original Mac WebKit choice above.

AppKit's report/thinking hosts now measure their SwiftUI content after layout
changes, shift sibling content and subsequent rows by the height difference,
and preserve the person's scroll position. A real-window test grows and
shrinks content after mounting. Debug captures use the actual conversation:
Resume arrives after a delayed connections response; Try again calls the fake
endpoint and displays its failure. The next message remains below the report.

Needs-you reasons offer Retry for a failed, terminated last step, creator only.
Recover uses the web's failed `machine_removed`, not-terminated, creator guards
and `POST /tasks/{id}/recover`. The held lead splits already-worded text at its
first colon. Resume reloads its connection and pause revision after refusal.
Run now returns reviewed failure words to the action view instead of swallowing
errors. Logs distinguish offline, malformed answers and other read failures.
Step details are one combined accessibility element; log disclosure is separate.
Both progress indicators have existing reviewed labels. Only `work.recover`
was added to copy, unchanged from the reviewed web entry and checked by parity.

Test-first commands:

- `swift test --package-path native/apple --filter StoppedWorkReviewTests`:
  failed for absent Recover, log-error mapping and browser opener support.
- `swift test --package-path native/apple --filter ResizingHostTests`:
  failed because the resizing host did not exist.
- `swift test --package-path native/apple --filter
  'ResizingHostTests|StoppedWorkReviewTests|StoppedWorkTests|PausedTests'`:
  passed 30 tests after implementation.

The review mutations each use
`swift test --package-path native/apple --filter StoppedWorkReviewTests`.
The mutation runner restores the original source in a `finally` block and
requires an actual expectation failure, not a compilation failure.

All 14 review mutations failed assertions and were restored:

| Removed or changed guard | Result |
| --- | --- |
| Needs-you retry creator (including review_blocked) | Non-creator retry assertion failed |
| Needs-you retry termination | Unterminated-step assertion failed |
| Update runner creator | Settings-path assertion failed |
| Raise budget creator (both branches) | Settings-path assertion failed |
| Resume creator | Resume-step assertion failed |
| no_further_changes mapping | Reason assertion failed |
| machine_removed unterminated branch | Recovery/tone assertion failed |
| Moving, stopping, copy-hold suppression | Transitional-task assertions failed |
| Triage restricted to rebasing only | Retrying/rechecking/waiting assertions failed |
| Resume spend.unknown match | Connection assertion failed |
| Resume local-id match | Connection assertion failed |
| Resume provider match | Connection assertion failed |
| Non-409 retry errors treated as success | Reviewed failure-message assertion failed |
| Held deadline condition | Deadline lead assertion failed |

The first full gate found a timing assumption in the new resizing test: its
fixed 200 ms wait was too short under the full parallel suite. The test now
waits for each measured height with a bounded deadline, before changing the
next state. The runtime resizing code did not change for this correction.

Final follow-up gate: `native/scripts/check-native.sh` passed 229 tests in 28
suites (one pre-existing known issue), 206 parity strings, Mac build and iPhone
Simulator build. The two actual AppKit conversation captures were inspected:
`site/build/slice1/mac-conversation-resume.png` and
`site/build/slice1/mac-conversation-retry-failed.png`. The following message
stays below the enlarged report in both. No server code changed in this delta;
Linux hub CI remains the final gate, reported with the pushed SHA.

## Release follow-up, 2026-11-25

Branch `native/stopped-work-followups` starts at landed main
`94a3684e135674998b6337edf11aa0e717f18d82` in its own physical-TMPDIR worktree.

Run now now selects the reviewed web sentence for each 409 code:
`offer_changed`, `already_running`, and `hold_bar`. All other errors use
`card.failed`. The two added catalog entries are copied byte-identically
from `internal/equipo/copy.go` and covered by the existing `api.*` parity
check. No new copy needs review. The log spinner keeps an accessibility label
without repeating the disclosure heading visibly.

Test first:
`swift test --package-path native/apple --filter StoppedWorkReviewTests`
failed with six expectation failures before the Run now change, including all
three named codes, unknown/not-retryable codes, and an unstructured 409.
After implementation, the same command passed all 16 tests. New tests also
exercise Recover's creator/reason/termination guards on both needs-you and
stopped-step paths, both settings actions for non-creators, failed Recover
responses, and an unlisted own-origin settings path (`/evil`).

Mutation command:
`python3 "$TMPDIR/stopped-followup-mutations.py"`. Each mutation runs that
same focused Swift command, requires an expectation failure (a compiler
failure does not count), and restores the source in a `finally` block.

All eight deliberate mutations failed assertions and were restored:

| Mutation | Result |
| --- | --- |
| Stopped-step Recover ignores creator | Caught |
| Needs-you Recover ignores machine_removed | Caught |
| Needs-you Recover ignores termination | Caught |
| Connect a model ignores creator | Caught |
| Check the machine ignores creator | Caught |
| Failed Recover returns success | Caught |
| Settings allowlist removed | Caught by /evil |
| Run now offer_changed uses retry sentence | Caught |

The two settings actions were mutated separately, covering the six review
findings with seven guard mutations, plus the Run now wording regression.

Release follow-up native gate:
`native/scripts/check-native.sh` passed: 234 tests in 28 suites with the
existing known issue, 208 strings matching the web, reference scan with zero
failures, Mac build, and iPhone Simulator build. No server code changed.
Post-commit reference scan and Linux hub CI are reported with the pushed SHA.
