mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-07 00:24:50 +08:00
chore: additional AI slop cleanup and enforcer wiring from sessions 1/5
Session 1 (ses_2ad65873): with_enforcer builders + 2 regression tests Session 5 (ses_2ad67e8e): continued AI slop cleanup pass — redundant comments, unused_self suppressions, unreachable! tightening Session cleanup (ses_2ad6b26c): Python placeholder centralization Workspace tests: 363+ passed, 0 failed.
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
//! LSP (Language Server Protocol) client registry for tool dispatch.
|
||||
//!
|
||||
//! Provides a stateful registry of LSP server connections, supporting
|
||||
//! the LSP tool actions: diagnostics, hover, definition, references,
|
||||
//! completion, symbols, and formatting.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@@ -62,7 +62,6 @@ pub struct McpServerState {
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
||||
/// Thread-safe registry of MCP server connections for tool dispatch.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct McpToolRegistry {
|
||||
inner: Arc<Mutex<HashMap<String, McpServerState>>>,
|
||||
@@ -82,7 +81,6 @@ impl McpToolRegistry {
|
||||
self.manager.set(manager)
|
||||
}
|
||||
|
||||
/// Register or update an MCP server connection.
|
||||
pub fn register_server(
|
||||
&self,
|
||||
server_name: &str,
|
||||
@@ -105,19 +103,16 @@ impl McpToolRegistry {
|
||||
);
|
||||
}
|
||||
|
||||
/// Get current state of an MCP server.
|
||||
pub fn get_server(&self, server_name: &str) -> Option<McpServerState> {
|
||||
let inner = self.inner.lock().expect("mcp registry lock poisoned");
|
||||
inner.get(server_name).cloned()
|
||||
}
|
||||
|
||||
/// List all registered MCP servers.
|
||||
pub fn list_servers(&self) -> Vec<McpServerState> {
|
||||
let inner = self.inner.lock().expect("mcp registry lock poisoned");
|
||||
inner.values().cloned().collect()
|
||||
}
|
||||
|
||||
/// List resources from a specific server.
|
||||
pub fn list_resources(&self, server_name: &str) -> Result<Vec<McpResourceInfo>, String> {
|
||||
let inner = self.inner.lock().expect("mcp registry lock poisoned");
|
||||
match inner.get(server_name) {
|
||||
@@ -134,7 +129,6 @@ impl McpToolRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
/// Read a specific resource from a server.
|
||||
pub fn read_resource(&self, server_name: &str, uri: &str) -> Result<McpResourceInfo, String> {
|
||||
let inner = self.inner.lock().expect("mcp registry lock poisoned");
|
||||
let state = inner
|
||||
@@ -156,7 +150,6 @@ impl McpToolRegistry {
|
||||
.ok_or_else(|| format!("resource '{}' not found on server '{}'", uri, server_name))
|
||||
}
|
||||
|
||||
/// List tools exposed by a specific server.
|
||||
pub fn list_tools(&self, server_name: &str) -> Result<Vec<McpToolInfo>, String> {
|
||||
let inner = self.inner.lock().expect("mcp registry lock poisoned");
|
||||
match inner.get(server_name) {
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
//! Permission enforcement layer that gates tool execution based on the
|
||||
//! active `PermissionPolicy`.
|
||||
//!
|
||||
//! This module provides `PermissionEnforcer` which wraps tool dispatch
|
||||
//! and validates that the active permission mode allows the requested tool
|
||||
//! before executing it.
|
||||
|
||||
use crate::permissions::{PermissionMode, PermissionOutcome, PermissionPolicy};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -34,7 +30,7 @@ impl PermissionEnforcer {
|
||||
}
|
||||
|
||||
/// Check whether a tool can be executed under the current permission policy.
|
||||
/// Uses the policy's `authorize` method with no prompter (auto-deny on prompt-required).
|
||||
/// Auto-denies when prompting is required but no prompter is provided.
|
||||
pub fn check(&self, tool_name: &str, input: &str) -> EnforcementResult {
|
||||
let outcome = self.policy.authorize(tool_name, input, None);
|
||||
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
//! In-memory task registry for sub-agent task lifecycle management.
|
||||
//!
|
||||
//! Provides create, get, list, stop, update, and output operations
|
||||
//! matching the upstream TaskCreate/TaskGet/TaskList/TaskStop/TaskUpdate/TaskOutput
|
||||
//! tool surface.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -10,7 +6,6 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Current status of a managed task.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TaskStatus {
|
||||
@@ -33,7 +28,6 @@ impl std::fmt::Display for TaskStatus {
|
||||
}
|
||||
}
|
||||
|
||||
/// A single managed task entry.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Task {
|
||||
pub task_id: String,
|
||||
@@ -47,7 +41,6 @@ pub struct Task {
|
||||
pub team_id: Option<String>,
|
||||
}
|
||||
|
||||
/// A message exchanged with a running task.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TaskMessage {
|
||||
pub role: String,
|
||||
@@ -55,7 +48,6 @@ pub struct TaskMessage {
|
||||
pub timestamp: u64,
|
||||
}
|
||||
|
||||
/// Thread-safe task registry.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct TaskRegistry {
|
||||
inner: Arc<Mutex<RegistryInner>>,
|
||||
@@ -75,13 +67,11 @@ fn now_secs() -> u64 {
|
||||
}
|
||||
|
||||
impl TaskRegistry {
|
||||
/// Create a new empty registry.
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Create a new task and return its ID.
|
||||
pub fn create(&self, prompt: &str, description: Option<&str>) -> Task {
|
||||
let mut inner = self.inner.lock().expect("registry lock poisoned");
|
||||
inner.counter += 1;
|
||||
@@ -102,13 +92,11 @@ impl TaskRegistry {
|
||||
task
|
||||
}
|
||||
|
||||
/// Look up a task by ID.
|
||||
pub fn get(&self, task_id: &str) -> Option<Task> {
|
||||
let inner = self.inner.lock().expect("registry lock poisoned");
|
||||
inner.tasks.get(task_id).cloned()
|
||||
}
|
||||
|
||||
/// List all tasks, optionally filtered by status.
|
||||
pub fn list(&self, status_filter: Option<TaskStatus>) -> Vec<Task> {
|
||||
let inner = self.inner.lock().expect("registry lock poisoned");
|
||||
inner
|
||||
@@ -119,7 +107,6 @@ impl TaskRegistry {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Mark a task as stopped.
|
||||
pub fn stop(&self, task_id: &str) -> Result<Task, String> {
|
||||
let mut inner = self.inner.lock().expect("registry lock poisoned");
|
||||
let task = inner
|
||||
@@ -142,7 +129,6 @@ impl TaskRegistry {
|
||||
Ok(task.clone())
|
||||
}
|
||||
|
||||
/// Send a message to a task, updating its state.
|
||||
pub fn update(&self, task_id: &str, message: &str) -> Result<Task, String> {
|
||||
let mut inner = self.inner.lock().expect("registry lock poisoned");
|
||||
let task = inner
|
||||
@@ -159,7 +145,6 @@ impl TaskRegistry {
|
||||
Ok(task.clone())
|
||||
}
|
||||
|
||||
/// Get the accumulated output of a task.
|
||||
pub fn output(&self, task_id: &str) -> Result<String, String> {
|
||||
let inner = self.inner.lock().expect("registry lock poisoned");
|
||||
let task = inner
|
||||
@@ -169,7 +154,6 @@ impl TaskRegistry {
|
||||
Ok(task.output.clone())
|
||||
}
|
||||
|
||||
/// Append output to a task (used by the task executor).
|
||||
pub fn append_output(&self, task_id: &str, output: &str) -> Result<(), String> {
|
||||
let mut inner = self.inner.lock().expect("registry lock poisoned");
|
||||
let task = inner
|
||||
@@ -181,7 +165,6 @@ impl TaskRegistry {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Transition a task to a new status.
|
||||
pub fn set_status(&self, task_id: &str, status: TaskStatus) -> Result<(), String> {
|
||||
let mut inner = self.inner.lock().expect("registry lock poisoned");
|
||||
let task = inner
|
||||
@@ -193,7 +176,6 @@ impl TaskRegistry {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Assign a task to a team.
|
||||
pub fn assign_team(&self, task_id: &str, team_id: &str) -> Result<(), String> {
|
||||
let mut inner = self.inner.lock().expect("registry lock poisoned");
|
||||
let task = inner
|
||||
@@ -205,20 +187,17 @@ impl TaskRegistry {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a task from the registry.
|
||||
pub fn remove(&self, task_id: &str) -> Option<Task> {
|
||||
let mut inner = self.inner.lock().expect("registry lock poisoned");
|
||||
inner.tasks.remove(task_id)
|
||||
}
|
||||
|
||||
/// Number of tasks in the registry.
|
||||
#[must_use]
|
||||
pub fn len(&self) -> usize {
|
||||
let inner = self.inner.lock().expect("registry lock poisoned");
|
||||
inner.tasks.len()
|
||||
}
|
||||
|
||||
/// Whether the registry has no tasks.
|
||||
#[must_use]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
|
||||
Reference in New Issue
Block a user