Skip to content

ios+mac: insert a capture from the iPad, by approving the proposal it shows - #403

Merged
GoKubar merged 1 commit into
mainfrom
agent/claude/companion-insert
Sep 16, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/claude/companion-insert

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Owner feedback item 3, after using the capture flow on a real iPad:

You should add an auto-insert button (no need to go through a prompt)

Today a capture goes iPad → Mac, converts, and the proposed LaTeX then sits in
the Mac's review sheet until someone walks over and clicks Insert there.
That walk is the entire cost of the feature: you draw a formula on the iPad and
then you get up.

The iPad is not missing information. Since the additive capture_status
message it already polls the Mac, and already displays the proposal
(capture_status_ack.latex) read-only on the Captures screen. What it could
not do was say yes.

What this adds

  • An Insert button on the iPad, directly beneath the proposal it is
    showing, with the destination's wrapping spelled out above it ("Will land in:
    text — formulas wrapped in \[ … \] or $ … $"). It appears only once there
    is a proposal to read.
  • capture_insert / capture_insert_ack, an additive nearby-v1 message —
    protocol/proposals/nearby-v1-companion-insert.md. Nothing frozen changes;
    a peer that does not implement it answers unknown_type.

Tapping it routes into the same code the Captures inspector's own Insert
button uses — insertCaptureFromInbox → approveBridgeProposal /
approveProposal. There are no new insertion semantics: the bridge still
prepares the edit and checks revision, source SHA-256, scalar boundaries and
removed text; the Mac still applies exactly one undoable edit; the edit ledger
still refuses a second edit for the same capture id, so a retried tap after a
dropped reply is idempotent.

How this squares with "Never inserted automatically"

FlashTeXProtocol/Capture.swift states the invariant flatly, and transfer-v1
requires the Mac to "require explicit review approval for the currently
displayed
proposal and target". I read that as two claims, not one:

  1. a human decides, and
  2. the thing they approve is the proposal they were shown.

The obvious implementation of "auto-insert" — a flag on capture_submit
meaning apply this once you have converted it — satisfies neither. At submit
time the proposal does not exist, so nobody has read the LaTeX that would enter
the document. That design was considered and rejected, and the proposal doc
says so in §2 so it does not get added later by someone reading only the
feature request.

What the feedback asks to remove is the second confirmation, not the first.
So this moves the review surface to the iPad rather than deleting the review,
and enforces claim 2 mechanically: the request carries
approved_latex_sha256, the SHA-256 of the exact text the companion displayed.
The proposal text itself is never sent. The Mac inserts its own journaled
proposal, and only when that proposal is the one the digest names.

That matters because transfer-v1 has paths that legitimately replace a proposal
between one read and the next — a dependency-fingerprint mismatch returns
proposal_context_stale, and the UI "must discard approval and explicitly
offer conversion again". Without the digest, such a re-conversion would be
inserted unread and this really would be an automatic insertion. With it, the
tap is refused with proposal_changed and the iPad says "read it again, then
Insert".

A side effect worth stating: because only a digest travels, a hostile or buggy
companion cannot author document content. The most it can do is approve, or
fail to approve, a proposal the Mac already holds.

Ownership is the existing capture_status rule — honoured only for a capture
this pairing submitted and whose receipt has been sent.

Wrapping (feedback item 4)

Built on #350 → #351 → #352. Wrapping is the Mac's and the bridge's, derived
from the destination's caret_context and enforced at insertion, which is what
makes a one-tap insert safe to use: a formula approved for a caret in running
text arrives wrapped for that destination instead of being pasted raw into
$…$.

Tests

  • apps/mac/Tests/FlashTeXMacTests/NearbyCaptureInsertTests.swift — the digest
    is identical on both ends (plus a known vector); wire spelling; and the
    refusals that carry the safety property: unknown capture, no proposal,
    approving text the Mac does not hold (proposal_changed, nothing prepared),
    then the same capture inserting correctly once the real text is approved, and
    a second tap changing nothing.
  • apps/ios/FlashTeXPadTests/CompanionInsertTests.swift — against the loopback
    FakeMac (extended to model the Mac's digest check): the button does not
    exist before a proposal; Insert sends exactly one approval naming the
    displayed text by digest and the row becomes inserted; a Mac that
    re-converted refuses; a Mac predating the message says so and points at the
    Mac-side path; no link sends nothing.

Not changed

The Captures inspector's Insert button, the review sheet and Reject are all
untouched and remain available. Approving on the Mac still works exactly as
before.

@GoKubar
GoKubar force-pushed the agent/claude/companion-insert branch 3 times, most recently from 61ef711 to 2a0668a Compare September 14, 2026 16:45
… shows

The owner's feedback after using this on a real iPad: "You should add an
auto-insert button (no need to go through a prompt)". Today a capture goes
iPad -> Mac, converts, and then the LaTeX sits in the Mac's review sheet
waiting for someone to walk over and click Insert. The iPad already polls
`capture_status` and already displays the proposal; what it could not do was
say yes.

This adds the additive nearby-v1 `capture_insert` message and an Insert
button beside the proposal on the Captures screen. Tapping it approves the
text on screen and the Mac applies it through the very same path the Captures
inspector's own Insert button uses — `insertCaptureFromInbox` ->
`approveBridgeProposal` — so there are no new insertion semantics: the bridge
still prepares the edit, the Mac still applies exactly one undoable edit
against a matching revision and hash, and the ledger still refuses a second
edit for the same capture id.

Reconciling it with "Never inserted automatically" (transfer-v1): the
invariant is not "a human taps something", it is that approval names the
*currently displayed* proposal. So the request carries
`approved_latex_sha256`, the SHA-256 of the text the companion actually
showed, and the proposal text itself is never sent. The Mac inserts its own
journaled proposal and only when that proposal is the one the digest names;
a proposal re-converted in between is refused with `proposal_changed` and the
companion is told to read the new text first. A flag on `capture_submit`
meaning "apply this once converted" was considered and rejected: at submit
time no proposal exists, so nobody could have read it. What the feedback asks
to remove is the second confirmation, not the first.

Wrapping comes from the caret context (#350/#351/#352), enforced at
insertion, which is what makes a one-tap insert safe: a formula approved for
a caret in running text arrives wrapped for that destination rather than
pasted raw into `$...$`.

Ownership is the `capture_status` rule: honoured only for a capture this
pairing submitted and whose receipt was sent. A Mac that predates the message
answers `unknown_type`, which the iPad reports instead of retrying, and the
Mac-side Insert button is untouched.

Implementation-Agent: Claude Opus 5 (lane ipad-unblock, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
@GoKubar
GoKubar force-pushed the agent/claude/companion-insert branch from 2a0668a to a5fe302 Compare September 14, 2026 16:52
@GoKubar
GoKubar marked this pull request as ready for review September 14, 2026 17:20
GoKubar pushed a commit that referenced this pull request Sep 15, 2026
… gaps (ordering only, on #476) (#411)

* wip(#76): failing tests for Problems list bucket order

Add DiagnosticsPanelTests that pin errors-then-warnings-then-gaps
across two documents, Copy Diagnostics walking that order, and
⌘⌥] starting on the first author error rather than an earlier gap.

What was run: `swift test --filter` of the three new methods in
apps/mac. Result: Executed 3 tests, with 7 failures (0 unexpected)
in 0.238 seconds. Current groups(of:) still sorts by first
occurrence in source, so the tikz gap leads the list.

Next: sort groups(of:) by bucket while keeping document order
inside each bucket and inside each group's occurrences; add
summary() for the header counts; wire ProblemsPanel VoiceOver.

Open questions: whether ProblemsPanel.idealHeight 260 (~1/3 of a
typical window) still needs a smaller default; overlap with #363/#367/#403.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#76): sort Problems groups by bucket and show header counts

groups(of:) lists author errors, then warnings, then FlashTeX gaps,
keeping document order inside each bucket and inside each group's
occurrences. result.diagnostics is not reordered. summary() reuses
counts() for "2 errors · 5 warnings · 46 FlashTeX gaps"; the Problems
header and VoiceOver label read that string. Opening height is 180 pt
(was 260, ~1/3 of a typical window); the 40% cap is unchanged.

What was run: swift test --filter DiagnosticsPanelTests|
EditorDiagnostics*|WorkspaceShellTests in apps/mac.
Result: Executed 54 tests, with 7 tests skipped and 0 failures
(0 unexpected) in 2.107 seconds.

Next: full `swift test` from apps/mac; overlap check; push.

Open questions: none on ordering/header. Existing AppStorage values
of 260 remain until the user resizes.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

* wip(#76): restore coloured Problems header count chips

Restore the three SF Symbol count labels (errors red, warnings orange,
gaps puzzle-piece secondary) including zeros so an all-gap document still
shows the error column. VoiceOver uses summary() once via .ignore on the
chips; the panel stays .contain so the list remains accessible.
DiagnosticsListView caption matches. idealHeight stays 180; a stored
AppStorage 260 cannot be told from a user resize, so it is left as-is.

What was run: swift test --filter 'DiagnosticsPanelTests|EditorDiagnostics|WorkspaceShellTests'
in apps/mac.
Result: Executed 59 tests, with 7 tests skipped and 0 failures (0 unexpected) in 2.112 seconds.

Next: daniel-parent review / PR.

Open questions: none on the header. AppStorage 260 left as-is.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: Cursor <[email protected]>
@GoKubar
GoKubar merged commit 6719e00 into main Sep 16, 2026
31 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant