@elyracode/agent-core 0.1.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/README.md +488 -0
- package/dist/agent-loop.d.ts +24 -0
- package/dist/agent-loop.d.ts.map +1 -0
- package/dist/agent-loop.js +479 -0
- package/dist/agent-loop.js.map +1 -0
- package/dist/agent.d.ts +118 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +402 -0
- package/dist/agent.js.map +1 -0
- package/dist/harness/agent-harness.d.ts +78 -0
- package/dist/harness/agent-harness.d.ts.map +1 -0
- package/dist/harness/agent-harness.js +602 -0
- package/dist/harness/agent-harness.js.map +1 -0
- package/dist/harness/compaction/branch-summarization.d.ts +88 -0
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/harness/compaction/branch-summarization.js +243 -0
- package/dist/harness/compaction/branch-summarization.js.map +1 -0
- package/dist/harness/compaction/compaction.d.ts +122 -0
- package/dist/harness/compaction/compaction.d.ts.map +1 -0
- package/dist/harness/compaction/compaction.js +616 -0
- package/dist/harness/compaction/compaction.js.map +1 -0
- package/dist/harness/compaction/utils.d.ts +38 -0
- package/dist/harness/compaction/utils.d.ts.map +1 -0
- package/dist/harness/compaction/utils.js +153 -0
- package/dist/harness/compaction/utils.js.map +1 -0
- package/dist/harness/env/nodejs.d.ts +44 -0
- package/dist/harness/env/nodejs.d.ts.map +1 -0
- package/dist/harness/env/nodejs.js +348 -0
- package/dist/harness/env/nodejs.js.map +1 -0
- package/dist/harness/execution-env.d.ts +4 -0
- package/dist/harness/execution-env.d.ts.map +1 -0
- package/dist/harness/execution-env.js +3 -0
- package/dist/harness/execution-env.js.map +1 -0
- package/dist/harness/messages.d.ts +51 -0
- package/dist/harness/messages.d.ts.map +1 -0
- package/dist/harness/messages.js +102 -0
- package/dist/harness/messages.js.map +1 -0
- package/dist/harness/prompt-templates.d.ts +45 -0
- package/dist/harness/prompt-templates.d.ts.map +1 -0
- package/dist/harness/prompt-templates.js +200 -0
- package/dist/harness/prompt-templates.js.map +1 -0
- package/dist/harness/session/repo/jsonl.d.ts +20 -0
- package/dist/harness/session/repo/jsonl.d.ts.map +1 -0
- package/dist/harness/session/repo/jsonl.js +92 -0
- package/dist/harness/session/repo/jsonl.js.map +1 -0
- package/dist/harness/session/repo/memory.d.ts +18 -0
- package/dist/harness/session/repo/memory.d.ts.map +1 -0
- package/dist/harness/session/repo/memory.js +42 -0
- package/dist/harness/session/repo/memory.js.map +1 -0
- package/dist/harness/session/repo/shared.d.ts +10 -0
- package/dist/harness/session/repo/shared.d.ts.map +1 -0
- package/dist/harness/session/repo/shared.js +31 -0
- package/dist/harness/session/repo/shared.js.map +1 -0
- package/dist/harness/session/session.d.ts +32 -0
- package/dist/harness/session/session.d.ts.map +1 -0
- package/dist/harness/session/session.js +196 -0
- package/dist/harness/session/session.js.map +1 -0
- package/dist/harness/session/storage/jsonl.d.ts +30 -0
- package/dist/harness/session/storage/jsonl.d.ts.map +1 -0
- package/dist/harness/session/storage/jsonl.js +170 -0
- package/dist/harness/session/storage/jsonl.js.map +1 -0
- package/dist/harness/session/storage/memory.d.ts +26 -0
- package/dist/harness/session/storage/memory.d.ts.map +1 -0
- package/dist/harness/session/storage/memory.js +90 -0
- package/dist/harness/session/storage/memory.js.map +1 -0
- package/dist/harness/skills.d.ts +41 -0
- package/dist/harness/skills.d.ts.map +1 -0
- package/dist/harness/skills.js +259 -0
- package/dist/harness/skills.js.map +1 -0
- package/dist/harness/system-prompt.d.ts +3 -0
- package/dist/harness/system-prompt.d.ts.map +1 -0
- package/dist/harness/system-prompt.js +30 -0
- package/dist/harness/system-prompt.js.map +1 -0
- package/dist/harness/types.d.ts +497 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +16 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/utils/shell-output.d.ts +14 -0
- package/dist/harness/utils/shell-output.d.ts.map +1 -0
- package/dist/harness/utils/shell-output.js +97 -0
- package/dist/harness/utils/shell-output.js.map +1 -0
- package/dist/harness/utils/truncate.d.ts +70 -0
- package/dist/harness/utils/truncate.d.ts.map +1 -0
- package/dist/harness/utils/truncate.js +205 -0
- package/dist/harness/utils/truncate.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/proxy.d.ts +69 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +278 -0
- package/dist/proxy.js.map +1 -0
- package/dist/types.d.ts +386 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ExecutionEnv, Skill } from "./types.js";
|
|
2
|
+
/** Warning produced while loading skills. */
|
|
3
|
+
export interface SkillDiagnostic {
|
|
4
|
+
/** Diagnostic severity. Currently only warnings are emitted. */
|
|
5
|
+
type: "warning";
|
|
6
|
+
/** Human-readable diagnostic message. */
|
|
7
|
+
message: string;
|
|
8
|
+
/** Path associated with the diagnostic. */
|
|
9
|
+
path: string;
|
|
10
|
+
}
|
|
11
|
+
/** Format a skill invocation prompt, optionally appending additional user instructions. */
|
|
12
|
+
export declare function formatSkillInvocation(skill: Skill, additionalInstructions?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Load skills from one or more directories.
|
|
15
|
+
*
|
|
16
|
+
* Traverses directories recursively, loads `SKILL.md` files, loads direct root `.md` files as skills, honors ignore files,
|
|
17
|
+
* and returns diagnostics for invalid skill files. Missing input directories are skipped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadSkills(env: ExecutionEnv, dirs: string | string[]): Promise<{
|
|
20
|
+
skills: Skill[];
|
|
21
|
+
diagnostics: SkillDiagnostic[];
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Load skills from source-tagged directories.
|
|
25
|
+
*
|
|
26
|
+
* Source values are preserved exactly and attached to every loaded skill and diagnostic. The agent package does not
|
|
27
|
+
* interpret source values; applications define their own provenance shape.
|
|
28
|
+
*/
|
|
29
|
+
export declare function loadSourcedSkills<TSource, TSkill extends Skill = Skill>(env: ExecutionEnv, inputs: Array<{
|
|
30
|
+
path: string;
|
|
31
|
+
source: TSource;
|
|
32
|
+
}>, mapSkill?: (skill: Skill, source: TSource) => TSkill): Promise<{
|
|
33
|
+
skills: Array<{
|
|
34
|
+
skill: TSkill;
|
|
35
|
+
source: TSource;
|
|
36
|
+
}>;
|
|
37
|
+
diagnostics: Array<SkillDiagnostic & {
|
|
38
|
+
source: TSource;
|
|
39
|
+
}>;
|
|
40
|
+
}>;
|
|
41
|
+
//# sourceMappingURL=skills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../src/harness/skills.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAQtD,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC/B,gEAAgE;IAChE,IAAI,EAAE,SAAS,CAAC;IAChB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;CACb;AASD,2FAA2F;AAC3F,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,sBAAsB,CAAC,EAAE,MAAM,GAAG,MAAM,CAG3F;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC/B,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GACrB,OAAO,CAAC;IAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAAC,WAAW,EAAE,eAAe,EAAE,CAAA;CAAE,CAAC,CAW9D;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5E,GAAG,EAAE,YAAY,EACjB,MAAM,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,EAChD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,KAAK,MAAM,GAClD,OAAO,CAAC;IACV,MAAM,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAClD,WAAW,EAAE,KAAK,CAAC,eAAe,GAAG;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAC1D,CAAC,CAWD","sourcesContent":["import ignore from \"ignore\";\nimport { parse } from \"yaml\";\nimport type { ExecutionEnv, Skill } from \"./types.js\";\n\nconst MAX_NAME_LENGTH = 64;\nconst MAX_DESCRIPTION_LENGTH = 1024;\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\n\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\n/** Warning produced while loading skills. */\nexport interface SkillDiagnostic {\n\t/** Diagnostic severity. Currently only warnings are emitted. */\n\ttype: \"warning\";\n\t/** Human-readable diagnostic message. */\n\tmessage: string;\n\t/** Path associated with the diagnostic. */\n\tpath: string;\n}\n\ninterface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t[key: string]: unknown;\n}\n\n/** Format a skill invocation prompt, optionally appending additional user instructions. */\nexport function formatSkillInvocation(skill: Skill, additionalInstructions?: string): string {\n\tconst skillBlock = `<skill name=\"${skill.name}\" location=\"${skill.filePath}\">\\nReferences are relative to ${dirnameEnvPath(skill.filePath)}.\\n\\n${skill.content}\\n</skill>`;\n\treturn additionalInstructions ? `${skillBlock}\\n\\n${additionalInstructions}` : skillBlock;\n}\n\n/**\n * Load skills from one or more directories.\n *\n * Traverses directories recursively, loads `SKILL.md` files, loads direct root `.md` files as skills, honors ignore files,\n * and returns diagnostics for invalid skill files. Missing input directories are skipped.\n */\nexport async function loadSkills(\n\tenv: ExecutionEnv,\n\tdirs: string | string[],\n): Promise<{ skills: Skill[]; diagnostics: SkillDiagnostic[] }> {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: SkillDiagnostic[] = [];\n\tfor (const dir of Array.isArray(dirs) ? dirs : [dirs]) {\n\t\tconst rootInfo = await safeFileInfo(env, dir);\n\t\tif (!rootInfo || (await resolveKind(env, rootInfo)) !== \"directory\") continue;\n\t\tconst result = await loadSkillsFromDirInternal(env, rootInfo.path, true, ignore(), rootInfo.path);\n\t\tskills.push(...result.skills);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\treturn { skills, diagnostics };\n}\n\n/**\n * Load skills from source-tagged directories.\n *\n * Source values are preserved exactly and attached to every loaded skill and diagnostic. The agent package does not\n * interpret source values; applications define their own provenance shape.\n */\nexport async function loadSourcedSkills<TSource, TSkill extends Skill = Skill>(\n\tenv: ExecutionEnv,\n\tinputs: Array<{ path: string; source: TSource }>,\n\tmapSkill?: (skill: Skill, source: TSource) => TSkill,\n): Promise<{\n\tskills: Array<{ skill: TSkill; source: TSource }>;\n\tdiagnostics: Array<SkillDiagnostic & { source: TSource }>;\n}> {\n\tconst skills: Array<{ skill: TSkill; source: TSource }> = [];\n\tconst diagnostics: Array<SkillDiagnostic & { source: TSource }> = [];\n\tfor (const input of inputs) {\n\t\tconst result = await loadSkills(env, input.path);\n\t\tfor (const skill of result.skills) {\n\t\t\tskills.push({ skill: mapSkill ? mapSkill(skill, input.source) : (skill as TSkill), source: input.source });\n\t\t}\n\t\tfor (const diagnostic of result.diagnostics) diagnostics.push({ ...diagnostic, source: input.source });\n\t}\n\treturn { skills, diagnostics };\n}\n\nasync function loadSkillsFromDirInternal(\n\tenv: ExecutionEnv,\n\tdir: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher: IgnoreMatcher,\n\trootDir: string,\n): Promise<{ skills: Skill[]; diagnostics: SkillDiagnostic[] }> {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: SkillDiagnostic[] = [];\n\n\tif (!(await env.exists(dir))) return { skills, diagnostics };\n\tconst dirInfo = await safeFileInfo(env, dir);\n\tif (!dirInfo || (await resolveKind(env, dirInfo)) !== \"directory\") return { skills, diagnostics };\n\n\tawait addIgnoreRules(env, ignoreMatcher, dir, rootDir);\n\n\tlet entries: Awaited<ReturnType<ExecutionEnv[\"listDir\"]>>;\n\ttry {\n\t\tentries = await env.listDir(dir);\n\t} catch {\n\t\treturn { skills, diagnostics };\n\t}\n\n\tfor (const entry of entries) {\n\t\tif (entry.name !== \"SKILL.md\") continue;\n\t\tconst fullPath = entry.path;\n\t\tconst kind = await resolveKind(env, entry);\n\t\tif (kind !== \"file\") continue;\n\t\tconst relPath = relativeEnvPath(rootDir, fullPath);\n\t\tif (ignoreMatcher.ignores(relPath)) continue;\n\n\t\tconst result = await loadSkillFromFile(env, fullPath);\n\t\tif (result.skill) skills.push(result.skill);\n\t\tdiagnostics.push(...result.diagnostics);\n\t\treturn { skills, diagnostics };\n\t}\n\n\tfor (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n\t\tif (entry.name.startsWith(\".\") || entry.name === \"node_modules\") continue;\n\t\tconst fullPath = entry.path;\n\t\tconst kind = await resolveKind(env, entry);\n\t\tif (!kind) continue;\n\n\t\tconst relPath = relativeEnvPath(rootDir, fullPath);\n\t\tconst ignorePath = kind === \"directory\" ? `${relPath}/` : relPath;\n\t\tif (ignoreMatcher.ignores(ignorePath)) continue;\n\n\t\tif (kind === \"directory\") {\n\t\t\tconst result = await loadSkillsFromDirInternal(env, fullPath, false, ignoreMatcher, rootDir);\n\t\t\tskills.push(...result.skills);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (kind !== \"file\" || !includeRootFiles || !entry.name.endsWith(\".md\")) continue;\n\t\tconst result = await loadSkillFromFile(env, fullPath);\n\t\tif (result.skill) skills.push(result.skill);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\n\treturn { skills, diagnostics };\n}\n\nasync function addIgnoreRules(env: ExecutionEnv, ig: IgnoreMatcher, dir: string, rootDir: string): Promise<void> {\n\tconst relativeDir = relativeEnvPath(rootDir, dir);\n\tconst prefix = relativeDir ? `${relativeDir}/` : \"\";\n\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePath = joinEnvPath(dir, filename);\n\t\tconst info = await safeFileInfo(env, ignorePath);\n\t\tif (info?.kind !== \"file\") continue;\n\t\ttry {\n\t\t\tconst content = await env.readTextFile(ignorePath);\n\t\t\tconst patterns = content\n\t\t\t\t.split(/\\r?\\n/)\n\t\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t\t.filter((line): line is string => Boolean(line));\n\t\t\tif (patterns.length > 0) ig.add(patterns);\n\t\t} catch {}\n\t}\n}\n\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\n\tlet pattern = line;\n\tlet negated = false;\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tif (pattern.startsWith(\"/\")) pattern = pattern.slice(1);\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\n\nasync function loadSkillFromFile(\n\tenv: ExecutionEnv,\n\tfilePath: string,\n): Promise<{ skill: Skill | null; diagnostics: SkillDiagnostic[] }> {\n\tconst diagnostics: SkillDiagnostic[] = [];\n\ttry {\n\t\tconst rawContent = await env.readTextFile(filePath);\n\t\tconst { frontmatter, body } = parseFrontmatter<SkillFrontmatter>(rawContent);\n\t\tconst skillDir = dirnameEnvPath(filePath);\n\t\tconst parentDirName = basenameEnvPath(skillDir);\n\n\t\tfor (const error of validateDescription(frontmatter.description)) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\tconst name = frontmatter.name || parentDirName;\n\t\tfor (const error of validateName(name, parentDirName)) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\tif (!frontmatter.description || frontmatter.description.trim() === \"\") {\n\t\t\treturn { skill: null, diagnostics };\n\t\t}\n\n\t\treturn {\n\t\t\tskill: {\n\t\t\t\tname,\n\t\t\t\tdescription: frontmatter.description,\n\t\t\t\tcontent: body,\n\t\t\t\tfilePath,\n\t\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t\t},\n\t\t\tdiagnostics,\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse skill file\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n}\n\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\tif (name !== parentDirName) errors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\tif (name.length > MAX_NAME_LENGTH) errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(\"name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)\");\n\t}\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) errors.push(\"name must not start or end with a hyphen\");\n\tif (name.includes(\"--\")) errors.push(\"name must not contain consecutive hyphens\");\n\treturn errors;\n}\n\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\treturn errors;\n}\n\nfunction parseFrontmatter<T extends Record<string, unknown>>(content: string): { frontmatter: T; body: string } {\n\tconst normalized = content.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n\tif (!normalized.startsWith(\"---\")) return { frontmatter: {} as T, body: normalized };\n\tconst endIndex = normalized.indexOf(\"\\n---\", 3);\n\tif (endIndex === -1) return { frontmatter: {} as T, body: normalized };\n\tconst yamlString = normalized.slice(4, endIndex);\n\tconst body = normalized.slice(endIndex + 4).trim();\n\treturn { frontmatter: (parse(yamlString) ?? {}) as T, body };\n}\n\nasync function safeFileInfo(\n\tenv: ExecutionEnv,\n\tpath: string,\n): Promise<Awaited<ReturnType<ExecutionEnv[\"fileInfo\"]>> | undefined> {\n\ttry {\n\t\treturn await env.fileInfo(path);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function resolveKind(\n\tenv: ExecutionEnv,\n\tinfo: Awaited<ReturnType<ExecutionEnv[\"fileInfo\"]>>,\n): Promise<\"file\" | \"directory\" | undefined> {\n\tif (info.kind === \"file\" || info.kind === \"directory\") return info.kind;\n\ttry {\n\t\tconst realPath = await env.realPath(info.path);\n\t\tconst target = await env.fileInfo(realPath);\n\t\treturn target.kind === \"file\" || target.kind === \"directory\" ? target.kind : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction joinEnvPath(base: string, child: string): string {\n\treturn `${base.replace(/\\/+$/, \"\")}/${child.replace(/^\\/+/, \"\")}`;\n}\n\nfunction dirnameEnvPath(path: string): string {\n\tconst normalized = path.replace(/\\/+$/, \"\");\n\tconst slashIndex = normalized.lastIndexOf(\"/\");\n\treturn slashIndex <= 0 ? \"/\" : normalized.slice(0, slashIndex);\n}\n\nfunction basenameEnvPath(path: string): string {\n\tconst normalized = path.replace(/\\/+$/, \"\");\n\tconst slashIndex = normalized.lastIndexOf(\"/\");\n\treturn slashIndex === -1 ? normalized : normalized.slice(slashIndex + 1);\n}\n\nfunction relativeEnvPath(root: string, path: string): string {\n\tconst normalizedRoot = root.replace(/\\/+$/, \"\");\n\tconst normalizedPath = path.replace(/\\/+$/, \"\");\n\tif (normalizedPath === normalizedRoot) return \"\";\n\treturn normalizedPath.startsWith(`${normalizedRoot}/`)\n\t\t? normalizedPath.slice(normalizedRoot.length + 1)\n\t\t: normalizedPath.replace(/^\\/+/, \"\");\n}\n"]}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import ignore from "ignore";
|
|
2
|
+
import { parse } from "yaml";
|
|
3
|
+
const MAX_NAME_LENGTH = 64;
|
|
4
|
+
const MAX_DESCRIPTION_LENGTH = 1024;
|
|
5
|
+
const IGNORE_FILE_NAMES = [".gitignore", ".ignore", ".fdignore"];
|
|
6
|
+
/** Format a skill invocation prompt, optionally appending additional user instructions. */
|
|
7
|
+
export function formatSkillInvocation(skill, additionalInstructions) {
|
|
8
|
+
const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${dirnameEnvPath(skill.filePath)}.\n\n${skill.content}\n</skill>`;
|
|
9
|
+
return additionalInstructions ? `${skillBlock}\n\n${additionalInstructions}` : skillBlock;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Load skills from one or more directories.
|
|
13
|
+
*
|
|
14
|
+
* Traverses directories recursively, loads `SKILL.md` files, loads direct root `.md` files as skills, honors ignore files,
|
|
15
|
+
* and returns diagnostics for invalid skill files. Missing input directories are skipped.
|
|
16
|
+
*/
|
|
17
|
+
export async function loadSkills(env, dirs) {
|
|
18
|
+
const skills = [];
|
|
19
|
+
const diagnostics = [];
|
|
20
|
+
for (const dir of Array.isArray(dirs) ? dirs : [dirs]) {
|
|
21
|
+
const rootInfo = await safeFileInfo(env, dir);
|
|
22
|
+
if (!rootInfo || (await resolveKind(env, rootInfo)) !== "directory")
|
|
23
|
+
continue;
|
|
24
|
+
const result = await loadSkillsFromDirInternal(env, rootInfo.path, true, ignore(), rootInfo.path);
|
|
25
|
+
skills.push(...result.skills);
|
|
26
|
+
diagnostics.push(...result.diagnostics);
|
|
27
|
+
}
|
|
28
|
+
return { skills, diagnostics };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Load skills from source-tagged directories.
|
|
32
|
+
*
|
|
33
|
+
* Source values are preserved exactly and attached to every loaded skill and diagnostic. The agent package does not
|
|
34
|
+
* interpret source values; applications define their own provenance shape.
|
|
35
|
+
*/
|
|
36
|
+
export async function loadSourcedSkills(env, inputs, mapSkill) {
|
|
37
|
+
const skills = [];
|
|
38
|
+
const diagnostics = [];
|
|
39
|
+
for (const input of inputs) {
|
|
40
|
+
const result = await loadSkills(env, input.path);
|
|
41
|
+
for (const skill of result.skills) {
|
|
42
|
+
skills.push({ skill: mapSkill ? mapSkill(skill, input.source) : skill, source: input.source });
|
|
43
|
+
}
|
|
44
|
+
for (const diagnostic of result.diagnostics)
|
|
45
|
+
diagnostics.push({ ...diagnostic, source: input.source });
|
|
46
|
+
}
|
|
47
|
+
return { skills, diagnostics };
|
|
48
|
+
}
|
|
49
|
+
async function loadSkillsFromDirInternal(env, dir, includeRootFiles, ignoreMatcher, rootDir) {
|
|
50
|
+
const skills = [];
|
|
51
|
+
const diagnostics = [];
|
|
52
|
+
if (!(await env.exists(dir)))
|
|
53
|
+
return { skills, diagnostics };
|
|
54
|
+
const dirInfo = await safeFileInfo(env, dir);
|
|
55
|
+
if (!dirInfo || (await resolveKind(env, dirInfo)) !== "directory")
|
|
56
|
+
return { skills, diagnostics };
|
|
57
|
+
await addIgnoreRules(env, ignoreMatcher, dir, rootDir);
|
|
58
|
+
let entries;
|
|
59
|
+
try {
|
|
60
|
+
entries = await env.listDir(dir);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return { skills, diagnostics };
|
|
64
|
+
}
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
if (entry.name !== "SKILL.md")
|
|
67
|
+
continue;
|
|
68
|
+
const fullPath = entry.path;
|
|
69
|
+
const kind = await resolveKind(env, entry);
|
|
70
|
+
if (kind !== "file")
|
|
71
|
+
continue;
|
|
72
|
+
const relPath = relativeEnvPath(rootDir, fullPath);
|
|
73
|
+
if (ignoreMatcher.ignores(relPath))
|
|
74
|
+
continue;
|
|
75
|
+
const result = await loadSkillFromFile(env, fullPath);
|
|
76
|
+
if (result.skill)
|
|
77
|
+
skills.push(result.skill);
|
|
78
|
+
diagnostics.push(...result.diagnostics);
|
|
79
|
+
return { skills, diagnostics };
|
|
80
|
+
}
|
|
81
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
82
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
83
|
+
continue;
|
|
84
|
+
const fullPath = entry.path;
|
|
85
|
+
const kind = await resolveKind(env, entry);
|
|
86
|
+
if (!kind)
|
|
87
|
+
continue;
|
|
88
|
+
const relPath = relativeEnvPath(rootDir, fullPath);
|
|
89
|
+
const ignorePath = kind === "directory" ? `${relPath}/` : relPath;
|
|
90
|
+
if (ignoreMatcher.ignores(ignorePath))
|
|
91
|
+
continue;
|
|
92
|
+
if (kind === "directory") {
|
|
93
|
+
const result = await loadSkillsFromDirInternal(env, fullPath, false, ignoreMatcher, rootDir);
|
|
94
|
+
skills.push(...result.skills);
|
|
95
|
+
diagnostics.push(...result.diagnostics);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (kind !== "file" || !includeRootFiles || !entry.name.endsWith(".md"))
|
|
99
|
+
continue;
|
|
100
|
+
const result = await loadSkillFromFile(env, fullPath);
|
|
101
|
+
if (result.skill)
|
|
102
|
+
skills.push(result.skill);
|
|
103
|
+
diagnostics.push(...result.diagnostics);
|
|
104
|
+
}
|
|
105
|
+
return { skills, diagnostics };
|
|
106
|
+
}
|
|
107
|
+
async function addIgnoreRules(env, ig, dir, rootDir) {
|
|
108
|
+
const relativeDir = relativeEnvPath(rootDir, dir);
|
|
109
|
+
const prefix = relativeDir ? `${relativeDir}/` : "";
|
|
110
|
+
for (const filename of IGNORE_FILE_NAMES) {
|
|
111
|
+
const ignorePath = joinEnvPath(dir, filename);
|
|
112
|
+
const info = await safeFileInfo(env, ignorePath);
|
|
113
|
+
if (info?.kind !== "file")
|
|
114
|
+
continue;
|
|
115
|
+
try {
|
|
116
|
+
const content = await env.readTextFile(ignorePath);
|
|
117
|
+
const patterns = content
|
|
118
|
+
.split(/\r?\n/)
|
|
119
|
+
.map((line) => prefixIgnorePattern(line, prefix))
|
|
120
|
+
.filter((line) => Boolean(line));
|
|
121
|
+
if (patterns.length > 0)
|
|
122
|
+
ig.add(patterns);
|
|
123
|
+
}
|
|
124
|
+
catch { }
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function prefixIgnorePattern(line, prefix) {
|
|
128
|
+
const trimmed = line.trim();
|
|
129
|
+
if (!trimmed)
|
|
130
|
+
return null;
|
|
131
|
+
if (trimmed.startsWith("#") && !trimmed.startsWith("\\#"))
|
|
132
|
+
return null;
|
|
133
|
+
let pattern = line;
|
|
134
|
+
let negated = false;
|
|
135
|
+
if (pattern.startsWith("!")) {
|
|
136
|
+
negated = true;
|
|
137
|
+
pattern = pattern.slice(1);
|
|
138
|
+
}
|
|
139
|
+
else if (pattern.startsWith("\\!")) {
|
|
140
|
+
pattern = pattern.slice(1);
|
|
141
|
+
}
|
|
142
|
+
if (pattern.startsWith("/"))
|
|
143
|
+
pattern = pattern.slice(1);
|
|
144
|
+
const prefixed = prefix ? `${prefix}${pattern}` : pattern;
|
|
145
|
+
return negated ? `!${prefixed}` : prefixed;
|
|
146
|
+
}
|
|
147
|
+
async function loadSkillFromFile(env, filePath) {
|
|
148
|
+
const diagnostics = [];
|
|
149
|
+
try {
|
|
150
|
+
const rawContent = await env.readTextFile(filePath);
|
|
151
|
+
const { frontmatter, body } = parseFrontmatter(rawContent);
|
|
152
|
+
const skillDir = dirnameEnvPath(filePath);
|
|
153
|
+
const parentDirName = basenameEnvPath(skillDir);
|
|
154
|
+
for (const error of validateDescription(frontmatter.description)) {
|
|
155
|
+
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
156
|
+
}
|
|
157
|
+
const name = frontmatter.name || parentDirName;
|
|
158
|
+
for (const error of validateName(name, parentDirName)) {
|
|
159
|
+
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
160
|
+
}
|
|
161
|
+
if (!frontmatter.description || frontmatter.description.trim() === "") {
|
|
162
|
+
return { skill: null, diagnostics };
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
skill: {
|
|
166
|
+
name,
|
|
167
|
+
description: frontmatter.description,
|
|
168
|
+
content: body,
|
|
169
|
+
filePath,
|
|
170
|
+
disableModelInvocation: frontmatter["disable-model-invocation"] === true,
|
|
171
|
+
},
|
|
172
|
+
diagnostics,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
const message = error instanceof Error ? error.message : "failed to parse skill file";
|
|
177
|
+
diagnostics.push({ type: "warning", message, path: filePath });
|
|
178
|
+
return { skill: null, diagnostics };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function validateName(name, parentDirName) {
|
|
182
|
+
const errors = [];
|
|
183
|
+
if (name !== parentDirName)
|
|
184
|
+
errors.push(`name "${name}" does not match parent directory "${parentDirName}"`);
|
|
185
|
+
if (name.length > MAX_NAME_LENGTH)
|
|
186
|
+
errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);
|
|
187
|
+
if (!/^[a-z0-9-]+$/.test(name)) {
|
|
188
|
+
errors.push("name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)");
|
|
189
|
+
}
|
|
190
|
+
if (name.startsWith("-") || name.endsWith("-"))
|
|
191
|
+
errors.push("name must not start or end with a hyphen");
|
|
192
|
+
if (name.includes("--"))
|
|
193
|
+
errors.push("name must not contain consecutive hyphens");
|
|
194
|
+
return errors;
|
|
195
|
+
}
|
|
196
|
+
function validateDescription(description) {
|
|
197
|
+
const errors = [];
|
|
198
|
+
if (!description || description.trim() === "") {
|
|
199
|
+
errors.push("description is required");
|
|
200
|
+
}
|
|
201
|
+
else if (description.length > MAX_DESCRIPTION_LENGTH) {
|
|
202
|
+
errors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);
|
|
203
|
+
}
|
|
204
|
+
return errors;
|
|
205
|
+
}
|
|
206
|
+
function parseFrontmatter(content) {
|
|
207
|
+
const normalized = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
208
|
+
if (!normalized.startsWith("---"))
|
|
209
|
+
return { frontmatter: {}, body: normalized };
|
|
210
|
+
const endIndex = normalized.indexOf("\n---", 3);
|
|
211
|
+
if (endIndex === -1)
|
|
212
|
+
return { frontmatter: {}, body: normalized };
|
|
213
|
+
const yamlString = normalized.slice(4, endIndex);
|
|
214
|
+
const body = normalized.slice(endIndex + 4).trim();
|
|
215
|
+
return { frontmatter: (parse(yamlString) ?? {}), body };
|
|
216
|
+
}
|
|
217
|
+
async function safeFileInfo(env, path) {
|
|
218
|
+
try {
|
|
219
|
+
return await env.fileInfo(path);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function resolveKind(env, info) {
|
|
226
|
+
if (info.kind === "file" || info.kind === "directory")
|
|
227
|
+
return info.kind;
|
|
228
|
+
try {
|
|
229
|
+
const realPath = await env.realPath(info.path);
|
|
230
|
+
const target = await env.fileInfo(realPath);
|
|
231
|
+
return target.kind === "file" || target.kind === "directory" ? target.kind : undefined;
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function joinEnvPath(base, child) {
|
|
238
|
+
return `${base.replace(/\/+$/, "")}/${child.replace(/^\/+/, "")}`;
|
|
239
|
+
}
|
|
240
|
+
function dirnameEnvPath(path) {
|
|
241
|
+
const normalized = path.replace(/\/+$/, "");
|
|
242
|
+
const slashIndex = normalized.lastIndexOf("/");
|
|
243
|
+
return slashIndex <= 0 ? "/" : normalized.slice(0, slashIndex);
|
|
244
|
+
}
|
|
245
|
+
function basenameEnvPath(path) {
|
|
246
|
+
const normalized = path.replace(/\/+$/, "");
|
|
247
|
+
const slashIndex = normalized.lastIndexOf("/");
|
|
248
|
+
return slashIndex === -1 ? normalized : normalized.slice(slashIndex + 1);
|
|
249
|
+
}
|
|
250
|
+
function relativeEnvPath(root, path) {
|
|
251
|
+
const normalizedRoot = root.replace(/\/+$/, "");
|
|
252
|
+
const normalizedPath = path.replace(/\/+$/, "");
|
|
253
|
+
if (normalizedPath === normalizedRoot)
|
|
254
|
+
return "";
|
|
255
|
+
return normalizedPath.startsWith(`${normalizedRoot}/`)
|
|
256
|
+
? normalizedPath.slice(normalizedRoot.length + 1)
|
|
257
|
+
: normalizedPath.replace(/^\/+/, "");
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=skills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.js","sourceRoot":"","sources":["../../src/harness/skills.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAG7B,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,MAAM,iBAAiB,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAqBjE,2FAA2F;AAC3F,MAAM,UAAU,qBAAqB,CAAC,KAAY,EAAE,sBAA+B,EAAU;IAC5F,MAAM,UAAU,GAAG,gBAAgB,KAAK,CAAC,IAAI,eAAe,KAAK,CAAC,QAAQ,kCAAkC,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,KAAK,CAAC,OAAO,YAAY,CAAC;IAC5K,OAAO,sBAAsB,CAAC,CAAC,CAAC,GAAG,UAAU,OAAO,sBAAsB,EAAE,CAAC,CAAC,CAAC,U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,EAAE,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AAAA,CAC/D;AAED,SAAS,eAAe,CAAC,IAAY,EAAU;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;AAAA,CACzE;AAED,SAAS,eAAe,CAAC,IAAY,EAAE,IAAY,EAAU;IAC5D,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChD,IAAI,cAAc,KAAK,cAAc;QAAE,OAAO,EAAE,CAAC;IACjD,OAAO,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,GAAG,CAAC;QACrD,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;QACjD,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAAA,CACtC","sourcesContent":["import ignore from \"ignore\";\nimport { parse } from \"yaml\";\nimport type { ExecutionEnv, Skill } from \"./types.js\";\n\nconst MAX_NAME_LENGTH = 64;\nconst MAX_DESCRIPTION_LENGTH = 1024;\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\n\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\n/** Warning produced while loading skills. */\nexport interface SkillDiagnostic {\n\t/** Diagnostic severity. Currently only warnings are emitted. */\n\ttype: \"warning\";\n\t/** Human-readable diagnostic message. */\n\tmessage: string;\n\t/** Path associated with the diagnostic. */\n\tpath: string;\n}\n\ninterface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t[key: string]: unknown;\n}\n\n/** Format a skill invocation prompt, optionally appending additional user instructions. */\nexport function formatSkillInvocation(skill: Skill, additionalInstructions?: string): string {\n\tconst skillBlock = `<skill name=\"${skill.name}\" location=\"${skill.filePath}\">\\nReferences are relative to ${dirnameEnvPath(skill.filePath)}.\\n\\n${skill.content}\\n</skill>`;\n\treturn additionalInstructions ? `${skillBlock}\\n\\n${additionalInstructions}` : skillBlock;\n}\n\n/**\n * Load skills from one or more directories.\n *\n * Traverses directories recursively, loads `SKILL.md` files, loads direct root `.md` files as skills, honors ignore files,\n * and returns diagnostics for invalid skill files. Missing input directories are skipped.\n */\nexport async function loadSkills(\n\tenv: ExecutionEnv,\n\tdirs: string | string[],\n): Promise<{ skills: Skill[]; diagnostics: SkillDiagnostic[] }> {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: SkillDiagnostic[] = [];\n\tfor (const dir of Array.isArray(dirs) ? dirs : [dirs]) {\n\t\tconst rootInfo = await safeFileInfo(env, dir);\n\t\tif (!rootInfo || (await resolveKind(env, rootInfo)) !== \"directory\") continue;\n\t\tconst result = await loadSkillsFromDirInternal(env, rootInfo.path, true, ignore(), rootInfo.path);\n\t\tskills.push(...result.skills);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\treturn { skills, diagnostics };\n}\n\n/**\n * Load skills from source-tagged directories.\n *\n * Source values are preserved exactly and attached to every loaded skill and diagnostic. The agent package does not\n * interpret source values; applications define their own provenance shape.\n */\nexport async function loadSourcedSkills<TSource, TSkill extends Skill = Skill>(\n\tenv: ExecutionEnv,\n\tinputs: Array<{ path: string; source: TSource }>,\n\tmapSkill?: (skill: Skill, source: TSource) => TSkill,\n): Promise<{\n\tskills: Array<{ skill: TSkill; source: TSource }>;\n\tdiagnostics: Array<SkillDiagnostic & { source: TSource }>;\n}> {\n\tconst skills: Array<{ skill: TSkill; source: TSource }> = [];\n\tconst diagnostics: Array<SkillDiagnostic & { source: TSource }> = [];\n\tfor (const input of inputs) {\n\t\tconst result = await loadSkills(env, input.path);\n\t\tfor (const skill of result.skills) {\n\t\t\tskills.push({ skill: mapSkill ? mapSkill(skill, input.source) : (skill as TSkill), source: input.source });\n\t\t}\n\t\tfor (const diagnostic of result.diagnostics) diagnostics.push({ ...diagnostic, source: input.source });\n\t}\n\treturn { skills, diagnostics };\n}\n\nasync function loadSkillsFromDirInternal(\n\tenv: ExecutionEnv,\n\tdir: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher: IgnoreMatcher,\n\trootDir: string,\n): Promise<{ skills: Skill[]; diagnostics: SkillDiagnostic[] }> {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: SkillDiagnostic[] = [];\n\n\tif (!(await env.exists(dir))) return { skills, diagnostics };\n\tconst dirInfo = await safeFileInfo(env, dir);\n\tif (!dirInfo || (await resolveKind(env, dirInfo)) !== \"directory\") return { skills, diagnostics };\n\n\tawait addIgnoreRules(env, ignoreMatcher, dir, rootDir);\n\n\tlet entries: Awaited<ReturnType<ExecutionEnv[\"listDir\"]>>;\n\ttry {\n\t\tentries = await env.listDir(dir);\n\t} catch {\n\t\treturn { skills, diagnostics };\n\t}\n\n\tfor (const entry of entries) {\n\t\tif (entry.name !== \"SKILL.md\") continue;\n\t\tconst fullPath = entry.path;\n\t\tconst kind = await resolveKind(env, entry);\n\t\tif (kind !== \"file\") continue;\n\t\tconst relPath = relativeEnvPath(rootDir, fullPath);\n\t\tif (ignoreMatcher.ignores(relPath)) continue;\n\n\t\tconst result = await loadSkillFromFile(env, fullPath);\n\t\tif (result.skill) skills.push(result.skill);\n\t\tdiagnostics.push(...result.diagnostics);\n\t\treturn { skills, diagnostics };\n\t}\n\n\tfor (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n\t\tif (entry.name.startsWith(\".\") || entry.name === \"node_modules\") continue;\n\t\tconst fullPath = entry.path;\n\t\tconst kind = await resolveKind(env, entry);\n\t\tif (!kind) continue;\n\n\t\tconst relPath = relativeEnvPath(rootDir, fullPath);\n\t\tconst ignorePath = kind === \"directory\" ? `${relPath}/` : relPath;\n\t\tif (ignoreMatcher.ignores(ignorePath)) continue;\n\n\t\tif (kind === \"directory\") {\n\t\t\tconst result = await loadSkillsFromDirInternal(env, fullPath, false, ignoreMatcher, rootDir);\n\t\t\tskills.push(...result.skills);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (kind !== \"file\" || !includeRootFiles || !entry.name.endsWith(\".md\")) continue;\n\t\tconst result = await loadSkillFromFile(env, fullPath);\n\t\tif (result.skill) skills.push(result.skill);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\n\treturn { skills, diagnostics };\n}\n\nasync function addIgnoreRules(env: ExecutionEnv, ig: IgnoreMatcher, dir: string, rootDir: string): Promise<void> {\n\tconst relativeDir = relativeEnvPath(rootDir, dir);\n\tconst prefix = relativeDir ? `${relativeDir}/` : \"\";\n\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePath = joinEnvPath(dir, filename);\n\t\tconst info = await safeFileInfo(env, ignorePath);\n\t\tif (info?.kind !== \"file\") continue;\n\t\ttry {\n\t\t\tconst content = await env.readTextFile(ignorePath);\n\t\t\tconst patterns = content\n\t\t\t\t.split(/\\r?\\n/)\n\t\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t\t.filter((line): line is string => Boolean(line));\n\t\t\tif (patterns.length > 0) ig.add(patterns);\n\t\t} catch {}\n\t}\n}\n\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\n\tlet pattern = line;\n\tlet negated = false;\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\tif (pattern.startsWith(\"/\")) pattern = pattern.slice(1);\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\n\nasync function loadSkillFromFile(\n\tenv: ExecutionEnv,\n\tfilePath: string,\n): Promise<{ skill: Skill | null; diagnostics: SkillDiagnostic[] }> {\n\tconst diagnostics: SkillDiagnostic[] = [];\n\ttry {\n\t\tconst rawContent = await env.readTextFile(filePath);\n\t\tconst { frontmatter, body } = parseFrontmatter<SkillFrontmatter>(rawContent);\n\t\tconst skillDir = dirnameEnvPath(filePath);\n\t\tconst parentDirName = basenameEnvPath(skillDir);\n\n\t\tfor (const error of validateDescription(frontmatter.description)) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\tconst name = frontmatter.name || parentDirName;\n\t\tfor (const error of validateName(name, parentDirName)) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\tif (!frontmatter.description || frontmatter.description.trim() === \"\") {\n\t\t\treturn { skill: null, diagnostics };\n\t\t}\n\n\t\treturn {\n\t\t\tskill: {\n\t\t\t\tname,\n\t\t\t\tdescription: frontmatter.description,\n\t\t\t\tcontent: body,\n\t\t\t\tfilePath,\n\t\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t\t},\n\t\t\tdiagnostics,\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse skill file\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n}\n\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\tif (name !== parentDirName) errors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\tif (name.length > MAX_NAME_LENGTH) errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(\"name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)\");\n\t}\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) errors.push(\"name must not start or end with a hyphen\");\n\tif (name.includes(\"--\")) errors.push(\"name must not contain consecutive hyphens\");\n\treturn errors;\n}\n\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\treturn errors;\n}\n\nfunction parseFrontmatter<T extends Record<string, unknown>>(content: string): { frontmatter: T; body: string } {\n\tconst normalized = content.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n\tif (!normalized.startsWith(\"---\")) return { frontmatter: {} as T, body: normalized };\n\tconst endIndex = normalized.indexOf(\"\\n---\", 3);\n\tif (endIndex === -1) return { frontmatter: {} as T, body: normalized };\n\tconst yamlString = normalized.slice(4, endIndex);\n\tconst body = normalized.slice(endIndex + 4).trim();\n\treturn { frontmatter: (parse(yamlString) ?? {}) as T, body };\n}\n\nasync function safeFileInfo(\n\tenv: ExecutionEnv,\n\tpath: string,\n): Promise<Awaited<ReturnType<ExecutionEnv[\"fileInfo\"]>> | undefined> {\n\ttry {\n\t\treturn await env.fileInfo(path);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function resolveKind(\n\tenv: ExecutionEnv,\n\tinfo: Awaited<ReturnType<ExecutionEnv[\"fileInfo\"]>>,\n): Promise<\"file\" | \"directory\" | undefined> {\n\tif (info.kind === \"file\" || info.kind === \"directory\") return info.kind;\n\ttry {\n\t\tconst realPath = await env.realPath(info.path);\n\t\tconst target = await env.fileInfo(realPath);\n\t\treturn target.kind === \"file\" || target.kind === \"directory\" ? target.kind : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction joinEnvPath(base: string, child: string): string {\n\treturn `${base.replace(/\\/+$/, \"\")}/${child.replace(/^\\/+/, \"\")}`;\n}\n\nfunction dirnameEnvPath(path: string): string {\n\tconst normalized = path.replace(/\\/+$/, \"\");\n\tconst slashIndex = normalized.lastIndexOf(\"/\");\n\treturn slashIndex <= 0 ? \"/\" : normalized.slice(0, slashIndex);\n}\n\nfunction basenameEnvPath(path: string): string {\n\tconst normalized = path.replace(/\\/+$/, \"\");\n\tconst slashIndex = normalized.lastIndexOf(\"/\");\n\treturn slashIndex === -1 ? normalized : normalized.slice(slashIndex + 1);\n}\n\nfunction relativeEnvPath(root: string, path: string): string {\n\tconst normalizedRoot = root.replace(/\\/+$/, \"\");\n\tconst normalizedPath = path.replace(/\\/+$/, \"\");\n\tif (normalizedPath === normalizedRoot) return \"\";\n\treturn normalizedPath.startsWith(`${normalizedRoot}/`)\n\t\t? normalizedPath.slice(normalizedRoot.length + 1)\n\t\t: normalizedPath.replace(/^\\/+/, \"\");\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/harness/system-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAsBnE","sourcesContent":["import type { Skill } from \"./types.js\";\n\nexport function formatSkillsForSystemPrompt(skills: Skill[]): string {\n\tconst visibleSkills = skills.filter((skill) => !skill.disableModelInvocation);\n\tif (visibleSkills.length === 0) return \"\";\n\n\tconst lines = [\n\t\t\"The following skills provide specialized instructions for specific tasks.\",\n\t\t\"Read the full skill file when the task matches its description.\",\n\t\t\"When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.\",\n\t\t\"\",\n\t\t\"<available_skills>\",\n\t];\n\n\tfor (const skill of visibleSkills) {\n\t\tlines.push(\" <skill>\");\n\t\tlines.push(` <name>${escapeXml(skill.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(skill.description)}</description>`);\n\t\tlines.push(` <location>${escapeXml(skill.filePath)}</location>`);\n\t\tlines.push(\" </skill>\");\n\t}\n\n\tlines.push(\"</available_skills>\");\n\treturn lines.join(\"\\n\");\n}\n\nfunction escapeXml(value: string): string {\n\treturn value\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\")\n\t\t.replace(/'/g, \"'\");\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function formatSkillsForSystemPrompt(skills) {
|
|
2
|
+
const visibleSkills = skills.filter((skill) => !skill.disableModelInvocation);
|
|
3
|
+
if (visibleSkills.length === 0)
|
|
4
|
+
return "";
|
|
5
|
+
const lines = [
|
|
6
|
+
"The following skills provide specialized instructions for specific tasks.",
|
|
7
|
+
"Read the full skill file when the task matches its description.",
|
|
8
|
+
"When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.",
|
|
9
|
+
"",
|
|
10
|
+
"<available_skills>",
|
|
11
|
+
];
|
|
12
|
+
for (const skill of visibleSkills) {
|
|
13
|
+
lines.push(" <skill>");
|
|
14
|
+
lines.push(` <name>${escapeXml(skill.name)}</name>`);
|
|
15
|
+
lines.push(` <description>${escapeXml(skill.description)}</description>`);
|
|
16
|
+
lines.push(` <location>${escapeXml(skill.filePath)}</location>`);
|
|
17
|
+
lines.push(" </skill>");
|
|
18
|
+
}
|
|
19
|
+
lines.push("</available_skills>");
|
|
20
|
+
return lines.join("\n");
|
|
21
|
+
}
|
|
22
|
+
function escapeXml(value) {
|
|
23
|
+
return value
|
|
24
|
+
.replace(/&/g, "&")
|
|
25
|
+
.replace(/</g, "<")
|
|
26
|
+
.replace(/>/g, ">")
|
|
27
|
+
.replace(/"/g, """)
|
|
28
|
+
.replace(/'/g, "'");
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=system-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/harness/system-prompt.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,2BAA2B,CAAC,MAAe,EAAU;IACpE,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC9E,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAE1C,MAAM,KAAK,GAAG;QACb,2EAA2E;QAC3E,iEAAiE;QACjE,8KAA8K;QAC9K,EAAE;QACF,oBAAoB;KACpB,CAAC;IAEF,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACxB,KAAK,CAAC,IAAI,CAAC,aAAa,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxD,KAAK,CAAC,IAAI,CAAC,oBAAoB,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;QAC7E,KAAK,CAAC,IAAI,CAAC,iBAAiB,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QACpE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACxB;AAED,SAAS,SAAS,CAAC,KAAa,EAAU;IACzC,OAAO,KAAK;SACV,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAAA,CAC1B","sourcesContent":["import type { Skill } from \"./types.js\";\n\nexport function formatSkillsForSystemPrompt(skills: Skill[]): string {\n\tconst visibleSkills = skills.filter((skill) => !skill.disableModelInvocation);\n\tif (visibleSkills.length === 0) return \"\";\n\n\tconst lines = [\n\t\t\"The following skills provide specialized instructions for specific tasks.\",\n\t\t\"Read the full skill file when the task matches its description.\",\n\t\t\"When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.\",\n\t\t\"\",\n\t\t\"<available_skills>\",\n\t];\n\n\tfor (const skill of visibleSkills) {\n\t\tlines.push(\" <skill>\");\n\t\tlines.push(` <name>${escapeXml(skill.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(skill.description)}</description>`);\n\t\tlines.push(` <location>${escapeXml(skill.filePath)}</location>`);\n\t\tlines.push(\" </skill>\");\n\t}\n\n\tlines.push(\"</available_skills>\");\n\treturn lines.join(\"\\n\");\n}\n\nfunction escapeXml(value: string): string {\n\treturn value\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\")\n\t\t.replace(/'/g, \"'\");\n}\n"]}
|