Repository navigation
mac: derive the caret context, wrap local insertions by it, announce it to the companion - #351
Merged
Merged
Conversation
…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
This was referenced Sep 14, 2026
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)
# 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
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
marked this pull request as ready for review
September 14, 2026 16:36
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)
d-q222
added a commit
that referenced
this pull request
Sep 14, 2026
Point preservedBodyEnvironments at SyntaxHighlighter.verbatimEnvironments.union(["comment"]) so verbatim*, Verbatim, BVerbatim and the rest keep byte-identical bodies. Trim the common UTF-16 prefix/suffix before insertText so a one-line change replaces only that span and an already-indented document is a no-op with no undo step. Merge origin/main (#351); reindent still uses insertText, not CaretContext.normalize, including when the caret is inside math. Ran: cd apps/mac && swift test --filter 'EditorIndentation|CommandTableTests|CaretContext' Result: Test Suite 'Selected tests' passed. Executed 41 tests, with 0 failures. EditorIndentation.reindent 560KB: best 30.283 ms, median 30.465 ms. Ran: cd apps/mac && swift test Result: Test Suite 'All tests' passed. Executed 1162 tests, with 135 tests skipped and 0 failures. Next: lane owner review. No GitHub issue number for GH-EDITOR-REINDENT, so no issue comment. Open questions: none from this review list. CARGO_TARGET_DIR does not apply; this lane is Swift in apps/mac. Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast Commit-Executor: cursor-agent cursor-grok-4.6-high-fast Lane-Owner: daniel-parent (mac-m5pro-dq222) Co-authored-by: Cursor <[email protected]>
GoKubar
pushed a commit
that referenced
this pull request
Sep 14, 2026
…im bodies untouched, one undo step (#413) * wip(editor-reindent): LaTeX-aware Re-indent Lines/Document in apps/mac Add EditorIndentation.reindent as a pure line rewriter (env nesting, document flat set, verbatim/lstlisting/minted/comment bodies, item continuation, braces, comments/escapes) plus Edit menu hooks (⌃I / Re-indent Document) as one undo step. SourceEditorView is untouched. Ran: cd apps/mac && swift test --filter 'EditorIndentationTests|EditorIndentationHostTests|EditorIndentationPerfTests|CommandTableTests' Result: Test Suite 'Selected tests' passed. Executed 29 tests, with 0 failures. EditorIndentation.reindent 560KB: best 31.180 ms, median 31.429 ms. Next: full `swift test` in apps/mac and push this lane branch. Open questions: no GitHub issue number found for GH-EDITOR-REINDENT (using this slug). Item continuation is implemented (one extra unit under \item). ⌃I chosen: not Tab, Vim does not bind it, ⌘⇧I stays Toggle Captures. Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast Commit-Executor: cursor-agent cursor-grok-4.6-high-fast Lane-Owner: daniel-parent (mac-m5pro-dq222) Co-authored-by: Cursor <[email protected]> * wip(editor-reindent): review fix-up Point preservedBodyEnvironments at SyntaxHighlighter.verbatimEnvironments.union(["comment"]) so verbatim*, Verbatim, BVerbatim and the rest keep byte-identical bodies. Trim the common UTF-16 prefix/suffix before insertText so a one-line change replaces only that span and an already-indented document is a no-op with no undo step. Merge origin/main (#351); reindent still uses insertText, not CaretContext.normalize, including when the caret is inside math. Ran: cd apps/mac && swift test --filter 'EditorIndentation|CommandTableTests|CaretContext' Result: Test Suite 'Selected tests' passed. Executed 41 tests, with 0 failures. EditorIndentation.reindent 560KB: best 30.283 ms, median 30.465 ms. Ran: cd apps/mac && swift test Result: Test Suite 'All tests' passed. Executed 1162 tests, with 135 tests skipped and 0 failures. Next: lane owner review. No GitHub issue number for GH-EDITOR-REINDENT, so no issue comment. Open questions: none from this review list. CARGO_TARGET_DIR does not apply; this lane is Swift in apps/mac. Implementation-Agent: cursor-agent cursor-grok-4.6-high-fast Commit-Executor: cursor-agent cursor-grok-4.6-high-fast Lane-Owner: daniel-parent (mac-m5pro-dq222) Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Cursor <[email protected]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Swift half of #350. 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 exactly the same bug, inserting recognised LaTeX raw wherever the caret happened to be.
Not drifting, by construction
Both halves are checked against one table,
protocol/fixtures/caret-context-v1.json, so they cannot drift from each other; that table is checked against pdflatex byscripts/caret_context_oracle.py, so neither can drift from what actually compiles.CaretContext.deriveis additionally checked againstSyntaxHighlighter— the app's existing authority on what is math and what is verbatim.testAgreesWithTheSyntaxHighlighterwalks every offset of seven documents (escaped\$, a$inside a comment, a$insideverbatim,alignednested inequation,\(…\)and$$…$$) and requires the two to agree. That is what keeps the environment lists and delimiter rules honest as either side changes, instead of leaving a second opinion to rot.SyntaxHighlightergains themode(at:)query that makes the comparison possible, built from the line-start modes it already keeps — including the nesting depth it recently gained.Insertion
Insertion.captureInsertionis deliberately separate frominsertionText: 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. The existing padding was unconditional, which:
%comment entirely when the caret is in one.testCommentInsertionKeepsTheTextInsideTheCommentpins the second.Told to the companion
The destination announced over nearby-v1 now carries
caret_context, so the iPad can say how a capture will be wrapped before it is sent.Three expectations changed, because they pinned the bug
InsertionTests—y^2approved at a mid-sentence caret was"\ny^2\n"(raw,^typeset literally, sentence split); it is now"$y^2$".zstays"z"because it carries no math marker.NearbyErrorsTests,NearbyReferenceClientTests— two whole-structDestinationcomparisons now assert the fields those tests are actually about, so an additive field does not break them again.Test run
Full
swift teston the owner's Mac, against a control run of the same base (0600747).CompletionTests.testBundledInventoryMatchesTheCompiler(a pre-existingsupported-latex.jsondrift, unrelated).Draft. Stacked on #350 (its fixture table is what these tests read).
apps/iosfollows.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu