File size: 6,535 Bytes
119e586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env node
// Agentic Arena β€” CLI entry point
// The graveyard floor. All commands stack here.

import { spawn } from 'child_process';
import { existsSync, readFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

const __dir = dirname(fileURLToPath(import.meta.url));
const ROOT  = join(__dir, '../..');

const RED    = '\x1b[31m';
const BLUE   = '\x1b[34m';
const PURPLE = '\x1b[35m';
const YELLOW = '\x1b[33m';
const RESET  = '\x1b[0m';
const BOLD   = '\x1b[1m';

const BANNER = `

${PURPLE}${BOLD}  β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘

  β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–‘β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•‘β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—

  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β•šβ•β•

  β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•—

  β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β•šβ–ˆβ–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•

  β•šβ•β•β–‘β–‘β•šβ•β•β–‘β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β•šβ•β•β–‘β–‘β•šβ•β•β•β–‘β–‘β–‘β•šβ•β•β–‘β–‘β–‘β•šβ•β•β–‘β•šβ•β•β•β•β•${RESET}

  ${RED}AHMAD-BOT [red]${RESET}  +  ${BLUE}EDUALC [blue]${RESET}  =  ${PURPLE}PURPLE DAEMON${RESET}

  the graveyard crawlers β€” they work when no one watches

`;

const HELP = `

${YELLOW}COMMANDS:${RESET}

  crawl          run both daemons in split-terminal mode (red + blue)

  crawl --red    run AHMAD-BOT only

  crawl --blue   run EDUALC only

  inject owner/repo  inject sovereign structure into target repo via PR

  worm           release the benevolent worm β€” audits, maps, verifies, repairs both chains

  report         show latest WORM-sealed crawl results

  status         show scoreboard from worm/scoreboard.json

  seal           trigger BOB to seal latest crawl to WORM chain

  help           show this message

`;

const cmd = process.argv[2];
const flag = process.argv[3];

console.log(BANNER);

switch (cmd) {
  case 'crawl':
    if (flag === '--red')  runDaemon('red');
    else if (flag === '--blue') runDaemon('blue');
    else runBoth();
    break;
  case 'worm':
    runWorm();
    break;
  case 'inject':
    runInjector(flag);
    break;
  case 'report':
    showReport();
    break;
  case 'status':
    showStatus();
    break;
  case 'seal':
    runSeal();
    break;
  default:
    console.log(HELP);
}

function runDaemon(hat) {
  const script = hat === 'red'
    ? join(__dir, '../crawlers/ahmad-bot.mjs')
    : join(__dir, '../crawlers/edualc.mjs');
  const p = spawn(process.execPath, [script], {
    stdio: 'inherit',
    env: { ...process.env }
  });
  p.on('exit', code => process.exit(code ?? 0));
}

function runBoth() {
  // Two daemons, interleaved output β€” red left, blue right, reasoning visible.
  // LISP handshake: each daemon writes .sexp, BOB reads both and reasons.
  console.log(`${PURPLE}${BOLD}releasing both daemons into the graveyard...${RESET}\n`);

  const red  = spawn(process.execPath,
    [join(__dir, '../crawlers/ahmad-bot.mjs')],
    { env: { ...process.env }, stdio: ['ignore', 'pipe', 'pipe'] }
  );
  const blue = spawn(process.execPath,
    [join(__dir, '../crawlers/edualc.mjs')],
    { env: { ...process.env }, stdio: ['ignore', 'pipe', 'pipe'] }
  );

  red.stdout.on('data',  d => process.stdout.write(d));
  red.stderr.on('data',  d => process.stderr.write(d));
  blue.stdout.on('data', d => process.stdout.write(d));
  blue.stderr.on('data', d => process.stderr.write(d));

  let done = 0;
  const onClose = () => { if (++done === 2) runBobBridge(); };
  red.on('close', onClose);
  blue.on('close', onClose);
}

function runBobBridge() {
  console.log(`\n${PURPLE}${BOLD}both daemons returned β€” BOB reasoning...${RESET}`);
  const bridge = join(__dir, '../bob-bridge/index.mjs');
  if (!existsSync(bridge)) {
    console.log(`${YELLOW}BOB bridge not wired yet β€” run: node runtime/bob-bridge/index.mjs${RESET}`);
    return;
  }
  const p = spawn(process.execPath, [bridge], { stdio: 'inherit', env: { ...process.env } });
  p.on('exit', () => console.log(`\n${PURPLE}BOB sealed the night's work.${RESET}`));
}

function showReport() {
  const redPath  = join(ROOT, 'worm/ahmad-bot-crawl.sexp');
  const bluePath = join(ROOT, 'worm/edualc-crawl.sexp');
  if (existsSync(redPath)) {
    console.log(`${RED}── AHMAD-BOT last crawl ──${RESET}`);
    console.log(readFileSync(redPath, 'utf8').slice(0, 2000));
  }
  if (existsSync(bluePath)) {
    console.log(`${BLUE}── EDUALC last crawl ──${RESET}`);
    console.log(readFileSync(bluePath, 'utf8').slice(0, 2000));
  }
  if (!existsSync(redPath) && !existsSync(bluePath)) {
    console.log('No crawl results yet. Run: arena crawl');
  }
}

function showStatus() {
  const p = join(ROOT, 'worm/scoreboard.json');
  if (!existsSync(p)) { console.log('No scoreboard yet.'); return; }
  const board = JSON.parse(readFileSync(p, 'utf8'));
  console.log(`${PURPLE}${BOLD}── SCOREBOARD ──${RESET}`);
  console.log(JSON.stringify(board, null, 2));
}

function runInjector(target) {
  if (!target) { console.log(`${YELLOW}usage: arena inject owner/repo${RESET}`); return; }
  console.log(`${RED}${BOLD}ransom-worm targeting: ${target}${RESET}\n`);
  const inj = join(__dir, '../injector/index.mjs');
  const p = spawn(process.execPath, [inj, target], { stdio: 'inherit', env: { ...process.env } });
  p.on('exit', code => process.exit(code ?? 0));
}

function runWorm() {
  console.log(`${PURPLE}${BOLD}releasing the benevolent worm...${RESET}\n`);
  const worm = join(__dir, '../benevolent-worm/index.mjs');
  const p = spawn(process.execPath, [worm], { stdio: 'inherit', env: { ...process.env } });
  p.on('exit', code => process.exit(code ?? 0));
}

function runSeal() {
  const bridge = join(__dir, '../bob-bridge/index.mjs');
  const p = spawn(process.execPath, [bridge, '--seal'], { stdio: 'inherit', env: { ...process.env } });
  p.on('exit', code => process.exit(code ?? 0));
}