Extract lib.rs, inline search in memory-search hook
Create lib.rs so all binaries can share library code directly instead
of shelling out to poc-memory. memory-search now calls search::search()
and store::Store::load() in-process instead of Command::new("poc-memory").
The load-context call still shells out (needs get_group_content moved
from main.rs to a library module).
Also: add search::format_results(), deduplicate extract_query_terms.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0c15002797
commit
aa24c40a1c
5 changed files with 59 additions and 31 deletions
|
|
@ -7,6 +7,8 @@
|
|||
// Reads JSON from stdin (Claude Code UserPromptSubmit hook format),
|
||||
// outputs results for injection into the conversation.
|
||||
|
||||
use poc_memory::search;
|
||||
use poc_memory::store;
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
use std::io::{self, Read, Write};
|
||||
|
|
@ -76,24 +78,24 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
let query = extract_query_terms(prompt, 3);
|
||||
let query = search::extract_query_terms(prompt, 3);
|
||||
if query.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let output = Command::new("poc-memory")
|
||||
.args(["search", &query])
|
||||
.output();
|
||||
|
||||
let search_output = match output {
|
||||
Ok(o) if o.status.success() => String::from_utf8_lossy(&o.stdout).to_string(),
|
||||
_ => return,
|
||||
let store = match store::Store::load() {
|
||||
Ok(s) => s,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
if search_output.trim().is_empty() {
|
||||
let results = search::search(&query, &store);
|
||||
if results.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Format results like poc-memory search output
|
||||
let search_output = search::format_results(&results);
|
||||
|
||||
let cookie = fs::read_to_string(&cookie_path).unwrap_or_default().trim().to_string();
|
||||
let seen = load_seen(&state_dir, session_id);
|
||||
|
||||
|
|
@ -128,27 +130,6 @@ fn main() {
|
|||
cleanup_stale_files(&state_dir, Duration::from_secs(86400));
|
||||
}
|
||||
|
||||
fn extract_query_terms(text: &str, max_terms: usize) -> String {
|
||||
const STOP_WORDS: &[&str] = &[
|
||||
"the", "a", "an", "is", "are", "was", "were", "do", "does", "did",
|
||||
"have", "has", "had", "will", "would", "could", "should", "can",
|
||||
"may", "might", "shall", "been", "being", "to", "of", "in", "for",
|
||||
"on", "with", "at", "by", "from", "as", "but", "or", "and", "not",
|
||||
"no", "if", "then", "than", "that", "this", "it", "its", "my",
|
||||
"your", "our", "we", "you", "i", "me", "he", "she", "they", "them",
|
||||
"what", "how", "why", "when", "where", "about", "just", "let",
|
||||
"want", "tell", "show", "think", "know", "see", "look", "make",
|
||||
"get", "go", "some", "any", "all", "very", "really", "also", "too",
|
||||
"so", "up", "out", "here", "there",
|
||||
];
|
||||
|
||||
text.to_lowercase()
|
||||
.split(|c: char| !c.is_alphanumeric())
|
||||
.filter(|w| !w.is_empty() && w.len() > 2 && !STOP_WORDS.contains(w))
|
||||
.take(max_terms)
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
}
|
||||
|
||||
fn extract_key_from_line(line: &str) -> Option<String> {
|
||||
let after_bracket = line.find("] ")?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue