|
| 1 | +/** |
| 2 | + * AgentKit Forge — propose-skill |
| 3 | + * |
| 4 | + * Promotes a local skill from .agents/skills/<name>/ to org-meta/skills/<name>/ |
| 5 | + * by creating a branch and copying the SKILL.md file. |
| 6 | + * |
| 7 | + * Usage: |
| 8 | + * node propose-skill.mjs <skill-name> |
| 9 | + * pnpm ak:propose-skill <skill-name> |
| 10 | + * |
| 11 | + * What it does: |
| 12 | + * 1. Reads the skill from {projectRoot}/.agents/skills/<name>/SKILL.md |
| 13 | + * 2. Resolves the org-meta path (ORG_META_PATH env var or ~/repos/org-meta) |
| 14 | + * 3. Creates a new git branch: feat/propose-skill-<name> |
| 15 | + * 4. Copies the SKILL.md to org-meta/skills/<name>/SKILL.md |
| 16 | + * 5. Prints instructions for the next steps (commit, push, PR) |
| 17 | + */ |
| 18 | +import { execFileSync } from 'child_process'; |
| 19 | +import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'; |
| 20 | +import { dirname, join, resolve } from 'path'; |
| 21 | +import { fileURLToPath } from 'url'; |
| 22 | + |
| 23 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 24 | + |
| 25 | +// --------------------------------------------------------------------------- |
| 26 | +// Helpers |
| 27 | +// --------------------------------------------------------------------------- |
| 28 | + |
| 29 | +function log(msg) { |
| 30 | + process.stdout.write(msg + '\n'); |
| 31 | +} |
| 32 | + |
| 33 | +function err(msg) { |
| 34 | + process.stderr.write(`[propose-skill] Error: ${msg}\n`); |
| 35 | + process.exit(1); |
| 36 | +} |
| 37 | + |
| 38 | +function resolveOrgMetaPath() { |
| 39 | + return process.env.ORG_META_PATH |
| 40 | + ? resolve(process.env.ORG_META_PATH) |
| 41 | + : resolve(process.env.HOME || process.env.USERPROFILE || '~', 'repos', 'org-meta'); |
| 42 | +} |
| 43 | + |
| 44 | +// --------------------------------------------------------------------------- |
| 45 | +// Main |
| 46 | +// --------------------------------------------------------------------------- |
| 47 | + |
| 48 | +const skillName = process.argv[2]; |
| 49 | + |
| 50 | +if (!skillName || skillName.startsWith('-')) { |
| 51 | + log('Usage: pnpm ak:propose-skill <skill-name>'); |
| 52 | + log(''); |
| 53 | + log('Promotes a local skill from .agents/skills/<name>/ to org-meta/skills/<name>/.'); |
| 54 | + log('The skill must exist in the current repo and NOT already be in skills.yaml.'); |
| 55 | + process.exit(0); |
| 56 | +} |
| 57 | + |
| 58 | +const projectRoot = process.cwd(); |
| 59 | +const localSkillPath = join(projectRoot, '.agents', 'skills', skillName, 'SKILL.md'); |
| 60 | + |
| 61 | +if (!existsSync(localSkillPath)) { |
| 62 | + err(`Skill '${skillName}' not found at ${localSkillPath}`); |
| 63 | +} |
| 64 | + |
| 65 | +const orgMetaRoot = resolveOrgMetaPath(); |
| 66 | +if (!existsSync(orgMetaRoot)) { |
| 67 | + err(`org-meta not found at ${orgMetaRoot}. Set ORG_META_PATH env var to override.`); |
| 68 | +} |
| 69 | + |
| 70 | +const destDir = join(orgMetaRoot, 'skills', skillName); |
| 71 | +const destPath = join(destDir, 'SKILL.md'); |
| 72 | + |
| 73 | +if (existsSync(destPath)) { |
| 74 | + log(`[propose-skill] '${skillName}' already exists in org-meta at ${destPath}`); |
| 75 | + log('If you want to update it, edit the file directly and open a PR in org-meta.'); |
| 76 | + process.exit(0); |
| 77 | +} |
| 78 | + |
| 79 | +// Read the local skill content |
| 80 | +const content = readFileSync(localSkillPath, 'utf-8'); |
| 81 | + |
| 82 | +// Create branch in org-meta |
| 83 | +const branchName = `feat/propose-skill-${skillName}`; |
| 84 | +log(`[propose-skill] Creating branch '${branchName}' in org-meta...`); |
| 85 | +try { |
| 86 | + execFileSync('git', ['checkout', '-b', branchName], { cwd: orgMetaRoot, stdio: 'pipe' }); |
| 87 | +} catch (e) { |
| 88 | + err(`Failed to create branch: ${e?.message ?? e}`); |
| 89 | +} |
| 90 | + |
| 91 | +// Write the skill file |
| 92 | +mkdirSync(destDir, { recursive: true }); |
| 93 | +writeFileSync(destPath, content, 'utf-8'); |
| 94 | +log(`[propose-skill] Wrote ${destPath}`); |
| 95 | + |
| 96 | +// Print next steps |
| 97 | +log(''); |
| 98 | +log('Next steps:'); |
| 99 | +log(` cd ${orgMetaRoot}`); |
| 100 | +log(` git add skills/${skillName}/SKILL.md`); |
| 101 | +log(` git commit -m "feat(skills): propose ${skillName} from downstream repo"`); |
| 102 | +log(` git push -u origin ${branchName}`); |
| 103 | +log(' # Then open a PR against org-meta main'); |
| 104 | +log(''); |
| 105 | +log(`Once merged, add '${skillName}' to .agentkit/spec/skills.yaml with source: org-meta.`); |
0 commit comments