refactor: eliminate 4 Rust backend duplications (retrieval lock, cosine sim, DiscoverMode, note context)#77
Merged
Conversation
…plication The 4-service read-lock sequence (search + graph + priority + retrieval) followed by retrieval.retrieve() was written out identically in commands/retrieval.rs, commands/memory.rs, and twice inline in commands/canvas.rs. Extract it into a pub(crate) helper in commands/mod.rs. recall_relevant now calls the helper and maps RetrievalResult → RecallResult. retrieve_relevant and the two canvas context resolvers call it directly. No behavior change; all 178 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e-access logic Two places in canvas.rs both locked the knowledge_store, iterated retrieval results, called store.get_note(), truncated content to 1500 chars, and built (id, title, content) tuples — once in resolve_note_level_context and once in the note-level fallback inside resolve_twin_prompt_context. Extract the shared logic into fetch_note_contexts(). The twin fallback now calls the helper and uses a HashSet of found IDs to filter context_notes, preserving the existing behavior of excluding unfound notes from both vecs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
commands/zettelkasten.rs defined a private DiscoverMode enum with identical variants and parse() logic to the canonical services::link_discovery::DiscoverMode, then converted between them via to_service_mode(). Import the service type directly, remove the local copy and the converter function. IPC receives mode as a raw Option<String>, so no serialization contract is affected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…cosine() link_discovery.rs contained a standalone cosine_similarity() function operating on HashMap<String, f64> term vectors, identical in math to SparseTfVector::cosine_similarity() in similarity.rs. Add sparse_cosine() as a free function in similarity.rs and have link_discovery.rs import and use it. The local definition and its two call sites in link_discovery.rs are updated accordingly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fb18810 to
d09cbc8
Compare
WKJBryan
added a commit
that referenced
this pull request
Jun 9, 2026
## Release v0.1.15 ### Changes since v0.1.14 **Rust backend — deduplication refactor (PR #77)** - Extract `run_retrieval()` helper in `commands/mod.rs` to eliminate 4x duplicated lock-acquire pattern across `retrieve_relevant`, `recall_relevant`, and both canvas context resolvers - Extract `fetch_note_contexts()` helper in `commands/canvas.rs` to deduplicate note content assembly - Remove duplicate `DiscoverMode` enum from `commands/zettelkasten.rs` — now uses `services::link_discovery::DiscoverMode` directly - Consolidate `cosine_similarity` into `services/similarity.rs` as `sparse_cosine()` free function **Frontend — component refactors (PRs #78–#80)** - `BaseModal.vue`: shared modal shell replacing 7 hand-rolled overlay implementations - `useAsyncOperation` composable: eliminates repeated loading/error/try-catch/finally store boilerplate - `PanelHeader.vue` + `AsyncListState.vue`: shared panel header and loading/empty tristate for 5 sidebar panels ## Checklist - [x] `npm run release:prepare -- 0.1.15` passed (versions bumped, Cargo.lock regenerated, 8 Cargo graphs validated) - [ ] CI passes - [ ] Merged to main - [ ] `npm run release:tag -- 0.1.15` + `git push origin v0.1.15` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
Removes four distinct instances of duplicated logic in the Rust backend, all with no behavior change:
run_retrieval helper — the 4-service read-lock pattern (
search + graph + priority + retrieval) followed byretrieval.retrieve()was written out identically incommands/retrieval.rs,commands/memory.rs, and twice inline incommands/canvas.rs. Extracted to a singlepub(crate) fn run_retrieval()incommands/mod.rs.fetch_note_contexts helper — two places in
canvas.rsboth locked the knowledge store, iterated retrieval results, truncated content to 1500 chars, and built(id, title, content)tuples. Extracted to a private helper. The twin path'scontext_notesfiltering is preserved via a HashSet of found IDs.DiscoverMode enum —
commands/zettelkasten.rsdefined a privateDiscoverModewith identical variants andparse()toservices::link_discovery::DiscoverMode, then converted between them withto_service_mode(). Removed the local copy; import the service type directly (safe: IPC receives mode asOption<String>, no serialization boundary).cosine_similarity — standalone
pub fn cosine_similarity(HashMap, HashMap) -> f64inlink_discovery.rswas identical math toSparseTfVector::cosine_similarity()insimilarity.rs. Addedpub fn sparse_cosine()tosimilarity.rs;link_discovery.rsimports and uses it.Test plan
cargo test){}blocks that drop all 4 locks before returning🤖 Generated with Claude Code