Skip to content

ios: show where a capture will land and how it will be wrapped - #352

Merged
GoKubar merged 4 commits into
mainfrom
agent/claude/caret-context-ios
Sep 14, 2026
Merged

GoKubar merged 4 commits into
mainfrom
agent/claude/caret-context-ios

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

The companion half of #350 / #351.

NearbyWire.Destination decodes the caret_context the Mac now announces, and the reference Destination section shows its one-line label:

  • already inside $…$ — no delimiters added
  • tabular cell — inline math only
  • verbatim — inserted literally
  • text — formulas wrapped in \[ … \] or $ … $

so it is clear before sending what will happen to the transcription.

The iPad deliberately does not derive this

It only displays it. The Mac derives it and the bridge enforces it. A companion that computed its own answer would be a second opinion that could disagree with the insertion — which is the exact failure mode this whole change exists to remove. capture_submit therefore gains nothing.

A Mac that predates the field omits the key and everything behaves as before; testAMacWithoutACaretContextStillPairs pins that rather than assuming it.

Left to the lane that owns the file

The one-screen capture flow's destination chip (CaptureView.swift:127) is the natural home for this label, and it is where a user would actually see it before tapping Send. That file belongs to another lane right now (canvas layout, insert button, auto-insert, camera focus), so I stayed out of it and out of PairingScanner.swift. Noted on issue #2 for whoever picks it up — it should be a one-line addition given the label already exists on NearbyWire.CaretContext.

⚠️ Not verified by a compiler

This Mac's Xcode is missing CoreSimulator.framework, so xcodebuild fails at plug-in load for any iOS destination — simulator, generic/platform=iOS, or -sdk iphoneos26.5 alike:

Library not loaded: /Library/Developer/PrivateFrameworks/CoreSimulator.framework/…
A required plugin failed to load. … try running 'xcodebuild -runFirstLaunch'

xcrun simctl fails the same way, with Install Failed: Authorization is required to install the packages. Fixing it needs an admin install on the owner's machine, which is not mine to run.

What I did verify: apps/ios/Packages/FlashTeXPadKit builds clean with swift build — and that is where the NearbyWire change actually lives, including NearbyWire.CaretContext and the new Destination.caretContext field.

What is unverified: the three app-target edits — one if let + Text row in ContentView.swift, the caret_context dictionary in the test FakeMac, and DestinationCaretContextTests. They need xcodebuild … -runFirstLaunch (admin) and then the normal simulator test run before this merges. Please do not merge this one on my say-so.


Draft. Stacked on #351.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 3 commits September 14, 2026 03:38
…nforce it on insertion

The destination pin says where a capture lands, never what kind of place that
is, so the recogniser guesses by wrapping: it returns `$x^2$` because that is
what a formula usually looks like. At a caret already inside `$…$` that writes
`Let $a + $x^2$ + b$ hold.`, which pdflatex rejects. Same shape of failure for
`\[…\]` inside `equation`, and for display math in a `tabular` cell.

`caret::derive` reads the caret's mode out of the pinned snapshot — text,
inline/display math, verbatim, comment, plus the enclosing environments and
whether amsmath is loaded — and reduces it to one `wrap` policy. That value
rides to the provider in `destination_context.caret_context` (with a plain
English `instruction` sentence, which a model obeys far more reliably than an
enum) and is used again when the proposal becomes an edit. One value decides
both, so the prompt and the insertion cannot disagree.

`caret::normalize` runs at conversion, not at insertion, so the reviewer
approves the exact text that will land. It peels delimiters the model added at
a math caret, wraps undelimited mathematics at a text caret, demotes display
math to inline in a tabular cell, and refuses rather than writing something
unbalanced. Every success goes through one gate that re-checks the result, so a
bug in the wrapping logic degrades to a refusal a reviewer sees instead of to
LaTeX that will not compile.

Undelimited output is only treated as mathematics when it carries a structural
signal (`^`, `_`, `\frac`, a Greek letter, …). Without one there is no reliable
way to tell `x = y` from `<F>`, and guessing wrong corrupts the document
silently, so it is left exactly as it came.

Prose recognised at a math caret goes in `\text{…}` when amsmath is loaded and
`\mbox{…}` when it is not: `\text` without amsmath is itself a pdflatex error.

Verified with pdflatex rather than assumed. `scripts/caret_context_oracle.py`
compiles all 22 cases of the new fixture table both ways; 13 of the rules turn
a real pdflatex error into a clean compile, and every normalised insertion
compiles. Worth recording: flashtex-render accepts 15 of those broken naive
insertions without a diagnostic, so the engine cannot catch this class of bug
and pdflatex is the oracle. That divergence deserves its own issue.

Implementation-Agent: claude-opus-5 (linux-primary, ipadmath lane)
Commit-Executor: claude-opus-5 (direct git, Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…it to the companion

The Swift half of the rules in `crates/bridge/src/caret.rs`. Two halves exist
because two paths insert: the bridge prepares the edit when one is attached,
and this shell prepares it when one is not — and the bridge-less path had the
same bug, inserting recognised LaTeX raw wherever the caret happened to be.

Both halves are checked against one table,
`protocol/fixtures/caret-context-v1.json`, so they cannot drift from each other,
and that table is checked against pdflatex so neither can drift from what
actually compiles.

`CaretContext.derive` is also checked against `SyntaxHighlighter`, which is the
app's existing authority on what is math and what is verbatim: for every offset
of seven documents the two must agree. That is what keeps the environment lists
and delimiter rules honest as either side changes, instead of leaving a second
opinion to rot. `SyntaxHighlighter` gains the `mode(at:)` query that makes the
comparison possible, built from the line-start modes it already keeps.

`Insertion.captureInsertion` is deliberately separate from `insertionText`:
scaffolding inserts (`\input{…}`) are the app's own text, not recognised
output, and are not second-guessed. It also pads only display insertions with
newlines — padding an inline one breaks a sentence across lines, and padding
one inside a `%` comment pushes the text out of the comment entirely.

The destination announced over nearby-v1 now carries `caret_context`, so a
companion can say how a capture will be wrapped before it is sent.

Three existing expectations changed because the behaviour they pinned was the
bug: `y^2` approved at a mid-sentence caret is now `$y^2$` rather than a raw
`\ny^2\n`, and two whole-struct `Destination` comparisons now assert the fields
those tests are actually about.

Implementation-Agent: claude-opus-5 (linux-primary, ipadmath lane)
Commit-Executor: claude-opus-5 (direct git, Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
`NearbyWire.Destination` decodes the `caret_context` the Mac now announces, and
the reference Destination section shows its one-line label — "already inside $…$,
no delimiters added", "tabular cell — inline math only", "verbatim — inserted
literally" — so it is clear before sending what will happen to the transcription.

The iPad only displays this. The Mac derives it and the bridge enforces it; a
companion that guessed would be a second opinion that could disagree with the
insertion, which is the failure this whole change exists to remove.

A Mac that predates the field omits the key and everything behaves as before;
that case is tested rather than assumed.

The one-screen capture flow's destination chip (`CaptureView.swift`) is the
natural home for this label and is left alone: that file belongs to another
lane right now. Noted on issue #2 for whoever picks it up.

Not verified by a compiler: this Mac's Xcode is missing
CoreSimulator.framework, so xcodebuild cannot build any iOS target, with or
without a simulator destination. `Packages/FlashTeXPadKit` (which is where the
`NearbyWire` change lives) does build. See the PR body.

Implementation-Agent: claude-opus-5 (linux-primary, ipadmath lane)
Commit-Executor: claude-opus-5 (direct git, Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar pushed a commit that referenced this pull request Sep 14, 2026
… 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 pushed a commit that referenced this pull request Sep 14, 2026
… 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 pushed a commit that referenced this pull request Sep 14, 2026
… 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 changed the base branch from agent/claude/caret-context-mac to main September 14, 2026 16:36
# Conflicts:
#	apps/mac/Sources/FlashTeXMac/SyntaxHighlighter.swift
GoKubar pushed a commit that referenced this pull request Sep 14, 2026
… 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 marked this pull request as ready for review September 14, 2026 16:52
@GoKubar
GoKubar merged commit 8a57903 into main Sep 14, 2026
10 of 21 checks passed
GoKubar pushed a commit that referenced this pull request Sep 14, 2026
… 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 deleted the agent/claude/caret-context-ios branch September 14, 2026 17:21
GoKubar added a commit that referenced this pull request Sep 16, 2026
… shows (#403)

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)

Co-authored-by: Claude Opus 5 <[email protected]>
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