Skip to content

Refine codebase learning#5

Merged
code-crusher merged 3 commits intomainfrom
refine_codebase_learning
Nov 14, 2025
Merged

Refine codebase learning#5
code-crusher merged 3 commits intomainfrom
refine_codebase_learning

Conversation

@code-crusher
Copy link
Member

No description provided.

@matter-ai-bot
Copy link
Contributor

matter-ai-bot bot commented Nov 14, 2025

Summary By MatterAI MatterAI logo

🔄 What Changed

Re-enabled OpenAI client initialization in OpenRouter provider with proper API key handling.

🔍 Impact of the Change

Fixes potential client initialization issues by ensuring the OpenAI client is properly instantiated with the correct configuration parameters.

📁 Total Files Changed

File ChangeLog
src/api/providers/openrouter.ts Re-enabled OpenAI client initialization line

🧪 Test Added/Recommended

Recommended

  • Add unit tests for OpenRouter provider client initialization
  • Verify API key handling in different environment configurations

🔒Security Vulnerabilities

N/A

Copy link
Contributor

@matter-ai-bot matter-ai-bot bot left a comment

Choose a reason for hiding this comment

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

🧪 PR Review is completed: Review of codebase learning refinement with MatterAI embedder integration and UI improvements

Skipped files
  • CHANGELOG.md: File hunk diff too large
⬇️ Low Priority Suggestions (5)
src/api/providers/fetchers/openrouter.ts

Location: src/api/providers/fetchers/openrouter.ts (Lines 167-167)

🔵 Code Quality

Issue: Debug console.log statement left in production code will clutter logs and impact performance.

Fix: Remove the debug console.log statement.

Impact: Improves performance and log cleanliness in production.

-  		console.log("getOpenRouterModelEndpoints 1", baseURL, modelId)
+  
src/core/assistant-message/AssistantMessageParser.ts

Location: src/core/assistant-message/AssistantMessageParser.ts (Lines 169-169)

🟠 Security

Issue: The regex for fixing unquoted JSON values is too broad and could inadvertently modify valid JSON structures or introduce security vulnerabilities.

Fix: Make the regex more specific to only match property values that are truly unquoted strings, avoiding false positives.

Impact: Reduces risk of JSON corruption and potential injection attacks.

-  					fixedArgs = fixedArgs.replace(/("([^"]+)"\s*:\s*)([a-zA-Z0-9_.*\/\\-]+)(?=\s*[,\]}])/g, '$1"$3"')
+  					// Fix unquoted string values in JSON (e.g., file_pattern:*.js -> file_pattern:"*.js")
+  					// More specific regex to avoid false positives
+  					fixedArgs = fixedArgs.replace(/("([^"]+)"\s*:\s*)(?:(?!["\d\{\[\-+])[^,\]}\s]+)(?=\s*[,\]}])/g, '$1"$3"')
src/services/code-index/embedders/matterai.ts

Location: src/services/code-index/embedders/matterai.ts (Lines 55-55)

🔵 Code Quality

Issue: Debug console.log statements left in production code will expose internal errors and clutter logs.

Fix: Remove or replace with proper logging mechanism.

Impact: Improves security and log management.

-  			console.error("MatterAI embedder error in createEmbeddings:", error) // kilocode_change
+  
src/services/code-index/embedders/matterai.ts

Location: src/services/code-index/embedders/matterai.ts (Lines 75-75)

🔵 Code Quality

Issue: Debug console.log statement left in production code will expose internal errors and clutter logs.

Fix: Remove or replace with proper logging mechanism.

Impact: Improves security and log management.

-  			console.error("MatterAI embedder error in validateConfiguration:", error) // kilocode_change
+  
webview-ui/src/components/ui/hooks/useOpenRouterModelProviders.ts

Location: webview-ui/src/components/ui/hooks/useOpenRouterModelProviders.ts (Lines 40-178)

🟡 Performance

Issue: Large hardcoded KILO_CODE_MODELS object increases bundle size and should be dynamically loaded for better maintainability.

Fix: Consider moving this data to a separate JSON file or loading it dynamically to reduce initial bundle size.

Impact: Reduces initial load time and improves maintainability of model definitions.

-  const KILO_CODE_MODELS: Record<string, KiloCodeModel> = {
-  	"axon-code": {
-  		id: "axon-code",
-  		name: "Axon Code",
-  		description: "Axon Code is super intelligent LLM model for coding tasks",
-  		input_modalities: ["text"],
-  		context_length: 256000,
-  		max_output_length: 32768,
-  		output_modalities: ["text"],
-  		supported_sampling_parameters: [
-  			"temperature",
-  			"top_p",
-  			"top_k",
-  			"repetition_penalty",
-  			"frequency_penalty",
-  			"presence_penalty",
-  			"seed",
-  			"stop",
-  		],
-  		supported_features: ["tools", "structured_outputs", "web_search"],
-  		openrouter: {
-  			slug: "matterai/axon",
-  		},
-  		datacenters: [{ country_code: "US" }],
-  		created: 1750426201,
-  		owned_by: "matterai",
-  		pricing: {
-  			prompt: "0.000001",
-  			completion: "0.000004",
-  			image: "0",
-  			request: "0",
-  			input_cache_reads: "0",
-  			input_cache_writes: "0",
-  		},
-  	},
-  	"axon-code-pro": {
-  		id: "axon-code-pro",
-  		name: "Axon Code Pro",
-  		description: "Axon Code Pro is a heavy, powerfull and super intelligent LLM model for coding tasks",
-  		input_modalities: ["text"],
-  		context_length: 192000,
-  		max_output_length: 192000,
-  		output_modalities: ["text"],
-  		supported_sampling_parameters: [
-  			"temperature",
-  			"top_p",
-  			"top_k",
-  			"repetition_penalty",
-  			"frequency_penalty",
-  			"presence_penalty",
-  			"seed",
-  			"stop",
-  		],
-  		supported_features: ["tools", "structured_outputs", "web_search"],
-  		openrouter: {
-  			slug: "matterai/axon-code-pro",
-  		},
-  		datacenters: [{ country_code: "US" }],
-  		created: 1762009846,
-  		owned_by: "matterai",
-  		pricing: {
-  			prompt: "0.000002",
-  			completion: "0.000008",
-  			image: "0",
-  			request: "0",
-  			input_cache_reads: "0",
-  			input_cache_writes: "0",
-  		},
-  	},
-  	axon: {
-  		id: "axon",
-  		name: "Axon",
-  		description: "Axon is an general purpose super intelligent LLM model for high-effort day-to-day tasks",
-  		input_modalities: ["text"],
-  		context_length: 256000,
-  		max_output_length: 32768,
-  		output_modalities: ["text"],
-  		supported_sampling_parameters: [
-  			"temperature",
-  			"top_p",
-  			"top_k",
-  			"repetition_penalty",
-  			"frequency_penalty",
-  			"presence_penalty",
-  			"seed",
-  			"stop",
-  		],
-  		supported_features: ["tools", "structured_outputs", "web_search"],
-  		openrouter: {
-  			slug: "matterai/axon",
-  		},
-  		datacenters: [{ country_code: "US" }],
-  		created: 1750426201,
-  		owned_by: "matterai",
-  		pricing: {
-  			prompt: "0.000001",
-  			completion: "0.000004",
-  			image: "0",
-  			request: "0",
-  			input_cache_reads: "0",
-  			input_cache_writes: "0",
-  		},
-  	},
-  	"axon-mini": {
-  		id: "axon-mini",
-  		name: "Axon Mini",
-  		description:
-  			"Axon Mini is an general purpose super intelligent LLM coding model for low-effort day-to-day tasks",
-  		input_modalities: ["text"],
-  		context_length: 256000,
-  		max_output_length: 16384,
-  		output_modalities: ["text"],
-  		supported_sampling_parameters: [
-  			"temperature",
-  			"top_p",
-  			"top_k",
-  			"repetition_penalty",
-  			"frequency_penalty",
-  			"presence_penalty",
-  			"seed",
-  			"stop",
-  		],
-  		supported_features: ["tools", "structured_outputs", "web_search"],
-  		openrouter: {
-  			slug: "matterai/axon",
-  		},
-  		datacenters: [{ country_code: "US" }],
-  		created: 1750426201,
-  		owned_by: "matterai",
-  		pricing: {
-  			prompt: "2.5e-7",
-  			completion: "0.000001",
-  			image: "0",
-  			request: "0",
-  			input_cache_reads: "0",
-  			input_cache_writes: "0",
-  		},
-  	},
-  }
+  // Consider moving KILO_CODE_MODELS to a separate JSON file
+  // import KILO_CODE_MODELS from './kilocode-models.json'

Co-authored-by: matter-code-review[bot] <150888575+matter-code-review[bot]@users.noreply.github.com>
Copy link
Contributor

@matter-ai-bot matter-ai-bot bot left a comment

Choose a reason for hiding this comment

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

🧪 PR Review is completed: Reviewing OpenRouter client initialization change for security and configuration correctness

Comment on lines 147 to 150
const apiKey = this.options.openRouterApiKey ?? "not-provided"

// this.client = new OpenAI({ baseURL, apiKey, defaultHeaders: DEFAULT_HEADERS })
this.client = new OpenAI({ baseURL, apiKey, defaultHeaders: DEFAULT_HEADERS })
Copy link
Contributor

Choose a reason for hiding this comment

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

🔴 Security

Issue: The API key defaults to "not-provided" when openRouterApiKey is undefined, which could lead to runtime failures or expose development configuration in production.

Fix: Add proper validation to ensure the API key is provided before client initialization, or throw a clear error if missing.

Impact: Prevents runtime errors and ensures proper configuration validation

Suggested change
const apiKey = this.options.openRouterApiKey ?? "not-provided"
// this.client = new OpenAI({ baseURL, apiKey, defaultHeaders: DEFAULT_HEADERS })
this.client = new OpenAI({ baseURL, apiKey, defaultHeaders: DEFAULT_HEADERS })
if (!this.options.openRouterApiKey) {
throw new Error('OpenRouter API key is required but not provided');
}
const apiKey = this.options.openRouterApiKey;
this.client = new OpenAI({ baseURL, apiKey, defaultHeaders: DEFAULT_HEADERS })

Fix in Cursor

Copy link
Member Author

Choose a reason for hiding this comment

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

/matter remember this is by design

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it — Updated memory for OpenRouter API Key Validation Design Decision 📖

@code-crusher code-crusher merged commit 79bb961 into main Nov 14, 2025
5 of 12 checks passed
@code-crusher code-crusher deleted the refine_codebase_learning branch November 14, 2025 11:34
@code-crusher
Copy link
Member Author

/matter release-notes

@matter-ai-bot
Copy link
Contributor

matter-ai-bot bot commented Nov 14, 2025

What's Changed

Summary

This PR refines the codebase learning capabilities by introducing MatterAI embedding support, enhancing code indexing, and improving UI components. It also includes critical fixes for JSON parsing and updates to system prompts for better tool usage.

New Features

  • Introduced MatterAI embedder for code indexing with support for matterai-embedding-large model
  • Added new search_files tool with comprehensive documentation and validation for file pattern usage
  • Enhanced code indexing configuration to support MatterAI provider and OpenRouter API key integration
  • Added new UI components and improved existing ones including CodeBlock, MarkdownBlock, and AlertDialog styling
  • Implemented JSON argument parsing fixes for function calls with unquoted string values

Bug fixes

  • Fixed JSON parsing errors by implementing automatic correction for unquoted string values in function arguments
  • Corrected header management by adding X-AxonCode-Version to API requests
  • Removed unused variables and cleaned up codebase
  • Fixed UI styling issues in code blocks and markdown rendering
  • Resolved configuration loading for OpenRouter API key in code indexing service

Commits

Dependencies added

  • MatterAI Embedder: New embedder implementation for code indexing using MatterAI's embedding API with matterai-embedding-large model support
  • Shiki Highlighter: Enhanced code block highlighting capabilities with language normalization and extended language support
  • Lucide React Icons: Added new icons including Search, CornerDownRight, Check, Copy for improved UI components
  • VSCode Webview UI Toolkit: Integrated VSCodeButton, VSCodeCheckbox, VSCodeLink components for better settings UI
  • Zod Schema Validation: Added for checkpoint validation and data integrity

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