fix(core,cli): harden install engine and argument parsing

- Reject unknown flags with exit 2 and never write on --dry-run, even in a TTY
- Treat files already matching the new content as up to date after an interrupted update
- Remove unmodified orphan files from older versions, keep and report modified ones and shared paths
- Degrade malformed manifests instead of blocking installs; readIfExists only maps ENOENT/ENOTDIR to null
- Block downgrades from older CLIs (semver), honor uninstall --scope, dedupe targets, fix next-step output and table width
- Deeper package verification, LF normalization for .mjs, MIT LICENSE
This commit is contained in:
Yun Chan 2026-10-09 18:18:49 +09:00
parent 97f2c241e4
commit eecd3f03ff
29 changed files with 867 additions and 124 deletions

View file

@ -13,7 +13,8 @@ const dest = path.resolve(here, "../dist/skill");
// Windows 에서 작업하면 파일이 CRLF 로 저장되고, 그대로 tarball 에 들어가면
// SKILL.md 의 YAML 프론트매터를 파서에 따라 못 읽는다.
// 배포물은 어느 OS 에서 만들었는지와 무관하게 같아야 한다.
const TEXT = new Set([".md", ".txt", ".json", ".yml", ".yaml"]);
// .mjs 도 포함한다 — tools/*.mjs 가 설치물이라 같은 바이트 동일성 원칙이 적용된다.
const TEXT = new Set([".md", ".txt", ".json", ".yml", ".yaml", ".mjs", ".js", ".cjs"]);
const excluded = [];

View file

@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
import { isAllowedSkillFile } from "./skill-allowlist.mjs";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const must = ["dist/index.js", "dist/skill/SKILL.md", "dist/skill/.designpaca_version"];
const must = ["dist/index.js", "dist/skill/SKILL.md", "dist/skill/.designpaca_version", "LICENSE"];
const missing = [];
for (const rel of must) {
@ -40,4 +40,45 @@ if (unexpected.length) {
console.error("scripts/skill-allowlist.mjs 를 확인하고 pnpm build 를 다시 실행해라.");
process.exit(1);
}
// SKILL.md 가 비었거나 프론트매터가 깨졌거나 본문이 링크한 문서가 빠졌으면 배포하지 않는다
const skillMd = await fs.readFile(path.join(skillDir, "SKILL.md"), "utf8");
if (!skillMd.startsWith("---\nname: designpaca\n")) {
console.error('dist/skill/SKILL.md 의 프론트매터가 "name: designpaca" 로 시작하지 않는다 (비었거나 CRLF·손상)');
process.exit(1);
}
const brokenLinks = [];
for (const m of skillMd.matchAll(/\]\((references\/[^)#\s]+)/g)) {
try {
await fs.access(path.join(skillDir, m[1]));
} catch {
brokenLinks.push(m[1]);
}
}
if (brokenLinks.length) {
const list = [...new Set(brokenLinks)].map((m) => ` - ${m}`).join("\n");
console.error(`SKILL.md 가 링크한 문서가 배포물에 없다:\n${list}`);
process.exit(1);
}
// 텍스트는 LF 여야 한다 — 정규화 대상 확장자가 빠졌을 때 여기서 잡는다
const crlf = [];
for (const e of await fs.readdir(skillDir, { recursive: true, withFileTypes: true })) {
if (!e.isFile() || !/\.(md|txt|json|ya?ml|mjs|c?js)$/.test(e.name)) continue;
const full = path.join(e.parentPath ?? e.path, e.name);
if ((await fs.readFile(full, "utf8")).includes("\r\n")) {
crlf.push(path.relative(skillDir, full).split(path.sep).join("/"));
}
}
if (crlf.length) {
console.error(`CRLF 가 남은 파일:\n${crlf.map((m) => ` - ${m}`).join("\n")}`);
process.exit(1);
}
// 실행 진입점은 첫 줄이 shebang 이어야 한다(tsup banner)
const indexHead = (await fs.readFile(path.join(root, "dist/index.js"), "utf8")).split("\n", 1)[0];
if (indexHead !== "#!/usr/bin/env node") {
console.error("dist/index.js 첫 줄이 shebang 이 아니다 (tsup banner 확인)");
process.exit(1);
}
console.log(`배포 점검 통과 (v${pkg.version})`);