cloud-sync

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloud Sync (cmem.ai Pro)

云同步(cmem.ai Pro)

The installed worker syncs through SyncHub. There is one client, one durable operation log, and no separate sync daemon. This skill checks status or writes the three connection values issued by cmem.ai → Connect.
Security rule: never print the sync token, put it in argv, or log it. Confirm only its length. Preserve every unrelated setting and keep
~/.claude-mem/settings.json
mode
0600
.
已安装的worker通过SyncHub进行同步。系统包含一个客户端、一个持久化操作日志,无独立的同步守护进程。本skill用于检查状态,或写入cmem.ai → 连接页面生成的三个连接值。
安全规则: 绝不要打印同步令牌、将其放入argv参数或记录日志。仅确认其长度即可。保留所有无关设置,并确保
~/.claude-mem/settings.json
的权限为
0600

1. Check status

1. 检查状态

Resolve the worker port and query the always-registered status route:
bash
PORT="${CLAUDE_MEM_WORKER_PORT:-$(node -e "const fs=require('fs'),p=require('path'),os=require('os');const uid=(typeof process.getuid==='function'?process.getuid():77);const fallback=String(37700+(uid%100));try{const s=JSON.parse(fs.readFileSync(p.join(os.homedir(),'.claude-mem','settings.json'),'utf-8'));process.stdout.write(String(s.CLAUDE_MEM_WORKER_PORT||fallback));}catch{process.stdout.write(fallback);}" 2>/dev/null)}"
curl -s "http://127.0.0.1:${PORT}/api/sync/status"
  • configured: true
    and
    hub.reachable: true
    → the worker completed an authenticated
    GET /v1/sync/status
    against SyncHub. Report
    deviceId
    , pending counts,
    lastFlushAt
    ,
    lastError
    , and the Hub head/checkpoint; stop unless the user asked to replace the connection.
  • configured: true
    and
    hub.reachable: false
    → report
    hub.error
    and say the SyncHub connection is not verified. A zero pending count or
    lastError: null
    is not success because an empty queue performs no push.
  • configured: false
    → continue.
  • Connection refused, 404, or 503 immediately after restart → retry every three seconds for about 30 seconds before diagnosing the worker.
解析worker端口并查询始终注册的状态路由:
bash
PORT="${CLAUDE_MEM_WORKER_PORT:-$(node -e "const fs=require('fs'),p=require('path'),os=require('os');const uid=(typeof process.getuid==='function'?process.getuid():77);const fallback=String(37700+(uid%100));try{const s=JSON.parse(fs.readFileSync(p.join(os.homedir(),'.claude-mem','settings.json'),'utf-8'));process.stdout.write(String(s.CLAUDE_MEM_WORKER_PORT||fallback));}catch{process.stdout.write(fallback);}" 2>/dev/null)}"
curl -s "http://127.0.0.1:${PORT}/api/sync/status"
  • configured: true
    hub.reachable: true
    → worker已完成对SyncHub的认证
    GET /v1/sync/status
    请求。报告
    deviceId
    、待处理计数、
    lastFlushAt
    lastError
    以及Hub的头部/检查点;除非用户要求更换连接,否则停止操作。
  • configured: true
    hub.reachable: false
    → 报告
    hub.error
    并说明SyncHub连接未验证。待处理计数为零或
    lastError: null
    并不代表成功,因为空队列不会执行推送操作。
  • configured: false
    → 继续下一步。
  • 重启后立即出现连接拒绝、404或503错误 → 每隔3秒重试一次,持续约30秒后再诊断worker问题。

2. Obtain the connection

2. 获取连接信息

Ask for all three values shown by cmem.ai → Connect:
  1. sync token;
  2. user id;
  3. SyncHub URL.
The Hub URL must be an absolute
https://
URL. Do not substitute the cmem.ai application API URL; the installed client talks only to SyncHub.
向用户索要cmem.ai → 连接页面显示的三个值:
  1. 同步令牌(sync token);
  2. 用户ID(user id);
  3. SyncHub URL。
Hub URL必须是绝对的
https://
格式URL。请勿替换为cmem.ai应用的API URL;已安装的客户端仅与SyncHub通信。

3. Write installed-client settings

3. 写入已安装客户端的设置

Substitute the collected values inside this quoted stdin script. Do not echo them before or after running it:
bash
node - <<'EOF'
const fs = require('fs'), os = require('os'), path = require('path');
const token = 'PASTE_TOKEN_HERE';
const userId = 'PASTE_USER_ID_HERE';
const hubUrl = 'PASTE_HUB_URL_HERE';
if (!token || !userId || !/^https:\/\/[^\s]+$/.test(hubUrl)) {
  console.error('token, user id, and an https SyncHub URL are required');
  process.exit(1);
}
const dir = path.join(os.homedir(), '.claude-mem');
const file = path.join(dir, 'settings.json');
fs.mkdirSync(dir, { recursive: true });
const settings = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
const target = settings.env && typeof settings.env === 'object' ? settings.env : settings;
target.CLAUDE_MEM_CLOUD_SYNC_TOKEN = token;
target.CLAUDE_MEM_CLOUD_SYNC_USER_ID = userId;
target.CLAUDE_MEM_CLOUD_SYNC_HUB_URL = hubUrl.replace(/\/+$/, '');
fs.writeFileSync(file, JSON.stringify(settings, null, 2) + '\n', { mode: 0o600 });
fs.chmodSync(file, 0o600);
console.log(`saved cloud connection: token length ${token.length}, user id length ${userId.length}`);
EOF
These are the only required connection keys. The worker mints and persists a device id on first start and defaults the device name to the hostname.
将收集到的值替换到以下带引号的标准输入脚本中。运行前后请勿回显这些值:
bash
node - <<'EOF'
const fs = require('fs'), os = require('os'), path = require('path');
const token = 'PASTE_TOKEN_HERE';
const userId = 'PASTE_USER_ID_HERE';
const hubUrl = 'PASTE_HUB_URL_HERE';
if (!token || !userId || !/^https:\/\/[^\s]+$/.test(hubUrl)) {
  console.error('token, user id, and an https SyncHub URL are required');
  process.exit(1);
}
const dir = path.join(os.homedir(), '.claude-mem');
const file = path.join(dir, 'settings.json');
fs.mkdirSync(dir, { recursive: true });
const settings = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
const target = settings.env && typeof settings.env === 'object' ? settings.env : settings;
target.CLAUDE_MEM_CLOUD_SYNC_TOKEN = token;
target.CLAUDE_MEM_CLOUD_SYNC_USER_ID = userId;
target.CLAUDE_MEM_CLOUD_SYNC_HUB_URL = hubUrl.replace(/\/+$/, '');
fs.writeFileSync(file, JSON.stringify(settings, null, 2) + '\n', { mode: 0o600 });
fs.chmodSync(file, 0o600);
console.log(`saved cloud connection: token length ${token.length}, user id length ${userId.length}`);
EOF
这三个是唯一必需的连接键。worker会在首次启动时生成并持久化一个设备ID,设备名称默认为主机名。

4. Restart and verify

4. 重启并验证

bash
curl -s -X POST "http://127.0.0.1:${PORT}/api/admin/restart"
Poll the status route every five seconds for up to 30 seconds while the successor starts. Success means
configured: true
,
hub.reachable: true
, and
lastError: null
. The local route always makes an authenticated, read-only SyncHub status probe, even when every pending count is zero; it never uses a legacy cmem.ai Pro status route and never appends or advances sync state. Pending counts describe only writes made after the SyncHub launch baseline; setup does not migrate a pre-launch local corpus.
If
hub.reachable
is false, report
hub.error
. If
lastError
is non-null, report it too. Ask the user to verify the three values in cmem.ai → Connect. Never include the token.
bash
curl -s -X POST "http://127.0.0.1:${PORT}/api/admin/restart"
在后续进程启动期间,每隔5秒轮询一次状态路由,最多持续30秒。成功的标志是
configured: true
hub.reachable: true
lastError: null
。本地路由始终会发起一个经过认证的只读SyncHub状态探测,即使所有待处理计数为零;它绝不会使用旧版cmem.ai Pro状态路由,也绝不会追加或推进同步状态。待处理计数仅描述SyncHub启动基线之后的写入操作;设置过程不会迁移启动前的本地语料库。
如果
hub.reachable
为false,报告
hub.error
。如果
lastError
非空,也一并报告。请用户验证cmem.ai → 连接页面中的三个值。绝不要包含令牌内容。

5. Report

5. 报告

Report device id, pending counts, last successful flush, Hub reachability and checkpoint, and any Hub/flush error. End with this privacy note:
Cloud sync uploads your observation narratives and full prompt text to your cmem.ai account.
报告设备ID、待处理计数、上次成功刷新时间、Hub可达性和检查点,以及任何Hub/刷新错误。最后附上以下隐私提示:
云同步会将您的观察叙述和完整提示文本上传至您的cmem.ai账户。