refactor(bot): Extract platform-agnostic tool system#1
Open
Conversation
Introduce core type definitions for the bot tool system: - ToolResult: result returned from tool execution - RequesterInfo: user attribution info for PRs - ToolExecutionContext: context passed to tool execution - BotTool: main interface for tools with dynamic loading support
Add global tool registry for managing bot tools: - registerTool: register a tool at module load time - getTool: look up a tool by name - getAllTools: get all registered tools - hasRegisteredTool: check if a tool exists - getRegisteredToolCount: get count for debugging
Add tool loader that dynamically loads tools based on owner's integrations: - getToolsForOwner: returns tools available to an owner - getToolDefinitionsForOwner: returns OpenAI tool definitions - Tools with requiredIntegration only available if owner has that integration
Move spawn_cloud_agent tool from slack-bot.ts to dedicated implementation: - Extracted tool definition and execution logic - Added BotTool interface implementation - Set requiredIntegration to 'github' for dynamic loading - Returns ToolResult with sessionId in metadata - Renamed logging prefix from [SlackBot] to [SpawnCloudAgent]
Create index.ts that: - Re-exports all types, registry, and loader functions - Auto-registers spawn_cloud_agent tool on module import - Provides usage documentation in JSDoc
Update slack-bot.ts to use the new tool system: - Import tools from @/lib/bot/tools instead of inline definitions - Dynamically load tools based on owner's integrations - Use getTool() from registry to execute tool calls - Build ToolExecutionContext with requester info for tools - Remove ~180 lines of tool-specific code (moved to tools module) This enables: - Dynamic tool availability based on owner's integrations - Easy addition of new tools without modifying slack-bot.ts - Consistent tool interface across different tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a tool registry system that enables dynamic tool loading based on the owner's integrations, laying the groundwork for:
Changes
New Tool System (
/src/lib/bot/tools/)types.ts: Core type definitions (BotTool,ToolResult,ToolExecutionContext,RequesterInfo)registry.ts: Global tool registry withregisterTool,getTool,getAllToolstool-loader.ts: Dynamic tool loading based on owner's active integrationsimplementations/spawn-cloud-agent.ts: Extractedspawn_cloud_agenttoolindex.ts: Barrel export with auto-registrationUpdated
slack-bot.tsgetToolDefinitionsForOwner()to dynamically load toolsgetTool()from registry to execute tool callsgithub)Architecture
Testing
spawn_cloud_agenttoolPR Stack
This is PR 1 of 7 in the Slack bot tech debt reduction initiative: