Ship skills built-in: bundle the catalogue, assign per hire, force humanizer
Skills no longer come from the user's ~/.agents library - most users have none, and the CEO branch that compiled the entire catalogue into its prompt overflowed the model context (1.1MB) and failed every CEO run. - Bundle "built-in skills/" with the app (extraResources) and stage it at startup into <profile>/builtin-skills as one dir-per-skill copy - both bundle shapes (SKILL.md dirs and flat category .md files) normalize into the same importable layout - Import the staged catalogue per org at startup and inside onboarding, so the CEO's first run already carries it - Forced house style: resolveRuntimeSnapshot unions the humanizer skill into every agent's runtime (CEO included) as a resolution rule - no binding row to forget, delete, or bypass; revoke_skill refuses it - CEO staffs hires with skills: hire_agent accepts a skills array, grant_skill/revoke_skill adjust later, list_skills now shows descriptions from skill frontmatter - Kill the c_suite compile-all branch; everyone resolves bindings-only, capped at 200k chars with omissions named in the prompt - Remove the Skills settings page and its import/sync/test IPC surface; drop ~/.agents discovery and the AGENTCOMPANY_NEW_SKILLS_ROOT seam in favor of AGENTCOMPANY_NEW_BUILTIN_SKILLS_DIR - Tests: staging/import/forced-resolution/cap units, real-bundle CI check, e2e asserts the tab is gone and the catalogue self-imports
This commit is contained in:
1 parent
55c043f8b4
commit
86aa6fdb29
318 files changed
+77467
-520
No files matched your search
@@ -0,0 +1,185 @@
|
||||
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { RISK_LEVEL } from "../../shared/domain";
|
||||
import { loadSkillManifest, type SkillManifest } from "./skill-manifest";
|
||||
import type { SkillService } from "./skill-service";
|
||||
|
||||
/**
|
||||
* The skill catalogue ships with the app: `built-in skills/` in the repo, and
|
||||
* `resources/built-in-skills` in a packaged build. The user never manages it.
|
||||
*
|
||||
* The bundle holds two shapes:
|
||||
* - a directory per skill with a SKILL.md (and optional skill.manifest.json),
|
||||
* e.g. `humanizer/`;
|
||||
* - category directories of flat one-file skills, e.g.
|
||||
* `engineering/engineering-backend-architect.md`.
|
||||
*
|
||||
* Staging normalizes both into one library layout the import machinery
|
||||
* understands — `<libraryRoot>/<slug>/SKILL.md` — a real copy on disk, never a
|
||||
* reference back into the bundle. Import then publishes every staged skill the
|
||||
* org does not carry yet into the immutable artifact store.
|
||||
*/
|
||||
|
||||
export interface StagedBuiltinSkill {
|
||||
slug: string;
|
||||
directory: string;
|
||||
manifest: SkillManifest;
|
||||
}
|
||||
|
||||
export interface BuiltinSkillSyncReport {
|
||||
imported: number;
|
||||
skipped: number;
|
||||
failures: string[];
|
||||
}
|
||||
|
||||
/** Test seam, same pattern as AGENTCOMPANY_NEW_PROFILE_DIR. */
|
||||
export function builtinSkillsSourceOverride(): string | undefined {
|
||||
return process.env.AGENTCOMPANY_NEW_BUILTIN_SKILLS_DIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors the bundled catalogue into the normalized on-disk library and
|
||||
* returns every staged skill. Idempotent: re-staging overwrites in place so
|
||||
* an app update refreshes the library on next launch.
|
||||
*/
|
||||
export function stageBuiltinSkillsLibrary(sourceRoot: string, libraryRoot: string): StagedBuiltinSkill[] {
|
||||
if (!existsSync(sourceRoot)) {
|
||||
throw new Error(`Built-in skills bundle was not found: ${sourceRoot}`);
|
||||
}
|
||||
const staged: StagedBuiltinSkill[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const entry of readdirSync(sourceRoot, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
const sourceDir = join(sourceRoot, entry.name);
|
||||
if (existsSync(join(sourceDir, "SKILL.md")) || existsSync(join(sourceDir, "skill.manifest.json"))) {
|
||||
staged.push(stageDirectorySkill(sourceDir, entry.name, libraryRoot, seen));
|
||||
continue;
|
||||
}
|
||||
staged.push(...stageCategorySkills(sourceDir, libraryRoot, seen));
|
||||
}
|
||||
return staged;
|
||||
}
|
||||
|
||||
/** Publishes every staged skill the org does not already carry. */
|
||||
export function importStagedSkills(skills: SkillService, orgId: string, staged: StagedBuiltinSkill[]): BuiltinSkillSyncReport {
|
||||
const report: BuiltinSkillSyncReport = { imported: 0, skipped: 0, failures: [] };
|
||||
for (const unit of staged) {
|
||||
try {
|
||||
if (skills.hasSkill(orgId, unit.slug)) {
|
||||
report.skipped += 1;
|
||||
continue;
|
||||
}
|
||||
skills.importManifest(orgId, unit.directory, unit.manifest, unit.slug);
|
||||
report.imported += 1;
|
||||
} catch (error) {
|
||||
report.failures.push(`${unit.slug}: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
function stageDirectorySkill(sourceDir: string, dirName: string, libraryRoot: string, seen: Set<string>): StagedBuiltinSkill {
|
||||
const slug = uniqueSlug(slugify(dirName), seen, sourceDir);
|
||||
const target = join(libraryRoot, slug);
|
||||
mkdirSync(target, { recursive: true });
|
||||
cpSync(sourceDir, target, { recursive: true });
|
||||
const manifest = existsSync(join(target, "skill.manifest.json"))
|
||||
? loadSkillManifest(target)
|
||||
: manifestFromSkillMarkdown(readFileSync(join(target, "SKILL.md"), "utf8"), dirName);
|
||||
return { slug, directory: target, manifest };
|
||||
}
|
||||
|
||||
function stageCategorySkills(categoryDir: string, libraryRoot: string, seen: Set<string>): StagedBuiltinSkill[] {
|
||||
const staged: StagedBuiltinSkill[] = [];
|
||||
for (const entry of readdirSync(categoryDir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
||||
if (!entry.isFile() || !entry.name.toLowerCase().endsWith(".md")) continue;
|
||||
if (entry.name.toLowerCase() === "readme.md") continue;
|
||||
const body = readFileSync(join(categoryDir, entry.name), "utf8");
|
||||
const frontmatter = parseFrontmatter(body);
|
||||
// A category file without a name: header is documentation, not a skill.
|
||||
if (!frontmatter.name) continue;
|
||||
const stem = entry.name.replace(/\.md$/i, "");
|
||||
const slug = uniqueSlug(slugify(stem), seen, join(categoryDir, entry.name));
|
||||
const target = join(libraryRoot, slug);
|
||||
mkdirSync(target, { recursive: true });
|
||||
writeFileSync(join(target, "SKILL.md"), body, "utf8");
|
||||
staged.push({
|
||||
slug,
|
||||
directory: target,
|
||||
manifest: derivedManifest(frontmatter.name, frontmatter.version, frontmatter.description),
|
||||
});
|
||||
}
|
||||
return staged;
|
||||
}
|
||||
|
||||
function manifestFromSkillMarkdown(markdown: string, fallbackName: string): SkillManifest {
|
||||
const frontmatter = parseFrontmatter(markdown);
|
||||
return derivedManifest(frontmatter.name ?? fallbackName, frontmatter.version, frontmatter.description);
|
||||
}
|
||||
|
||||
function derivedManifest(name: string, version: string | undefined, description: string | undefined): SkillManifest {
|
||||
return {
|
||||
name,
|
||||
version: version && /^\d+\.\d+\.\d+$/.test(version) ? version : "1.0.0",
|
||||
entrypoint: "SKILL.md",
|
||||
capabilities: [],
|
||||
requiredTools: [],
|
||||
compatibleModels: [],
|
||||
riskLevel: RISK_LEVEL.LOW,
|
||||
tests: [],
|
||||
inputs: {},
|
||||
outputs: {},
|
||||
...(description ? { description } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
interface SkillFrontmatter {
|
||||
name?: string;
|
||||
version?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimal YAML-frontmatter reader for the three fields skills declare. Handles
|
||||
* inline values (`description: text`) and block scalars (`description: |`)
|
||||
* because the bundled skills use both.
|
||||
*/
|
||||
export function parseFrontmatter(markdown: string): SkillFrontmatter {
|
||||
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(markdown);
|
||||
if (!match) return {};
|
||||
const lines = match[1].split(/\r?\n/);
|
||||
const result: SkillFrontmatter = {};
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
const field = /^(name|version|description)\s*:\s*(.*)$/.exec(lines[index]);
|
||||
if (!field) continue;
|
||||
const key = field[1] as keyof SkillFrontmatter;
|
||||
const inline = field[2].trim();
|
||||
if (inline && !/^[|>][+-]?$/.test(inline)) {
|
||||
result[key] = stripQuotes(inline);
|
||||
continue;
|
||||
}
|
||||
const block: string[] = [];
|
||||
while (index + 1 < lines.length && (/^\s+\S/.test(lines[index + 1]) || lines[index + 1].trim() === "")) {
|
||||
block.push(lines[index + 1].trim());
|
||||
index += 1;
|
||||
}
|
||||
const value = block.join(" ").replace(/\s+/g, " ").trim();
|
||||
if (value) result[key] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function stripQuotes(value: string): string {
|
||||
return value.replace(/^["']|["']$/g, "");
|
||||
}
|
||||
|
||||
function slugify(value: string): string {
|
||||
return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
||||
}
|
||||
|
||||
function uniqueSlug(slug: string, seen: Set<string>, source: string): string {
|
||||
if (!slug) throw new Error(`Built-in skill has no usable slug: ${source}`);
|
||||
if (seen.has(slug)) throw new Error(`Built-in skill slug collision: ${slug} (${source})`);
|
||||
seen.add(slug);
|
||||
return slug;
|
||||
}
|
||||
Reference in new issue
Block a user