Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

skill resolver: read SKILL.md frontmatter through the alias-bounded YAML loader

garrytan0bb11a5cfb85
diff --git a/src/core/data-frontmatter.ts b/src/core/data-frontmatter.ts
index 3ed47b70b5..bc7a67d439 100644
--- a/src/core/data-frontmatter.ts
+++ b/src/core/data-frontmatter.ts
@@ -54,7 +54,7 @@ export class YamlAliasBoundError extends Error {
* keys by length, other nodes as one; shared nodes memoized, a cycle infinite)
* and throws YamlAliasBoundError past the bound, before any caller can walk it.
*/
-export function loadBoundedYaml(text: string, opts: { schema?: Schema } = {}): unknown {
+export function loadBoundedYaml(text: string, opts: { schema?: Schema; json?: boolean } = {}): unknown {
const value = load(text, opts);
const limit = text.length + MAX_YAML_ALIAS_EXPANSION;
const sizes = new Map<object, number>();
diff --git a/src/core/skills/resolver/frontmatter.ts b/src/core/skills/resolver/frontmatter.ts
index f4de092c47..dcbb2392e9 100644
--- a/src/core/skills/resolver/frontmatter.ts
+++ b/src/core/skills/resolver/frontmatter.ts
@@ -2,12 +2,13 @@
* Bounded SKILL.md reader for the resolver: name, description,
* when_to_use, triggers, `disable-model-invocation` and `eligible`, plus
* the first 4 KB of the body. Reads at most 64 KB of a file. Leaf module
- * (js-yaml and the one-line description rule only).
+ * (alias-bounded js-yaml via data-frontmatter.ts and the one-line description rule only).
*
* The body rule matches the Step 1 catalog builder: drop the frontmatter
* fence, trim, keep the first 4,096 UTF-8 bytes without a split character.
*/
-import { CORE_SCHEMA, load } from 'js-yaml';
+import { CORE_SCHEMA } from 'js-yaml';
+import { loadBoundedYaml } from '../../data-frontmatter.ts';
import { oneLineDescription } from '../../skill-description.ts';
export const SKILL_FILE_CAP_BYTES = 64 * 1024;
@@ -34,7 +35,7 @@ export function boundBody(text: string): string {
function yamlFields(raw: string): Record<string, unknown> | null {
try {
- const v = load(raw, { schema: CORE_SCHEMA, json: true });
+ const v = loadBoundedYaml(raw, { schema: CORE_SCHEMA, json: true });
return v && typeof v === 'object' && !Array.isArray(v) ? (v as Record<string, unknown>) : null;
} catch {
return null;
diff --git a/test/skill-resolver-module-graph.test.ts b/test/skill-resolver-module-graph.test.ts
index 49677031b6..6fa35eb36f 100644
--- a/test/skill-resolver-module-graph.test.ts
+++ b/test/skill-resolver-module-graph.test.ts
@@ -25,8 +25,8 @@ function loadedBy(script: string): string[] {
return (JSON.parse(r.stdout.toString().trim().split('\n').pop()!) as string[]).map(f => f.slice(REPO_ROOT.length + 1)).sort();
}
-const LEAF = new Set(['src/core/cjk.ts', 'src/core/fs-durable.ts', 'src/version.ts', 'package.json', 'src/core/skill-description.ts', 'node_modules/js-yaml/dist/js-yaml.mjs']);
-const BUNDLED = new Set(['src/core/skills/bundled.ts', 'src/core/skills/bundled-skills.generated.ts', 'src/core/skill-frontmatter.ts', 'src/core/data-frontmatter.ts', 'src/core/effective-date.ts']);
+const LEAF = new Set(['src/core/cjk.ts', 'src/core/fs-durable.ts', 'src/version.ts', 'package.json', 'src/core/skill-description.ts', 'src/core/data-frontmatter.ts', 'src/core/effective-date.ts', 'node_modules/js-yaml/dist/js-yaml.mjs']);
+const BUNDLED = new Set(['src/core/skills/bundled.ts', 'src/core/skills/bundled-skills.generated.ts', 'src/core/skill-frontmatter.ts']);
const FORBIDDEN = /^(src\/core\/(operations\.ts|engine\.ts|engine-(factory|open|connect|construct)\.ts|pglite-engine|postgres-engine\.ts|skill-catalog\.ts|ai\/)|node_modules\/(@electric-sql|postgres|openai|@anthropic-ai))/;
describe('the skill resolver module graph', () => {