Skip to content

feat: add opt-in prompt-time proactive recall - #1129

Closed
EugeneTrapeznikov wants to merge 1 commit into
rohitg00:mainfrom
EugeneTrapeznikov:feat/prompt-proactive-recall
Closed

feat: add opt-in prompt-time proactive recall#1129
EugeneTrapeznikov wants to merge 1 commit into
rohitg00:mainfrom
EugeneTrapeznikov:feat/prompt-proactive-recall

Conversation

@EugeneTrapeznikov

@EugeneTrapeznikov EugeneTrapeznikov commented Jul 30, 2026

Copy link
Copy Markdown

Summary

  • add AGENTMEMORY_PROMPT_RECALL=true as a separate, default-off opt-in for proactive recall on UserPromptSubmit
  • support Claude Code and Codex while keeping Copilot's shared prompt hook observe-only
  • query /agentmemory/smart-search with a 500 ms fail-open deadline and inject at most 5 compact memories (lessons excluded)
  • preserve existing prompt observation capture and exclude automatic prompt-hook searches from follow-up diagnostics
  • load hook configuration from ~/.agentmemory/.env, sanitize recalled labels, and document/expose the new flag

Why a separate flag?

AGENTMEMORY_INJECT_CONTEXT enables SessionStart and PreToolUse injection. This PR allows users to opt into prompt-time recall only, without enabling those other injection points.

Validation

  • npm run build
  • HOME=<clean-temp-home> npx vitest run — 1,452 passed, 1 skipped
  • targeted prompt/Copilot/context/diagnostic tests — 35 passed
  • npm run skills:check
  • npm pack --dry-run --json — generated prompt hook and skills included
  • git diff --check

Scope note

Claude Code and Codex share the registered UserPromptSubmit hook/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

    • Added optional prompt-time memory recall for Claude Code and Codex.
    • When enabled, up to five relevant, sanitized memories can be added to each prompt.
    • Added independent configuration, status reporting, and .env support.
  • Bug Fixes

    • Prompt-hook searches are excluded from diagnostic follow-up statistics.
    • Copilot remains observation-only, without injected context.
  • Documentation

    • Updated configuration, hook, and setup documentation with prompt-recall behavior and defaults.

@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown

@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.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added opt-in prompt-time memory recall for Claude Code and Codex prompts, with .env fallback configuration, sanitized smart-search results, observation telemetry, runtime reporting, Copilot exclusion, and fail-open test coverage.

Changes

Prompt recall

Layer / File(s) Summary
Configuration contract
.env.example, README.md, AGENTS.md, plugin/skills/..., src/config.ts
Documents and exposes default-disabled AGENTMEMORY_PROMPT_RECALL independently from context injection.
Prompt hook recall flow
src/hooks/*, plugin/scripts/prompt-submit.mjs
Loads hook configuration, observes prompts, queries smart search with authenticated headers, sanitizes results, and emits bounded context for Claude Code and Codex while skipping Copilot recall.
Runtime and diagnostic integration
src/index.ts, src/triggers/api.ts, src/functions/smart-search.ts
Reports prompt-recall status and excludes prompt-hook searches from follow-up diagnostics.
Hook and diagnostic validation
test/prompt-recall.test.ts, test/copilot-plugin.test.ts, test/diagnostic-followup-rate.test.ts
Covers configuration, output, sanitization, failure tolerance, Copilot behavior, and diagnostic exclusion.

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
Loading

Possibly related PRs

Suggested reviewers: rohitg00

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the opt-in prompt-time proactive recall feature, which is the pull request’s primary change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8c90741 and 39cd269.

📒 Files selected for processing (16)
  • .env.example
  • AGENTS.md
  • README.md
  • plugin/scripts/prompt-submit.mjs
  • plugin/skills/agentmemory-config/REFERENCE.md
  • plugin/skills/agentmemory-config/SKILL.md
  • plugin/skills/agentmemory-hooks/SKILL.md
  • src/config.ts
  • src/functions/smart-search.ts
  • src/hooks/_env.ts
  • src/hooks/prompt-submit.ts
  • src/index.ts
  • src/triggers/api.ts
  • test/copilot-plugin.test.ts
  • test/diagnostic-followup-rate.test.ts
  • test/prompt-recall.test.ts

Comment on lines +142 to +162
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(),
);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 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 and clearTimeout it immediately after recallContext resolves, 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 same clearTimeout.
📍 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.

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