Repository navigation
Improve package action search results - #412
Conversation
📝 WalkthroughWalkthroughThis PR introduces package action-aware search matching to Kody's MCP search pipeline. It adds types for matched package actions, computes action matches from package export metadata scored against query tokens, formats results with "Best action" import guidance, and expands task lexicon term recognition for operate queries. ChangesPackage Action Matching in Search
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
🔎 Preview deployed: https://kody-pr-412.kentcdodds.workers.dev Worker: Mocks:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/worker/src/mcp/tools/search.ts (1)
927-930: ⚡ Quick winAvoid recomputing query tokens per package row.
extractMeaningfulSearchTokens(input.query)is invariant per query, but it runs once per package row. Precompute it once before the map to reduce repeated tokenization on larger package sets.♻️ Suggested diff
function buildPackageCandidates(input: { query: string rows: Array<PackageSearchRow> queryEmbedding: ReadonlyArray<number> }): Array<SearchCandidate> { + const meaningfulTokens = extractMeaningfulSearchTokens(input.query) return input.rows .map((entry) => { const exports = Array.isArray(entry.projection.exports) ? entry.projection.exports : [] @@ const actionMatches = buildPackageActionMatches({ query: input.query, - meaningfulTokens: extractMeaningfulSearchTokens(input.query), + meaningfulTokens, exports, })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/worker/src/mcp/tools/search.ts` around lines 927 - 930, extractMeaningfulSearchTokens(input.query) is being recomputed for every package row; precompute it once before iterating packages and reuse the result inside the map that calls buildPackageActionMatches. Specifically, call extractMeaningfulSearchTokens(input.query) into a variable (e.g., meaningfulTokens) outside the loop/array.map, then pass that variable to buildPackageActionMatches instead of calling the function inline so actionMatches is created using the precomputed meaningfulTokens together with input.query and exports.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/worker/src/mcp/tools/search-format.ts`:
- Around line 647-651: The nextStep construction currently prefers opening the
app when match.hasApp even if an action-specific usage
(primaryAction/primaryActionFunction) exists; change the conditional order so
nextStep first checks for primaryAction && primaryActionFunction and uses `Use
${primaryActionFunction.usage}; inspect search({ entity:
"${match.kodyId}:package" }) only if you need more exports.`, then fall back to
match.hasApp with `Open the app with open_generated_ui({ kody_id:
"${match.kodyId}" }) or inspect package detail...`, and finally the
package-inspect/import fallback using `Inspect package detail... import from
"${buildPackageImportSpecifier(match.name, '.')}".` Apply the same reorder to
the analogous block around the other occurrence (lines ~660-663) so
action-prioritized usage always wins over hasApp.
---
Nitpick comments:
In `@packages/worker/src/mcp/tools/search.ts`:
- Around line 927-930: extractMeaningfulSearchTokens(input.query) is being
recomputed for every package row; precompute it once before iterating packages
and reuse the result inside the map that calls buildPackageActionMatches.
Specifically, call extractMeaningfulSearchTokens(input.query) into a variable
(e.g., meaningfulTokens) outside the loop/array.map, then pass that variable to
buildPackageActionMatches instead of calling the function inline so
actionMatches is created using the precomputed meaningfulTokens together with
input.query and exports.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 764cb75d-2bda-4b4d-9657-4d548109c126
📒 Files selected for processing (6)
docs/use/execute.mdpackages/worker/src/mcp/tools/search-format.node.test.tspackages/worker/src/mcp/tools/search-format.tspackages/worker/src/mcp/tools/search.node.test.tspackages/worker/src/mcp/tools/search.tspackages/worker/src/mcp/tools/understand-search-query.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 005623a. Configure here.
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
7e0a9a4 to
f777463
Compare

Summary
createAuthenticatedFetchmust be awaited before using the returned fetch wrapper.main.Testing
npm test -- search.node.test.ts search-format.node.test.tsnpm run format:checknpm run typechecknpm run lintnpm run testnpm run buildSummary by CodeRabbit
New Features
add,create,update,schedule).Documentation
Tests