feat(embedding,vision): candle embeddings with offline fallback, on-demand clipboard vision capture, and concurrency audit

This commit is contained in:
Riz Ashraf committed 2026-10-07 06:36:09 +01:00
1 parent 5bd8b1587a
commit e4a0fe72df
47 files changed
+6292 -3503

No files matched your search

+7 -10
View File
@@ -1,6 +1,5 @@
use clap::Parser;
use futures_util::{SinkExt, StreamExt};
use tokio::sync::mpsc;
#[derive(Parser)]
#[command(name = "mcp-memory-stub", author, version = env!("APP_VERSION"), about = "Antigravity MCP Memory Stub / Proxy", long_about = None)]
@@ -35,14 +34,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new()?;
rt.block_on(async {
let (msg_tx, msg_rx) = async_channel::bounded::<String>(100);
let (shutdown_tx, mut shutdown_rx) = mpsc::channel::<()>(1);
let (shutdown_tx, mut shutdown_rx) = tokio::sync::watch::channel(false);
tokio::spawn(async move {
let mut stdin = tokio::io::BufReader::new(tokio::io::stdin());
while let Some(msg) = mcp_stdio::read_mcp_message(&mut stdin).await {
let _ = msg_tx.send(msg).await;
}
let _ = shutdown_tx.send(()).await;
let _ = shutdown_tx.send(true);
});
let target_url = if cli.target == "http://localhost:3000" {
@@ -58,7 +57,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut retry_count = 0;
loop {
if shutdown_rx.try_recv().is_ok() {
if *shutdown_rx.borrow() {
tracing::info!("Stub shutdown requested");
break;
}
@@ -76,7 +75,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
};
let connect_result = tokio::select! {
_ = shutdown_rx.recv() => {
_ = shutdown_rx.wait_for(|&is_shutdown| is_shutdown) => {
tracing::info!("Shutdown received during connect");
break;
}
@@ -126,11 +125,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if text.len() > 1000 { "..." } else { "" }
);
use tokio::io::AsyncWriteExt;
let mut payload = Vec::with_capacity(text.len() + 1);
payload.extend_from_slice(text.as_bytes());
payload.push(b'\n');
let mut stdout = tokio::io::stdout();
let _ = stdout.write_all(&payload).await;
let _ = stdout.write_all(text.as_bytes()).await;
let _ = stdout.write_all(b"\n").await;
let _ = stdout.flush().await;
}
}
@@ -138,7 +135,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
});
tokio::select! {
_ = shutdown_rx.recv() => {
_ = shutdown_rx.wait_for(|&is_shutdown| is_shutdown) => {
tracing::info!("Shutdown received while connected");
break;
}
+15 -16
View File
@@ -15,13 +15,20 @@ fn get_stub_exe() -> std::path::PathBuf {
get_target_dir().join(format!("mcp-memory-stub{}", std::env::consts::EXE_SUFFIX))
}
fn ensure_stub_built() {
let stub_path = get_stub_exe();
if !stub_path.exists() {
let _ = std::process::Command::new("cargo")
.arg("build")
.arg("--bin")
.arg("mcp-memory-stub")
.status();
}
}
#[tokio::test]
async fn test_stub_connection_refused() {
let _ = std::process::Command::new("cargo")
.arg("build")
.arg("--bin")
.arg("mcp-memory-stub")
.status();
ensure_stub_built();
let target = "http://127.0.0.1:49999";
@@ -44,13 +51,9 @@ async fn test_stub_connection_refused() {
#[tokio::test]
async fn test_stub_handles_eof_cleanly() {
let _ = std::process::Command::new("cargo")
.arg("build")
.arg("--bin")
.arg("mcp-memory-stub")
.status();
ensure_stub_built();
let target = "http://127.0.0.1:49998";
let target = "http://127.0.0.1:4998";
let mut child = Command::new(get_stub_exe())
.arg("--target")
@@ -76,11 +79,7 @@ async fn test_stub_handles_eof_cleanly() {
#[tokio::test]
async fn test_stub_sse_fallback_failure() {
let _ = std::process::Command::new("cargo")
.arg("build")
.arg("--bin")
.arg("mcp-memory-stub")
.status();
ensure_stub_built();
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let local_addr = listener.local_addr().unwrap();