Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cotabby.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@
E51FA12B690428CA431328FC /* WritingPaneView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48B95B6665109B6C6A63B42 /* WritingPaneView.swift */; };
E54F5F03E16859D5A1E3437A /* MacroController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4638C74239D1DE2DC4D87975 /* MacroController.swift */; };
E5CB34ED76BAE87E8A858112 /* WebContentFieldDetectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 210F9AD332273FE2EB3A9A01 /* WebContentFieldDetectorTests.swift */; };
E64AE96DF2A80A368FDE522D /* LlamaSuggestionEnginePrewarmTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26EF16C7439BEB156BD9FB03 /* LlamaSuggestionEnginePrewarmTests.swift */; };
E6EE3C13FA31F261CD734C69 /* DownloadOutcomeClassifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DE1975F3B5F4A70478DBF41 /* DownloadOutcomeClassifier.swift */; };
E853B9C7AF93FA595DC417B2 /* EmojiVariantResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A8414BEB7E34F57607E37FE /* EmojiVariantResolver.swift */; };
E912D4617AE1376061DF1F00 /* LanguageSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4793D4EA5D36D7E5CC216C27 /* LanguageSupportTests.swift */; };
Expand Down Expand Up @@ -696,6 +697,7 @@
24F613F0E2F7046E6532A09C /* OnboardingTemplateFeatureList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingTemplateFeatureList.swift; sourceTree = "<group>"; };
262BE2F1E97389FE8D7A5FB9 /* Cotabby.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Cotabby.app; sourceTree = BUILT_PRODUCTS_DIR; };
264CA64B2AB1611F82E5B760 /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; };
26EF16C7439BEB156BD9FB03 /* LlamaSuggestionEnginePrewarmTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LlamaSuggestionEnginePrewarmTests.swift; sourceTree = "<group>"; };
273B4DC844F79B4BE2C8910F /* FocusPollBackoffTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FocusPollBackoffTests.swift; sourceTree = "<group>"; };
27A5D63F390E9B7A7FE343FE /* SystemResourceSampler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemResourceSampler.swift; sourceTree = "<group>"; };
28B7EB84781C0ED57844585E /* OnboardingTemplateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingTemplateTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1363,6 +1365,7 @@
4793D4EA5D36D7E5CC216C27 /* LanguageSupportTests.swift */,
0CA88BB29BC8727878C99E95 /* LlamaPromptCacheHintTrackerTests.swift */,
AABCC3FD99B1824A81E665F3 /* LlamaSuggestionEngineCancellationTests.swift */,
26EF16C7439BEB156BD9FB03 /* LlamaSuggestionEnginePrewarmTests.swift */,
9030FAAB468119A0236284A6 /* LLMIOFileHandlerTests.swift */,
D8083D44ABCDCFA68A4CD497 /* MacroEngineTests.swift */,
22BE47D1DBF6C23151458836 /* MacroTriggerStateMachineTests.swift */,
Expand Down Expand Up @@ -2334,6 +2337,7 @@
E912D4617AE1376061DF1F00 /* LanguageSupportTests.swift in Sources */,
E38801433B99E65BD7E45A0E /* LlamaPromptCacheHintTrackerTests.swift in Sources */,
BE3CB85508055D159C35020A /* LlamaSuggestionEngineCancellationTests.swift in Sources */,
E64AE96DF2A80A368FDE522D /* LlamaSuggestionEnginePrewarmTests.swift in Sources */,
8429B116328C392DCA018D95 /* MacroEngineTests.swift in Sources */,
3F8CBCBCC45E377DF9ADB216 /* MacroTriggerStateMachineTests.swift in Sources */,
87806DE08881D11F2608A13D /* MarkerSelectionSynthesizerTests.swift in Sources */,
Expand Down
18 changes: 14 additions & 4 deletions Cotabby/Models/SuggestionSubsystemContracts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ protocol SuggestionGenerating: AnyObject {
/// continuous. Stateless engines may implement this as a no-op.
func resetCachedGenerationContext() async
/// Best-effort warmup hook the coordinator calls after focus arrives on an editable surface.
/// Engines that benefit from prefix caching or weight loading (Apple Foundation Models) use it
/// to prime the next request; engines that do not (llama already keeps its KV cache hot) can
/// rely on the default no-op extension. Failures are intentionally swallowed by implementations
/// because prewarming is opportunistic.
/// Apple Foundation Models primes its session here, and the llama engine prefills the new
/// field's prompt KV (a focus change destroys the previous field's native sequence, so without
/// this the first suggestion in every field pays the full cold prompt decode). Failures are
/// intentionally swallowed by implementations because prewarming is opportunistic.
func prewarm(for request: SuggestionRequest) async
}

Expand All @@ -113,6 +113,16 @@ extension SuggestionGenerating {
protocol LlamaRuntimeGenerating: AnyObject {
func generate(prompt: String, cachedPrefixBytes: Int?, options: LlamaGenerationOptions) async throws -> String
func resetPromptCache()
/// Decodes `prompt` into the native prompt cache without sampling any tokens, so the next
/// `generate` whose prompt extends this one only decodes the typed delta. Best-effort warmup:
/// callers treat failures as "no cache primed", never as a user-facing error.
func prefill(prompt: String, cachedPrefixBytes: Int?, options: LlamaGenerationOptions) async throws
}

extension LlamaRuntimeGenerating {
/// Default no-op so test fakes that only exercise the generate/cancel contract keep compiling;
/// the production manager overrides this with a real prompt prefill.
func prefill(prompt: String, cachedPrefixBytes: Int?, options: LlamaGenerationOptions) async throws {}
}

@MainActor
Expand Down
Loading