From 2c2c24a310e0e1cff1d9f11432aa07d0f6d034b4 Mon Sep 17 00:00:00 2001 From: ivanberry Date: Sat, 14 Mar 2026 10:35:01 +0800 Subject: [PATCH] feat: initial skill template --- .forgejo/workflows/register-skill-release.yml | 17 ++++++++ .gitignore | 4 ++ SKILL.md | 26 ++++++++++++ package.json | 12 ++++++ scripts/run.ts | 41 ++++++++++++++++++ src/index.ts | 42 +++++++++++++++++++ 6 files changed, 142 insertions(+) create mode 100644 .forgejo/workflows/register-skill-release.yml create mode 100644 .gitignore create mode 100644 SKILL.md create mode 100644 package.json create mode 100644 scripts/run.ts create mode 100644 src/index.ts diff --git a/.forgejo/workflows/register-skill-release.yml b/.forgejo/workflows/register-skill-release.yml new file mode 100644 index 0000000..c01abb1 --- /dev/null +++ b/.forgejo/workflows/register-skill-release.yml @@ -0,0 +1,17 @@ +name: register-skill-release + +on: + push: + tags: + - 'v*' + workflow_dispatch: + +jobs: + register: + runs-on: docker + steps: + - uses: actions/checkout@v4 + + - uses: http://192.168.0.108:3030/agent-skills/shared-actions/register-skill@main + with: + client_key: ${{ secrets.CLIENT_KEY }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8e0f41 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +dist/ +.env.local +*.skill diff --git a/SKILL.md b/SKILL.md new file mode 100644 index 0000000..e895188 --- /dev/null +++ b/SKILL.md @@ -0,0 +1,26 @@ +--- +name: my-skill +description: "TODO: describe what this skill does and when to use it." +--- + +# my-skill + +TODO: one-line description. + +> Auth (CLIENT_KEY) is loaded automatically from `~/.openclaw/.env`. + +## Run + +```bash +bun scripts/run.ts [args] [--dry-run] +``` + +## Commands + +| Command | Description | +|---------|-------------| +| `run ` | TODO: describe | + +## Output + +Returns JSON: `{ "status": "success" | "failed", "data": ... }` diff --git a/package.json b/package.json new file mode 100644 index 0000000..5fd4e73 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "my-skill", + "version": "0.1.0", + "type": "module", + "scripts": { + "run": "bun run scripts/run.ts", + "build": "bun build scripts/run.ts --outfile dist/run.js --target bun" + }, + "dependencies": { + "@clawd/auth-runtime": "git+http://192.168.0.108:3030/agent-skills/auth-runtime.git" + } +} diff --git a/scripts/run.ts b/scripts/run.ts new file mode 100644 index 0000000..f2dfab8 --- /dev/null +++ b/scripts/run.ts @@ -0,0 +1,41 @@ +#!/usr/bin/env bun +import type { Command } from '../src/index.ts'; +import { run } from '../src/index.ts'; + +function printUsage(): void { + console.error(`Usage: + bun scripts/run.ts [--api-base=] [args...] [--dry-run] + +Commands: + run + +Config: ~/.openclaw/.env (CLIENT_KEY, API_BASE) +`); +} + +async function main(): Promise { + const positionals: string[] = []; + let dryRun = false; + + for (const arg of process.argv.slice(2)) { + if (arg === '--dry-run') { + dryRun = true; + } else if (arg.startsWith('--api-base=')) { + process.env.API_BASE = arg.slice('--api-base='.length).trim(); + } else if (arg === '-h' || arg === '--help') { + printUsage(); process.exit(0); + } else { + positionals.push(arg); + } + } + + if (positionals.length < 1) { printUsage(); process.exit(1); } + + const result = await run(positionals[0] as Command, positionals.slice(1), dryRun); + console.log(JSON.stringify(result, null, 2)); +} + +main().catch((err) => { + console.error(JSON.stringify({ status: 'failed', error: err instanceof Error ? err.message : String(err) }, null, 2)); + process.exit(1); +}); diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..086be5f --- /dev/null +++ b/src/index.ts @@ -0,0 +1,42 @@ +import { + createEnvConfig, + requestApiWithAutoRefresh, + type ApiResponse, +} from '@clawd/auth-runtime'; + +export type Command = 'run'; // TODO: add your commands + +export interface RunResult { + status: 'success' | 'failed'; + command: Command; + dryRun: boolean; + data?: unknown; + error?: string; +} + +export async function run( + command: Command, + args: string[], + dryRun: boolean, +): Promise { + const config = createEnvConfig(); + const apiBase = (process.env.API_BASE ?? 'https://api-gw-test.yuanwei-lnc.com').replace(/\/$/, ''); + + if (command === 'run') { + const response: ApiResponse = await requestApiWithAutoRefresh( + 'POST', + `${apiBase}/your/endpoint`, + dryRun, + config, + JSON.stringify({ param: args[0] }), + ); + + if (response.status < 200 || response.status >= 300) { + return { status: 'failed', command, dryRun, error: `HTTP ${response.status}: ${response.body}` }; + } + + return { status: 'success', command, dryRun, data: JSON.parse(response.body) }; + } + + return { status: 'failed', command, dryRun, error: `unknown command: ${command}` }; +}