feat: 编译为独立 auth-rt 二进制,安装到 ~/.openclaw/bin/

- bun build --compile 生成独立可执行文件
- install.sh 编译并安装到 ~/.openclaw/bin/auth-rt
- auth-cli.ts 改为调用 auth-rt 二进制(不再需要 bun run cli.ts)
- skill 不再需要 clone auth-runtime 源码

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ywkj 2026-03-20 18:26:20 +08:00
parent 97a8fd9c7b
commit f079b68559
4 changed files with 24 additions and 38 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
node_modules/ node_modules/
auth-rt

View File

@ -1,33 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Bootstrap auth-runtime into the skill store. # Compile auth-rt CLI binary and install to ~/.openclaw/bin/
# Run this ONCE before installing any skills.
# #
# Usage: # Usage:
# curl -fsSL https://your-forgejo/raw/auth-runtime/main/install.sh | bash # ./install.sh
# # or: # ./install.sh /custom/bin/dir
# ./install.sh [skill-store-dir]
set -euo pipefail set -euo pipefail
cd "$(dirname "$0")"
STORE="${1:-$HOME/.openclaw/skills}" BIN_DIR="${1:-$HOME/.openclaw/bin}"
DEST="$STORE/_shared/auth-runtime" mkdir -p "$BIN_DIR"
REPO="${AUTH_RUNTIME_REPO:-}" # set via env or hardcode below
# Hardcode your Forgejo URL here: echo "Compiling auth-rt..."
# REPO="https://git.yourserver.com/you/auth-runtime.git" bun build --compile src/cli.ts --outfile "$BIN_DIR/auth-rt"
if [[ -z "$REPO" ]]; then echo "Installed: $BIN_DIR/auth-rt"
echo "Error: set AUTH_RUNTIME_REPO=https://git.yourserver.com/you/auth-runtime.git" echo "Ensure $BIN_DIR is in your PATH."
exit 1
fi
if [[ -d "$DEST/.git" ]]; then
echo "Updating auth-runtime..."
git -C "$DEST" pull --ff-only
else
echo "Installing auth-runtime to $DEST..."
mkdir -p "$STORE/_shared"
git clone "$REPO" "$DEST"
fi
echo "auth-runtime ready at $DEST"

View File

@ -13,7 +13,8 @@
}, },
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"clean": "rm -rf dist" "compile": "bun build --compile src/cli.ts --outfile auth-rt",
"clean": "rm -rf dist auth-rt"
}, },
"keywords": [ "keywords": [
"auth", "auth",

View File

@ -1,9 +1,12 @@
/** /**
* Thin CLI wrapper for auth-runtime. * Thin CLI wrapper for auth-runtime.
* *
* Copy this file into your skill's src/ directory. It spawns * Copy this file into your skill's src/ directory. It calls the
* `bun run <auth-runtime>/src/cli.ts` as a subprocess, so the * `auth-rt` binary (compiled from auth-runtime), so the skill has
* skill has zero npm dependency on @clawd/auth-runtime. * zero npm dependency on @clawd/auth-runtime.
*
* Prerequisites:
* ~/.openclaw/bin/auth-rt must exist (run auth-runtime/install.sh)
* *
* Usage: * Usage:
* import { createSkillClient } from './auth-cli.ts'; * import { createSkillClient } from './auth-cli.ts';
@ -15,9 +18,8 @@ import { spawnSync } from 'child_process';
import * as path from 'path'; import * as path from 'path';
import * as os from 'os'; import * as os from 'os';
const AUTH_RUNTIME_DIR = process.env.AUTH_RUNTIME_DIR const AUTH_RT_BIN = process.env.AUTH_RT_BIN
|| path.join(os.homedir(), 'clawd', 'skills', 'auth-runtime'); || path.join(os.homedir(), '.openclaw', 'bin', 'auth-rt');
const CLI_ENTRY = path.join(AUTH_RUNTIME_DIR, 'src', 'cli.ts');
export interface ApiResponse { export interface ApiResponse {
status: number; status: number;
@ -38,19 +40,16 @@ export interface SkillClientOptions {
} }
function runCli(...args: string[]): string { function runCli(...args: string[]): string {
// Use the same bun binary that's running this process const result = spawnSync(AUTH_RT_BIN, args, {
const bun = process.execPath;
const result = spawnSync(bun, ['run', CLI_ENTRY, ...args], {
cwd: AUTH_RUNTIME_DIR,
encoding: 'utf-8', encoding: 'utf-8',
timeout: 60_000, timeout: 60_000,
}); });
if (result.error) { if (result.error) {
throw new Error(`auth-cli spawn failed: ${result.error.message}`); throw new Error(`auth-rt spawn failed: ${result.error.message}`);
} }
if (result.status !== 0) { if (result.status !== 0) {
throw new Error(`auth-cli failed (exit ${result.status}): ${(result.stderr || '').trim()}`); throw new Error(`auth-rt failed (exit ${result.status}): ${(result.stderr || '').trim()}`);
} }
return (result.stdout || '').trim(); return (result.stdout || '').trim();
} }