feat(context,smart-search): inject insights into session context and smart search results (#457)#615
Conversation
…smart search results (rohitg00#457) ## Summary `mem::context` (SessionStart injection) and `mem::smart-search` (hybrid search) loaded lessons but skipped insights — the higher-order reflections synthesised by `mem::reflect`. Insights sat in KV reachable only via the explicit `memory_insight_list` / `memory_insight_search` MCP tools, never surfacing automatically in context or search results. ## Diff - **src/functions/context.ts** (+34/-1): parallel-load `KV.insights` alongside lessons; filter non-deleted, project-scoped; sort by confidence descending; cap at 8; render as `## Insights` block. - **src/functions/smart-search.ts** (+41/-4): add `recallInsights()` helper calling `mem::insight-search` with minConfidence 0.3; run in parallel with hybrid search and lesson recall; attach results as `insights` field on the compact response. Reuses `CompactLessonResult` type — insight fields map cleanly onto it. Both follow the existing lessons pattern exactly: same cap strategy, token-budget loop, recency sort, and best-effort catch semantics. ## Validation - TypeScript type safety verified: `Insight` interface (types.ts:757) fields all match; `KV.insights` scope defined (schema.ts:38); `mem::insight-search` payload signature matches handler (reflect.ts:361). - Reviewer agent passed: 0 Critical, 0 Major. Two Minor observations (M1: `includeInsights` param, M2: `ContextBlock.type` — both addressable in follow-up). - npm install blocked by pre-existing arborist bug on Windows (@node-rs/jieba + @anthropic-ai/claude-agent-sdk optional deps trigger npm 10/11 canDedupe crash). Unrelated to this change. CI runs ubuntu+macos only per `.github/workflows/ci.yml`. - Existing tests do not reference insights — this is purely additive, no test assertion changes needed. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Someone is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughAgent memory context and smart-search functions now retrieve insights in parallel with existing data. The context handler aggregates insights into the memory prompt with filtering, sorting, and formatting; smart-search performs insight recall alongside hybrid search and lesson recall, extending the response payload to include insights when available. ChangesInsight Retrieval and Integration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
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 unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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.
🧹 Nitpick comments (2)
src/functions/smart-search.ts (1)
85-88: ⚡ Quick winDrop this WHAT-style comment and let naming carry intent.
This comment explains mechanics already visible in the code path; prefer clearer local naming over explanatory prose.
As per coding guidelines, "Avoid code comments explaining WHAT — use clear naming instead".
🤖 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 `@src/functions/smart-search.ts` around lines 85 - 88, Remove the WHAT-style block comment and instead make the intent explicit via names: delete the three-line comment and ensure the parallel calls are named/encapsulated with clear identifiers (e.g., runObservationHybridSearch, runLessonRecall, runInsightRecall or a helper like performParallelBestEffortLookups) and use descriptive result variable names (e.g., observationResults, lessonRecallResults, insightRecallResults) so the code reads self-documentingly without the explanatory comment.src/functions/context.ts (1)
137-140: ⚡ Quick winRemove WHAT-style inline commentary in this block.
Please replace this explanatory block comment with self-descriptive naming (or keep only intent-level rationale if needed).
As per coding guidelines, "Avoid code comments explaining WHAT — use clear naming instead".
🤖 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 `@src/functions/context.ts` around lines 137 - 140, Remove the WHAT-style explanatory block comment and instead make the code self-descriptive: replace the multi-line comment about "Insights — higher-order reflections..." with either a short intent-level comment (one line) or better, rename the related symbol(s) such as the insights collection/variable and any helper like mem::reflect to a self-descriptive identifier (e.g., insights, reflectInsights, cappedInsights) so the purpose is clear from names; keep only a brief rationale about the 8-item cap or token-budget behavior if needed (mentioning "8-item cap for token-budget trimming") and delete the rest of the inline WHAT commentary.
🤖 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.
Nitpick comments:
In `@src/functions/context.ts`:
- Around line 137-140: Remove the WHAT-style explanatory block comment and
instead make the code self-descriptive: replace the multi-line comment about
"Insights — higher-order reflections..." with either a short intent-level
comment (one line) or better, rename the related symbol(s) such as the insights
collection/variable and any helper like mem::reflect to a self-descriptive
identifier (e.g., insights, reflectInsights, cappedInsights) so the purpose is
clear from names; keep only a brief rationale about the 8-item cap or
token-budget behavior if needed (mentioning "8-item cap for token-budget
trimming") and delete the rest of the inline WHAT commentary.
In `@src/functions/smart-search.ts`:
- Around line 85-88: Remove the WHAT-style block comment and instead make the
intent explicit via names: delete the three-line comment and ensure the parallel
calls are named/encapsulated with clear identifiers (e.g.,
runObservationHybridSearch, runLessonRecall, runInsightRecall or a helper like
performParallelBestEffortLookups) and use descriptive result variable names
(e.g., observationResults, lessonRecallResults, insightRecallResults) so the
code reads self-documentingly without the explanatory comment.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 66bed8b9-6123-4557-a229-04ff95bdb8a6
📒 Files selected for processing (2)
src/functions/context.tssrc/functions/smart-search.ts
Summary
mem::context(SessionStart injection) andmem::smart-search(hybridsearch) loaded lessons but skipped insights — the higher-order reflections
synthesised by
mem::reflect. Insights sat in KV reachable only via theexplicit
memory_insight_list/memory_insight_searchMCP tools, neversurfacing automatically in context or search results.
Diff
KV.insightsalongside lessons; filter non-deleted, project-scoped; sort by
confidence descending; cap at 8; render as
## Insightsblock.recallInsights()helper calling
mem::insight-searchwith minConfidence 0.3; run inparallel with hybrid search and lesson recall; attach results as
insightsfield on the compact response. ReusesCompactLessonResulttype.
Both follow the existing lessons pattern exactly: same cap strategy,
token-budget loop, recency sort, and best-effort catch semantics.
Validation
Insightinterface fields all match;KV.insightsscope defined;
mem::insight-searchpayload signature matches handler.@node-rs/jieba@anthropic-ai/claude-agent-sdkoptional deps trigger npm 10/11canDedupe crash). Unrelated to this change. CI runs ubuntu+macos only.
assertion changes needed.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features