feat(tool): tambah abort_flag ke ToolCtx dan sambungkan dari session state
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
b1c0265e8c
commit
79e2bfcc9c
@@ -283,6 +283,29 @@ impl AppStateRest {
|
|||||||
lsp_manager: self.lsp_manager.clone(),
|
lsp_manager: self.lsp_manager.clone(),
|
||||||
turn_events: Some(self.turn_events.clone()),
|
turn_events: Some(self.turn_events.clone()),
|
||||||
workflow_findings: None,
|
workflow_findings: None,
|
||||||
|
abort_flag: Some(self.abort_flag.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tool_ctx_for_shares_the_session_abort_flag() {
|
||||||
|
let tmp = std::env::temp_dir().join(format!("zesdex-rest-test-{}", uuid::Uuid::new_v4()));
|
||||||
|
std::fs::create_dir_all(&tmp).unwrap();
|
||||||
|
let state = AppStateRest::new(vec![tmp.clone()], &tmp, tmp.join("memory"));
|
||||||
|
|
||||||
|
let ctx = state.tool_ctx_for(Origin::Main);
|
||||||
|
|
||||||
|
assert!(ctx.abort_flag.is_some());
|
||||||
|
assert!(std::sync::Arc::ptr_eq(
|
||||||
|
ctx.abort_flag.as_ref().unwrap(),
|
||||||
|
&state.abort_flag,
|
||||||
|
));
|
||||||
|
|
||||||
|
std::fs::remove_dir_all(&tmp).ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
@@ -56,6 +57,11 @@ pub struct ToolCtx {
|
|||||||
/// reference earlier results. `None` means "not inside a workflow" —
|
/// reference earlier results. `None` means "not inside a workflow" —
|
||||||
/// `note_finding` becomes a no-op.
|
/// `note_finding` becomes a no-op.
|
||||||
pub workflow_findings: Option<Arc<Mutex<Vec<String>>>>,
|
pub workflow_findings: Option<Arc<Mutex<Vec<String>>>>,
|
||||||
|
/// The current turn's abort flag, threaded through so tools that
|
||||||
|
/// delegate to long-running orchestration (e.g. the `hive_mind` tool)
|
||||||
|
/// can be cancelled the same way the main agent loop is. `None` when
|
||||||
|
/// no turn-level abort flag is available.
|
||||||
|
pub abort_flag: Option<Arc<AtomicBool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find which graduated checks apply to a given file path/content pair.
|
/// Find which graduated checks apply to a given file path/content pair.
|
||||||
@@ -93,6 +99,7 @@ pub struct ToolCtxBuilder {
|
|||||||
pub lsp_manager: Arc<Mutex<crate::app::lsp::LspManager>>,
|
pub lsp_manager: Arc<Mutex<crate::app::lsp::LspManager>>,
|
||||||
pub turn_events: Option<Arc<Mutex<std::collections::VecDeque<crate::app::state::runtime::TurnEvent>>>>,
|
pub turn_events: Option<Arc<Mutex<std::collections::VecDeque<crate::app::state::runtime::TurnEvent>>>>,
|
||||||
pub workflow_findings: Option<Arc<Mutex<Vec<String>>>>,
|
pub workflow_findings: Option<Arc<Mutex<Vec<String>>>>,
|
||||||
|
pub abort_flag: Option<Arc<AtomicBool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ToolCtxBuilder {
|
impl Default for ToolCtxBuilder {
|
||||||
@@ -108,6 +115,7 @@ impl Default for ToolCtxBuilder {
|
|||||||
lsp_manager: Arc::new(Mutex::new(crate::app::lsp::LspManager::new())),
|
lsp_manager: Arc::new(Mutex::new(crate::app::lsp::LspManager::new())),
|
||||||
turn_events: None,
|
turn_events: None,
|
||||||
workflow_findings: None,
|
workflow_findings: None,
|
||||||
|
abort_flag: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,6 +143,7 @@ impl ToolCtxBuilder {
|
|||||||
lsp_manager: self.lsp_manager,
|
lsp_manager: self.lsp_manager,
|
||||||
turn_events: self.turn_events,
|
turn_events: self.turn_events,
|
||||||
workflow_findings: self.workflow_findings,
|
workflow_findings: self.workflow_findings,
|
||||||
|
abort_flag: self.abort_flag,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,3 +273,14 @@ pub fn resolve_path(workspaces: &[PathBuf], rel: &str) -> Result<PathBuf> {
|
|||||||
anyhow::bail!("path '{rel}' is outside all workspace roots")
|
anyhow::bail!("path '{rel}' is outside all workspace roots")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tool_ctx_builder_defaults_abort_flag_to_none() {
|
||||||
|
let ctx = ToolCtx::builder().build();
|
||||||
|
assert!(ctx.abort_flag.is_none());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user