-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: consume logger + cache from @four-bytes/opencode-plugin-lib v0.2.0 (#89) #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e6b5e53
refactor: consume logger + cache from @four-bytes/opencode-plugin-lib…
four-bytes-robby f17e867
refactor: switch to JSONL logger from lib — console noise removed #89
four-bytes-robby b7f1a34
refactor: keep console logger (opencode captures it), lib provides JS…
four-bytes-robby 4dd21d5
fix: route debug logs to stderr — prevent stdout pollution #89
four-bytes-robby 52dab08
merge: sync main into feat/89-expand-plugin-lib
four-bytes-robby 2353ba6
fix: pin @four-bytes/opencode-plugin-lib to v0.2.0 tag #89
four-bytes-robby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,2 @@ | ||
| // --------------------------------------------------------------------------- | ||
| // Per-session LRU cache using Map (TTL = process lifetime) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| export class LRUCache<K, V> { | ||
| private map = new Map<K, { value: V; ts: number }>(); | ||
|
|
||
| constructor(private maxEntries: number = 1000) {} | ||
|
|
||
| get(key: K): V | undefined { | ||
| const entry = this.map.get(key); | ||
| if (!entry) return undefined; | ||
| // Refresh LRU position | ||
| this.map.delete(key); | ||
| this.map.set(key, entry); | ||
| return entry.value; | ||
| } | ||
|
|
||
| set(key: K, value: V): void { | ||
| if (this.map.has(key)) this.map.delete(key); | ||
| else if (this.map.size >= this.maxEntries) { | ||
| // Evict oldest (first key in insertion order) | ||
| const firstKey = this.map.keys().next().value; | ||
| if (firstKey !== undefined) this.map.delete(firstKey); | ||
| } | ||
| this.map.set(key, { value, ts: Date.now() }); | ||
| } | ||
|
|
||
| has(key: K): boolean { | ||
| return this.map.has(key); | ||
| } | ||
|
|
||
| clear(): void { | ||
| this.map.clear(); | ||
| } | ||
|
|
||
| get size(): number { | ||
| return this.map.size; | ||
| } | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Singleton session cache — reset on plugin init / opencode restart | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| export const sessionCache = { | ||
| embeddings: new LRUCache<string, Float32Array>(500), // text hash → embedding vector | ||
| search: new LRUCache<string, unknown[]>(200), // query+filters serialized → results | ||
| chunks: new LRUCache<string, unknown>(500), // chunk ID → chunk data | ||
| hashes: new LRUCache<string, string>(2000), // content → sha256 hex | ||
|
|
||
| reset(): void { | ||
| this.embeddings.clear(); | ||
| this.search.clear(); | ||
| this.chunks.clear(); | ||
| this.hashes.clear(); | ||
| }, | ||
| }; | ||
| // Re-exported from @four-bytes/opencode-plugin-lib | ||
| export { LRUCache, sessionCache } from "@four-bytes/opencode-plugin-lib"; | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.