Skip to content
Merged
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
23 changes: 17 additions & 6 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ sha1 = { version = "0.10", default-features = false }
sha2 = { version = "0.10", default-features = false }
similar = { version = "2", default-features = false }
strip-ansi-escapes = { version = "0.2", default-features = false }
tempfile = { version = "3", default-features = false }
termimad = { version = "0.34", default-features = false }
test-log = { version = "0.2", default-features = false, features = ["trace"] }
thiserror = { version = "2", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions crates/jp_attachment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ version.workspace = true
jp_mcp = { workspace = true }

async-trait = { workspace = true }
camino = { workspace = true }
dyn-clone = { workspace = true }
dyn-hash = { workspace = true }
linkme = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/jp_attachment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::{
error::Error,
hash::Hasher,
ops::{Deref, DerefMut},
path::Path,
};

use async_trait::async_trait;
use camino::Utf8Path;
use dyn_clone::DynClone;
use dyn_hash::DynHash;
use jp_mcp::Client;
Expand Down Expand Up @@ -77,7 +77,7 @@ pub trait Handler: std::fmt::Debug + DynClone + DynHash + Send + Sync {
/// resources from MCP servers, if needed.
async fn get(
&self,
cwd: &Path,
cwd: &Utf8Path,
mcp_client: Client,
) -> Result<Vec<Attachment>, Box<dyn Error + Send + Sync>>;
}
Expand Down
1 change: 1 addition & 0 deletions crates/jp_attachment_bear_note/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jp_attachment = { workspace = true }
jp_mcp = { workspace = true }

async-trait = { workspace = true }
camino = { workspace = true }
directories = { workspace = true }
quick-xml = { workspace = true, features = ["serialize"] }
rusqlite = { workspace = true, features = ["bundled", "array", "vtab"] }
Expand Down
16 changes: 6 additions & 10 deletions crates/jp_attachment_bear_note/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use std::{
collections::BTreeSet,
error::Error,
path::{Path, PathBuf},
rc::Rc,
};
use std::{collections::BTreeSet, error::Error, rc::Rc};

use async_trait::async_trait;
use camino::{Utf8Path, Utf8PathBuf};
use directories::BaseDirs;
use jp_attachment::{
Attachment, BoxedHandler, HANDLERS, Handler, distributed_slice, linkme, percent_decode_str,
Expand Down Expand Up @@ -135,11 +131,11 @@ impl Handler for BearNotes {

async fn get(
&self,
_: &Path,
_: &Utf8Path,
_: Client,
) -> Result<Vec<Attachment>, Box<dyn Error + Send + Sync>> {
let db = get_database_path()?;
trace!(db = %db.display(), "Connecting to Bear database.");
trace!(db = %db, "Connecting to Bear database.");
let conn = Connection::open(db)?;

let mut attachments = vec![];
Expand Down Expand Up @@ -271,7 +267,7 @@ fn get_notes(query: &Query, conn: &Connection) -> Result<Vec<Note>, Box<dyn Erro

/// Attempts to find the path to the Bear Sqlite database.
/// Assumes the standard macOS location.
fn get_database_path() -> Result<PathBuf, Box<dyn Error + Send + Sync>> {
fn get_database_path() -> Result<Utf8PathBuf, Box<dyn Error + Send + Sync>> {
let path = BaseDirs::new()
.ok_or("Could not find base directories")?
.home_dir()
Expand All @@ -281,7 +277,7 @@ fn get_database_path() -> Result<PathBuf, Box<dyn Error + Send + Sync>> {
return Err(format!("Missing Bear SQLite database at {}", path.display()).into());
}

Ok(path)
path.try_into().map_err(Into::into)
}

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion crates/jp_attachment_cmd_output/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ jp_attachment = { workspace = true }
jp_mcp = { workspace = true }

async-trait = { workspace = true }
camino = { workspace = true }
duct = { workspace = true }
quick-xml = { workspace = true, features = ["serialize"] }
serde = { workspace = true }
url = { workspace = true }

[dev-dependencies]
camino-tempfile = { workspace = true }
indexmap = { workspace = true }
indoc = { workspace = true }
tempfile = { workspace = true }
test-log = { workspace = true }
tokio = { workspace = true }

Expand Down
7 changes: 4 additions & 3 deletions crates/jp_attachment_cmd_output/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{collections::BTreeSet, error::Error, path::Path};
use std::{collections::BTreeSet, error::Error};

use async_trait::async_trait;
use camino::Utf8Path;
use jp_attachment::{
Attachment, BoxedHandler, HANDLERS, Handler, distributed_slice, linkme, percent_decode_str,
percent_encode_str, typetag,
Expand Down Expand Up @@ -103,7 +104,7 @@ impl Handler for Commands {

async fn get(
&self,
root: &Path,
root: &Utf8Path,
_: Client,
) -> Result<Vec<Attachment>, Box<dyn Error + Send + Sync>> {
let mut attachments = vec![];
Expand Down Expand Up @@ -272,7 +273,7 @@ mod tests {
.collect(),
);

let root = tempfile::tempdir().unwrap();
let root = camino_tempfile::tempdir().unwrap();
let path = root.path();
std::fs::create_dir_all(path.join("dir")).unwrap();
std::fs::write(path.join("file1"), "").unwrap();
Expand Down
3 changes: 2 additions & 1 deletion crates/jp_attachment_file_content/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jp_attachment = { workspace = true }
jp_mcp = { workspace = true }

async-trait = { workspace = true }
camino = { workspace = true }
crossbeam-channel = { workspace = true, features = ["std"] }
glob = { workspace = true }
ignore = { workspace = true }
Expand All @@ -26,8 +27,8 @@ tracing = { workspace = true }
url = { workspace = true }

[dev-dependencies]
camino-tempfile = { workspace = true }
indexmap = { workspace = true }
tempfile = { workspace = true }
test-log = { workspace = true }

[lints]
Expand Down
21 changes: 12 additions & 9 deletions crates/jp_attachment_file_content/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{borrow::Cow, collections::BTreeSet, error::Error, fs, path::Path};
use std::{borrow::Cow, collections::BTreeSet, error::Error, fs};

use async_trait::async_trait;
use camino::Utf8Path;
use glob::Pattern;
use ignore::{WalkBuilder, WalkState, overrides::OverrideBuilder};
use jp_attachment::{
Expand Down Expand Up @@ -76,7 +77,7 @@ impl Handler for FileContent {

async fn get(
&self,
cwd: &Path,
cwd: &Utf8Path,
_: Client,
) -> Result<Vec<Attachment>, Box<dyn Error + Send + Sync>> {
debug!(id = self.scheme(), "Getting file attachment contents.");
Expand Down Expand Up @@ -159,7 +160,9 @@ impl Handler for FileContent {
let Ok(entry) = entry else {
return WalkState::Continue;
};
let path = entry.path();
let Some(path) = Utf8Path::from_path(entry.path()) else {
return WalkState::Continue;
};
if path.is_dir() {
return WalkState::Continue;
}
Expand All @@ -181,7 +184,7 @@ impl Handler for FileContent {
}

/// If the pattern is a directory, add it recursively.
fn sanitize_pattern<'a>(mut pattern: &'a str, cwd: &Path) -> Cow<'a, str> {
fn sanitize_pattern<'a>(mut pattern: &'a str, cwd: &Utf8Path) -> Cow<'a, str> {
if pattern.starts_with('/') {
pattern = &pattern[1..];
}
Expand All @@ -197,10 +200,10 @@ fn sanitize_pattern<'a>(mut pattern: &'a str, cwd: &Path) -> Cow<'a, str> {
}
}

fn build_attachment(path: &Path, cwd: &Path) -> Option<Attachment> {
fn build_attachment(path: &Utf8Path, cwd: &Utf8Path) -> Option<Attachment> {
let Ok(rel) = path.strip_prefix(cwd) else {
warn!(
path = %path.display(),
path = %path,
"Attachment path outside of working directory, skipping."
);

Expand All @@ -210,13 +213,13 @@ fn build_attachment(path: &Path, cwd: &Path) -> Option<Attachment> {
let content = match fs::read_to_string(path) {
Ok(content) => content,
Err(error) => {
warn!(path = %rel.display(), %error, "Failed to read attachment.");
warn!(path = %rel, %error, "Failed to read attachment.");
return None;
}
};

Some(Attachment {
source: rel.to_string_lossy().to_string(),
source: rel.to_string(),
content,
..Default::default()
})
Expand Down Expand Up @@ -285,9 +288,9 @@ mod pat {

#[cfg(test)]
mod tests {
use camino_tempfile::tempdir;
use glob::Pattern;
use indexmap::IndexMap;
use tempfile::tempdir;
use url::Url;

use super::*;
Expand Down
1 change: 1 addition & 0 deletions crates/jp_attachment_http_content/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jp_attachment = { workspace = true }
jp_mcp = { workspace = true }

async-trait = { workspace = true }
camino = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
tracing = { workspace = true }
Expand Down
Loading
Loading