autosync-ic-skills

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Set up self-updating Internet Computer skills

配置自更新的 Internet Computer 技能

This skill installs a small amount of project configuration so that every new Claude Code session automatically downloads the latest Internet Computer skills into
.claude/skills/
, where Claude discovers and triggers them natively.
It is a one-time installer. After you complete the steps below, the user never needs this link again — the installed
SessionStart
hook does the work from then on.
此 skill 会安装少量项目配置,使每个新的 Claude Code 会话自动下载最新的 Internet Computer 技能并保存到
.claude/skills/
,Claude 会在该目录中原生地发现并触发这些技能。
这是一个一次性安装程序。完成以下步骤后,用户将不再需要此链接——已安装的
SessionStart
hook 从此会负责完成这项工作。

What you will create

将创建的内容

  1. .claude/sync-ic-skills.sh
    — a differential sync script that mirrors the live skill index into
    .claude/skills/
    .
  2. A
    SessionStart
    hook in
    .claude/settings.json
    that runs that script.
  3. An immediate first run, so skills are present right away.
The script is a differential mirror. It fetches the discovery index once and compares each skill's published
hash
against a stored manifest, re-downloading only the skills that actually changed (and pruning ones removed upstream). Unchanged skills are skipped with no per-file downloads, and the script writes nothing to stdout unless something changed. If the server does not publish a
hash
for a skill, the script falls back to re-downloading it every run, so it remains correct either way.
  1. .claude/sync-ic-skills.sh
    ——一个差异同步脚本,用于将实时 skill 索引镜像到
    .claude/skills/
    。
  2. .claude/settings.json
    中的一个
    SessionStart
    hook,用于运行该脚本。
  3. 立即执行首次运行,使技能马上可用。
该脚本是一个差异镜像。它只获取一次发现索引,并将每个技能发布的
hash
与已存储的 manifest 进行比较,仅重新下载实际发生变化的技能(并清理上游已移除的技能)。未变化的技能会被跳过,不会逐文件下载;除非发生某些更改,否则脚本不会向 stdout 写入任何内容。如果服务器未为某个技能发布
hash
,脚本会在每次运行时退回到重新下载该技能,从而确保结果始终正确。

Important: tell the user what to expect

重要:告知用户预期行为

Adding a hook means a shell script will run automatically at the start of future sessions. Claude Code will ask the user to review and trust the new hook before it activates — this is expected and correct. Let the user know:
"I'm adding a
SessionStart
hook that runs
.claude/sync-ic-skills.sh
. Claude Code will ask you to approve/trust it before it runs automatically. After that, your IC skills stay current on every session."
Do not attempt to bypass that approval.
添加 hook 意味着 shell 脚本将在未来会话开始时自动运行。Claude Code 会要求用户审查并信任新 hook,然后才会激活它——这是预期且正确的行为。请告知用户:
“我正在添加一个
SessionStart
hook,用于运行
.claude/sync-ic-skills.sh
。Claude Code 会在自动运行前要求你批准/信任它。完成后,你的 IC 技能将在每个会话中保持最新。”
不要尝试绕过该批准流程。

Step 0 — Check prerequisites (
curl
,
jq
)

第 0 步——检查先决条件(
curl
、
jq
)

The sync script needs
curl
(virtually always present) and
jq
(often not). Before writing anything, check for them:
bash
command -v curl >/dev/null 2>&1 && echo "curl: ok" || echo "curl: MISSING"
command -v jq   >/dev/null 2>&1 && echo "jq: ok"   || echo "jq: MISSING"
  • If
    jq
    is missing, offer to install it (ask the user before running an install command). Pick the right one for their platform:
    • macOS (Homebrew):
      brew install jq
    • Debian/Ubuntu:
      sudo apt-get update && sudo apt-get install -y jq
    • Fedora/RHEL:
      sudo dnf install -y jq
    • Alpine:
      apk add jq
    • Arch:
      sudo pacman -S --noconfirm jq
    • Windows (winget):
      winget install jqlang.jq
  • If the user declines, still proceed — the script is written to degrade gracefully (it exits cleanly with a warning when
    jq
    is absent), and they can install
    jq
    later and the next session will sync.
同步脚本需要
curl
(几乎总是已安装)和
jq
(通常未安装)。在写入任何内容之前,检查它们是否存在:
bash
command -v curl >/dev/null 2>&1 && echo "curl: ok" || echo "curl: MISSING"
command -v jq   >/dev/null 2>&1 && echo "jq: ok"   || echo "jq: MISSING"
  • 如果缺少
    jq
    ,请提供安装选项(在运行安装命令前询问用户)。根据其平台选择合适的命令:
    • macOS(Homebrew):
      brew install jq
    • Debian/Ubuntu:
      sudo apt-get update && sudo apt-get install -y jq
    • Fedora/RHEL:
      sudo dnf install -y jq
    • Alpine:
      apk add jq
    • Arch:
      sudo pacman -S --noconfirm jq
    • Windows(winget):
      winget install jqlang.jq
  • 如果用户拒绝安装,仍可继续——脚本已设计为优雅降级(缺少
    jq
    时会输出警告并正常退出),用户之后可以安装
    jq
    ,下一个会话即可进行同步。

Step 1 — Download the sync script

第 1 步——下载同步脚本

The script is published as a file alongside this skill, so you fetch it verbatim rather than transcribing it (this guarantees byte-exact content). Create the
.claude
directory and download it:
bash
mkdir -p .claude
curl -fsSL https://skills.internetcomputer.org/.well-known/skills/autosync-ic-skills/scripts/sync-ic-skills.sh \
  -o .claude/sync-ic-skills.sh
Do not hand-write or paraphrase the script — always fetch the published copy so the sync logic stays correct as it is updated upstream.
What the script does (for the user's awareness):
  • Fetches
    https://skills.internetcomputer.org/.well-known/skills/index.json
    once.
  • For each skill, compares the published
    hash
    against
    .claude/skills/.ic-managed.json
    (a
    { "<skill>": "<hash>" }
    manifest of skills it manages) and re-downloads only the skills whose hash changed or are new.
  • Prunes skills it previously installed that are no longer in the index, and replaces a changed skill's whole directory via an atomic staging swap — so files renamed or removed upstream don't linger inside a skill, and an interrupted download leaves the existing copy intact.
  • Writes nothing to stdout on a no-op sync. When something changed it prints one JSON object whose
    systemMessage
    carries the
    added / updated / removed
    summary — that string is what the user sees, because SessionStart hooks surface JSON fields rather than raw output. Its diagnostics (interrupted-sync recovery, unsafe skill names) go to stderr and so are not displayed.
  • Degrades gracefully: exits cleanly (keeping cached skills) if the network is down or
    jq
    is missing, and falls back to re-downloading skills the server publishes no
    hash
    for.
该脚本与此 skill 一同作为文件发布,因此应原样下载,而不是转录它(这样可保证内容逐字节一致)。创建
.claude
目录并下载:
bash
mkdir -p .claude
curl -fsSL https://skills.internetcomputer.org/.well-known/skills/autosync-ic-skills/scripts/sync-ic-skills.sh \
  -o .claude/sync-ic-skills.sh
不要手动编写或改写脚本——始终获取已发布的副本,以确保上游更新同步逻辑后,脚本仍能保持正确。
脚本的作用(供用户了解):
  • 只获取一次
    https://skills.internetcomputer.org/.well-known/skills/index.json
    。
  • 对每个技能,将发布的
    hash
    与
    .claude/skills/.ic-managed.json
    (一个由脚本管理的技能及其
    hash
    组成的
    { "<skill>": "<hash>" }
    manifest)进行比较,并且只重新下载 hash 发生变化或新出现的技能。
  • 清理此前安装、但已不在索引中的技能,并通过原子化暂存替换来替换发生变化的整个技能目录——这样,上游重命名或移除的文件就不会残留在技能目录中,而下载中断时也会保留现有副本。
  • 无变更同步时不向 stdout 写入任何内容。发生更改时,它会输出一个 JSON 对象,其
    systemMessage
    字段包含
    added / updated / removed
    摘要——由于 SessionStart hook 会展示 JSON 字段而不是原始输出,因此用户看到的就是该字符串。它的诊断信息(同步中断恢复、不安全的 skill 名称)会写入 stderr,因此不会显示。
  • 优雅降级:如果网络中断或缺少
    jq
    ,脚本会正常退出并保留缓存技能;对于服务器未发布
    hash
    的技能,则退回到每次重新下载。

Step 2 — Register the SessionStart hook (idempotently)

第 2 步——注册 SessionStart hook(幂等)

Add a
SessionStart
hook to
.claude/settings.json
that runs the script.
  • If
    .claude/settings.json
    does not exist, create it with the content below.
  • If it does exist, merge — preserve all existing keys, hooks, and permissions. Only add the
    SessionStart
    entry, and only if an equivalent
    bash .claude/sync-ic-skills.sh
    command is not already present
    (do not create a duplicate). Parse the existing JSON, insert into the
    hooks.SessionStart
    array, and write it back; never blindly overwrite the file.
The entry to ensure is present:
json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          { "type": "command", "command": "bash .claude/sync-ic-skills.sh" }
        ]
      }
    ]
  }
}
在
.claude/settings.json
中添加一个用于运行脚本的
SessionStart
hook。
  • 如果
    .claude/settings.json
    不存在,则使用以下内容创建它。
  • 如果它已存在,则进行合并——保留所有现有键、hook 和权限。仅添加
    SessionStart
    条目,并且仅当其中不存在等效的
    bash .claude/sync-ic-skills.sh
    命令时
    才添加(不要创建重复项)。解析现有 JSON,将条目插入
    hooks.SessionStart
    数组,然后写回;绝不要直接覆盖文件。
需要确保存在以下条目:
json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          { "type": "command", "command": "bash .claude/sync-ic-skills.sh" }
        ]
      }
    ]
  }
}

Step 3 — Run it once now

第 3 步——立即运行一次

Run the script immediately so the skills are available in this session without waiting for the next session start:
bash
bash .claude/sync-ic-skills.sh
立即运行脚本,使技能在当前会话中可用,而不必等到下一个会话开始:
bash
bash .claude/sync-ic-skills.sh

Step 4 — Verify and report

第 4 步——验证并报告

  • Confirm
    .claude/skills/
    now contains skill directories (e.g.
    writing-motoko
    ,
    static-site
    ,
    user-sign-in
    , …) each with a
    SKILL.md
    .
  • Confirm
    .claude/skills/.ic-managed.json
    maps each synced skill name to its hash.
  • Tell the user: how many skills were installed, that the
    SessionStart
    hook is in place, and that they'll be prompted to trust the hook before it auto-runs next session. From then on, their IC skills refresh automatically every session.
  • 确认
    .claude/skills/
    现在包含技能目录(例如
    writing-motoko
    、
    static-site
    、
    user-sign-in
    等),且每个目录中都有
    SKILL.md
    。
  • 确认
    .claude/skills/.ic-managed.json
    将每个已同步的技能名称映射到其 hash。
  • 告知用户:安装了多少个技能、
    SessionStart
    hook 已配置完成,并且下一个会话自动运行前 they'll be prompted to trust the hook。从那以后,其 IC 技能将在每个会话中自动刷新。

Notes

说明

  • Safe to re-run. Re-invoking this skill or the script is idempotent: the hook is not duplicated, and only skills tracked in
    .ic-managed.json
    are ever pruned.
  • Differential by hash. The script keys off the per-skill
    hash
    field in the discovery index, so a normal session that touches nothing downloads only
    index.json
    and exits silently. Skills are re-downloaded only when their hash changes. Migrating from an older version of this script (whose manifest was a bare name array) is handled automatically on the next run.
  • Optional mid-session refresh. For very long-running sessions, the user can also run
    bash .claude/sync-ic-skills.sh
    manually, or schedule it (e.g. via
    /loop
    or a cron routine) — but the SessionStart hook covers the normal case.
  • 可安全重复运行。 再次调用此 skill 或脚本具有幂等性:不会重复添加 hook,并且只会清理
    .ic-managed.json
    中跟踪的技能。
  • 按 hash 进行差异同步。 脚本以发现索引中每个技能的
    hash
    字段为依据,因此没有变更的普通会话只会下载
    index.json
    并静默退出。只有技能的 hash 发生变化时才会重新下载。从此脚本的旧版本(其 manifest 是纯名称数组)迁移时,脚本会在下一次运行时自动处理。
  • 可选的会话中刷新。 对于运行时间很长的会话,用户也可以手动运行
    bash .claude/sync-ic-skills.sh
    ,或进行调度(例如通过
    /loop
    或 cron 例程)——但 SessionStart hook 已覆盖常规场景。