cn-coding-mirrors 0.0.0-stage → 0.1.2

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.
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env bash
2
+ # check-mirrors.sh —— 实时探测技能里引用的所有国内镜像源,输出可用性表。
3
+ #
4
+ # ./scripts/check-mirrors.sh # 终端表格(人类看)
5
+ # ./scripts/check-mirrors.sh --md # Markdown 表格(可粘进文档)
6
+ # ./scripts/check-mirrors.sh --json # JSON(给脚本/CI 用)
7
+ # ./scripts/check-mirrors.sh --write # 覆盖写 MIRRORS-STATUS.md
8
+ # ./scripts/check-mirrors.sh --strict # 任何"关键源"失败 → 退出码 1(CI 用)
9
+ # ./scripts/check-mirrors.sh -t 8 -j 16 # 单源超时 8s、并发 16
10
+ #
11
+ # 探测方式是"取 1 KB 真实资源"(-r 0-1023),比 HEAD 更能反映真实可用性。
12
+ # 退出码:0 正常;1 表示 --strict 下有关键源不可用。
13
+ set -uo pipefail
14
+
15
+ TIMEOUT=10
16
+ JOBS=16
17
+ MODE="table"
18
+ WRITE=0
19
+ STRICT=0
20
+
21
+ while [ $# -gt 0 ]; do
22
+ case "$1" in
23
+ --md) MODE="md"; shift ;;
24
+ --json) MODE="json"; shift ;;
25
+ --write) WRITE=1; shift ;;
26
+ --strict) STRICT=1; shift ;;
27
+ -t|--timeout) TIMEOUT="${2:?}"; shift 2 ;;
28
+ -j|--jobs) JOBS="${2:?}"; shift 2 ;;
29
+ -h|--help) sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
30
+ *) echo "未知参数: $1" >&2; exit 2 ;;
31
+ esac
32
+ done
33
+
34
+ # 关键源标记 *:这些挂了说明该生态在国内基本没得用(用于 --strict)
35
+ # 格式:生态|标记|名称|探测 URL
36
+ CHECKS=$(cat <<'EOF'
37
+ Python|*|tuna pypi|https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/requests/
38
+ Python| |aliyun pypi|https://mirrors.aliyun.com/pypi/simple/requests/
39
+ Python| |tencent pypi|https://mirrors.cloud.tencent.com/pypi/simple/requests/
40
+ Python| |ustc pypi|https://mirrors.ustc.edu.cn/pypi/simple/requests/
41
+ Python| |huawei pypi|https://mirrors.huaweicloud.com/repository/pypi/simple/requests/
42
+ Node|*|npmmirror registry|https://registry.npmmirror.com/react
43
+ Node| |npmmirror node bin|https://npmmirror.com/mirrors/node/index.json
44
+ Node| |npmmirror electron|https://npmmirror.com/mirrors/electron/
45
+ Java|*|aliyun maven|https://maven.aliyun.com/repository/public/org/slf4j/slf4j-api/2.0.13/slf4j-api-2.0.13.pom
46
+ Java| |huawei maven|https://repo.huaweicloud.com/repository/maven/org/slf4j/slf4j-api/2.0.13/slf4j-api-2.0.13.pom
47
+ Java| |tencent maven|https://mirrors.cloud.tencent.com/nexus/repository/maven-public/org/slf4j/slf4j-api/2.0.13/slf4j-api-2.0.13.pom
48
+ Go|*|goproxy.cn|https://goproxy.cn/github.com/pkg/errors/@v/list
49
+ Go| |aliyun goproxy|https://mirrors.aliyun.com/goproxy/github.com/pkg/errors/@v/list
50
+ Rust|*|rsproxy sparse|https://rsproxy.cn/index/se/rd/serde
51
+ Rust| |tuna crates|https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/config.json
52
+ AI|*|hf-mirror|https://hf-mirror.com/api/models/bert-base-chinese
53
+ AI| |modelscope|https://www.modelscope.cn/api/v1/models/Qwen/Qwen2.5-7B-Instruct
54
+ AI| |aliyun pytorch|https://mirrors.aliyun.com/pytorch-wheels/cpu/
55
+ Docker|*|ghcr nju|https://ghcr.nju.edu.cn/v2/
56
+ Docker| |ghcr daocloud|https://ghcr.m.daocloud.io/v2/
57
+ Docker| |docker daocloud|https://docker.m.daocloud.io/v2/
58
+ Docker| |docker 1panel|https://docker.1panel.live/v2/
59
+ Docker| |k8s daocloud|https://k8s.m.daocloud.io/v2/
60
+ GitHub|*|ghproxy.net|https://ghproxy.net/https://github.com/sharkdp/fd/releases/download/v10.5.2/fd-v10.5.2-x86_64-unknown-linux-gnu.tar.gz
61
+ GitHub| |ghfast.top|https://ghfast.top/https://github.com/sharkdp/fd/releases/download/v10.5.2/fd-v10.5.2-x86_64-unknown-linux-gnu.tar.gz
62
+ GitHub| |gh-proxy.com|https://gh-proxy.com/https://github.com/sharkdp/fd/releases/download/v10.5.2/fd-v10.5.2-x86_64-unknown-linux-gnu.tar.gz
63
+ GitHub| |api.github.com|https://api.github.com/repos/sharkdp/fd
64
+ 系统| |tuna ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/jammy/Release
65
+ 系统| |aliyun ubuntu|https://mirrors.aliyun.com/ubuntu/dists/jammy/Release
66
+ 系统| |ustc ubuntu|https://mirrors.ustc.edu.cn/ubuntu/dists/jammy/Release
67
+ 系统| |huawei ubuntu|https://repo.huaweicloud.com/ubuntu/dists/jammy/Release
68
+ Conda| |tuna anaconda|https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch/repodata.json
69
+ 其他| |flutter pub|https://pub.flutter-io.cn/api/packages/http
70
+ 其他| |aliyun composer|https://mirrors.aliyun.com/composer/packages.json
71
+ 其他| |huawei nuget|https://mirrors.huaweicloud.com/repository/nuget/v3/index.json
72
+ 其他| |tuna cran|https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/PACKAGES
73
+ 其他| |tuna rubygems|https://mirrors.tuna.tsinghua.edu.cn/rubygems/specs.4.8.gz
74
+ 其他| |huawei helm|https://mirrors.huaweicloud.com/helm/v3.16.2/
75
+ EOF
76
+ )
77
+
78
+ TMPD=$(mktemp -d)
79
+ trap 'rm -rf "$TMPD"' EXIT
80
+
81
+ probe_one() {
82
+ local idx="$1" line="$2"
83
+ local eco mark name url
84
+ IFS='|' read -r eco mark name url <<<"$line"
85
+ local out code t
86
+ out=$(curl -sS -L -r 0-1023 --connect-timeout "$TIMEOUT" --max-time "$TIMEOUT" \
87
+ -o /dev/null -w '%{http_code} %{time_total}' "$url" 2>/dev/null) || true
88
+ code="${out%% *}"; t="${out##* }"
89
+ [ -z "$code" ] && code="000"
90
+ local status
91
+ case "$code" in
92
+ 2*|3*) status="OK" ;;
93
+ 401|403) status="AUTH" ;;
94
+ 404) status="404" ;;
95
+ 000|"") status="FAIL" ;;
96
+ *) status="HTTP$code" ;;
97
+ esac
98
+ if [ "$status" = "OK" ] && awk -v t="${t:-0}" 'BEGIN{exit !(t>3)}'; then status="SLOW"; fi
99
+ printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$eco" "$mark" "$name" "$status" "$code" "${t:-0}" > "$TMPD/$idx"
100
+ }
101
+
102
+ i=0
103
+ while IFS= read -r line; do
104
+ [ -z "$line" ] && continue
105
+ i=$((i + 1))
106
+ probe_one "$i" "$line" &
107
+ while [ "$(jobs -rp | wc -l)" -ge "$JOBS" ]; do wait -n 2>/dev/null || true; done
108
+ done <<<"$CHECKS"
109
+ wait
110
+
111
+ RESULTS="$TMPD/all.tsv"
112
+ : > "$RESULTS"
113
+ for f in $(ls "$TMPD" | grep -E '^[0-9]+$' | sort -n); do cat "$TMPD/$f" >> "$RESULTS"; done
114
+
115
+ total=$(wc -l < "$RESULTS")
116
+ ok=$(awk -F'\t' '$4=="OK"' "$RESULTS" | wc -l)
117
+ degraded=$(awk -F'\t' '$4=="SLOW"||$4=="AUTH"' "$RESULTS" | wc -l)
118
+ bad=$(awk -F'\t' '$4!="OK"&&$4!="SLOW"&&$4!="AUTH"' "$RESULTS" | wc -l)
119
+ critical_bad=$(awk -F'\t' '$4!="OK"&&$4!="SLOW"&&$4!="AUTH"&&$2=="*"' "$RESULTS" | wc -l)
120
+ stamp=$(date -u '+%Y-%m-%d %H:%M UTC')
121
+
122
+ emit_md() {
123
+ echo "# 镜像源实时可用性"
124
+ echo
125
+ echo "> 由 \`scripts/check-mirrors.sh --write\` 生成,勿手改。上次探测:**$stamp**"
126
+ echo "> 共 $total 项:**OK $ok** · 降级(SLOW/AUTH) $degraded · 不可用 $bad"
127
+ echo
128
+ echo "| 生态 | 源 | 状态 | HTTP | 耗时(s) |"
129
+ echo "|---|---|---|---|---|"
130
+ awk -F'\t' '{printf "| %s | %s%s | %s | %s | %s |\n", $1, ($2=="*"?"**":""), $3 ($2=="*"?"**":""), $4, $5, $6}' "$RESULTS"
131
+ echo
132
+ echo '图例:`OK` 正常 · `SLOW` >3s · `AUTH` 401/403(可达但需鉴权)· `404` 路径变更 · `FAIL` 超时/连不上。加粗为关键源。'
133
+ }
134
+
135
+ case "$MODE" in
136
+ table)
137
+ printf '%-8s %-24s %-6s %-5s %s\n' "生态" "源" "状态" "HTTP" "耗时s"
138
+ awk -F'\t' '{printf "%-8s %-24s %-6s %-5s %s\n", $1, $3, $4, $5, $6}' "$RESULTS"
139
+ printf '\n共 %s 项:OK %s · 降级 %s · 不可用 %s(探测时间 %s)\n' "$total" "$ok" "$degraded" "$bad" "$stamp"
140
+ ;;
141
+ md)
142
+ emit_md
143
+ ;;
144
+ json)
145
+ awk -F'\t' 'BEGIN{printf "["} {printf "%s{\"ecosystem\":\"%s\",\"critical\":%s,\"name\":\"%s\",\"status\":\"%s\",\"http\":\"%s\",\"seconds\":%s}", (NR>1?",":""), $1, ($2=="*"?"true":"false"), $3, $4, $5, $6} END{print "]"}' "$RESULTS"
146
+ ;;
147
+ esac
148
+
149
+ if [ "$WRITE" = 1 ]; then
150
+ emit_md > "$(cd "$(dirname "$0")/.." && pwd)/MIRRORS-STATUS.md"
151
+ [ "$MODE" = "table" ] && echo "已写入 MIRRORS-STATUS.md"
152
+ fi
153
+
154
+ if [ "$STRICT" = 1 ] && [ "$critical_bad" -gt 0 ]; then
155
+ echo "strict: $critical_bad 个关键源不可用" >&2
156
+ exit 1
157
+ fi
158
+ exit 0
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env bash
2
+ # 把 skills/ 下的技能安装到任意"Agent Skills"兼容目录。
3
+ #
4
+ # ./scripts/install.sh # 默认 ~/.agents/skills(跨智能体通用位置)
5
+ # ./scripts/install.sh ~/.claude/skills
6
+ # ./scripts/install.sh .agents/skills # 项目级
7
+ # ./scripts/install.sh --copy PATH # 复制而不是软链(发布/分享场景)
8
+ #
9
+ # 兼容:Pi / Pi-Bolt(~/.pi/agent/skills)、Claude Code、Codex 等实现 agentskills.io 规范的工具。
10
+ set -euo pipefail
11
+
12
+ MODE="link"
13
+ if [ "${1:-}" = "--copy" ]; then MODE="copy"; shift; fi
14
+ DEST="${1:-$HOME/.agents/skills}"
15
+ SRC="$(cd "$(dirname "$0")/.." && pwd)/skills"
16
+
17
+ [ -d "$SRC" ] || { echo "找不到 $SRC" >&2; exit 1; }
18
+ mkdir -p "$DEST"
19
+
20
+ for d in "$SRC"/*/; do
21
+ name="$(basename "$d")"
22
+ target="$DEST/$name"
23
+ if [ -e "$target" ] || [ -L "$target" ]; then
24
+ rm -rf "$target"
25
+ fi
26
+ if [ "$MODE" = "copy" ]; then
27
+ cp -r "$d" "$target"
28
+ echo "复制 $name -> $target"
29
+ else
30
+ ln -s "${d%/}" "$target"
31
+ echo "软链 $name -> $target"
32
+ fi
33
+ chmod +x "$target"/scripts/* 2>/dev/null || true
34
+ done
35
+
36
+ echo
37
+ echo "完成。已安装到 $DEST"
38
+ echo "Pi/Pi-Bolt 用户若想用 user skills 目录,可再执行:"
39
+ echo " $0 \"$HOME/.pi/agent/skills\""
@@ -0,0 +1,281 @@
1
+ #!/usr/bin/env bash
2
+ # release.sh —— 一条命令走完发版:预检 → 打包核对 → 发布 npmjs → 异步等待 → 全链路验证 → 打 tag
3
+ #
4
+ # ./scripts/release.sh --dry-run # 只做预检与打包核对(不发布,安全)
5
+ # ./scripts/release.sh # 正式发布当前 package.json 的版本
6
+ # ./scripts/release.sh --otp 123456 # 需要 2FA 验证码时
7
+ # ./scripts/release.sh --stage # 走 staged publishing(需之后 approve)
8
+ # ./scripts/release.sh --tag # 发布成功后打 git tag 并推送
9
+ # ./scripts/release.sh --bump patch # 先 npm version 再发布(patch|minor|major)
10
+ #
11
+ # 背景(踩过的坑,脚本已内建处理):
12
+ # 1. 本机 npm registry 可能是 npmmirror —— 它是只读镜像,绝不能发布,脚本强制 npmjs。
13
+ # 2. npm 限制「绕过 2FA 的 token 直接发布」后,publish 会先产生 0.0.0-stage 占位版本,
14
+ # 真实版本**异步**出现(几十秒到几分钟),所以校验必须轮询,不能发完就 `npm view`。
15
+ # 3. npmmirror 同步更慢,脚本会轮询并明确区分「发布失败」与「国内镜像还没同步」。
16
+ # 4. 发布后必须做一次「干净缓存安装」验证,否则可能装到占位空包。
17
+ set -uo pipefail
18
+
19
+ REGISTRY="https://registry.npmjs.org"
20
+ MIRROR="https://registry.npmmirror.com"
21
+ REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
22
+ DRY_RUN=0; DO_TAG=0; STAGE=0; OTP=""; BUMP=""; SET_VER=""
23
+ WAIT_REG="${WAIT_REG:-180}" # 等 npmjs 出现新版本(秒)
24
+ WAIT_MIRROR="${WAIT_MIRROR:-600}" # 等 npmmirror 同步(秒)
25
+
26
+ usage() { sed -n '2,20p' "$0" | sed 's/^# \{0,1\}//'; exit "${1:-0}"; }
27
+ die() { printf '\033[31m✗ %s\033[0m\n' "$*" >&2; exit 1; }
28
+ ok() { printf '\033[32m✓ %s\033[0m\n' "$*"; }
29
+ warn(){ printf '\033[33m! %s\033[0m\n' "$*"; }
30
+ step(){ printf '\n\033[36m== %s\033[0m\n' "$*"; }
31
+
32
+ while [ $# -gt 0 ]; do
33
+ case "$1" in
34
+ --dry-run) DRY_RUN=1; shift ;;
35
+ --tag) DO_TAG=1; shift ;;
36
+ --stage) STAGE=1; shift ;;
37
+ --otp) OTP="${2:?--otp 需要验证码}"; shift 2 ;;
38
+ --otp=*) OTP="${1#*=}"; shift ;;
39
+ --bump) BUMP="${2:?--bump 需要 patch|minor|major}"; shift 2 ;;
40
+ --version) SET_VER="${2:?--version 需要 x.y.z}"; shift 2 ;;
41
+ -h|--help) usage 0 ;;
42
+ *) die "未知参数: $1(-h 看帮助)" ;;
43
+ esac
44
+ done
45
+
46
+ cd "$REPO_DIR" || die "进不去仓库目录"
47
+
48
+ # ---------- 0. 前置 ----------
49
+ step "0/6 前置检查"
50
+ command -v npm >/dev/null || die "找不到 npm"
51
+ command -v curl >/dev/null || die "找不到 curl"
52
+ [ -f package.json ] || die "不在包根目录"
53
+
54
+ command -v jq >/dev/null 2>&1 && JQ=jq || JQ=""
55
+ pkg() { # pkg <field> —— 只支持顶层字段,避免 shell 引号与 eval 打架
56
+ if [ -n "$JQ" ]; then jq -r ".$1" package.json; else
57
+ python3 -c "import json,sys;d=json.load(open('package.json'));print(d.get(sys.argv[1],''))" "$1"
58
+ fi
59
+ }
60
+
61
+ changelog_stamp() { # 把 CHANGELOG 的 [Unreleased] 段定格为本次版本
62
+ local v="$1" d; d=$(date +%F)
63
+ grep -q '^## \[Unreleased\]' CHANGELOG.md || { warn "CHANGELOG 无 [Unreleased] 段,跳过定格"; return 0; }
64
+ python3 - "$v" "$d" <<'PYEOF'
65
+ import sys, pathlib
66
+ v, d = sys.argv[1], sys.argv[2]
67
+ p = pathlib.Path('CHANGELOG.md')
68
+ s = p.read_text()
69
+ s = s.replace('## [Unreleased]', '## [Unreleased]\n\n## [' + v + '] - ' + d, 1)
70
+ p.write_text(s)
71
+ PYEOF
72
+ ok "CHANGELOG: [Unreleased] 定格为 [$v] - $d"
73
+ }
74
+
75
+ if [ -n "$SET_VER" ]; then
76
+ [ "$DRY_RUN" = 1 ] && warn "dry-run: 跳过设置版本 $SET_VER" || {
77
+ python3 -c "
78
+ import json,sys,pathlib
79
+ p=pathlib.Path('package.json'); d=json.loads(p.read_text()); d['version']=sys.argv[1]
80
+ p.write_text(json.dumps(d,indent=2,ensure_ascii=False)+'\n')" "$SET_VER" || die "设置版本失败"
81
+ ok "版本设为 $SET_VER"
82
+ changelog_stamp "$SET_VER"
83
+ if [ -d .git ] && [ -n "$(git status --porcelain)" ]; then
84
+ git add -A && git commit -q -m "chore(release): v$SET_VER" && ok "已提交版本变更"
85
+ fi
86
+ }
87
+ elif [ -n "$BUMP" ]; then
88
+ case "$BUMP" in patch|minor|major) ;; *) die "--bump 只能是 patch|minor|major" ;; esac
89
+ [ "$DRY_RUN" = 1 ] && warn "dry-run: 跳过 npm version $BUMP" || {
90
+ npm version "$BUMP" --no-git-tag-version >/dev/null || die "版本号递增失败"
91
+ ok "版本递增为 $(pkg version)"
92
+ changelog_stamp "$(pkg version)"
93
+ if [ -d .git ] && [ -n "$(git status --porcelain)" ]; then
94
+ git add -A && git commit -q -m "chore(release): v$(pkg version)" \
95
+ && ok "已提交版本变更($(git log --oneline -1 | cut -d' ' -f1))"
96
+ fi
97
+ }
98
+ fi
99
+
100
+ NAME=$(pkg name); VERSION=$(pkg version)
101
+ [ -n "$NAME" ] && [ "$NAME" != "None" ] || die "package.json 缺少 name"
102
+ [ -n "$VERSION" ] && [ "$VERSION" != "None" ] || die "package.json 缺少 version"
103
+ ok "目标: $NAME@$VERSION"
104
+
105
+ for f in README.md CHANGELOG.md LICENSE SECURITY.md; do
106
+ [ -f "$f" ] || die "缺少必需文档: $f"
107
+ done
108
+ ok "必需文档齐全"
109
+
110
+ grep -q "pi-package" package.json || die "keywords 缺少 pi-package(Pi 画廊不会收录)"
111
+ ok "pi-package 关键字存在"
112
+
113
+ if grep -qE "npm_[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{20,}|sk-[A-Za-z0-9]{20,}" -r \
114
+ --include='*.md' --include='*.sh' --include='*.ts' --include='*.py' --include='*.json' . 2>/dev/null; then
115
+ die "工作区疑似含凭据(npm_/ghp_/sk- 开头),请先移除"
116
+ fi
117
+ ok "未发现明文凭据"
118
+
119
+ if [ -d .git ]; then
120
+ [ -z "$(git status --porcelain)" ] || die "工作区有未提交改动,先 commit(或用 git stash)"
121
+ ok "工作区干净"
122
+ fi
123
+
124
+ WHOAMI=$(npm whoami --registry "$REGISTRY" 2>/dev/null) || die "未登录 npmjs($REGISTRY)"
125
+ ok "npm 登录身份: $WHOAMI"
126
+
127
+ # ---------- 1. 版本是否已被占用 ----------
128
+ step "1/6 版本占用检查"
129
+ COLLIDE=$(curl -sS -m 20 "$REGISTRY/$NAME" 2>/dev/null |
130
+ python3 -c "
131
+ import sys,json
132
+ try: d=json.load(sys.stdin)
133
+ except Exception: print(''); raise SystemExit
134
+ print('yes' if '$VERSION' in (d.get('versions') or {}) else '')" 2>/dev/null || echo "")
135
+ STAGED_HIT=$(curl -sS -m 20 -H "Authorization: Bearer $(grep -o 'npm_[A-Za-z0-9]*' "$HOME/.npmrc" 2>/dev/null | head -1)" \
136
+ "https://registry.npmjs.org/-/stage" 2>/dev/null |
137
+ python3 -c "
138
+ import sys,json
139
+ try: d=json.load(sys.stdin)
140
+ except Exception: raise SystemExit
141
+ print('yes' if any(i.get('packageName')=='$NAME' and i.get('version')=='$VERSION' for i in d.get('items') or []) else '')" 2>/dev/null)
142
+ if [ "$STAGED_HIT" = "yes" ]; then
143
+ die "$NAME@$VERSION 已在 npm 暂存区(未批准),不能复用:请换版本号(如 --version 更高版本)"
144
+ fi
145
+
146
+ if [ "$COLLIDE" = "yes" ]; then
147
+ warn "$NAME@$VERSION 已存在于 registry"
148
+ if [ "$STAGE" = 1 ]; then
149
+ die "已发布版本不能再 stage:请先 --bump patch"
150
+ fi
151
+ die "已发布版本不能再发布:请先 --bump patch"
152
+ fi
153
+ [ "$COLLIDE" = "yes" ] || ok "$NAME@$VERSION 未被占用"
154
+
155
+ # CHANGELOG 是否记录本版本
156
+ if grep -qE "^## \[?v?$VERSION\]?" CHANGELOG.md; then ok "CHANGELOG 含 [$VERSION] 条目"; else
157
+ warn "CHANGELOG 没有 [$VERSION] 条目(继续,但建议补上)"
158
+ fi
159
+
160
+ # ---------- 2. 打包内容核对 ----------
161
+ step "2/6 打包内容核对"
162
+ PACK_JSON=$(npm pack --dry-run --json --registry "$REGISTRY" 2>/dev/null) || die "npm pack --dry-run 失败"
163
+ echo "$PACK_JSON" | python3 -c "
164
+ import sys,json
165
+ d=json.load(sys.stdin)[0]
166
+ files=[f['path'] for f in d['files']]
167
+ n=len(files)
168
+ skills=[f for f in files if f.endswith('SKILL.md')]
169
+ scripts=[f for f in files if '/scripts/' in f or f.startswith('scripts/')]
170
+ docs=[f for f in ['README.md','CHANGELOG.md','LICENSE','SECURITY.md','MIRRORS-STATUS.md'] if f in files]
171
+ missing=[f for f in ['README.md','CHANGELOG.md','LICENSE','SECURITY.md','MIRRORS-STATUS.md'] if f not in files]
172
+ print(f' 文件数 {n} / 打包 {d[\"size\"]/1024:.1f} kB / 解包 {d[\"unpackedSize\"]/1024:.1f} kB')
173
+ print(f' SKILL.md {len(skills)} 个: ' + ', '.join(s.split('/')[-2] for s in skills))
174
+ print(f' 脚本 {len(scripts)} 个')
175
+ if missing: print(' ❌ 打包缺文件: ' + ', '.join(missing)); sys.exit(1)
176
+ if len(skills) < 1: print(' ❌ 没有 SKILL.md,Pi 不会发现任何技能'); sys.exit(1)
177
+ if not scripts: print(' ❌ 没有 scripts/,ghdl/dpull 会缺失'); sys.exit(1)
178
+ print(' ✓ 内容核对通过')
179
+ " || die "打包内容不合格(见上)"
180
+
181
+ if [ "$DRY_RUN" = 1 ]; then
182
+ step "dry-run 结束"
183
+ echo "将执行:"
184
+ echo " npm $([ "$STAGE" = 1 ] && echo 'stage publish' || echo publish) --registry $REGISTRY${OTP:+ --otp ***}"
185
+ [ -n "$BUMP" ] && echo " (真实运行时:npm version $BUMP,并把 CHANGELOG 的 [Unreleased] 定格为 $(pkg version))"
186
+ echo " 等待 npmjs 出现 $VERSION(最多 ${WAIT_REG}s)→ 干净缓存安装验证 → 等待 npmmirror 同步(最多 ${WAIT_MIRROR}s)"
187
+ [ "$DO_TAG" = 1 ] && echo " git tag v$VERSION && git push origin v$VERSION"
188
+ exit 0
189
+ fi
190
+
191
+ # ---------- 3. 发布 ----------
192
+ step "3/6 发布到 npmjs"
193
+ PUBLISH_ARGS=(--registry "$REGISTRY")
194
+ [ -n "$OTP" ] && PUBLISH_ARGS+=(--otp "$OTP")
195
+ if [ "$STAGE" = 1 ]; then
196
+ OUT=$(npm stage publish "${PUBLISH_ARGS[@]}" 2>&1) || { printf '%s\n' "$OUT" | tail -15; die "staged publish 失败"; }
197
+ printf '%s\n' "$OUT" | tail -3
198
+ SID=$(printf '%s\n' "$OUT" | grep -oE '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' | head -1)
199
+ ok "已暂存:${SID:-见上}"
200
+ cat <<EOF
201
+
202
+ 下一步(需要 2FA 证明,脚本无法代做):
203
+ npm stage approve ${SID:-<stage-id>} --otp <6位验证码>
204
+ 或到 https://www.npmjs.com/package/$NAME 的 staged 列表点批准
205
+ 批准后重跑本脚本的验证段:./scripts/release.sh --verify-only(或手工跑第 4、5 步)
206
+ EOF
207
+ exit 0
208
+ fi
209
+
210
+ OUT=$(npm publish "${PUBLISH_ARGS[@]}" 2>&1) || { printf '%s\n' "$OUT" | tail -15; die "publish 失败"; }
211
+ printf '%s\n' "$OUT" | grep -E "^\+|notice Publishing" | tail -3
212
+ ok "publish 请求已被接受(注意:registry 侧是异步生效)"
213
+
214
+ # ---------- 4. 等待生效 ----------
215
+ step "4/6 等待 registry 生效(异步,最多 ${WAIT_REG}s)"
216
+ deadline=$(( $(date +%s) + WAIT_REG ))
217
+ while :; do
218
+ LIVE=$(curl -sS -m 15 "$REGISTRY/$NAME/$VERSION" 2>/dev/null | head -c 80)
219
+ if printf '%s' "$LIVE" | grep -q "\"version\""; then break; fi
220
+ [ "$(date +%s)" -ge "$deadline" ] && die "超时:$NAME@$VERSION 未出现在 registry(可能被审核/占位版本阻塞)"
221
+ sleep 5
222
+ done
223
+ ok "registry 已可解析 $NAME@$VERSION"
224
+
225
+ LATEST=$(curl -sS -m 15 "$REGISTRY/$NAME" | python3 -c "import sys,json;print(json.load(sys.stdin).get('dist-tags',{}).get('latest',''))")
226
+ [ "$LATEST" = "$VERSION" ] && ok "dist-tags latest → $VERSION" || warn "latest 仍指向 $LATEST(发的是非 latest 版本?)"
227
+
228
+ # ---------- 5. 干净缓存安装验证 ----------
229
+ step "5/6 干净缓存安装验证"
230
+ TMPD=$(mktemp -d); CACHE=$(mktemp -d)
231
+ trap 'rm -rf "$TMPD" "$CACHE"' EXIT
232
+ npm install --prefix "$TMPD" --cache "$CACHE" "$NAME@$VERSION" --registry "$REGISTRY" -s >/dev/null 2>&1 ||
233
+ die "从 registry 安装 $NAME@$VERSION 失败"
234
+ python3 - "$TMPD" "$VERSION" <<'PY' || exit 1
235
+ import json,os,sys
236
+ root=os.path.join(sys.argv[1],'node_modules')
237
+ if not os.path.isdir(root): print(' ❌ 安装目录不存在'); sys.exit(1)
238
+ pkg=os.path.join(root,os.listdir(root)[0])
239
+ v=json.load(open(os.path.join(pkg,'package.json')))['version']
240
+ sk=[os.path.join(r,f) for r,_,fs in os.walk(os.path.join(pkg,'skills')) for f in fs if f=='SKILL.md']
241
+ print(f' 安装版本 {v},SKILL.md {len(sk)} 个')
242
+ if v!=sys.argv[2]: print(f' ❌ 版本不符,期望 {sys.argv[2]}'); sys.exit(1)
243
+ if len(sk)<1: print(' ❌ 技能缺失(可能装到占位版本)'); sys.exit(1)
244
+ print(' ✓ 安装验证通过')
245
+ PY
246
+
247
+ # ---------- 6. npmmirror 同步(不阻塞成功) ----------
248
+ step "6/6 等待 npmmirror 同步(最多 ${WAIT_MIRROR}s,超时不视为失败)"
249
+ deadline=$(( $(date +%s) + WAIT_MIRROR ))
250
+ while :; do
251
+ MT=$(curl -sS -m 10 "$MIRROR/$NAME" 2>/dev/null |
252
+ python3 -c "import sys,json;d=json.load(sys.stdin);print(d.get('dist-tags',{}).get('latest',''), 'yes' if sys.argv[1] in d.get('versions',{}) else '')" "$VERSION" 2>/dev/null)
253
+ case "$MT" in
254
+ "$VERSION yes") ok "npmmirror 已同步(国内用户可直接安装)"; break ;;
255
+ esac
256
+ if [ "$(date +%s)" -ge "$deadline" ]; then
257
+ warn "npmmirror 尚未同步到 $VERSION(当前: ${MT:-未知})—— 通常几分钟后自愈,无需操作"
258
+ break
259
+ fi
260
+ sleep 20
261
+ done
262
+
263
+ # ---------- tag ----------
264
+ if [ "$DO_TAG" = 1 ] && [ -d .git ]; then
265
+ step "打 tag v$VERSION"
266
+ git tag -a "v$VERSION" -m "release: v$VERSION" 2>/dev/null || warn "tag v$VERSION 已存在"
267
+ git push origin HEAD 2>&1 | tail -1
268
+ git push origin "v$VERSION" 2>&1 | tail -1
269
+ ok "tag v$VERSION 与分支已推送"
270
+ fi
271
+
272
+ cat <<EOF
273
+
274
+ \033[32m发布完成\033[0m
275
+ npm : https://www.npmjs.com/package/$NAME/v/$VERSION
276
+ 国内镜像 : https://npmmirror.com/package/$NAME
277
+ 安装验证 : pi install npm:$NAME
278
+
279
+ 提示:若曾出现 0.0.0-stage 占位版本,它不影响 latest,可忽略;
280
+ staged 版本(未批准)会在约 7 天后自动过期。
281
+ EOF
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: cn-coding-mirrors
3
+ description: 中国网络环境下的下载与镜像配置速查:pip/uv、npm/yarn/pnpm、maven/gradle、Go GOPROXY、cargo/rustup、apt/apk/brew、conda、HuggingFace/ModelScope、PyTorch wheels、Flutter、Composer、NuGet、CRAN 等。当包管理器下载极慢、超时、TLS 重置,或需要"改用国内源/换镜像/配代理"时使用。Use when installs are slow or failing in mainland China and you need the right domestic mirror endpoint or config command.
4
+ license: MIT
5
+ compatibility: 需要 curl;各生态的命令行工具按需(pip/uv/npm/mvn/cargo 等)。写系统级配置通常需要 sudo 或用户级配置文件。
6
+ metadata:
7
+ author: cn-coding-mirrors
8
+ scope: china-network
9
+ ---
10
+
11
+ # 国内镜像配置总入口
12
+
13
+ **不要凭记忆猜镜像地址**:先按下面的流程定位生态,再打开对应的 reference 文件,里面是最小可用的配置片段。
14
+
15
+ ## 使用流程
16
+
17
+ 1. 判断生态:Python / Node / Java / Go / Rust / 系统包 / AI 模型与权重 / 容器镜像 / VCS。
18
+ 2. 打开 `references/<生态>.md`,复制对应配置。
19
+ 3. 配置完**验证一次**(每个 reference 底部都有验证命令),把结果告诉用户。
20
+ 4. 需要"下载单个文件 / 拉镜像"这类非包管理器场景,别在本技能里硬写 curl,改用:
21
+ - GitHub release/资产 → 技能 `gh-download`(`scripts/ghdl`)
22
+ - Docker/OCI 镜像 → 技能 `docker-pull`(`scripts/dpull`)
23
+
24
+ ## Reference 索引
25
+
26
+ | 生态 | 文件 | 覆盖 |
27
+ |---|---|---|
28
+ | Python | `references/python.md` | pip、uv、poetry/pdm、conda |
29
+ | Node/JS | `references/node.md` | npm/yarn/pnpm、node 二进制、electron/sass/puppeteer |
30
+ | Java | `references/java.md` | maven、gradle、spring/sbt |
31
+ | Go | `references/go.md` | GOPROXY、sumdb |
32
+ | Rust | `references/rust.md` | cargo sparse index、rustup |
33
+ | 系统包 | `references/system.md` | apt/Ubuntu、apk/alpine、dnf/centos、brew |
34
+ | AI | `references/ai.md` | HuggingFace、ModelScope、PyTorch wheels、tiktoken 等 |
35
+ | 其他语言 | `references/misc.md` | Flutter/Dart、Composer/PHP、NuGet/.NET、CRAN/R、RubyGems、Helm |
36
+ | 容器镜像 | `references/docker.md` | registry 镜像源、`dpull` 用法 |
37
+ | 版本控制 | `references/vcs.md` | GitHub 代理、git 加速、Mercurial(hg)/SVN |
38
+
39
+ ## 源不可用时:先做实时探测
40
+
41
+ 不要凭猜测换源。技能自带探测脚本(相对本 SKILL.md 所在目录)会并发检查 38 个端点:
42
+
43
+ ```bash
44
+ bash ../../scripts/check-mirrors.sh # 表格
45
+ bash ../../scripts/check-mirrors.sh --json # 机器可读
46
+ ```
47
+
48
+ 按结果选择:优先用状态 `OK`、耗时低的源;`AUTH`(401/403) 说明可达但需登录,别当故障;
49
+ `404` 通常是路径变更,更新 reference 里的地址。同一个生态**至多试两个源**,还不行就报告
50
+ "该生态的国内镜像当前均不可用,建议配代理或稍后重试",不要把重试循环留给用户等。
51
+
52
+ ## 通用原则
53
+
54
+ - **优先用户级配置**(`~/.npmrc`、`~/.pip/pip.conf`、`~/.cargo/config.toml`),避免动系统文件;必须动系统文件时明确告知用户需要 sudo。
55
+ - **一次只改一个源**,改完立即验证;失败就回退到上一个可用源,别叠加多层配置。
56
+ - 镜像站会挂(403/429/超时),**永远准备 2–3 个备选**,reference 里已按优先级排好。
57
+ - 不要用 `curl | sh` 之类的安装脚本"顺手"改配置;显式写配置文件,用户可审计、可回滚。
58
+ - 报告结果时说清:改了哪个文件、原内容是否备份、验证命令与输出。
@@ -0,0 +1,65 @@
1
+ # AI 模型与权重(HuggingFace / ModelScope / PyTorch)
2
+
3
+ ## HuggingFace:hf-mirror.com(最常用)
4
+
5
+ ```bash
6
+ # 最省事:只改环境变量,huggingface_hub / transformers / diffusers 全部生效
7
+ export HF_ENDPOINT="https://hf-mirror.com"
8
+ ```
9
+
10
+ 持久化写到 `~/.bashrc` 或 `~/.config/huggingface/huggingface.toml`(新版 hub 支持 `endpoint = ...`)。
11
+
12
+ ```bash
13
+ # 下载单个仓库
14
+ hf download <repo_id> --repo-type model # 新版 CLI(huggingface_hub>=0.24)
15
+ huggingface-cli download <repo_id> --resume # 旧版
16
+ hugging-cli download <repo_id> # hf-mirror 自带的极简 CLI
17
+
18
+ # 代码里
19
+ import os
20
+ os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
21
+ from huggingface_hub import snapshot_download
22
+ snapshot_download("bert-base-chinese")
23
+ ```
24
+
25
+ 要点:
26
+ - `HF_ENDPOINT` 必须**在 import transformers/huggingface_hub 之前**设置。
27
+ - 大文件用 `resume`/断点续传;`hf-mirror` 支持 Range,中断后重跑即可续。
28
+ - 私有仓库/gated 模型仍需 `HF_TOKEN`;镜像不绕过授权。
29
+ - 备选:`https://hf-mirror.com` 为唯一成熟公共镜像;再不通就走代理 `HF_ENDPOINT` 保留官方 + `HTTPS_PROXY`。
30
+
31
+ ## ModelScope(国内权重源,常与 HF 互为备份)
32
+
33
+ ```bash
34
+ pip install modelscope -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
35
+ modelscope download --model Qwen/Qwen2.5-7B-Instruct --local_dir ./qwen
36
+ ```
37
+
38
+ ## PyTorch wheels(`download.pytorch.org` 国内慢)
39
+
40
+ ```bash
41
+ # 阿里云 wheel 镜像
42
+ pip install torch torchvision torchaudio \
43
+ --index-url https://mirrors.aliyun.com/pytorch-wheels/cu121
44
+ # CPU 版
45
+ pip install torch --index-url https://mirrors.aliyun.com/pytorch-wheels/cpu
46
+ ```
47
+
48
+ ## 其他常见卡点
49
+
50
+ ```bash
51
+ export TIKTOKEN_CACHE_DIR="$HOME/.cache/tiktoken" # 避免每次下载 BPE 文件
52
+ export HF_HUB_ENABLE_HF_TRANSFER=0 # hf_transfer 在国内常失败,先关掉
53
+ export TRANSFORMERS_OFFLINE=1 # 权重已就位、只想跑推理时
54
+ export OLLAMA_HOST="https://ollama.example.com" # ollama 拉模型仍走 registry
55
+ ```
56
+
57
+ Ollama 拉模型走 Docker Hub 风格 registry,卡住时用技能 `docker-pull` 的思路或配代理。
58
+
59
+ ## 验证
60
+
61
+ ```bash
62
+ curl -sI -m 8 https://hf-mirror.com/api/models/bert-base-chinese | head -1
63
+ HF_ENDPOINT=https://hf-mirror.com python -c "
64
+ from huggingface_hub import model_info; print(model_info('bert-base-chinese').modelId)"
65
+ ```
@@ -0,0 +1,48 @@
1
+ # 容器镜像(registry 镜像源与 dpull)
2
+
3
+ ## 优先方案:不用 `docker pull`,用 `dpull`
4
+
5
+ `docker pull` 在 ghcr.io / docker.io 上常被限速到几十 KB/s(实测 ghcr.io 单连接 ~70 KB/s)。
6
+ 技能 `docker-pull` 提供的 `scripts/dpull` 按 registry v2 协议分片下载 layer,走国内镜像源并校验 sha256,
7
+ 1.38 GB 镜像约 155 秒完成:
8
+
9
+ ```bash
10
+ python3 <this-skill-dir>/../docker-pull/scripts/dpull ghcr.io/usestrix/strix-sandbox:1.3.0
11
+ ```
12
+
13
+ ## 兜底方案:daemon 级 registry mirror
14
+
15
+ `/etc/docker/daemon.json`(需要 sudo + 重启 dockerd;且多数公共加速器已要求登录/已停服,成功率不稳定):
16
+
17
+ ```json
18
+ {
19
+ "registry-mirrors": [
20
+ "https://docker.m.daocloud.io",
21
+ "https://docker.1panel.live",
22
+ "https://hub.rat.dev"
23
+ ]
24
+ }
25
+ ```
26
+
27
+ ```bash
28
+ sudo systemctl restart docker && docker info | grep -A3 "Registry Mirrors"
29
+ ```
30
+
31
+ 分 registry 的镜像源(路径不变,替换 host 即可):
32
+
33
+ | 官方 | 国内镜像 |
34
+ |---|---|
35
+ | `docker.io` | `docker.m.daocloud.io`、`docker.1panel.live`、`hub.rat.dev` |
36
+ | `ghcr.io` | `ghcr.nju.edu.cn`(最稳)、`ghcr.m.daocloud.io`(常 403) |
37
+ | `gcr.io` / `registry.k8s.io` | `gcr.m.daocloud.io` / `k8s.m.daocloud.io` |
38
+ | `quay.io` | `quay.m.daocloud.io` |
39
+
40
+ 实测(2025,本机):`ghcr.nju.edu.cn` 单连接 4.9 MB/s、16 分片并发约 15 MB/s;
41
+ `ghcr.io` 直连 0.07 MB/s;`ghcr.m.daocloud.io` 对私有镜像返回 403。
42
+
43
+ ## 验证
44
+
45
+ ```bash
46
+ docker info | grep -A3 "Registry Mirrors"
47
+ time curl -sI -m 10 https://ghcr.nju.edu.cn/v2/ | head -1
48
+ ```