@brainbase-labs/cli 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +72 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -49586,6 +49586,77 @@ import path35 from "node:path";
|
|
|
49586
49586
|
import os7 from "node:os";
|
|
49587
49587
|
import fs32 from "node:fs";
|
|
49588
49588
|
import { execFileSync } from "node:child_process";
|
|
49589
|
+
var SKIP_DIRS = new Set(["node_modules"]);
|
|
49590
|
+
function skillMdPath(dir) {
|
|
49591
|
+
try {
|
|
49592
|
+
const hit = fs32.readdirSync(dir, { withFileTypes: true }).find((e2) => e2.isFile() && e2.name.toLowerCase() === "skill.md");
|
|
49593
|
+
return hit ? path35.join(dir, hit.name) : null;
|
|
49594
|
+
} catch {
|
|
49595
|
+
return null;
|
|
49596
|
+
}
|
|
49597
|
+
}
|
|
49598
|
+
function hasSkillMd(dir) {
|
|
49599
|
+
return skillMdPath(dir) !== null;
|
|
49600
|
+
}
|
|
49601
|
+
function declaredSkillName(dir) {
|
|
49602
|
+
const md = skillMdPath(dir);
|
|
49603
|
+
if (!md)
|
|
49604
|
+
return null;
|
|
49605
|
+
let text;
|
|
49606
|
+
try {
|
|
49607
|
+
text = fs32.readFileSync(md, "utf8");
|
|
49608
|
+
} catch {
|
|
49609
|
+
return null;
|
|
49610
|
+
}
|
|
49611
|
+
const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
|
|
49612
|
+
if (!fm)
|
|
49613
|
+
return null;
|
|
49614
|
+
const m3 = /^name:[ \t]*(.+?)[ \t]*$/m.exec(fm[1]);
|
|
49615
|
+
if (!m3)
|
|
49616
|
+
return null;
|
|
49617
|
+
return m3[1].replace(/^['"]|['"]$/g, "").trim().toLowerCase() || null;
|
|
49618
|
+
}
|
|
49619
|
+
function findSkillDirs(root) {
|
|
49620
|
+
const found = [];
|
|
49621
|
+
const walk = (dir, depth) => {
|
|
49622
|
+
if (hasSkillMd(dir))
|
|
49623
|
+
found.push({ dir, depth });
|
|
49624
|
+
let entries;
|
|
49625
|
+
try {
|
|
49626
|
+
entries = fs32.readdirSync(dir, { withFileTypes: true });
|
|
49627
|
+
} catch {
|
|
49628
|
+
return;
|
|
49629
|
+
}
|
|
49630
|
+
for (const e2 of entries) {
|
|
49631
|
+
if (!e2.isDirectory())
|
|
49632
|
+
continue;
|
|
49633
|
+
if (e2.name.startsWith(".") || SKIP_DIRS.has(e2.name))
|
|
49634
|
+
continue;
|
|
49635
|
+
walk(path35.join(dir, e2.name), depth + 1);
|
|
49636
|
+
}
|
|
49637
|
+
};
|
|
49638
|
+
walk(root, 0);
|
|
49639
|
+
return found.sort((a3, b4) => a3.depth - b4.depth).map((x3) => x3.dir);
|
|
49640
|
+
}
|
|
49641
|
+
function resolveSkillRoot(tmp, subpath) {
|
|
49642
|
+
if (!subpath) {
|
|
49643
|
+
if (hasSkillMd(tmp))
|
|
49644
|
+
return tmp;
|
|
49645
|
+
const skillDirs = findSkillDirs(tmp);
|
|
49646
|
+
return skillDirs.length === 1 ? skillDirs[0] : tmp;
|
|
49647
|
+
}
|
|
49648
|
+
const literal = path35.join(tmp, subpath);
|
|
49649
|
+
const literalIsDir = fs32.existsSync(literal) && fs32.statSync(literal).isDirectory();
|
|
49650
|
+
if (literalIsDir && hasSkillMd(literal))
|
|
49651
|
+
return literal;
|
|
49652
|
+
const wanted = path35.basename(subpath).toLowerCase();
|
|
49653
|
+
const byName = findSkillDirs(tmp).find((d3) => path35.basename(d3).toLowerCase() === wanted || declaredSkillName(d3) === wanted);
|
|
49654
|
+
if (byName)
|
|
49655
|
+
return byName;
|
|
49656
|
+
if (literalIsDir)
|
|
49657
|
+
return literal;
|
|
49658
|
+
throw new Error(`Could not locate skill '${path35.basename(subpath)}' in repo: no ` + `'${subpath}' directory, and no skill (SKILL.md folder) whose name ` + `is '${path35.basename(subpath)}' was found anywhere in it.`);
|
|
49659
|
+
}
|
|
49589
49660
|
function gitCloneSubpath(opts) {
|
|
49590
49661
|
const tmp = fs32.mkdtempSync(path35.join(os7.tmpdir(), "bb-skill-"));
|
|
49591
49662
|
try {
|
|
@@ -49600,14 +49671,7 @@ function gitCloneSubpath(opts) {
|
|
|
49600
49671
|
const stderr = e2.stderr?.toString() ?? "";
|
|
49601
49672
|
throw new Error(`git clone failed: ${stderr.trim() || e2.message}`.trim());
|
|
49602
49673
|
}
|
|
49603
|
-
const sourceRoot =
|
|
49604
|
-
if (!fs32.existsSync(sourceRoot)) {
|
|
49605
|
-
throw new Error(`Path not found in repo: ${opts.subpath ?? "/"}`);
|
|
49606
|
-
}
|
|
49607
|
-
const stat = fs32.statSync(sourceRoot);
|
|
49608
|
-
if (!stat.isDirectory()) {
|
|
49609
|
-
throw new Error(`Source path is not a directory: ${opts.subpath}`);
|
|
49610
|
-
}
|
|
49674
|
+
const sourceRoot = resolveSkillRoot(tmp, opts.subpath);
|
|
49611
49675
|
ensureDir(opts.destDir);
|
|
49612
49676
|
copyDir(sourceRoot, opts.destDir);
|
|
49613
49677
|
} finally {
|