Compare commits

..

97 Commits

Author SHA1 Message Date
5fbf8c1be2 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-18 04:00:24 +09:00
33285c4f6f Sync 2026-04-18 04:00 2026-04-18 04:00:24 +09:00
a084858863 Sync 2026-04-17 18:20 2026-04-17 18:20:36 +00:00
2a196dd576 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-18 02:00:16 +09:00
2a98835f2f Sync 2026-04-18 02:00 2026-04-18 02:00:15 +09:00
d06c265003 Sync 2026-04-17 16:20 2026-04-17 16:20:24 +00:00
5fd8081646 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-18 00:00:10 +09:00
5adbf31d09 Sync 2026-04-18 00:00 2026-04-18 00:00:10 +09:00
56bc2a53f7 Sync 2026-04-17 14:20 2026-04-17 14:20:17 +00:00
c58befd27a Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 22:00:07 +09:00
c4865d3e62 Sync 2026-04-17 22:00 2026-04-17 22:00:07 +09:00
394d149954 Sync 2026-04-17 12:20 2026-04-17 12:20:11 +00:00
ddbfe5a321 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 20:00:06 +09:00
67e1c19dee Sync 2026-04-17 20:00 2026-04-17 20:00:05 +09:00
7d368e52c2 Sync 2026-04-17 10:20 2026-04-17 10:20:09 +00:00
76fa3117ca Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 18:00:04 +09:00
e1399098f0 Sync 2026-04-17 18:00 2026-04-17 18:00:03 +09:00
e93a8c3bef Sync 2026-04-17 08:20 2026-04-17 08:20:07 +00:00
a842f38cc2 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 16:00:04 +09:00
a5c9c8d687 Sync 2026-04-17 16:00 2026-04-17 16:00:04 +09:00
16aaa54d4f Sync 2026-04-17 06:20 2026-04-17 06:20:07 +00:00
3211c9b953 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 14:00:03 +09:00
87955f80e0 Sync 2026-04-17 14:00 2026-04-17 14:00:02 +09:00
d6759f9fd7 Sync 2026-04-17 04:20 2026-04-17 04:20:06 +00:00
2e3d83cbab Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 12:00:02 +09:00
fe76773cb5 Sync 2026-04-17 12:00 2026-04-17 12:00:02 +09:00
9298ebf965 Sync 2026-04-17 02:20 2026-04-17 02:20:04 +00:00
50000c0dc0 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 10:00:03 +09:00
e03ac06f03 Sync 2026-04-17 10:00 2026-04-17 10:00:02 +09:00
d95b580e5f Sync 2026-04-17 00:20 2026-04-17 00:20:05 +00:00
3615ca15bc Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 08:00:03 +09:00
0f173943ee Sync 2026-04-17 08:00 2026-04-17 08:00:02 +09:00
5428ccc4c2 Sync 2026-04-16 22:20 2026-04-16 22:20:04 +00:00
d2f91e941c Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 06:00:02 +09:00
e0345a68fc Sync 2026-04-17 06:00 2026-04-17 06:00:02 +09:00
6fa45102ca Sync 2026-04-16 20:20 2026-04-16 20:20:04 +00:00
1dddeb3318 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 04:00:03 +09:00
b994fb85b8 Sync 2026-04-17 04:00 2026-04-17 04:00:02 +09:00
148bec815b Sync 2026-04-16 18:20 2026-04-16 18:20:04 +00:00
64b344b64c Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 02:00:02 +09:00
59c6dd974b Sync 2026-04-17 02:00 2026-04-17 02:00:02 +09:00
58841a133b Sync 2026-04-16 16:20 2026-04-16 16:20:04 +00:00
55156989c8 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-17 00:00:02 +09:00
73a14eacb4 Sync 2026-04-17 00:00 2026-04-17 00:00:02 +09:00
27050cd06c Sync 2026-04-16 14:20 2026-04-16 14:20:04 +00:00
d5a8d954a1 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-16 22:51:50 +09:00
b521283903 Sync 2026-04-16 22:51 2026-04-16 22:51:49 +09:00
3caff4fa9f Sync 2026-04-16 12:20 2026-04-16 12:20:03 +00:00
5420ee1cb7 Sync 2026-04-16 10:20 2026-04-16 10:20:04 +00:00
3a291d78af Sync 2026-04-16 08:20 2026-04-16 08:20:04 +00:00
9842015eaf Sync 2026-04-16 06:20 2026-04-16 06:20:04 +00:00
5e0603c079 Sync 2026-04-16 04:20 2026-04-16 04:20:03 +00:00
efb2a4a1aa Sync 2026-04-16 02:20 2026-04-16 02:20:04 +00:00
374ea026e8 Sync 2026-04-16 00:20 2026-04-16 00:20:03 +00:00
09286f5abd Sync 2026-04-15 22:20 2026-04-15 22:20:04 +00:00
a8390dc49c Sync 2026-04-15 20:20 2026-04-15 20:20:03 +00:00
5ef6acf77e Sync 2026-04-15 18:20 2026-04-15 18:20:04 +00:00
7660209de8 Sync 2026-04-15 16:20 2026-04-15 16:20:04 +00:00
3df2174a4a Sync 2026-04-15 14:20 2026-04-15 14:20:04 +00:00
d079e0eb5f Sync 2026-04-15 12:20 2026-04-15 12:20:04 +00:00
70ebc57990 Sync 2026-04-15 10:20 2026-04-15 10:20:04 +00:00
60e9188e53 Sync 2026-04-15 08:20 2026-04-15 08:20:04 +00:00
649985db97 Sync 2026-04-15 06:20 2026-04-15 06:20:04 +00:00
65fdd51495 Sync 2026-04-15 04:20 2026-04-15 04:20:04 +00:00
5d0d72cbc4 Sync 2026-04-15 02:20 2026-04-15 02:20:03 +00:00
7805305100 Sync 2026-04-15 00:20 2026-04-15 00:20:04 +00:00
2a4cfcaee3 Sync 2026-04-14 22:20 2026-04-14 22:20:03 +00:00
35e534e126 Sync 2026-04-14 20:20 2026-04-14 20:20:04 +00:00
b64bbad44a Sync 2026-04-14 18:20 2026-04-14 18:20:03 +00:00
6c11196996 Sync 2026-04-14 16:20 2026-04-14 16:20:04 +00:00
fcfb6af1eb Sync 2026-04-14 14:20 2026-04-14 14:20:03 +00:00
c8ea5a5aa5 Sync 2026-04-14 12:20 2026-04-14 12:20:04 +00:00
0d46d4a900 Sync 2026-04-14 10:20 2026-04-14 10:20:04 +00:00
1a34b59f42 Sync 2026-04-14 08:20 2026-04-14 08:20:05 +00:00
5d6d6f32d7 Sync 2026-04-14 14:40 2026-04-14 14:40:03 +08:00
5cec3fd321 Sync 2026-04-14 14:28 2026-04-14 14:28:33 +08:00
47c609c886 Sync 2026-04-14 06:28 2026-04-14 06:28:27 +00:00
781526de56 stop tracking state_merged.db (binary merge conflict) 2026-04-14 06:28:17 +00:00
1c36b771ff Sync 2026-04-14 06:27 2026-04-14 06:27:31 +00:00
3dd382198d Sync 2026-04-14 15:25 2026-04-14 15:25:29 +09:00
b46bc8ef6a Merge remote-tracking branch 'origin/main' 2026-04-14 15:25:28 +09:00
f888bae907 Sync 2026-04-14 14:00 2026-04-14 14:00:35 +09:00
da764ab901 Sync 2026-04-14 02:20 2026-04-14 02:20:04 +00:00
0a8e6b5ac9 Sync 2026-04-14 00:20 2026-04-14 00:20:04 +00:00
e89a6618d4 Sync 2026-04-14 07:31 2026-04-14 07:31:17 +08:00
ad9b6b7d98 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-14 08:29:18 +09:00
5ab10d466d Fix: remove state_merged.db before git pull to avoid conflicts 2026-04-14 08:29:14 +09:00
dc2e9fcbb6 Sync 2026-04-13 23:28 2026-04-13 23:28:44 +00:00
251f7480c3 Fix step numbers in sync.sh 2026-04-14 08:23:48 +09:00
738bd5b762 Fix: stage state_merged.db after merge 2026-04-14 08:23:33 +09:00
2dce9223e0 Add merged state DB 2026-04-14 08:23:21 +09:00
56bea3d587 Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-14 07:16:39 +08:00
a4ac06e8f0 Sync 2026-04-14 07:16 2026-04-14 07:16:37 +08:00
074af516be Merge branch 'main' of https://d.momix.cc/Mixer/hermes-sync 2026-04-13 23:07:40 +00:00
b8192bd321 Sync 2026-04-13 23:07 2026-04-13 23:07:38 +00:00
12d1ee08be Sync 2026-04-14 08:07 2026-04-14 08:07:18 +09:00
eeed2f14d5 Sync 2026-04-14 08:03 2026-04-14 08:03:42 +09:00
6 changed files with 133 additions and 102 deletions

1
.gitignore vendored
View File

@@ -7,3 +7,4 @@ __pycache__/
*.db-shm *.db-shm
*.db-journal *.db-journal
!state_*.db !state_*.db
state_merged.db

View File

@@ -26,4 +26,33 @@ RackNerd VPS (New Year Special):
- Username: root - Username: root
- Root Password: Zg58Mb73C4ueHFYhq3 - Root Password: Zg58Mb73C4ueHFYhq3
- 已安装 hermes agent - 已安装 hermes agent
- 问题: Telegram 对话失联无响应 - 问题: Telegram 对话失联无响应
§
## Hermes Sync 架构 (2026-04-14 建成)
Gitea: https://d.momix.cc/Mixer/hermes-sync
三台机器:
- 本地 Linux (10-40-29-186): ~/.hermes-sync (symlink to ~/hermes-sync-tmp), ~/.hermes
- VPS RackNerd (soe219028): ~/.hermes-sync, ~/.hermes
- MacOS (MixdeMac-mini.local): /Users/moore/.hermes-sync, /Users/moore/.hermes
同步内容memories/MEMORY.md, skills/, state.db每机器一个 state_<hostname>.db
不同步config.yaml, .env, auth.json 等配置
sync.sh 已稳定217行无checkpoint直接copy到temp dir再处理避免SQLite WAL锁冲突
cron: 每2小时VPS和MacOS用绝对路径 /Users/moore/.hermes-sync/sync.sh
本地: 软链 ~/hermes-sync-tmp -> ~/hermes-sync
MacOS hostname: MixdeMac-mini.local
## macOS Hermes 路径
- 数据目录: /Users/moore/.hermes/state.db
- Hermes CLI: /Users/moore/.local/bin/hermes
- 无systemd用cron管理后台进程
## SQLite 多机同步关键经验
- WAL模式的db不能直接copy会损坏。用temp dir中转。
- 不能对WAL模式的db做checkpoint会造成malformed image直接shutil.copy2即可WAL会在下次连接时自动attach。
- merge时sessions用INSERT OR REPLACE去重messages用INSERT OR IGNORE避免重复插入
- 列数用PRAGMA table_info动态获取不硬编码

Binary file not shown.

Binary file not shown.

BIN
state_soe219028.db Normal file

Binary file not shown.

203
sync.sh
View File

@@ -8,24 +8,32 @@ cd "$SYNC_DIR"
echo "[$(date '+%H:%M:%S')] Sync from $HOSTNAME..." echo "[$(date '+%H:%M:%S')] Sync from $HOSTNAME..."
# ── Step 1: Export local state.db → state_<hostname>.db ────────────────── # ── Step 0: Clean local state_merged.db to avoid git pull conflicts ──────
# The merged db is produced by this script, not tracked, and can conflict
# with remote when pulling. Remove it before fetch+merge.
rm -f "$SYNC_DIR/state_merged.db"
# ── Step 1: Export local state.db (via temp dir to avoid lock) ────────────
python3 << PYEOF python3 << PYEOF
import sqlite3, os, shutil import sqlite3, os, shutil, tempfile
local_db = os.path.join(os.environ['HERMES_HOME'], 'state.db') local_db = os.path.join(os.path.expanduser('~/.hermes'), 'state.db')
export_db = os.path.join(os.environ['SYNC_DIR'], f"state_{os.environ['HOSTNAME']}.db") export_db = os.path.join(os.path.expanduser('~/.hermes-sync'), f"state_{os.environ.get('HOSTNAME') or __import__('socket').gethostname()}.db")
tmpdir = tempfile.mkdtemp(prefix='hs_exp_')
# Checkpoint WAL
try: try:
conn = sqlite3.connect(local_db) tmp_db = os.path.join(tmpdir, 'db')
conn.execute('PRAGMA wal_checkpoint(TRUNCATE)') shutil.copy2(local_db, tmp_db)
conn.execute('PRAGMA optimize')
conn.close()
except Exception as e:
print(f'Checkpoint: {e}', file=__import__('sys').stderr)
shutil.copy2(local_db, export_db) test = sqlite3.connect(tmp_db)
print(f'Exported: {export_db}') r = test.execute('SELECT COUNT(*) FROM sessions').fetchone()[0]
m = test.execute('SELECT COUNT(*) FROM messages').fetchone()[0]
test.close()
shutil.copy2(tmp_db, export_db)
print(f'Exported: {r}s/{m}m')
finally:
shutil.rmtree(tmpdir, ignore_errors=True)
PYEOF PYEOF
# ── Step 2: Git stage ──────────────────────────────────────────────────── # ── Step 2: Git stage ────────────────────────────────────────────────────
@@ -65,42 +73,26 @@ fi
# ── Step 4: Merge all state_*.db → state_merged.db ────────────────────── # ── Step 4: Merge all state_*.db → state_merged.db ──────────────────────
python3 << 'PYEOF' python3 << 'PYEOF'
import sqlite3, os, glob, shutil import sqlite3, os, glob, shutil, tempfile
sync_dir = os.environ['SYNC_DIR'] sync_dir = os.path.expanduser('~/.hermes-sync')
hermes_home = os.environ['HERMES_HOME']
merged_path = os.path.join(sync_dir, 'state_merged.db') merged_path = os.path.join(sync_dir, 'state_merged.db')
db_files = sorted(glob.glob(os.path.join(sync_dir, 'state_*.db'))) db_files = sorted(glob.glob(os.path.join(sync_dir, 'state_*.db')))
db_files = [f for f in db_files if not f.endswith('_merged.db')] db_files = [f for f in db_files if not f.endswith('_merged.db')]
print(f'DBs to merge: {[os.path.basename(f) for f in db_files]}') print(f'Merging {len(db_files)} DBs')
if os.path.exists(merged_path): tmpdir = tempfile.mkdtemp(prefix='hs_merge_')
os.remove(merged_path) tmp_merged = os.path.join(tmpdir, 'merged.db')
def get_schema(conn, table): try:
cols = conn.execute(f'PRAGMA table_info("{table}")').fetchall() # Create merged DB with proper schema
return [c[1] for c in cols] # column names conn = sqlite3.connect(tmp_merged)
conn.execute('PRAGMA journal_mode=DELETE')
conn.execute('PRAGMA locking_mode=NORMAL')
conn.execute('PRAGMA synchronous=FULL')
def copy_table(src_conn, dst_conn, table): conn.execute('''
cols = get_schema(src_conn, table) CREATE TABLE sessions (
placeholders = ','.join(['?'] * len(cols))
col_names = ','.join(f'"{c}"' for c in cols)
rows = src_conn.execute(f'SELECT {col_names} FROM "{table}"').fetchall()
for row in rows:
dst_conn.execute(f'INSERT OR REPLACE INTO "{table}" ({col_names}) VALUES ({placeholders})', row)
return len(rows)
# Open merged DB and rebuild from scratch
conn_merged = sqlite3.connect(merged_path)
conn_merged.execute('PRAGMA journal_mode=WAL')
conn_merged.execute('PRAGMA synchronous=NORMAL')
# We need at least one source to initialize schema
if not db_files:
print('No state DBs found, creating empty merged DB')
conn_merged.execute('''
CREATE TABLE IF NOT EXISTS sessions (
id TEXT PRIMARY KEY, source TEXT NOT NULL, user_id TEXT, id TEXT PRIMARY KEY, source TEXT NOT NULL, user_id TEXT,
model TEXT, model_config TEXT, system_prompt TEXT, model TEXT, model_config TEXT, system_prompt TEXT,
parent_session_id TEXT, started_at REAL, ended_at REAL, parent_session_id TEXT, started_at REAL, ended_at REAL,
@@ -112,8 +104,9 @@ if not db_files:
estimated_cost_usd REAL, actual_cost_usd REAL, estimated_cost_usd REAL, actual_cost_usd REAL,
cost_status TEXT, cost_source TEXT, pricing_version TEXT, title TEXT cost_status TEXT, cost_source TEXT, pricing_version TEXT, title TEXT
)''') )''')
conn_merged.execute('''
CREATE TABLE IF NOT EXISTS messages ( conn.execute('''
CREATE TABLE messages (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
session_id TEXT NOT NULL, role TEXT NOT NULL, content TEXT, session_id TEXT NOT NULL, role TEXT NOT NULL, content TEXT,
tool_call_id TEXT, tool_calls TEXT, tool_name TEXT, tool_call_id TEXT, tool_calls TEXT, tool_name TEXT,
@@ -121,43 +114,56 @@ if not db_files:
finish_reason TEXT, reasoning TEXT, reasoning_details TEXT, finish_reason TEXT, reasoning TEXT, reasoning_details TEXT,
codex_reasoning_items TEXT codex_reasoning_items TEXT
)''') )''')
conn_merged.commit()
else:
first_db = db_files[0]
src_conn = sqlite3.connect(first_db)
src_conn.execute('PRAGMA wal_checkpoint(TRUNCATE)')
for table in ['sessions', 'messages']:
cols = get_schema(src_conn, table)
col_defs = []
for c in cols:
if c == 'id' and table == 'messages':
col_defs.append('id INTEGER PRIMARY KEY')
elif c == 'id':
col_defs.append(f'{c} TEXT PRIMARY KEY')
else:
col_defs.append(f'{c} TEXT')
conn_merged.execute(f'DROP TABLE IF EXISTS "{table}"')
conn_merged.execute(f'CREATE TABLE "{table}" ({", ".join(col_defs)})')
placeholders = ','.join(['?'] * len(cols))
col_names = ','.join(f'"{c}"' for c in cols)
rows = src_conn.execute(f'SELECT {col_names} FROM "{table}"').fetchall()
for row in rows:
conn_merged.execute(f'INSERT OR REPLACE INTO "{table}" ({col_names}) VALUES ({placeholders})', row)
print(f' {os.path.basename(first_db)}.{table}: {len(rows)} rows')
src_conn.close() conn.execute('CREATE INDEX idx_msg_session ON messages(session_id)')
conn.execute('CREATE INDEX idx_msg_ts ON messages(timestamp)')
conn_merged.execute('PRAGMA wal_checkpoint(TRUNCATE)') for db_file in db_files:
conn_merged.commit() name = os.path.basename(db_file)
conn_merged.close() # Copy to temp file first (avoids WAL lock issues with open connections)
tmp_copy = os.path.join(tmpdir, name)
shutil.copy2(db_file, tmp_copy)
# Also copy WAL if exists
if os.path.exists(db_file + '-wal'):
shutil.copy2(db_file + '-wal', tmp_copy + '-wal')
print(f'Merged: {merged_path} ({os.path.getsize(merged_path)/1024:.0f} KB)') src = sqlite3.connect(tmp_copy)
s_cnt = src.execute('SELECT COUNT(*) FROM sessions').fetchone()[0]
m_cnt = src.execute('SELECT COUNT(*) FROM messages').fetchone()[0]
print(f' {name}: {s_cnt}s/{m_cnt}m')
sess_rows = src.execute('SELECT * FROM sessions').fetchall()
sess_cols = len(src.execute('PRAGMA table_info(sessions)').fetchall())
for row in sess_rows:
conn.execute(f'INSERT OR REPLACE INTO sessions VALUES ({",".join(["?"]*sess_cols)})', row)
msg_rows = src.execute('SELECT * FROM messages').fetchall()
msg_cols = len(src.execute('PRAGMA table_info(messages)').fetchall())
for row in msg_rows:
conn.execute(f'INSERT OR IGNORE INTO messages VALUES ({",".join(["?"]*msg_cols)})', row)
src.close()
os.remove(tmp_copy)
if os.path.exists(tmp_copy + '-wal'):
os.remove(tmp_copy + '-wal')
conn.commit()
conn.close()
if os.path.exists(merged_path):
os.remove(merged_path)
shutil.copy2(tmp_merged, merged_path)
print(f'Merged: {os.path.getsize(merged_path)/1024:.0f} KB')
finally:
shutil.rmtree(tmpdir, ignore_errors=True)
PYEOF PYEOF
# ── Step 5: Push ───────────────────────────────────────────────────────── # ── Step 5: Stage merged DB (it was just created in Step 4) ─────────────
git add state_merged.db 2>/dev/null || true
# ── Step 6: Push ─────────────────────────────────────────────────────────
if [ "$HAS_LOCAL" = true ]; then if [ "$HAS_LOCAL" = true ]; then
git commit -m "Sync $(date '+%Y-%m-%d %H:%M')" 2>/dev/null || true git commit -m "Sync $(date '+%Y-%m-%d %H:%M')" 2>/dev/null || true
if ! git push origin main 2>&1; then if ! git push origin main 2>&1; then
@@ -169,41 +175,36 @@ else
echo "No local changes" echo "No local changes"
fi fi
# ── Step 6: Restore merged state to local hermes ───────────────────────── # ── Step 7: Restore merged state to local hermes ─────────────────────────
python3 << 'PYEOF' python3 << 'PYEOF'
import sqlite3, os, shutil import sqlite3, os, shutil, tempfile
sync_dir = os.environ['SYNC_DIR'] hermes_home = os.path.expanduser('~/.hermes')
hermes_home = os.environ['HERMES_HOME'] merged_path = os.path.join(os.path.expanduser('~/.hermes-sync'), 'state_merged.db')
merged_path = os.path.join(sync_dir, 'state_merged.db')
local_db = os.path.join(hermes_home, 'state.db') local_db = os.path.join(hermes_home, 'state.db')
if not os.path.exists(merged_path): if not os.path.exists(merged_path):
print('No merged DB, skipping restore') print('No merged DB, skipping restore')
else: else:
# Checkpoint + close local tmpdir = tempfile.mkdtemp(prefix='hs_rest_')
try: try:
conn = sqlite3.connect(local_db) tmp_db = os.path.join(tmpdir, 'db')
conn.execute('PRAGMA wal_checkpoint(TRUNCATE)') shutil.copy2(merged_path, tmp_db)
conn.execute('PRAGMA optimize')
conn.close() test = sqlite3.connect(tmp_db)
except Exception as e: r = test.execute('SELECT COUNT(*) FROM sessions').fetchone()[0]
print(f'Local checkpoint: {e}') m = test.execute('SELECT COUNT(*) FROM messages').fetchone()[0]
test.close()
# Backup
shutil.copy2(local_db, local_db + '.pre_sync_bak') shutil.copy2(local_db, local_db + '.bak')
shutil.copy2(tmp_db, local_db)
# Replace with merged os.remove(local_db + '.bak')
shutil.copy2(merged_path, local_db) print(f'Restored: {r}s/{m}m')
print(f'Restored merged state to {local_db}') finally:
shutil.rmtree(tmpdir, ignore_errors=True)
# Remove backup after successful restore
bak = local_db + '.pre_sync_bak'
if os.path.exists(bak):
os.remove(bak)
PYEOF PYEOF
# ── Step 7: Sync memories + skills (additive) ──────────────────────────── # ── Step 8: Sync memories + skills (additive) ────────────────────────────
cp "$SYNC_DIR/memories/MEMORY.md" "$HERMES_HOME/memories/MEMORY.md" 2>/dev/null || true cp "$SYNC_DIR/memories/MEMORY.md" "$HERMES_HOME/memories/MEMORY.md" 2>/dev/null || true
if [ -d "$SYNC_DIR/skills" ]; then if [ -d "$SYNC_DIR/skills" ]; then
mkdir -p "$HERMES_HOME/skills" mkdir -p "$HERMES_HOME/skills"