Files
pm-claude-skills/action/run.mjs
T
mohitagw15856 51bf4be52f AI-powered tooling: GitHub Action, generate command, evals + leaderboard (#41)
Three features riding 2026 trends (agentic CI, codegen, evals), sharing one
dependency-free Anthropic client (bin/lib/anthropic.mjs).

1. GitHub Action (action/) — run any skill in a consumer repo's CI:
   uses: mohitagw15856/pm-claude-skills/action@main. Composite action +
   run.mjs (loads the bundled SKILL.md, calls the API, exposes result as a
   step output / file). Docs with auto-PR-description example.

2. generate command — `npx pm-claude-skills generate --from <url|file>` turns
   a team's docs into a SKILL.md following the authoring standard
   (bin/generate.mjs, wired into the CLI; needs ANTHROPIC_API_KEY).

3. Skill evals + Leaderboard — evals/run-evals.mjs runs each case across models
   and scores output with an LLM judge (structure/completeness/usefulness/
   grounding); scripts/build-leaderboard.mjs renders web/leaderboard.html
   (built in the Pages deploy, falls back to clearly-labelled example data).
   Linked from README, catalog, and playground.

Offline-testable parts verified (prompt building, skill loading, graceful
errors, leaderboard render). SkillCheck/audit/exports all green.


Claude-Session: https://claude.ai/code/session_016JWn5jRD5tcEFKrubjQ6Px

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-18 08:37:40 +01:00

59 lines
2.8 KiB
JavaScript

#!/usr/bin/env node
// Runner for the pm-skills GitHub Action. Loads a bundled SKILL.md, runs it on
// the provided input via the Anthropic API, and exposes the result as a step
// output (and optionally a file). Inputs arrive as INPUT_* env vars.
import { readFileSync, existsSync, writeFileSync, appendFileSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { complete, parseSkill } from '../bin/lib/anthropic.mjs';
const ACTION_DIR = dirname(fileURLToPath(import.meta.url));
const REPO_ROOT = join(ACTION_DIR, '..');
const inp = (name, def = '') => (process.env[`INPUT_${name.toUpperCase()}`] ?? def).trim();
// Pure: assemble the system prompt + user message for a skill run (testable offline).
export function buildRequest(skillBody, userInput) {
const system = skillBody +
'\n\n---\nExecute this skill now on the input below and produce the complete output. ' +
'Do not ask follow-up questions — work with what is given and note any reasonable assumptions. ' +
'Output only the finished artifact (no preamble).';
return { system, messages: [{ role: 'user', content: userInput }] };
}
async function main() {
const skill = inp('skill');
if (!skill) throw new Error('Input `skill` is required.');
const apiKey = inp('api_key') || process.env.ANTHROPIC_API_KEY || '';
const model = inp('model', 'claude-sonnet-4-6');
const maxTokens = parseInt(inp('max_tokens', '4096'), 10) || 4096;
let input = inp('input');
const inputFile = inp('input_file');
if (!input && inputFile && existsSync(inputFile)) input = readFileSync(inputFile, 'utf8');
if (!input) throw new Error('Provide `input` or `input_file`.');
const skillFile = join(REPO_ROOT, 'skills', skill, 'SKILL.md');
if (!existsSync(skillFile)) throw new Error(`Unknown skill "${skill}" (no skills/${skill}/SKILL.md).`);
const { body } = parseSkill(readFileSync(skillFile, 'utf8'));
const { system, messages } = buildRequest(body, input);
console.log(`Running skill "${skill}" with ${model}…`);
const result = await complete({ apiKey, model, system, messages, maxTokens });
// Step output (multiline-safe heredoc) + optional file.
if (process.env.GITHUB_OUTPUT) {
const d = `EOF_${Math.random().toString(36).slice(2)}`;
appendFileSync(process.env.GITHUB_OUTPUT, `result<<${d}\n${result}\n${d}\n`);
}
const outFile = inp('output_file');
if (outFile) { writeFileSync(outFile, result + '\n'); console.log(`Wrote ${outFile}`); }
console.log('\n----- skill output -----\n' + result);
}
// Run only when executed directly (so tests can import buildRequest).
if (import.meta.url === pathToFileURL(process.argv[1] || '').href) {
main().catch((e) => { console.error(`Error: ${e.message}`); process.exit(1); });
}