Skip to content

Your app looks AI-generated. Vincent Van Gogh noticed. An agent skill that finds and fixes AI-looking UI and UX in mobile apps, web apps, and websites.

fix(install): refuse to install into the skill's own folder (#93)

Manuel Gasparini4e5e85e7d7b7
diff --git a/bin/install.js b/bin/install.js
index 1329f28..6a24531 100755
--- a/bin/install.js
+++ b/bin/install.js
@@ -68,9 +68,24 @@ function removeOldSkill(base) {
} catch {}
}
+function isSkillFolder(dir) {
+ try {
+ const a = fs.statSync(dir);
+ const b = fs.statSync(skill);
+ return a.dev === b.dev && a.ino === b.ino;
+ } catch {
+ return false;
+ }
+}
+
function copySkill(base) {
- removeOldSkill(base);
const dest = path.join(base, "unslop-anything");
+ // Installing into the skill's own folder would delete each file before copying it onto itself.
+ if (isSkillFolder(dest)) {
+ console.error(`${dest} is where the skill is installed from, so there is nothing to install.`);
+ return null;
+ }
+ removeOldSkill(base);
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(skill)) {
fs.rmSync(path.join(dest, entry), { recursive: true, force: true });
@@ -82,6 +97,7 @@ function copySkill(base) {
const dir = option("--dir");
if (dir) {
const dest = copySkill(path.resolve(dir.replace(/^~(?=$|\/)/, home)));
+ if (!dest) process.exit(1);
console.log(`Dr. Unslopovich will see you now.\nInstalled to ${dest}\nNext, ask your agent: review my app with unslop-anything`);
return;
}
@@ -117,6 +133,7 @@ for (const id of agents) {
console.log("Dr. Unslopovich will see you now.");
for (const { dest, agents: list } of installed.values()) {
+ if (!dest) continue;
console.log(`\n${list.map((a) => a.name).join(", ")}\n installed to ${dest}`);
for (const a of list) console.log(` in ${a.name}: ${a.call} review my app`);
}
diff --git a/test/detect.test.js b/test/detect.test.js
index 3ad258a..52a3a53 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -473,6 +473,32 @@ test("the installer replaces a skill folder from before the rename", () => {
}
});
+test("the installer refuses to install into the folder it installs from", () => {
+ const fs = require("fs");
+ const os = require("os");
+ const { spawnSync } = require("child_process");
+ // A copy of the package, so a failure cannot delete files from this checkout.
+ const pkg = fs.mkdtempSync(path.join(os.tmpdir(), "unslop-pkg-"));
+ fs.cpSync(path.join(__dirname, "..", "bin"), path.join(pkg, "bin"), { recursive: true });
+ fs.cpSync(path.join(__dirname, "..", "skills"), path.join(pkg, "skills"), { recursive: true });
+ const before = fs.readdirSync(path.join(pkg, "skills", "unslop-anything")).sort();
+ fs.symlinkSync(path.join(pkg, "skills"), path.join(pkg, "link"), "junction");
+ const dirs = ["skills", "./skills/../skills", "link"];
+ // On a case-insensitive file system, another spelling is the same folder.
+ if (fs.existsSync(path.join(pkg, "SKILLS"))) dirs.push("SKILLS");
+ try {
+ for (const dir of dirs) {
+ const run = spawnSync(process.execPath, [path.join("bin", "install.js"), "--dir", dir], { cwd: pkg, encoding: "utf8" });
+ assert.strictEqual(run.status, 1);
+ assert.match(run.stderr, /nothing to install/);
+ assert.deepStrictEqual(fs.readdirSync(path.join(pkg, "skills", "unslop-anything")).sort(), before);
+ assert.ok(fs.existsSync(path.join(pkg, "skills", "unslop-anything", "SKILL.md")));
+ }
+ } finally {
+ fs.rmSync(pkg, { recursive: true, force: true });
+ }
+});
+
test("an arrow function in an attribute does not end the tag for clickable-div and img-no-alt", () => {
const rulesFor = (src) => scanSource(src, "a.tsx").map((f) => f.rule);
assert.deepStrictEqual(rulesFor('<div onClick={() => go()} role="button" tabIndex={0}>x</div>\n'), []);