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).
139 lines
4.5 KiB
Rust
139 lines
4.5 KiB
Rust
//! # Zesdex Infrastructure Layer
|
|
//!
|
|
//! ALL concrete implementations of domain repository traits, application port
|
|
//! traits, and platform services. This is the outermost ring of the Clean
|
|
//! Architecture onion — it depends on `zesdex-domain` and `zesdex-application`
|
|
//! but NEVER on interface/presentation crates.
|
|
//!
|
|
//! ## Architecture
|
|
//!
|
|
//! ```text
|
|
//! src/
|
|
//! ├── lib.rs — Foundational types + re-exports
|
|
//! ├── utils.rs — CastOr, write_json_atomic, slugify
|
|
//! ├── persistence/ — Repository implementations (IAM, CMS, SQLite)
|
|
//! ├── auth/ — JWT, Argon2, OAuth loopback
|
|
//! ├── llm/ — LLM provider HTTP client
|
|
//! ├── ipc/ — Unix-socket IPC protocol
|
|
//! ├── mcp/ — Model Context Protocol bridge
|
|
//! ├── bgbash/ — Background bash job management
|
|
//! ├── tools/ — All 37 agent-invocable tools
|
|
//! ├── subagent/ — Subagent spawning & execution engine
|
|
//! ├── workflow/ — Hive-mind orchestration engine
|
|
//! ├── review/ — Post-edit auto-review subagent
|
|
//! ├── guard/ — Tool-gate access control
|
|
//! └── middleware/ — Axum HTTP middleware (auth, cors, rate-limit)
|
|
//! ```
|
|
|
|
pub mod auth;
|
|
pub mod best_practice;
|
|
pub mod bgbash;
|
|
pub mod guard;
|
|
pub mod ipc;
|
|
pub mod llm;
|
|
pub mod mcp;
|
|
pub mod middleware;
|
|
pub mod persistence;
|
|
pub mod runtime;
|
|
pub mod subagent;
|
|
pub mod tools;
|
|
pub mod utils;
|
|
pub mod workflow;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Re-exports from domain
|
|
// ---------------------------------------------------------------------------
|
|
pub use zesdex_domain::*;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Foundation types — these replace `crate::app::state::*` references
|
|
// from the legacy backend code.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
|
|
// Which kind of caller (main agent vs. subagent vs. reviewer) is
|
|
// invoking a tool, used to scope permissions and tag log/output paths.
|
|
// ---------------------------------------------------------------------------
|
|
// TurnEvent & runtime types have been moved to zesdex_domain::agent
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Tool types — needed by all tool modules
|
|
// ---------------------------------------------------------------------------
|
|
|
|
pub use tools::{GraduatedCheck, Tool, ToolCtx, ToolCtxBuilder};
|
|
|
|
// Re-export commonly needed types at the crate root
|
|
pub use zesdex_domain::core::{ChatMessage, Role, Store, ToolCallResult, UsageStats};
|
|
|
|
/// A shared, async-writable cache of directory entries, used to avoid
|
|
/// re-reading a directory every render frame.
|
|
#[derive(Clone)]
|
|
pub struct DirCache {
|
|
entries: Arc<tokio::sync::RwLock<Vec<PathBuf>>>,
|
|
}
|
|
|
|
impl DirCache {
|
|
/// Create an empty directory cache.
|
|
pub fn new() -> Self {
|
|
DirCache {
|
|
entries: Arc::new(tokio::sync::RwLock::new(Vec::new())),
|
|
}
|
|
}
|
|
|
|
/// Replace the cached directory entries.
|
|
pub async fn set(&self, paths: Vec<PathBuf>) {
|
|
let mut w = self.entries.write().await;
|
|
*w = paths;
|
|
}
|
|
}
|
|
|
|
impl Default for DirCache {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
/// A shared, whole-workspace file-path index used for `@file` mention
|
|
/// autocomplete.
|
|
#[derive(Clone)]
|
|
pub struct MentionIndex {
|
|
entries: Arc<std::sync::RwLock<Vec<String>>>,
|
|
}
|
|
|
|
impl MentionIndex {
|
|
/// Create an empty mention index.
|
|
pub fn new() -> Self {
|
|
MentionIndex {
|
|
entries: Arc::new(std::sync::RwLock::new(Vec::new())),
|
|
}
|
|
}
|
|
|
|
/// Replace the entire index with a new set of file paths.
|
|
pub fn set(&self, paths: Vec<String>) {
|
|
if let Ok(mut w) = self.entries.write() {
|
|
*w = paths;
|
|
}
|
|
}
|
|
|
|
/// Append a single file path to the index.
|
|
pub fn push(&self, path: String) {
|
|
if let Ok(mut w) = self.entries.write() {
|
|
w.push(path);
|
|
}
|
|
}
|
|
|
|
/// Return a copy of all indexed paths.
|
|
pub fn snapshot(&self) -> Vec<String> {
|
|
self.entries.read().map(|r| r.clone()).unwrap_or_default()
|
|
}
|
|
}
|
|
|
|
impl Default for MentionIndex {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|