mirror of
https://github.com/obra/episodic-memory.git
synced 2026-09-14 13:43:14 +08:00
16f4d46a7a
Implements episodic-memory sync to copy and index new conversations atomically. Features: - Copies .jsonl files from ~/.claude/projects to archive - Only copies new or modified files (mtime check) - Generates embeddings and indexes copied files - Idempotent - safe to run repeatedly - No explicit locking - uses atomic operations + SQLite WAL Race condition handling: - Atomic file copy (temp + rename) - SQLite WAL mode for concurrent database writes - mtime checks prevent duplicate copies - last_indexed prevents duplicate indexing Designed for Claude Code session-end hooks to automatically index conversations without blocking or causing conflicts. Tests: 66/66 passing including 5 new sync tests
79 lines
1.8 KiB
Bash
Executable File
79 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Resolve the real directory even if this script is symlinked
|
|
SOURCE="${BASH_SOURCE[0]}"
|
|
while [ -h "$SOURCE" ]; do
|
|
DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
SOURCE="$(readlink "$SOURCE")"
|
|
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
|
done
|
|
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
|
|
# Main CLI entry point with subcommands
|
|
COMMAND="$1"
|
|
shift
|
|
|
|
case "$COMMAND" in
|
|
index)
|
|
# Route to index-conversations script with remaining args
|
|
"$SCRIPT_DIR/index-conversations" "$@"
|
|
;;
|
|
|
|
search)
|
|
# Route to search implementation
|
|
npx tsx "$SCRIPT_DIR/../src/search-cli.ts" "$@"
|
|
;;
|
|
|
|
show)
|
|
# Route to show implementation
|
|
npx tsx "$SCRIPT_DIR/../src/show-cli.ts" "$@"
|
|
;;
|
|
|
|
stats)
|
|
# Route to stats implementation
|
|
npx tsx "$SCRIPT_DIR/../src/stats-cli.ts" "$@"
|
|
;;
|
|
|
|
sync)
|
|
# Route to sync implementation
|
|
npx tsx "$SCRIPT_DIR/../src/sync-cli.ts" "$@"
|
|
;;
|
|
|
|
--help|-h|"")
|
|
cat <<'EOF'
|
|
episodic-memory - Manage and search Claude Code conversations
|
|
|
|
USAGE:
|
|
episodic-memory <command> [options]
|
|
|
|
COMMANDS:
|
|
sync Sync conversations from ~/.claude/projects and index them
|
|
index Index conversations for search
|
|
search Search indexed conversations
|
|
show Display a conversation in readable format
|
|
stats Show index statistics
|
|
|
|
Run 'episodic-memory <command> --help' for command-specific help.
|
|
|
|
EXAMPLES:
|
|
# Index all conversations
|
|
episodic-memory index --cleanup
|
|
|
|
# Search for something
|
|
episodic-memory search "React Router auth"
|
|
|
|
# Display a conversation
|
|
episodic-memory show path/to/conversation.jsonl
|
|
|
|
# Generate HTML output
|
|
episodic-memory show --format html conversation.jsonl > output.html
|
|
EOF
|
|
;;
|
|
|
|
*)
|
|
echo "Unknown command: $COMMAND"
|
|
echo "Try: episodic-memory --help"
|
|
exit 1
|
|
;;
|
|
esac
|