mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-15 23:32:46 +00:00
parent
f596705f7f
commit
211aa97537
5 changed files with 1393 additions and 30 deletions
414
run.json
414
run.json
File diff suppressed because one or more lines are too long
698
stages/006-simplify_opus@1/diff.patch
Normal file
698
stages/006-simplify_opus@1/diff.patch
Normal file
|
|
@ -0,0 +1,698 @@
|
|||
diff --git a/apps/fabro-web/app/components/stage-insights-sidebar.tsx b/apps/fabro-web/app/components/stage-insights-sidebar.tsx
|
||||
index 135f1dd72..1b534c181 100644
|
||||
--- a/apps/fabro-web/app/components/stage-insights-sidebar.tsx
|
||||
+++ b/apps/fabro-web/app/components/stage-insights-sidebar.tsx
|
||||
@@ -283,13 +283,18 @@ function todoStatusVisual(status: TodoStatus): { Icon: IconType; color: string;
|
||||
return { Icon: XCircleIcon, color: "text-fg-muted", srLabel: "Deleted" };
|
||||
case TodoStatus.PENDING:
|
||||
default:
|
||||
- return { Icon: TodoPendingIcon, color: "text-fg-muted", srLabel: "Pending" };
|
||||
+ return { Icon: EmptyCircleIcon, color: "text-fg-muted", srLabel: "Pending" };
|
||||
}
|
||||
}
|
||||
|
||||
-/** Empty circle for pending todos (matches Tailwind sizing). */
|
||||
-function TodoPendingIcon({ className }: { className?: string }) {
|
||||
- return <span className={`inline-block rounded-full border border-current ${className ?? ""}`} />;
|
||||
+/** Empty circle for pending/available states (matches Tailwind sizing). */
|
||||
+function EmptyCircleIcon({ className }: { className?: string }) {
|
||||
+ return (
|
||||
+ <span
|
||||
+ className={`inline-block rounded-full border border-current ${className ?? ""}`}
|
||||
+ aria-hidden="true"
|
||||
+ />
|
||||
+ );
|
||||
}
|
||||
|
||||
// ---------- Context window ----------
|
||||
@@ -529,7 +534,7 @@ function AgentToolsSection({ tools }: { tools: AgentToolSummary[] }) {
|
||||
{tool.invoked ? (
|
||||
<CheckCircleIcon className="size-3.5 shrink-0 text-mint" aria-label="Invoked" />
|
||||
) : (
|
||||
- <ToolAvailableIcon className="size-3.5 shrink-0 text-fg-muted" />
|
||||
+ <EmptyCircleIcon className="size-3.5 shrink-0 text-fg-muted" />
|
||||
)}
|
||||
<span className={nameClass}>{tool.name}</span>
|
||||
<span className="font-mono text-[10px] tabular-nums text-fg-muted">
|
||||
@@ -564,10 +569,6 @@ function toolSourceLabel(source: AgentToolSummary["source"]): string {
|
||||
}
|
||||
}
|
||||
|
||||
-function ToolAvailableIcon({ className }: { className?: string }) {
|
||||
- return <span className={`inline-block rounded-full border border-current ${className ?? ""}`} aria-hidden="true" />;
|
||||
-}
|
||||
-
|
||||
// ---------- MCPs ----------
|
||||
|
||||
function McpSection({ servers }: { servers: McpServerProjection[] }) {
|
||||
diff --git a/lib/crates/fabro-agent/src/cli.rs b/lib/crates/fabro-agent/src/cli.rs
|
||||
index b736fdb3f..e3e874803 100644
|
||||
--- a/lib/crates/fabro-agent/src/cli.rs
|
||||
+++ b/lib/crates/fabro-agent/src/cli.rs
|
||||
@@ -93,7 +93,7 @@ pub enum OutputFormat {
|
||||
Json,
|
||||
}
|
||||
|
||||
-pub use fabro_types::PermissionLevel;
|
||||
+pub use fabro_types::{AgentToolCategory, PermissionLevel};
|
||||
|
||||
impl AgentArgs {
|
||||
/// Fill `None` fields from settings.toml values, then hardcoded defaults.
|
||||
@@ -155,6 +155,8 @@ fn build_tool_approval(
|
||||
"Allow {} ({category})? [y]es / [n]o / [a]lways: ",
|
||||
styles.bold.apply_to(tool_name),
|
||||
);
|
||||
+ // `AgentToolCategory` derives strum::Display so it renders as the
|
||||
+ // canonical snake_case label (e.g. "read", "write").
|
||||
std::io::stderr().flush().ok();
|
||||
|
||||
let mut input = String::new();
|
||||
@@ -166,7 +168,7 @@ fn build_tool_approval(
|
||||
"y" | "yes" => Ok(()),
|
||||
"a" | "always" => {
|
||||
let mut lvl = level.lock().expect("permission lock poisoned");
|
||||
- *lvl = if category == "write" {
|
||||
+ *lvl = if category == AgentToolCategory::Write {
|
||||
PermissionLevel::ReadWrite
|
||||
} else {
|
||||
PermissionLevel::Full
|
||||
@@ -816,62 +818,98 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn tool_category_read_tools() {
|
||||
- assert_eq!(tool_category("read_file"), "read");
|
||||
- assert_eq!(tool_category("read_many_files"), "read");
|
||||
- assert_eq!(tool_category("grep"), "read");
|
||||
- assert_eq!(tool_category("glob"), "read");
|
||||
- assert_eq!(tool_category("list_dir"), "read");
|
||||
+ assert_eq!(tool_category("read_file"), AgentToolCategory::Read);
|
||||
+ assert_eq!(tool_category("read_many_files"), AgentToolCategory::Read);
|
||||
+ assert_eq!(tool_category("grep"), AgentToolCategory::Read);
|
||||
+ assert_eq!(tool_category("glob"), AgentToolCategory::Read);
|
||||
+ assert_eq!(tool_category("list_dir"), AgentToolCategory::Read);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_category_write_tools() {
|
||||
- assert_eq!(tool_category("write_file"), "write");
|
||||
- assert_eq!(tool_category("edit_file"), "write");
|
||||
- assert_eq!(tool_category("apply_patch"), "write");
|
||||
+ assert_eq!(tool_category("write_file"), AgentToolCategory::Write);
|
||||
+ assert_eq!(tool_category("edit_file"), AgentToolCategory::Write);
|
||||
+ assert_eq!(tool_category("apply_patch"), AgentToolCategory::Write);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_category_shell() {
|
||||
- assert_eq!(tool_category("shell"), "shell");
|
||||
+ assert_eq!(tool_category("shell"), AgentToolCategory::Shell);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_category_subagent_tools() {
|
||||
- assert_eq!(tool_category("spawn_agent"), "subagent");
|
||||
- assert_eq!(tool_category("send_input"), "subagent");
|
||||
- assert_eq!(tool_category("wait"), "subagent");
|
||||
- assert_eq!(tool_category("close_agent"), "subagent");
|
||||
+ assert_eq!(tool_category("spawn_agent"), AgentToolCategory::Subagent);
|
||||
+ assert_eq!(tool_category("send_input"), AgentToolCategory::Subagent);
|
||||
+ assert_eq!(tool_category("wait"), AgentToolCategory::Subagent);
|
||||
+ assert_eq!(tool_category("close_agent"), AgentToolCategory::Subagent);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_category_unknown_defaults_to_shell() {
|
||||
- assert_eq!(tool_category("some_random_tool"), "shell");
|
||||
+ assert_eq!(tool_category("some_random_tool"), AgentToolCategory::Shell);
|
||||
}
|
||||
|
||||
// is_auto_approved tests
|
||||
|
||||
#[test]
|
||||
fn is_auto_approved_read_only() {
|
||||
- assert!(is_auto_approved(PermissionLevel::ReadOnly, "read"));
|
||||
- assert!(is_auto_approved(PermissionLevel::ReadOnly, "subagent"));
|
||||
- assert!(!is_auto_approved(PermissionLevel::ReadOnly, "write"));
|
||||
- assert!(!is_auto_approved(PermissionLevel::ReadOnly, "shell"));
|
||||
+ assert!(is_auto_approved(
|
||||
+ PermissionLevel::ReadOnly,
|
||||
+ AgentToolCategory::Read
|
||||
+ ));
|
||||
+ assert!(is_auto_approved(
|
||||
+ PermissionLevel::ReadOnly,
|
||||
+ AgentToolCategory::Subagent
|
||||
+ ));
|
||||
+ assert!(!is_auto_approved(
|
||||
+ PermissionLevel::ReadOnly,
|
||||
+ AgentToolCategory::Write
|
||||
+ ));
|
||||
+ assert!(!is_auto_approved(
|
||||
+ PermissionLevel::ReadOnly,
|
||||
+ AgentToolCategory::Shell
|
||||
+ ));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_auto_approved_read_write() {
|
||||
- assert!(is_auto_approved(PermissionLevel::ReadWrite, "read"));
|
||||
- assert!(is_auto_approved(PermissionLevel::ReadWrite, "subagent"));
|
||||
- assert!(is_auto_approved(PermissionLevel::ReadWrite, "write"));
|
||||
- assert!(!is_auto_approved(PermissionLevel::ReadWrite, "shell"));
|
||||
+ assert!(is_auto_approved(
|
||||
+ PermissionLevel::ReadWrite,
|
||||
+ AgentToolCategory::Read
|
||||
+ ));
|
||||
+ assert!(is_auto_approved(
|
||||
+ PermissionLevel::ReadWrite,
|
||||
+ AgentToolCategory::Subagent
|
||||
+ ));
|
||||
+ assert!(is_auto_approved(
|
||||
+ PermissionLevel::ReadWrite,
|
||||
+ AgentToolCategory::Write
|
||||
+ ));
|
||||
+ assert!(!is_auto_approved(
|
||||
+ PermissionLevel::ReadWrite,
|
||||
+ AgentToolCategory::Shell
|
||||
+ ));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_auto_approved_full() {
|
||||
- assert!(is_auto_approved(PermissionLevel::Full, "read"));
|
||||
- assert!(is_auto_approved(PermissionLevel::Full, "subagent"));
|
||||
- assert!(is_auto_approved(PermissionLevel::Full, "write"));
|
||||
- assert!(is_auto_approved(PermissionLevel::Full, "shell"));
|
||||
+ assert!(is_auto_approved(
|
||||
+ PermissionLevel::Full,
|
||||
+ AgentToolCategory::Read
|
||||
+ ));
|
||||
+ assert!(is_auto_approved(
|
||||
+ PermissionLevel::Full,
|
||||
+ AgentToolCategory::Subagent
|
||||
+ ));
|
||||
+ assert!(is_auto_approved(
|
||||
+ PermissionLevel::Full,
|
||||
+ AgentToolCategory::Write
|
||||
+ ));
|
||||
+ assert!(is_auto_approved(
|
||||
+ PermissionLevel::Full,
|
||||
+ AgentToolCategory::Shell
|
||||
+ ));
|
||||
}
|
||||
|
||||
// build_tool_approval non-interactive tests
|
||||
diff --git a/lib/crates/fabro-agent/src/context_window.rs b/lib/crates/fabro-agent/src/context_window.rs
|
||||
index da8da9d72..88dcc616b 100644
|
||||
--- a/lib/crates/fabro-agent/src/context_window.rs
|
||||
+++ b/lib/crates/fabro-agent/src/context_window.rs
|
||||
@@ -382,7 +382,8 @@ mod tests {
|
||||
let tools = vec![
|
||||
tool("read_file", ToolSource::Native),
|
||||
tool("mcp__server__search", ToolSource::Mcp {
|
||||
- server_name: "server".to_string(),
|
||||
+ server_name: "server".to_string(),
|
||||
+ original_name: "search".to_string(),
|
||||
}),
|
||||
tool("use_skill", ToolSource::Skill),
|
||||
];
|
||||
diff --git a/lib/crates/fabro-agent/src/mcp_integration.rs b/lib/crates/fabro-agent/src/mcp_integration.rs
|
||||
index e839ef4e3..65787f448 100644
|
||||
--- a/lib/crates/fabro-agent/src/mcp_integration.rs
|
||||
+++ b/lib/crates/fabro-agent/src/mcp_integration.rs
|
||||
@@ -15,6 +15,7 @@ pub fn make_mcp_tools(manager: &Arc<McpConnectionManager>) -> Vec<RegisteredTool
|
||||
let mgr = Arc::clone(manager);
|
||||
let name = qualified_name.clone();
|
||||
let server_name = info.server_name.clone();
|
||||
+ let original_name = info.original_tool_name.clone();
|
||||
let tool_timeout = std::time::Duration::from_mins(2);
|
||||
|
||||
RegisteredTool {
|
||||
@@ -35,7 +36,10 @@ pub fn make_mcp_tools(manager: &Arc<McpConnectionManager>) -> Vec<RegisteredTool
|
||||
call_result_to_string(&result)
|
||||
})
|
||||
}),
|
||||
- source: ToolSource::Mcp { server_name },
|
||||
+ source: ToolSource::Mcp {
|
||||
+ server_name,
|
||||
+ original_name,
|
||||
+ },
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
diff --git a/lib/crates/fabro-agent/src/session.rs b/lib/crates/fabro-agent/src/session.rs
|
||||
index 8a8fcf189..f6921361b 100644
|
||||
--- a/lib/crates/fabro-agent/src/session.rs
|
||||
+++ b/lib/crates/fabro-agent/src/session.rs
|
||||
@@ -18,8 +18,8 @@ use fabro_mcp::config::{McpServerSettings, McpTransport};
|
||||
use fabro_mcp::connection_manager::McpConnectionManager;
|
||||
use fabro_model::{AgentProfileKind, Catalog, ModelRef, Speed};
|
||||
use fabro_types::{
|
||||
- PermissionLevel, Principal, SessionMessage, SessionRecord, StageContextWindowProjection,
|
||||
- SteeringMessage,
|
||||
+ AgentToolSummary, PermissionLevel, Principal, SessionMessage, SessionRecord,
|
||||
+ StageContextWindowProjection, SteeringMessage,
|
||||
};
|
||||
use futures::StreamExt;
|
||||
use tokio::sync::{Mutex as AsyncMutex, Notify, broadcast};
|
||||
@@ -501,9 +501,32 @@ impl Session {
|
||||
self.config.permission_level
|
||||
}
|
||||
|
||||
+ /// Effective tool list the model is exposed to after provider-profile
|
||||
+ /// setup, optional registrations, MCP integration, and access-policy
|
||||
+ /// filtering. This is the same path used to build outbound requests.
|
||||
#[must_use]
|
||||
- pub fn available_tools(&self) -> Vec<ToolDefinitionWithSource> {
|
||||
- self.effective_tools()
|
||||
+ pub fn effective_tools(&self) -> Vec<ToolDefinitionWithSource> {
|
||||
+ self.provider_profile
|
||||
+ .tool_registry()
|
||||
+ .definitions_with_source_for_policy(
|
||||
+ self.config.tool_access_policy.as_deref(),
|
||||
+ self.config.tool_exposure_mode,
|
||||
+ )
|
||||
+ }
|
||||
+
|
||||
+ /// Public projection of `effective_tools()` for
|
||||
+ /// `StageProjection.agent_tools` and the `agent.tools.available` event.
|
||||
+ /// Sorted by name for deterministic snapshots; the underlying registry
|
||||
+ /// stores tools in a `HashMap`.
|
||||
+ #[must_use]
|
||||
+ pub fn agent_tool_summaries(&self) -> Vec<AgentToolSummary> {
|
||||
+ let mut summaries: Vec<_> = self
|
||||
+ .effective_tools()
|
||||
+ .iter()
|
||||
+ .map(ToolDefinitionWithSource::to_agent_tool_summary)
|
||||
+ .collect();
|
||||
+ summaries.sort_by(|left, right| left.name.cmp(&right.name));
|
||||
+ summaries
|
||||
}
|
||||
|
||||
/// Initialize session by discovering project docs and capturing environment
|
||||
@@ -2021,15 +2044,6 @@ impl Session {
|
||||
});
|
||||
}
|
||||
}
|
||||
-
|
||||
- fn effective_tools(&self) -> Vec<ToolDefinitionWithSource> {
|
||||
- self.provider_profile
|
||||
- .tool_registry()
|
||||
- .definitions_with_source_for_policy(
|
||||
- self.config.tool_access_policy.as_deref(),
|
||||
- self.config.tool_exposure_mode,
|
||||
- )
|
||||
- }
|
||||
}
|
||||
|
||||
const fn is_auth_error(err: &LlmError) -> bool {
|
||||
@@ -3281,7 +3295,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
- async fn available_tools_uses_same_effective_registry_filter_as_requests() {
|
||||
+ async fn effective_tools_match_request_tool_filtering() {
|
||||
let provider = Arc::new(CapturingLlmProvider::new());
|
||||
let client = make_client(provider as Arc<dyn ProviderAdapter>).await;
|
||||
let mut registry = ToolRegistry::new();
|
||||
@@ -3301,7 +3315,7 @@ mod tests {
|
||||
};
|
||||
let session = Session::new(client, profile, env, config, None);
|
||||
|
||||
- let tools = session.available_tools();
|
||||
+ let tools = session.effective_tools();
|
||||
let mut tool_names: Vec<&str> = tools
|
||||
.iter()
|
||||
.map(|tool| tool.definition.name.as_str())
|
||||
diff --git a/lib/crates/fabro-agent/src/tool_permissions.rs b/lib/crates/fabro-agent/src/tool_permissions.rs
|
||||
index b22dba945..a56d17e08 100644
|
||||
--- a/lib/crates/fabro-agent/src/tool_permissions.rs
|
||||
+++ b/lib/crates/fabro-agent/src/tool_permissions.rs
|
||||
@@ -1,25 +1,35 @@
|
||||
-use fabro_types::PermissionLevel;
|
||||
+use fabro_types::{AgentToolCategory, PermissionLevel};
|
||||
|
||||
-pub fn tool_category(name: &str) -> &'static str {
|
||||
- known_tool_category(name).unwrap_or("shell")
|
||||
-}
|
||||
-
|
||||
-pub fn known_tool_category(name: &str) -> Option<&'static str> {
|
||||
+/// Coarse access category for an exposed tool. Returns `None` for unknown
|
||||
+/// names so callers can decide whether to default (legacy CLI permission
|
||||
+/// gate) or surface a distinct "other" category (projection metadata).
|
||||
+pub fn known_tool_category(name: &str) -> Option<AgentToolCategory> {
|
||||
match name {
|
||||
- "read_file" | "read_many_files" | "grep" | "glob" | "list_dir" => Some("read"),
|
||||
- "write_file" | "edit_file" | "apply_patch" => Some("write"),
|
||||
- "shell" => Some("shell"),
|
||||
- "spawn_agent" | "send_input" | "wait" | "close_agent" => Some("subagent"),
|
||||
+ "read_file" | "read_many_files" | "grep" | "glob" | "list_dir" => {
|
||||
+ Some(AgentToolCategory::Read)
|
||||
+ }
|
||||
+ "write_file" | "edit_file" | "apply_patch" => Some(AgentToolCategory::Write),
|
||||
+ "shell" => Some(AgentToolCategory::Shell),
|
||||
+ "spawn_agent" | "send_input" | "wait" | "close_agent" => Some(AgentToolCategory::Subagent),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
-pub fn is_auto_approved(level: PermissionLevel, category: &str) -> bool {
|
||||
+/// CLI permission gate category. Unknown tools fall back to `Shell` so they
|
||||
+/// require explicit user approval at any permission level below `Full`.
|
||||
+pub fn tool_category(name: &str) -> AgentToolCategory {
|
||||
+ known_tool_category(name).unwrap_or(AgentToolCategory::Shell)
|
||||
+}
|
||||
+
|
||||
+pub fn is_auto_approved(level: PermissionLevel, category: AgentToolCategory) -> bool {
|
||||
matches!(
|
||||
(level, category),
|
||||
- (_, "read" | "subagent")
|
||||
- | (PermissionLevel::ReadWrite | PermissionLevel::Full, "write")
|
||||
- | (PermissionLevel::Full, "shell")
|
||||
+ (_, AgentToolCategory::Read | AgentToolCategory::Subagent)
|
||||
+ | (
|
||||
+ PermissionLevel::ReadWrite | PermissionLevel::Full,
|
||||
+ AgentToolCategory::Write,
|
||||
+ )
|
||||
+ | (PermissionLevel::Full, AgentToolCategory::Shell)
|
||||
)
|
||||
}
|
||||
|
||||
diff --git a/lib/crates/fabro-agent/src/tool_registry.rs b/lib/crates/fabro-agent/src/tool_registry.rs
|
||||
index 3e43d7e34..74af24354 100644
|
||||
--- a/lib/crates/fabro-agent/src/tool_registry.rs
|
||||
+++ b/lib/crates/fabro-agent/src/tool_registry.rs
|
||||
@@ -4,11 +4,13 @@ use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
|
||||
use fabro_llm::types::ToolDefinition;
|
||||
+use fabro_types::{AgentToolCategory, AgentToolSource, AgentToolSummary};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use crate::config::{ToolAccessPolicy, ToolExposureMode};
|
||||
use crate::sandbox::Sandbox;
|
||||
use crate::session::ToolEnvProvider;
|
||||
+use crate::tool_permissions;
|
||||
use crate::types::AgentEvent;
|
||||
|
||||
/// Narrow handle a tool uses to publish typed agent events (e.g. todo
|
||||
@@ -72,8 +74,13 @@ pub struct RegisteredTool {
|
||||
pub enum ToolSource {
|
||||
#[default]
|
||||
Native,
|
||||
+ /// `original_name` is the raw upstream MCP tool name (before the
|
||||
+ /// `mcp__<server>__` qualification applied by `fabro_mcp`). It is
|
||||
+ /// supplied by the MCP integration that registers the tool, so consumers
|
||||
+ /// never need to re-parse the qualified name.
|
||||
Mcp {
|
||||
- server_name: String,
|
||||
+ server_name: String,
|
||||
+ original_name: String,
|
||||
},
|
||||
Skill,
|
||||
}
|
||||
@@ -84,6 +91,39 @@ pub struct ToolDefinitionWithSource {
|
||||
pub source: ToolSource,
|
||||
}
|
||||
|
||||
+impl ToolDefinitionWithSource {
|
||||
+ /// Project this tool into the public `AgentToolSummary` used by
|
||||
+ /// `StageProjection.agent_tools` and the `agent.tools.available` event.
|
||||
+ /// Drops the parameter schema; `invoked` defaults to `false` and is set
|
||||
+ /// by the projection reducer when matching `agent.tool.started` events
|
||||
+ /// replay.
|
||||
+ #[must_use]
|
||||
+ pub fn to_agent_tool_summary(&self) -> AgentToolSummary {
|
||||
+ AgentToolSummary {
|
||||
+ name: self.definition.name.clone(),
|
||||
+ description: self.definition.description.clone(),
|
||||
+ source: agent_tool_source(&self.source),
|
||||
+ category: tool_permissions::known_tool_category(&self.definition.name)
|
||||
+ .unwrap_or(AgentToolCategory::Other),
|
||||
+ invoked: false,
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+fn agent_tool_source(source: &ToolSource) -> AgentToolSource {
|
||||
+ match source {
|
||||
+ ToolSource::Native => AgentToolSource::Native,
|
||||
+ ToolSource::Mcp {
|
||||
+ server_name,
|
||||
+ original_name,
|
||||
+ } => AgentToolSource::Mcp {
|
||||
+ server_name: server_name.clone(),
|
||||
+ original_name: original_name.clone(),
|
||||
+ },
|
||||
+ ToolSource::Skill => AgentToolSource::Skill,
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
pub struct ToolRegistry {
|
||||
tools: HashMap<String, RegisteredTool>,
|
||||
}
|
||||
@@ -385,4 +425,59 @@ mod tests {
|
||||
assert!(registry.names().is_empty());
|
||||
assert!(registry.definitions().is_empty());
|
||||
}
|
||||
+
|
||||
+ fn tool_with_source(name: &str, source: ToolSource) -> ToolDefinitionWithSource {
|
||||
+ ToolDefinitionWithSource {
|
||||
+ definition: ToolDefinition {
|
||||
+ name: name.to_string(),
|
||||
+ description: format!("{name} description"),
|
||||
+ parameters: serde_json::json!({
|
||||
+ "type": "object",
|
||||
+ "properties": { "path": { "type": "string" } }
|
||||
+ }),
|
||||
+ },
|
||||
+ source,
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn to_agent_tool_summary_maps_known_native_categories_and_drops_parameters() {
|
||||
+ let cases = [
|
||||
+ ("apply_patch", AgentToolCategory::Write),
|
||||
+ ("grep", AgentToolCategory::Read),
|
||||
+ ("glob", AgentToolCategory::Read),
|
||||
+ ("spawn_agent", AgentToolCategory::Subagent),
|
||||
+ ("shell", AgentToolCategory::Shell),
|
||||
+ ("unknown_native", AgentToolCategory::Other),
|
||||
+ ];
|
||||
+ for (name, expected) in cases {
|
||||
+ let summary = tool_with_source(name, ToolSource::Native).to_agent_tool_summary();
|
||||
+ assert_eq!(summary.name, name);
|
||||
+ assert_eq!(summary.description, format!("{name} description"));
|
||||
+ assert_eq!(summary.source, AgentToolSource::Native);
|
||||
+ assert_eq!(summary.category, expected);
|
||||
+ assert!(!summary.invoked);
|
||||
+
|
||||
+ let json = serde_json::to_value(&summary).unwrap();
|
||||
+ assert!(
|
||||
+ json.as_object().unwrap().get("parameters").is_none(),
|
||||
+ "agent tool summaries must not include parameter schemas"
|
||||
+ );
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn to_agent_tool_summary_carries_mcp_original_name_from_source() {
|
||||
+ let summary = tool_with_source("mcp__filesystem__read_file", ToolSource::Mcp {
|
||||
+ server_name: "filesystem".to_string(),
|
||||
+ original_name: "read_file".to_string(),
|
||||
+ })
|
||||
+ .to_agent_tool_summary();
|
||||
+
|
||||
+ assert_eq!(summary.source, AgentToolSource::Mcp {
|
||||
+ server_name: "filesystem".to_string(),
|
||||
+ original_name: "read_file".to_string(),
|
||||
+ });
|
||||
+ assert_eq!(summary.category, AgentToolCategory::Other);
|
||||
+ }
|
||||
}
|
||||
diff --git a/lib/crates/fabro-workflow/src/handler/llm/api.rs b/lib/crates/fabro-workflow/src/handler/llm/api.rs
|
||||
index 135b5e3b7..8fcdf32c2 100644
|
||||
--- a/lib/crates/fabro-workflow/src/handler/llm/api.rs
|
||||
+++ b/lib/crates/fabro-workflow/src/handler/llm/api.rs
|
||||
@@ -3,13 +3,11 @@ use std::sync::{Arc, Mutex};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use fabro_agent::subagent::{SessionFactory, SubAgentManager};
|
||||
-use fabro_agent::tool_registry::{
|
||||
- RegisteredTool, ToolContext, ToolDefinitionWithSource, ToolRegistry, ToolSource,
|
||||
-};
|
||||
+use fabro_agent::tool_registry::{RegisteredTool, ToolContext, ToolRegistry, ToolSource};
|
||||
use fabro_agent::{
|
||||
AgentEvent, AgentProfile, AnthropicProfile, CompletionCoordinator, GeminiProfile,
|
||||
Message as AgentMessage, OpenAiProfile, Sandbox, Session, SessionOptions, StaticEnvProvider,
|
||||
- ToolEnvProvider, register_question_tools, tool_permissions,
|
||||
+ ToolEnvProvider, register_question_tools,
|
||||
};
|
||||
use fabro_auth::{CredentialSource, EnvCredentialSource};
|
||||
use fabro_graphviz::graph::{AttrValue, Node};
|
||||
@@ -23,10 +21,7 @@ use fabro_mcp::config::McpServerSettings;
|
||||
use fabro_model::catalog::LlmCatalogSettings;
|
||||
use fabro_model::{AgentProfileKind, Catalog, FallbackTarget, ModelRef, ProviderId};
|
||||
use fabro_types::settings::run::RunModelControls;
|
||||
-use fabro_types::{
|
||||
- AgentToolCategory, AgentToolSource, AgentToolSummary, PermissionLevel, RunId,
|
||||
- SessionCapability, StageId,
|
||||
-};
|
||||
+use fabro_types::{PermissionLevel, RunId, SessionCapability, StageId};
|
||||
use serde::de::DeserializeOwned;
|
||||
use tokio::sync::Mutex as TokioMutex;
|
||||
use tokio::task::JoinHandle;
|
||||
@@ -501,58 +496,17 @@ fn last_assistant_response(session: &Session) -> String {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
-fn agent_tool_summaries_from_definitions(
|
||||
- tools: &[ToolDefinitionWithSource],
|
||||
-) -> Vec<AgentToolSummary> {
|
||||
- let mut summaries: Vec<_> = tools
|
||||
- .iter()
|
||||
- .map(|tool| AgentToolSummary {
|
||||
- name: tool.definition.name.clone(),
|
||||
- description: tool.definition.description.clone(),
|
||||
- source: agent_tool_source(&tool.definition.name, &tool.source),
|
||||
- category: agent_tool_category(&tool.definition.name),
|
||||
- invoked: false,
|
||||
- })
|
||||
- .collect();
|
||||
- summaries.sort_by(|left, right| left.name.cmp(&right.name));
|
||||
- summaries
|
||||
-}
|
||||
-
|
||||
-fn agent_tool_source(name: &str, source: &ToolSource) -> AgentToolSource {
|
||||
- match source {
|
||||
- ToolSource::Native => AgentToolSource::Native,
|
||||
- ToolSource::Mcp { server_name } => AgentToolSource::Mcp {
|
||||
- server_name: server_name.clone(),
|
||||
- original_name: fabro_mcp::connection_manager::parse_qualified_name(name)
|
||||
- .map(|(_, original_name)| original_name)
|
||||
- .unwrap_or_else(|| name.to_string()),
|
||||
- },
|
||||
- ToolSource::Skill => AgentToolSource::Skill,
|
||||
- }
|
||||
-}
|
||||
-
|
||||
-fn agent_tool_category(name: &str) -> AgentToolCategory {
|
||||
- match tool_permissions::known_tool_category(name) {
|
||||
- Some("read") => AgentToolCategory::Read,
|
||||
- Some("write") => AgentToolCategory::Write,
|
||||
- Some("shell") => AgentToolCategory::Shell,
|
||||
- Some("subagent") => AgentToolCategory::Subagent,
|
||||
- Some(_) | None => AgentToolCategory::Other,
|
||||
- }
|
||||
-}
|
||||
-
|
||||
fn emit_agent_tools_available(
|
||||
session: &Session,
|
||||
node_id: &str,
|
||||
stage_id: &StageId,
|
||||
emitter: &Arc<Emitter>,
|
||||
) {
|
||||
- let tools = agent_tool_summaries_from_definitions(&session.available_tools());
|
||||
emitter.emit(&Event::AgentToolsAvailable {
|
||||
- node_id: node_id.to_string(),
|
||||
- visit: stage_id.visit(),
|
||||
+ node_id: node_id.to_string(),
|
||||
+ visit: stage_id.visit(),
|
||||
session_id: session.id().to_string(),
|
||||
- tools,
|
||||
+ tools: session.agent_tool_summaries(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1257,7 +1211,13 @@ impl CodergenBackend for AgentApiBackend {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
- emit_agent_tools_available(&session, &node.id, &stage_id, emitter);
|
||||
+ // Reused steerable sessions already emitted their effective
|
||||
+ // tool list on first activation; the registry, access policy,
|
||||
+ // and exposure mode are immutable for the session's lifetime,
|
||||
+ // so re-emitting on every subsequent prompt is wasted work.
|
||||
+ if !is_reused {
|
||||
+ emit_agent_tools_available(&session, &node.id, &stage_id, emitter);
|
||||
+ }
|
||||
session
|
||||
.process_input_with_runtime(prompt, agent_tool_runtime.clone())
|
||||
.await
|
||||
@@ -1562,7 +1522,6 @@ mod tests {
|
||||
|
||||
use chrono::TimeZone;
|
||||
use fabro_agent::subagent::SessionFactory;
|
||||
- use fabro_agent::tool_registry::ToolDefinitionWithSource;
|
||||
use fabro_agent::{AgentProfile, LocalSandbox, ToolRegistry};
|
||||
use fabro_api::types;
|
||||
use fabro_auth::{EnvCredentialSource, VaultCredentialSource};
|
||||
@@ -1629,68 +1588,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
- fn test_tool_with_source(name: &str, source: ToolSource) -> ToolDefinitionWithSource {
|
||||
- ToolDefinitionWithSource {
|
||||
- definition: LlmToolDefinition {
|
||||
- name: name.to_string(),
|
||||
- description: format!("{name} description"),
|
||||
- parameters: serde_json::json!({
|
||||
- "type": "object",
|
||||
- "properties": {
|
||||
- "path": { "type": "string" }
|
||||
- }
|
||||
- }),
|
||||
- },
|
||||
- source,
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- #[test]
|
||||
- fn agent_tool_summaries_map_known_native_categories_without_schemas() {
|
||||
- let summaries = agent_tool_summaries_from_definitions(&[
|
||||
- test_tool_with_source("apply_patch", ToolSource::Native),
|
||||
- test_tool_with_source("grep", ToolSource::Native),
|
||||
- test_tool_with_source("glob", ToolSource::Native),
|
||||
- test_tool_with_source("spawn_agent", ToolSource::Native),
|
||||
- test_tool_with_source("unknown_native", ToolSource::Native),
|
||||
- ]);
|
||||
-
|
||||
- assert_eq!(summaries[0].name, "apply_patch");
|
||||
- assert_eq!(summaries[0].description, "apply_patch description");
|
||||
- assert_eq!(summaries[0].source, fabro_types::AgentToolSource::Native);
|
||||
- assert_eq!(summaries[0].category, fabro_types::AgentToolCategory::Write);
|
||||
- assert!(!summaries[0].invoked);
|
||||
- assert_eq!(summaries[1].category, fabro_types::AgentToolCategory::Read);
|
||||
- assert_eq!(summaries[2].category, fabro_types::AgentToolCategory::Read);
|
||||
- assert_eq!(
|
||||
- summaries[3].category,
|
||||
- fabro_types::AgentToolCategory::Subagent
|
||||
- );
|
||||
- assert_eq!(summaries[4].category, fabro_types::AgentToolCategory::Other);
|
||||
-
|
||||
- let json = serde_json::to_value(&summaries[0]).unwrap();
|
||||
- assert!(
|
||||
- json.as_object().unwrap().get("parameters").is_none(),
|
||||
- "agent tool summaries should not include tool parameter schemas"
|
||||
- );
|
||||
- }
|
||||
-
|
||||
- #[test]
|
||||
- fn agent_tool_summaries_map_mcp_source_and_original_name_from_qualified_name() {
|
||||
- let summaries = agent_tool_summaries_from_definitions(&[test_tool_with_source(
|
||||
- "mcp__filesystem__read_file",
|
||||
- ToolSource::Mcp {
|
||||
- server_name: "filesystem".to_string(),
|
||||
- },
|
||||
- )]);
|
||||
-
|
||||
- assert_eq!(summaries[0].source, fabro_types::AgentToolSource::Mcp {
|
||||
- server_name: "filesystem".to_string(),
|
||||
- original_name: "read_file".to_string(),
|
||||
- });
|
||||
- assert_eq!(summaries[0].category, fabro_types::AgentToolCategory::Other);
|
||||
- }
|
||||
-
|
||||
struct ShutdownTestProvider;
|
||||
|
||||
#[async_trait]
|
||||
6
stages/006-simplify_opus@1/status.json
Normal file
6
stages/006-simplify_opus@1/status.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"outcome": "succeeded",
|
||||
"notes": "Stage completed: simplify_opus",
|
||||
"failure_reason": null,
|
||||
"timestamp": "2026-05-24T17:57:19.242878Z"
|
||||
}
|
||||
300
stages/007-simplify_gpt@1/prompt.md
Normal file
300
stages/007-simplify_gpt@1/prompt.md
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
Goal: ---
|
||||
title: feat: StageProjection agent tools API
|
||||
type: feat
|
||||
status: active
|
||||
date: 2026-05-24
|
||||
---
|
||||
|
||||
# feat: StageProjection Agent Tools API
|
||||
|
||||
## Overview
|
||||
|
||||
Expose the complete effective tool list for each agent-backed stage through `StageProjection`, so UI and API consumers can show actual tools such as `apply_patch`, `grep`, `glob`, `read_file`, MCP tools, skill tools, and subagent tools without inferring them from `permission_level`.
|
||||
|
||||
The API should expose tool summaries with `name`, `description`, `source`, `category`, and `invoked`. It must not expose full JSON parameter schemas in the run projection.
|
||||
|
||||
## Problem Frame
|
||||
|
||||
The stage sidebar currently has permission metadata such as "Full access", but `permission_level` is only an access mode. It does not tell consumers which tools were actually exposed to the model after provider profile setup, optional tool registration, MCP integration, and tool access policy filtering.
|
||||
|
||||
The authoritative list already exists at request-build time in the agent session registry. The API needs to capture that effective list once per stage session and project it onto the stage.
|
||||
|
||||
## Requirements Trace
|
||||
|
||||
- R1. Add a StageProjection API field containing the complete effective tools for a stage session.
|
||||
- R2. Include `name`, `description`, `source`, `category`, and `invoked` for each tool.
|
||||
- R3. Do not infer tools from `permission_level` in backend or frontend code.
|
||||
- R4. Do not expose full tool parameter schemas through StageProjection.
|
||||
- R5. Preserve existing `permission_level` and `mcp_servers` fields for compatibility.
|
||||
- R6. Mark individual tools as invoked when matching `agent.tool.started` events are projected.
|
||||
- R7. Keep legacy runs backward compatible by defaulting missing tool lists to empty.
|
||||
|
||||
## Scope Boundaries
|
||||
|
||||
- Do not remove or rename `StageProjection.permission_level`.
|
||||
- Do not remove the existing MCP server projection or `AgentMcpToolSummary`.
|
||||
- Do not change completion API tool definitions.
|
||||
- Do not add ACP-native tool discovery in this pass unless an ACP path already has an equivalent effective tool list available.
|
||||
- Do not render parameter schemas in the web UI.
|
||||
|
||||
## Context & Research
|
||||
|
||||
### Relevant Code and Patterns
|
||||
|
||||
- OpenAPI is the source of truth for HTTP contracts in `docs/public/api-reference/fabro-api.yaml`.
|
||||
- Shared API/projection DTOs should live in `fabro-types`, with `fabro-api/build.rs` replacements to avoid duplicate generated Rust types.
|
||||
- `StageProjection` lives in `lib/crates/fabro-types/src/run_projection.rs`.
|
||||
- Durable run event props live in `lib/crates/fabro-types/src/run_event/agent.rs` and `lib/crates/fabro-types/src/run_event/mod.rs`.
|
||||
- Workflow event conversion and event names live in `lib/crates/fabro-workflow/src/event/convert.rs`, `events.rs`, and `names.rs`.
|
||||
- Projection replay lives in `lib/crates/fabro-store/src/run_state.rs`.
|
||||
- The effective request tool list is built in `lib/crates/fabro-agent/src/session.rs` from `ToolRegistry::definitions_with_source_for_policy`.
|
||||
- Tool source metadata already exists as `ToolSource` and `ToolDefinitionWithSource` in `lib/crates/fabro-agent/src/tool_registry.rs`.
|
||||
- Tool category mapping already exists in `lib/crates/fabro-agent/src/tool_permissions.rs`.
|
||||
- The sidebar display lives in `apps/fabro-web/app/components/stage-insights-sidebar.tsx`.
|
||||
|
||||
### Strategy Docs
|
||||
|
||||
- Read `docs/internal/events-strategy.md` before adding the new durable event.
|
||||
- Read `docs/internal/testing-strategy.md` before adding or reorganizing tests.
|
||||
- Follow the OpenAPI type ownership guidance in `AGENTS.md`: reuse `fabro-types` through `fabro-api/build.rs` replacements when the API schema has the same product meaning and serde shape.
|
||||
|
||||
## Key Technical Decisions
|
||||
|
||||
- Add a new StageProjection field named `agent_tools`, not `tools`, to avoid ambiguity with MCP nested tools and completion tool definitions.
|
||||
- Add a dedicated durable event named `agent.tools.available` instead of overloading `agent.session.activated`.
|
||||
- Capture the effective tool list after session setup and filtering, using the same path as model request construction.
|
||||
- Store descriptions in the summary because they are useful API/UI metadata; omit parameter schemas to keep projection payloads small and avoid leaking full implementation detail.
|
||||
- Keep `AgentMcpToolSummary` MCP-only. Add a new general-purpose `AgentToolSummary` instead of stretching the MCP type beyond its meaning.
|
||||
- Treat `invoked` as projected state. The availability event should emit tools with `invoked: false`; replay of `agent.tool.started` flips matching tools to true.
|
||||
|
||||
## API Contract
|
||||
|
||||
Add these schemas to OpenAPI and map them to `fabro_types` replacements:
|
||||
|
||||
- `AgentToolSummary`
|
||||
- required: `name`, `description`, `source`, `category`, `invoked`
|
||||
- `name`: exposed tool name, e.g. `apply_patch` or `mcp__filesystem__read_file`
|
||||
- `description`: model-facing tool description
|
||||
- `source`: `AgentToolSource`
|
||||
- `category`: `AgentToolCategory`
|
||||
- `invoked`: boolean
|
||||
- `AgentToolSource`
|
||||
- tagged by `kind`
|
||||
- `native`
|
||||
- `mcp` with `server_name` and `original_name`
|
||||
- `skill`
|
||||
- `AgentToolCategory`
|
||||
- enum: `read`, `write`, `shell`, `subagent`, `other`
|
||||
- `AgentToolsAvailableProps`
|
||||
- required: `tools`, `visit`
|
||||
- `tools`: array of `AgentToolSummary`
|
||||
- `visit`: stage visit number
|
||||
|
||||
Add to `StageProjection`:
|
||||
|
||||
- `agent_tools`: array of `AgentToolSummary`
|
||||
- Default to an empty array when omitted.
|
||||
- Skip serializing when empty, matching existing projection optional-list style.
|
||||
|
||||
Add event body:
|
||||
|
||||
- Serialized event name: `agent.tools.available`
|
||||
- Event body type: `AgentToolsAvailableProps`
|
||||
|
||||
## Implementation Units
|
||||
|
||||
- [ ] **Unit 1: Add shared tool summary types**
|
||||
|
||||
**Goal:** Define the canonical API/projection DTOs in `fabro-types`.
|
||||
|
||||
**Files:**
|
||||
- Modify: `lib/crates/fabro-types/src/run_event/agent.rs`
|
||||
- Modify: `lib/crates/fabro-types/src/run_event/mod.rs`
|
||||
- Modify: `lib/crates/fabro-types/src/run_projection.rs`
|
||||
- Modify: `lib/crates/fabro-types/src/lib.rs`
|
||||
|
||||
**Work:**
|
||||
- Add `AgentToolSummary`, `AgentToolSource`, `AgentToolCategory`, and `AgentToolsAvailableProps`.
|
||||
- Add `EventBody::AgentToolsAvailable` serialized as `agent.tools.available`.
|
||||
- Add `agent_tools: Vec<AgentToolSummary>` to `StageProjection`.
|
||||
- Ensure all new fields default cleanly for older persisted events/projections.
|
||||
- Export the new public types from `fabro-types`.
|
||||
|
||||
- [ ] **Unit 2: Capture effective session tools**
|
||||
|
||||
**Goal:** Provide an authoritative one-time source for the list that the model can actually call.
|
||||
|
||||
**Files:**
|
||||
- Modify: `lib/crates/fabro-agent/src/session.rs`
|
||||
- Modify: `lib/crates/fabro-workflow/src/handler/llm/api.rs`
|
||||
- Modify: `lib/crates/fabro-workflow/src/event/events.rs`
|
||||
- Modify: `lib/crates/fabro-workflow/src/event/names.rs`
|
||||
- Modify: `lib/crates/fabro-workflow/src/event/convert.rs`
|
||||
- Modify: `lib/crates/fabro-workflow/src/event/stored_fields.rs` only if the new event needs non-standard stored fields.
|
||||
|
||||
**Work:**
|
||||
- Add `Session::available_tools()` that returns the same effective `ToolDefinitionWithSource` list as `build_request()`.
|
||||
- Map `ToolDefinitionWithSource` to `AgentToolSummary` at the workflow boundary.
|
||||
- Populate `description` from `ToolDefinition.description`.
|
||||
- Populate `source` from `ToolSource`.
|
||||
- For MCP tools, include the server name from `ToolSource::Mcp` and derive `original_name` from the qualified exposed name using the existing MCP naming convention.
|
||||
- Populate `category` from the existing tool category mapping for known exposed names; use `other` when no category mapping applies.
|
||||
- Emit `agent.tools.available` once for the stage session after session setup and filtering are complete.
|
||||
|
||||
- [ ] **Unit 3: Project available and invoked tools**
|
||||
|
||||
**Goal:** Make `StageProjection.agent_tools` replay-authoritative.
|
||||
|
||||
**Files:**
|
||||
- Modify: `lib/crates/fabro-store/src/run_state.rs`
|
||||
|
||||
**Work:**
|
||||
- On `EventBody::AgentToolsAvailable`, replace the current stage visit's `agent_tools` with the event tools.
|
||||
- On `EventBody::AgentToolStarted`, find a matching `agent_tools` entry by exposed `tool_name` and set `invoked = true`.
|
||||
- Keep the existing MCP server `invoked` update unchanged.
|
||||
- If a legacy run has no availability event, do not synthesize a full list from permissions.
|
||||
|
||||
- [ ] **Unit 4: Update OpenAPI and generated clients**
|
||||
|
||||
**Goal:** Expose the new projection field and event contract through public API clients without duplicate Rust API types.
|
||||
|
||||
**Files:**
|
||||
- Modify: `docs/public/api-reference/fabro-api.yaml`
|
||||
- Modify: `lib/crates/fabro-api/build.rs`
|
||||
- Modify: `lib/crates/fabro-api/src/lib.rs`
|
||||
- Modify generated files under `lib/crates/fabro-api/src/generated.rs` via `cargo build -p fabro-api`.
|
||||
- Modify generated files under `lib/packages/fabro-api-client/src` via TypeScript client generation.
|
||||
|
||||
**Work:**
|
||||
- Add the OpenAPI schemas listed in the API Contract section.
|
||||
- Add `StageProjection.agent_tools`.
|
||||
- Add `fabro-api/build.rs` replacements for the new `fabro-types` types.
|
||||
- Regenerate Rust API code.
|
||||
- Regenerate TypeScript API client code.
|
||||
|
||||
- [ ] **Unit 5: Render tools in the web sidebar**
|
||||
|
||||
**Goal:** Replace the permission-derived sidebar display with the actual projected tool list.
|
||||
|
||||
**Files:**
|
||||
- Modify: `apps/fabro-web/app/components/stage-insights-sidebar.tsx`
|
||||
- Modify: `apps/fabro-web/app/components/stage-insights-sidebar.test.tsx`
|
||||
|
||||
**Work:**
|
||||
- Render `stage.agent_tools` when present.
|
||||
- Show each tool's name, description, source/category, and invoked state.
|
||||
- Keep permission level as secondary metadata or fallback for legacy stages with no `agent_tools`.
|
||||
- Do not infer tool availability from permission level.
|
||||
|
||||
## Test Plan
|
||||
|
||||
- `fabro-types`
|
||||
- JSON round-trip for `agent.tools.available`.
|
||||
- Serialization checks for `AgentToolSource` and `AgentToolCategory`.
|
||||
- Backward compatibility check that missing `agent_tools` deserializes to an empty list.
|
||||
|
||||
- `fabro-workflow`
|
||||
- Event name and conversion tests for `agent.tools.available`.
|
||||
- Capture test proving native tools such as `apply_patch`, `grep`, and `glob` are emitted from the effective registry path.
|
||||
- MCP source mapping test for a qualified MCP tool name.
|
||||
|
||||
- `fabro-store`
|
||||
- Projection test that `agent.tools.available` populates `StageProjection.agent_tools`.
|
||||
- Projection test that `agent.tool.started` marks only the matching tool as invoked.
|
||||
- Regression test that MCP server `invoked` status still updates as before.
|
||||
|
||||
- `fabro-api`
|
||||
- Type identity/parity tests confirming API types reuse `fabro_types::AgentToolSummary`, `AgentToolSource`, `AgentToolCategory`, and `AgentToolsAvailableProps`.
|
||||
- StageProjection round-trip test including `agent_tools`.
|
||||
|
||||
- `fabro-web`
|
||||
- Sidebar test rendering tool names and descriptions from `stage.agent_tools`.
|
||||
- Sidebar test showing invoked state.
|
||||
- Legacy fallback test for stages without `agent_tools`.
|
||||
|
||||
## Run Checks
|
||||
|
||||
- `cargo +nightly-2026-04-14 fmt --check --all`
|
||||
- `cargo nextest run -p fabro-types -p fabro-workflow -p fabro-store -p fabro-api`
|
||||
- `cargo build -p fabro-api`
|
||||
- `cd lib/packages/fabro-api-client && bun run generate`
|
||||
- `cd apps/fabro-web && bun test && bun run typecheck`
|
||||
|
||||
## Assumptions
|
||||
|
||||
- The first implementation targets normal API-backed agent sessions, not ACP-native sessions.
|
||||
- `description` is safe to expose because it is already model-facing tool metadata, but parameter schemas remain out of scope for StageProjection.
|
||||
- `agent_tools` is a complete list only for runs that emit `agent.tools.available`; legacy runs return an empty list and may still show existing permission/MCP metadata.
|
||||
- If tool registration becomes mutable later, the event contract can be re-emitted and projection replacement semantics will still work.
|
||||
|
||||
|
||||
## Completed stages
|
||||
- **toolchain**: succeeded
|
||||
- Script: `command -v cargo >/dev/null || { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && sudo ln -sf $HOME/.cargo/bin/* /usr/local/bin/; }; cargo --version 2>&1`
|
||||
- Output:
|
||||
```
|
||||
cargo 1.95.0 (f2d3ce0bd 2026-03-21)
|
||||
```
|
||||
- **preflight_compile**: succeeded
|
||||
- Script: `cargo check -q --workspace 2>&1`
|
||||
- Output: (empty)
|
||||
- **preflight_lint**: succeeded
|
||||
- Script: `cargo +nightly-2026-04-14 clippy -q --workspace --all-targets -- -D warnings 2>&1`
|
||||
- Output: (empty)
|
||||
- **implement**: succeeded
|
||||
- Model: gpt-5.5, 6.7m tokens in / 34.2k out
|
||||
- **simplify_opus**: succeeded
|
||||
- Model: claude-opus-4-7, 113.7k tokens in / 35.0k out
|
||||
- Files: /home/daytona/workspace/fabro/apps/fabro-web/app/components/stage-insights-sidebar.tsx, /home/daytona/workspace/fabro/lib/crates/fabro-agent/src/cli.rs, /home/daytona/workspace/fabro/lib/crates/fabro-agent/src/context_window.rs, /home/daytona/workspace/fabro/lib/crates/fabro-agent/src/mcp_integration.rs, /home/daytona/workspace/fabro/lib/crates/fabro-agent/src/session.rs, /home/daytona/workspace/fabro/lib/crates/fabro-agent/src/tool_permissions.rs, /home/daytona/workspace/fabro/lib/crates/fabro-agent/src/tool_registry.rs, /home/daytona/workspace/fabro/lib/crates/fabro-workflow/src/handler/llm/api.rs
|
||||
|
||||
|
||||
# Simplify: Code Review and Cleanup
|
||||
|
||||
Review changes vs. origin for reuse, quality, and efficiency. Fix any issues found.
|
||||
|
||||
## Phase 1: Identify Changes
|
||||
|
||||
Run git diff (or git diff HEAD if there are staged changes) to see what changed. If there are no git changes, review the most recently modified files that the user mentioned or that you edited earlier in this conversation.
|
||||
|
||||
## Phase 2: Launch Three Review Agents in Parallel
|
||||
|
||||
Use the Agent tool to launch all three agents concurrently in a single message. Pass each agent the full diff so it has the complete context.
|
||||
|
||||
### Agent 1: Code Reuse Review
|
||||
|
||||
For each change:
|
||||
|
||||
1. Search for existing utilities and helpers that could replace newly written code. Use Grep to find similar patterns elsewhere in the codebase — common locations are utility directories, shared modules, and files adjacent to the changed ones.
|
||||
2. Flag any new function that duplicates existing functionality. Suggest the existing function to use instead.
|
||||
3. Flag any inline logic that could use an existing utility — hand-rolled string manipulation, manual path handling, custom environment checks, ad-hoc type guards, and similar patterns are common candidates.
|
||||
|
||||
Note: This is a greenfield app, so focus on maximizing simplicity and don't worry about changing things to achieve it.
|
||||
|
||||
### Agent 2: Code Quality Review
|
||||
|
||||
Review the same changes for hacky patterns:
|
||||
|
||||
1. Redundant state: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls
|
||||
2. Parameter sprawl: adding new parameters to a function instead of generalizing or restructuring existing ones
|
||||
3. Copy-paste with slight variation: near-duplicate code blocks that should be unified with a shared abstraction
|
||||
4. Leaky abstractions: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries
|
||||
5. Stringly-typed code: using raw strings where constants, enums (string unions), or branded types already exist in the codebase
|
||||
|
||||
Note: This is a greenfield app, so be aggressive in optimizing quality.
|
||||
|
||||
### Agent 3: Efficiency Review
|
||||
|
||||
Review the same changes for efficiency:
|
||||
|
||||
1. Unnecessary work: redundant computations, repeated file reads, duplicate network/API calls, N+1 patterns
|
||||
2. Missed concurrency: independent operations run sequentially when they could run in parallel
|
||||
3. Hot-path bloat: new blocking work added to startup or per-request/per-render hot paths
|
||||
4. Unnecessary existence checks: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error
|
||||
5. Memory: unbounded data structures, missing cleanup, event listener leaks
|
||||
6. Overly broad operations: reading entire files when only a portion is needed, loading all items when filtering for one
|
||||
|
||||
## Phase 3: Fix Issues
|
||||
|
||||
Wait for all three agents to complete. Aggregate their findings and fix each issue directly. If a finding is a false positive or not worth addressing, note it and move on — do not argue with the finding, just skip it.
|
||||
|
||||
When done, briefly summarize what was fixed (or confirm the code was already clean).
|
||||
5
stages/007-simplify_gpt@1/provider_used.json
Normal file
5
stages/007-simplify_gpt@1/provider_used.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"mode": "agent",
|
||||
"provider": "openai",
|
||||
"model": "gpt-5.5"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue