wangchuan 5.7.0 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wangchuan",
3
- "version": "5.7.0",
3
+ "version": "5.8.0",
4
4
  "description": "忘川 · AI 记忆同步系统 — 智能体记忆永不遗失",
5
5
  "bin": {
6
6
  "wangchuan": "./dist/bin/wangchuan.js"
package/skill/SKILL.md CHANGED
@@ -1,239 +1,113 @@
1
+ ---
2
+ name: wangchuan
3
+ version: 1.4.0
4
+ description: >-
5
+ Encrypt and sync AI agent configs, memories, skills, and MCP servers across environments via a private Git repo.
6
+ Supports Claude, OpenClaw, Gemini, CodeBuddy, WorkBuddy, Cursor, and Codex.
7
+ TRIGGER when: user mentions syncing AI memories/configs, wangchuan/忘川, cross-machine agent setup, backup/restore agent settings, memory sync, skill distribution, MCP server sync, agent migration, master key export, sync status, watch daemon, environment management, snapshot, pushing/pulling memories, conflict resolution, syncing between agents, rolling back/restoring versions, switching environments, health check, customizing agent paths, or any commands: init, sync, status, watch, doctor, memory, env, snapshot, lang.
8
+ Triggers: 忘川、wangchuan、同步记忆、同步配置、同步技能、同步MCP、初始化忘川、备份记忆、恢复记忆、迁移agent、导出密钥、轮换密钥、同步状态、健康检查、多环境、快照、跨机器同步、agent记忆、配置路径、查看技能、删除技能、新增技能、修改技能、自定义agent、MCP服务器、新增MCP、删除MCP、修改MCP、查看MCP、写记忆、删除记忆、修改记忆、查看记忆、广播记忆、复制记忆、推送记忆、拉取记忆、同步到agent、冲突、合并记忆、回退记忆、回滚、恢复版本、切换环境、忘川状态、新建环境、删除环境、查看环境、切换语言、sync memories、push memory、pull memory、rollback、switch environment、custom agent、MCP server、health status、rotate key、switch language.
9
+ DO NOT TRIGGER when: general git operations, unrelated CLI tools, or AI model APIs.
10
+ ---
11
+
1
12
  # wangchuan — AI Agent Memory Sync Skill
2
13
 
3
- ## Overview
14
+ ## Quick Start
4
15
 
5
- OpenClaw Skill wrapper for the Wangchuan AI memory sync system. Invoke directly in conversation to sync AI agent configs — memories never lost across environments.
16
+ ```bash
17
+ command -v wangchuan || npm install -g wangchuan
18
+ ```
19
+ If `~/.wangchuan/config.json` does not exist → Read [references/install-setup.md](references/install-setup.md) for initialization guide.
6
20
 
7
21
  ## Command Reference
8
22
 
9
23
  ```
10
- wangchuan init [--repo <url>] [--key <path>] One-time setup — auto-detects agents, offers gh repo create, runs first sync
11
- wangchuan sync [-a, --agent <name>] [-n, --dry-run] Smart bidirectional sync (THE daily command)
12
- [-o, --only <patterns...>] Filter: only sync files matching patterns
13
- [-x, --exclude <patterns...>] Filter: exclude files matching patterns
14
- wangchuan status [-v, --verbose] One-screen summary + health score
15
- wangchuan watch [-i, --interval <min>] Background daemon for continuous sync
16
- wangchuan doctor [--key-export|--key-rotate|--setup] Diagnose + auto-fix everything
17
- wangchuan memory list|show|copy|broadcast Browse/copy memories between agents
18
- wangchuan env list|create|switch|current|delete Multi-environment management
19
- wangchuan snapshot save|list|restore|delete [name] Manage sync snapshots
20
- wangchuan lang [zh|en] Switch CLI display language
24
+ wangchuan init [--repo <url>] [--key <path>] One-time setup
25
+ wangchuan sync [-a <agent>] [-n] [-o <pat>] [-x <pat>] Smart bidirectional sync
26
+ wangchuan status [-v] Health + diff summary
27
+ wangchuan watch [-i <min>] Pull-only background daemon
28
+ wangchuan doctor [--key-export|--key-rotate|--setup] Diagnose + auto-fix
29
+ wangchuan memory list|show|copy|broadcast [-a <agent>] Memory management
30
+ wangchuan env list|create|switch|current|delete Multi-environment
31
+ wangchuan snapshot save|list|restore|delete [name] Snapshots
32
+ wangchuan lang [zh|en] Display language
21
33
  ```
34
+ Aliases: `sync`→`s`, `status`→`st`, `snapshot`→`snap`. All support `--agent` / `-a` filter.
22
35
 
23
- Aliases: `sync` `s`, `status` `st`, `snapshot` `snap`
24
-
25
- ## Invocation Examples
26
-
27
- > Sync my AI memories
28
-
29
- > Check sync status
30
-
31
- > Show full sync status with file list and diff
32
-
33
- > Sync claude configs only
34
-
35
- > Run a health check and fix any issues
36
-
37
- > Export my master key for migration
38
-
39
- > Generate a setup command for my new laptop
40
-
41
- > Create a work environment
42
-
43
- > Switch to work environment
44
-
45
- > Start continuous background sync
46
-
47
- > List memories from all agents
48
-
49
- > Copy openclaw memory to claude
50
-
51
- > Broadcast a memory to all agents
52
-
53
- > Save a snapshot before making changes
36
+ ## Task Routing Load the right reference BEFORE acting
54
37
 
55
- > Restore the last snapshot
38
+ | User intent | Read this reference first |
39
+ |-------------|--------------------------|
40
+ | Create/modify/delete skills, custom agents, MCP, or memory | [references/resource-crud.md](references/resource-crud.md) |
41
+ | Push/pull memories, resolve conflicts, sync between agents | [references/sync-conflict.md](references/sync-conflict.md) |
42
+ | Switch/create/list/delete environments, rollback, snapshots | [references/environment.md](references/environment.md) |
43
+ | Inspect/check skills, agents, MCP, memory, or health status | [references/inspect-status.md](references/inspect-status.md) |
44
+ | Initialize wangchuan, install, migrate key, new machine setup | [references/install-setup.md](references/install-setup.md) |
56
45
 
57
- > Switch to English output
46
+ **IMPORTANT**: Before executing any task below, **Read the corresponding reference file** for detailed instructions, bash commands, and decision flows. The reference files contain the complete procedures.
58
47
 
59
- ## Output Guide
48
+ ## Non-TTY Constraints (Agent shell)
60
49
 
61
- ### status (default)
62
- - Health score bar (0-100)
63
- - Changed files count since last sync
64
- - Last sync timestamp
65
- - Hint: `wangchuan sync` to update
50
+ | Command | Constraint | Required |
51
+ |---------|-----------|----------|
52
+ | `wangchuan init` | Interactive prompt fails | Must pass `--repo <url>` |
53
+ | `wangchuan sync` | Pending confirmations skipped | Must pass `-y` |
54
+ | `wangchuan env create` | Memory import prompt fails | Auto-forks (OK) |
66
55
 
67
- ### status --verbose
68
- - Full file inventory with local/repo presence
69
- - Line-level diff for changed files
70
- - Recent sync history
71
- - Per-agent health breakdown
56
+ ## Customizing Agent Workspace Paths
72
57
 
73
- ### sync
74
- - Auto-creates safety snapshot before syncing
75
- - Pulls remote changes if any, then pushes local changes
76
- - Shows compact summary with files synced count
77
- - `--only` / `--exclude` for fine-grained file filtering (stale detection auto-skipped when filters active)
78
-
79
- ### snapshot
80
- - `save [name]` — save a named snapshot (auto-named if omitted)
81
- - `list` — show all saved snapshots with timestamps
82
- - `restore <name>` — roll back to a previous snapshot
83
- - `delete <name>` — remove a snapshot
84
-
85
- ### watch
86
- - Runs as a background daemon with configurable interval
87
- - Auto-syncs on detected file changes
88
- - PID file at `~/.wangchuan/watch.pid`
89
-
90
- ### doctor
91
- - Auto-fixes all common issues (no --fix needed)
92
- - Auto-discovers installed agents and enables them
93
- - Detects stale/phantom files
94
- - `--key-export` / `--key-rotate` for key management
95
- - Validates key fingerprint against repo — detects wrong master.key before sync
96
- - `--setup` generates migration one-liner
97
-
98
- **Key mismatch error handling**: If `⛔ Key mismatch!` appears during sync, the local `master.key` does not match the repo. Guide the user to:
99
- 1. Run `wangchuan doctor --key-export` on the machine that last pushed
100
- 2. Copy the key hex to the current machine
101
- 3. Run `wangchuan init --key <hex>` or write to `~/.wangchuan/master.key`
102
-
103
- ### memory
104
- - `list` — show all agent memories with summaries
105
- - `show <agent>` — list all files when no filename given; fuzzy/substring matching with suggestions on mismatch
106
- - `copy <from> <to>` — copy memory between agents
107
- - `broadcast <agent>` — distribute memory to all agents
108
-
109
- ## --agent Filter
110
-
111
- Supported by: `sync`, `status`, `watch`, `memory`.
112
-
113
- | Value | Description |
114
- |-------|-------------|
115
- | `openclaw` | MEMORY.md (enc), AGENTS.md, SOUL.md, TOOLS.md, IDENTITY.md, USER.md (enc), HEARTBEAT.md, BOOTSTRAP.md, memory/ (enc), openclaw.json → agents/skills/ui (enc), skills/ |
116
- | `claude` | CLAUDE.md, settings.json (enc), .claude.json → mcpServers (enc), commands/ (dir), plugins/ (installed + marketplaces) |
117
- | `gemini` | settings.internal.json → security + model + general (enc), skills/ (dir) |
118
- | `codebuddy` | MEMORY.md (enc), CODEBUDDY.md, mcp.json → mcpServers (enc), settings.json → enabledPlugins + hooks (enc), plugins/ (marketplaces) |
119
- | `workbuddy` | MEMORY.md (enc), IDENTITY.md, SOUL.md, USER.md (enc), BOOTSTRAP.md, mcp.json → mcpServers (enc), settings.json → enabledPlugins + hooks (enc), skills/ (dir), extensions/ |
120
- | `cursor` | rules/ dir, mcp.json → mcpServers (enc), cli-config.json → permissions + model + enabledPlugins (enc), extensions/, hooks.json |
121
- | `codex` | MEMORY.md (enc), instructions.md, config.toml (enc), skills/ (dir), memories/ (enc) |
122
-
123
- When omitted, operates on all enabled agents plus the shared tier (skills/MCP/custom agents/shared memory).
124
-
125
- ## Custom Sub-Agent Sync
126
-
127
- Custom sub-agents defined in the `agents/` directory of any supported agent (Claude, Cursor, CodeBuddy, WorkBuddy) are automatically synced across all agents via the shared tier (`shared/agents/`). The same deletion confirmation logic as skills applies — a custom agent is pruned from the repo only when all local agents have removed it.
128
-
129
- ## Dynamic Agent Registration
130
-
131
- Custom agents can be registered at runtime via the `customAgents` field in `config.json`, without recompilation. Custom agents participate in sync identically to built-in agents and support all three entry types (`syncFiles`, `syncDirs`, `jsonFields`).
132
-
133
- ## Sync Protocol for AI Agents (IMPORTANT — all agents must follow)
134
-
135
- When this skill is loaded by an AI agent, the agent MUST follow these rules:
136
-
137
- ### After modifying skills or custom agents
138
- If you (the AI agent) create, modify, or delete any file under your `skills/` or `agents/` directory, you MUST immediately run:
58
+ Default paths are in `~/.wangchuan/config.json`. To change (e.g. Claude to `~/.claude-internal`):
139
59
  ```bash
140
- wangchuan sync
60
+ jq '.profiles.default.claude.workspacePath = "~/.claude-internal"' ~/.wangchuan/config.json > /tmp/wc-cfg.json && mv /tmp/wc-cfg.json ~/.wangchuan/config.json
61
+ wangchuan sync -y
141
62
  ```
142
- This triggers cross-agent distribution with user confirmation — the user chooses which other agents receive the change.
143
63
 
144
- ### After modifying memory or config
145
- If you update MEMORY.md, CLAUDE.md, settings.json, or any synced config file, run `wangchuan sync` to push changes to the cloud.
64
+ ## Sync Protocol Rules agents MUST follow
146
65
 
147
66
  ### On session start
148
- Check if the watch daemon is running. If not, suggest starting it:
149
67
  ```bash
150
- wangchuan watch
68
+ wangchuan status
69
+ wangchuan sync -y # process pending actions
151
70
  ```
152
- The watch daemon auto-detects file changes and triggers sync, serving as a safety net when the agent forgets to sync manually.
153
-
154
- ### Rule summary
155
- | Event | Action |
156
- |-------|--------|
157
- | Created/modified/deleted a skill | Run `wangchuan sync` immediately |
158
- | Created/modified/deleted a custom agent | Run `wangchuan sync` immediately |
159
- | Updated memory or config | Run `wangchuan sync` |
160
- | Session start | Check `wangchuan status`, suggest `wangchuan watch` if not running |
161
-
162
- ## Prerequisites
163
-
164
- 1. Node.js ≥ 18
165
- 2. Git installed and configured (SSH key or HTTPS credentials)
166
- 3. A **private** Git repo on any hosting platform (GitHub, GitLab, Gitee, Bitbucket, Gitea, or self-hosted)
167
-
168
- ## Installation
169
-
170
- ### Install wangchuan CLI
171
-
172
- ```bash
173
- npm install -g wangchuan
174
- ```
175
-
176
- ### First-time setup
177
71
 
72
+ ### After EVERY skill invocation (mandatory)
73
+ After completing any user instruction, check if the watch daemon is running and start it if not:
178
74
  ```bash
179
- # Interactive auto-detects installed agents, creates repo via GitHub CLI if available
180
- wangchuan init
181
-
182
- # Or specify a repo URL directly (any Git hosting):
183
- wangchuan init --repo git@github.com:you/brain.git
184
- wangchuan init --repo git@gitlab.com:you/brain.git
185
- wangchuan init --repo git@gitee.com:you/brain.git
75
+ # Check if watch is running, start if not (pull-only daemon)
76
+ pgrep -f 'wangchuan.*watch' >/dev/null 2>&1 || nohup wangchuan watch >/dev/null 2>&1 &
186
77
  ```
78
+ This ensures cloud memories are always pulled in the background. Watch is pull-only — it never pushes.
187
79
 
188
- ### Install this skill to an agent
189
-
190
- Copy the `wangchuan/` skill folder to your agent's skills directory:
191
-
192
- ```bash
193
- # Claude
194
- cp -r wangchuan/ ~/.claude/skills/wangchuan/
195
-
196
- # OpenClaw
197
- cp -r wangchuan/ ~/.openclaw/workspace/skills/wangchuan/
198
-
199
- # Codex
200
- cp -r wangchuan/ ~/.codex/skills/wangchuan/
201
-
202
- # Or let wangchuan sync distribute it to all agents automatically:
203
- wangchuan sync
204
- ```
205
-
206
- ### Setting up Git repo (if you don't have one)
207
-
208
- Create a **private** repo on your preferred platform:
209
-
210
- | Platform | How to create |
211
- |----------|--------------|
212
- | **GitHub** | `wangchuan init` auto-creates via `gh` CLI, or: github.com → New repository → Private |
213
- | **GitLab** | gitlab.com → New project → Private |
214
- | **Gitee** | gitee.com → New repo → Private |
215
- | **Bitbucket** | bitbucket.org → Create repository → Private |
216
- | **Gitea** | Your instance → New Repository → Private |
217
-
218
- Then: `wangchuan init --repo <ssh-url>`
219
-
220
- ### New machine setup
221
-
222
- ```bash
223
- npm install -g wangchuan
224
- wangchuan init --repo <your-repo-url> --key <master-key-hex>
225
- ```
226
-
227
- Get the master key from your original machine: `wangchuan doctor --key-export`
228
-
229
- ### Migrating the master key
230
-
231
- ⚠️ **`master.key` is the ONLY thing that cannot be recovered.** Back it up securely.
232
-
233
- ```bash
234
- # On the source machine:
235
- wangchuan doctor --key-export # prints wangchuan_<hex>
80
+ ### Rule summary
236
81
 
237
- # On the target machine:
238
- wangchuan init --repo <url> --key wangchuan_<hex>
239
- ```
82
+ | Event | Action |
83
+ |-------|--------|
84
+ | Created/modified a **shared** skill or custom agent | Copy to all other agents → `wangchuan sync -y` |
85
+ | Created/modified a **new/local** skill or custom agent | Ask user which agents → copy → `wangchuan sync -y` |
86
+ | **Deleted** a skill or custom agent | **Always ask** → inform shared status → remove selected → `wangchuan sync -y` |
87
+ | Created/modified an **MCP server** | Ask user which agents → jq write → `wangchuan sync -y` |
88
+ | **Deleted** an MCP server | Ask user which agents → jq del → `wangchuan sync -y` |
89
+ | Created/modified **memory** | Ask user → broadcast/copy if yes → `wangchuan sync -y` |
90
+ | **Deleted** memory | Ask user which agents → rm → `wangchuan sync -y` |
91
+ | Updated other config | `wangchuan sync -y` |
92
+ | **Any skill invocation completes** | **Ensure watch daemon is running** (see above) |
93
+
94
+ ### Environment awareness
95
+
96
+ All push/pull/watch operations target the **current environment's branch only**. Key rules:
97
+ - **Push/pull**: always bound to `cfg.environment` → the current env's git branch
98
+ - **Watch**: pulls from current env only. After `env switch`, restart watch
99
+ - **Cross-env access**: NOT supported — must `env switch` first, then sync
100
+ - **Workspace leakage**: switching env does NOT delete local files from the previous env. After switch, stale files from old env may remain in `~/.claude/skills/` etc. Do NOT push these to the new env — run `wangchuan status -v` to check `localOnly` files first
101
+ - **Pull from another env**: if user asks "pull work env's memory", must switch first: `wangchuan env switch work` → auto-syncs
102
+
103
+ ### --agent filter values
104
+
105
+ | Agent | Key synced files |
106
+ |-------|-----------------|
107
+ | `openclaw` | MEMORY.md (enc), AGENTS.md, SOUL.md, TOOLS.md, IDENTITY.md, USER.md (enc), memory/ (enc), skills/ |
108
+ | `claude` | CLAUDE.md, settings.json (enc), .claude.json→mcpServers (enc), commands/, plugins/ |
109
+ | `gemini` | settings.internal.json→security+model+general (enc), skills/ |
110
+ | `codebuddy` | MEMORY.md (enc), CODEBUDDY.md, mcp.json→mcpServers (enc), settings.json→enabledPlugins (enc), plugins/ |
111
+ | `workbuddy` | MEMORY.md (enc), IDENTITY.md, SOUL.md, USER.md (enc), mcp.json→mcpServers (enc), skills/, extensions/ |
112
+ | `cursor` | rules/, mcp.json→mcpServers (enc), cli-config.json→permissions+model (enc), extensions/ |
113
+ | `codex` | MEMORY.md (enc), instructions.md, config.toml (enc), skills/, memories/ (enc) |
@@ -0,0 +1,198 @@
1
+ # Environment Management, Rollback, and Snapshots
2
+
3
+ ## Environment basics
4
+
5
+ Environments map to git branches: `default` → `main`, `<name>` → `env/<name>`.
6
+
7
+ **Critical: isolation model.** Environments are **Git-branch-only isolation**. The local workspace (`~/.claude/`, `~/.cursor/`, etc.) is a **single shared copy** across all environments. Switching env = switch branch + overwrite local from new branch. But pull **never deletes** local files — files from the old env may remain as "leakage".
8
+
9
+ ### Impact on all operations
10
+
11
+ | Operation | Environment behavior |
12
+ |-----------|---------------------|
13
+ | `sync` (push/pull) | Always targets current env's branch. Cannot push to or pull from another env. |
14
+ | `watch` | Pulls from current env only. After `env switch`, **must restart watch**. |
15
+ | Skill/agent/MCP CRUD | Changes apply to local workspace, pushed to current env's branch on sync. |
16
+ | `memory copy/broadcast` | Operates on local workspace files (shared). Pushed to current env on sync. |
17
+ | After `env switch` | Old env's local files may linger. Check `wangchuan status -v` for `localOnly` files before pushing — do NOT blindly push stale files to the new env. |
18
+ | Pull from another env | Must `env switch <target>` first. No `--from-env` flag exists. |
19
+
20
+ ## Listing environments (指令 26)
21
+
22
+ When user says "查看忘川环境列表" / "list environments":
23
+
24
+ ```bash
25
+ # List all environments
26
+ wangchuan env list
27
+ ```
28
+
29
+ For per-environment health, iterate branches and check sync metadata:
30
+ ```bash
31
+ # For each environment, check active machines and health
32
+ cd ~/.wangchuan/repo
33
+ for branch in $(git branch -r --list 'origin/env/*' | sed 's|origin/||'); do
34
+ env_name=$(echo "$branch" | sed 's|env/||')
35
+ echo "=== Environment: $env_name ==="
36
+ # Count active machines from recent commits on that branch
37
+ git log "origin/$branch" --oneline -20 --format="%s" | grep -oP '\[([^\]]+)\]$' | sort -u | wc -l | xargs -I{} echo " Active machines: {}"
38
+ # Check last sync time
39
+ git log "origin/$branch" --oneline -1 --format="%ci" | xargs -I{} echo " Last sync: {}"
40
+ done
41
+ # Also check default branch
42
+ echo "=== Environment: default ==="
43
+ git log origin/main --oneline -20 --format="%s" | grep -oP '\[([^\]]+)\]$' | sort -u | wc -l | xargs -I{} echo " Active machines: {}"
44
+ ```
45
+
46
+ For detailed health of a specific environment, switch to it and run `wangchuan status -v` (see inspect-status.md).
47
+
48
+ ## Current environment (指令 27)
49
+
50
+ When user says "看下忘川当前环境" / "which environment am I in":
51
+
52
+ ```bash
53
+ wangchuan env current
54
+ wangchuan status -v
55
+ ```
56
+
57
+ Report: environment name, active machines count, health score, unsynced files, anomalies.
58
+
59
+ ## Creating a new environment (指令 28)
60
+
61
+ When user says "新建忘川 xxx 环境" / "create xxx environment":
62
+
63
+ **Step 1: Check if environment already exists.**
64
+ ```bash
65
+ wangchuan env list
66
+ ```
67
+ If the name already exists, inform the user and ask: "Environment 'xxx' already exists. Switch to it instead?"
68
+
69
+ **Step 2: Ask about data initialization.**
70
+ Ask the user which option they prefer:
71
+ - **Fork current environment** (recommended for most cases) — the new env starts with a complete copy of the current env's memories, skills, MCP, agents, and configs. This is the default.
72
+ - **Start empty** — the new env starts with no data. Note: `env create` in non-TTY mode auto-forks; to create a truly empty env, the agent must create the branch manually and make an empty initial commit.
73
+
74
+ **Step 3: Create.**
75
+ ```bash
76
+ # Fork current env (default, works in non-TTY):
77
+ wangchuan env create <name>
78
+
79
+ # To create from a specific existing env instead of current:
80
+ wangchuan env switch <source-env> # switch to source first
81
+ wangchuan env create <name> # fork from it
82
+ wangchuan env switch <name> # switch to the new env
83
+ ```
84
+
85
+ **Step 4: Confirm and report.**
86
+ After creation, the user is still on the **original** environment. Ask if they want to switch to the new one:
87
+ ```bash
88
+ wangchuan env switch <name>
89
+ ```
90
+
91
+ `env create` in non-TTY mode auto-forks with memories (no interactive prompt needed). To create an empty environment, there is no flag — the fork behavior is the default. If user explicitly wants empty, agent would need to create the branch manually.
92
+
93
+ ## Deleting an environment (指令 29)
94
+
95
+ When user says "删除忘川 xxx 环境" / "delete xxx environment":
96
+
97
+ **Step 1: Confirm with user.**
98
+ Ask: "Are you sure you want to delete environment 'xxx'? This removes the cloud branch and all its history."
99
+
100
+ **Step 2: Check constraints.**
101
+ - Cannot delete `default` environment
102
+ - Cannot delete the currently active environment (must switch first)
103
+
104
+ **Step 3: Execute.**
105
+ ```bash
106
+ wangchuan env delete <name>
107
+ ```
108
+
109
+ **Important**: `env delete` only removes the git branch. Local workspace files are NOT affected — they belong to whatever environment is currently active. Cloud data for that environment is permanently gone.
110
+
111
+ ## Switching environments
112
+
113
+ When user says "切换到 xxx 环境" / "switch to work environment":
114
+
115
+ **Step 1: Check for unsynced local changes BEFORE switching.**
116
+ ```bash
117
+ wangchuan status
118
+ ```
119
+ - **Few changes (≤3 files)**: warn briefly, push first: `wangchuan sync -y`
120
+ - **Many changes or conflicts**: `wangchuan status -v` → show diff → ask "Push current changes first, or discard and switch?"
121
+
122
+ **Step 2: Switch.**
123
+ ```bash
124
+ wangchuan env switch <name>
125
+ ```
126
+ Auto-switches branch, updates config, runs sync to pull target env's data.
127
+
128
+ **Step 3: Post-switch checks.**
129
+
130
+ Check for conflict markers:
131
+ ```bash
132
+ grep -rl '<<<<<<< LOCAL' ~/.claude/ ~/.openclaw/workspace/ ~/.codebuddy/ ~/.workbuddy/ ~/.codex/ 2>/dev/null
133
+ ```
134
+ - No conflicts → success
135
+ - Conflicts → show to user, resolve
136
+
137
+ Check for stale files from previous env (workspace leakage):
138
+ ```bash
139
+ wangchuan status -v # look for "localOnly" files — these are from the old env
140
+ ```
141
+ Warn user: "These files exist locally but not in the new environment. Do NOT push them unless you intentionally want to bring them into this env."
142
+
143
+ **Step 4: Restart watch daemon** (watch only pulls from current env's branch):
144
+ ```bash
145
+ pkill -f 'wangchuan.*watch' 2>/dev/null; nohup wangchuan watch >/dev/null 2>&1 &
146
+ ```
147
+ Watch mode **only pulls** cloud changes — it does NOT push local changes. Users must run `wangchuan sync` manually to push. If watch encounters a conflict it cannot auto-merge, it records it to `~/.wangchuan/pending-conflicts.json` — the next `wangchuan sync` will display these conflicts for user resolution.
148
+
149
+ **Step 5: If user asked "pull memory from env X" without switching:**
150
+ Explain that cross-env pull is not supported — must switch first:
151
+ ```bash
152
+ wangchuan env switch <target-env> # switch → auto-pulls target env's data
153
+ # After done, switch back:
154
+ wangchuan env switch <original-env>
155
+ ```
156
+
157
+ ## Rolling back (snapshots and git history)
158
+
159
+ When user says "回退记忆" / "rollback" / "restore a previous version":
160
+
161
+ **Step 1: Identify target.** Ask user's intent:
162
+ - **Undo last sync** → find auto-snapshot
163
+ - **Specific time** → `wangchuan snapshot list`
164
+ - **Recover deleted file** → `cd ~/.wangchuan/repo && git log --oneline --name-status -20`
165
+ - **Revert specific change** → `git log` + `git show <hash> --stat`
166
+
167
+ **Step 2: Find version.**
168
+
169
+ Option A — Snapshot:
170
+ ```bash
171
+ wangchuan snapshot list
172
+ ```
173
+
174
+ Option B — Git history:
175
+ ```bash
176
+ cd ~/.wangchuan/repo && git log --oneline --name-status -20
177
+ cd ~/.wangchuan/repo && git show <hash> --stat
178
+ cd ~/.wangchuan/repo && git show <hash>:<file-path>
179
+ ```
180
+
181
+ **Step 3: Execute.**
182
+
183
+ Snapshot restore (auto-pushes to cloud):
184
+ ```bash
185
+ wangchuan snapshot restore <name>
186
+ ```
187
+
188
+ Single file from git (needs sync after):
189
+ ```bash
190
+ cd ~/.wangchuan/repo && git checkout <hash> -- <file-path>
191
+ wangchuan sync -y
192
+ ```
193
+
194
+ Undo last sync:
195
+ ```bash
196
+ wangchuan snapshot list # find pre-sync auto-snapshot (second most recent)
197
+ wangchuan snapshot restore <pre-sync-snapshot>
198
+ ```
@@ -0,0 +1,90 @@
1
+ # Inspecting Resources and Status
2
+
3
+ ## Inspecting a skill
4
+
5
+ Report three things:
6
+ ```bash
7
+ # 1. Which agents have it:
8
+ for entry in $(jq -r '.profiles.default | to_entries[] | select(.value.enabled) | "\(.key)=\(.value.workspacePath)"' ~/.wangchuan/config.json); do
9
+ agent="${entry%%=*}"; wspath="${entry#*=}"
10
+ expanded=$(echo "$wspath" | sed "s|^~|$HOME|")
11
+ [ -d "${expanded}/skills/xxx" ] && echo " ✓ $agent" || echo " ✗ $agent"
12
+ done
13
+ # 2. Shared or local:
14
+ cat ~/.wangchuan/shared-registry.json 2>/dev/null | grep -q '"name":"xxx".*"kind":"skill"' && echo "SHARED" || echo "LOCAL"
15
+ # 3. Cloud sync:
16
+ [ -d ~/.wangchuan/repo/shared/skills/xxx ] && echo "Synced to cloud" || echo "Not in cloud"
17
+ ```
18
+
19
+ ## Inspecting a custom agent
20
+
21
+ Same pattern, but only Claude, Cursor, CodeBuddy, WorkBuddy support custom agents.
22
+ ```bash
23
+ for a in claude cursor codebuddy workbuddy; do
24
+ wspath=$(jq -r ".profiles.default.${a}.workspacePath" ~/.wangchuan/config.json)
25
+ expanded=$(echo "$wspath" | sed "s|^~|$HOME|")
26
+ [ -d "${expanded}/agents/xxx" ] && echo " ✓ $a" || echo " ✗ $a"
27
+ done
28
+ cat ~/.wangchuan/shared-registry.json 2>/dev/null | grep -q '"name":"xxx".*"kind":"agent"' && echo "SHARED" || echo "LOCAL"
29
+ [ -d ~/.wangchuan/repo/shared/agents/xxx ] && echo "Synced to cloud" || echo "Not in cloud"
30
+ ```
31
+
32
+ ## Inspecting MCP servers
33
+
34
+ MCP configs are JSON fields. Agents with MCP: Claude, OpenClaw, CodeBuddy, WorkBuddy, Cursor.
35
+ ```bash
36
+ # List servers per agent:
37
+ jq -r '.mcpServers // {} | keys[]' ~/.claude/.claude.json 2>/dev/null | sed 's/^/ claude: /'
38
+ jq -r '.mcpServers // {} | keys[]' ~/.codebuddy/mcp.json 2>/dev/null | sed 's/^/ codebuddy: /'
39
+ # (repeat for workbuddy, cursor with mcp.json; openclaw with config/mcporter.json)
40
+ ```
41
+ MCP has **no shared registry** — it uses a single merged file in the cloud (`shared/mcp/mcpServers.json.enc`). On each sync, all agents' MCP servers are merged into one superset and distributed to all agents locally. Report which agents have a given server, compare config values.
42
+
43
+ ## Inspecting memory
44
+
45
+ ```bash
46
+ # 1. List all agents' memory files:
47
+ wangchuan memory list
48
+ # 2. Show specific agent's memory:
49
+ wangchuan memory show <agent>
50
+ # 3. Shared memory status:
51
+ expanded=$(echo "~/.openclaw/workspace/memory/SHARED.md" | sed "s|^~|$HOME|")
52
+ [ -f "$expanded" ] && echo "✓ Shared memory exists" || echo "✗ No shared memory"
53
+ [ -f ~/.wangchuan/repo/shared/memory/SHARED.md.enc ] && echo "✓ Synced to cloud" || echo "✗ Not in cloud"
54
+ # 4. Per-agent cloud sync:
55
+ for a in openclaw codebuddy workbuddy codex; do
56
+ [ -f ~/.wangchuan/repo/agents/${a}/MEMORY.md.enc ] && echo " ✓ $a synced" || echo " ✗ $a not synced"
57
+ done
58
+ [ -f ~/.wangchuan/repo/agents/claude/CLAUDE.md ] && echo " ✓ claude synced" || echo " ✗ claude not synced"
59
+ ```
60
+
61
+ ## Status diagnostic (wangchuan status)
62
+
63
+ ### Compact view: `wangchuan status`
64
+ - Health score (0–100), 4 dimensions: freshness / coverage / integrity / encryption
65
+ - Current environment and branch
66
+ - Changed files count (+added, ~modified, -missing)
67
+ - Last sync timestamp, pending actions
68
+
69
+ ### Verbose view: `wangchuan status -v`
70
+ All of compact, plus:
71
+ - 4 health sub-scores with explanations
72
+ - File inventory per-agent (local ✔/✖, repo ✔/·, [enc], [field])
73
+ - Line-level diff per modified file
74
+ - Active machines (from git commit `[hostname]`)
75
+ - Recent 3 git commits
76
+ - Sync history (last 5 events)
77
+ - Conflict detection (local+remote both changed)
78
+ - Sync lock warnings
79
+
80
+ ### Interpreting health issues
81
+
82
+ | Symptom | Meaning | Fix |
83
+ |---------|---------|-----|
84
+ | Freshness low | Haven't synced recently | `wangchuan sync -y` |
85
+ | Coverage low | Local files missing | `wangchuan sync -y` (pull restores) |
86
+ | Integrity low | Checksums mismatch | `wangchuan doctor` |
87
+ | Encryption low | Sensitive files unencrypted | Review config profiles |
88
+ | Conflict warning | Local+remote both changed | `wangchuan sync -y` → resolve markers |
89
+ | Stale sync lock | Previous sync crashed | `wangchuan doctor` |
90
+ | Pending distributions | Unprocessed sharing | `wangchuan sync -y` |