storebound/tools/gen-adapters.ts

122 lines
8.2 KiB
TypeScript

#!/usr/bin/env bun
// Generates every AI-tool adapter from the single sources: skills/*/SKILL.md, docs/agents-core.md, package.json.
// bun tools/gen-adapters.ts write the files
// bun tools/gen-adapters.ts --check exit 1 when a committed file is stale (CI)
// Outputs are committed so each tool works straight from a git checkout.
import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
import { dirname, join } from 'node:path';
export interface Skill { name: string; description: string }
const NAME_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
/** Frontmatter of one SKILL.md, checked against the Agent Skills spec subset we use (name + description only). */
export function parseSkill(folder: string, text: string): Skill {
const m = /^---\n([\s\S]*?)\n---\n/.exec(text);
if (!m) throw new Error(`skills/${folder}/SKILL.md: no frontmatter`);
const fields: Record<string, string> = {};
for (const line of m[1]!.split('\n')) {
const kv = /^([A-Za-z-]+):\s*(.*)$/.exec(line);
if (!kv) throw new Error(`skills/${folder}/SKILL.md: frontmatter line "${line.slice(0, 40)}" is not "key: value" on one line`);
fields[kv[1]!] = kv[2]!.trim();
}
const extra = Object.keys(fields).filter(k => k !== 'name' && k !== 'description');
if (extra.length) throw new Error(`skills/${folder}/SKILL.md: only name + description allowed in frontmatter (found ${extra.join(', ')})`);
const { name = '', description = '' } = fields;
if (!NAME_RE.test(name) || name.length > 64) throw new Error(`skills/${folder}/SKILL.md: name "${name}" must be lowercase-hyphen, max 64`);
if (name !== folder) throw new Error(`skills/${folder}/SKILL.md: name "${name}" must equal the folder name`);
if (!description || description.length > 1024) throw new Error(`skills/${folder}/SKILL.md: description must be 1-1024 characters`);
return { name, description };
}
export function readSkills(root: string): Skill[] {
const dir = join(root, 'skills');
return readdirSync(dir).filter(n => existsSync(join(dir, n, 'SKILL.md'))).sort()
.map(n => parseSkill(n, readFileSync(join(dir, n, 'SKILL.md'), 'utf8')));
}
const json = (o: unknown) => JSON.stringify(o, null, 2) + '\n';
/** First sentence-ish part of a skill description for compact indexes. */
const short = (d: string) => d.split(' - ')[0]!.split('. Use when')[0]!.replace(/\.$/, '');
/** Every generated file: path -> content. Pure apart from reading the sources. */
export function generate(root: string): Map<string, string> {
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as { version: string; description: string; license: string; keywords: string[] };
const core = readFileSync(join(root, 'docs', 'agents-core.md'), 'utf8').trim();
const coreBody = core.replace(/^# .*\n+/, '');
const skills = readSkills(root);
const out = new Map<string, string>();
const homepage = 'https://git.crt.fyi/CRT/storebound';
const repository = 'https://git.crt.fyi/CRT/storebound.git';
const description = 'From nothing to Submit for review on Google Play and the App Store: app records, listings in every language, in-app products with regional prices, every questionnaire (Data safety, IARC, target audience, ads, App Privacy, age rating, export compliance), privacy, icons, screenshots and previews, validate, release management. Agent Skills plus a Bun CLI and MCP server (storebound); you press Submit. CRTkafa\'s own toolchain, open-sourced.';
const keywords = ['google-play', 'app-store', 'app-store-connect', 'mobile-games', 'iap', 'screenshots', 'app-icons', 'release', 'aso', 'mcp'];
// 1. Claude Code plugin + its MCP server + marketplace
out.set('.claude-plugin/plugin.json', json({ name: 'storebound', version: pkg.version, description, author: { name: 'CRTkafa' }, homepage, repository, license: pkg.license, keywords }));
out.set('.mcp.json', json({ mcpServers: { storebound: { command: '${CLAUDE_PLUGIN_ROOT}/bin/storebound', args: ['mcp'] } } }));
out.set('.claude-plugin/marketplace.json', json({ name: 'crtkafa', description: 'CRTkafa\'s open-sourced tools.', owner: { name: 'CRTkafa' },
plugins: [{ name: 'storebound', source: '.', description: 'Take a mobile game from nothing to Submit for review on both stores: skills for every store step and questionnaire plus the storebound CLI and MCP server.',
version: pkg.version, category: 'development', tags: ['mobile', 'google-play', 'app-store', 'release'] }] }));
// 2. OpenAI Codex plugin (skills; MCP via `storebound install --agent codex`)
out.set('.codex-plugin/plugin.json', json({ name: 'storebound', version: pkg.version, description, author: { name: 'CRTkafa' }, homepage, repository, license: pkg.license, keywords, skills: './skills/' }));
// 3. Gemini CLI extension
out.set('gemini-extension.json', json({ name: 'storebound', version: pkg.version, description, contextFileName: 'GEMINI.md',
mcpServers: { storebound: { command: '${extensionPath}${/}bin${/}storebound', args: ['mcp'] } } }));
const index = skills.map(s => `| \`${s.name}\` | ${short(s.description)} |`).join('\n');
const indexPaths = skills.map(s => `- \`skills/${s.name}/SKILL.md\`: ${short(s.description)}`).join('\n');
const generated = '<!-- generated by tools/gen-adapters.ts from docs/agents-core.md and skills/*/SKILL.md; do not edit -->';
const cli = [
'## Tools',
'',
'- CLI: `storebound <command>` (`storebound help`); config `storebound.config.ts`, credentials in env or `.storebound/`.',
'- MCP: `storebound mcp` (stdio). Write tools default to `dry_run: true`; submit / release / cancel / delete are not exposed.',
'- Readiness: `storebound check` (offline), `storebound validate` (read-only, both stores).',
].join('\n');
// 4. AGENTS.md (Codex, Cursor, Copilot, Windsurf, OpenCode, ...)
out.set('AGENTS.md', [generated, '', '# storebound', '',
'Toolchain for shipping mobile games to Google Play and the App Store. Before a store task, open the matching skill',
'file below and follow it step by step.', '', coreBody.replace(/^/, ''), '', cli, '', '## Skills', '', indexPaths, '',
'## Working on storebound itself', '',
'- Bun + TypeScript strict, zero runtime dependencies. `bun run ci` must pass (adapters fresh, tests, typecheck, scrub).',
'- Skills are the single source: edit `skills/*/SKILL.md` or `docs/agents-core.md`, then `bun tools/gen-adapters.ts`.',
'- Never commit credentials, account / team / issuer / key / app ids or personal data; placeholders use example.com.',
''].join('\n'));
// 5. GitHub Copilot repository instructions
out.set('.github/copilot-instructions.md', [generated, '', '# storebound for GitHub Copilot', '',
'Mobile game store releases (Google Play, App Store). Skills live in `skills/<name>/SKILL.md` (Agent Skills format;',
'`storebound install --agent copilot` copies them to `.github/skills/` of a game project).', '', coreBody, '', cli, '', '## Skills', '',
'| skill | for |', '|---|---|', index, ''].join('\n'));
// 6. Cursor project rule (agent-requested)
out.set('.cursor/rules/storebound.mdc', ['---',
'description: Shipping a mobile game to Google Play or the App Store with storebound (listings, IAPs, screenshots, releases, review, compliance)',
'alwaysApply: false', '---', '', generated, '', coreBody, '', cli, '', '## Skills', '', indexPaths, ''].join('\n'));
// 7. Gemini context file
out.set('GEMINI.md', [generated, '', '# storebound', '',
'This extension ships Agent Skills (skills/) and the storebound MCP server for mobile game store releases.', '',
coreBody, '', cli, '', '## Skills', '', '| skill | for |', '|---|---|', index, ''].join('\n'));
return out;
}
if (import.meta.main) {
const root = join(import.meta.dir, '..');
const check = process.argv.includes('--check');
const stale: string[] = [];
for (const [rel, text] of generate(root)) {
const p = join(root, rel);
const cur = existsSync(p) ? readFileSync(p, 'utf8') : null;
if (cur === text) continue;
if (check) { stale.push(rel); continue; }
mkdirSync(dirname(p), { recursive: true });
writeFileSync(p, text);
console.log(`wrote ${rel}`);
}
if (check && stale.length) { console.error(`stale adapters (run bun tools/gen-adapters.ts): ${stale.join(', ')}`); process.exit(1); }
if (check) console.log('adapters up to date');
}