Skip to content

Node.js API ​

rolecraft exposes a programmatic API for use in your own Node.js scripts, tools, and CI pipelines. All API functions return plain objects with no side-effects.

Usage ​

js
import { install, list, search, doctor } from 'rolecraft'

// install a skill
const result = await install('./my-skill', { global: true })

// list installed skills
const skills = await list()

// search GitHub for skills
const results = await search('code-review')

// run health check
const health = await doctor()

Available Functions ​

install(source, options?) ​

Install a skill with security scan.

OptionTypeDefaultDescription
globalbooleanfalseInstall to ~/.agents/skills/
projectbooleantrueInstall to ./.agents/skills/
scopeobject{ project: true }Target scope object ({ project, global, [agentFlag]: true, ... }); overrides global/project
yesbooleanfalseBypass security prompts
dryRunbooleanfalsePreview only
symlinkbooleanfalseSymlink instead of copy
frozenLockfilebooleanfalseFail if already installed
noMcpbooleanfalseSkip MCP server installation
skillstring|string[]—Specific skill slug(s)

Returns { results: [{ name, slug, owner, security, install }], mcpResults?: [...] }.

rollback(slug, options?) ​

Restore a skill to its previous version from backup history. History is created automatically on update or re-install.

OptionTypeDefaultDescription
listbooleanfalseShow history without restoring
dryRunbooleanfalsePreview without restoring

Returns { slug, files, targets, prevContentSha }.

Or with list: true: { slug, currentVersion, history: [{ version, contentSha, installedAt }] }.

list(cwd?, options?) ​

List installed skills.

OptionTypeDefaultDescription
jsonbooleanfalseReturn structured data
agentstring—Filter skills by agent name (case-insensitive)

Returns { skills: { [slug]: { name, slug, owner, description, source, sourceType, scope, installedAt, contentSha, ... } }, total: number, globals: number, projects: number, agent?: string }.

remove(slug, options?) ​

Uninstall a skill.

OptionTypeDefaultDescription
dryRunbooleanfalsePreview only

Returns { removed: [...], targets: [...] }.

update(slug, options?) ​

Re-install a skill from its original source.

OptionTypeDefaultDescription
dryRunbooleanfalsePreview only

Returns { slug, source, updated: boolean }.

check(options?) ​

Check installed skills for available updates.

Returns { skills: [{ slug, status: 'update_available'|'up_to_date'|'error', current?, latest?, source?, fromRegistry?, oldHash?, newHash?, hash?, reason? }], updatesAvailable: number, total: number }.

verify(options?) ​

Verify SHA256 content hashes of installed skills.

Returns { verified: [...], failed: [...] }.

ci(options?) ​

Re-install all skills and MCP servers from lockfile.

Takes no options. Non-interactive by design — installs everything from the lockfile.

Returns { installed: [{ slug, name, scope }], failed: [{ slug, reason }], skillCount, mcpCount, total, allPassed, mcpInstalled: [{ name, agents }], mcpFailed: [{ name, reason }] }.

search(query, options?) ​

Search for skills on GitHub or skills.sh.

OptionTypeDefaultDescription
skillsShbooleanfalseSearch skills.sh instead of GitHub
interactivebooleanfalseEnable TUI picker

Returns { results: [{ full_name, description, stargazers_count, language }], source: 'github'|'skills.sh' }.

doctor(options?) ​

Run system health check.

OptionTypeDefaultDescription
jsonbooleanfalseReturn structured data
networkbooleanfalseInclude GitHub connectivity test
deepbooleanfalseRun conflict detection across all installed skills

Returns { status, checks: [...], summary: { passed, warnings, errors, total }, agents, mcp, skills, conflicts }.

When deep: true, the conflicts array contains objects shaped as { a, b, sections: [{ heading, a, b }] } where a and b are conflicting skill slugs and each section lists up to 3 differing lines from each skill.

use(source, options?) ​

Preview a skill's files without installing.

Returns { name, slug, files: [...], targets: [...] }.

resolve(source) ​

Resolve a source string to its metadata. Returns { slug, name, files, contentSha, ... }.

resolveSkills(source) ​

Resolve a source string and discover all skills within it (including multi-skill repos). Used internally by install, use, and setup.

Returns [{ slug, name, description, owner, files, sourcePath, sourceType, content }].

diff(skillA, skillB, options?) ​

Section-aware comparison of two SKILL.md files.

OptionTypeDefaultDescription
jsonbooleanfalseReturn structured JSON
briefbooleanfalseShow only summary of changes
noColorbooleanfalseDisable colored output

Returns { a, b, frontmatter, sections: [{ heading, status, added, removed }], stats }.

compose(sources, options?) ​

Merge or chain multiple SKILL.md files into one.

OptionTypeDefaultDescription
modestring'merge''merge' (dedup lines) or 'chain' (override)
namestring—Output skill name
jsonbooleanfalseReturn structured JSON
noColorbooleanfalseDisable colored output

Returns { content, stats: { sources, totalInputSections, totalOutputSections, mergedSections, frontmatterFields } }.

test(skillPath, options?) ​

Run quality assertions against a SKILL.md file.

OptionTypeDefaultDescription
allbooleanfalseTest all installed skills
jsonbooleanfalseReturn structured JSON
verbosebooleanfalseShow detailed results
noColorbooleanfalseDisable colored output
noEmojibooleanfalseUse ASCII fallback for emojis
minScorenumber0Fail if score is below threshold
onlystring|string[]—Run specific checks by name

Returns { skill, score, grade, label, assertions: [...], suggestions: [...] }. With --all, returns { results: [...], summary: { total, passed, failed, skipped } }.

mcpInstall(source, options?) ​

Install an MCP server.

OptionTypeDefaultDescription
namestring—Override the server name
yesbooleanfalseSkip confirmation and security blocks
dryRunbooleanfalsePreview without making changes

Returns { name, source, resolved: { command, args }, results: [{ agent, name, success }], scanResult }.

mcpList(options?) ​

List all installed MCP servers.

Returns { servers: [{ agent, name, command, args }], total: number }.

mcpUpdate(name, options?) ​

Update an MCP server.

OptionTypeDefaultDescription
namestring—Server name override
yesbooleanfalseSkip confirmation
dryRunbooleanfalsePreview without making changes

Returns { name, source, resolved: { command, args }, results: [{ agent, name, success }] }.

mcpRemove(name, options?) ​

Remove an MCP server.

OptionTypeDefaultDescription
dryRunbooleanfalsePreview only

Returns { name, results: [{ agent, name, success }] }.

mcpCheck(options?) ​

Check MCP server health.

Returns { servers: [{ agent, name, currentVersion, latestVersion, hasUpdate }], updatesAvailable: number, total: number }.

mcpSearch(query, options?) ​

Search for MCP servers on npm or GitHub.

OptionTypeDefaultDescription
npmbooleanfalseSearch npm registry instead of GitHub
interactivebooleanfalseEnable TUI picker

Returns { results: [{ name, description, source, stars }], source: 'npm'|'github', total: number }.

profileSave(name, options?) ​

Save current agent configuration as a profile. Returns { name, agents: number, profile: { name, description, agents } }.

profileApply(name, options?) ​

Apply a saved profile.

OptionTypeDefaultDescription
dryRunbooleanfalsePreview only
skipMcpbooleanfalseSkip MCP configuration
skipSkillsbooleanfalseSkip skill installation
yesbooleanfalseNon-interactive mode

Returns { agents: [...], mcp: [...], skills: [...] }.

profileDiff(name) ​

Compare current config against a saved profile. Returns { added: [...], removed: [...], changed: [...] }.

profileList() ​

List all saved profiles. Returns { profiles: [...] }.

profileShow(name) ​

Show profile details. Returns { name, agents: {...}, createdAt, updatedAt }.

profileDelete(name) ​

Delete a saved profile. Returns { deleted: true }.

profileImport(source) ​

Import a profile from file or URL. Returns { name, agents: number }.

setup(source, options?) ​

Detect agents and optionally install a skill to all detected agents.

OptionTypeDefaultDescription
yesbooleanfalseInstall all skills without prompt
dryRunbooleanfalsePreview only
listbooleanfalseList available skills without installing
skillstring|string[]—Install specific skills by name
candidatesbooleanfalseReturn the resolved skills without selecting or installing

Returns { agents: [{ flag, label }], installed?: [{ name, slug, owner, files, results, mcpServers }] }. With list: true, returns { agents, skills: [{ name, slug, owner, description, files }] }. With candidates: true, returns { agents, candidates: [{ name, slug, description }] } and writes nothing — read the list, then call again with skill to install a choice.

bundle(sources, options?) ​

Install multiple skills from inline sources or a bundle file.

OptionTypeDefaultDescription
dryRunbooleanfalsePreview only
noMcpbooleanfalseSkip MCP server installation

Returns { installed: number, failed: number, results: [{ source, status, error? }] }.

watch(slug?, cwd?, options?) ​

Watch installed local skills for file changes and auto-sync.

OptionTypeDefaultDescription
dryRunbooleanfalsePreview only
onEvent(event) => voidnoneCalled for setup and sync events (see below)

Returns { watchers: FSWatcher[], skills: string[], installedCount: number, close: () => void }. Call close() to cancel pending syncs and close every watcher; it is safe to call more than once. With dryRun, returns { dryRun: true, skills: [{ slug, source, path }] } instead.

Throws a UserError with code WATCH_SKILL_NOT_FOUND when slug is not installed.

onEvent receives objects with a type field:

typeExtra fieldsWhen
startslugsBefore watchers are set up
skipslug, sourceTypeA non-local skill was requested
watchingslug, pathA watcher started
errorslug, path, errorA watcher could not start, or reported an error later
syncingslug, filename, startedAtA change triggered a re-install
syncedslug, ok, startedAtThe re-install finished (ok: false on failure)

convert(source, options?) ​

Convert skills bidirectionally between rolecraft's SKILL.md format and Cursor/Claude Code's .mdc rule format. Programmatic implementation is in src/api/convert.js.

OptionTypeDefaultDescription
dryRunbooleanfalsePreview conversion plan without writing files or creating directories
outputstringprocess.cwd()Target output directory (created recursively if missing in write mode)

Return Value ​

convert() always returns an array of result objects (one per converted file), even when passed a single file path:

  • Write mode (dryRun: false): Returns [{ from: string, to: string, format: 'skill-to-mdc' | 'mdc-to-skill' }]. Files are written to disk.
  • Dry-run mode (dryRun: true): Returns [{ dryRun: true, from: string, to: string }]. Returns the planned destination paths without creating directories or writing any files to disk (format is omitted in dry-run mode).

Destination Path Resolution ​

The destination filename is determined by the input format:

  • SKILL.md → .mdc (skill-to-mdc): Destination filename is derived from the skill's frontmatter slug or name (${slug}.mdc, falling back to skill.mdc). Slashes in slugs are normalized to dashes.
  • .mdc → SKILL.md (mdc-to-skill): Destination filename is always SKILL.md inside the specified output directory (path.join(outDir, 'SKILL.md')).

Source Resolution and Format Detection ​

  1. Directories: convert() checks for SKILL.md first. If found, only that skill file is converted to .mdc. If no SKILL.md exists, it scans for all *.mdc files in the directory and converts each one to SKILL.md. If neither is found, it throws No SKILL.md or .mdc files found in <dir>.
  2. Single Files: If a file does not use the standard name SKILL.md or .mdc extension (e.g. rules.txt), convert() sniffs frontmatter keys: slug: detects a skill file, while alwaysApply: or globs: detects an MDC rule. If neither is found, it throws Cannot detect format.
  3. Empty Files: Throws Source is empty: <path>.

Example ​

js
import { convert } from 'rolecraft'

// Preview conversion plan without writing files
const plan = await convert('./rules/cursor-rule.mdc', {
  dryRun: true,
  output: './converted',
})

console.log(plan)
// [
//   {
//     dryRun: true,
//     from: '/path/to/rules/cursor-rule.mdc',
//     to: '/path/to/converted/SKILL.md',
//   }
// ]

// Execute the actual conversion
const results = await convert('./rules/cursor-rule.mdc', {
  output: './converted',
})

console.log(results)
// [
//   {
//     from: '/path/to/rules/cursor-rule.mdc',
//     to: '/path/to/converted/SKILL.md',
//     format: 'mdc-to-skill',
//   }
// ]

init(name?) ​

Scaffold a new SKILL.md file.

ParamTypeDescription
namestringSkill name or owner/name (default: my-skill)

Returns { path: string, slug: string, name: string, owner: string }.

upgrade(options?) ​

Check for rolecraft updates and upgrade.

OptionTypeDefaultDescription
dryRunbooleanfalseCheck without upgrading

Returns { current: string, latest: string|null, isUpToDate: boolean|null, upgraded?: boolean, version?: string }.

completions(shell) ​

Generate shell completion script.

ParamTypeDescription
shellstring'bash', 'zsh', or 'fish'

Returns the completion script as a string.

agentsXml(writeToFile?) ​

Generate a <skills_system> XML block listing installed skills.

ParamTypeDefaultDescription
writeToFilebooleanfalseWrite or replace XML section in ./AGENTS.md

Returns { xml: string, written: boolean, path?: string }.

compareVersions(a, b) ​

Compare two semver version strings. Returns negative, zero, or positive number.

See also ​

  • CLI Reference — every command with all flags on one page.
  • Commands — each command grouped by what you are trying to do.
  • Architecture — how rolecraft is put together under the hood.