Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .cargo/audit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# replacements require upstream API changes across the platform, font, HTTP,
# and archive layers; keep the exact list here so every new warning still
# fails CI. Recheck on every UI release and no later than 2027-02-12.
# Chrono's notice is maintenance-only. The current MCP and schema libraries
# still depend on it, even if Synapse replaces its own date formatting.
ignore = [
"RUSTSEC-2024-0384", # instant, through the UI executor
"RUSTSEC-2024-0436", # paste, through the macOS graphics bindings
Expand All @@ -32,6 +34,7 @@ ignore = [
"RUSTSEC-2026-0372", # zvariant_derive, Linux platform graph
"RUSTSEC-2026-0441", # pin-utils, through async-std
"RUSTSEC-2026-0459", # bundled SQLite; restore rejects adjacent WAL state
"RUSTSEC-2026-0543", # chrono, through MCP and schema libraries
]

[output]
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ synapse

`synapse connect` connects installed tools. Restart them afterward. Use `synapse status` for text status; the same binary provides the CLI and MCP server. The Linux build has no desktop UI dependency and uses the encrypted vault instead of macOS Keychain. Release downloads contain the macOS app and Windows installer; Linux users build from source.

For a VS Code devcontainer, run `synapse devcontainer setup` from the host checkout
on macOS or Linux and paste the generated settings into your container config.
The container's first startup registers the connection and uses OpenSSH to
access the host's project memory. See [Devcontainer setup](docs/devcontainer.md).

See the [installation guide](https://wess.io/synapse/docs/install/) for CLI setup and connection troubleshooting.

## What you can share
Expand Down
2 changes: 1 addition & 1 deletion crates/synapse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "synapse"
# Bumping this on main is the release trigger. Keep it in step with
# crates/synapsecore, which is where `synapse version` reads its number from.
version = "1.19.3"
version = "1.19.4"
edition.workspace = true
description = "Local memory and scoped credentials for developer tools"

Expand Down
10 changes: 5 additions & 5 deletions crates/synapsecore/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/synapsecore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ name = "synapsecore"
# Keep this in step with crates/synapse: `synapse version` reads the version of
# the crate that holds the command, and the two ship as one product. Only the
# desktop crate's version triggers the release workflow.
version = "1.19.3"
version = "1.19.4"
edition = "2024"
description = "Memory, credentials, and the command surface for Synapse, without a window"

Expand Down
7 changes: 4 additions & 3 deletions crates/synapsecore/src/brain/rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(super) const CLOSE: char = '\u{3}';
pub(super) enum Reach<'a> {
/// What a session in this project can see: global memory, this project's,
/// and nothing superseded.
Visible(&'a str),
Visible(&'a str, bool),
/// Every stored memory, for a person browsing their own store.
Everything,
}
Expand Down Expand Up @@ -193,7 +193,8 @@ async fn list(
reach: Reach<'_>,
) -> Result<Vec<(i64, Option<String>)>> {
let filter = match reach {
Reach::Visible(_) => format!("AND {}", super::store::VISIBLE),
Reach::Visible(_, true) => format!("AND {}", super::store::VISIBLE),
Reach::Visible(_, false) => format!("AND {}", super::store::PROJECT),
Reach::Everything => String::new(),
};
let sql = format!(
Expand All @@ -203,7 +204,7 @@ async fn list(
ORDER BY bm25({table}, {WEIGHTS}) LIMIT ?"
);
let mut query = sqlx::query_as::<_, (i64, Option<String>)>(&sql).bind(expression);
if let Reach::Visible(project) = reach {
if let Reach::Visible(project, _) = reach {
query = query.bind(project);
}
query
Expand Down
24 changes: 18 additions & 6 deletions crates/synapsecore/src/brain/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ impl Brain {
offset: u32,
budget: Option<Optimization>,
project: Option<&Path>,
) -> Result<ReadResponse> {
let project = project
.map(crate::brain::projectkey)
.transpose()?
.flatten()
.unwrap_or_default();
self.readkeyed(id, offset, budget, &project, true).await
}

pub(crate) async fn readkeyed(
&self,
id: i64,
offset: u32,
budget: Option<Optimization>,
project: &str,
globals: bool,
) -> Result<ReadResponse> {
anyhow::ensure!(id > 0, "memory id must be positive");
let configured = self.settings().await?;
Expand All @@ -69,11 +85,6 @@ impl Brain {
.characterbudget
.unwrap_or(PAGEBYTES)
.min(PAGEBYTES);
let project = project
.map(crate::brain::projectkey)
.transpose()?
.flatten()
.unwrap_or_default();
// slice in SQLite so a small read never loads the entire body into Rust.
// blobs preserve embedded NULs; SQLite's text length stops at the first one.
let row = sqlx::query_as::<_, PageRow>(
Expand All @@ -84,13 +95,14 @@ impl Brain {
length(CAST(memory.body AS BLOB)) AS total \
FROM memory JOIN memorymeta meta ON meta.memoryid = memory.rowid \
WHERE memory.rowid = ?1 AND meta.superseded = 0 AND \
(meta.scope = 'global' OR (meta.scope = 'project' AND meta.project = ?2))",
((?6 AND meta.scope = 'global') OR (meta.scope = 'project' AND meta.project = ?2))",
)
.bind(id)
.bind(project)
.bind(i64::from(offset))
.bind(bytes as i64)
.bind(SOURCEBYTES as i64)
.bind(globals)
.fetch_optional(&self.pool)
.await
.context("could not read memory page")?;
Expand Down
96 changes: 82 additions & 14 deletions crates/synapsecore/src/brain/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub(crate) const COLUMNS: &str = "memory.rowid AS id, memory.body, memory.source
/// Restricts a read to memory a session in `project` can see: everything
/// global, plus that project's own, and nothing that has been replaced.
pub(super) const VISIBLE: &str = "(meta.scope = 'global' OR (meta.scope = 'project' AND meta.project = ?)) AND meta.superseded = 0";
pub(super) const PROJECT: &str =
"meta.scope = 'project' AND meta.project = ? AND meta.superseded = 0";

#[derive(Clone)]
pub struct Brain {
Expand All @@ -27,12 +29,17 @@ pub struct Brain {

impl Brain {
pub async fn open(path: impl AsRef<Path>) -> Result<Self> {
let path = path.as_ref().to_path_buf();
let brain = Self::from(crate::database::open(&path).await?, path)?;
let brain = Self::openkeyed(path.as_ref()).await?;
brain.rekey().await?;
Ok(brain)
}

/// Opens the store with project identities as recorded, without reading
/// checkouts and refiling memories.
pub(crate) async fn openkeyed(path: &Path) -> Result<Self> {
Self::from(crate::database::open(path).await?, path.to_path_buf())
}

/// Open only to report on what is stored. See [`crate::database::glance`].
pub async fn glance(path: impl AsRef<Path>) -> Result<Self> {
let path = path.as_ref().to_path_buf();
Expand Down Expand Up @@ -104,10 +111,45 @@ impl Brain {
(false, Some(project)) => crate::brain::evidence::capture(project, sources)?,
(false, None) => anyhow::bail!("repository evidence needs a project path"),
};
let project = scope.project(project)?;
self.rememberkeyed(body, source, scope, &project, supersedes, &evidence, false)
.await
}

#[cfg(unix)]
pub(crate) async fn rememberproject(
&self,
body: &str,
source: Option<&str>,
project: &str,
supersedes: &[i64],
) -> Result<(i64, Vec<i64>)> {
self.rememberkeyed(
body,
source,
MemoryScope::Project,
project,
supersedes,
&[],
true,
)
.await
}

#[allow(clippy::too_many_arguments)]
async fn rememberkeyed(
&self,
body: &str,
source: Option<&str>,
scope: MemoryScope,
project: &str,
supersedes: &[i64],
evidence: &[crate::brain::evidence::Captured],
projectonly: bool,
) -> Result<(i64, Vec<i64>)> {
let body = stored(body)?;
let body = body.as_str();
let source = sourced(source);
let project = scope.project(project)?;

let created = SystemTime::now()
.duration_since(UNIX_EPOCH)
Expand Down Expand Up @@ -136,16 +178,25 @@ impl Brain {
for source in evidence {
sqlx::query("INSERT INTO memoryevidence(memoryid, path, digest) VALUES (?, ?, ?)")
.bind(id)
.bind(source.path)
.bind(source.digest)
.bind(&source.path)
.bind(&source.digest)
.execute(&mut *transaction)
.await?;
}
let mut replaced = Vec::new();
for old in supersedes {
let done = sqlx::query("UPDATE memorymeta SET superseded = ? WHERE memoryid = ?")
.bind(id)
.bind(old)
let mut update = sqlx::query(if projectonly {
"UPDATE memorymeta SET superseded = ? WHERE memoryid = ? AND memoryid != ? \
AND scope = 'project' AND project = ? AND superseded = 0"
} else {
"UPDATE memorymeta SET superseded = ? WHERE memoryid = ?"
})
.bind(id)
.bind(old);
if projectonly {
update = update.bind(id).bind(project);
}
let done = update
.execute(&mut *transaction)
.await
.with_context(|| format!("could not supersede memory #{old}"))?;
Expand Down Expand Up @@ -272,15 +323,31 @@ impl Brain {
budget: Option<Optimization>,
project: Option<&Path>,
) -> Result<(Settings, Vec<Memory>, usize)> {
let configured = self.settings().await?;
let settings = Settings::from(configured.optimization.constrained(budget));
let project = project
.map(crate::brain::projectkey)
.transpose()?
.flatten()
.unwrap_or_default();
self.recallkeyed(query, limit, budget, &project, true).await
}

pub(crate) async fn recallkeyed(
&self,
query: &str,
limit: u32,
budget: Option<Optimization>,
project: &str,
globals: bool,
) -> Result<(Settings, Vec<Memory>, usize)> {
let configured = self.settings().await?;
let settings = Settings::from(configured.optimization.constrained(budget));
let found = self
.searchscoped(query, limit.clamp(1, settings.resultlimit), &project)
.searchscoped(
query,
limit.clamp(1, settings.resultlimit),
project,
globals,
)
.await?;
let excerpts = found
.iter()
Expand Down Expand Up @@ -436,6 +503,7 @@ impl Brain {
query: &str,
limit: u32,
project: &str,
globals: bool,
) -> Result<Vec<(Memory, Option<rank::Hit>)>> {
let limit = limit.clamp(1, 200);
// A query of nothing but function words asks for nothing in particular,
Expand All @@ -447,7 +515,7 @@ impl Brain {
&self.pool,
&kept,
limit as usize,
Reach::Visible(project),
Reach::Visible(project, globals),
Purpose::Recall,
)
.await?;
Expand All @@ -462,12 +530,12 @@ impl Brain {
// those. Filtering and ordering in the outer join instead lets the
// planner drive from the full-text table, which means reading every
// memory and sorting all of them to answer for the newest handful.
let filter = if globals { VISIBLE } else { PROJECT };
sqlx::query_as::<_, Memory>(&format!(
"SELECT {COLUMNS} \
FROM memorymeta meta JOIN memory ON memory.rowid = meta.memoryid \
WHERE meta.memoryid IN (\
SELECT memoryid FROM memorymeta \
WHERE (scope = 'global' OR (scope = 'project' AND project = ?)) AND superseded = 0 \
SELECT memoryid FROM memorymeta meta WHERE {filter} \
ORDER BY created DESC, memoryid DESC LIMIT ?) \
ORDER BY meta.created DESC, meta.memoryid DESC"
))
Expand Down
2 changes: 2 additions & 0 deletions crates/synapsecore/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod backend;
mod command;
mod connect;
#[cfg(unix)]
mod devcontainer;
mod doctor;
mod drift;
mod editor;
Expand Down
Loading
Loading