Skip to content

Comments

feat(kilo): codebase search tool #405

Open
mikij wants to merge 26 commits intoKilo-Org:devfrom
mikij:feat/codebase-search-tool
Open

feat(kilo): codebase search tool #405
mikij wants to merge 26 commits intoKilo-Org:devfrom
mikij:feat/codebase-search-tool

Conversation

@mikij
Copy link
Contributor

@mikij mikij commented Feb 17, 2026

Context

Added cloud based codebase_search tool to CLI. closes #409

Implementation

This tool implementation reuses VSCode codebase indexing. As I am using Mistral embedded model with Qdrant cloud vector DB, I tested only that type of index search. Added tools menu to the CLI (can be invoked by /tools command or Ctrl+P) to setup tool. API keys for Mistral and Qdrant must be added via /connect or manual editing of auth.json.

Screenshots

before after
image

How to Test

Picture tells more than thousend words:
image

Get in Touch

Discord user id: 861519093852012544

Extract Kilo-specific codebase search utilities into a dedicated module
to improve code organization and minimize merge conflicts with upstream.

Changes:
- Add types.ts with Zod schemas for configuration validation
- Add config.ts for configuration loading with defaults
- Add collection.ts for SHA-256 hash-based collection naming
- Add embeddings.ts with OpenAI, Mistral, Ollama provider support
- Refactor codebase-search.ts to use extracted modules
- Conditionally register tool only when configured
- Add comprehensive unit tests
Rename tool definition and permission identifiers from kebab-case
(codebase-search) to snake_case (codebase_search) for naming consistency.
@github-actions
Copy link
Contributor

Hey! Your PR title Feat/codebase search tool doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, kilo).

See CONTRIBUTING.md for details.

Add a new codebase search tool with support for semantic search using Qdrant or LanceDB vector databases. Includes:
- Documentation in AGENTS.md
- Codebase search configuration dialog (dialog-tool-codebase-search.tsx)
- Tool selection dialog (dialog-tool.tsx)
- Integration with prompt menu in prompt/index.tsx

The tool allows configuring:
- Embedding model (e.g., codestral-embed-2505, text-embedding-3-small)
- Vector database type (Qdrant or LanceDB)
- Database connection settings (URL for Qdrant, path for LanceDB)
- Similarity threshold for search results
- Maximum number of results to return

Configuration is saved to opencode.jsonc file in the project or global config directory.
@mikij mikij force-pushed the feat/codebase-search-tool branch from 89d65ca to 708f008 Compare February 17, 2026 22:56
@mikij mikij changed the title Feat/codebase search tool feat(tools): codebase search tool Feb 17, 2026
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@mikij mikij changed the title feat(tools): codebase search tool feat(kilo): codebase search tool Feb 18, 2026
Export formatResults function to enable direct testing. Add comprehensive
test coverage for edge cases including empty results, threshold filtering,
max results limiting, and output formatting.
@mikij mikij marked this pull request as ready for review February 18, 2026 09:23
@mikij mikij marked this pull request as draft February 19, 2026 13:42
@mikij mikij force-pushed the feat/codebase-search-tool branch from a6c7dcb to d319a33 Compare February 19, 2026 13:57
@mikij mikij force-pushed the feat/codebase-search-tool branch from d319a33 to cc7e1be Compare February 19, 2026 14:07
@mikij mikij marked this pull request as ready for review February 19, 2026 14:08
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 19, 2026

Code Review Summary

Status: 15 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 3
WARNING 8
SUGGESTION 4
Issue Details (click to expand)

CRITICAL

File Line Issue
packages/opencode/src/cli/cmd/run.ts Tool ID mismatch — the tool is defined as "codebase_search" but may not match the expected pattern in the handler
packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx Permission name mismatch — the tool sends permission: "codebase_search" but the permission UI may not handle it correctly
packages/opencode/src/cli/cmd/tui/routes/session/index.tsx 1479 Tool ID mismatch — same issue as in run.ts

WARNING

File Line Issue
packages/opencode/src/server/routes/config.ts Instance.dispose() was replaced with clearCache() — verify this doesn't break config update flow
packages/opencode/src/kilocode/codebase-search/embeddings.ts Potential runtime error — data.data[0].embedding could fail if API returns empty array
packages/opencode/src/index.ts process.stdin change appears unrelated to codebase search feature
packages/opencode/src/kilocode/codebase-search/config.ts Config.parse(raw) throws a ZodError if the config is malformed — safeParse is used correctly but the error is silently swallowed (returns null)
packages/opencode/src/cli/cmd/tui/routes/session/index.tsx 1870 metadata.results will always be undefined — the tool returns metadata: { results: limitedResults.length } which is a number, but the <Show when={metadata.results}> check treats 0 as falsy
packages/opencode/src/tool/codebase-search.ts Redundant double-filtering — lines 203–204 filter by similarityThreshold then slice by maxResults, but maxResults was already passed to Qdrant as limit
packages/opencode/src/cli/cmd/tui/component/dialog-tool.tsx Empty catch {} blocks (if still present) — per the project's AGENTS.md, empty catch blocks should at minimum log the error
packages/opencode/src/cli/cmd/tui/component/dialog-tool.tsx Empty catch {} block — same issue (second occurrence)

SUGGESTION

File Line Issue
packages/opencode/src/cli/cmd/tui/component/dialog-tool.tsx Dead code — getExistingConfig was defined but never called (may have been fixed)
packages/opencode/src/server/routes/config.ts Unnecessary dynamic import — Config is already imported statically
packages/opencode/src/project/state.ts Dead code — clearAll was defined but never called (may have been fixed)
packages/opencode/AGENTS.md 80 JSON comment in code block — the block is tagged jsonc which supports comments, so this is actually valid
Other Observations (not in diff)

Several issues from the initial review appear to have been addressed in subsequent commits:

  • Empty catch {} blocks in dialog-tool.tsx — no longer present in the current code
  • Dead code getExistingConfig in dialog-tool.tsx — no longer present in the current code
  • Dead code clearAll in state.ts — no longer present in the current code

The AGENTS.md line 80 comment about "Invalid JSON comment" is a false positive — the code block is correctly tagged as jsonc which supports comments.

Files Reviewed (26 files)
  • bun.lock — 0 issues (generated)
  • package.json — 0 issues
  • packages/opencode/AGENTS.md — 1 issue
  • packages/opencode/src/cli/cmd/run.ts — 1 issue
  • packages/opencode/src/cli/cmd/tui/component/dialog-tool-codebase-search.tsx — 0 issues
  • packages/opencode/src/cli/cmd/tui/component/dialog-tool.tsx — 2 issues
  • packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx — 0 issues
  • packages/opencode/src/cli/cmd/tui/routes/session/index.tsx — 2 issues
  • packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx — 1 issue
  • packages/opencode/src/config/config.ts — 1 issue
  • packages/opencode/src/kilocode/codebase-search/collection.ts — 0 issues
  • packages/opencode/src/kilocode/codebase-search/config.ts — 1 issue
  • packages/opencode/src/kilocode/codebase-search/embeddings.ts — 1 issue
  • packages/opencode/src/kilocode/codebase-search/index.ts — 0 issues
  • packages/opencode/src/kilocode/codebase-search/types.ts — 0 issues
  • packages/opencode/src/kilocode/index.ts — 0 issues
  • packages/opencode/src/project/instance.ts — 0 issues
  • packages/opencode/src/project/state.ts — 1 issue
  • packages/opencode/src/server/routes/config.ts — 2 issues
  • packages/opencode/src/tool/codebase-search.ts — 1 issue
  • packages/opencode/src/tool/codebase-search.txt — 0 issues
  • packages/opencode/src/tool/registry.ts — 0 issues
  • packages/opencode/test/kilocode/codebase-search.test.ts — 0 issues
  • packages/sdk/js/src/v2/gen/sdk.gen.ts — 0 issues (generated)
  • packages/sdk/js/src/v2/gen/types.gen.ts — 0 issues (generated)
  • packages/sdk/openapi.json — 0 issues (generated)
  • plans/codebase-search-to-opencode-plan.md — 0 issues

@mikij mikij force-pushed the feat/codebase-search-tool branch from 16f25ab to 4d564b9 Compare February 19, 2026 19:08
@mikij mikij marked this pull request as draft February 19, 2026 19:09
…ol name

- Rename codebase-search tool to codebase_search for consistency
- Add Config.clearCache() to clear config cache without disposing entire instance
- Add State.clearEntry() and State.clearAll() for granular state management
- Improve embeddings error handling with null check for embedding data
- Change Zod parse to safeParse in codebase-search config for better error handling
@mikij mikij marked this pull request as ready for review February 19, 2026 19:50
Add consistent error handling across all embedding providers (OpenAI, Mistral, Ollama) to properly validate response data and throw meaningful errors when embedding data is missing. Also removes unused SIGHUP handler from index.ts.
@mikij mikij marked this pull request as draft February 19, 2026 20:29
@mikij mikij marked this pull request as draft February 19, 2026 20:29
…ng logic

Move similarity threshold filtering and result limiting to the caller. Also refactor
config file existence check to use Bun.file().exists() and improve error logging.
@mikij mikij marked this pull request as ready for review February 19, 2026 22:30
Removes the unused `clearAll` function from State namespace and cleans up the unused Config import in the config route handler. Also updates AGENTS.md to use jsonc code block for better syntax highlighting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: reuse codebase search from VSCode extension in CLI

1 participant