Fix memories indexing in non-git projects and harden the sync hook#11
Merged
Conversation
- Resolve the project root without requiring a git repo (git toplevel when present, else launch dir), so memories in a plain folder are indexed - Mark indexed only on verified success and re-index when the library is missing, so a failed or cleared index no longer sticks at zero - Add a session-scoped, best-effort diagnostic log (gitignored)
47bc21e to
7abfae7
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the memories sync hook so .claude/memories/*.md are indexed into docs-mcp-server even when running in non-git directories, and makes indexing more resilient to partial failures or cleared stores.
Changes:
- Resolve
project_rootwithout requiring a git repo, add per-session logging, and gate “indexed” state on verified document presence. - Add recovery behavior on
SessionStartwhen the docs-mcp-server store is missing/empty. - Extend ignore rules to exclude the new indexing log, and add a repo
.gitignorewith common macOS ignores.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| techpack.yaml | Ignores the new .claude/.memories-index.log file from version control via the pack’s gitignore component. |
| hooks/sync-memories.sh | Reworks root resolution and indexing logic; adds logging and validates index success via document count. |
| .gitignore | Adds macOS-specific ignore entries for this repository. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+19
to
+23
| project_root=$(git rev-parse --show-toplevel 2>/dev/null) | ||
| if [ -z "$project_root" ]; then | ||
| cwd=$(printf '%s' "$hook_input" | jq -r '.cwd // empty' 2>/dev/null) | ||
| project_root="${CLAUDE_PROJECT_DIR:-${cwd:-$PWD}}" | ||
| fi |
Comment on lines
+72
to
+77
| # --- Decide whether to (re)index --- | ||
| # The cheap local checks (timestamp vs. file mtimes) run every invocation. The | ||
| # store-existence probe spawns npx, so it runs only at SessionStart — enough to | ||
| # re-add a library whose store was cleared while its timestamp lingered, without | ||
| # paying npx on every prompt. Anything changed, or no timestamp yet, => index. | ||
| should_index=1 |
| printf '%s %s\n' "$(date '+%Y-%m-%dT%H:%M:%S')" "$1" 2>/dev/null >>"$LOG_FILE" || true | ||
| } | ||
|
|
||
| repo_name=$(basename "$project_root") |
| } | ||
|
|
||
| repo_name=$(basename "$project_root") | ||
| memories_url="file://$MEMORIES_DIR" |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Memories weren't indexed for anyone running Claude in a plain (non-git) folder: the sync hook resolved the project through git and bailed out immediately when there was no repo, so nothing was ever scraped and the search interface showed no libraries. Separately, a single failed index — or an externally cleared store — could permanently mark the project as "indexed" and leave the library stuck at zero.
Now the hook anchors to the git repo root when there is one — so launching from any subdirectory of a repo resolves to the same memories and library — and otherwise falls back to where Claude was launched, so non-git folders index correctly. Indexing is recorded only after content is verified present, and a missing library is re-added at session start, so failures and cleared stores recover instead of sticking.
Test plan
.claude/memories/*.mdwith Ollama running, start a session → expect the library to appear in docs-mcp-server and the last-indexed marker to be written.