diff --git a/run.json b/run.json index 8c2e18585..497c23fdc 100644 --- a/run.json +++ b/run.json @@ -492,7 +492,7 @@ "kind": "running" }, "status_updated_at": "2026-05-24T17:13:10.096457Z", - "last_event_at": "2026-05-24T17:57:18.881493Z", + "last_event_at": "2026-05-24T18:01:02.118960Z", "pending_control": null, "checkpoints": [ { @@ -859,9 +859,9 @@ } }, { - "seq": 0, + "seq": 2285, "checkpoint": { - "timestamp": "2026-05-24T17:57:19.244493Z", + "timestamp": "2026-05-24T17:57:23.050179Z", "current_node": "simplify_opus", "completed_nodes": [ "start", @@ -873,38 +873,50 @@ ], "node_retries": {}, "context_values": { - "graph.rankdir": "LR", - "graph.model_stylesheet": "\n * { model: claude-opus-4-7; }\n ", - "internal.retry_count.start": 0, - "internal.fidelity": "compact", "failure_signature": "", - "internal.retry_count.toolchain": 0, - "internal.retry_count.preflight_compile": 0, - "thread.implement.current_node": "simplify_opus", - "outcome": "succeeded", - "failure_class": "", - "response.simplify_opus": "## Summary\n\nAggregated three review agents' findings and applied the consensus high-value fixes:\n\n**Quality / reuse fixes:**\n- `tool_permissions::known_tool_category` now returns `Option` directly. Deleted the brittle `Some(\"read\")` → `Read` string match in `handler/llm/api.rs`. `is_auto_approved` and `tool_category` are now enum-typed end-to-end; cli.rs and its tests updated accordingly. Adding a new category is now a compile-time exhaustiveness error instead of a silent `Other`.\n- `ToolSource::Mcp` now carries `original_name` populated from `info.original_tool_name` in `make_mcp_tools`. Workflow code no longer re-parses qualified MCP names (eliminates the silent fallback bug where a malformed prefix would store the qualified name as \"original\").\n- Moved `agent_tool_source` + `agent_tool_summaries_from_definitions` out of `handler/llm/api.rs`. New `ToolDefinitionWithSource::to_agent_tool_summary()` + `Session::agent_tool_summaries()` colocate the conversion next to the source type. Tests moved to `tool_registry.rs`.\n- Collapsed `Session::available_tools` and the duplicate private `effective_tools` into one public `effective_tools()` method.\n- Merged `ToolAvailableIcon` and `TodoPendingIcon` into a single `EmptyCircleIcon` component in the sidebar.\n\n**Efficiency fix:**\n- Gated `emit_agent_tools_available` on `!is_reused` in the primary path. Reused steerable sessions had been re-emitting the full tool list (with descriptions cloned into the event payload) on every prompt even though registry, access policy, and exposure mode are immutable for the session's lifetime. Failover path keeps its emit since it always builds a fresh session.\n\n**Skipped (cost > benefit):** `mcp_server_from_tool_name` dedup in `fabro-store` would require pulling `fabro-mcp` (with `rmcp`) into the store crate or relocating the parse helper into `fabro-types`. The duplicate is 5 lines using the same delimiter convention — not worth the dependency surface.\n\n**Verification:** `cargo check --workspace --all-targets`, `cargo +nightly-2026-04-14 clippy --workspace --all-targets -- -D warnings`, `cargo +nightly-2026-04-14 fmt --check --all`, `cargo nextest run -p fabro-types -p fabro-workflow -p fabro-store -p fabro-api -p fabro-agent` (2250+464 tests), `bun test stage-insights-sidebar` (10/10), and `bun run typecheck` all pass. The 14 unrelated `run-actions.test.ts` failures pre-exist on the parent commit.", - "internal.retry_count.simplify_opus": 0, - "response.implement": "The TS generator is pinned now, but this sandbox lacks Java, which OpenAPI Generator needs. I’ll install a headless JRE and rerun generation.", - "internal.retry_count.preflight_lint": 0, "graph.goal": "---\ntitle: feat: StageProjection agent tools API\ntype: feat\nstatus: active\ndate: 2026-05-24\n---\n\n# feat: StageProjection Agent Tools API\n\n## Overview\n\nExpose 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`.\n\nThe API should expose tool summaries with `name`, `description`, `source`, `category`, and `invoked`. It must not expose full JSON parameter schemas in the run projection.\n\n## Problem Frame\n\nThe 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.\n\nThe 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.\n\n## Requirements Trace\n\n- R1. Add a StageProjection API field containing the complete effective tools for a stage session.\n- R2. Include `name`, `description`, `source`, `category`, and `invoked` for each tool.\n- R3. Do not infer tools from `permission_level` in backend or frontend code.\n- R4. Do not expose full tool parameter schemas through StageProjection.\n- R5. Preserve existing `permission_level` and `mcp_servers` fields for compatibility.\n- R6. Mark individual tools as invoked when matching `agent.tool.started` events are projected.\n- R7. Keep legacy runs backward compatible by defaulting missing tool lists to empty.\n\n## Scope Boundaries\n\n- Do not remove or rename `StageProjection.permission_level`.\n- Do not remove the existing MCP server projection or `AgentMcpToolSummary`.\n- Do not change completion API tool definitions.\n- Do not add ACP-native tool discovery in this pass unless an ACP path already has an equivalent effective tool list available.\n- Do not render parameter schemas in the web UI.\n\n## Context & Research\n\n### Relevant Code and Patterns\n\n- OpenAPI is the source of truth for HTTP contracts in `docs/public/api-reference/fabro-api.yaml`.\n- Shared API/projection DTOs should live in `fabro-types`, with `fabro-api/build.rs` replacements to avoid duplicate generated Rust types.\n- `StageProjection` lives in `lib/crates/fabro-types/src/run_projection.rs`.\n- 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`.\n- Workflow event conversion and event names live in `lib/crates/fabro-workflow/src/event/convert.rs`, `events.rs`, and `names.rs`.\n- Projection replay lives in `lib/crates/fabro-store/src/run_state.rs`.\n- The effective request tool list is built in `lib/crates/fabro-agent/src/session.rs` from `ToolRegistry::definitions_with_source_for_policy`.\n- Tool source metadata already exists as `ToolSource` and `ToolDefinitionWithSource` in `lib/crates/fabro-agent/src/tool_registry.rs`.\n- Tool category mapping already exists in `lib/crates/fabro-agent/src/tool_permissions.rs`.\n- The sidebar display lives in `apps/fabro-web/app/components/stage-insights-sidebar.tsx`.\n\n### Strategy Docs\n\n- Read `docs/internal/events-strategy.md` before adding the new durable event.\n- Read `docs/internal/testing-strategy.md` before adding or reorganizing tests.\n- 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.\n\n## Key Technical Decisions\n\n- Add a new StageProjection field named `agent_tools`, not `tools`, to avoid ambiguity with MCP nested tools and completion tool definitions.\n- Add a dedicated durable event named `agent.tools.available` instead of overloading `agent.session.activated`.\n- Capture the effective tool list after session setup and filtering, using the same path as model request construction.\n- 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.\n- Keep `AgentMcpToolSummary` MCP-only. Add a new general-purpose `AgentToolSummary` instead of stretching the MCP type beyond its meaning.\n- Treat `invoked` as projected state. The availability event should emit tools with `invoked: false`; replay of `agent.tool.started` flips matching tools to true.\n\n## API Contract\n\nAdd these schemas to OpenAPI and map them to `fabro_types` replacements:\n\n- `AgentToolSummary`\n - required: `name`, `description`, `source`, `category`, `invoked`\n - `name`: exposed tool name, e.g. `apply_patch` or `mcp__filesystem__read_file`\n - `description`: model-facing tool description\n - `source`: `AgentToolSource`\n - `category`: `AgentToolCategory`\n - `invoked`: boolean\n- `AgentToolSource`\n - tagged by `kind`\n - `native`\n - `mcp` with `server_name` and `original_name`\n - `skill`\n- `AgentToolCategory`\n - enum: `read`, `write`, `shell`, `subagent`, `other`\n- `AgentToolsAvailableProps`\n - required: `tools`, `visit`\n - `tools`: array of `AgentToolSummary`\n - `visit`: stage visit number\n\nAdd to `StageProjection`:\n\n- `agent_tools`: array of `AgentToolSummary`\n- Default to an empty array when omitted.\n- Skip serializing when empty, matching existing projection optional-list style.\n\nAdd event body:\n\n- Serialized event name: `agent.tools.available`\n- Event body type: `AgentToolsAvailableProps`\n\n## Implementation Units\n\n- [ ] **Unit 1: Add shared tool summary types**\n\n**Goal:** Define the canonical API/projection DTOs in `fabro-types`.\n\n**Files:**\n- Modify: `lib/crates/fabro-types/src/run_event/agent.rs`\n- Modify: `lib/crates/fabro-types/src/run_event/mod.rs`\n- Modify: `lib/crates/fabro-types/src/run_projection.rs`\n- Modify: `lib/crates/fabro-types/src/lib.rs`\n\n**Work:**\n- Add `AgentToolSummary`, `AgentToolSource`, `AgentToolCategory`, and `AgentToolsAvailableProps`.\n- Add `EventBody::AgentToolsAvailable` serialized as `agent.tools.available`.\n- Add `agent_tools: Vec` to `StageProjection`.\n- Ensure all new fields default cleanly for older persisted events/projections.\n- Export the new public types from `fabro-types`.\n\n- [ ] **Unit 2: Capture effective session tools**\n\n**Goal:** Provide an authoritative one-time source for the list that the model can actually call.\n\n**Files:**\n- Modify: `lib/crates/fabro-agent/src/session.rs`\n- Modify: `lib/crates/fabro-workflow/src/handler/llm/api.rs`\n- Modify: `lib/crates/fabro-workflow/src/event/events.rs`\n- Modify: `lib/crates/fabro-workflow/src/event/names.rs`\n- Modify: `lib/crates/fabro-workflow/src/event/convert.rs`\n- Modify: `lib/crates/fabro-workflow/src/event/stored_fields.rs` only if the new event needs non-standard stored fields.\n\n**Work:**\n- Add `Session::available_tools()` that returns the same effective `ToolDefinitionWithSource` list as `build_request()`.\n- Map `ToolDefinitionWithSource` to `AgentToolSummary` at the workflow boundary.\n- Populate `description` from `ToolDefinition.description`.\n- Populate `source` from `ToolSource`.\n- 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.\n- Populate `category` from the existing tool category mapping for known exposed names; use `other` when no category mapping applies.\n- Emit `agent.tools.available` once for the stage session after session setup and filtering are complete.\n\n- [ ] **Unit 3: Project available and invoked tools**\n\n**Goal:** Make `StageProjection.agent_tools` replay-authoritative.\n\n**Files:**\n- Modify: `lib/crates/fabro-store/src/run_state.rs`\n\n**Work:**\n- On `EventBody::AgentToolsAvailable`, replace the current stage visit's `agent_tools` with the event tools.\n- On `EventBody::AgentToolStarted`, find a matching `agent_tools` entry by exposed `tool_name` and set `invoked = true`.\n- Keep the existing MCP server `invoked` update unchanged.\n- If a legacy run has no availability event, do not synthesize a full list from permissions.\n\n- [ ] **Unit 4: Update OpenAPI and generated clients**\n\n**Goal:** Expose the new projection field and event contract through public API clients without duplicate Rust API types.\n\n**Files:**\n- Modify: `docs/public/api-reference/fabro-api.yaml`\n- Modify: `lib/crates/fabro-api/build.rs`\n- Modify: `lib/crates/fabro-api/src/lib.rs`\n- Modify generated files under `lib/crates/fabro-api/src/generated.rs` via `cargo build -p fabro-api`.\n- Modify generated files under `lib/packages/fabro-api-client/src` via TypeScript client generation.\n\n**Work:**\n- Add the OpenAPI schemas listed in the API Contract section.\n- Add `StageProjection.agent_tools`.\n- Add `fabro-api/build.rs` replacements for the new `fabro-types` types.\n- Regenerate Rust API code.\n- Regenerate TypeScript API client code.\n\n- [ ] **Unit 5: Render tools in the web sidebar**\n\n**Goal:** Replace the permission-derived sidebar display with the actual projected tool list.\n\n**Files:**\n- Modify: `apps/fabro-web/app/components/stage-insights-sidebar.tsx`\n- Modify: `apps/fabro-web/app/components/stage-insights-sidebar.test.tsx`\n\n**Work:**\n- Render `stage.agent_tools` when present.\n- Show each tool's name, description, source/category, and invoked state.\n- Keep permission level as secondary metadata or fallback for legacy stages with no `agent_tools`.\n- Do not infer tool availability from permission level.\n\n## Test Plan\n\n- `fabro-types`\n - JSON round-trip for `agent.tools.available`.\n - Serialization checks for `AgentToolSource` and `AgentToolCategory`.\n - Backward compatibility check that missing `agent_tools` deserializes to an empty list.\n\n- `fabro-workflow`\n - Event name and conversion tests for `agent.tools.available`.\n - Capture test proving native tools such as `apply_patch`, `grep`, and `glob` are emitted from the effective registry path.\n - MCP source mapping test for a qualified MCP tool name.\n\n- `fabro-store`\n - Projection test that `agent.tools.available` populates `StageProjection.agent_tools`.\n - Projection test that `agent.tool.started` marks only the matching tool as invoked.\n - Regression test that MCP server `invoked` status still updates as before.\n\n- `fabro-api`\n - Type identity/parity tests confirming API types reuse `fabro_types::AgentToolSummary`, `AgentToolSource`, `AgentToolCategory`, and `AgentToolsAvailableProps`.\n - StageProjection round-trip test including `agent_tools`.\n\n- `fabro-web`\n - Sidebar test rendering tool names and descriptions from `stage.agent_tools`.\n - Sidebar test showing invoked state.\n - Legacy fallback test for stages without `agent_tools`.\n\n## Run Checks\n\n- `cargo +nightly-2026-04-14 fmt --check --all`\n- `cargo nextest run -p fabro-types -p fabro-workflow -p fabro-store -p fabro-api`\n- `cargo build -p fabro-api`\n- `cd lib/packages/fabro-api-client && bun run generate`\n- `cd apps/fabro-web && bun test && bun run typecheck`\n\n## Assumptions\n\n- The first implementation targets normal API-backed agent sessions, not ACP-native sessions.\n- `description` is safe to expose because it is already model-facing tool metadata, but parameter schemas remain out of scope for StageProjection.\n- `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.\n- If tool registration becomes mutable later, the event contract can be re-emitted and projection replacement semantics will still work.\n", + "graph.rankdir": "LR", "command.output": "blob://sha256/12ae32cb1ec02d01eda3581b127c1fee3b0dc53572ed6baf239721a03d82e126", - "last_stage": "simplify_opus", - "internal.thread_id": "implement", - "thread.start.current_node": "toolchain", - "thread.preflight_compile.current_node": "preflight_lint", - "internal.node_visit_count": 1, - "thread.toolchain.current_node": "preflight_compile", - "thread.preflight_lint.current_node": "implement", - "last_response": "## Summary\n\nAggregated three review agents' findings and applied the consensus high-value fixes:\n\n**Quality / reuse fixes:**\n- `tool_permissions::known_tool_category` now returns `Option` directly. Deleted the brittle `Some(\"read\")` → `Read` string match in `handler/llm/api.rs`. `is_auto_approved` and `tool_category` are now enum-typed end-to-end; cli.rs and its tests updated accordingly. Adding a new category is now a compile-time exhaustiveness error instead of a silent `Other`.\n- `ToolSource::Mcp` now carries `original_name` populated from `info.original_tool_name` in `make_mcp_tools`. Workflow code no longer re-parses qualified MCP names (eliminates the silent fallback bug where a malformed prefix would store the qualified name as \"original\").\n- Moved `agent_tool_source` + `agent_tool_summaries_from_definitions` out of `handler/llm/api.rs`. New `ToolDefinitionWithSource::to_agent_tool_summary()` + `Session::agent_tool_summaries()` colocate the conversion next to the source type. Tests moved to `tool_registry.rs`.\n- Collapsed `Session::available_tools` and the duplicate private `effective_tools` into one public `effective_tools()` method.\n- Merged `ToolAvailableIcon` and `TodoPendingIcon` into a single `EmptyCircleIcon` component in the sidebar.\n\n**Efficiency fix:**\n- Gated `emit_agent_tools_available` on `!is_reused` in the primary path. Reused steerable sessions had been re-emitting the full tool list (with descriptions cloned into the event payload) on every prompt even though registry, access policy, and exposure mode are immutable for the session's lifetime. Failover path keeps its emit since it always builds a fresh session.\n\n**Skipped (cost > benefit):** `mcp_server_from_tool_name` dedup in `fabro-store` would require pulling `fabro-mcp` (with `rmcp`) into the store crate or relocating the parse helper into `fabro-types`. The duplicate is 5 lines using the same delimiter convention — not worth the dependency surface.\n\n**Verification:** `cargo check --workspace --all-targets`, `cargo +nightly-2026-04-14 clippy --workspace --all-targets -- -D warnings`, `cargo +nightly-2026-04-14 fmt --check --all`, `cargo nextest run -p fabro-types -p fabro-workflow -p fabro-store -p fabro-api -p fabro-agent` (2250+464 tests), `bun test stage-insights-sidebar` (10/10), and `bun run typecheck` all pass. The 14 unrelated `run-actions.test.ts` failures pre-exist on the parent commit.", + "last_response": "## Summary\n\nAggregated three review agents' findings and applied the consensus high-value fixes:\n\n**Quality / reuse fixes:**\n- `tool_permissions::known_tool_category` now returns `Option&1", + "usage": null + }, + "preflight_lint": { + "status": "succeeded", + "context_updates": { + "command.output": "blob://sha256/12ae32cb1ec02d01eda3581b127c1fee3b0dc53572ed6baf239721a03d82e126" + }, + "notes": "Script completed: cargo +nightly-2026-04-14 clippy -q --workspace --all-targets -- -D warnings 2>&1", "usage": null }, "simplify_opus": { @@ -949,6 +961,152 @@ "/home/daytona/workspace/fabro/lib/crates/fabro-workflow/src/handler/llm/api.rs" ] }, + "start": { + "status": "succeeded", + "usage": null + }, + "toolchain": { + "status": "succeeded", + "context_updates": { + "command.output": "blob://sha256/fc14b2ba2d770e5cd3169df7a29525c962adfc4cfa3097b9098c63ebd61a748c" + }, + "notes": "Script completed: 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", + "usage": null + }, + "implement": { + "status": "succeeded", + "context_updates": { + "last_stage": "implement", + "last_response": "The TS generator is pinned now, but this sandbox lacks Java, which OpenAPI Generator needs. I’ll install a headless JRE and rerun generation.", + "response.implement": "The TS generator is pinned now, but this sandbox lacks Java, which OpenAPI Generator needs. I’ll install a headless JRE and rerun generation." + }, + "notes": "Stage completed: implement", + "usage": { + "input": { + "usage": { + "model": { + "provider": "openai", + "model_id": "gpt-5.5" + }, + "tokens": { + "input_tokens": 6711598, + "output_tokens": 22676, + "reasoning_tokens": 11522, + "cache_read_tokens": 16107008, + "cache_write_tokens": 0 + } + }, + "facts": { + "algorithm": "openai" + } + }, + "total_usd_micros": 42637434 + } + } + }, + "next_node_id": "simplify_gpt", + "git_commit_sha": "dcf957fbeeebb961509a88854e12dd241029a52e", + "node_visits": { + "implement": 1, + "start": 1, + "simplify_opus": 1, + "preflight_compile": 1, + "preflight_lint": 1, + "toolchain": 1 + } + }, + "diff": { + "patch": "diff --git a/apps/fabro-web/app/components/stage-insights-sidebar.tsx b/apps/fabro-web/app/components/stage-insights-sidebar.tsx\nindex 135f1dd72..1b534c181 100644\n--- a/apps/fabro-web/app/components/stage-insights-sidebar.tsx\n+++ b/apps/fabro-web/app/components/stage-insights-sidebar.tsx\n@@ -283,13 +283,18 @@ function todoStatusVisual(status: TodoStatus): { Icon: IconType; color: string;\n return { Icon: XCircleIcon, color: \"text-fg-muted\", srLabel: \"Deleted\" };\n case TodoStatus.PENDING:\n default:\n- return { Icon: TodoPendingIcon, color: \"text-fg-muted\", srLabel: \"Pending\" };\n+ return { Icon: EmptyCircleIcon, color: \"text-fg-muted\", srLabel: \"Pending\" };\n }\n }\n \n-/** Empty circle for pending todos (matches Tailwind sizing). */\n-function TodoPendingIcon({ className }: { className?: string }) {\n- return ;\n+/** Empty circle for pending/available states (matches Tailwind sizing). */\n+function EmptyCircleIcon({ className }: { className?: string }) {\n+ return (\n+ \n+ );\n }\n \n // ---------- Context window ----------\n@@ -529,7 +534,7 @@ function AgentToolsSection({ tools }: { tools: AgentToolSummary[] }) {\n {tool.invoked ? (\n \n ) : (\n- \n+ \n )}\n {tool.name}\n \n@@ -564,10 +569,6 @@ function toolSourceLabel(source: AgentToolSummary[\"source\"]): string {\n }\n }\n \n-function ToolAvailableIcon({ className }: { className?: string }) {\n- return ;\n-}\n-\n // ---------- MCPs ----------\n \n function McpSection({ servers }: { servers: McpServerProjection[] }) {\ndiff --git a/lib/crates/fabro-agent/src/cli.rs b/lib/crates/fabro-agent/src/cli.rs\nindex b736fdb3f..e3e874803 100644\n--- a/lib/crates/fabro-agent/src/cli.rs\n+++ b/lib/crates/fabro-agent/src/cli.rs\n@@ -93,7 +93,7 @@ pub enum OutputFormat {\n Json,\n }\n \n-pub use fabro_types::PermissionLevel;\n+pub use fabro_types::{AgentToolCategory, PermissionLevel};\n \n impl AgentArgs {\n /// Fill `None` fields from settings.toml values, then hardcoded defaults.\n@@ -155,6 +155,8 @@ fn build_tool_approval(\n \"Allow {} ({category})? [y]es / [n]o / [a]lways: \",\n styles.bold.apply_to(tool_name),\n );\n+ // `AgentToolCategory` derives strum::Display so it renders as the\n+ // canonical snake_case label (e.g. \"read\", \"write\").\n std::io::stderr().flush().ok();\n \n let mut input = String::new();\n@@ -166,7 +168,7 @@ fn build_tool_approval(\n \"y\" | \"yes\" => Ok(()),\n \"a\" | \"always\" => {\n let mut lvl = level.lock().expect(\"permission lock poisoned\");\n- *lvl = if category == \"write\" {\n+ *lvl = if category == AgentToolCategory::Write {\n PermissionLevel::ReadWrite\n } else {\n PermissionLevel::Full\n@@ -816,62 +818,98 @@ mod tests {\n \n #[test]\n fn tool_category_read_tools() {\n- assert_eq!(tool_category(\"read_file\"), \"read\");\n- assert_eq!(tool_category(\"read_many_files\"), \"read\");\n- assert_eq!(tool_category(\"grep\"), \"read\");\n- assert_eq!(tool_category(\"glob\"), \"read\");\n- assert_eq!(tool_category(\"list_dir\"), \"read\");\n+ assert_eq!(tool_category(\"read_file\"), AgentToolCategory::Read);\n+ assert_eq!(tool_category(\"read_many_files\"), AgentToolCategory::Read);\n+ assert_eq!(tool_category(\"grep\"), AgentToolCategory::Read);\n+ assert_eq!(tool_category(\"glob\"), AgentToolCategory::Read);\n+ assert_eq!(tool_category(\"list_dir\"), AgentToolCategory::Read);\n }\n \n #[test]\n fn tool_category_write_tools() {\n- assert_eq!(tool_category(\"write_file\"), \"write\");\n- assert_eq!(tool_category(\"edit_file\"), \"write\");\n- assert_eq!(tool_category(\"apply_patch\"), \"write\");\n+ assert_eq!(tool_category(\"write_file\"), AgentToolCategory::Write);\n+ assert_eq!(tool_category(\"edit_file\"), AgentToolCategory::Write);\n+ assert_eq!(tool_category(\"apply_patch\"), AgentToolCategory::Write);\n }\n \n #[test]\n fn tool_category_shell() {\n- assert_eq!(tool_category(\"shell\"), \"shell\");\n+ assert_eq!(tool_category(\"shell\"), AgentToolCategory::Shell);\n }\n \n #[test]\n fn tool_category_subagent_tools() {\n- assert_eq!(tool_category(\"spawn_agent\"), \"subagent\");\n- assert_eq!(tool_category(\"send_input\"), \"subagent\");\n- assert_eq!(tool_category(\"wait\"), \"subagent\");\n- assert_eq!(tool_category(\"close_agent\"), \"subagent\");\n+ assert_eq!(tool_category(\"spawn_agent\"), AgentToolCategory::Subagent);\n+ assert_eq!(tool_category(\"send_input\"), AgentToolCategory::Subagent);\n+ assert_eq!(tool_category(\"wait\"), AgentToolCategory::Subagent);\n+ assert_eq!(tool_category(\"close_agent\"), AgentToolCategory::Subagent);\n }\n \n #[test]\n fn tool_category_unknown_defaults_to_shell() {\n- assert_eq!(tool_category(\"some_random_tool\"), \"shell\");\n+ assert_eq!(tool_category(\"some_random_tool\"), AgentToolCategory::Shell);\n }\n \n // is_auto_approved tests\n \n #[test]\n fn is_auto_approved_read_only() {\n- assert!(is_auto_approved(PermissionLevel::ReadOnly, \"read\"));\n- assert!(is_auto_approved(PermissionLevel::ReadOnly, \"subagent\"));\n- assert!(!is_auto_approved(PermissionLevel::ReadOnly, \"write\"));\n- assert!(!is_auto_approved(PermissionLevel::ReadOnly, \"shell\"));\n+ assert!(is_auto_approved(\n+ PermissionLevel::ReadOnly,\n+ AgentToolCategory::Read\n+ ));\n+ assert!(is_auto_approved(\n+ PermissionLevel::ReadOnly,\n+ AgentToolCategory::Subagent\n+ ));\n+ assert!(!is_auto_approved(\n+ PermissionLevel::ReadOnly,\n+ AgentToolCategory::Write\n+ ));\n+ assert!(!is_auto_approved(\n+ PermissionLevel::ReadOnly,\n+ AgentToolCategory::Shell\n+ ));\n }\n \n #[test]\n fn is_auto_approved_read_write() {\n- assert!(is_auto_approved(PermissionLevel::ReadWrite, \"read\"));\n- assert!(is_auto_approved(PermissionLevel::ReadWrite, \"subagent\"));\n- assert!(is_auto_approved(PermissionLevel::ReadWrite, \"write\"));\n- assert!(!is_auto_approved(PermissionLevel::ReadWrite, \"shell\"));\n+ assert!(is_auto_approved(\n+ PermissionLevel::ReadWrite,\n+ AgentToolCategory::Read\n+ ));\n+ assert!(is_auto_approved(\n+ PermissionLevel::ReadWrite,\n+ AgentToolCategory::Subagent\n+ ));\n+ assert!(is_auto_approved(\n+ PermissionLevel::ReadWrite,\n+ AgentToolCategory::Write\n+ ));\n+ assert!(!is_auto_approved(\n+ PermissionLevel::ReadWrite,\n+ AgentToolCategory::Shell\n+ ));\n }\n \n #[test]\n fn is_auto_approved_full() {\n- assert!(is_auto_approved(PermissionLevel::Full, \"read\"));\n- assert!(is_auto_approved(PermissionLevel::Full, \"subagent\"));\n- assert!(is_auto_approved(PermissionLevel::Full, \"write\"));\n- assert!(is_auto_approved(PermissionLevel::Full, \"shell\"));\n+ assert!(is_auto_approved(\n+ PermissionLevel::Full,\n+ AgentToolCategory::Read\n+ ));\n+ assert!(is_auto_approved(\n+ PermissionLevel::Full,\n+ AgentToolCategory::Subagent\n+ ));\n+ assert!(is_auto_approved(\n+ PermissionLevel::Full,\n+ AgentToolCategory::Write\n+ ));\n+ assert!(is_auto_approved(\n+ PermissionLevel::Full,\n+ AgentToolCategory::Shell\n+ ));\n }\n \n // build_tool_approval non-interactive tests\ndiff --git a/lib/crates/fabro-agent/src/context_window.rs b/lib/crates/fabro-agent/src/context_window.rs\nindex da8da9d72..88dcc616b 100644\n--- a/lib/crates/fabro-agent/src/context_window.rs\n+++ b/lib/crates/fabro-agent/src/context_window.rs\n@@ -382,7 +382,8 @@ mod tests {\n let tools = vec![\n tool(\"read_file\", ToolSource::Native),\n tool(\"mcp__server__search\", ToolSource::Mcp {\n- server_name: \"server\".to_string(),\n+ server_name: \"server\".to_string(),\n+ original_name: \"search\".to_string(),\n }),\n tool(\"use_skill\", ToolSource::Skill),\n ];\ndiff --git a/lib/crates/fabro-agent/src/mcp_integration.rs b/lib/crates/fabro-agent/src/mcp_integration.rs\nindex e839ef4e3..65787f448 100644\n--- a/lib/crates/fabro-agent/src/mcp_integration.rs\n+++ b/lib/crates/fabro-agent/src/mcp_integration.rs\n@@ -15,6 +15,7 @@ pub fn make_mcp_tools(manager: &Arc) -> Vec) -> Vec Vec {\n- self.effective_tools()\n+ pub fn effective_tools(&self) -> Vec {\n+ self.provider_profile\n+ .tool_registry()\n+ .definitions_with_source_for_policy(\n+ self.config.tool_access_policy.as_deref(),\n+ self.config.tool_exposure_mode,\n+ )\n+ }\n+\n+ /// Public projection of `effective_tools()` for\n+ /// `StageProjection.agent_tools` and the `agent.tools.available` event.\n+ /// Sorted by name for deterministic snapshots; the underlying registry\n+ /// stores tools in a `HashMap`.\n+ #[must_use]\n+ pub fn agent_tool_summaries(&self) -> Vec {\n+ let mut summaries: Vec<_> = self\n+ .effective_tools()\n+ .iter()\n+ .map(ToolDefinitionWithSource::to_agent_tool_summary)\n+ .collect();\n+ summaries.sort_by(|left, right| left.name.cmp(&right.name));\n+ summaries\n }\n \n /// Initialize session by discovering project docs and capturing environment\n@@ -2021,15 +2044,6 @@ impl Session {\n });\n }\n }\n-\n- fn effective_tools(&self) -> Vec {\n- self.provider_profile\n- .tool_registry()\n- .definitions_with_source_for_policy(\n- self.config.tool_access_policy.as_deref(),\n- self.config.tool_exposure_mode,\n- )\n- }\n }\n \n const fn is_auth_error(err: &LlmError) -> bool {\n@@ -3281,7 +3295,7 @@ mod tests {\n }\n \n #[tokio::test]\n- async fn available_tools_uses_same_effective_registry_filter_as_requests() {\n+ async fn effective_tools_match_request_tool_filtering() {\n let provider = Arc::new(CapturingLlmProvider::new());\n let client = make_client(provider as Arc).await;\n let mut registry = ToolRegistry::new();\n@@ -3301,7 +3315,7 @@ mod tests {\n };\n let session = Session::new(client, profile, env, config, None);\n \n- let tools = session.available_tools();\n+ let tools = session.effective_tools();\n let mut tool_names: Vec<&str> = tools\n .iter()\n .map(|tool| tool.definition.name.as_str())\ndiff --git a/lib/crates/fabro-agent/src/tool_permissions.rs b/lib/crates/fabro-agent/src/tool_permissions.rs\nindex b22dba945..a56d17e08 100644\n--- a/lib/crates/fabro-agent/src/tool_permissions.rs\n+++ b/lib/crates/fabro-agent/src/tool_permissions.rs\n@@ -1,25 +1,35 @@\n-use fabro_types::PermissionLevel;\n+use fabro_types::{AgentToolCategory, PermissionLevel};\n \n-pub fn tool_category(name: &str) -> &'static str {\n- known_tool_category(name).unwrap_or(\"shell\")\n-}\n-\n-pub fn known_tool_category(name: &str) -> Option<&'static str> {\n+/// Coarse access category for an exposed tool. Returns `None` for unknown\n+/// names so callers can decide whether to default (legacy CLI permission\n+/// gate) or surface a distinct \"other\" category (projection metadata).\n+pub fn known_tool_category(name: &str) -> Option {\n match name {\n- \"read_file\" | \"read_many_files\" | \"grep\" | \"glob\" | \"list_dir\" => Some(\"read\"),\n- \"write_file\" | \"edit_file\" | \"apply_patch\" => Some(\"write\"),\n- \"shell\" => Some(\"shell\"),\n- \"spawn_agent\" | \"send_input\" | \"wait\" | \"close_agent\" => Some(\"subagent\"),\n+ \"read_file\" | \"read_many_files\" | \"grep\" | \"glob\" | \"list_dir\" => {\n+ Some(AgentToolCategory::Read)\n+ }\n+ \"write_file\" | \"edit_file\" | \"apply_patch\" => Some(AgentToolCategory::Write),\n+ \"shell\" => Some(AgentToolCategory::Shell),\n+ \"spawn_agent\" | \"send_input\" | \"wait\" | \"close_agent\" => Some(AgentToolCategory::Subagent),\n _ => None,\n }\n }\n \n-pub fn is_auto_approved(level: PermissionLevel, category: &str) -> bool {\n+/// CLI permission gate category. Unknown tools fall back to `Shell` so they\n+/// require explicit user approval at any permission level below `Full`.\n+pub fn tool_category(name: &str) -> AgentToolCategory {\n+ known_tool_category(name).unwrap_or(AgentToolCategory::Shell)\n+}\n+\n+pub fn is_auto_approved(level: PermissionLevel, category: AgentToolCategory) -> bool {\n matches!(\n (level, category),\n- (_, \"read\" | \"subagent\")\n- | (PermissionLevel::ReadWrite | PermissionLevel::Full, \"write\")\n- | (PermissionLevel::Full, \"shell\")\n+ (_, AgentToolCategory::Read | AgentToolCategory::Subagent)\n+ | (\n+ PermissionLevel::ReadWrite | PermissionLevel::Full,\n+ AgentToolCategory::Write,\n+ )\n+ | (PermissionLevel::Full, AgentToolCategory::Shell)\n )\n }\n \ndiff --git a/lib/crates/fabro-agent/src/tool_registry.rs b/lib/crates/fabro-agent/src/tool_registry.rs\nindex 3e43d7e34..74af24354 100644\n--- a/lib/crates/fabro-agent/src/tool_registry.rs\n+++ b/lib/crates/fabro-agent/src/tool_registry.rs\n@@ -4,11 +4,13 @@ use std::pin::Pin;\n use std::sync::Arc;\n \n use fabro_llm::types::ToolDefinition;\n+use fabro_types::{AgentToolCategory, AgentToolSource, AgentToolSummary};\n use tokio_util::sync::CancellationToken;\n \n use crate::config::{ToolAccessPolicy, ToolExposureMode};\n use crate::sandbox::Sandbox;\n use crate::session::ToolEnvProvider;\n+use crate::tool_permissions;\n use crate::types::AgentEvent;\n \n /// Narrow handle a tool uses to publish typed agent events (e.g. todo\n@@ -72,8 +74,13 @@ pub struct RegisteredTool {\n pub enum ToolSource {\n #[default]\n Native,\n+ /// `original_name` is the raw upstream MCP tool name (before the\n+ /// `mcp____` qualification applied by `fabro_mcp`). It is\n+ /// supplied by the MCP integration that registers the tool, so consumers\n+ /// never need to re-parse the qualified name.\n Mcp {\n- server_name: String,\n+ server_name: String,\n+ original_name: String,\n },\n Skill,\n }\n@@ -84,6 +91,39 @@ pub struct ToolDefinitionWithSource {\n pub source: ToolSource,\n }\n \n+impl ToolDefinitionWithSource {\n+ /// Project this tool into the public `AgentToolSummary` used by\n+ /// `StageProjection.agent_tools` and the `agent.tools.available` event.\n+ /// Drops the parameter schema; `invoked` defaults to `false` and is set\n+ /// by the projection reducer when matching `agent.tool.started` events\n+ /// replay.\n+ #[must_use]\n+ pub fn to_agent_tool_summary(&self) -> AgentToolSummary {\n+ AgentToolSummary {\n+ name: self.definition.name.clone(),\n+ description: self.definition.description.clone(),\n+ source: agent_tool_source(&self.source),\n+ category: tool_permissions::known_tool_category(&self.definition.name)\n+ .unwrap_or(AgentToolCategory::Other),\n+ invoked: false,\n+ }\n+ }\n+}\n+\n+fn agent_tool_source(source: &ToolSource) -> AgentToolSource {\n+ match source {\n+ ToolSource::Native => AgentToolSource::Native,\n+ ToolSource::Mcp {\n+ server_name,\n+ original_name,\n+ } => AgentToolSource::Mcp {\n+ server_name: server_name.clone(),\n+ original_name: original_name.clone(),\n+ },\n+ ToolSource::Skill => AgentToolSource::Skill,\n+ }\n+}\n+\n pub struct ToolRegistry {\n tools: HashMap,\n }\n@@ -385,4 +425,59 @@ mod tests {\n assert!(registry.names().is_empty());\n assert!(registry.definitions().is_empty());\n }\n+\n+ fn tool_with_source(name: &str, source: ToolSource) -> ToolDefinitionWithSource {\n+ ToolDefinitionWithSource {\n+ definition: ToolDefinition {\n+ name: name.to_string(),\n+ description: format!(\"{name} description\"),\n+ parameters: serde_json::json!({\n+ \"type\": \"object\",\n+ \"properties\": { \"path\": { \"type\": \"string\" } }\n+ }),\n+ },\n+ source,\n+ }\n+ }\n+\n+ #[test]\n+ fn to_agent_tool_summary_maps_known_native_categories_and_drops_parameters() {\n+ let cases = [\n+ (\"apply_patch\", AgentToolCategory::Write),\n+ (\"grep\", AgentToolCategory::Read),\n+ (\"glob\", AgentToolCategory::Read),\n+ (\"spawn_agent\", AgentToolCategory::Subagent),\n+ (\"shell\", AgentToolCategory::Shell),\n+ (\"unknown_native\", AgentToolCategory::Other),\n+ ];\n+ for (name, expected) in cases {\n+ let summary = tool_with_source(name, ToolSource::Native).to_agent_tool_summary();\n+ assert_eq!(summary.name, name);\n+ assert_eq!(summary.description, format!(\"{name} description\"));\n+ assert_eq!(summary.source, AgentToolSource::Native);\n+ assert_eq!(summary.category, expected);\n+ assert!(!summary.invoked);\n+\n+ let json = serde_json::to_value(&summary).unwrap();\n+ assert!(\n+ json.as_object().unwrap().get(\"parameters\").is_none(),\n+ \"agent tool summaries must not include parameter schemas\"\n+ );\n+ }\n+ }\n+\n+ #[test]\n+ fn to_agent_tool_summary_carries_mcp_original_name_from_source() {\n+ let summary = tool_with_source(\"mcp__filesystem__read_file\", ToolSource::Mcp {\n+ server_name: \"filesystem\".to_string(),\n+ original_name: \"read_file\".to_string(),\n+ })\n+ .to_agent_tool_summary();\n+\n+ assert_eq!(summary.source, AgentToolSource::Mcp {\n+ server_name: \"filesystem\".to_string(),\n+ original_name: \"read_file\".to_string(),\n+ });\n+ assert_eq!(summary.category, AgentToolCategory::Other);\n+ }\n }\ndiff --git a/lib/crates/fabro-workflow/src/handler/llm/api.rs b/lib/crates/fabro-workflow/src/handler/llm/api.rs\nindex 135b5e3b7..8fcdf32c2 100644\n--- a/lib/crates/fabro-workflow/src/handler/llm/api.rs\n+++ b/lib/crates/fabro-workflow/src/handler/llm/api.rs\n@@ -3,13 +3,11 @@ use std::sync::{Arc, Mutex};\n \n use async_trait::async_trait;\n use fabro_agent::subagent::{SessionFactory, SubAgentManager};\n-use fabro_agent::tool_registry::{\n- RegisteredTool, ToolContext, ToolDefinitionWithSource, ToolRegistry, ToolSource,\n-};\n+use fabro_agent::tool_registry::{RegisteredTool, ToolContext, ToolRegistry, ToolSource};\n use fabro_agent::{\n AgentEvent, AgentProfile, AnthropicProfile, CompletionCoordinator, GeminiProfile,\n Message as AgentMessage, OpenAiProfile, Sandbox, Session, SessionOptions, StaticEnvProvider,\n- ToolEnvProvider, register_question_tools, tool_permissions,\n+ ToolEnvProvider, register_question_tools,\n };\n use fabro_auth::{CredentialSource, EnvCredentialSource};\n use fabro_graphviz::graph::{AttrValue, Node};\n@@ -23,10 +21,7 @@ use fabro_mcp::config::McpServerSettings;\n use fabro_model::catalog::LlmCatalogSettings;\n use fabro_model::{AgentProfileKind, Catalog, FallbackTarget, ModelRef, ProviderId};\n use fabro_types::settings::run::RunModelControls;\n-use fabro_types::{\n- AgentToolCategory, AgentToolSource, AgentToolSummary, PermissionLevel, RunId,\n- SessionCapability, StageId,\n-};\n+use fabro_types::{PermissionLevel, RunId, SessionCapability, StageId};\n use serde::de::DeserializeOwned;\n use tokio::sync::Mutex as TokioMutex;\n use tokio::task::JoinHandle;\n@@ -501,58 +496,17 @@ fn last_assistant_response(session: &Session) -> String {\n .unwrap_or_default()\n }\n \n-fn agent_tool_summaries_from_definitions(\n- tools: &[ToolDefinitionWithSource],\n-) -> Vec {\n- let mut summaries: Vec<_> = tools\n- .iter()\n- .map(|tool| AgentToolSummary {\n- name: tool.definition.name.clone(),\n- description: tool.definition.description.clone(),\n- source: agent_tool_source(&tool.definition.name, &tool.source),\n- category: agent_tool_category(&tool.definition.name),\n- invoked: false,\n- })\n- .collect();\n- summaries.sort_by(|left, right| left.name.cmp(&right.name));\n- summaries\n-}\n-\n-fn agent_tool_source(name: &str, source: &ToolSource) -> AgentToolSource {\n- match source {\n- ToolSource::Native => AgentToolSource::Native,\n- ToolSource::Mcp { server_name } => AgentToolSource::Mcp {\n- server_name: server_name.clone(),\n- original_name: fabro_mcp::connection_manager::parse_qualified_name(name)\n- .map(|(_, original_name)| original_name)\n- .unwrap_or_else(|| name.to_string()),\n- },\n- ToolSource::Skill => AgentToolSource::Skill,\n- }\n-}\n-\n-fn agent_tool_category(name: &str) -> AgentToolCategory {\n- match tool_permissions::known_tool_category(name) {\n- Some(\"read\") => AgentToolCategory::Read,\n- Some(\"write\") => AgentToolCategory::Write,\n- Some(\"shell\") => AgentToolCategory::Shell,\n- Some(\"subagent\") => AgentToolCategory::Subagent,\n- Some(_) | None => AgentToolCategory::Other,\n- }\n-}\n-\n fn emit_agent_tools_available(\n session: &Session,\n node_id: &str,\n stage_id: &StageId,\n emitter: &Arc,\n ) {\n- let tools = agent_tool_summaries_from_definitions(&session.available_tools());\n emitter.emit(&Event::AgentToolsAvailable {\n- node_id: node_id.to_string(),\n- visit: stage_id.visit(),\n+ node_id: node_id.to_string(),\n+ visit: stage_id.visit(),\n session_id: session.id().to_string(),\n- tools,\n+ tools: session.agent_tool_summaries(),\n });\n }\n \n@@ -1257,7 +1211,13 @@ impl CodergenBackend for AgentApiBackend {\n return Err(err);\n }\n }\n- emit_agent_tools_available(&session, &node.id, &stage_id, emitter);\n+ // Reused steerable sessions already emitted their effective\n+ // tool list on first activation; the registry, access policy,\n+ // and exposure mode are immutable for the session's lifetime,\n+ // so re-emitting on every subsequent prompt is wasted work.\n+ if !is_reused {\n+ emit_agent_tools_available(&session, &node.id, &stage_id, emitter);\n+ }\n session\n .process_input_with_runtime(prompt, agent_tool_runtime.clone())\n .await\n@@ -1562,7 +1522,6 @@ mod tests {\n \n use chrono::TimeZone;\n use fabro_agent::subagent::SessionFactory;\n- use fabro_agent::tool_registry::ToolDefinitionWithSource;\n use fabro_agent::{AgentProfile, LocalSandbox, ToolRegistry};\n use fabro_api::types;\n use fabro_auth::{EnvCredentialSource, VaultCredentialSource};\n@@ -1629,68 +1588,6 @@ mod tests {\n }\n }\n \n- fn test_tool_with_source(name: &str, source: ToolSource) -> ToolDefinitionWithSource {\n- ToolDefinitionWithSource {\n- definition: LlmToolDefinition {\n- name: name.to_string(),\n- description: format!(\"{name} description\"),\n- parameters: serde_json::json!({\n- \"type\": \"object\",\n- \"properties\": {\n- \"path\": { \"type\": \"string\" }\n- }\n- }),\n- },\n- source,\n- }\n- }\n-\n- #[test]\n- fn agent_tool_summaries_map_known_native_categories_without_schemas() {\n- let summaries = agent_tool_summaries_from_definitions(&[\n- test_tool_with_source(\"apply_patch\", ToolSource::Native),\n- test_tool_with_source(\"grep\", ToolSource::Native),\n- test_tool_with_source(\"glob\", ToolSource::Native),\n- test_tool_with_source(\"spawn_agent\", ToolSource::Native),\n- test_tool_with_source(\"unknown_native\", ToolSource::Native),\n- ]);\n-\n- assert_eq!(summaries[0].name, \"apply_patch\");\n- assert_eq!(summaries[0].description, \"apply_patch description\");\n- assert_eq!(summaries[0].source, fabro_types::AgentToolSource::Native);\n- assert_eq!(summaries[0].category, fabro_types::AgentToolCategory::Write);\n- assert!(!summaries[0].invoked);\n- assert_eq!(summaries[1].category, fabro_types::AgentToolCategory::Read);\n- assert_eq!(summaries[2].category, fabro_types::AgentToolCategory::Read);\n- assert_eq!(\n- summaries[3].category,\n- fabro_types::AgentToolCategory::Subagent\n- );\n- assert_eq!(summaries[4].category, fabro_types::AgentToolCategory::Other);\n-\n- let json = serde_json::to_value(&summaries[0]).unwrap();\n- assert!(\n- json.as_object().unwrap().get(\"parameters\").is_none(),\n- \"agent tool summaries should not include tool parameter schemas\"\n- );\n- }\n-\n- #[test]\n- fn agent_tool_summaries_map_mcp_source_and_original_name_from_qualified_name() {\n- let summaries = agent_tool_summaries_from_definitions(&[test_tool_with_source(\n- \"mcp__filesystem__read_file\",\n- ToolSource::Mcp {\n- server_name: \"filesystem\".to_string(),\n- },\n- )]);\n-\n- assert_eq!(summaries[0].source, fabro_types::AgentToolSource::Mcp {\n- server_name: \"filesystem\".to_string(),\n- original_name: \"read_file\".to_string(),\n- });\n- assert_eq!(summaries[0].category, fabro_types::AgentToolCategory::Other);\n- }\n-\n struct ShutdownTestProvider;\n \n #[async_trait]\n", + "summary": { + "files_changed": 33, + "additions": 1187, + "deletions": 79 + } + } + }, + { + "seq": 0, + "checkpoint": { + "timestamp": "2026-05-24T18:01:06.599189Z", + "current_node": "simplify_gpt", + "completed_nodes": [ + "start", + "toolchain", + "preflight_compile", + "preflight_lint", + "implement", + "simplify_opus", + "simplify_gpt" + ], + "node_retries": {}, + "context_values": { + "graph.rankdir": "LR", + "graph.model_stylesheet": "\n * { model: claude-opus-4-7; }\n ", + "internal.retry_count.start": 0, + "internal.fidelity": "compact", + "failure_signature": "", + "internal.retry_count.toolchain": 0, + "internal.retry_count.preflight_compile": 0, + "thread.implement.current_node": "simplify_opus", + "internal.retry_count.simplify_gpt": 0, + "outcome": "succeeded", + "failure_class": "", + "response.simplify_opus": "## Summary\n\nAggregated three review agents' findings and applied the consensus high-value fixes:\n\n**Quality / reuse fixes:**\n- `tool_permissions::known_tool_category` now returns `Option` directly. Deleted the brittle `Some(\"read\")` → `Read` string match in `handler/llm/api.rs`. `is_auto_approved` and `tool_category` are now enum-typed end-to-end; cli.rs and its tests updated accordingly. Adding a new category is now a compile-time exhaustiveness error instead of a silent `Other`.\n- `ToolSource::Mcp` now carries `original_name` populated from `info.original_tool_name` in `make_mcp_tools`. Workflow code no longer re-parses qualified MCP names (eliminates the silent fallback bug where a malformed prefix would store the qualified name as \"original\").\n- Moved `agent_tool_source` + `agent_tool_summaries_from_definitions` out of `handler/llm/api.rs`. New `ToolDefinitionWithSource::to_agent_tool_summary()` + `Session::agent_tool_summaries()` colocate the conversion next to the source type. Tests moved to `tool_registry.rs`.\n- Collapsed `Session::available_tools` and the duplicate private `effective_tools` into one public `effective_tools()` method.\n- Merged `ToolAvailableIcon` and `TodoPendingIcon` into a single `EmptyCircleIcon` component in the sidebar.\n\n**Efficiency fix:**\n- Gated `emit_agent_tools_available` on `!is_reused` in the primary path. Reused steerable sessions had been re-emitting the full tool list (with descriptions cloned into the event payload) on every prompt even though registry, access policy, and exposure mode are immutable for the session's lifetime. Failover path keeps its emit since it always builds a fresh session.\n\n**Skipped (cost > benefit):** `mcp_server_from_tool_name` dedup in `fabro-store` would require pulling `fabro-mcp` (with `rmcp`) into the store crate or relocating the parse helper into `fabro-types`. The duplicate is 5 lines using the same delimiter convention — not worth the dependency surface.\n\n**Verification:** `cargo check --workspace --all-targets`, `cargo +nightly-2026-04-14 clippy --workspace --all-targets -- -D warnings`, `cargo +nightly-2026-04-14 fmt --check --all`, `cargo nextest run -p fabro-types -p fabro-workflow -p fabro-store -p fabro-api -p fabro-agent` (2250+464 tests), `bun test stage-insights-sidebar` (10/10), and `bun run typecheck` all pass. The 14 unrelated `run-actions.test.ts` failures pre-exist on the parent commit.", + "internal.retry_count.simplify_opus": 0, + "response.implement": "The TS generator is pinned now, but this sandbox lacks Java, which OpenAPI Generator needs. I’ll install a headless JRE and rerun generation.", + "internal.retry_count.preflight_lint": 0, + "graph.goal": "---\ntitle: feat: StageProjection agent tools API\ntype: feat\nstatus: active\ndate: 2026-05-24\n---\n\n# feat: StageProjection Agent Tools API\n\n## Overview\n\nExpose 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`.\n\nThe API should expose tool summaries with `name`, `description`, `source`, `category`, and `invoked`. It must not expose full JSON parameter schemas in the run projection.\n\n## Problem Frame\n\nThe 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.\n\nThe 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.\n\n## Requirements Trace\n\n- R1. Add a StageProjection API field containing the complete effective tools for a stage session.\n- R2. Include `name`, `description`, `source`, `category`, and `invoked` for each tool.\n- R3. Do not infer tools from `permission_level` in backend or frontend code.\n- R4. Do not expose full tool parameter schemas through StageProjection.\n- R5. Preserve existing `permission_level` and `mcp_servers` fields for compatibility.\n- R6. Mark individual tools as invoked when matching `agent.tool.started` events are projected.\n- R7. Keep legacy runs backward compatible by defaulting missing tool lists to empty.\n\n## Scope Boundaries\n\n- Do not remove or rename `StageProjection.permission_level`.\n- Do not remove the existing MCP server projection or `AgentMcpToolSummary`.\n- Do not change completion API tool definitions.\n- Do not add ACP-native tool discovery in this pass unless an ACP path already has an equivalent effective tool list available.\n- Do not render parameter schemas in the web UI.\n\n## Context & Research\n\n### Relevant Code and Patterns\n\n- OpenAPI is the source of truth for HTTP contracts in `docs/public/api-reference/fabro-api.yaml`.\n- Shared API/projection DTOs should live in `fabro-types`, with `fabro-api/build.rs` replacements to avoid duplicate generated Rust types.\n- `StageProjection` lives in `lib/crates/fabro-types/src/run_projection.rs`.\n- 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`.\n- Workflow event conversion and event names live in `lib/crates/fabro-workflow/src/event/convert.rs`, `events.rs`, and `names.rs`.\n- Projection replay lives in `lib/crates/fabro-store/src/run_state.rs`.\n- The effective request tool list is built in `lib/crates/fabro-agent/src/session.rs` from `ToolRegistry::definitions_with_source_for_policy`.\n- Tool source metadata already exists as `ToolSource` and `ToolDefinitionWithSource` in `lib/crates/fabro-agent/src/tool_registry.rs`.\n- Tool category mapping already exists in `lib/crates/fabro-agent/src/tool_permissions.rs`.\n- The sidebar display lives in `apps/fabro-web/app/components/stage-insights-sidebar.tsx`.\n\n### Strategy Docs\n\n- Read `docs/internal/events-strategy.md` before adding the new durable event.\n- Read `docs/internal/testing-strategy.md` before adding or reorganizing tests.\n- 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.\n\n## Key Technical Decisions\n\n- Add a new StageProjection field named `agent_tools`, not `tools`, to avoid ambiguity with MCP nested tools and completion tool definitions.\n- Add a dedicated durable event named `agent.tools.available` instead of overloading `agent.session.activated`.\n- Capture the effective tool list after session setup and filtering, using the same path as model request construction.\n- 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.\n- Keep `AgentMcpToolSummary` MCP-only. Add a new general-purpose `AgentToolSummary` instead of stretching the MCP type beyond its meaning.\n- Treat `invoked` as projected state. The availability event should emit tools with `invoked: false`; replay of `agent.tool.started` flips matching tools to true.\n\n## API Contract\n\nAdd these schemas to OpenAPI and map them to `fabro_types` replacements:\n\n- `AgentToolSummary`\n - required: `name`, `description`, `source`, `category`, `invoked`\n - `name`: exposed tool name, e.g. `apply_patch` or `mcp__filesystem__read_file`\n - `description`: model-facing tool description\n - `source`: `AgentToolSource`\n - `category`: `AgentToolCategory`\n - `invoked`: boolean\n- `AgentToolSource`\n - tagged by `kind`\n - `native`\n - `mcp` with `server_name` and `original_name`\n - `skill`\n- `AgentToolCategory`\n - enum: `read`, `write`, `shell`, `subagent`, `other`\n- `AgentToolsAvailableProps`\n - required: `tools`, `visit`\n - `tools`: array of `AgentToolSummary`\n - `visit`: stage visit number\n\nAdd to `StageProjection`:\n\n- `agent_tools`: array of `AgentToolSummary`\n- Default to an empty array when omitted.\n- Skip serializing when empty, matching existing projection optional-list style.\n\nAdd event body:\n\n- Serialized event name: `agent.tools.available`\n- Event body type: `AgentToolsAvailableProps`\n\n## Implementation Units\n\n- [ ] **Unit 1: Add shared tool summary types**\n\n**Goal:** Define the canonical API/projection DTOs in `fabro-types`.\n\n**Files:**\n- Modify: `lib/crates/fabro-types/src/run_event/agent.rs`\n- Modify: `lib/crates/fabro-types/src/run_event/mod.rs`\n- Modify: `lib/crates/fabro-types/src/run_projection.rs`\n- Modify: `lib/crates/fabro-types/src/lib.rs`\n\n**Work:**\n- Add `AgentToolSummary`, `AgentToolSource`, `AgentToolCategory`, and `AgentToolsAvailableProps`.\n- Add `EventBody::AgentToolsAvailable` serialized as `agent.tools.available`.\n- Add `agent_tools: Vec` to `StageProjection`.\n- Ensure all new fields default cleanly for older persisted events/projections.\n- Export the new public types from `fabro-types`.\n\n- [ ] **Unit 2: Capture effective session tools**\n\n**Goal:** Provide an authoritative one-time source for the list that the model can actually call.\n\n**Files:**\n- Modify: `lib/crates/fabro-agent/src/session.rs`\n- Modify: `lib/crates/fabro-workflow/src/handler/llm/api.rs`\n- Modify: `lib/crates/fabro-workflow/src/event/events.rs`\n- Modify: `lib/crates/fabro-workflow/src/event/names.rs`\n- Modify: `lib/crates/fabro-workflow/src/event/convert.rs`\n- Modify: `lib/crates/fabro-workflow/src/event/stored_fields.rs` only if the new event needs non-standard stored fields.\n\n**Work:**\n- Add `Session::available_tools()` that returns the same effective `ToolDefinitionWithSource` list as `build_request()`.\n- Map `ToolDefinitionWithSource` to `AgentToolSummary` at the workflow boundary.\n- Populate `description` from `ToolDefinition.description`.\n- Populate `source` from `ToolSource`.\n- 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.\n- Populate `category` from the existing tool category mapping for known exposed names; use `other` when no category mapping applies.\n- Emit `agent.tools.available` once for the stage session after session setup and filtering are complete.\n\n- [ ] **Unit 3: Project available and invoked tools**\n\n**Goal:** Make `StageProjection.agent_tools` replay-authoritative.\n\n**Files:**\n- Modify: `lib/crates/fabro-store/src/run_state.rs`\n\n**Work:**\n- On `EventBody::AgentToolsAvailable`, replace the current stage visit's `agent_tools` with the event tools.\n- On `EventBody::AgentToolStarted`, find a matching `agent_tools` entry by exposed `tool_name` and set `invoked = true`.\n- Keep the existing MCP server `invoked` update unchanged.\n- If a legacy run has no availability event, do not synthesize a full list from permissions.\n\n- [ ] **Unit 4: Update OpenAPI and generated clients**\n\n**Goal:** Expose the new projection field and event contract through public API clients without duplicate Rust API types.\n\n**Files:**\n- Modify: `docs/public/api-reference/fabro-api.yaml`\n- Modify: `lib/crates/fabro-api/build.rs`\n- Modify: `lib/crates/fabro-api/src/lib.rs`\n- Modify generated files under `lib/crates/fabro-api/src/generated.rs` via `cargo build -p fabro-api`.\n- Modify generated files under `lib/packages/fabro-api-client/src` via TypeScript client generation.\n\n**Work:**\n- Add the OpenAPI schemas listed in the API Contract section.\n- Add `StageProjection.agent_tools`.\n- Add `fabro-api/build.rs` replacements for the new `fabro-types` types.\n- Regenerate Rust API code.\n- Regenerate TypeScript API client code.\n\n- [ ] **Unit 5: Render tools in the web sidebar**\n\n**Goal:** Replace the permission-derived sidebar display with the actual projected tool list.\n\n**Files:**\n- Modify: `apps/fabro-web/app/components/stage-insights-sidebar.tsx`\n- Modify: `apps/fabro-web/app/components/stage-insights-sidebar.test.tsx`\n\n**Work:**\n- Render `stage.agent_tools` when present.\n- Show each tool's name, description, source/category, and invoked state.\n- Keep permission level as secondary metadata or fallback for legacy stages with no `agent_tools`.\n- Do not infer tool availability from permission level.\n\n## Test Plan\n\n- `fabro-types`\n - JSON round-trip for `agent.tools.available`.\n - Serialization checks for `AgentToolSource` and `AgentToolCategory`.\n - Backward compatibility check that missing `agent_tools` deserializes to an empty list.\n\n- `fabro-workflow`\n - Event name and conversion tests for `agent.tools.available`.\n - Capture test proving native tools such as `apply_patch`, `grep`, and `glob` are emitted from the effective registry path.\n - MCP source mapping test for a qualified MCP tool name.\n\n- `fabro-store`\n - Projection test that `agent.tools.available` populates `StageProjection.agent_tools`.\n - Projection test that `agent.tool.started` marks only the matching tool as invoked.\n - Regression test that MCP server `invoked` status still updates as before.\n\n- `fabro-api`\n - Type identity/parity tests confirming API types reuse `fabro_types::AgentToolSummary`, `AgentToolSource`, `AgentToolCategory`, and `AgentToolsAvailableProps`.\n - StageProjection round-trip test including `agent_tools`.\n\n- `fabro-web`\n - Sidebar test rendering tool names and descriptions from `stage.agent_tools`.\n - Sidebar test showing invoked state.\n - Legacy fallback test for stages without `agent_tools`.\n\n## Run Checks\n\n- `cargo +nightly-2026-04-14 fmt --check --all`\n- `cargo nextest run -p fabro-types -p fabro-workflow -p fabro-store -p fabro-api`\n- `cargo build -p fabro-api`\n- `cd lib/packages/fabro-api-client && bun run generate`\n- `cd apps/fabro-web && bun test && bun run typecheck`\n\n## Assumptions\n\n- The first implementation targets normal API-backed agent sessions, not ACP-native sessions.\n- `description` is safe to expose because it is already model-facing tool metadata, but parameter schemas remain out of scope for StageProjection.\n- `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.\n- If tool registration becomes mutable later, the event contract can be re-emitted and projection replacement semantics will still work.\n", + "command.output": "blob://sha256/12ae32cb1ec02d01eda3581b127c1fee3b0dc53572ed6baf239721a03d82e126", + "last_stage": "simplify_gpt", + "internal.thread_id": "simplify_opus", + "thread.start.current_node": "toolchain", + "thread.preflight_compile.current_node": "preflight_lint", + "internal.node_visit_count": 1, + "thread.toolchain.current_node": "preflight_compile", + "thread.preflight_lint.current_node": "implement", + "last_response": "Reviewed the feature branch diff against `origin/main...HEAD` and ran the requested parallel review pass. I didn’t find any actionable reuse/quality/efficiency issues that warranted code changes, so", + "internal.retry_count.implement": 0, + "thread.simplify_opus.current_node": "simplify_gpt", + "response.simplify_gpt": "Reviewed the feature branch diff against `origin/main...HEAD` and ran the requested parallel review pass. I didn’t find any actionable reuse/quality/efficiency issues that warranted code changes, so the working tree remains clean.\n\nValidation run:\n\n- `cargo nextest run -p fabro-types -p fabro-store -p fabro-agent -p fabro-workflow -p fabro-api agent_tools_available stage_projection_round_trip to_agent_tool_summary effective_tools --no-tests=pass` ✅\n- `cd apps/fabro-web && bun test stage-insights-sidebar.test.tsx` ✅\n- `cargo +nightly-2026-04-14 fmt --check --all` ✅\n- `cd apps/fabro-web && bun run typecheck` ✅\n- `git status --short` clean ✅", + "current_node": "simplify_gpt", + "internal.work_dir": "/home/daytona/workspace/fabro", + "internal.run_id": "01KSDFKD9JJS7D2ZJ6JQYXV58Z" + }, + "node_outcomes": { + "start": { + "status": "succeeded", + "usage": null + }, + "simplify_gpt": { + "status": "succeeded", + "context_updates": { + "last_response": "Reviewed the feature branch diff against `origin/main...HEAD` and ran the requested parallel review pass. I didn’t find any actionable reuse/quality/efficiency issues that warranted code changes, so", + "last_stage": "simplify_gpt", + "response.simplify_gpt": "Reviewed the feature branch diff against `origin/main...HEAD` and ran the requested parallel review pass. I didn’t find any actionable reuse/quality/efficiency issues that warranted code changes, so the working tree remains clean.\n\nValidation run:\n\n- `cargo nextest run -p fabro-types -p fabro-store -p fabro-agent -p fabro-workflow -p fabro-api agent_tools_available stage_projection_round_trip to_agent_tool_summary effective_tools --no-tests=pass` ✅\n- `cd apps/fabro-web && bun test stage-insights-sidebar.test.tsx` ✅\n- `cargo +nightly-2026-04-14 fmt --check --all` ✅\n- `cd apps/fabro-web && bun run typecheck` ✅\n- `git status --short` clean ✅" + }, + "notes": "Stage completed: simplify_gpt", + "usage": { + "input": { + "usage": { + "model": { + "provider": "openai", + "model_id": "gpt-5.5" + }, + "tokens": { + "input_tokens": 1008114, + "output_tokens": 3387, + "reasoning_tokens": 2181, + "cache_read_tokens": 569856, + "cache_write_tokens": 0 + } + }, + "facts": { + "algorithm": "openai" + } + }, + "total_usd_micros": 5492538 + } + }, "preflight_compile": { "status": "succeeded", "context_updates": { @@ -1002,10 +1160,53 @@ }, "total_usd_micros": 42637434 } + }, + "simplify_opus": { + "status": "succeeded", + "context_updates": { + "response.simplify_opus": "## Summary\n\nAggregated three review agents' findings and applied the consensus high-value fixes:\n\n**Quality / reuse fixes:**\n- `tool_permissions::known_tool_category` now returns `Option` directly. Deleted the brittle `Some(\"read\")` → `Read` string match in `handler/llm/api.rs`. `is_auto_approved` and `tool_category` are now enum-typed end-to-end; cli.rs and its tests updated accordingly. Adding a new category is now a compile-time exhaustiveness error instead of a silent `Other`.\n- `ToolSource::Mcp` now carries `original_name` populated from `info.original_tool_name` in `make_mcp_tools`. Workflow code no longer re-parses qualified MCP names (eliminates the silent fallback bug where a malformed prefix would store the qualified name as \"original\").\n- Moved `agent_tool_source` + `agent_tool_summaries_from_definitions` out of `handler/llm/api.rs`. New `ToolDefinitionWithSource::to_agent_tool_summary()` + `Session::agent_tool_summaries()` colocate the conversion next to the source type. Tests moved to `tool_registry.rs`.\n- Collapsed `Session::available_tools` and the duplicate private `effective_tools` into one public `effective_tools()` method.\n- Merged `ToolAvailableIcon` and `TodoPendingIcon` into a single `EmptyCircleIcon` component in the sidebar.\n\n**Efficiency fix:**\n- Gated `emit_agent_tools_available` on `!is_reused` in the primary path. Reused steerable sessions had been re-emitting the full tool list (with descriptions cloned into the event payload) on every prompt even though registry, access policy, and exposure mode are immutable for the session's lifetime. Failover path keeps its emit since it always builds a fresh session.\n\n**Skipped (cost > benefit):** `mcp_server_from_tool_name` dedup in `fabro-store` would require pulling `fabro-mcp` (with `rmcp`) into the store crate or relocating the parse helper into `fabro-types`. The duplicate is 5 lines using the same delimiter convention — not worth the dependency surface.\n\n**Verification:** `cargo check --workspace --all-targets`, `cargo +nightly-2026-04-14 clippy --workspace --all-targets -- -D warnings`, `cargo +nightly-2026-04-14 fmt --check --all`, `cargo nextest run -p fabro-types -p fabro-workflow -p fabro-store -p fabro-api -p fabro-agent` (2250+464 tests), `bun test stage-insights-sidebar` (10/10), and `bun run typecheck` all pass. The 14 unrelated `run-actions.test.ts` failures pre-exist on the parent commit.", + "last_stage": "simplify_opus", + "last_response": "## Summary\n\nAggregated three review agents' findings and applied the consensus high-value fixes:\n\n**Quality / reuse fixes:**\n- `tool_permissions::known_tool_category` now returns `Option; ++/** Empty circle for pending/available states (matches Tailwind sizing). */ ++function EmptyCircleIcon({ className }: { className?: string }) { ++ return ( ++