Download Game! Currently 71 players and visitors. Last logged in:WhlxchGlauriCordobaDefault

Blitzer's Blog >> 72529

Back to blogs index
Posted: 16 Sep 2026 06:43 [ permalink ]
You are completely right on all fronts. I owe you an apologymy regex patch
script mangled the backticks inside the JavaScript template literal, which
caused Node to read ````fso-state` as raw code and instantly crash.
More importantly, your philosophy about making the engine FRIENDLY and
building a deterministic auto-corrector is exactly how compilers work in the
real world. We shouldn't punish the AI for tiny syntax mistakes if our
pipeline can easily infer its intent.
If Gemma accidentally lowercases a verb or names the init label
init_glass_bottle instead of init_healing_potion, our pipeline should silently
fix it before it even hits the VM.
Let's do a complete, clean overwrite of compiler.js to fix the syntax crash,
and patch forge.js with a brilliant little auto-corrector.
1. The Clean Compiler
Run this to completely overwrite compiler.js with correct, properly escaped
JavaScript syntax:
cat << 'EOF' > compiler.js
export class SemanticCompiler {
    constructor() {
        this.baseUrl = "[http://100.111.184.107:8080/v1/chat/completions](http:
//100.111.184.107:8080/v1/chat/completions)";
        this.model = "gemma-2-9b-it";
    }

    async compile(naturalLanguageIntent) {
        const systemPrompt = `
You are a deterministic FSO bytecode compiler. Translate the user's item into
bytecode.
Output ONLY the markdown envelope (\`\`\`fso-state and \`\`\`fso-code). No
chat.

MINIMAL OPCODES:
- VAR [NAME] [TYPE] [VALUE] (Types: STR, NUM, BOOL, ARR)
- SET [NAME] [VALUE]
- MATH [NAME] [OPERATOR] [VALUE] (+, -, *, /)
- JMP_IF [VAR] [==/!=/HAS/CONTAINS] "[VALUE]" [LABEL]
- OUT "[STRING]"
- ACTION "[VERB]" [LABEL]
- AWAIT

SHADOW VARIABLES (CRITICAL RULES):
1. To modify the room, prefix variables with ENVIRONMENT_ (e.g.,
ENVIRONMENT_LIGHT).
2. To save the item's own state, you MUST prefix variables with THIS_ (e.g.,
THIS_OPEN).

NAMING CONVENTION:
1. Your first label MUST be exactly: LBL init_[ITEM_NAME_IN_LOWERCASE]
2. That init label must register ACTIONs and end with AWAIT.

EXAMPLE OUTPUT FORMAT:
\`\`\`fso-state
VAR THIS_EMPTY BOOL "false"
\`\`\`
\`\`\`fso-code
LBL init_healing_potion
ACTION "DRINK" drink_potion
AWAIT

LBL drink_potion
JMP_IF THIS_EMPTY == "true" potion_empty
SET THIS_EMPTY "true"
MATH ENVIRONMENT_HEALTH + 25
OUT "You drink the potion. Health is now {ENVIRONMENT_HEALTH}."
AWAIT

LBL potion_empty
OUT "The bottle is empty."
AWAIT
\`\`\`
`.trim();

        const payload = {
            model: this.model,
            messages: [
                { role: "system", content: systemPrompt },
                { role: "user", content: naturalLanguageIntent }
            ],
            temperature: 0.1 
        };

        const response = await fetch(this.baseUrl, {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify(payload)
        });
        const data = await response.json();
        return data.choices[0].message.content.replace(/<[^>]+>/g, '').trim();
    }
}
EOF

2. The Deterministic Auto-Corrector (forge.js)
We will intercept the artifact right after Gemma generates it, but before we
save it to disk.
Because we know the filename (e.g., healing_potion.md), we can forcefully
rewrite the init_ label to guarantee the engine's event pump will hook it, and
forcefully uppercase all action verbs.
Run this patch:
cat << 'EOF' > patch_forge_corrector.js
import fs from 'fs';

let forgeCode = fs.readFileSync('forge.js', 'utf-8');

/ Ensure path is imported
if (!forgeCode.includes("import path from 'path';")) {
    forgeCode = `import path from 'path';
` + forgeCode;
}

const correctorLogic = `
        let artifact = await compiler.compile(description);
        
        // --- THE FRIENDLY AUTO-CORRECTOR ---
        const cleanName = path.basename(outputFile, '.md').toLowerCase();
        
        // 1. Forgive bad init labels (forces it to match the filename)
        artifact = artifact.replace(/LBL init_[a-zA-Z0-9_]+/i, \`LBL
init_\${cleanName}\`);
        
        // 2. Forgive lowercased action verbs
        artifact = artifact.replace(/ACTION "([^"]+)"/g, (match, verb) =>
\`ACTION "\${verb.toUpperCase()}"\`);
        // -----------------------------------

        fs.writeFileSync(outputFile, artifact);
`;

forgeCode = forgeCode.replace(
    /const artifact = await compiler\.compile\(description\);\s*fs\.writeFileSy
nc\(outputFile, artifact\);/,
    correctorLogic
);

fs.writeFileSync('forge.js', forgeCode);
console.log('[SYS] Deterministic Auto-Corrector installed in forge.js!');
EOF

node patch_forge_corrector.js

Run the Pipeline Again!
Now that the syntax crash is fixed and the safety net is in place, let's run
the exact same command.
./run_ci.sh healing_potion "A glass bottle containing red liquid. If the
player drinks it, it increases ENVIRONMENT_HEALTH by 25 and sets THIS_EMPTY to
true."

If Gemma hallucinates LBL init_glass_bottle again, forge.js will silently
correct it to LBL init_healing_potion before writing it to disk.
Let's see the trace!