refactor(prism-facet): become a pure registration framework

Strip all Hangman-Lab-specific content out of PrismFacet so it can be
reused by any project. Content (always router, pcexec-convention prompt,
fabric-chat-injector hook) moves to the new sibling plugin ClawPrompts.

Mechanism additions:
- `globalThis.__prismFacet` cross-plugin API installed at module-import
  time (so consumers loaded before PrismFacet can still register):
    .addRouter(name, resolveFn)
    .addRule(router, key, { file })
- core/rule-store: tier rules into `persistent` (rules.json, mutated by
  the prompt-rules admin tool) and `external` (in-memory, registered by
  other plugins via the API). Persistent overrides external on conflict.
- core/router-loader: addExternalRouter() for programmatic registration
  into the same map the file-based loader uses.
- index.ts: drops registerFabricChatInjector wiring, registerBeforePromptBuild
  remains.

Removed (now shipped from ClawPrompts):
- plugin/routers/always.ts
- plugin/hooks/fabric-chat-injector.ts
- plugin/prompts/pcexec-convention.md
- plugin/rules.json: now `{}`; ClawPrompts registers its rule externally

What still lives in PrismFacet:
- before_prompt_build hook (the wiring between routers/rules and the
  agent's system prompt)
- prompt-rules admin tool (lists + mutates persistent rules)
- file-based routersDir / rulesFile scanning (kept for operator ad-hoc
  use; ClawPrompts uses the API instead)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
h z
2026-05-25 10:19:39 +01:00
parent b0fd02c50b
commit 241cced780
11 changed files with 175 additions and 146 deletions

View File

@@ -1,8 +1,30 @@
/**
* PrismFacet — prompt-rule registration framework.
*
* Provides:
* - router loader (file-based: routersDir + programmatic: __prismFacet.addRouter)
* - rule store (persistent rules.json + in-memory external rules)
* - before_prompt_build hook that resolves all loaded routers/rules
* and appends the matching prompt fragments to the agent's system
* prompt
* - prompt-rules admin tool to inspect / mutate persistent rules
* - cross-plugin API installed at module load time (globalThis.__prismFacet)
*
* PrismFacet ships NO content of its own — the routers/, prompts/, and
* rules.json directories are empty placeholders. Hangman-Lab-specific
* routers and rules live in the ClawPrompts plugin, which registers
* them at startup via the cross-plugin API.
*/
import path from "node:path";
// Importing core/cross-plugin-api.ts has a side-effect: it installs
// globalThis.__prismFacet at module-import time. Doing this side-effect
// import early — before any other plugin's register() — means a
// consumer plugin (ClawPrompts) loaded before us still finds a working
// __prismFacet to call into.
import "./core/cross-plugin-api.js";
import { loadRouters } from "./core/router-loader.js";
import { initRuleStore } from "./core/rule-store.js";
import { registerBeforePromptBuild } from "./hooks/before-prompt-build.js";
import { registerFabricChatInjector } from "./hooks/fabric-chat-injector.js";
import { registerPromptRulesTool } from "./tools/prompt-rules.js";
interface PluginConfig {
@@ -58,11 +80,10 @@ export default {
// Agent session hooks: register every time (dedup inside handler)
registerBeforePromptBuild(api);
registerFabricChatInjector(api);
// Tools
registerPromptRulesTool(api, routersDir);
api.logger.info("[prism-facet] plugin registered");
api.logger.info("[prism-facet] plugin registered (framework only — content via ClawPrompts)");
},
};