Adapters for every AI tool from one source, tests and CI
- tools/gen-adapters.ts writes the Claude Code plugin + .mcp.json, Codex plugin, Gemini CLI extension + GEMINI.md, AGENTS.md, Copilot instructions and a Cursor rule from skills/ and docs/agents-core.md; --check fails on stale files - tests for adapters, MCP tools and JSON-RPC, validate rules, ASO, release notes, privacy manifest, release helpers, install merging, scrub - bun run ci: adapters check, tests, typecheck, secrets / personal data scrub - 0.2.0
This commit is contained in:
parent
f2e29fd748
commit
1d7b178119
14 changed files with 950 additions and 16 deletions
17
tools/ci.ts
Normal file
17
tools/ci.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bun
|
||||
// Everything CI runs, in order; stops at the first failure. bun run ci
|
||||
const steps: [string, string[]][] = [
|
||||
['adapters', ['bun', 'tools/gen-adapters.ts', '--check']],
|
||||
['tests', ['bun', 'test']],
|
||||
['typecheck', ['bunx', 'tsc', '--noEmit']],
|
||||
['scrub', ['bun', 'tools/scrub.ts']],
|
||||
];
|
||||
const root = new URL('..', import.meta.url).pathname;
|
||||
for (const [name, cmd] of steps) {
|
||||
const t = Date.now();
|
||||
console.log(`\n== ${name}: ${cmd.join(' ')}`);
|
||||
const r = Bun.spawnSync(cmd, { cwd: root, stdout: 'inherit', stderr: 'inherit' });
|
||||
if (r.exitCode !== 0) { console.error(`\nci: ${name} failed (exit ${r.exitCode})`); process.exit(1); }
|
||||
console.log(`== ${name} ok (${((Date.now() - t) / 1000).toFixed(1)}s)`);
|
||||
}
|
||||
console.log('\nci: all green');
|
||||
122
tools/gen-adapters.ts
Normal file
122
tools/gen-adapters.ts
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
#!/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 = 'Ship mobile games to Google Play and the App Store: store listings, in-app products, data safety, screenshots, icons, release management and review checklists, as Agent Skills plus a Bun CLI and MCP server (storebound). 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: 'Ship mobile games to Google Play and the App Store: skills for every store step 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');
|
||||
}
|
||||
56
tools/scrub.ts
Normal file
56
tools/scrub.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env bun
|
||||
// Secrets / personal data scrub over every tracked (and staged-new) text file. Fails on any hit.
|
||||
// bun tools/scrub.ts
|
||||
// Patterns are built from parts so this file does not match itself.
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
export interface Rule { id: string; re: RegExp; files?: RegExp; allow?: (m: string, line: string) => boolean; wholeFile?: boolean }
|
||||
|
||||
const at = '@';
|
||||
export const RULES: Rule[] = [
|
||||
{ id: 'email', re: new RegExp(`[A-Za-z0-9._%+-]+${at}[A-Za-z0-9.-]+\\.[A-Za-z]{2,}`, 'g'),
|
||||
allow: m => /@example\.(com|org|net)$/i.test(m) || /@users\.noreply\./.test(m) },
|
||||
{ id: 'private-key', re: new RegExp('-----BEGIN [A-Z ]*PRIVATE ' + 'KEY-----\\s*[A-Za-z0-9+/=]{20,}', 'g'), wholeFile: true },
|
||||
{ id: 'private_key-json', re: new RegExp('"private' + '_key"\\s*:\\s*"-----BEGIN', 'g') },
|
||||
{ id: 'asc-key-file', re: new RegExp('AuthKey' + '_[A-Z0-9]{10}\\.p8', 'g') },
|
||||
{ id: 'apple-id-like', re: /\b(?=[A-Z0-9]{10}\b)(?=[A-Z0-9]*\d)(?=[A-Z0-9]*[A-Z])[A-Z0-9]{10}\b/g,
|
||||
files: /^(templates\/|.*\.config\.(ts|js|json)$|.*\.json$|.*\.toml$|.*\.plist$)/ },
|
||||
{ id: 'issuer-uuid', re: /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/g,
|
||||
allow: m => /^0{8}-0{4}-0{4}-0{4}-0{12}$/.test(m) },
|
||||
{ id: 'ip-address', re: /(?<![\w.\-]|[A-Za-z]\/)(?:\d{1,3}\.){3}\d{1,3}(?![\w.\-])/g, allow: m => ['127.0.0.1', '0.0.0.0'].includes(m) },
|
||||
{ id: 'private-name', re: new RegExp(['Yon', 'ga'].join(''), 'gi') },
|
||||
{ id: 'google-api-key', re: new RegExp('AI' + 'za[0-9A-Za-z_-]{35}', 'g') },
|
||||
];
|
||||
|
||||
const SKIP = /(^|\/)(bun\.lock|LICENSE)$|\.(png|jpe?g|webp|gif|ico|woff2?|ttf|otf|p8|p12|aab|ipa|zip)$/i;
|
||||
|
||||
export function scan(files: { path: string; text: string }[]): { file: string; line: number; rule: string; match: string }[] {
|
||||
const hits: { file: string; line: number; rule: string; match: string }[] = [];
|
||||
for (const f of files) {
|
||||
if (SKIP.test(f.path)) continue;
|
||||
const lines = f.text.split('\n');
|
||||
for (const r of RULES) {
|
||||
if (r.files && !r.files.test(f.path)) continue;
|
||||
if (r.wholeFile) {
|
||||
for (const m of f.text.matchAll(r.re)) hits.push({ file: f.path, line: f.text.slice(0, m.index).split('\n').length, rule: r.id, match: m[0] });
|
||||
continue;
|
||||
}
|
||||
lines.forEach((line, i) => {
|
||||
for (const m of line.matchAll(r.re)) if (!r.allow?.(m[0], line)) hits.push({ file: f.path, line: i + 1, rule: r.id, match: m[0] });
|
||||
});
|
||||
}
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
const root = join(import.meta.dir, '..');
|
||||
const ls = Bun.spawnSync(['git', 'ls-files', '--cached', '--others', '--exclude-standard'], { cwd: root });
|
||||
const paths = ls.stdout.toString().split('\n').filter(Boolean);
|
||||
const files = paths.flatMap(p => { try { return [{ path: p, text: readFileSync(join(root, p), 'utf8') }]; } catch { return []; } });
|
||||
const hits = scan(files);
|
||||
for (const h of hits) console.error(`${h.file}:${h.line} ${h.rule} ${h.match.slice(0, 60)}`);
|
||||
console.log(`scrub: ${files.length} files, ${hits.length} hits`);
|
||||
if (hits.length) process.exit(1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue