- 新增 src/auth-cli.ts:通过 subprocess 调用 auth-runtime CLI - 新增 install.sh:检查 auth-runtime 目录 - 新增 README.md:文档化 auth-cli.ts 认证机制和新建 skill 检查清单 - package.json 移除 @clawd/auth-runtime 依赖 - src/index.ts 改用 createSkillClient API Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> |
||
|---|---|---|
| .forgejo/workflows | ||
| scripts | ||
| src | ||
| .gitignore | ||
| README.md | ||
| SKILL.md | ||
| install.sh | ||
| package.json | ||
README.md
template-skill
新 skill 的基础模版。
认证机制:auth-cli.ts
每个 skill 内置一份 src/auth-cli.ts,它是一个薄 wrapper,通过 subprocess 调用 auth-runtime CLI(bun run ~/clawd/skills/auth-runtime/src/cli.ts)。
不使用 npm 依赖,避免了 git 包缓存导致的版本不一致问题。
工作原理
skill/src/index.ts
→ import { createSkillClient } from './auth-cli.ts'
→ auth-cli.ts 通过 spawnSync 调用 bun run cli.ts
→ auth-runtime/src/cli.ts 处理 token/session/request
使用方式
import { createSkillClient } from './auth-cli.ts';
const client = createSkillClient({
apiBase: process.env.API_BASE, // 可选
dryRun: false, // 可选,dry-run 模式返回模拟数据
});
// API 调用
const res = await client.post('/ecom/your/endpoint', { param: 'value' });
// res = { status: 200, body: '...' }
// 获取 session
const session = await client.session();
// session = { accessToken: '...', expiresIn: 900 }
前置条件
每台运行 skill 的机器上必须有 auth-runtime:
git clone http://192.168.0.108:3030/agent-skills/auth-runtime.git ~/clawd/skills/auth-runtime
install.sh 会检查此目录是否存在。
路径解析
默认路径:~/clawd/skills/auth-runtime
可通过环境变量覆盖:AUTH_RUNTIME_DIR=/custom/path bun run scripts/run.ts ...
新建 skill 检查清单
- 从此模版创建仓库
- 确认
src/auth-cli.ts已包含(直接从模版继承) src/index.ts中import { createSkillClient } from './auth-cli.ts'package.json中 不要 添加@clawd/auth-runtime依赖install.sh中包含 auth-runtime 目录检查