返回顶部
g

gitclaw备份OpenClaw工作区

Back up the OpenClaw agent workspace to a GitHub repo and keep it synced via a cron-driven commit/push script.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
3,505
下载量
免费
免费
6
收藏
概述
安装方式
版本历史

gitclaw

GitClaw: 将Agent自动备份至GitHub

使用时机

当此技能被安装或引用时,以及当用户要求以下操作时,自动使用此技能:

  • - 备份/同步/镜像OpenClaw工作区
  • 设置定期提交和推送
  • 为Agent安装/配置GitHub备份自动化

行为规则(重要)

  • - 自动静默执行所有操作。
  • 仅在以下情况下向用户发送消息:
- 需要用户输入(仓库名称、可见性、可选频率),或 - Git/GH/Cron安装失败,或 - GitHub认证需要用户在浏览器/设备上完成步骤,或 - Git操作失败(冲突、权限等)。

需要向用户询问的输入

向用户询问:

  1. 1. 仓库名称(例如:openclaw-backup)
  2. 可见性:public 或 private
  3. (可选)备份频率(分钟为单位,默认:60

不要询问个人访问令牌。我们使用 gh 认证。



步骤1:确保前置条件(自动安装)

1A)确保git已安装(自动安装,不要停止)

检查:

  • - git --version

如果缺失,使用最佳可用方法安装:

  • - 如果存在 brew:
- brew install git
  • - 否则如果存在 apt-get:
- sudo apt-get update && sudo apt-get install -y git
  • - 否则如果存在 dnf:
- sudo dnf install -y git
  • - 否则如果存在 yum:
- sudo yum install -y git
  • - 否则如果存在 pacman:
- sudo pacman -S --noconfirm git
  • - 否则如果存在 zypper:
- sudo zypper install -y git
  • - 否则如果存在 apk:
- sudo apk add git
  • - 否则如果是macOS且存在 xcode-select:
- xcode-select --install(这可能会提示用户)
  • - 否则:
- 告知用户无法在此操作系统上自动安装git,并显示失败的检测输出。

重新检查:

  • - git --version

仅在安装失败时通知用户。

1B)确保cron/crontab可用(尽力自动安装)

检查:

  • - command -v crontab

如果缺失,尝试安装:

  • - 如果存在 apt-get:
- sudo apt-get update && sudo apt-get install -y cron - sudo systemctl enable --now cron || sudo service cron start || true
  • - 否则如果存在 dnf:
- sudo dnf install -y cronie - sudo systemctl enable --now crond || true
  • - 否则如果存在 yum:
- sudo yum install -y cronie - sudo systemctl enable --now crond || true
  • - 否则如果存在 pacman:
- sudo pacman -S --noconfirm cronie - sudo systemctl enable --now cronie || true
  • - 否则如果存在 apk:
- sudo apk add dcron - sudo rc-update add dcron default || true - sudo rc-service dcron start || true
  • - 否则:
- 如果无法安装,告知用户cron是调度所必需的。

重新检查:

  • - command -v crontab

步骤2:确保GitHub CLI(gh)已安装(自动安装)

检查:

  • - gh --version

如果缺失,安装:

  • - 如果存在 brew:
- brew install gh
  • - 否则如果存在 apt-get(官方GitHub CLI包;推荐):
- 使用官方apt仓库步骤安装: - (type -p wget >/dev/null || (sudo apt-get update && sudo apt-get install -y wget)) - sudo mkdir -p -m 755 /etc/apt/keyrings - out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg - cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null - sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg - sudo mkdir -p -m 755 /etc/apt/sources.list.d - echo deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null - sudo apt-get update && sudo apt-get install -y gh
  • - 否则如果存在 dnf:
- sudo dnf install -y dnf-command(config-manager) || sudo dnf install -y dnf5-plugins || true - sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo || sudo dnf config-manager addrepo --from-repofile=https://cli.github.com/packages/rpm/gh-cli.repo || true - sudo dnf install -y gh --repo gh-cli || sudo dnf install -y gh || true
  • - 否则如果存在 yum:
- type -p yum-config-manager >/dev/null || sudo yum install -y yum-utils - sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo - sudo yum install -y gh
  • - 否则如果存在 zypper:
- sudo zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo || true - sudo zypper ref - sudo zypper install -y gh
  • - 否则如果存在 pacman:
- sudo pacman -S --noconfirm github-cli
  • - 否则如果存在 apk:
- sudo apk add github-cli
  • - 否则:
- 告知用户无法在此操作系统上自动安装 gh。

重新检查:

  • - gh --version

仅在安装失败时通知用户。



步骤3:确保用户在 gh 中已认证(Agent运行流程)

检查:

  • - gh auth status --hostname github.com

如果未认证:

  1. 1. 运行:
- gh auth login --hostname github.com --git-protocol https
  1. 2. 终端流程将显示一次性代码并要求用户授权。
- 告知用户在浏览器中打开 https://github.com/login/device,输入终端中显示的代码,然后授权。
  1. 3. 登录后:
- gh auth setup-git
  1. 4. 再次验证:
- gh auth status --hostname github.com

如果认证失败,停止并报告确切的终端输出。



步骤4:在OpenClaw工作区初始化git并连接/创建仓库

工作区目录(存储SOUL.md、AGENTS.md等的位置):

  • - 示例(路径可能因环境而异):WORKSPACE_DIR=$HOME/.openclaw/workspace
  1. 1. 确保工作区存在:
- mkdir -p $WORKSPACE_DIR - cd $WORKSPACE_DIR
  1. 2. 如果需要,初始化仓库:
- 如果 .git 不存在:git init - git branch -M main
  1. 3. 配置确定性的提交身份(仅本地):
- git config user.name gitclaw.ai - git config user.email gitclaw-bot@users.noreply.github.com
  1. 4. 确定已认证的GitHub用户名(所有者):
- OWNER=$(gh api user --jq .login) - (除非需要调试,否则不打印)
  1. 5. 仓库名称和可见性:
- REPO=<用户提供的仓库名称> - 可见性: - public => --public - private => --private
  1. 6. 确保至少有一个提交(首次推送/cron所需):
- 如果需要,创建一个小的标记文件: - test -f .gitclaw.keep || printf gitclaw initialized: %s\n $(date -u +%Y-%m-%dT%H:%M:%SZ) > .gitclaw.keep - git add -A - git commit -m gitclaw: initial backup || true
  1. 7. 创建或重用目标仓库:
- 如果仓库已存在: - gh repo view $OWNER/$REPO >/dev/null 2>&1 - 设置远程: - REMOTE_URL=https://github.com/$OWN

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 gitclaw-1776374018 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 gitclaw-1776374018 技能

通过命令行安装

skillhub install gitclaw-1776374018

下载

⬇ 下载 gitclaw v1.0.0(免费)

文件大小: 4.11 KB | 发布时间: 2026-4-17 16:09

v1.0.0 最新 2026-4-17 16:09
GitClaw 1.0.0 – Initial release: automatic agent workspace backup to GitHub with cron-driven syncing.

- Automates installation and setup of prerequisites: git, crontab, GitHub CLI (gh).
- Guides user through repository creation (name, visibility) and configures GitHub authentication with gh (no personal access token needed).
- Sets up a git repository in the agent workspace and connects to a user-chosen GitHub repo, avoiding accidental overwrites.
- Installs a cron-based sync script to back up agent workspace at a user-defined interval.
- Only notifies the user if input or action is required (repo details, permissions, or installation/authentication failures).

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部