mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
45 lines
2.3 KiB
JavaScript
45 lines
2.3 KiB
JavaScript
// Assemble the plugin's skill content: a dsh-specific routing prelude, the
|
|
// canonical CLI skill body verbatim (repo-root skill/SKILL.md — the same source
|
|
// crates/bsk-cli's build.rs mirrors), then a dsh routing reminder postlude. The
|
|
// original's YAML frontmatter is stripped: name/description are supplied by the
|
|
// registration.
|
|
// Output: src/skill-content.generated.ts (gitignored, built before tsdown and
|
|
// before vitest) so the markdown ships inlined in the bundle and registration
|
|
// is a pure in-memory read — never a per-step disk access.
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const pkg = join(here, "..");
|
|
const prelude = readFileSync(join(pkg, "skill", "prelude.md"), "utf8");
|
|
const upstream = readFileSync(join(pkg, "..", "..", "skill", "SKILL.md"), "utf8");
|
|
const postlude = readFileSync(join(pkg, "skill", "postlude.md"), "utf8");
|
|
|
|
function stripFrontmatter(markdown) {
|
|
if (!markdown.startsWith("---\n")) return markdown;
|
|
const end = markdown.indexOf("\n---\n", 4);
|
|
return end === -1 ? markdown : markdown.slice(end + 5).replace(/^\s*\n/, "");
|
|
}
|
|
|
|
const NAME = "browser-skill";
|
|
const DESCRIPTION =
|
|
"Browser automation against the user's logged-in Chromium through this plugin's injected browser_* tools; never invoke bsk through bash or shell. " +
|
|
"tools (bsk engine): visit and read pages, fill forms, click through flows, scrape data, " +
|
|
"smoke-test UI changes. Use when a task needs a real browser; requires the bsk CLI and the " +
|
|
"browser-skill extension connected.";
|
|
|
|
const content = `${prelude.trim()}\n\n${stripFrontmatter(upstream).trim()}\n\n${postlude.trim()}\n`;
|
|
|
|
const banner =
|
|
"// GENERATED by scripts/build-skill-content.mjs — do not edit.\n" +
|
|
"// Sources: skill/prelude.md + ../../../skill/SKILL.md + skill/postlude.md.\n";
|
|
|
|
writeFileSync(
|
|
join(pkg, "src", "skill-content.generated.ts"),
|
|
`${banner}export const BSK_SKILL_NAME = ${JSON.stringify(NAME)};\n` +
|
|
`export const BSK_SKILL_DESCRIPTION = ${JSON.stringify(DESCRIPTION)};\n` +
|
|
`export const BSK_SKILL_MARKDOWN = ${JSON.stringify(content)};\n`,
|
|
);
|
|
console.log(`skill-content.generated.ts written (${content.length} chars)`);
|