Send FM trailing context, length hint, per-app tone, bigger prefix budget#344
Merged
Conversation
FuJacob
added a commit
that referenced
this pull request
May 28, 2026
- Apply the maxSuffixCharacters cap to trailing text inside the FM renderer instead of relying on upstream truncation that does not exist; protects a long-document caret-at-top from pushing the entire document body through the 4096-token context window. - Remove terminal emulators from the code-editor tone bucket so a prose context in a terminal stops getting code-shaped completions. - Remove Cursor's opaque ToDesktop bundle ID since prefix-matching cannot survive Cursor updates; leave a note explaining why.
6f1afe5 to
3a129d0
Compare
- Apply the maxSuffixCharacters cap to trailing text inside the FM renderer instead of relying on upstream truncation that does not exist; protects a long-document caret-at-top from pushing the entire document body through the 4096-token context window. - Remove terminal emulators from the code-editor tone bucket so a prose context in a terminal stops getting code-shaped completions. - Remove Cursor's opaque ToDesktop bundle ID since prefix-matching cannot survive Cursor updates; leave a note explaining why.
5aece19 to
2238567
Compare
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.
Summary
Four prompt-side improvements bundled because they all live in the FM prompt channel and were all measurable against the eval suite from the parent stack:
Text after the caret:section so the model can bridge into existing text rather than overwrite it.Return only the next 7 to 12 words.) is reintroduced on the prompt channel — not instructions, so it does not bust the cached session prefix from PR 2. Apple's model lands cleaner stopping points with a natural-language cue than withmaximumResponseTokensalone.SuggestionConfigurationgains FM-only prefix caps (2500 chars / 150 words) so Apple's larger context can take more surrounding sentences without crowding instructions. Llama keeps its existing tighter window.Stacked on
refactor/fm-positive-frame. Use the eval suite from the head of the stack to compare mid-word truncation, mid-line bridging, and category drift.Validation
xcodebuild -project Cotabby.xcodeproj -scheme Cotabby -destination 'platform=macOS' build CODE_SIGNING_ALLOWED=NO→
** BUILD SUCCEEDED **xcodebuild test ... -only-testing:CotabbyTests/FoundationModelPromptRendererTests -only-testing:CotabbyTests/SuggestionRequestFactoryTests -only-testing:CotabbyTests/SuggestionEngineRouterTests→
Executed 33 tests, with 0 failures (0 unexpected)swiftlint lint --quiet→ no violations.Manual: focus a real text field in Mail / Slack / Xcode / Safari and verify the diagnostics panel shows the matching per-app tone hint and (where applicable) the trailing-text section.
Linked issues
Refs the FM-quality investigation.
Risk / rollout notes
SuggestionConfigurationgained two new memberwise fields (maxPrefixWordsFoundationModel,maxPrefixCharactersFoundationModel). Production uses.standard, which is updated; the two explicit-constructor test sites were updated alongside.SuggestionRequestFactory.truncatedPromptPrefixnow takes an optionalengine:parameter (defaulting to.llamaOpenSource) so external callers stay source-compatible. The internal call frombuildRequestand the coordinator's clipboard-filter call both pass the active engine explicitly.FoundationModelPromptRenderer; the absence of a hint is the safe default.test_promptPreviewassertion was flipped — and a new assertion ensures the cue still does NOT appear in instructions (so the session-cache key remains stable across word-count preset changes... wait, those should invalidate; correction: word-count preset only changes the prompt, not instructions, so cache stays warm).Greptile Summary
This PR enriches the Foundation Models prompt channel with four coordinated improvements: trailing-context injection (bounded by
maxSuffixCharacters), a natural-language length hint on the per-request prompt, per-app tone cues keyed by bundle-ID prefix, and a separate, larger prefix budget (2500 chars / 150 words) for the FM path.maxSuffixCharactersbefore being sent, closing the previously identified gap where a caret at the top of a long document would flood the 4096-token context window.SuggestionConfigurationgains two new FM-specific prefix cap fields; all existing explicit constructors in tests were updated alongside, andtruncatedPromptPrefixselects the right budget via an engine switch with a backward-compatible default.com.apple.mobilesms) references an iOS-only bundle ID that will not match macOS Messages.Confidence Score: 5/5
Safe to merge — all prompt-channel changes are additive and the most significant correctness fix (trailing-text overflow) is properly addressed.
The trailing-text cap is correctly applied before injection, the engine-aware prefix budget switch is clean with a backward-compatible default, and the tone-hint dictionary's safe-default-on-no-match design means unknown or mismatched bundle IDs degrade gracefully. The one dead entry (com.apple.mobilesms) silently misses macOS Messages but causes no harm. Tests cover the new code paths thoroughly.
FoundationModelPromptRenderer.swift — the chatBundlePrefixes list contains one iOS-only entry that will not fire on macOS.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Coord as SuggestionCoordinator participant Factory as SuggestionRequestFactory participant FM as FoundationModelPromptRenderer participant Apple as Apple FM API Coord->>Factory: truncatedPromptPrefix(engine: .appleIntelligence) Note over Factory: Selects maxPrefixCharactersFoundationModel=2500<br/>maxPrefixWordsFoundationModel=150 Factory-->>Coord: bounded prefixText Coord->>Factory: buildRequest(context, settings, configuration) Factory->>Factory: truncatedPromptPrefix(engine: appleIntelligence) Factory-->>Coord: SuggestionRequestBuildResult Coord->>FM: promptPreview(for: request) FM->>FM: sessionInstructions(for: request) Note over FM: Role + output contract + examples<br/>(no length hint, no tone hint) FM->>FM: prompt(for: request) Note over FM: appToneHint(bundleIdentifier)<br/>+ Text before caret (prefixText)<br/>+ Text after caret (trailingText, capped at maxSuffixCharacters)<br/>+ Write only the next continuation fragment.<br/>+ completionLengthInstruction FM-->>Coord: instructions + prompt Coord->>Apple: generate(instructions, prompt) Apple-->>Coord: completion textReviews (4): Last reviewed commit: "Address Greptile review on #344" | Re-trigger Greptile