Gitignore backups/, add memory git sync, update daily service

- .gitignore: Add backups/ to stop noisy session backup rotation diffs
- Remove tracked backup files from index
- skills/cognitive-memory/mcp_server.py: Auto-push to Gitea on memory_store and memory_relate
- skills/cognitive-memory/scripts/memory-git-sync.sh: New git commit+push script
- skills/cognitive-memory/systemd/cognitive-memory-daily.service: Add git sync as fallback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-02-19 23:37:49 -06:00
parent a189bb546d
commit 25792a74f4
9 changed files with 68 additions and 11477 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@ secrets/
**/proxmox.json
# ===== SESSION DATA =====
backups/
history.jsonl
session-env/
shell-snapshots/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@ Exposes 18 memory operations as MCP tools for Claude Code.
"""
import json
import subprocess
import sys
from pathlib import Path
from typing import Any, Dict
@ -16,6 +17,22 @@ sys.path.insert(0, str(Path(__file__).parent))
from client import CognitiveMemoryClient, _load_memory_config, MEMORY_DIR
SYNC_SCRIPT = Path(__file__).parent / "scripts" / "memory-git-sync.sh"
def _trigger_git_sync():
"""Fire-and-forget git sync after a write operation."""
if SYNC_SCRIPT.exists():
try:
subprocess.Popen(
[str(SYNC_SCRIPT)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
start_new_session=True,
)
except Exception:
pass # Non-critical — daily timer is the fallback
def create_tools() -> list:
"""Define all 18 MCP tool definitions with inputSchema."""
@ -431,6 +448,7 @@ def handle_tool_call(
tags=tags,
)
episode_logged = True
_trigger_git_sync()
return ok(
{
"success": True,
@ -471,6 +489,7 @@ def handle_tool_call(
strength=arguments.get("strength", 0.8),
)
if edge_id:
_trigger_git_sync()
return ok({"success": True, "edge_id": edge_id})
return ok({"success": False, "message": "Relationship already exists"})

View File

@ -0,0 +1,46 @@
#!/bin/bash
# Commit and push cognitive memory changes to Gitea (cal/claude-memory)
#
# Called daily by cognitive-memory-daily.service after decay/core/symlinks.
# Only commits if there are actual changes. Safe to run multiple times.
#
# Location: ~/.claude/skills/cognitive-memory/scripts/memory-git-sync.sh
# Repo: ~/.claude/memory/ -> https://git.manticorum.com/cal/claude-memory.git
set -euo pipefail
MEMORY_DIR="$HOME/.claude/memory"
cd "$MEMORY_DIR"
# Check if there are any changes to commit
if git diff --quiet && git diff --cached --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then
echo "memory-git-sync: no changes to commit"
exit 0
fi
# Stage all changes (.gitignore handles exclusions)
git add -A
# Build a commit message from what changed
ADDED=$(git diff --cached --name-only --diff-filter=A | wc -l)
MODIFIED=$(git diff --cached --name-only --diff-filter=M | wc -l)
DELETED=$(git diff --cached --name-only --diff-filter=D | wc -l)
EDGES=$(git diff --cached --name-only --diff-filter=ACM | grep -c '^graph/edges/' || true)
MSG="daily sync: ${ADDED} added, ${MODIFIED} modified, ${DELETED} deleted"
if [ "$EDGES" -gt 0 ]; then
MSG="$MSG (${EDGES} edges)"
fi
git commit -m "$MSG" --no-gpg-sign 2>/dev/null || {
echo "memory-git-sync: commit failed (pre-commit hook?)"
exit 1
}
git push origin main 2>/dev/null || {
echo "memory-git-sync: push failed"
exit 1
}
echo "memory-git-sync: pushed to origin/main"

View File

@ -1,6 +1,6 @@
[Unit]
Description=Cognitive Memory daily maintenance (decay, core, symlinks)
Description=Cognitive Memory daily maintenance (decay, core, symlinks, git sync fallback)
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'export PATH="/home/cal/.local/bin:$PATH" && /home/cal/.local/bin/claude-memory decay && /home/cal/.local/bin/claude-memory core && /home/cal/.local/bin/claude-memory-symlinks'
ExecStart=/bin/bash -c 'export PATH="/home/cal/.local/bin:$PATH" && /home/cal/.local/bin/claude-memory decay && /home/cal/.local/bin/claude-memory core && /home/cal/.local/bin/claude-memory-symlinks && /home/cal/.claude/skills/cognitive-memory/scripts/memory-git-sync.sh'