Add bounded skill handoff graph

This commit is contained in:
dahyeon committed 2026-05-18 17:22:12 -07:00
1 parent 54bc295ead
commit c14adac162
42 files changed
+2243 -31

No files matched your search

+55 -1
View File
@@ -3,14 +3,36 @@ import { dirname, resolve } from "node:path";
import { getLogger } from "@obs/logger";
export type TrustTier = "T1" | "T2" | "T3" | "T4";
export type SkillRiskTier = "low" | "medium" | "high";
export interface SkillOutputContract {
format?: string | undefined;
maxChars?: string | undefined;
requiredFields?: string | undefined;
}
export interface SkillCapabilityCard {
canHandle: string[];
cannotHandle: string[];
domain: string;
handoffTargets: string[];
outputContract: SkillOutputContract;
riskTier: SkillRiskTier;
}
export interface SkillManifest {
bodyPath: string;
canHandle: string[];
cannotHandle: string[];
description: string;
domain: string;
handoffTargets: string[];
intents: string[];
name: string;
outputContract: SkillOutputContract;
priority: number;
resources: Record<string, string>;
riskTier: SkillRiskTier;
tools: string[];
triggers: string[];
trustTier: TrustTier;
@@ -121,10 +143,32 @@ function readResources(
);
}
function readStringMap(
fields: Record<string, unknown>,
key: string,
): Record<string, string> {
const raw = fields[key];
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
return {};
}
return Object.fromEntries(
Object.entries(raw as Record<string, unknown>).flatMap(([mapKey, value]) =>
typeof value === "string" && value.trim()
? [[mapKey, value.trim().replace(/^["']|["']$/gu, "")]]
: [],
),
);
}
function isTrustTier(value: unknown): value is TrustTier {
return value === "T1" || value === "T2" || value === "T3" || value === "T4";
}
function isRiskTier(value: unknown): value is SkillRiskTier {
return value === "low" || value === "medium" || value === "high";
}
function isPriority(value: unknown): value is number {
return (
typeof value === "number" &&
@@ -147,6 +191,8 @@ function parseSkillFile(path: string): ParsedSkillFile | null {
const priority = parsed.fields["priority"] ?? 50;
const version = parsed.fields["version"];
const trustTier = parsed.fields["trustTier"];
const domain = parsed.fields["domain"];
const riskTier = parsed.fields["riskTier"] ?? "low";
if (
typeof name !== "string" ||
@@ -155,20 +201,28 @@ function parseSkillFile(path: string): ParsedSkillFile | null {
!description.trim() ||
!isPriority(priority) ||
typeof version !== "number" ||
!isTrustTier(trustTier)
!isTrustTier(trustTier) ||
!isRiskTier(riskTier)
) {
return null;
}
const outputContract = readStringMap(parsed.fields, "outputContract");
return {
body: parsed.body,
manifest: {
bodyPath: path,
canHandle: readStringArray(parsed.fields, "canHandle"),
cannotHandle: readStringArray(parsed.fields, "cannotHandle"),
description,
domain: typeof domain === "string" && domain.trim() ? domain : "general",
handoffTargets: readStringArray(parsed.fields, "handoffTargets"),
intents: readStringArray(parsed.fields, "intents"),
name,
outputContract,
priority,
resources: readResources(parsed.fields, skillDir),
riskTier,
tools: readStringArray(parsed.fields, "tools"),
triggers: readStringArray(parsed.fields, "triggers"),
trustTier,