Skip to content

Feat/tool integration v2 - #86

Open
Amazing-Stardom wants to merge 14 commits into
masterfrom
feat/tool-integration-v2
Open

Amazing-Stardom wants to merge 14 commits into
masterfrom
feat/tool-integration-v2

Conversation

@Amazing-Stardom

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread ui/src/pages/Reviews/ReviewDetail.tsx Fixed
@lovestaco
lovestaco marked this pull request as ready for review August 29, 2026 16:13
@LiveReview-Bot

Copy link
Copy Markdown

Implement Third-Party Tool Integration

Overview

This change introduces a new feature enabling third-party static analysis tools to run as Lambda-backed jobs during LiveReview code reviews. It establishes a comprehensive system including new database schemas, API endpoints, UI components, and job orchestration. The system aims to provide detailed tool findings and credit consumption within the review process.

Technical Highlights

  • db/migrations/*, db/schema.sql: Add available_tools, org_tools, org_tool_billing_state, and tool_credit_ledger tables.
  • internal/api/server.go, tools_handler.go: Implement new API endpoints for managing global and organization-specific tools.
  • internal/review_processor/events.go: Introduce SeverityCounts and ToolSummary structs for review event aggregation.
  • docs/tools/tools-integration-beta.md: Defines the tool_invocation River job for orchestrating Lambda-based tool execution.
  • ui/src/components/reviews/ToolAnalysisCard.tsx: New UI component displays detailed tool analysis results with filtering and pagination.
  • ui/src/pages/Reviews/ReviewDetail.tsx: Integrates ToolAnalysisCard and processes tool accounting data for display.
  • internal/api/diff_review.go: Gracefully handles decoding failures for reviews without AI comments.
  • ui/src/components/Dashboard/widgets/ToolsUsageWidget.tsx: Adds a new dashboard widget for tool usage overview.

Impact

  • Functionality: Users can now integrate, configure, and view results from third-party static analysis tools directly within code reviews. Review summaries include detailed tool findings and severity counts.
  • Risk: New database schemas require careful migration and data integrity checks. The hasNoReviewLayerData function in ReviewLayersData.tsx now always returns false, potentially affecting existing dashboard logic. Extensive mock data usage in ReviewDetail.tsx could mask real API issues during development.


1. THE System SHALL provide an `available_tools` table with columns: `id` (bigserial primary key), `name` (text not null unique), `description` (text not null), and `lambda_arn` (text not null).
2. THE System SHALL seed the `available_tools` table with at least two initial rows: one for `ruff` and one for `pylint`, each with a non-empty `description` and a placeholder `lambda_arn`.
3. THE System SHALL manage the `available_tools` schema exclusively through dbmate migration files located in `db/migrations/`, and SHALL NOT apply these migrations directly to any production database.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: critical

The dbmate migrations have not been applied to the production environment. The strategy for updating the schema needs to be clarified.

Suggestions:

  1. Clarify how production database schema updates will be managed if dbmate migrations are not applied directly.
  2. Reconcile this statement with standard dbmate usage for all environments.


1. THE System SHALL provide an `org_tools` table with columns: `org_id` (bigint not null, references `organizations.id`), `tool_id` (bigint not null, references `available_tools.id`), `enabled` (boolean not null default false), `config_json` (jsonb not null default `'{}'`), and a composite primary key on (`org_id`, `tool_id`).
2. THE System SHALL enforce that every row in `org_tools` references a valid `org_id` in the `organizations` table and a valid `tool_id` in the `available_tools` table via foreign key constraints.
3. THE System SHALL manage the `org_tools` schema exclusively through dbmate migration files and SHALL NOT apply these migrations directly to any production database.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: critical

The dbmate migrations have not been applied to the production environment. The strategy for updating the schema needs to be clarified.

Suggestions:

  1. Clarify how production database schema updates will be managed if dbmate migrations are not applied directly.
  2. Reconcile this statement with standard dbmate usage for all environments.

1. WHEN `isCloudMode()` returns `true` AND the authenticated user's role is `owner`, THE Settings Page SHALL render a navigable tab at the hash route `third-party-tools` within `/#/settings`.
2. WHEN `isCloudMode()` returns `false`, THE Settings Page SHALL NOT render the `third-party-tools` tab.
3. WHEN the authenticated user's role is not `owner`, THE Settings Page SHALL NOT render the `third-party-tools` tab as a clickble navigation item.
4. WHEN a non-owner org member navigates directly to `/#/settings#third-party-tools`, THE Settings Page SHALL render a read-only view of the enabled tools without controls to modify them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

A read-only view should be implemented for non-owners. Ensure that no sensitive configuration information is exposed through this view.

Suggestions:

  1. Verify that the read-only view for non-owners does not expose any sensitive configuration details that should be restricted.
  2. Implement robust data filtering on the backend for read-only access.

id bigserial PRIMARY KEY,
name text NOT NULL UNIQUE,
description text NOT NULL,
lambda_arn text NOT NULL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The lambda_arn column is defined as NOT NULL, but the seeding process requires placeholders. This needs to be reconciled with requirement R1.2.

Suggestions:

  1. Clarify how lambda_arn will be handled for initial seeded tools (R1.2) if they are NOT NULL and 'no hardcoded ARNs belong here'.
  2. Consider allowing NULL initially or ensuring a robust placeholder/update mechanism.

name text NOT NULL UNIQUE,
description text NOT NULL,
lambda_arn text NOT NULL,
multiplier numeric(6,2) NOT NULL DEFAULT 1.0,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

A multiplier column has been added. Its purpose is not clear from the schema definition.

Suggestions:

  1. Add a comment or documentation explaining the purpose and usage of the multiplier column.

description text NOT NULL,
lambda_arn text NOT NULL,
multiplier numeric(6,2) NOT NULL DEFAULT 1.0,
use_case text NOT NULL DEFAULT '',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

A use_case column has been added. Its purpose is not clear from the schema definition.

Suggestions:

  1. Add a comment or documentation explaining the purpose and usage of the use_case column.

created_at timestamptz NOT NULL DEFAULT now()
);

-- Tools are registered via the lr-tools deployer's `register-tools` command,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: critical

This comment conflicts with requirement R1.2, which specifies seeding with placeholder ARNs.

Suggestions:

  1. Reconcile this comment with Requirement 1.2, which states that available_tools should be seeded with placeholder lambda_arns.
  2. Clarify if seeding happens outside of this migration or if placeholders are acceptable here.

@@ -0,0 +1,15 @@
-- migrate:up
CREATE TABLE IF NOT EXISTS public.org_tools (
org_id bigint NOT NULL REFERENCES public.orgs(id) ON DELETE CASCADE,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The ON DELETE CASCADE option is used for the orgs table. Please confirm that this aligns with the business logic requirements.

Suggestions:

  1. Confirm that cascading deletion of org_tools entries upon orgs deletion aligns with business requirements.
  2. Consider ON DELETE RESTRICT or SET NULL if org_tools data needs to be preserved or handled differently.

-- migrate:up
CREATE TABLE IF NOT EXISTS public.org_tools (
org_id bigint NOT NULL REFERENCES public.orgs(id) ON DELETE CASCADE,
tool_id bigint NOT NULL REFERENCES public.available_tools(id) ON DELETE CASCADE,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The ON DELETE CASCADE option is used for the available_tools table. Please confirm that this aligns with the business logic requirements.

Suggestions:

  1. Confirm that cascading deletion of org_tools entries upon available_tools deletion aligns with business requirements.
  2. This is generally acceptable, as configurations for a non-existent tool are usually irrelevant.

tool_id bigint NOT NULL REFERENCES public.available_tools(id) ON DELETE CASCADE,
enabled boolean NOT NULL DEFAULT false,
config_json jsonb NOT NULL DEFAULT '{}',
updated_at timestamptz NOT NULL DEFAULT now(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The updated_at column lacks an ON UPDATE trigger, meaning it is only set upon insertion and not updated thereafter.

Suggestions:

  1. Add an ON UPDATE trigger to automatically update the updated_at timestamp whenever a row in org_tools is modified.
  2. Consider using the org_tool_billing_state_set_updated_at() function if applicable.

Comment thread db/schema.sql
@@ -1,7 +1,7 @@
\restrict dbmate

-- Dumped from database version 15.17 (Debian 15.17-1.pgdg13+1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

There is a PostgreSQL version bump from 15.17 to 16.14. Please ensure compatibility with existing applications and queries.

Suggestions:

  1. Verify compatibility of all application components and dependencies with PostgreSQL 16.14.
  2. Ensure all environments (dev, staging, prod) are aligned or tested for this version.

Comment thread db/schema.sql Outdated
Comment thread db/schema.sql Outdated

SET default_table_access_method = heap;

--

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The _seed_backup table has been removed. Please confirm that it is no longer needed for any processes.

Suggestions:

  1. Confirm that the _seed_backup table is no longer required or its functionality has been safely replaced.
  2. Ensure no data loss or unexpected behavior results from its removal.

Comment thread db/schema.sql Outdated
id bigint NOT NULL,
name text NOT NULL,
description text NOT NULL,
lambda_arn text NOT NULL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: info

The Lambda ARN implies a dependency on AWS. This architectural choice should be documented.

Suggestions:

  1. Add a comment or documentation explaining the dependency on AWS Lambda for tool execution.

Comment thread db/schema.sql Outdated
name text NOT NULL,
description text NOT NULL,
lambda_arn text NOT NULL,
multiplier numeric(6,2) DEFAULT 1.0 NOT NULL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The multiplier column is defined with numeric(6,2) precision. Consider if this precision is sufficient for billing purposes, as double precision is used elsewhere.

Suggestions:

  1. Ensure numeric(6,2) provides sufficient precision for billing calculations. If double precision is used for credits_used_month and credits_limit_month, consider making multiplier consistent to avoid potential precision issues or unexpected rounding in calculations.

Comment thread db/schema.sql Outdated
ALTER SEQUENCE public.loc_usage_ledger_id_seq OWNED BY public.loc_usage_ledger.id;


--

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: critical

The mcp_authorizations table has been removed. Ensure that all code references to this table have been updated accordingly.

Suggestions:

  1. Verify that all application code, services, and tests that previously interacted with mcp_authorizations have been updated or removed. Missing references will cause runtime errors.

Comment thread db/schema.sql Outdated
id bigint NOT NULL,
org_id bigint NOT NULL,
credits_used_month double precision DEFAULT 0.0 NOT NULL,
credits_limit_month double precision DEFAULT 50000.0 NOT NULL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The default value for credits_limit_month is set to 50000.0, which is a magic number. It is recommended to define this as a constant.

Suggestions:

  1. Replace 50000.0 with a named constant or configuration parameter for clarity and easier modification.

Comment thread db/schema.sql Outdated
org_id bigint NOT NULL,
credits_used_month double precision DEFAULT 0.0 NOT NULL,
credits_limit_month double precision DEFAULT 50000.0 NOT NULL,
billing_period_start timestamp with time zone NOT NULL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

Default values are missing for the billing_period_start and billing_period_end columns.

Suggestions:

  1. Add a default value for billing_period_start and billing_period_end (e.g., now() and now() + interval '1 month') or ensure these are always explicitly set on insert.

Comment thread db/schema.sql Outdated
billing_period_end timestamp with time zone NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT chk_tool_billing_period_valid CHECK ((billing_period_end > billing_period_start)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: info

The constraint chk_tool_billing_period_valid ensures that the end date is greater than the start date, but it does not enforce that the end date is greater than or equal to the start date.

Suggestions:

  1. Consider if billing_period_end >= billing_period_start is more appropriate, allowing for periods of zero duration if needed. If not, this is fine.

Comment thread db/schema.sql Outdated
org_id bigint NOT NULL,
review_id bigint,
credits_deducted double precision NOT NULL,
idempotency_key character varying(255) NOT NULL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: critical

The idempotency_key is critical for billing operations. Ensure that a uniqueness constraint is enforced for this key.

Suggestions:

  1. Add a UNIQUE constraint on idempotency_key to prevent duplicate credit deductions, which is crucial for billing accuracy.

Comment thread db/schema.sql
ADD CONSTRAINT loc_usage_ledger_pkey PRIMARY KEY (id);


--

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: critical

The primary key constraint mcp_authorizations_pkey has been removed. Verify that there are no lingering references to this constraint.

Suggestions:

  1. Confirm that all code, including foreign key constraints in other tables, no longer references the mcp_authorizations_pkey.

Comment thread docs/openapi.yaml
operationId: UpdateUser
parameters:
- in: path
name: org_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: critical

The path parameter names for org_id and user_id have been swapped. This represents a breaking change if clients rely on the original order of these parameters.

Suggestions:

  1. Confirm this change aligns with the actual API endpoint path. If the API path itself has not changed, this is a breaking change for clients using the old parameter order. Communicate this breaking change to API consumers.

Comment thread docs/openapi.yaml
schema:
type: string
- in: path
name: user_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: critical

The path parameter names for org_id and user_id have been swapped. This represents a breaking change if clients rely on the original order of these parameters.

Suggestions:

  1. Confirm this change aligns with the actual API endpoint path. If the API path itself has not changed, this is a breaking change for clients using the old parameter order. Communicate this breaking change to API consumers.

Comment thread docs/tools/tools-integration-beta.md Outdated

### Tool catalog reference

The table below lists available tools. `multiplier` is computed by the API (`(memory_mb / 1024) × timeout_s` relative to the cheapest tool) and returned in the `GET /api/v1/orgs/:org_id/tools` response. Tools marked **Beta** are included in the initial seed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The multiplier is indicated as computed in this context, but the database schema shows it is stored. Please clarify whether it is computed during seeding/updates or dynamically.

Suggestions:

  1. Clarify how the multiplier value is derived and maintained, especially if the 'cheapest tool' baseline changes.

Comment thread docs/tools/tools-integration-beta.md Outdated
id bigserial PRIMARY KEY,
name text NOT NULL UNIQUE,
description text NOT NULL,
lambda_arn text NOT NULL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The lambda_arn placeholder hardcodes us-east-1 and ACCOUNT. This needs to be dynamic to support multi-region and multi-account deployments.

Suggestions:

  1. Ensure lambda_arn is configurable or derived dynamically based on environment and account.

Comment thread docs/tools/tools-integration-beta.md Outdated
name text NOT NULL UNIQUE,
description text NOT NULL,
lambda_arn text NOT NULL,
multiplier numeric(6,2) NOT NULL DEFAULT 1.0,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

For the multiplier column defined as numeric(6,2), please check if the precision is sufficient for all potential cost calculation scenarios.

Suggestions:

  1. Confirm numeric(6,2) precision is adequate for all expected multiplier values, especially for very cheap or expensive tools.

Comment thread docs/tools/tools-integration-beta.md Outdated
description text NOT NULL,
lambda_arn text NOT NULL,
multiplier numeric(6,2) NOT NULL DEFAULT 1.0,
use_case text NOT NULL DEFAULT '',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: info

The default value for use_case is an empty string (''). Consider using NULL if no specific use case is applicable, or an enum for better consistency.

Suggestions:

  1. Evaluate using NULL for use_case if it's truly optional, or an enum for better data integrity and consistency.

if jsonErr := json.Unmarshal(outBytes, &altResp); jsonErr != nil {
log.Printf("[WARN] ToolReviewWorker: failed to unmarshal Lambda findings output for tool=%s review=%d: %v", args.ToolName, args.ReviewID, jsonErr)
} else if len(altResp.Findings) > 0 {
rawList := make([]toolclassifier.RawToolFinding, len(altResp.Findings))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The logic for extracting finding fields is complex and appears brittle to future changes.

Suggestions:

  1. Centralize this logic if multiple tools have similar output variations.
  2. Consider a more robust mapping or adapter pattern if tool outputs are highly variable.
  3. Add comments explaining the priority order for field extraction.

rm := reviewprocessor.NewReviewManager(w.db)
stored := 0
for _, c := range classifiedComments {
if c == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

There is a nil check for a classified comment, but ClassifyToolResult should ideally not return nil elements.

Suggestions:

  1. Review toolclassifier.ClassifyToolResult to ensure it does not return nil elements in the slice.
  2. If nil elements are possible, add a comment explaining why and if they should be filtered earlier.

}

// finalizeIfAllDone checks if all dispatched tools have returned results and marks the review completed.
func (w *ToolReviewWorker) finalizeIfAllDone(ctx context.Context, args ToolReviewJobArgs) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: critical

There is a race condition risk because multiple workers can finalize concurrently.

Suggestions:

  1. Implement a distributed lock (e.g., using pg_advisory_lock) around the finalizeIfAllDone logic for a given review_id.
  2. Consider using a transactional approach or a single-threaded finalization mechanism to prevent multiple completion events or status updates.

// finalizeIfAllDone checks if all dispatched tools have returned results and marks the review completed.
func (w *ToolReviewWorker) finalizeIfAllDone(ctx context.Context, args ToolReviewJobArgs) error {
var pendingJobs int
err := w.db.QueryRowContext(ctx, `

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The SQL query is inefficient due to JSON field extraction being performed within the WHERE or NOT IN clauses.

Suggestions:

  1. Add a GIN index on the data column for review_events to speed up JSON key lookups (e.g., CREATE INDEX idx_review_events_data_tool_name ON public.review_events USING GIN (data jsonb_path_ops);).
  2. Consider restructuring review_events schema to have tool_name as a direct column if this query is frequent, avoiding JSON extraction overhead.


eventSink := reviewprocessor.NewDatabaseEventSink(w.db)
if emitErr := eventSink.EmitCompletionEvent(ctx, args.ReviewID, args.OrgID,
"### Static Analysis Tools Review Only\n\nAI review skipped due to --tools flag.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The completion message is hardcoded and may not always be accurate.

Suggestions:

  1. Make the completion message dynamic based on the actual review type or flags.
  2. Pass the appropriate message as an argument to finalizeIfAllDone.

Comment thread internal/license/plans.go

// IsToolsEligible returns true if the plan type is eligible for static analysis tool credit deduction.
func IsToolsEligible(p PlanType) bool {
if p == PlanType("") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

An empty PlanType currently returns true; please clarify the intended behavior.

Suggestions:

  1. Clarify if an empty PlanType should indeed be eligible for tools. This might allow tool usage without a valid plan.
  2. If not intended, change return true to return false or handle PlanType("") as an invalid state.

return nil, nil
}

var raw map[string]interface{}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

Manual type assertions are used for each field, which makes the code verbose and error-prone.

Suggestions:

  1. Consider using a library like mapstructure for safer, more concise mapping from map[string]interface{} to ToolRuleConfig.
  2. Extract field parsing logic into smaller helper functions for enabled, category, include, exclude.

results[toolName] = &ToolRuleConfig{Enabled: &bVal}
case map[string]interface{}:
cfg := &ToolRuleConfig{}
if enabledRaw, exists := v["enabled"]; exists && enabledRaw != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: info

The repeated exists && enabledRaw != nil checks appear redundant.

Suggestions:

  1. Simplify: if enabledVal, ok := v["enabled"].(bool); ok { cfg.Enabled = &enabledVal }. If key doesn't exist or is nil, ok will be false.

}
}
if incRaw, exists := v["include"]; exists && incRaw != nil {
if incSlice, ok := incRaw.([]interface{}); ok {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

Non-string items in the include slice are silently skipped, which could lead to potential configuration misinterpretation.

Suggestions:

  1. Add logging for non-string items in include or exclude to alert users to malformed configuration.
  2. Consider returning an error if unexpected types are found, making configuration stricter.

}
}
}
if excRaw, exists := v["exclude"]; exists && excRaw != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

Non-string items in the exclude slice are silently skipped, which could lead to potential configuration misinterpretation.

Suggestions:

  1. Add logging for non-string items in include or exclude to alert users to malformed configuration.
  2. Consider returning an error if unexpected types are found, making configuration stricter.

return true
}

var includeMatcher *gitignore.GitIgnore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The gitignore matcher creation logic is duplicated in both ShouldRunToolRuleForDiff and FilterLocalCodeDiffsForTool.

Suggestions:

  1. Extract createGitIgnoreMatchers(cfg *ToolRuleConfig) helper function to return (includeMatcher, excludeMatcher *gitignore.GitIgnore).
  2. Call this helper once at the start of both functions.

}

matchingFilesCount := 0
for _, d := range diffs {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The path extraction logic is duplicated in both ShouldRunToolRuleForDiff and FilterLocalCodeDiffsForTool.

Suggestions:

  1. Extract getDiffPath(d lib.LocalCodeDiff) helper function.
  2. Call this helper within the loop in both functions.

return diffs
}

var includeMatcher *gitignore.GitIgnore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The gitignore matcher creation logic is duplicated in both ShouldRunToolRuleForDiff and FilterLocalCodeDiffsForTool.

Suggestions:

  1. Extract createGitIgnoreMatchers(cfg *ToolRuleConfig) helper function to return (includeMatcher, excludeMatcher *gitignore.GitIgnore).
  2. Call this helper once at the start of both functions.


var filtered []lib.LocalCodeDiff
for _, d := range diffs {
path := d.NewPath

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The path extraction logic is duplicated in both ShouldRunToolRuleForDiff and FilterLocalCodeDiffsForTool.

Suggestions:

  1. Extract getDiffPath(d lib.LocalCodeDiff) helper function.
  2. Call this helper within the loop in both functions.


b.WriteString(fmt.Sprintf("diff --git a/%s b/%s\n", oldPath, newPath))
if d.OldPath == "/dev/null" || d.OldPath == "" {
b.WriteString("new file mode 100644\n")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: warning

The file mode 100644 is hardcoded and may not be accurate for all file types, such as executables.

Suggestions:

  1. If lib.LocalCodeDiff contains file mode information, use that instead.
  2. If not, consider if 100644 is always acceptable or if a default is sufficient for current use cases.

@Amazing-Stardom
Amazing-Stardom force-pushed the feat/tool-integration-v2 branch from 179ad51 to ffaa037 Compare October 17, 2026 20:52
LiveReview Pre-Commit Check: ran (iter:57, coverage:92%)
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
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.

4 participants