feat: add opt-in prompt-time proactive recall - #1129
Conversation
|
@EugeneTrapeznikov is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughAdded opt-in prompt-time memory recall for Claude Code and Codex prompts, with ChangesPrompt recall
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant PromptSubmitHook
participant AgentMemory
participant SmartSearch
participant ClaudeOrCodex
PromptSubmitHook->>AgentMemory: Observe normalized prompt
PromptSubmitHook->>SmartSearch: Request prompt-hook memories
SmartSearch-->>PromptSubmitHook: Return compact search results
PromptSubmitHook->>ClaudeOrCodex: Emit sanitized UserPromptSubmit context
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/hooks/prompt-submit.ts`:
- Around line 142-162: Capture the exit timer handle in the prompt-submit flow,
then call clearTimeout immediately after recallContext resolves and before
writing model-visible stdout; preserve the existing timeout behavior for recall
and non-recall paths. Regenerate plugin/scripts/prompt-submit.mjs from the fixed
src/hooks/prompt-submit.ts so it includes the same timer clearing.
🪄 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: 9fc2b98b-465b-44d8-aa3c-37093ee54f6e
📒 Files selected for processing (16)
.env.exampleAGENTS.mdREADME.mdplugin/scripts/prompt-submit.mjsplugin/skills/agentmemory-config/REFERENCE.mdplugin/skills/agentmemory-config/SKILL.mdplugin/skills/agentmemory-hooks/SKILL.mdsrc/config.tssrc/functions/smart-search.tssrc/hooks/_env.tssrc/hooks/prompt-submit.tssrc/index.tssrc/triggers/api.tstest/copilot-plugin.test.tstest/diagnostic-followup-rate.test.tstest/prompt-recall.test.ts
| setTimeout( | ||
| () => process.exit(0), | ||
| promptRecall ? RECALL_TIMEOUT_MS + 250 : 500, | ||
| ).unref(); | ||
|
|
||
| if (!promptRecall) return; | ||
|
|
||
| const additionalContext = await recallContext(prompt, project, sessionId); | ||
| if (!additionalContext) return; | ||
|
|
||
| await new Promise<void>((resolve) => { | ||
| process.stdout.write( | ||
| JSON.stringify({ | ||
| hookSpecificOutput: { | ||
| hookEventName: "UserPromptSubmit", | ||
| additionalContext, | ||
| }, | ||
| }), | ||
| () => resolve(), | ||
| ); | ||
| }); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Exit timer is never cleared before the model-visible stdout write. The recall path arms a process.exit(0) timer at RECALL_TIMEOUT_MS + 250 and then awaits recall plus a stdout flush; a recall that lands near its 500 ms deadline can be interrupted mid-write, emitting truncated JSON that the host injects as raw text.
src/hooks/prompt-submit.ts#L142-L162: capture the timer handle andclearTimeoutit immediately afterrecallContextresolves, before writing to stdout.plugin/scripts/prompt-submit.mjs#L156-L165: regenerate this bundle from the fixed source so the shipped plugin script carries the sameclearTimeout.
📍 Affects 2 files
src/hooks/prompt-submit.ts#L142-L162(this comment)plugin/scripts/prompt-submit.mjs#L156-L165
🤖 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/hooks/prompt-submit.ts` around lines 142 - 162, Capture the exit timer
handle in the prompt-submit flow, then call clearTimeout immediately after
recallContext resolves and before writing model-visible stdout; preserve the
existing timeout behavior for recall and non-recall paths. Regenerate
plugin/scripts/prompt-submit.mjs from the fixed src/hooks/prompt-submit.ts so it
includes the same timer clearing.
Summary
AGENTMEMORY_PROMPT_RECALL=trueas a separate, default-off opt-in for proactive recall onUserPromptSubmit/agentmemory/smart-searchwith a 500 ms fail-open deadline and inject at most 5 compact memories (lessons excluded)~/.agentmemory/.env, sanitize recalled labels, and document/expose the new flagWhy a separate flag?
AGENTMEMORY_INJECT_CONTEXTenables SessionStart and PreToolUse injection. This PR allows users to opt into prompt-time recall only, without enabling those other injection points.Validation
npm run buildHOME=<clean-temp-home> npx vitest run— 1,452 passed, 1 skippednpm run skills:checknpm pack --dry-run --json— generated prompt hook and skills includedgit diff --checkScope note
Claude Code and Codex share the registered
UserPromptSubmithook/output contract. Automated tests validate the emitted context envelope; an interactive Codex host smoke was not run in this PR workspace.Summary by CodeRabbit
New Features
.envsupport.Bug Fixes
Documentation