#!/usr/bin/env bash # Amphion Work — install the amphion-work plugin into the DSH desktop profile. # # curl -fsSL https://work.amphiondev.com/amphion-work/install.sh | bash # # What it does: # 1. downloads the plugin package to ~/.dsh/plugins/amphion-work # 2. adds it to ~/.dsh/profiles/desktop/package.json (dependencies + dsh.profile.bundles), # keeping a backup next to it # and takes the public "DSH 随行" plugin (dsh-suixing) out of it: both own /mobile # 3. links it with the pnpm that ships inside DSH desktop (or pnpm on PATH) # Then restart DSH and run `/mobile pair <配对码>` in any session. set -euo pipefail BASE_URL="${DSH_MOBILE_BASE:-https://work.amphiondev.com/amphion-work}" DSH_HOME="${DSH_HOME:-$HOME/.dsh}" PROFILE="${DSH_PROFILE:-desktop}" PROFILE_DIR="$DSH_HOME/profiles/$PROFILE" TARGET="$DSH_HOME/plugins/amphion-work" say() { printf '\033[1m%s\033[0m\n' "$*"; } die() { printf '安装失败:%s\n' "$*" >&2; exit 1; } [ -d "$PROFILE_DIR" ] || die "没有找到 DSH 配置目录 ${PROFILE_DIR}。请先安装并打开一次 DSH 桌面版。" [ -f "$PROFILE_DIR/package.json" ] || die "${PROFILE_DIR}/package.json 不存在。" # A JavaScript runtime for editing JSON: DSH's bundled node, then node, then python3. DSH_APP="" for app in "$HOME/Applications/DeepSeek Harness.app" "/Applications/DeepSeek Harness.app"; do [ -d "$app" ] && DSH_APP="$app" && break done DEPS="$DSH_APP/Contents/Resources/runtime/primary-runtime/dependencies" NODE="" if [ -n "$DSH_APP" ] && [ -x "$DEPS/node/bin/node" ]; then NODE="$DEPS/node/bin/node"; elif command -v node >/dev/null; then NODE="$(command -v node)"; fi say "下载插件…" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT curl -fsSL "$BASE_URL/download/amphion-work.tgz" -o "$tmp/bridge.tgz" || die "下载失败,请检查网络。" mkdir -p "$tmp/x" tar -xzf "$tmp/bridge.tgz" -C "$tmp/x" [ -f "$tmp/x/package/dist/index.js" ] || die "插件包内容不完整。" rm -rf "$TARGET" mkdir -p "$(dirname "$TARGET")" mv "$tmp/x/package" "$TARGET" say "加入 DSH 配置(${PROFILE})…" stamp="$(date +%Y%m%d%H%M%S)" cp "$PROFILE_DIR/package.json" "$PROFILE_DIR/package.json.bak-amphion-work-$stamp" edit_js=' const fs = require("fs"); const [file, target] = process.argv.slice(1); const pkg = JSON.parse(fs.readFileSync(file, "utf8")); pkg.dependencies = pkg.dependencies || {}; // Its name before 0.4; an npm package of that name belongs to someone else and is left alone. const old = pkg.dependencies["dsh-mobile-bridge"]; const ours = typeof old === "string" && /^link:.*[\\/](plugins[\\/]dsh-mobile-bridge|packages[\\/]bridge)$/.test(old); if (ours) delete pkg.dependencies["dsh-mobile-bridge"]; pkg.dependencies["amphion-work"] = "link:" + target; // The public DSH 随行 plugin registers the same /mobile command; only one can be loaded. const suixing = "dsh-suixing" in pkg.dependencies; if (suixing) { delete pkg.dependencies["dsh-suixing"]; console.log("SUIXING_REMOVED"); } pkg.dsh = pkg.dsh || {}; pkg.dsh.profile = pkg.dsh.profile || {}; const bundles = pkg.dsh.profile.bundles = (pkg.dsh.profile.bundles || []).filter(b => !(ours && b === "dsh-mobile-bridge") && b !== "dsh-suixing"); if (!bundles.includes("amphion-work")) bundles.push("amphion-work"); fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + "\n"); ' if [ -n "$NODE" ]; then EDIT_OUT="$("$NODE" -e "$edit_js" "$PROFILE_DIR/package.json" "$TARGET")" elif command -v python3 >/dev/null; then EDIT_OUT="$(python3 - "$PROFILE_DIR/package.json" "$TARGET" <<'PY' import json, re, sys OURS = re.compile(r"^link:.*[\\/](plugins[\\/]dsh-mobile-bridge|packages[\\/]bridge)$") f, t = sys.argv[1], sys.argv[2] p = json.load(open(f)) d = p.setdefault("dependencies", {}) old = d.get("dsh-mobile-bridge") ours = isinstance(old, str) and OURS.search(old) if ours: del d["dsh-mobile-bridge"] d["amphion-work"] = "link:" + t if d.pop("dsh-suixing", None) is not None: print("SUIXING_REMOVED") pr = p.setdefault("dsh", {}).setdefault("profile", {}) b = pr["bundles"] = [x for x in pr.get("bundles", []) if not (ours and x == "dsh-mobile-bridge") and x != "dsh-suixing"] if "amphion-work" not in b: b.append("amphion-work") open(f, "w").write(json.dumps(p, indent=2, ensure_ascii=False) + "\n") PY )" else die "需要 node 或 python3 来修改配置文件。" fi say "安装依赖链接…" if [ -n "$DSH_APP" ] && [ -f "$DEPS/pnpm/bin/pnpm.mjs" ] && [ -n "$NODE" ]; then (cd "$PROFILE_DIR" && "$NODE" "$DEPS/pnpm/bin/pnpm.mjs" install --silent) || die "pnpm install 失败,配置已备份为 package.json.bak-amphion-work-$stamp" elif command -v pnpm >/dev/null; then (cd "$PROFILE_DIR" && pnpm install --silent) || die "pnpm install 失败,配置已备份为 package.json.bak-amphion-work-$stamp" else echo "没有找到 pnpm;DSH 重启时会自行安装。" fi # the copy under the old name is no longer used if grep -q "DSH 随行" "$DSH_HOME/plugins/dsh-mobile-bridge/package.json" 2>/dev/null && ! grep -q "plugins/dsh-mobile-bridge" "$PROFILE_DIR/package.json"; then rm -rf "$DSH_HOME/plugins/dsh-mobile-bridge"; fi echo say "已安装 Amphion Work 插件。" case "${EDIT_OUT:-}" in *SUIXING_REMOVED*) echo "已从 DSH 配置里移除公开版「DSH 随行」插件(两者都使用 /mobile 命令,只能启用一个)。" echo "它的文件和配对信息都保留着;想换回去,重新运行 DSH 随行的安装命令即可。" ;; esac echo "1. 重启 DSH 桌面版。" echo "2. 在手机上打开 ${BASE_URL}/ ,登录后点「添加电脑」获取配对码。" # the plugin defaults to the official server; any other one is named when pairing case "$BASE_URL" in *work.amphiondev.com/amphion-work) RELAY_ARG="" ;; *) RELAY_ARG=" $BASE_URL/" ;; esac echo "3. 在任意 DSH 会话里发送:/mobile pair <配对码>$RELAY_ARG"