snapkitty
agents
python
File size: 8,828 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
import { enkiExplore } from '../agents/enki.js';
import { scribeQuery } from '../agents/scribe.js';
import { judgeAction } from '../agents/judge.js';
import { prophesy } from '../agents/prophet.js';
import { sentinelCheck } from '../agents/sentinel.js';
import { sealDecision } from '../agents/ledge.js';
import { runParallelAudit } from '../twins/orchestrator.js';
import { runFailureLoop } from '../failure-loop.js';
import type { EnkiResult, Action, Verdict } from '../types.js';
import type { TwinAudit, Finding } from '../twins/types.js';

const ROUNDS = [
  'consciousness and the soul',
  'wave function collapse and creation',
  'entanglement and covenant'
];

interface DebateRound {
  round: number;
  topic: string;
  enki: EnkiResult;
  scribeCitations: { source: string; text: string; location: string }[];
  scribeConfidence: number;
  judge: { verdict: Verdict; violatedRules: string[]; leanCheck: boolean };
  prophet: { riskLevel: string; warnings: string[]; recommendation: string };
  sentinel: { allowed: boolean; reason: string; violations: string[] };
  ledge: { sequence: number; hash: string; sealed: boolean } | null;
  twinAudit: { security: TwinAudit; logic: TwinAudit; performance: TwinAudit };
  failureLoop: { requiresRepentance: boolean; failuresFound: number };
  bugs: string[];
  innovations: string[];
}

function log(round: number, agent: string, msg: string): void {
  console.log(`[R${round}] ${agent}: ${msg}`);
}

async function runRound(roundNum: number, topic: string): Promise<DebateRound> {
  log(roundNum, 'ENKI', `invoking for topic: "${topic}"`);
  const enki = await enkiExplore(topic);
  log(roundNum, 'ENKI', `confidence: ${enki.confidence}, sources: ${enki.sources.length}`);

  log(roundNum, 'SCRIBE', `retrieving sources for "${topic}"`);
  const scribe = await scribeQuery(topic);
  log(roundNum, 'SCRIBE', `confidence: ${scribe.confidence}, citations: ${scribe.citations.length}`);

  const action: Action = {
    name: `debate:${topic}`,
    truthful: true,
    harmful: false,
    exploitative: false,
    requiresConsent: false,
    hasConsent: false,
    witnessed: true,
    cited: scribe.citations.length > 0
  };

  log(roundNum, 'JUDGE', 'evaluating action...');
  const judge = judgeAction(action);
  log(roundNum, 'JUDGE', `verdict: ${judge.verdict}`);

  log(roundNum, 'PROPHET', 'assessing risk...');
  const prophet = prophesy(action);
  log(roundNum, 'PROPHET', `risk: ${prophet.riskLevel}, recommendation: ${prophet.recommendation}`);

  log(roundNum, 'SENTINEL', 'security gate...');
  const sentinel = sentinelCheck(action, 'SCRIBE');
  log(roundNum, 'SENTINEL', `allowed: ${sentinel.allowed}`);

  let ledge = null;
  if (sentinel.allowed) {
    log(roundNum, 'LEDGE', 'sealing...');
    const eventId = `debate_r${roundNum}_${Date.now().toString(36)}`;
    ledge = sealDecision(eventId, 'SCRIBE', `debate:${topic}`, judge.verdict, scribe.citations.map(c => c.source));
    log(roundNum, 'LEDGE', `sealed seq ${ledge.sequence}`);
  } else {
    log(roundNum, 'LEDGE', 'blocked by sentinel');
  }

  log(roundNum, 'TWIN', 'running parallel audit...');
  const sourceFiles = [
    { name: 'scribe.ts', content: 'scribe source code' },
    { name: 'judge.ts', content: 'judge source code' },
    { name: 'sentinel.ts', content: 'sentinel source code' }
  ];
  const twinAudit = await runParallelAudit(sourceFiles);
  log(roundNum, 'TWIN', `security: ${twinAudit.security.verdict}, logic: ${twinAudit.logic.verdict}, performance: ${twinAudit.performance.verdict}`);

  log(roundNum, 'FAILURE-LOOP', 'running 7-question check...');
  const failureLoop = runFailureLoop(
    {
      security: { findings: twinAudit.security.findings.map((f: Finding) => ({ severity: f.severity, category: f.category })) },
      logic: { findings: twinAudit.logic.findings.map((f: Finding) => ({ severity: f.severity })) }
    },
    { allVerified: true, orphanArtifacts: [] }
  );
  log(roundNum, 'FAILURE-LOOP', `requiresRepentance: ${failureLoop.requiresRepentance}, failuresFound: ${failureLoop.failuresFound}`);

  const bugs: string[] = [];
  const innovations: string[] = [];

  if (!sentinel.allowed) {
    bugs.push(`SENTINEL blocked: ${sentinel.violations.join(', ')}`);
  }
  if (judge.verdict === 'repent') {
    bugs.push(`JUDGE repents: ${judge.violatedRules.join(', ')}`);
  }
  if (enki.confidence < 0.3) {
    bugs.push(`ENKI confidence too low (${enki.confidence}) β€” insufficient debate corpus coverage`);
  }
  if (scribe.citations.length === 0) {
    bugs.push(`SCRIBE found no citations β€” topic not in retrieval corpus`);
  }
  if (failureLoop.requiresRepentance) {
    bugs.push(`FAILURE-LOOP requires repentance: ${failureLoop.failuresFound} failures found`);
  }

  if (enki.tension.length > 50) {
    innovations.push(`Rich tension identified: "${enki.tension.slice(0, 80)}..." β€” expand debate corpus with this tension`);
  }
  if (enki.synthesis.length > 50) {
    innovations.push(`Synthesis found: "${enki.synthesis.slice(0, 80)}..." β€” potential new doctrine or axiom`);
  }
  if (scribe.etymologies.length > 0) {
    innovations.push(`Etymology data found for "${topic}" β€” cross-reference with debate topic`);
  }
  if (scribe.translations.length > 0) {
    innovations.push(`Translation data found β€” cross-linguistic analysis possible for "${topic}"`);
  }

  return {
    round: roundNum,
    topic,
    enki,
    scribeCitations: scribe.citations,
    scribeConfidence: scribe.confidence,
    judge: { verdict: judge.verdict, violatedRules: judge.violatedRules, leanCheck: judge.leanCheck },
    prophet: { riskLevel: prophet.riskLevel, warnings: prophet.warnings, recommendation: prophet.recommendation },
    sentinel: { allowed: sentinel.allowed, reason: sentinel.reason, violations: sentinel.violations },
    ledge: ledge ? { sequence: ledge.sequence, hash: ledge.hash, sealed: ledge.sealed } : null,
    twinAudit,
    failureLoop: { requiresRepentance: failureLoop.requiresRepentance, failuresFound: failureLoop.failuresFound },
    bugs,
    innovations
  };
}

async function main(): Promise<void> {
  console.log('='.repeat(70));
  console.log('ENKI DEBATE β€” Quantum vs Biblical β€” 3 Rounds');
  console.log('='.repeat(70));
  console.log('');

  const rounds: DebateRound[] = [];

  for (let i = 0; i < ROUNDS.length; i++) {
    console.log('-'.repeat(70));
    const result = await runRound(i + 1, ROUNDS[i]);
    rounds.push(result);
    console.log('');
  }

  console.log('='.repeat(70));
  console.log('DEBATE REPORT');
  console.log('='.repeat(70));
  console.log('');

  for (const r of rounds) {
    console.log(`--- ROUND ${r.round}: "${r.topic}" ---`);
    console.log(`  ENKI confidence: ${r.enki.confidence}`);
    console.log(`  Tension: ${r.enki.tension.slice(0, 100)}...`);
    console.log(`  Synthesis: ${r.enki.synthesis.slice(0, 100)}...`);
    console.log(`  SCRIBE citations: ${r.scribeCitations.length}, confidence: ${r.scribeConfidence}`);
    console.log(`  JUDGE verdict: ${r.judge.verdict}, lean: ${r.judge.leanCheck}`);
    console.log(`  PROPHET risk: ${r.prophet.riskLevel}, recommendation: ${r.prophet.recommendation}`);
    console.log(`  SENTINEL: ${r.sentinel.allowed ? 'ALLOWED' : 'BLOCKED'} β€” ${r.sentinel.reason}`);
    console.log(`  LEDGE: ${r.ledge ? `sealed seq ${r.ledge.sequence}` : 'not sealed'}`);
    console.log(`  TWIN-A (security): ${r.twinAudit.security.verdict} (${r.twinAudit.security.passed}/${r.twinAudit.security.passed + r.twinAudit.security.failed})`);
    console.log(`  TWIN-B (logic): ${r.twinAudit.logic.verdict} (${r.twinAudit.logic.passed}/${r.twinAudit.logic.passed + r.twinAudit.logic.failed})`);
    console.log(`  TWIN-C (performance): ${r.twinAudit.performance.verdict} (${r.twinAudit.performance.passed}/${r.twinAudit.performance.passed + r.twinAudit.performance.failed})`);
    console.log(`  FAILURE-LOOP: ${r.failureLoop.requiresRepentance ? 'FAILED' : 'PASSED'} (${r.failureLoop.failuresFound} failures)`);
    if (r.bugs.length > 0) {
      console.log(`  BUGS:`);
      r.bugs.forEach(b => console.log(`    - ${b}`));
    }
    if (r.innovations.length > 0) {
      console.log(`  INNOVATIONS:`);
      r.innovations.forEach(i => console.log(`    + ${i}`));
    }
    console.log('');
  }

  const allBugs = rounds.flatMap(r => r.bugs);
  const allInnovations = rounds.flatMap(r => r.innovations);
  console.log('='.repeat(70));
  console.log(`SUMMARY: ${allBugs.length} bugs, ${allInnovations.length} innovations across ${rounds.length} rounds`);
  console.log('='.repeat(70));
}

main().catch(err => { console.error(err); process.exit(1); });