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>
This commit is contained in:
25
plugin/hooks/before-prompt-build.ts
Normal file
25
plugin/hooks/before-prompt-build.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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 };
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user