feat(ghost): integrate generator reuse for autocomplete (attempt 2)
Summary
Integrate generator reuse functionality from continuedev's GeneratorReuseManager into GhostInlineCompletionProvider. When a user types characters that match the beginning of an in-progress completion, the existing generator is reused instead of starting a new API request.
New Files
- GhostListenableGenerator.ts: Wrapper for AsyncGenerator with buffering, tee(), and cancellation support
- GhostGeneratorReuseManager.ts: Manages generator reuse logic
- Tests for both new classes (60 tests total)
Modified Files
-
GhostModel.ts: Added
streamResponse()andstreamFimResponse()methods -
HoleFiller.ts: Added
createStreamingGenerator()andextractCompletionText() -
FillInTheMiddle.ts: Added
createStreamingGenerator() - GhostInlineCompletionProvider.ts: Integrated generator reuse manager
- Updated existing tests to use streaming API
Key Features
- Generator reuse when
(pendingPrefix + pendingCompletion).startsWith(currentPrefix) - Character stripping for already-typed characters
- Streaming accumulation with multiple consumers via
tee() - Proper cancellation support
Test Results
All 137 tests pass across 6 test files.
Known Limitation
Cost tracking is not yet implemented for streaming generators. The UsageInfo return value from the generators is not captured. This can be addressed in a future enhancement.
⚠️ No Changeset found
Latest commit: e9cae121124247fe480e83da5526b02c460b44c2
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR