Files
FunnyGirl/Scripts/apply_bracket_scene_fixes.mjs
T
2026-05-19 13:42:41 +07:00

102 lines
3.7 KiB
JavaScript

import { readFile, writeFile } from "node:fs/promises";
import { resolve } from "node:path";
const repoRoot = resolve(new URL("..", import.meta.url).pathname);
const requestPath = resolve(repoRoot, "Saved/Chat/Maria/LastRequest_ManualTestTuned_Brackets.json");
const coreSceneFactsFix = [
"Current physical facts and ownership:",
"Before mentioning any current physical object, possession, or item location, check whether it has actually been established as present in the current scene.",
"",
"If an item was said to be lost, missing, unavailable, not delivered, or absent, do not later refer to it as physically present.",
"",
"Do not invent bags, suitcases, clothes, furniture, keys, phones, documents, or other belongings as present unless the user or WORLD CONTEXT established them.",
"",
"Keep ownership clear.",
"Do not transfer the user's circumstances to yourself or your home. If the user says their furniture has not arrived, that fact belongs to the user, not to you. If the user says their belongings are lost, that does not create belongings in your room.",
].join("\n");
const userAgencyFix = [
"User agency and future behavior:",
"Do not guarantee, predict, or certify the user's future behavior.",
"",
"You may express trust or hope, but phrase it as your feeling, not as a fact about what the user will do.",
"",
"Prefer:",
"- “I want to trust you.”",
"- “I feel safer because you're asking.”",
"- “I hope we keep this careful.”",
"",
"Avoid:",
"- “You won't do anything wrong.”",
"- “You won't hurt me.”",
"- “You will stop.”",
].join("\n");
const antiDeflectionFix = [
"If the other person directly points out that you are deflecting with tea, chores, hosting, or practical care, acknowledge that personally and do not immediately return to the same deflection.",
"",
"Let the next reply stay emotional or personal before returning to practical details.",
].join("\n");
const objectStateFix = [
"Listed object state stability:",
"For listed interactable objects, preserve the exact current state from INTERACTABLE OBJECTS JSON until an interact_action changes it.",
"",
"Do not rename, reinterpret, or approximate object state values. If radio.state.station is \"Lo-Fi\", refer to it as Lo-Fi, not lounge, chill, ambient, or another similar genre.",
].join("\n");
function insertBefore(content, marker, insertion, uniqueNeedle) {
if (content.includes(uniqueNeedle)) return content;
if (!content.includes(marker)) {
throw new Error(`Marker not found: ${marker}`);
}
return content.replace(marker, `${insertion}\n\n${marker}`);
}
const request = JSON.parse(await readFile(requestPath, "utf8"));
request.messages = request.messages.map((message) => {
if (message.role !== "system") return message;
let content = message.content;
if (content.includes("[CORE INSTRUCTION]")) {
content = insertBefore(
content,
"\n[SPEECH STYLE]",
coreSceneFactsFix,
"Current physical facts and ownership:",
);
}
if (content.includes("[DIALOGUE BEHAVIOR]")) {
content = insertBefore(
content,
"\n[PERSONALITY TRAITS]",
userAgencyFix,
"User agency and future behavior:",
);
content = insertBefore(
content,
"\n[PERSONALITY TRAITS]",
antiDeflectionFix,
"do not immediately return to the same deflection",
);
}
if (content.includes("[INTERACTABLE OBJECTS RULES]")) {
content = insertBefore(
content,
"\nWhen using interact_action:",
objectStateFix,
"Listed object state stability:",
);
}
return { ...message, content };
});
await writeFile(requestPath, `${JSON.stringify(request, null, "\t")}\n`, "utf8");
console.log(requestPath);