Files
PrismFacet/plugin/hooks/before-prompt-build.ts
zhi d5c057a3f9 refactor: restructure PrismFacet per OpenClaw plugin spec
- plugin/ directory structure: hooks/, tools/, core/
- export default { id, name, register } entry format
- globalThis state management with lifecycle protection
- WeakSet dedup on before_prompt_build hook
- Tool uses inputSchema + execute (not parameters + handler)
- additionalProperties: false in config schema
- Core logic in plugin/core/ (no plugin-sdk dependency)
- Install/uninstall script (scripts/install.mjs)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-18 17:22:17 +00:00

26 lines
889 B
TypeScript

import { resolveInjection } from "../core/prompt-injector.js";
const _G = globalThis as Record<string, unknown>;
const DEDUP_KEY = "_prismFacetBPBDedup";
export function registerBeforePromptBuild(api: {
on(hook: string, handler: (...args: any[]) => any): void;
logger: { info(msg: string): void; warn(msg: string): void };
}): void {
if (!(_G[DEDUP_KEY] instanceof WeakSet)) _G[DEDUP_KEY] = new WeakSet<object>();
const dedup = _G[DEDUP_KEY] as WeakSet<object>;
api.on("before_prompt_build", async (event: unknown, ctx: { agentId?: string }) => {
if (dedup.has(event as object)) return;
dedup.add(event as object);
const agentId = ctx.agentId || "";
if (!agentId) return;
const result = await resolveInjection({ agentId }, api.logger);
if (result.appendSystemContext) {
return { appendSystemContext: result.appendSystemContext };
}
});
}