Skip to content

Fix/stop hook tool turn parsing#27

Merged
sachitrafa merged 2 commits into
mainfrom
fix/stop-hook-tool-turn-parsing
Jul 14, 2026
Merged

Fix/stop hook tool turn parsing#27
sachitrafa merged 2 commits into
mainfrom
fix/stop-hook-tool-turn-parsing

Conversation

@sachitrafa

Copy link
Copy Markdown
Owner

No description provided.

sachitrafa and others added 2 commits July 14, 2026 13:53
extract_all_exchanges paired each user prompt with messages[i+1] — the
assistant's short preamble ("I'll fetch that repository...") — and threw
away the real answer that follows the tool calls. Tool results are type
"user" with no text block, so they filter out and the preamble wins the
pairing. Every tool-using turn (most turns) therefore posted a
fact-free exchange to /auto-store and stored nothing, silently.

Join every assistant text block up to the next real user message, and
truncate to the TAIL of the 4000-char budget so a long turn keeps the
answer (last) over the progress notes (first).

Because setup COPIES hooks into ~/.claude/hooks and registers those
copies, upgrading the package alone would not fix installed users. Add
src/services/hook_sync.py, run from server startup (which always ships
the current templates), to refresh stale hook copies by content hash. It
never creates hooks a user lacks and never touches settings.json.

Tests: tests/test_store_hook.py (parser), tests/test_hook_sync.py (sync).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Turns the advisory access checks into real enforcement. New require_caller()
dependency resolves a trusted identity from the ym_ API key
(Authorization: Bearer / X-YourMemory-Key); effective_user() locks userId/
memberId to that identity so a caller can't act as anyone else.

Two postures via YOURMEMORY_AUTH:
- off (default): unchanged behaviour — no key works, client-supplied id honoured
  (keeps every local install / MCP hook working; safe because loopback-bound).
- required: every request needs a valid key; missing/invalid -> 401; identity
  is taken from the key, ignoring any client-claimed userId/memberId.

Wired into memory routes (add/update/delete/list), /retrieve (incl. its pool
union path, which already filters by the now-trusted user_id), and pool
write/list/retrieve.

Also fixes a latent bug: validate_api_key() did dict(row), which only worked on
postgres (RealDictCursor) and crashed on DuckDB/SQLite tuples — so agent-key
auth was broken on the default backend. Now maps the row by column.

tests/test_auth.py proves both modes: off works keyless; required blocks
cross-user reads, id spoofing, and unauthorized pool writes (8/8). Existing
pool suite still 10/10; live server in off mode unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cognitive-ai-memory Ready Ready Preview, Comment Jul 14, 2026 6:23pm

@sachitrafa
sachitrafa merged commit 0bda3e0 into main Jul 14, 2026
3 checks passed
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