mirror of
https://github.com/lWolvesl/claw-code.git
synced 2026-04-04 16:31:51 +08:00
feat: plugin hooks + tool registry + CLI integration
This commit is contained in:
@@ -2,7 +2,7 @@ mod init;
|
||||
mod input;
|
||||
mod render;
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::collections::BTreeSet;
|
||||
use std::env;
|
||||
use std::fmt::Write as _;
|
||||
use std::fs;
|
||||
@@ -1912,8 +1912,7 @@ fn build_system_prompt() -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
||||
)?)
|
||||
}
|
||||
|
||||
fn build_runtime_plugin_state(
|
||||
) -> Result<
|
||||
fn build_runtime_plugin_state() -> Result<
|
||||
(
|
||||
runtime::RuntimeFeatureConfig,
|
||||
PluginRegistry,
|
||||
@@ -1927,7 +1926,11 @@ fn build_runtime_plugin_state(
|
||||
let plugin_manager = build_plugin_manager(&cwd, &loader, &runtime_config);
|
||||
let plugin_registry = plugin_manager.plugin_registry()?;
|
||||
let tool_registry = GlobalToolRegistry::with_plugin_tools(plugin_registry.aggregated_tools()?)?;
|
||||
Ok((runtime_config.feature_config().clone(), plugin_registry, tool_registry))
|
||||
Ok((
|
||||
runtime_config.feature_config().clone(),
|
||||
plugin_registry,
|
||||
tool_registry,
|
||||
))
|
||||
}
|
||||
|
||||
fn build_plugin_manager(
|
||||
@@ -2737,12 +2740,12 @@ impl ToolExecutor for CliToolExecutor {
|
||||
}
|
||||
|
||||
fn permission_policy(mode: PermissionMode, tool_registry: &GlobalToolRegistry) -> PermissionPolicy {
|
||||
tool_registry
|
||||
.permission_specs(None)
|
||||
.into_iter()
|
||||
.fold(PermissionPolicy::new(mode), |policy, (name, required_permission)| {
|
||||
tool_registry.permission_specs(None).into_iter().fold(
|
||||
PermissionPolicy::new(mode),
|
||||
|policy, (name, required_permission)| {
|
||||
policy.with_tool_requirement(name, required_permission)
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn convert_messages(messages: &[ConversationMessage]) -> Vec<InputMessage> {
|
||||
@@ -2893,6 +2896,7 @@ mod tests {
|
||||
use runtime::{AssistantEvent, ContentBlock, ConversationMessage, MessageRole, PermissionMode};
|
||||
use serde_json::json;
|
||||
use std::path::PathBuf;
|
||||
use tools::GlobalToolRegistry;
|
||||
|
||||
#[test]
|
||||
fn defaults_to_repl_when_no_args() {
|
||||
@@ -3106,7 +3110,7 @@ mod tests {
|
||||
.into_iter()
|
||||
.map(str::to_string)
|
||||
.collect();
|
||||
let filtered = filter_tool_specs(Some(&allowed));
|
||||
let filtered = filter_tool_specs(&GlobalToolRegistry::builtin(), Some(&allowed));
|
||||
let names = filtered
|
||||
.into_iter()
|
||||
.map(|spec| spec.name)
|
||||
@@ -3140,7 +3144,7 @@ mod tests {
|
||||
assert!(help.contains("/export [file]"));
|
||||
assert!(help.contains("/session [list|switch <session-id>]"));
|
||||
assert!(help.contains(
|
||||
"/plugins [list|install <source>|enable <id>|disable <id>|uninstall <id>|update <id>]"
|
||||
"/plugins [list|install <path>|enable <name>|disable <name>|uninstall <id>|update <id>]"
|
||||
));
|
||||
assert!(help.contains("/exit"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user