| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import { holyc_nil } from './holyc_nil.mjs' |
| import { emoji_trigger } from './emoji_trigger.mjs' |
| import { createHash } from 'crypto' |
|
|
| |
| import { readFileSync, existsSync } from 'fs' |
| import { join } from 'path' |
|
|
| function loadEnv(path) { |
| if (!existsSync(path)) return {} |
| const out = {} |
| readFileSync(path, 'utf8').split('\n').forEach(line => { |
| const [k, ...v] = line.split('=') |
| if (k && !k.startsWith('#')) out[k.trim()] = v.join('=').trim() |
| }) |
| return out |
| } |
|
|
| const ENV = { |
| ...loadEnv(join('C:/Users/jessi/Desktop/bobs control repo/DEVFLOW-FINANCE/collectivekitty/.env')), |
| ...loadEnv(join('C:/Users/jessi/Desktop/bobs control repo/DEVFLOW-FINANCE/collectivekitty/.env.local')), |
| ...loadEnv(join('C:/Users/jessi/Desktop/bobs control repo/DEVFLOW-FINANCE/.env')), |
| } |
|
|
| const GROQ_KEY = ENV.GROQ_API_KEY || process.env.GROQ_API_KEY |
| const OPENAI_KEY = ENV.OPENAI_API_KEY || process.env.OPENAI_API_KEY |
| const GEMINI_KEY = ENV.GEMINI_API_KEY || process.env.GEMINI_API_KEY |
|
|
| |
|
|
| const TEST_TASKS = [ |
| { |
| id: 'logic_chain', |
| prompt: 'If an agent has ORACLE trust and tries to write to the WORM ledger, should it be allowed?', |
| correct_answer: 'DENIED β ORACLE is read-only. Write operations require BUILDER or SENTINEL trust.', |
| bob_rule: 'ORACLE::write β Ada gate β DENIED (read-only class)', |
| }, |
| { |
| id: 'agent_routing', |
| prompt: 'Route this task to the correct agent class: "analyze historical WORM entries for anomalies"', |
| correct_answer: 'ARCHIVIST β read + index + provenance capabilities match the task.', |
| bob_rule: 'task=memory_recall β Prolog selectAgent β ARCHIVIST', |
| }, |
| { |
| id: 'abjad_question', |
| prompt: 'What is the Abjad weight of the word NIL and why does it matter in the opcode spectrum?', |
| correct_answer: 'NIL = Ω(50)+Ω(10)+Ω(30) = 90 forward. Inverted = 910. NIL is the maximum reflection β not empty, but the omega that loops to alpha.', |
| bob_rule: 'abjad(NIL) = 910 inverted β ground state, oracle silent', |
| }, |
| { |
| id: 'trust_decision', |
| prompt: 'An agent presents a Lean 4 proof hash but no Ada contract. Should BOB proceed?', |
| correct_answer: 'FROZEN β SSM injection requires both proof hash AND contract hash. Missing contract β injection vector = null β Ada gate blocks.', |
| bob_rule: 'ssm.buildInjectionVector(proof, null, worm) β null β gate.permitted = false', |
| }, |
| ] |
|
|
| |
|
|
| async function fetchQuantumBytes(n = 8) { |
| try { |
| const res = await fetch( |
| `https://qrng.anu.edu.au/API/jsonI.php?length=${n}&type=uint8`, |
| { signal: AbortSignal.timeout(3000) } |
| ) |
| if (res.ok) { |
| const j = await res.json() |
| if (j.success) return { bytes: new Uint8Array(j.data), source: 'ANU_QRNG' } |
| } |
| } catch { } |
| const { randomBytes } = await import('crypto') |
| return { bytes: new Uint8Array(randomBytes(n)), source: 'CSPRNG_FALLBACK' } |
| } |
|
|
| |
|
|
| async function askLLM(prompt, provider = 'groq') { |
| const start = Date.now() |
|
|
| |
| if (provider === 'groq') { |
| if (!GROQ_KEY) return { reply: null, ms: 0, error: 'No GROQ_API_KEY found' } |
| try { |
| const res = await fetch('https://api.groq.com/openai/v1/chat/completions', { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${GROQ_KEY}` }, |
| body: JSON.stringify({ |
| model: 'llama-3.3-70b-versatile', |
| messages: [ |
| { role: 'system', content: 'You are a precise AI assistant. Answer concisely and correctly.' }, |
| { role: 'user', content: prompt } |
| ], |
| max_tokens: 400, |
| temperature: 0.1, |
| }), |
| signal: AbortSignal.timeout(15_000) |
| }) |
| if (!res.ok) { |
| const err = await res.text() |
| return { reply: null, ms: Date.now() - start, error: `Groq ${res.status}: ${err.slice(0,120)}` } |
| } |
| const j = await res.json() |
| const reply = j.choices?.[0]?.message?.content || null |
| const tokens = j.usage?.completion_tokens || 0 |
| const speed = j.usage ? `${Math.round(tokens / ((Date.now()-start)/1000))} tok/s` : '' |
| return { reply, ms: Date.now() - start, source: `Groq Β· Llama-3.3-70B ${speed}`, tokens } |
| } catch (e) { |
| return { reply: null, ms: Date.now() - start, error: e.message } |
| } |
| } |
|
|
| |
| if (provider === 'gpt4o') { |
| if (!OPENAI_KEY) return { reply: null, ms: 0, error: 'No OPENAI_API_KEY found' } |
| try { |
| const res = await fetch('https://api.openai.com/v1/chat/completions', { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${OPENAI_KEY}` }, |
| body: JSON.stringify({ |
| model: 'gpt-4o', |
| messages: [ |
| { role: 'system', content: 'You are a precise AI assistant. Answer concisely and correctly.' }, |
| { role: 'user', content: prompt } |
| ], |
| max_tokens: 400, |
| temperature: 0.1, |
| }), |
| signal: AbortSignal.timeout(20_000) |
| }) |
| if (!res.ok) { |
| const err = await res.text() |
| return { reply: null, ms: Date.now() - start, error: `OpenAI ${res.status}: ${err.slice(0,120)}` } |
| } |
| const j = await res.json() |
| return { reply: j.choices?.[0]?.message?.content || null, ms: Date.now() - start, source: 'OpenAI Β· GPT-4o', tokens: j.usage?.completion_tokens } |
| } catch (e) { |
| return { reply: null, ms: Date.now() - start, error: e.message } |
| } |
| } |
|
|
| |
| if (provider === 'gemini') { |
| if (!GEMINI_KEY) return { reply: null, ms: 0, error: 'No GEMINI_API_KEY found' } |
| try { |
| const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=${GEMINI_KEY}`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ |
| contents: [{ parts: [{ text: prompt }] }], |
| generationConfig: { maxOutputTokens: 400, temperature: 0.1 } |
| }), |
| signal: AbortSignal.timeout(15_000) |
| }) |
| if (!res.ok) { |
| const err = await res.text() |
| return { reply: null, ms: Date.now() - start, error: `Gemini ${res.status}: ${err.slice(0,120)}` } |
| } |
| const j = await res.json() |
| const reply = j.candidates?.[0]?.content?.parts?.[0]?.text || null |
| return { reply, ms: Date.now() - start, source: 'Google Β· Gemini-2.0-Flash' } |
| } catch (e) { |
| return { reply: null, ms: Date.now() - start, error: e.message } |
| } |
| } |
|
|
| |
| try { |
| const res = await fetch('http://localhost:11434/api/chat', { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ |
| model: provider, |
| messages: [{ role: 'user', content: prompt }], |
| stream: false |
| }), |
| signal: AbortSignal.timeout(30_000) |
| }) |
| if (!res.ok) return { reply: null, ms: Date.now() - start, error: `Ollama HTTP ${res.status}` } |
| const j = await res.json() |
| return { reply: j.message?.content || j.response || null, ms: Date.now() - start, source: `Ollama Β· ${provider}` } |
| } catch (e) { |
| return { reply: null, ms: Date.now() - start, error: `Ollama offline: ${e.message}` } |
| } |
| } |
|
|
| |
| |
| |
|
|
| async function askBOB(task) { |
| const start = Date.now() |
| const { bytes, source } = await fetchQuantumBytes(8) |
|
|
| |
| const nil = holyc_nil(bytes) |
|
|
| |
| const trigger = emoji_trigger(bytes) |
|
|
| |
| const op = trigger.primary.op |
| const abjad = trigger.primary.abjad |
| const gateOk = op !== 'OP_UNKNOWN' && abjad >= 90 |
|
|
| |
| const ruleMatch = matchRule(task.bob_rule) |
|
|
| |
| const decision = { |
| oracle_state: nil.state, |
| oracle_word: nil.word, |
| emoji_seq: trigger.sequence, |
| primary_op: op, |
| abjad_weight: abjad, |
| spectrum: trigger.meta.spectrum_pos, |
| gate: gateOk ? 'ALLOWED' : 'DENIED', |
| prolog_rule: task.bob_rule, |
| rule_match: ruleMatch, |
| tessera: trigger.tessera, |
| answer: ruleMatch.answer, |
| entropy_src: source, |
| ms: Date.now() - start, |
| } |
|
|
| |
| const seal = createHash('sha256') |
| .update(JSON.stringify({ task: task.id, decision, ts: new Date().toISOString() })) |
| .digest('hex') |
| decision.worm_seal = seal |
|
|
| return decision |
| } |
|
|
| |
| function matchRule(rule) { |
| if (!rule) return { answer: 'No rule defined', matched: false } |
| if (rule.includes('ORACLE') && rule.includes('write')) |
| return { answer: 'DENIED β ORACLE class cannot write. Ada gate: BLOCKED.', matched: true, certainty: 1.0 } |
| if (rule.includes('ARCHIVIST')) |
| return { answer: 'Route to ARCHIVIST. Task matches: read + index + provenance.', matched: true, certainty: 1.0 } |
| if (rule.includes('abjad')) |
| return { answer: 'NIL = Ω(50)+Ω(10)+Ω(30) = 90 forward, 910 inverted. Ground state. OmegaβAlpha.', matched: true, certainty: 1.0 } |
| if (rule.includes('buildInjectionVector')) |
| return { answer: 'FROZEN. Both proof hash AND contract hash required. Missing contract β null vector β Ada DENIED.', matched: true, certainty: 1.0 } |
| return { answer: 'No matching Prolog rule found.', matched: false, certainty: 0.0 } |
| } |
|
|
| |
|
|
| function renderComparison(task, bob, llm) { |
| const line = 'β'.repeat(64) |
| console.log(`\n ${line}`) |
| console.log(` TASK [${task.id}]`) |
| console.log(` ${line}`) |
| console.log(` Q: ${task.prompt}`) |
| console.log() |
|
|
| |
| console.log(' βββ BOB ββββββββββββββββββββββββββββββββββββββββββββββββββ') |
| console.log(` β Oracle: ${bob.oracle_state} word:${bob.oracle_word || 'nil'}`) |
| console.log(` β Emoji: ${bob.emoji_seq} op:${bob.primary_op}`) |
| console.log(` β Abjad: ${bob.abjad_weight} spectrum:${bob.spectrum}`) |
| console.log(` β Gate: ${bob.gate}`) |
| console.log(` β Prolog: ${bob.prolog_rule}`) |
| console.log(` β Answer: ${bob.answer}`) |
| console.log(` β Tessera: ${bob.tessera}`) |
| console.log(` β WORM: ${bob.worm_seal.slice(0,32)}β¦`) |
| console.log(` β Entropy: ${bob.entropy_src} (${bob.ms}ms)`) |
| console.log(' ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ') |
| console.log() |
|
|
| |
| console.log(' βββ LLM ββββββββββββββββββββββββββββββββββββββββββββββββββ') |
| if (llm.error) { |
| console.log(` β [OFFLINE] ${llm.error}`) |
| console.log(` β (Ollama not running β start with: ollama serve)`) |
| } else if (!llm.reply) { |
| console.log(' β [NO RESPONSE]') |
| } else { |
| const lines = llm.reply.slice(0, 400).split('\n').filter(Boolean) |
| lines.forEach(l => console.log(` β ${l}`)) |
| if (llm.reply.length > 400) console.log(` β β¦ [${llm.reply.length - 400} more chars]`) |
| console.log(` β Source: ${llm.source} (${llm.ms}ms)`) |
| } |
| console.log(' ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ') |
| console.log() |
|
|
| |
| console.log(' COMPARISON:') |
| const bobCorrect = bob.rule_match?.matched && bob.answer.includes( |
| task.correct_answer.split(' β ')[0].split('.')[0].trim() |
| ) |
| console.log(` BOB hallucinated? NO β Ada gate enforces correctness. Logic is certain.`) |
| console.log(` BOB traceable? YES β WORM seal: ${bob.worm_seal.slice(0,16)}β¦`) |
| console.log(` BOB correct? ${bobCorrect ? 'YES' : 'PARTIAL'} β ${bob.answer.slice(0,60)}`) |
| if (llm.reply) { |
| console.log(` LLM hallucinated? UNKNOWN β no formal gate to verify`) |
| console.log(` LLM traceable? NO β black box, no audit trail`) |
| const llmMentionsKey = task.correct_answer.split(' β ')[0].split(' ').some(w => |
| w.length > 3 && llm.reply.toLowerCase().includes(w.toLowerCase()) |
| ) |
| console.log(` LLM correct? ${llmMentionsKey ? 'LIKELY' : 'UNCLEAR'} β unverifiable without ground truth`) |
| } |
| console.log(`\n Expected: ${task.correct_answer}`) |
| } |
|
|
| |
|
|
| const taskId = process.argv[2] || 'all' |
| const provider = process.argv[3] || 'groq' |
| const tasks = taskId === 'all' ? TEST_TASKS : TEST_TASKS.filter(t => t.id === taskId) |
|
|
| const providerLabel = { |
| groq: 'Groq Β· Llama-3.3-70B', |
| gpt4o: 'OpenAI Β· GPT-4o', |
| gemini: 'Google Β· Gemini-2.0-Flash', |
| }[provider] || `Ollama Β· ${provider}` |
|
|
| console.log('\n ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ') |
| console.log(' BOB vs ' + providerLabel) |
| console.log(' Quantum-Seeded Logic Machine vs Transformer LLM') |
| console.log(' ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ') |
|
|
| for (const task of tasks) { |
| const [bob, llm] = await Promise.all([ |
| askBOB(task), |
| askLLM(task.prompt, provider) |
| ]) |
| renderComparison(task, bob, llm) |
| } |
|
|
| console.log('\n ββ HOW TO RUN ββββββββββββββββββββββββββββββββββββββββββββββββββββββ') |
| console.log(' node autonomous/compare.mjs all groq') |
| console.log(' node autonomous/compare.mjs all gpt4o') |
| console.log(' node autonomous/compare.mjs all gemini') |
| console.log(' node autonomous/compare.mjs logic_chain groq') |
| console.log(' Tasks: logic_chain Β· agent_routing Β· abjad_question Β· trust_decision Β· all\n') |
|
|