update-nanoclaw
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAbout
关于
Your NanoClaw fork drifts from upstream as you customize it. This skill pulls upstream changes into your install without losing your modifications.
Run in Claude Code.
/update-nanoclaw当你自定义NanoClaw后,你的分支会与上游代码逐渐产生差异。本Skill可帮助你将上游变更整合到本地安装中,同时保留你的自定义修改。
在Claude Code中运行 即可使用。
/update-nanoclawHow it works
工作原理
Preflight: checks for clean working tree (). If remote is missing, asks you for the URL (defaults to ) and adds it. Detects the upstream branch name ( or ).
git status --porcelainupstreamhttps://github.com/qwibitai/nanoclaw.gitmainmasterBackup: creates a timestamped backup branch and tag (, ) before touching anything. Safe to run multiple times.
backup/pre-update-<hash>-<timestamp>pre-update-<hash>-<timestamp>Preview: runs and against the merge base to show upstream changes since your last sync. Groups changed files into categories:
git loggit diff- Skills (): unlikely to conflict unless you edited an upstream skill
.claude/skills/ - Source (): may conflict if you modified the same files
src/ - Build/config (,
package.json,tsconfig*.json): review neededcontainer/
Update paths (you pick one):
- (default):
merge. Resolves all conflicts in one pass.git merge upstream/<branch> - :
cherry-pick. Pull in only the commits you want.git cherry-pick <hashes> - :
rebase. Linear history, but conflicts resolve per-commit.git rebase upstream/<branch> - : just view the changelog, change nothing.
abort
Conflict preview: before merging, runs a dry-run () to show which files would conflict. You can still abort at this point.
git merge --no-commit --no-ffConflict resolution: opens only conflicted files, resolves the conflict markers, keeps your local customizations intact.
Validation: runs and .
npm run buildnpm testBreaking changes check: after validation, reads CHANGELOG.md for any entries introduced by the update. If found, shows each breaking change and offers to run the recommended skill to migrate.
[BREAKING]预检:检查工作树是否干净(执行)。如果缺少远程仓库,会询问你仓库URL(默认值为)并添加它。自动检测上游分支名称(或)。
git status --porcelainupstreamhttps://github.com/qwibitai/nanoclaw.gitmainmaster备份:在进行任何操作前,创建带时间戳的备份分支和标签(格式为和)。可安全多次运行。
backup/pre-update-<hash>-<timestamp>pre-update-<hash>-<timestamp>预览:基于合并基准执行和,展示自上次同步以来的上游变更。将变更文件分为以下类别:
git loggit diff- Skills():除非你编辑过上游Skill,否则不太可能产生冲突
.claude/skills/ - 源码():如果你修改过相同文件,可能会产生冲突
src/ - 构建/配置(、
package.json、tsconfig*.json):需要重点检查container/
更新路径(你可选择其一):
- (默认):执行
merge,一次性解决所有冲突。git merge upstream/<branch> - :执行
cherry-pick,仅拉取你需要的提交。git cherry-pick <hashes> - :执行
rebase,生成线性提交历史,但需逐个提交解决冲突。git rebase upstream/<branch> - :仅查看变更日志,不做任何修改。
abort
冲突预览:合并前执行试运行(),展示可能产生冲突的文件。此时你仍可选择中止操作。
git merge --no-commit --no-ff冲突解决:仅打开存在冲突的文件,解决冲突标记,保留本地自定义内容。
验证:执行和。
npm run buildnpm test破坏性变更检查:验证通过后,读取CHANGELOG.md查看更新引入的条目。如果存在,会展示每个破坏性变更,并提供推荐的迁移Skill供你运行。
[BREAKING]Rollback
回滚
The backup tag is printed at the end of each run:
git reset --hard pre-update-<hash>-<timestamp>Backup branch also exists.
backup/pre-update-<hash>-<timestamp>每次运行结束后会打印备份标签:
git reset --hard pre-update-<hash>-<timestamp>同时会创建备份分支。
backup/pre-update-<hash>-<timestamp>Token usage
Token消耗
Only opens files with actual conflicts. Uses , , and for everything else. Does not scan or refactor unrelated code.
git loggit diffgit status仅打开存在实际冲突的文件。其他操作均依赖、和,不会扫描或重构无关代码,Token消耗较低。
git loggit diffgit statusGoal
目标
Help a user with a customized NanoClaw install safely incorporate upstream changes without a fresh reinstall and without blowing tokens.
帮助使用自定义NanoClaw安装的用户安全整合上游变更,无需重新安装,且Token消耗低。
Operating principles
操作原则
- Never proceed with a dirty working tree.
- Always create a rollback point (backup branch + tag) before touching anything.
- Prefer git-native operations (fetch, merge, cherry-pick). Do not manually rewrite files except conflict markers.
- Default to MERGE (one-pass conflict resolution). Offer REBASE as an explicit option.
- Keep token usage low: rely on ,
git status,git log, and open only conflicted files.git diff
- 工作树不干净时绝不继续操作。
- 在进行任何操作前,始终创建回滚点(备份分支+标签)。
- 优先使用Git原生操作(fetch、merge、cherry-pick)。除冲突标记外,不手动重写文件。
- 默认使用MERGE(一次性解决冲突),将REBASE作为高级选项提供。
- 保持Token消耗低:依赖、
git status、git log,仅打开冲突文件。git diff
Step 0: Preflight (stop early if unsafe)
步骤0:预检(不安全则提前终止)
Run:
- If output is non-empty:
git status --porcelain - Tell the user to commit or stash first, then stop.
Confirm remotes:
- If
git remote -vis missing:upstream - Ask the user for the upstream repo URL (default: ).
https://github.com/qwibitai/nanoclaw.git - Add it:
git remote add upstream <user-provided-url> - Then:
git fetch upstream --prune
Determine the upstream branch name:
git branch -r | grep upstream/- If exists, use
upstream/main.main - If only exists, use
upstream/master.master - Otherwise, ask the user which branch to use.
- Store this as UPSTREAM_BRANCH for all subsequent commands. Every command below that references should use
upstream/maininstead.upstream/$UPSTREAM_BRANCH
Fetch:
git fetch upstream --prune
执行:
- 如果输出非空:
git status --porcelain - 告知用户先提交或暂存变更,然后终止操作。
确认远程仓库:
- 如果缺少
git remote -v:upstream - 询问用户上游仓库URL(默认:)。
https://github.com/qwibitai/nanoclaw.git - 添加远程仓库:
git remote add upstream <用户提供的URL> - 然后执行:
git fetch upstream --prune
确定上游分支名称:
git branch -r | grep upstream/- 如果存在,使用
upstream/main。main - 如果仅存在,使用
upstream/master。master - 否则,询问用户要使用哪个分支。
- 将其存储为UPSTREAM_BRANCH,供后续所有命令使用。以下所有引用的命令均替换为
upstream/main。upstream/$UPSTREAM_BRANCH
拉取上游代码:
git fetch upstream --prune
Step 1: Create a safety net
步骤1:创建安全保障
Capture current state:
HASH=$(git rev-parse --short HEAD)TIMESTAMP=$(date +%Y%m%d-%H%M%S)
Create backup branch and tag (using timestamp to avoid collisions on retry):
git branch backup/pre-update-$HASH-$TIMESTAMPgit tag pre-update-$HASH-$TIMESTAMP
Save the tag name for later reference in the summary and rollback instructions.
捕获当前状态:
HASH=$(git rev-parse --short HEAD)TIMESTAMP=$(date +%Y%m%d-%H%M%S)
创建备份分支和标签(使用时间戳避免重试时冲突):
git branch backup/pre-update-$HASH-$TIMESTAMPgit tag pre-update-$HASH-$TIMESTAMP
保存标签名称,用于后续总结和回滚说明。
Step 2: Preview what upstream changed (no edits yet)
步骤2:预览上游变更(暂不编辑)
Compute common base:
BASE=$(git merge-base HEAD upstream/$UPSTREAM_BRANCH)
Show upstream commits since BASE:
git log --oneline $BASE..upstream/$UPSTREAM_BRANCH
Show local commits since BASE (custom drift):
git log --oneline $BASE..HEAD
Show file-level impact from upstream:
git diff --name-only $BASE..upstream/$UPSTREAM_BRANCH
Bucket the upstream changed files:
- Skills (): unlikely to conflict unless the user edited an upstream skill
.claude/skills/ - Source (): may conflict if user modified the same files
src/ - Build/config (,
package.json,package-lock.json,tsconfig*.json,container/): review neededlaunchd/ - Other: docs, tests, misc
Present these buckets to the user and ask them to choose one path using AskUserQuestion:
- A) Full update: merge all upstream changes
- B) Selective update: cherry-pick specific upstream commits
- C) Abort: they only wanted the preview
- D) Rebase mode: advanced, linear history (warn: resolves conflicts per-commit)
If Abort: stop here.
计算共同基准:
BASE=$(git merge-base HEAD upstream/$UPSTREAM_BRANCH)
展示自基准以来的上游提交:
git log --oneline $BASE..upstream/$UPSTREAM_BRANCH
展示自基准以来的本地提交(自定义差异):
git log --oneline $BASE..HEAD
展示上游变更的文件级影响:
git diff --name-only $BASE..upstream/$UPSTREAM_BRANCH
将上游变更文件分类:
- Skills():除非用户编辑过上游Skill,否则不太可能冲突
.claude/skills/ - 源码():如果用户修改过相同文件,可能冲突
src/ - 构建/配置(、
package.json、package-lock.json、tsconfig*.json、container/):需要检查launchd/ - 其他:文档、测试、杂项
将这些分类展示给用户,使用AskUserQuestion让用户选择更新路径:
- A) 完整更新:合并所有上游变更
- B) 选择性更新:cherry-pick特定上游提交
- C) 中止:仅需要预览
- D) Rebase模式:高级选项,生成线性历史(警告:需逐个提交解决冲突)
如果选择中止:在此处停止操作。
Step 3: Conflict preview (before committing anything)
步骤3:冲突预览(提交前)
If Full update or Rebase:
- Dry-run merge to preview conflicts. Run these as a single chained command so the abort always executes:
git merge --no-commit --no-ff upstream/$UPSTREAM_BRANCH; git diff --name-only --diff-filter=U; git merge --abort - If conflicts were listed: show them and ask user if they want to proceed.
- If no conflicts: tell user it is clean and proceed.
如果选择完整更新或Rebase:
- 执行试运行合并以预览冲突。将以下命令链式执行,确保中止操作始终生效:
git merge --no-commit --no-ff upstream/$UPSTREAM_BRANCH; git diff --name-only --diff-filter=U; git merge --abort - 如果列出了冲突:展示给用户并询问是否继续。
- 如果无冲突:告知用户可安全继续。
Step 4A: Full update (MERGE, default)
步骤4A:完整更新(MERGE,默认)
Run:
git merge upstream/$UPSTREAM_BRANCH --no-edit
If conflicts occur:
- Run and identify conflicted files.
git status - For each conflicted file:
- Open the file.
- Resolve only conflict markers.
- Preserve intentional local customizations.
- Incorporate upstream fixes/improvements.
- Do not refactor surrounding code.
git add <file>
- When all resolved:
- If merge did not auto-commit:
git commit --no-edit
- If merge did not auto-commit:
执行:
git merge upstream/$UPSTREAM_BRANCH --no-edit
如果产生冲突:
- 执行识别冲突文件。
git status - 对每个冲突文件:
- 打开文件。
- 仅解决冲突标记。
- 保留有意的本地自定义内容。
- 整合上游修复/改进。
- 不重构周边代码。
- 执行
git add <file>
- 所有冲突解决后:
- 如果合并未自动提交:执行
git commit --no-edit
- 如果合并未自动提交:执行
Step 4B: Selective update (CHERRY-PICK)
步骤4B:选择性更新(CHERRY-PICK)
If user chose Selective:
- Recompute BASE if needed:
BASE=$(git merge-base HEAD upstream/$UPSTREAM_BRANCH) - Show commit list again:
git log --oneline $BASE..upstream/$UPSTREAM_BRANCH - Ask user which commit hashes they want.
- Apply:
git cherry-pick <hash1> <hash2> ...
If conflicts during cherry-pick:
- Resolve only conflict markers, then:
git add <file>- If user wants to stop:
git cherry-pick --continue git cherry-pick --abort
如果用户选择选择性更新:
- 必要时重新计算基准:
BASE=$(git merge-base HEAD upstream/$UPSTREAM_BRANCH) - 再次展示提交列表:
git log --oneline $BASE..upstream/$UPSTREAM_BRANCH - 询问用户要选择哪些提交哈希值。
- 执行:
git cherry-pick <hash1> <hash2> ...
如果cherry-pick过程中产生冲突:
- 仅解决冲突标记,然后:
- 执行
git add <file> - 执行如果用户想停止:
git cherry-pick --continue - 执行
git cherry-pick --abort
- 执行
Step 4C: Rebase (only if user explicitly chose option D)
步骤4C:Rebase(仅当用户明确选择选项D时)
Run:
git rebase upstream/$UPSTREAM_BRANCH
If conflicts:
- Resolve conflict markers only, then:
git add <file>- If it gets messy (more than 3 rounds of conflicts):
git rebase --continue git rebase --abort- Recommend merge instead.
执行:
git rebase upstream/$UPSTREAM_BRANCH
如果产生冲突:
- 仅解决冲突标记,然后:
- 执行
git add <file> - 执行如果情况复杂(超过3轮冲突):
git rebase --continue - 执行
git rebase --abort - 推荐使用merge方式。
- 执行
Step 5: Validation
步骤5:验证
Run:
npm run build- (do not fail the flow if tests are not configured)
npm test
If build fails:
- Show the error.
- Only fix issues clearly caused by the merge (missing imports, type mismatches from merged code).
- Do not refactor unrelated code.
- If unclear, ask the user before making changes.
执行:
npm run build- (如果未配置测试,不终止流程)
npm test
如果构建失败:
- 展示错误信息。
- 仅修复明显由合并导致的问题(缺失的导入、合并代码导致的类型不匹配)。
- 不重构无关代码。
- 如果不确定,修改前询问用户。
Step 6: Breaking changes check
步骤6:破坏性变更检查
After validation succeeds, check if the update introduced any breaking changes.
Determine which CHANGELOG entries are new by diffing against the backup tag:
git diff <backup-tag-from-step-1>..HEAD -- CHANGELOG.md
Parse the diff output for lines starting with . Each such line is one breaking change entry. The format is:
+[BREAKING][BREAKING] <description>. Run `/<skill-name>` to <action>.If no lines are found:
[BREAKING]- Skip this step silently. Proceed to Step 7 (skill updates check).
If one or more lines are found:
[BREAKING]- Display a warning header to the user: "This update includes breaking changes that may require action:"
- For each breaking change, display the full description.
- Collect all skill names referenced in the breaking change entries (the part).
/<skill-name> - Use AskUserQuestion to ask the user which migration skills they want to run now. Options:
- One option per referenced skill (e.g., "Run /add-whatsapp to re-add WhatsApp channel")
- "Skip — I'll handle these manually"
- Set so the user can pick multiple skills if there are several breaking changes.
multiSelect: true - For each skill the user selects, invoke it using the Skill tool.
- After all selected skills complete (or if user chose Skip), proceed to Step 7 (skill updates check).
验证通过后,检查更新是否引入了破坏性变更。
通过对比备份标签和当前HEAD,确定CHANGELOG中的新增条目:
git diff <步骤1中的备份标签>..HEAD -- CHANGELOG.md
解析diff输出中以开头的行,每行对应一个破坏性变更条目。格式如下:
+[BREAKING][BREAKING] <描述>。运行`/<skill-name>`以<执行操作>。如果未找到行:
[BREAKING]- 静默跳过此步骤,进入步骤7(Skill更新检查)。
如果找到一个或多个行:
[BREAKING]- 向用户展示警告标题:"本次更新包含可能需要操作的破坏性变更:"
- 展示每个破坏性变更的完整描述。
- 收集破坏性变更条目中引用的所有Skill名称(即部分)。
/<skill-name> - 使用AskUserQuestion询问用户现在要运行哪些迁移Skill。选项:
- 每个引用的Skill对应一个选项(例如:"运行 /add-whatsapp 重新添加WhatsApp渠道")
- "跳过 — 我将手动处理"
- 设置,以便用户在存在多个破坏性变更时可选择多个Skill。
multiSelect: true - 对用户选择的每个Skill,使用Skill工具调用它。
- 所有选中的Skill执行完成后(或用户选择跳过),进入步骤7(Skill更新检查)。
Step 7: Check for skill updates
步骤7:检查Skill更新
After the summary, check if skills are distributed as branches in this repo:
git branch -r --list 'upstream/skill/*'
If any branches exist:
upstream/skill/*- Use AskUserQuestion to ask: "Upstream has skill branches. Would you like to check for skill updates?"
- Option 1: "Yes, check for updates" (description: "Runs /update-skills to check for and apply skill branch updates")
- Option 2: "No, skip" (description: "You can run /update-skills later any time")
- If user selects yes, invoke using the Skill tool.
/update-skills - After the skill completes (or if user selected no), proceed to Step 8.
总结完成后,检查本仓库是否以分支形式分发Skill:
git branch -r --list 'upstream/skill/*'
如果存在分支:
upstream/skill/*- 使用AskUserQuestion询问:"上游存在Skill分支。是否要检查Skill更新?"
- 选项1:"是,检查更新"(描述:"运行 /update-skills 检查并应用Skill分支更新")
- 选项2:"否,跳过"(描述:"你可稍后随时运行 /update-skills")
- 如果用户选择是,使用Skill工具调用。
/update-skills - Skill执行完成后(或用户选择跳过),进入步骤8。
Step 8: Summary + rollback instructions
步骤8:总结 + 回滚说明
Show:
- Backup tag: the tag name created in Step 1
- New HEAD:
git rev-parse --short HEAD - Upstream HEAD:
git rev-parse --short upstream/$UPSTREAM_BRANCH - Conflicts resolved (list files, if any)
- Breaking changes applied (list skills run, if any)
- Remaining local diff vs upstream:
git diff --name-only upstream/$UPSTREAM_BRANCH..HEAD
Tell the user:
- To rollback:
git reset --hard <backup-tag-from-step-1> - Backup branch also exists:
backup/pre-update-<HASH>-<TIMESTAMP> - Restart the service to apply changes:
- If using launchd:
launchctl unload ~/Library/LaunchAgents/com.nanoclaw.plist && launchctl load ~/Library/LaunchAgents/com.nanoclaw.plist - If running manually: restart
npm run dev
- If using launchd:
展示:
- 备份标签:步骤1中创建的标签名称
- 当前HEAD:
git rev-parse --short HEAD - 上游HEAD:
git rev-parse --short upstream/$UPSTREAM_BRANCH - 已解决的冲突(如有,列出文件)
- 已应用的破坏性变更(如有,列出运行的Skill)
- 与上游的剩余本地差异:
git diff --name-only upstream/$UPSTREAM_BRANCH..HEAD
告知用户:
- 回滚命令:
git reset --hard <步骤1中的备份标签> - 同时存在备份分支:
backup/pre-update-<HASH>-<TIMESTAMP> - 重启服务以应用变更:
- 如果使用launchd:执行
launchctl unload ~/Library/LaunchAgents/com.nanoclaw.plist && launchctl load ~/Library/LaunchAgents/com.nanoclaw.plist - 如果手动运行:重启
npm run dev
- 如果使用launchd:执行