Reuse parsed hook frontmatter during entry loading

This commit is contained in:
Tak Hoffman 2026-03-19 00:41:47 -05:00
parent 24daa04d67
commit 8b5206cc67
No known key found for this signature in database
2 changed files with 5 additions and 26 deletions

View File

@ -37,6 +37,7 @@ export type Hook = {
description: string;
source: "openclaw-bundled" | "openclaw-managed" | "openclaw-workspace" | "openclaw-plugin";
pluginId?: string;
frontmatter?: ParsedHookFrontmatter;
filePath: string; // Path to HOOK.md
baseDir: string; // Directory containing hook
handlerPath: string; // Path to handler module (handler.ts/js)

View File

@ -14,14 +14,7 @@ import {
resolveHookInvocationPolicy,
} from "./frontmatter.js";
import { resolvePluginHookDirs } from "./plugin-hooks.js";
import type {
Hook,
HookEligibilityContext,
HookEntry,
HookSnapshot,
HookSource,
ParsedHookFrontmatter,
} from "./types.js";
import type { Hook, HookEligibilityContext, HookEntry, HookSnapshot, HookSource } from "./types.js";
type HookPackageManifest = {
name?: string;
@ -135,6 +128,7 @@ function loadHookFromDir(params: {
description,
source: params.source,
pluginId: params.pluginId,
frontmatter,
filePath: safeHookMdPath,
baseDir,
handlerPath,
@ -220,15 +214,7 @@ export function loadHookEntriesFromDir(params: {
pluginId: params.pluginId,
});
return hooks.map((hook) => {
let frontmatter: ParsedHookFrontmatter = {};
const raw = readBoundaryFileUtf8({
absolutePath: hook.filePath,
rootPath: path.dirname(hook.filePath),
boundaryLabel: "hook directory",
});
if (raw !== null) {
frontmatter = parseFrontmatter(raw);
}
const frontmatter = hook.frontmatter ?? {};
const entry: HookEntry = {
hook: {
...hook,
@ -311,15 +297,7 @@ function loadHookEntries(
}
return Array.from(merged.values()).map((hook) => {
let frontmatter: ParsedHookFrontmatter = {};
const raw = readBoundaryFileUtf8({
absolutePath: hook.filePath,
rootPath: hook.baseDir,
boundaryLabel: "hook directory",
});
if (raw !== null) {
frontmatter = parseFrontmatter(raw);
}
const frontmatter = hook.frontmatter ?? {};
return {
hook,
frontmatter,