Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(agent-tools): alias seen-chunk type, await scratch guard, allow execute_tool arg count

thinhlpge3f83b5aa810
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs
index 5f2618e1f..5fbd1829e 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/commands.rs
@@ -460,12 +460,14 @@ async fn execute_tool_inner(
match gate::resolve_decision(
tool,
&args,
- &root,
- Some(&scratch),
- &read_roots,
+ &gate::GateContext {
+ project_root: &root,
+ scratch: Some(&scratch),
+ read_roots: &read_roots,
+ hide_jan: true,
+ },
&ToolPermissions::default(),
&SessionGrants::default(),
- true,
) {
Decision::Allow => {}
Decision::HardDeny(gate::DenyReason::Hidden) => {
@@ -591,14 +593,16 @@ fn output_sink(
mod tests {
use super::*;
use serde_json::json;
+
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
- /// The output sink test's shared ledger: what was sent, tagged with call id.
- type Seen = Arc<Mutex<Vec<(u64, Option<String>, String)>>>;
static COUNTER: AtomicUsize = AtomicUsize::new(0);
+ /// Chunks recorded by [`test_sink`]: monotonic `(seq, call_id, text)`.
+ type SeenChunks = Arc<Mutex<Vec<(u64, Option<String>, String)>>>;
+
/// A temp dir standing in for the Jan data folder.
fn unique_data_folder() -> PathBuf {
let n = COUNTER.fetch_add(1, Ordering::SeqCst);
@@ -798,7 +802,7 @@ mod tests {
// "No change" instead of "Created".
// The sweep test collects every scratch in the shared temp dir; without
// this it can delete ours between the write and the assertion.
- let _guard = crate::workspace::lock_scratch_namespace();
+ let _guard = crate::workspace::lock_scratch_namespace().await;
let scratch = crate::workspace::ensure_scratch_dir(T_SCRATCH)
.await
.unwrap();
@@ -1452,7 +1456,7 @@ mod tests {
/// and what matters here is the ordering, correlation and the byte budget.
#[test]
fn the_output_sink_numbers_chunks_and_tags_them_with_the_call() {
- let seen: Seen = Arc::new(Mutex::new(Vec::new()));
+ let seen: SeenChunks = Arc::new(Mutex::new(Vec::new()));
let sink = test_sink(seen.clone(), Some("call-7".into()));
sink("one".into());
@@ -1471,7 +1475,7 @@ mod tests {
/// tool result.
#[test]
fn the_output_sink_stops_at_the_byte_cap_and_says_so() {
- let seen: Seen = Arc::new(Mutex::new(Vec::new()));
+ let seen: SeenChunks = Arc::new(Mutex::new(Vec::new()));
let sink = test_sink(seen.clone(), None);
sink("x".repeat(MAX_STREAMED_BYTES + 1));
@@ -1485,7 +1489,7 @@ mod tests {
/// Mirrors `output_sink`'s accounting without a `Channel`, which cannot be
/// constructed outside a webview.
- fn test_sink(seen: Seen, call_id: Option<String>) -> crate::tools::OutputSink {
+ fn test_sink(seen: SeenChunks, call_id: Option<String>) -> crate::tools::OutputSink {
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
use std::sync::Arc;
let seq = Arc::new(AtomicU64::new(0));