File size: 2,198 Bytes
fc93158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require("fs");

let content = fs.readFileSync("src/auto-reply/reply/get-reply.ts", "utf-8");

const imports = `
import { getNeuralLogicEngine } from "../../omega/neural-logic-engine.js";
import { HolographicMemoryManager } from "../../omega/holographic-memory.js";
`;

content = content.replace(
  'import { runPreparedReply } from "./get-reply-run.js";',
  'import { runPreparedReply } from "./get-reply-run.js";' + imports,
);

const logic = `
  const finalized = finalizeInboundContext(ctx);

  // --- OMEGA NEURAL LOGIC INJECTION ---
  if (!isFastTestEnv) {
    try {
      const nle = getNeuralLogicEngine();
      const hmem = new HolographicMemoryManager(workspaceDir);
      await hmem.initialize();
      
      const bodyText = finalized.Body ?? "";
      if (bodyText.trim().length > 0) {
        // Record into holographic memory
        const fossilId = await hmem.fossilize(bodyText, { 
          source: "user_input", 
          sessionKey: agentSessionKey 
        });
        
        // Basic feature extraction for latent state (dummy features for now, to be replaced by true embedding)
        const latentState = [
          Math.min(1, bodyText.length / 500),
          bodyText.includes("?") ? 0.8 : 0.2,
          bodyText.match(/error|fail|bug|wrong|bad/i) ? 0.9 : 0.1,
        ];
        
        const nleState = nle.infer(latentState);
        
        // Inject NLE context into the system prompt implicitly
        if (nleState.activeRules.length > 0) {
          const nleContext = \`[Omega NLE Active: \${nleState.activeRules.join(",")} | Confidence: \${nleState.inferenceConfidence.toFixed(2)} | Delta: \${nleState.logicalDelta[0].toFixed(2)}]\`;
          finalized.UntrustedContext = finalized.UntrustedContext ? finalized.UntrustedContext + "\\n" + nleContext : nleContext;
        }
      }
    } catch (e) {
      console.warn("[Omega] Failed to run Neural Logic Engine on inbound message:", e);
    }
  }
  // ------------------------------------
`;

content = content.replace("  const finalized = finalizeInboundContext(ctx);", logic);

fs.writeFileSync("src/auto-reply/reply/get-reply.ts", content, "utf-8");
console.log("Patched get-reply.ts");