diff --git a/README.md b/README.md index b8dbb90e2..c4eb243ef 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Runs on macOS, Windows and Linux (menu bar app, window, TUI, web UI and CLI), in curl -fsSL https://usemagpie.ai/install.sh | sh ``` -Mac builds are signed and notarised, and every build updates itself. Behind a firewall, use `--proxy` or `--mirror`. Or `go install github.com/yetone/magpie@latest`, or the [Docker image](https://usemagpie.ai/docs/docker). +Mac builds are signed and notarised, and every build updates itself. Behind a firewall, use `--proxy` or `--mirror`. Or `go install github.com/yetone/magpie@latest`, or the [Docker image](https://usemagpie.ai/docs/docker). Remove what the script installed with `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall`; your settings in `~/.config/magpie` stay unless you add `--purge`, which disconnects your agents and deletes them too. **2 · Add a provider.** Open magpie and go to **Providers → Add provider**. Pick a preset and paste a key, or sign in with a subscription. diff --git a/README.zh-CN.md b/README.zh-CN.md index 3738665cc..6c2e14576 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -52,7 +52,7 @@ curl -fsSL https://usemagpie.ai/install.sh | sh ``` -Mac 版已签名并公证,每个版本都会自动更新。网络受限时可用 `--proxy` 或 `--mirror`。也可以 `go install github.com/yetone/magpie@latest`,或者用 [Docker 镜像](https://usemagpie.ai/docs/zh/docker)。 +Mac 版已签名并公证,每个版本都会自动更新。网络受限时可用 `--proxy` 或 `--mirror`。也可以 `go install github.com/yetone/magpie@latest`,或者用 [Docker 镜像](https://usemagpie.ai/docs/zh/docker)。 用 `curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall` 卸载脚本装上的东西;`~/.config/magpie` 里的设置会保留,加 `--purge` 才会断开 Agent 并一起删除。 **2 · 添加 provider**。打开 magpie,进入 **Providers → 添加 provider**。选一个预设、粘贴 key,或者登录一个订阅。 diff --git a/site/install.test.mjs b/site/install.test.mjs index a82b3678f..4c9f7b157 100644 --- a/site/install.test.mjs +++ b/site/install.test.mjs @@ -33,6 +33,13 @@ function install(t, { termux = true, arch = "aarch64", override = false, prefixO const requests = join(dir, "requests"); writeFileSync(join(tools, "uname"), `#!/bin/sh\ncase "$1" in -m) echo '${arch}';; -s) echo Linux;; esac\n`, { mode: 0o755 }); writeFileSync(join(tools, "ldconfig"), "#!/bin/sh\necho libwebkit2gtk-4.1.so.0\n", { mode: 0o755 }); + // xdg-mime as xdg-utils writes the default: one line in mimeapps.list + writeFileSync(join(tools, "xdg-mime"), `#!/bin/sh +[ "$1" = default ] || exit 0 +mkdir -p "$XDG_CONFIG_HOME" +printf '[Default Applications]\\n' >> "$XDG_CONFIG_HOME/mimeapps.list" +printf '%s=%s\\n' "$3" "$2" >> "$XDG_CONFIG_HOME/mimeapps.list" +`, { mode: 0o755 }); writeFileSync(join(tools, "curl"), `#!${process.execPath} const fs = require("node:fs"); const args = process.argv.slice(2); @@ -62,10 +69,15 @@ else fs.writeFileSync(args[args.indexOf("-o") + 1], tamper && url.startsWith(tam MAGPIE_MIRROR: "", ...extra, }; - const result = spawnSync("sh", [installer, ...args], { env, encoding: "utf8" }); const read = (p) => (existsSync(p) ? readFileSync(p, "utf8") : ""); - const calls = read(env.INSTALL_ARGS).trim().split("\n").filter(Boolean).map((l) => JSON.parse(l)); - return { ...result, bin, file, payload, share: env.XDG_DATA_HOME, requests: read(requests), calls }; + const run = (args) => { + rmSync(requests, { force: true }); + rmSync(env.INSTALL_ARGS, { force: true }); + const result = spawnSync("sh", [installer, ...args], { env, encoding: "utf8" }); + const calls = read(env.INSTALL_ARGS).trim().split("\n").filter(Boolean).map((l) => JSON.parse(l)); + return { ...result, requests: read(requests), calls }; + }; + return { ...run(args), run, bin, file, payload, home, env, share: env.XDG_DATA_HOME, config: env.XDG_CONFIG_HOME }; } test("Termux downloads Android arm64 into PREFIX/bin even with WebKit installed", (t) => { @@ -168,3 +180,110 @@ test("a file the mirror changed is refused and the installed magpie kept", (t) = assert.notEqual(bad.status, 0); assert.match(bad.stderr, /--mirror is an http\(s\) address/); }); + +// pota on Discord: the script installed magpie and had no way to take it +// off. --uninstall takes off what it put there and keeps the user's +// settings; --purge has magpie disconnect the agents and delete them first. +function installedDesktop(t, opts = {}) { + const r = install(t, { termux: false, desktop: true, ...opts }); + assert.equal(r.status, 0, r.stderr); + const exe = join(r.bin, "magpie"); + // magpie itself, as far as the uninstall asks it anything + writeFileSync(exe, `#!/bin/sh +echo "$*" >> "$HOME/magpie-calls" +[ "$1 $2" = "daemon uninstall" ] && rm -f "$XDG_CONFIG_HOME/systemd/user/magpie.service" +[ "$1 $2" = "uninstall --yes" ] && { [ -z "$MAGPIE_FAIL" ] || exit 1; rm -rf "$XDG_CONFIG_HOME/magpie" "$XDG_DATA_HOME/applications/magpie.desktop"; } +exit 0 +`, { mode: 0o755 }); + const settings = join(r.config, "magpie", "settings.json"); + mkdirSync(join(r.config, "magpie"), { recursive: true }); + writeFileSync(settings, "{}"); + const calls = () => (existsSync(join(r.home, "magpie-calls")) ? readFileSync(join(r.home, "magpie-calls"), "utf8") : ""); + return { ...r, exe, settings, calls, entry: join(r.share, "applications/magpie.desktop"), icon: join(r.share, "icons/hicolor/256x256/apps/magpie.png"), mime: join(r.config, "mimeapps.list") }; +} + +test("--uninstall takes off the command, menu entry, icon and magpie:// default, and keeps the settings", (t) => { + const r = installedDesktop(t); + for (const p of [r.exe, r.entry, r.icon]) assert.ok(existsSync(p), p); + writeFileSync(r.mime, readFileSync(r.mime, "utf8") + "text/html=firefox.desktop\n"); + assert.match(readFileSync(r.mime, "utf8"), /^x-scheme-handler\/magpie=magpie\.desktop$/m); + const u = r.run(["--uninstall"]); + assert.equal(u.status, 0, u.stderr); + for (const p of [r.exe, r.entry, r.icon]) assert.equal(existsSync(p), false, p); + assert.equal(readFileSync(r.mime, "utf8"), "[Default Applications]\ntext/html=firefox.desktop\n"); + assert.ok(existsSync(r.settings), "the settings stay"); + assert.equal(r.calls(), "", "magpie isn't asked to uninstall"); + assert.equal(u.calls.length, 0, "nothing is downloaded"); + assert.match(u.stdout, /kept your settings.*--purge/); + // again: nothing there, nothing wrong + const again = r.run(["--uninstall"]); + assert.equal(again.status, 0, again.stderr); + assert.match(again.stdout, /no magpie installed by this script/); +}); + +test("--uninstall takes the service and login entry that start this magpie, never another's", (t) => { + const r = installedDesktop(t); + const unit = join(r.config, "systemd/user/magpie.service"); + const login = join(r.config, "autostart/magpie.desktop"); + mkdirSync(join(r.config, "systemd/user"), { recursive: true }); + mkdirSync(join(r.config, "autostart"), { recursive: true }); + writeFileSync(unit, `[Service]\nExecStart="${r.exe}" serve\n`); + writeFileSync(login, `[Desktop Entry]\nExec="${r.exe}" --autostart\n`); + const u = r.run(["--uninstall"]); + assert.equal(u.status, 0, u.stderr); + assert.equal(existsSync(unit), false); + assert.equal(existsSync(login), false); + assert.match(r.calls(), /^daemon uninstall$/m); + + // another magpie's (one still there) are left alone + const o = installedDesktop(t); + const other = join(o.home, "elsewhere/magpie"); + mkdirSync(join(o.home, "elsewhere"), { recursive: true }); + writeFileSync(other, "", { mode: 0o755 }); + mkdirSync(join(o.config, "systemd/user"), { recursive: true }); + mkdirSync(join(o.config, "autostart"), { recursive: true }); + const ounit = join(o.config, "systemd/user/magpie.service"); + const ologin = join(o.config, "autostart/magpie.desktop"); + writeFileSync(ounit, `[Service]\nExecStart="${other}" serve\n`); + writeFileSync(ologin, `[Desktop Entry]\nExec="${other}" --autostart\n`); + writeFileSync(o.entry, `[Desktop Entry]\nExec=${other} %u\n`); + const ou = o.run(["--uninstall"]); + assert.equal(ou.status, 0, ou.stderr); + for (const p of [ounit, ologin, o.entry]) assert.ok(existsSync(p), p); + assert.equal(existsSync(o.exe), false); +}); + +test("--purge has magpie uninstall itself first, then takes off the install", (t) => { + const r = installedDesktop(t); + const u = r.run(["--purge"]); + assert.equal(u.status, 0, u.stderr); + assert.match(r.calls(), /^uninstall --yes$/m); + for (const p of [r.exe, r.entry, r.icon, r.settings]) assert.equal(existsSync(p), false, p); + // magpie took the menu entry itself; its icon and magpie:// default go too + assert.doesNotMatch(readFileSync(r.mime, "utf8"), /magpie/); + assert.doesNotMatch(u.stdout, /kept your settings/); + + // magpie failing to: the command stays, to run it again + const f = installedDesktop(t, { env: { MAGPIE_FAIL: "1" } }); + const fu = f.run(["--uninstall", "--purge"]); + assert.notEqual(fu.status, 0); + assert.match(fu.stderr, /magpie uninstall didn't finish/); + for (const p of [f.exe, f.entry, f.settings]) assert.ok(existsSync(p), p); + + // no magpie to ask: refused, the settings kept + const n = installedDesktop(t); + rmSync(n.exe); + const nu = n.run(["--purge"]); + assert.notEqual(nu.status, 0); + assert.match(nu.stderr, /no magpie at .* --uninstall alone/); + assert.ok(existsSync(n.settings)); +}); + +test("--uninstall in Termux takes off PREFIX/bin/magpie", (t) => { + const r = install(t, {}); + assert.equal(r.status, 0, r.stderr); + const u = r.run(["--uninstall"]); + assert.equal(u.status, 0, u.stderr); + assert.equal(existsSync(join(r.bin, "magpie")), false); + assert.match(u.stdout, /removed .*com\.termux\/files\/usr\/bin\/magpie/); +}); diff --git a/site/public/docs/ja/start.html b/site/public/docs/ja/start.html index 350e87264..23295b6a3 100644 --- a/site/public/docs/ja/start.html +++ b/site/public/docs/ja/start.html @@ -285,6 +285,9 @@ magpie claude group/opus-anywhere # これを使う
GitHub に届かない環境で、インストールや更新をするには?インストーラと magpie update にプロキシを渡します:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --proxy http://127.0.0.1:7890、または magpie update --proxy socks5://127.0.0.1:1080(http・https・socks5・socks5h に対応。HTTPS_PROXY と ALL_PROXY も使われます)。--mirror <prefix> を付けると、指定した GitHub ダウンロードミラーから <prefix>https://github.com/… としてリリースファイルを取得します。magpie update mirror <prefix> でアプリ自身の更新を含め毎回使い、magpie update mirror off で解除します。指定しない限りミラーは使われず、ファイルの SHA-256 はミラーではなく常に usemagpie.ai から取得するので、ミラーが書き換えたファイルはインストールされません。アプリ自身の更新は Settings → Proxy を通ります。
スクリプトでインストールした場合:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall で、スクリプトが置いたものを取り除きます。magpie コマンド、macOS ではアプリ、Linux ではメニュー項目・アイコン・magpie:// のハンドラ、それに Linux ではもう無い magpie を起動してしまうサービスとログイン時の起動です。~/.config/magpie の設定・プロバイダ・使用量は残るので、再インストールすれば戻ります。接続したエージェントはそれまで magpie のアドレスを指したままです。--purge を付けると先に magpie uninstall --yes を実行し、すべてのエージェントの接続を外して元の設定に戻してから、magpie の設定・プロバイダ・使用量を削除します。ほかの方法でインストールした場合は、magpie uninstall または Settings → magpie をアンインストール が --purge と同じことを行い、プログラム本体は手動で削除します。
アプリ(ウィンドウ、メニューバーやトレイのアイコン、パネル。どう開いたかによらず)は app.log を書きます。macOS では ~/Library/Logs/magpie/app.log、Windows では %LOCALAPPDATA%\magpie\logs\app.log、Linux では ~/.local/state/magpie/app.log($XDG_STATE_HOME が設定されていれば $XDG_STATE_HOME/magpie)、ポータブル版ではデータフォルダーの logs です。設定 → 情報 → ログにパスがあり、開くでそのフォルダーを表示します。magpie log はパスを表示し、magpie log -f は追いかけます。5 MiB に達すると隣の app.old.log になり、残るのは最大 2 ファイルです。記録されるのは magpie がしたことと出会ったエラー(プロバイダーがリクエストを断った、再試行した、プラグインが起動しなかった)で、キー、プロンプト、返答は含みません。キーやトークンに見えるものも伏せられます。サービスとして動く magpie serve のログは別の場所です。macOS では ~/Library/Logs/magpie/serve.log、Linux では journalctl --user -u magpie。magpie log はそれも示します。
Give the installer and magpie update a proxy: curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --proxy http://127.0.0.1:7890, or magpie update --proxy socks5://127.0.0.1:1080 (http, https, socks5 and socks5h; HTTPS_PROXY and ALL_PROXY are honoured too). --mirror <prefix> fetches the release file from a GitHub download mirror you choose, as <prefix>https://github.com/…; magpie update mirror <prefix> keeps it for every update, the app’s too, and magpie update mirror off removes it. No mirror is used unless you give one, and the file’s SHA-256 still comes from usemagpie.ai, never from the mirror: a file the mirror changed is refused. The app’s own updates go through Settings → Proxy.
Installed with the script: curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall takes off what it put there: the magpie command, and the app on macOS or its menu entry, icon and magpie:// handler on Linux, with magpie’s service and opening at login there, which would start a magpie that is gone. Your settings, providers and usage in ~/.config/magpie stay, for when you install again; agents you connected keep magpie’s address until then. Add --purge to have magpie uninstall --yes run first: it disconnects every agent and puts back what each had, then deletes magpie’s settings, providers and usage. Installed another way, magpie uninstall or Settings → Uninstall magpie does what --purge does and leaves the program itself for you to delete.
The app (its window, the menu bar or tray icon and the panel, however it was opened) writes app.log: ~/Library/Logs/magpie/app.log on macOS, %LOCALAPPDATA%\magpie\logs\app.log on Windows, ~/.local/state/magpie/app.log on Linux ($XDG_STATE_HOME/magpie when that is set), and logs in a portable magpie’s data folder. Settings → About → Log has its path and an Open that shows its folder; magpie log prints it, and magpie log -f follows it. At 5 MiB it becomes app.old.log beside it, so two files at most are kept. It holds what magpie did and the errors it met (a provider refusing a request, a retry, a plugin that failed to start), not your keys, prompts or replies; what looks like a key or token is masked anyway. magpie serve run as a service logs elsewhere: ~/Library/Logs/magpie/serve.log on macOS, journalctl --user -u magpie on Linux; magpie log names it too.
给安装脚本和 magpie update 加代理:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --proxy http://127.0.0.1:7890,或 magpie update --proxy socks5://127.0.0.1:1080(支持 http、https、socks5、socks5h;环境变量 HTTPS_PROXY、ALL_PROXY 同样生效)。--mirror <前缀> 从你指定的 GitHub 下载镜像取发布文件,即 <前缀>https://github.com/…;magpie update mirror <前缀> 让之后每次更新(包括应用自己的更新)都用它,magpie update mirror off 取消。不指定就不用任何镜像;文件的 SHA-256 始终来自 usemagpie.ai,而不是镜像,镜像改过的文件会被拒绝安装。应用自己的更新走 设置 → 代理。
用安装脚本装的:curl -fsSL https://usemagpie.ai/install.sh | sh -s -- --uninstall 会拿掉它装上的东西:magpie 命令,macOS 上的应用,Linux 上的菜单项、图标和 magpie:// 链接处理,以及 Linux 上会去启动一个已不存在的 magpie 的后台服务和开机启动。~/.config/magpie 里的设置、provider 和用量都保留,重新安装就回来;已连接的 Agent 在那之前仍指向 magpie 的地址。加上 --purge 会先运行 magpie uninstall --yes:断开每个 Agent 并恢复它原来的配置,再删除 magpie 的设置、provider 和用量。用其他方式装的,magpie uninstall 或 设置 → 卸载 magpie 做的就是 --purge 那些事,程序本身留给你删除。
应用(窗口、菜单栏或托盘图标、快捷面板,不论怎样打开)写入 app.log:macOS 上是 ~/Library/Logs/magpie/app.log,Windows 上是 %LOCALAPPDATA%\magpie\logs\app.log,Linux 上是 ~/.local/state/magpie/app.log(设置了 $XDG_STATE_HOME 时是 $XDG_STATE_HOME/magpie),便携版则在数据文件夹的 logs 里。设置 → 关于 → 日志里有它的路径,打开会显示它所在的文件夹;magpie log 打印路径,magpie log -f 持续跟随。满 5 MiB 后它变成旁边的 app.old.log,最多保留两个文件。它记的是 magpie 做了什么、遇到了哪些错误(服务商拒绝请求、重试、插件没能启动),不含你的密钥、提示词或回复;看起来像密钥或令牌的内容也会被遮掉。作为服务运行的 magpie serve 日志在别处:macOS 上是 ~/Library/Logs/magpie/serve.log,Linux 上是 journalctl --user -u magpie;magpie log 也会列出它。