refactor: unified tool registry and agent executor#9
Conversation
- Add shared/toolRegistry with typed tool definitions and validation - Add shared/toolTypes for consistent tool type contracts - Refactor agent executor with format tests and parser improvements - Add formatCellsTool, pendingActionPreview, previewBuilders - Remove legacy src/agent/types.ts (replaced by shared types) - Update server prompt and parseResponse for new tool interface
Reviewer's GuideRefactors the spreadsheet agent to use a shared, typed tool registry and central format_cells implementation, updates the executor/parser/server prompt to this new contract, and adds tests plus preview helpers for formatting and action previews. Sequence diagram for message parsing and unified format_cells executionsequenceDiagram
actor User
participant AgentIndex as agent.index
participant Parser as parser.parseMessage
participant Executor as executor.executeTool
participant FormatCells as formatCellsTool.applyFormatCells
participant ToolRegistry as shared.toolRegistry
User->>AgentIndex: send message
AgentIndex->>Parser: parseMessage(message, sheetContext)
Parser-->>AgentIndex: ParseResult(calls)
AgentIndex->>Executor: executeTool(call, ctx)
Executor->>ToolRegistry: resolveToolName(call.tool)
ToolRegistry-->>Executor: canonicalToolName (e.g. format_cells)
Executor->>FormatCells: applyFormatCells(params, ctx)
FormatCells-->>Executor: ExecutionResult
Executor-->>AgentIndex: ExecutionResult
AgentIndex-->>User: updated sheet & explanation
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reached
Next review available in: 25 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (23)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The FONT_COLOR_HEX and HIGHLIGHT_BG_HEX maps are now duplicated in both src/agent/parser.ts and shared/actTemplates.ts; consider centralizing these in a shared helper to avoid drift between the fast-path parser and the LLM templates.
- resolveColumnIndex currently scans a fixed 60 columns and relies on findHeaderRow; it might be more robust to derive the column limit from the actual sheet shape (e.g., lastDataCol or header row cells) instead of a magic constant.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The FONT_COLOR_HEX and HIGHLIGHT_BG_HEX maps are now duplicated in both src/agent/parser.ts and shared/actTemplates.ts; consider centralizing these in a shared helper to avoid drift between the fast-path parser and the LLM templates.
- resolveColumnIndex currently scans a fixed 60 columns and relies on findHeaderRow; it might be more robust to derive the column limit from the actual sheet shape (e.g., lastDataCol or header row cells) instead of a magic constant.
## Individual Comments
### Comment 1
<location path="src/agent/executor.ts" line_range="315-323" />
<code_context>
+}
+
+/** Resolve a column given as a letter ("B") or a header name ("Amount"). */
+function resolveColumnIndex(
+ column: string,
+ sheet: SheetData,
+ getComputedValue: (row: number, col: number) => string,
+): number | null {
+ if (/^[A-Z]{1,3}$/i.test(column)) return letterToCol(column.toUpperCase())
+ const headerRow = findHeaderRow(sheet)
+ const lowered = column.toLowerCase()
+ for (let c = 0; c < 60; c++) {
+ if (getComputedValue(headerRow, c).toLowerCase() === lowered) return c
+ }
</code_context>
<issue_to_address>
**issue:** resolveColumnIndex doesn’t guard against missing header rows and uses a hard-coded column scan limit.
If `findHeaderRow(sheet)` returns `-1`, `getComputedValue(headerRow, c)` will be called with a negative row index, which can misbehave. Also, scanning with `for (let c = 0; c < 60; c++)` assumes a 60-column sheet and will miss headers on wider sheets. Please short-circuit when `headerRow < 0`, and use the sheet’s actual last data column or metadata instead of the hard-coded limit.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| function resolveColumnIndex( | ||
| column: string, | ||
| sheet: SheetData, | ||
| getComputedValue: (row: number, col: number) => string, | ||
| ): number | null { | ||
| if (/^[A-Z]{1,3}$/i.test(column)) return letterToCol(column.toUpperCase()) | ||
| const headerRow = findHeaderRow(sheet) | ||
| const lowered = column.toLowerCase() | ||
| for (let c = 0; c < 60; c++) { |
There was a problem hiding this comment.
issue: resolveColumnIndex doesn’t guard against missing header rows and uses a hard-coded column scan limit.
If findHeaderRow(sheet) returns -1, getComputedValue(headerRow, c) will be called with a negative row index, which can misbehave. Also, scanning with for (let c = 0; c < 60; c++) assumes a 60-column sheet and will miss headers on wider sheets. Please short-circuit when headerRow < 0, and use the sheet’s actual last data column or metadata instead of the hard-coded limit.
…mnIndex - Extract FONT_COLOR_HEX and HIGHLIGHT_BG_HEX into shared/colorMaps.ts to avoid drift between parser and actTemplates - resolveColumnIndex now derives max column from actual sheet data instead of hardcoded 60-column limit
Introduces a shared tool registry and refactors the agent executor layer.
Changes:
Summary by Sourcery
Unify spreadsheet agent tools behind a shared, typed registry and update the agent execution, parsing, and server prompt/response layers to consume this single source of truth while improving formatting and filter behaviors.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: