mirror of
https://github.com/Fission-AI/OpenSpec.git
synced 2026-09-14 20:16:53 +08:00
46a4d78222
* feat(skills): publish workflow skills to skills.sh Commit the 12 OpenSpec workflow skills as static skills/<name>/SKILL.md so `npx skills add Fission-AI/OpenSpec` can install them (skills.sh reads static files from the repo; OpenSpec otherwise only generates skills at init time). Files are generated from the existing templates via `pnpm generate:skills`, not hand-copied, and skillssh-parity.test.ts fails CI if a template changes without regenerating. The volatile generatedBy frontmatter line is stripped so the committed copies stay byte-stable across releases. Closes #1258 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(skills): force LF on committed skills/ so Windows CI parity holds The skills.sh distribution files are generated LF-only and compared byte-for-byte by skillssh-parity.test.ts. Windows autocrlf checked them out as CRLF, failing the parity assertion. A scoped .gitattributes pins them to LF on checkout. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(skills): reject symlinks and assert the exact committed skill set Review feedback (alfred): the parity test only visited expected templates, so an extra or renamed skills/ directory shipped with green CI, and the generator would write through a pre-existing symlinked skill directory to anywhere on disk. - generator: refuse to run if skills/ contains any symlink (checked before any deletion, so a bad tree is left intact), validate dirNames against a path-segment allowlist, and lstat the target before writing. - parity test: assert skills/ holds exactly README.md plus one real directory per template, each containing a single real SKILL.md. - focused tests cover symlink refusal (no partial deletion), traversal names, and stale-directory cleanup. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(templates): abort archive on Cancel, honest summary, fence languages CodeRabbit review on #1357, fixed at the template source and regenerated: - archive-change: choosing "Cancel" at the sync prompt now stops the flow instead of archiving anyway (skill + command templates). - archive-change skill: the success output no longer hardcodes "All artifacts complete. All tasks complete." when archiving incomplete work. - archive/bulk-archive/sync-specs/verify-change: language identifiers on previously plain code fences (MD040), skill and command twins alike. Golden hashes in skill-templates-parity.test.ts recomputed from dist/; skills/ regenerated via pnpm generate:skills. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
61 lines
2.3 KiB
JavaScript
61 lines
2.3 KiB
JavaScript
/**
|
|
* Shared helpers for the skills.sh distribution generator and its parity test.
|
|
*/
|
|
|
|
import { lstatSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
/** Directory (repo-relative) that skills.sh scans for `SKILL.md` files. */
|
|
export const SKILLS_DIR = 'skills';
|
|
|
|
/**
|
|
* Drop the per-release `generatedBy` frontmatter line so the committed
|
|
* skills.sh copies stay byte-stable across OpenSpec version bumps. The line is
|
|
* meaningful only for skills that `openspec init` writes into a project; in the
|
|
* standalone distribution it would just churn the files on every release.
|
|
*/
|
|
export function stripVolatileFrontmatter(content) {
|
|
return content.replace(/^ {2}generatedBy: .*\n/m, '');
|
|
}
|
|
|
|
/**
|
|
* Remove existing skill subdirectories (clears any renamed/removed skills)
|
|
* while preserving top-level files like README.md. Refuses to run if the tree
|
|
* contains a symlink: deleting one would only unlink it, and a symlinked skill
|
|
* directory would otherwise let later writes land outside the repo.
|
|
*/
|
|
export function cleanSkillSubdirectories(outDir) {
|
|
mkdirSync(outDir, { recursive: true });
|
|
const entries = readdirSync(outDir, { withFileTypes: true });
|
|
// Reject before deleting anything so a bad tree is left fully intact.
|
|
for (const entry of entries) {
|
|
if (entry.isSymbolicLink()) {
|
|
throw new Error(
|
|
`Refusing to generate: ${join(outDir, entry.name)} is a symlink. Remove it and re-run.`
|
|
);
|
|
}
|
|
}
|
|
for (const entry of entries) {
|
|
if (entry.isDirectory()) {
|
|
rmSync(join(outDir, entry.name), { recursive: true, force: true });
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create `<outDir>/<dirName>` and return its path, guaranteeing the write
|
|
* target is a real directory contained in outDir — never a path-traversing
|
|
* name and never a symlink that would redirect the write elsewhere.
|
|
*/
|
|
export function prepareSkillDirectory(outDir, dirName) {
|
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(dirName)) {
|
|
throw new Error(`Refusing to generate: unsafe skill directory name ${JSON.stringify(dirName)}`);
|
|
}
|
|
const skillDir = join(outDir, dirName);
|
|
mkdirSync(skillDir, { recursive: true });
|
|
if (!lstatSync(skillDir).isDirectory()) {
|
|
throw new Error(`Refusing to write through ${skillDir}: not a real directory.`);
|
|
}
|
|
return skillDir;
|
|
}
|