phase2-4 recall prompt-flow hardening

This commit is contained in:
Youzini-afk
2026-04-11 18:51:50 +08:00
parent 3a10dbb9ba
commit 0cb95c4f2b
14 changed files with 1069 additions and 143 deletions

View File

@@ -1,11 +1,27 @@
import { register, registerHooks } from "node:module";
const DEFAULT_REGEX_ENGINE_HOOK_ENTRIES = Object.freeze([
{
specifiers: ["../../../../regex/engine.js"],
url: toDataModuleUrl([
"export const regex_placement = { USER_INPUT: 1, AI_OUTPUT: 2, SLASH_COMMAND: 3, WORLD_INFO: 5, REASONING: 6 };",
"export function getRegexedString(...args) {",
" const fn = globalThis.__taskRegexTestCoreGetRegexedString;",
" return typeof fn === 'function' ? fn(...args) : String(args?.[0] ?? '');",
"}",
].join("\n")),
},
]);
export function toDataModuleUrl(source = "") {
return `data:text/javascript,${encodeURIComponent(String(source || ""))}`;
}
export function installResolveHooks(entries = []) {
const normalizedEntries = (Array.isArray(entries) ? entries : [])
const normalizedEntries = [
...(Array.isArray(entries) ? entries : []),
...DEFAULT_REGEX_ENGINE_HOOK_ENTRIES,
]
.map((entry) => ({
specifiers: Array.isArray(entry?.specifiers)
? entry.specifiers.map((value) => String(value || "")).filter(Boolean)