/** * Copy the bundled excaliplant skill (or a rule-file variant of it) to the * place a given tool reads it from. All file-system access goes through the * caller's `io` object, and nothing is ever written outside the target folder. * @module skills/install */ export type SkillsIo = { /** * Read a UTF-8 text file. */ readFile: (file: string) => Promise; /** * Write a UTF-8 text file. */ writeFile: (file: string, data: string) => Promise; mkdir: (dir: string, options: { recursive: true; }) => Promise; exists: (file: string) => Promise; homedir: () => string; cwd: () => string; stdout: { write: (text: string) => unknown; }; stderr: { write: (text: string) => unknown; }; /** * Folder of the packaged skills (defaults to the package's `skills/`). */ skillsRoot?: string; }; export type Bundle = { /** * Package version substituted for `{{version}}`. */ version: string; /** * Skill files, paths relative to the skill folder. */ files: { path: string; content: string; }[]; /** * Rule text shared by the rule-file targets. */ rules: string; }; export type InstallOptions = { /** * Tool ids, `all` or `rules`. */ tools: string[]; /** * Default `project`. */ scope?: "project" | "user"; /** * Install below this folder instead of the tool's own location. */ dir?: string; /** * Overwrite existing files. */ force?: boolean; /** * Only report what would be written. */ dryRun?: boolean; }; export type InstallResult = { /** * Tool id. */ tool: string; kind: "skill" | "rule"; /** * Skill folder or rule file. */ root: string; status: "installed" | "would-install" | "exists"; /** * Absolute paths written (or planned). */ files: string[]; }; /** * File-system and console access for the skills commands. * @typedef {object} SkillsIo * @property {(file: string) => Promise} readFile Read a UTF-8 text file. * @property {(file: string, data: string) => Promise} writeFile Write a UTF-8 text file. * @property {(dir: string, options: { recursive: true }) => Promise} mkdir * @property {(file: string) => Promise} exists * @property {() => string} homedir * @property {() => string} cwd * @property {{ write: (text: string) => unknown }} stdout * @property {{ write: (text: string) => unknown }} stderr * @property {string} [skillsRoot] Folder of the packaged skills (defaults to the package's `skills/`). */ /** * The packaged skill, read once. * @typedef {object} Bundle * @property {string} version Package version substituted for `{{version}}`. * @property {{ path: string, content: string }[]} files Skill files, paths relative to the skill folder. * @property {string} rules Rule text shared by the rule-file targets. */ /** * @typedef {object} InstallOptions * @property {string[]} tools Tool ids, `all` or `rules`. * @property {"project" | "user"} [scope] Default `project`. * @property {string} [dir] Install below this folder instead of the tool's own location. * @property {boolean} [force] Overwrite existing files. * @property {boolean} [dryRun] Only report what would be written. */ /** * @typedef {object} InstallResult * @property {string} tool Tool id. * @property {"skill" | "rule"} kind * @property {string} root Skill folder or rule file. * @property {"installed" | "would-install" | "exists"} status * @property {string[]} files Absolute paths written (or planned). */ /** Thrown for problems the user can fix (bad flag, unknown tool, existing files). */ export declare class SkillsUsageError extends Error { } /** * Whether `rel` is a plain relative path with forward slashes and no `.`/`..` * segments, so joining it below a folder cannot leave that folder. * @param {unknown} rel * @returns {boolean} */ export declare function isSafeRelativePath(rel: unknown): boolean; /** * @param {string} root * @param {string} candidate * @returns {boolean} True when `candidate` is strictly inside `root`. */ export declare function isInside(root: string, candidate: string): boolean; /** * Read the packaged skill through `io`. * @param {SkillsIo} io * @param {string} root Folder that contains `manifest.json` and the skill folder. * @returns {Promise} */ export declare function loadBundle(io: SkillsIo, root: string): Promise; /** * Turn `--tool` values into target ids, expanding `all` and `rules`. * @param {string[]} tools * @returns {string[]} */ export declare function expandTools(tools: string[]): string[]; /** * Work out where everything goes without touching the file system. * @param {InstallOptions} options * @param {SkillsIo} io * @param {Bundle} bundle * @returns {{ tool: string, kind: "skill" | "rule", root: string, files: { path: string, content: string }[] }[]} */ export declare function planInstall(options: InstallOptions, io: SkillsIo, bundle: Bundle): { tool: string; kind: "skill" | "rule"; root: string; files: { path: string; content: string; }[]; }[]; /** * Install the skill for the requested tools. * @param {InstallOptions} options * @param {SkillsIo} io * @param {Bundle} bundle * @returns {Promise} */ export declare function installSkills(options: InstallOptions, io: SkillsIo, bundle: Bundle): Promise;