Skip to content

feat(tool): unify extension registry#38

Closed
omarluq wants to merge 4 commits into
mainfrom
feat/unified-tool-registry
Closed

feat(tool): unify extension registry#38
omarluq wants to merge 4 commits into
mainfrom
feat/unified-tool-registry

Conversation

@omarluq

@omarluq omarluq commented May 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • register extension-provided tools in the same runtime tool registry as built-ins
  • advertise extension tool schemas to OpenAI/Anthropic provider payloads
  • execute extension tools through the normal assistant tool loop

Validation

  • mise exec -- task ci

Stacked after #35.

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 93de342e-0eaa-44b3-80d0-0f3b885288b5

📥 Commits

Reviewing files that changed from the base of the PR and between ec4b5d5 and 04f5073.

📒 Files selected for processing (25)
  • internal/assistant/anthropic.go
  • internal/assistant/anthropic_internal_test.go
  • internal/assistant/client.go
  • internal/assistant/openai_chat.go
  • internal/assistant/openai_responses.go
  • internal/assistant/runtime.go
  • internal/assistant/tool_loop.go
  • internal/assistant/tool_loop_test.go
  • internal/assistant/tool_registry.go
  • internal/assistant/tool_registry_test.go
  • internal/assistant/tool_schema.go
  • internal/extension/manager.go
  • internal/extension/manager_test.go
  • internal/extension/types.go
  • internal/tool/bash.go
  • internal/tool/edit.go
  • internal/tool/extension.go
  • internal/tool/find.go
  • internal/tool/grep.go
  • internal/tool/ls.go
  • internal/tool/read.go
  • internal/tool/registry.go
  • internal/tool/registry_test.go
  • internal/tool/types.go
  • internal/tool/write.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Extension tools now support defining input schemas to provide structured parameter documentation.
    • Tool registry now properly validates and registers extension-provided tools.
  • Bug Fixes

    • Duplicate tool registrations are now rejected with a clear error message.
    • Write tool now validates that content is provided before attempting file operations.

Walkthrough

This PR integrates extension-provided tools into the assistant's tool execution pipeline. A Schema field is added to tool definitions, extension tools are adapted to the core API via an ExtensionExecutor type, and request-scoped registries are wired into the completion client and assistant providers to enable per-request tool definition selection.

Changes

Extension Tool Integration

Layer / File(s) Summary
Tool definition schema field
internal/tool/types.go, internal/tool/bash.go, internal/tool/edit.go, internal/tool/find.go, internal/tool/grep.go, internal/tool/ls.go, internal/tool/read.go, internal/tool/write.go
tool.Definition gains Schema map[string]any field; all built-in tools explicitly set Schema: nil.
Tool registry registration API
internal/tool/registry.go, internal/tool/registry_test.go
Registry.Register method and ErrDuplicateTool error enable dynamic tool registration with duplicate detection, validated by tests rejecting duplicate tools and empty write content.
Extension tool adapter and Lua registration
internal/tool/extension.go, internal/extension/types.go, internal/extension/manager.go, internal/extension/manager_test.go
ExtensionToolRunner interface and ExtensionExecutor type adapt extension tools to core API; Registry.RegisterExtensions registers them; extension.Tool gains InputSchema field extracted from Lua arguments via luaOptionalSchema.
Tool loop and test registry wiring
internal/assistant/tool_loop.go, internal/assistant/tool_loop_test.go
executeToolCalls signature changes from cwd string to *tool.Registry, creating default registry when nil; newToolRegistryForTest helper centralizes test setup.
CompletionRequest registry field and helper
internal/assistant/client.go, internal/assistant/tool_registry.go
CompletionRequest.ToolRegistry field added; newToolRegistry helper creates registries and conditionally registers extension tools from runtime.
Request-aware tool schema generation
internal/assistant/tool_schema.go
responseTools and openAIChatTools accept request; requestToolDefinitions derives definitions from registry or global list; toolParameterSchema accepts Definition and uses builtinToolSchemas map with cloning and additionalProperties=false enforcement.
Assistant provider tool wiring
internal/assistant/anthropic.go, internal/assistant/openai_chat.go, internal/assistant/openai_responses.go
Anthropic, OpenAI Chat, and OpenAI Responses pass request.ToolRegistry to executeToolCalls and call request-aware tool helpers instead of global imports.
Runtime model response and registry wiring
internal/assistant/runtime.go
loadSkillWithReadTool, respondToToolCommand, and modelResponse use newToolRegistry with error handling; modelCompletionRequest accepts and wires registry into request.
Anthropic and tool registry test coverage
internal/assistant/anthropic_internal_test.go, internal/assistant/tool_registry_test.go
Anthropic tests validate tool names and eager streaming in JSON payload; tool registry tests verify extension registration, schema exposure, and duplicate name rejection with custom extensionToolCompletionClient.

Sequence Diagram

sequenceDiagram
  participant Runtime
  participant newToolRegistry
  participant Registry
  participant ExtensionProvider
  participant AssistantClient
  participant toolSchema
  Runtime->>newToolRegistry: newToolRegistry(cwd, extensions)
  newToolRegistry->>Registry: tool.NewRegistry(cwd)
  alt extensions provided
    newToolRegistry->>Registry: RegisterExtensions(runner, definitions)
    Registry->>ExtensionProvider: iterate extension.Tool definitions
    Registry->>ExtensionProvider: NewExtensionExecutor(definition, runner)
  end
  newToolRegistry-->>Runtime: *tool.Registry
  Runtime->>AssistantClient: modelCompletionRequest(registry)
  AssistantClient->>AssistantClient: set CompletionRequest.ToolRegistry
  AssistantClient->>toolSchema: responseTools(request)
  toolSchema->>toolSchema: requestToolDefinitions(request)
  alt registry present
    toolSchema-->>toolSchema: use registry definitions
  else
    toolSchema-->>toolSchema: use global tool.AllDefinitions()
  end
  toolSchema-->>AssistantClient: []map[string]any tools
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • omarluq/librecode#39: Both PRs touch Anthropic tool payload tests and tool schema/write validation, including jsonContentKey constant and write_content_required error handling.
  • omarluq/librecode#34: Both PRs update Anthropic tool-generation logic per-request and tool-name mapping during tool-call handling in the same code paths.
  • omarluq/librecode#32: Both PRs modify the assistant's tool-calling pipeline in core files (tool_schema.go, anthropic.go, openai_chat.go, tool_loop.go) with overlapping registry and tool execution changes.

Poem

🐰 Extension tools now bloom in registries wide,
Schemas define each parameter with pride,
Request-scoped definitions, adapters so keen,
Runtime wires tools where they're needed—pristine!
The loop accepts registries, not working directories alone,
A flexible pipeline makes assistant power known.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/unified-tool-registry
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/unified-tool-registry

Comment @coderabbitai help to get the list of available commands and usage tips.

@omarluq
omarluq changed the base branch from fix/anthropic-native-tools to main May 22, 2026 23:51
@omarluq
omarluq force-pushed the feat/unified-tool-registry branch from 91b5010 to 04f5073 Compare May 22, 2026 23:53
@omarluq omarluq closed this May 22, 2026
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant