Seperti Claude Code: satu runtime shared, concurrency dibatasi, error subagent terisolasi (satu node gagal tidak menggagalkan cycle). - feat(runtime): global tokio runtime via OnceLock — ganti 9+ titik Runtime::new() per tool call (spawn, parallel_delegate, workflow, explore, dir_cache, daemon handler). Hemat resource, hilangkan panic path Runtime::new().expect() di daemon compaction. - fix(workflow): execute_cycle ganti try_join_all (fail-fast) → buffer_unordered(8) + isolasi error per node; node gagal di-log dan diganti [ERROR], hasil node lain tetap dipakai (Claude Code-style). - fix(parallel_delegate): spawn subagent dibatasi per batch max_parallel (tidak unbounded threads). - perf(subagent): run_agent adaptif max_tokens (800/1600/4096), temp 0.2, truncate tool output 12k, error-recovery note utk tool error berulang. - test: runtime singleton + block_on (2 test).
73 lines
2.3 KiB
Rust
73 lines
2.3 KiB
Rust
//! Update the shared directory cache by resolving each path against
|
|
//! workspaces and storing the resolved paths in `ctx.dir_cache`.
|
|
//!
|
|
//! The cache is an `Arc<RwLock<DirCache>>` shared with the TUI and
|
|
//! other components so they can read the cached listing without
|
|
//! re-scanning the filesystem.
|
|
|
|
use crate::tools::{resolve_path, ToolCtx};
|
|
use anyhow::Result;
|
|
use serde_json::{json, Value};
|
|
use std::path::PathBuf;
|
|
use tracing::{info, instrument};
|
|
|
|
/// Tool that updates the cached directory listing.
|
|
///
|
|
/// Flow: parse `paths` array → resolve each against workspaces →
|
|
/// persist resolved paths into the shared `DirCache` via an
|
|
/// async write → confirm with the entry count.
|
|
pub struct DirCacheUpdate;
|
|
|
|
impl crate::tools::Tool for DirCacheUpdate {
|
|
fn name(&self) -> &'static str {
|
|
"dir_cache_update"
|
|
}
|
|
|
|
fn description(&self) -> &'static str {
|
|
"Update the cached directory listing"
|
|
}
|
|
|
|
fn parameters(&self) -> Value {
|
|
json!({
|
|
"type": "object",
|
|
"properties": {
|
|
"paths": {
|
|
"type": "array",
|
|
"items": {"type": "string"},
|
|
"description": "New list of paths for the cache"
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
#[instrument(skip(self, ctx, args))]
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
let paths: Vec<String> = args
|
|
.get("paths")
|
|
.and_then(|v| v.as_array())
|
|
.map(|arr| {
|
|
arr.iter()
|
|
.filter_map(|v| v.as_str().map(String::from))
|
|
.collect()
|
|
})
|
|
.unwrap_or_default();
|
|
|
|
let resolved: Vec<PathBuf> = paths
|
|
.iter()
|
|
.map(|p| resolve_path(&ctx.workspaces, p))
|
|
.collect::<Result<Vec<_>>>()?;
|
|
|
|
let count = resolved.len();
|
|
info!(count, "directory cache update requested");
|
|
|
|
// Persist the resolved paths into the shared DirCache so the TUI
|
|
// and other tools can read the cached listing without re-scanning.
|
|
let dc = ctx.dir_cache.clone();
|
|
let rt = crate::runtime::runtime();
|
|
rt.block_on(async { dc.write().await.set(resolved).await });
|
|
|
|
info!(count, "directory cache updated");
|
|
Ok(format!("Directory cache updated with {} entries", count))
|
|
}
|
|
}
|