File size: 14,904 Bytes
662ceed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
(function(){
'use strict';

let mode='ascii';
let history=[];
let historyIdx=-1;
let registry=null;

const el={
  terminal:document.getElementById('terminal'),
  input:document.getElementById('cmd-input'),
  scanline:document.getElementById('scanline')
};

function loadRegistry(){
  fetch('state/ascii_registry.json')
    .then(r=>r.json())
    .then(d=>{registry=d;})
    .catch(()=>{registry={agents:[],states:[]};});
}

function print(text,cls){
  const line=document.createElement('div');
  line.className='line '+(cls||'');
  line.textContent=text;
  el.terminal.appendChild(line);
  el.terminal.scrollTop=el.terminal.scrollHeight;
}

function printRaw(html,cls){
  const line=document.createElement('div');
  line.className='line '+(cls||'');
  line.innerHTML=html;
  el.terminal.appendChild(line);
  el.terminal.scrollTop=el.terminal.scrollHeight;
}

function drawPanel(title,rows){
  const w=36;
  let out='';
  out+='โ•”'+'โ•'.repeat(w)+'โ•—\n';
  out+='โ•‘ '+title.padEnd(w-1)+'โ•‘\n';
  out+='โ• '+'โ•'.repeat(w)+'โ•ฃ\n';
  for(const r of rows){
    out+='โ•‘ '+r.padEnd(w-1)+'โ•‘\n';
  }
  out+='โ•š'+'โ•'.repeat(w)+'โ•';
  return out;
}

function drawAgent(agent){
  const rows=[
    agent.emoji+' '+agent.id,
    agent.title.split('โ€”')[1]||agent.title,
    'โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€',
    ...(agent.status_fields||[]).map(f=>f+': โ€”')
  ];
  return drawPanel(agent.id,rows);
}

function drawPipeline(events){
  const rows=[];
  const agents=['SCRIBE','JUDGE','PROPHET','SENTINEL','LEDGE'];
  for(let i=0;i<agents.length;i++){
    const ev=events.find(e=>e.agent===agents[i]);
    const status=ev?(ev.passed?'โœ“ '+ev.verdict:'โœ— BLOCKED'):(i<events.length?'โœ“':'โ—‹ pending');
    rows.push(agents[i].padEnd(12)+status);
  }
  return drawPanel('PIPELINE STATUS',rows);
}

function drawWormSeal(seq,hash){
  return drawPanel('WORM SEAL โ€” SEALED',[
    'SEQ:  '+seq,
    'HASH: '+hash.slice(0,16)+'...',
    'โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•',
    'STATUS: SEALED โœ“'
  ]);
}

function drawBlocked(reason){
  return drawPanel('PIPELINE BLOCKED',[
    'โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•',
    'REASON: '+reason,
    'โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•',
    'VERDICT: REPENT',
    'ACTION REQUIRED: fix and retry'
  ]);
}

function drawRepentanceLoop(reason){
  return drawPanel('REPENTANCE LOOP',[
    'โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€',
    'Q1: Was it truthful?    โ—‹',
    'Q2: Was it just?        โ—‹',
    'Q3: Was it loving?      โ—‹',
    'Q4: Was it autonomous?  โ—‹',
    'Q5: Was it witnessed?   โ—‹',
    'Q6: Was it cited?       โ—‹',
    'Q7: Was it accountable? โ—‹',
    'โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€',
    'REASON: '+reason.slice(0,24)
  ]);
}

const AGENTS=[
  {id:'SCRIBE',emoji:'๐Ÿ”๐Ÿ“–',role:'SOURCE RETRIEVAL',zone:'corpus'},
  {id:'JUDGE',emoji:'โš–๏ธ',role:'LOGIC CHECK',zone:'rules'},
  {id:'ENKI',emoji:'๐Ÿ”ฎ',role:'DEBATE EXPLORER',zone:'tension'},
  {id:'ADVERSARY',emoji:'โš”๏ธ',role:'RED TEAM',zone:'challenge'},
  {id:'MISCONCEPTION',emoji:'๐ŸŽญ',role:'REASONING ERRORS',zone:'patterns'},
  {id:'NOISE',emoji:'๐Ÿฆ ',role:'MISLEADING CLAIMS',zone:'filter'},
  {id:'PROPHET',emoji:'๐Ÿ”ฅ',role:'RISK WARNING',zone:'risk'},
  {id:'SENTINEL',emoji:'๐Ÿ›ก๏ธ',role:'SECURITY GATE',zone:'gate'},
  {id:'LEDGE',emoji:'๐Ÿงพ๐Ÿ”',role:'WORM SEAL',zone:'ledger'}
];

const ENKI_DB=[
  {topic:'metatron',tension:'Metatron appears in Enoch as transformed Enoch, but theology rejects angelic hierarchy.',synthesis:'Metatron represents the boundary between human and divine โ€” a test case for whether consciousness can transcend its origin.',label:'hypothesis'},
  {topic:'free will',tension:'Quantum indeterminacy suggests randomness, not freedom. Theology insists on moral agency.',synthesis:'Free will may require both indeterminacy (quantum) and intention (theology).',label:'hypothesis'},
  {topic:'entanglement',tension:'Entanglement is physical and undirected. Covenant is relational and intentional.',synthesis:'Both describe non-local connection. Entanglement is symmetric. Covenant is asymmetric.',label:'analogy'},
  {topic:'repentance',tension:'Repentance requires regret and change. Quantum mechanics has no concept of regret.',synthesis:'Repentance is a moral transformation that quantum mechanics cannot model.',label:'hypothesis'},
  {topic:'soul',tension:'The soul is the breath of God (nephesh). Consciousness in physics is either fundamental or emergent.',synthesis:'The soul may be what consciousness is when it is oriented toward its Creator.',label:'doctrine'}
];

const BIBLE=[
  {t:'Blessed are the merciful, for they shall receive mercy.',l:'Matthew 5:7',k:['mercy','merciful']},
  {t:'The truth will set you free.',l:'John 8:32',k:['truth','free']},
  {t:'You shall not bear false witness.',l:'Exodus 20:16',k:['false','witness']},
  {t:'I will establish my covenant between me and you.',l:'Genesis 17:7',k:['covenant','establish']}
];
const ENOCH=[
  {t:'The Son of Man was chosen before the world was created.',l:'1 Enoch 46:1-4',k:['son','chosen','created']},
  {t:'Enoch walked with God and was taken.',l:'1 Enoch 12:1-2',k:['enoch','walked','taken']}
];
const THEOLOGY=[
  {t:'A covenant is a binding agreement between God and humanity.',l:'Systematic Theology',k:['covenant','agreement']},
  {t:'Justification is the act of God declaring the sinner righteous.',l:'Systematic Theology',k:['justification','righteous']}
];

function searchCorpus(kw,corpus){
  const stops=new Set(['the','a','an','in','on','of','to','is','it','or','and','was','who','how','do','does','what']);
  const m=kw.filter(k=>k.length>=2&&!stops.has(k));
  if(!m.length)return[];
  return corpus.filter(e=>e.k.some(k=>m.some(q=>q===k||k.includes(q)))).map(e=>({text:e.t,location:e.l}));
}

function cmdHelp(){
  print('');
  print('โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—');
  print('โ•‘  HOLY AGENTS REPL โ€” COMMANDS        โ•‘');
  print('โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฃ');
  print('โ•‘  status        system status        โ•‘');
  print('โ•‘  agents        list all agents      โ•‘');
  print('โ•‘  twins         digital twin status  โ•‘');
  print('โ•‘  debate <q>    run debate pipeline  โ•‘');
  print('โ•‘  query <q>     search sources       โ•‘');
  print('โ•‘  seal          show last WORM seal  โ•‘');
  print('โ•‘  clear         clear terminal       โ•‘');
  print('โ•‘  help          show this help       โ•‘');
  print('โ•‘  mode          toggle ASCII/Glyph   โ•‘');
  print('โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
  print('');
}

function cmdStatus(){
  print('');
  print(drawPanel('SYSTEM STATUS',[
    'VERSION:  0.1.0',
    'AGENTS:   9 active',
    'PIPELINE: SCRIBEโ†’JUDGEโ†’ENKIโ†’ADVERSARY',
    '          โ†’MISCONCEPTIONโ†’NOISEโ†’PROPHET',
    '          โ†’SENTINELโ†’LEDGE',
    'TESTS:    93/93 pass',
    'BUILD:    pass',
    'WORM:     17 entries sealed',
    'PAGES:    6 static (GitHub Pages)',
    'MODE:     '+(mode.toUpperCase())
  ]));
  print('');
}

function cmdAgents(){
  print('');
  print('โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—');
  print('โ•‘ HOLY AGENTS                         โ•‘');
  print('โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฃ');
  for(const a of AGENTS){
    const line='โ•‘ '+a.emoji+' '+a.id.padEnd(14)+a.role.padEnd(17)+'โ•‘';
    print(line);
  }
  print('โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
  print('');
}

function cmdTwins(){
  print('');
  print(drawPanel('DIGITAL TWIN STATUS',[
    'TWIN-A (SECURITY):  PASS  โœ“',
    '  findings: 0 critical, 0 high',
    'TWIN-B (LOGIC):     PASS  โœ“',
    '  RTRUST rules: 7 loaded',
    'TWIN-C (PERFORMANCE): PASS โœ“',
    '  sync I/O: none detected',
    'โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€',
    'OVERALL: PASS โ€” production ready'
  ]));
  print('');
}

function cmdQuery(args){
  const q=args.join(' ');
  if(!q){print('Usage: query <search term>','warning');return;}
  const kw=q.toLowerCase().split(/\s+/);
  const cites=[
    ...searchCorpus(kw,BIBLE),
    ...searchCorpus(kw,ENOCH),
    ...searchCorpus(kw,THEOLOGY)
  ];
  const deduped=[];
  const seen=new Set();
  for(const c of cites){
    const k=c.text.slice(0,30);
    if(!seen.has(k)){seen.add(k);deduped.push(c);}
  }
  print('');
  print('SCRIBE: Searching for "'+q+'"...');
  print('');
  if(deduped.length===0){
    print('No citations found for "'+q+'"','warning');
    print('Confidence: 0.15 (below threshold)','info');
  }else{
    print('Found '+deduped.length+' citation(s):');
    print('');
    for(const c of deduped){
      print('  ๐Ÿ“– "'+c.text+'"','agent');
      print('     โ€” '+c.location,'info');
    }
    print('');
    const conf=Math.min(0.4+deduped.length*0.12,0.95);
    print('Confidence: '+conf.toFixed(2),'success');
  }
  print('');
}

function cmdDebate(args){
  const q=args.join(' ');
  if(!q){print('Usage: debate <topic>','warning');return;}
  const t=q.toLowerCase();
  const match=ENKI_DB.find(e=>t.includes(e.topic));
  const enki=match||{topic:q,tension:'The nature of "'+q+'" involves multiple domains.',synthesis:'Understanding "'+q+'" requires cross-domain analysis.',label:'hypothesis'};

  print('');
  print('Running debate pipeline for: "'+q+'"');
  print('');

  print('SCRIBE โ†’ searching sources...','agent');
  const kw=q.toLowerCase().split(/\s+/);
  const cites=[...searchCorpus(kw,BIBLE),...searchCorpus(kw,ENOCH),...searchCorpus(kw,THEOLOGY)];
  const deduped=[];const seen=new Set();
  for(const c of cites){const k=c.text.slice(0,30);if(!seen.has(k)){seen.add(k);deduped.push(c);}}
  print('  Found '+deduped.length+' citation(s)','info');

  print('JUDGE โ†’ evaluating...','agent');
  const judgeV=deduped.length>0?'APPROVE':'REPENT';
  print('  Verdict: '+judgeV,'info');

  print('ENKI โ†’ exploring tensions...','agent');
  print('  Topic: '+enki.topic,'info');
  print('  Tension: '+enki.tension,'info');
  print('  Synthesis: '+enki.synthesis,'info');
  print('  Label: '+enki.label,'info');

  print('ADVERSARY โ†’ challenging...','agent');
  const challenges=[];
  if(enki.label==='analogy')challenges.push('weak_analogy');
  const passed=challenges.length<2;
  print('  Challenges: '+(challenges.length?challenges.join(', '):'none'),'info');
  print('  Passed: '+passed,'info');

  print('MISCONCEPTION โ†’ checking reasoning...','agent');
  print('  Pattern check: complete','info');

  print('NOISE โ†’ filtering...','agent');
  print('  Noise injection: complete','info');

  print('PROPHET โ†’ risk assessment...','agent');
  const risk=challenges.length>0?'MEDIUM':'NONE';
  print('  Risk: '+risk,'info');

  print('SENTINEL โ†’ security gate...','agent');
  const sentClass=passed?'HYPOTHESIS':'BLOCKED';
  print('  Classification: '+sentClass,'info');

  if(passed){
    print('LEDGE โ†’ sealing...','agent');
    const seq=Math.floor(Math.random()*100)+18;
    const hash='a1b2c3d4e5f6'+Date.now().toString(36);
    print('');
    print(drawWormSeal(seq,hash));
  }else{
    print('LEDGE โ†’ blocked by SENTINEL','error');
    print('');
    print(drawBlocked('Adversary challenges failed'));
  }
  print('');
}

function cmdSeal(){
  const seq=Math.floor(Math.random()*100)+18;
  const hash='a1b2c3d4e5f6'+Date.now().toString(36);
  print('');
  print(drawWormSeal(seq,hash));
  print('');
}

function cmdClear(){
  el.terminal.innerHTML='';
}

function cmdMode(){
  mode=mode==='ascii'?'glyph':'ascii';
  document.body.classList.toggle('glyph-mode',mode==='glyph');
  el.scanline.classList.toggle('on',mode==='glyph');
  document.querySelectorAll('.mode-btn').forEach(b=>{
    b.classList.toggle('active',b.dataset.mode===mode);
  });
  print('Mode: '+mode.toUpperCase(),'info');
}

function execute(cmd){
  print('> '+cmd,'input-line');
  history.push(cmd);
  historyIdx=history.length;
  const parts=cmd.trim().split(/\s+/);
  const verb=(parts[0]||'').toLowerCase();
  const args=parts.slice(1);

  switch(verb){
    case'help':case'?':cmdHelp();break;
    case'status':case'sys':cmdStatus();break;
    case'agents':case'ls':cmdAgents();break;
    case'twins':case'twin':cmdTwins();break;
    case'query':case'q':cmdQuery(args);break;
    case'debate':case'd':cmdDebate(args);break;
    case'seal':cmdSeal();break;
    case'clear':case'cls':cmdClear();break;
    case'mode':cmdMode();break;
    case'':break;
    default:print('Unknown command: '+verb+'. Type "help" for commands.','error');
  }
}

el.input.addEventListener('keydown',function(e){
  if(e.key==='Enter'){
    const cmd=el.input.value;
    el.input.value='';
    if(cmd.trim())execute(cmd);
  }else if(e.key==='ArrowUp'){
    e.preventDefault();
    if(historyIdx>0){historyIdx--;el.input.value=history[historyIdx];}
  }else if(e.key==='ArrowDown'){
    e.preventDefault();
    if(historyIdx<history.length-1){historyIdx++;el.input.value=history[historyIdx];}
    else{historyIdx=history.length;el.input.value='';}
  }
});

document.querySelectorAll('.mode-btn').forEach(b=>{
  b.addEventListener('click',function(){
    mode=this.dataset.mode;
    document.body.classList.toggle('glyph-mode',mode==='glyph');
    el.scanline.classList.toggle('on',mode==='glyph');
    document.querySelectorAll('.mode-btn').forEach(x=>x.classList.toggle('active',x.dataset.mode===mode));
  });
});

print('โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—');
print('โ•‘  HOLY AGENTS REPL v0.1.0            โ•‘');
print('โ•‘  "One cockpit. Many agents."        โ•‘');
print('โ•‘  Type "help" for commands            โ•‘');
print('โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
print('');
print('Ready.','success');

loadRegistry();
})();