This commit is contained in:
ZacharyZhang-NY committed 2026-04-17 14:03:56 -04:00
1 parent 806200b3d1
commit 5547c29491
216 files changed
+5043 -3352

No files matched your search

+1 -54
View File
@@ -1,5 +1,5 @@
import { extname } from "node:path";
import type { FileInventoryEntry, SkillContextMode, TrustLevel } from "./skill-types.js";
import type { FileInventoryEntry, TrustLevel } from "./skill-types.js";
function isPlainRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -220,56 +220,3 @@ export function deriveTrustLevel(inventory: FileInventoryEntry[]): TrustLevel {
return "markdown_only";
}
/**
* Estimate the token count for a text string.
* Uses a rough 1:4 character-to-token ratio.
*/
export function estimateTokens(text: string): number {
if (text.length === 0) return 0;
return Math.ceil(text.length / 4);
}
/**
* Runtime semantics extracted from a skill's YAML frontmatter.
* These fields control how the skill interacts with the execution runtime.
*/
export interface SkillRuntimeSemantics {
allowedTools: string[];
hooks: string[];
contextMode: SkillContextMode;
isAgent: boolean;
effort: "low" | "medium" | "high";
whenToUse: string;
}
function toStringArray(value: unknown): string[] {
if (Array.isArray(value)) return value.filter((v): v is string => typeof v === "string");
if (typeof value === "string") return value.split(",").map((s) => s.trim()).filter(Boolean);
return [];
}
/**
* Extract runtime semantics from parsed frontmatter.
* Missing fields default to safe, passive values.
*/
export function extractRuntimeSemantics(
frontmatter: Record<string, unknown>,
): SkillRuntimeSemantics {
const contextRaw = typeof frontmatter.context === "string" ? frontmatter.context : "inline";
const contextMode: SkillContextMode = contextRaw === "fork" ? "fork" : "inline";
const effortRaw = typeof frontmatter.effort === "string" ? frontmatter.effort : "medium";
const validEfforts = new Set(["low", "medium", "high"]);
const effort: "low" | "medium" | "high" = validEfforts.has(effortRaw)
? (effortRaw as "low" | "medium" | "high")
: "medium";
return {
allowedTools: toStringArray(frontmatter["allowed-tools"] ?? frontmatter.allowedTools),
hooks: toStringArray(frontmatter.hooks),
contextMode,
isAgent: frontmatter.agent === true || frontmatter.agent === "true",
effort,
whenToUse: typeof frontmatter.when_to_use === "string" ? frontmatter.when_to_use : "",
};
}