Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-harness/blob/main/cli/src/tests/cli.test.ts # omega-harness Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-harness / cli / src / tests / cli.test.ts` 422 lines · 16892 bytes Raw Blame History 1 import test from 'node:test'; 2 import assert from 'node:assert/strict'; 3 import fs from 'node:fs'; 4 import http from 'node:http'; 5 import os from 'node:os'; 6 import path from 'node:path'; 7 import { execFileSync } from 'node:child_process'; 8 import { detectHarnessRoot, detectOmcPath, loadConfig } from '../config.js'; 9 import { discoverSkills, loadErrorTable, readPinInfo } from '../harness.js'; 10 import { executeTool, needsApproval, parseDuckDuckGoHtml, stripHtmlToText, TOOL_DECLARATIONS } from '../tools.js'; 11 import { SessionState } from '../state.js'; 12 import { OmegaAgent, expandAtMentions } from '../agent.js'; 13 import { matchSlashCommands } from '../commands.js'; 14 import { SYMBOL, renderBanner } from '../brand.js'; 15 import { 16 buildNativeServePayload, 17 parseInklingTokens, 18 probeInkling, 19 } from '../inkling.js'; 20 21 const harnessRoot = detectHarnessRoot(); 22 23 test('brand renders custom Ω symbol and banner', () => { 24 assert.equal(SYMBOL, 'Ω'); 25 const lines = renderBanner(80); 26 assert.ok(lines.length >= 3); 27 const compact = renderBanner(40); 28 assert.ok(compact.length >= 3); 29 }); 30 31 test('default config points to Inkling-2-Mini', () => { 32 const cfg = loadConfig(); 33 assert.equal(cfg.provider, 'inkling'); 34 assert.equal(cfg.model, 'inkling-2-mini'); 35 assert.match(cfg.endpoint, /^http:\/\/127\.0\.0\.1:8080/); 36 }); 37 38 test('harness discovers skills, PIN, and error table dynamically', () => { 39 const skills = discoverSkills(harnessRoot); 40 assert.ok(skills.length >= 5, `expected skills in ${harnessRoot}, found ${skills.length}`); 41 assert.ok(skills.some((s) => s.name === 'omega-harness')); 42 assert.ok(skills.some((s) => s.name === 'writing-omega')); 43 44 const pin = readPinInfo(harnessRoot, detectOmcPath()); 45 assert.ok(pin.omegaMvCommit && pin.omegaMvCommit.length === 40); 46 assert.ok(pin.omcSha256 && pin.omcSha256.length === 64); 47 48 const errors = loadErrorTable(harnessRoot); 49 assert.ok(errors.size >= 20, `expected error table entries, got ${errors.size}`); 50 assert.ok(errors.get(1)?.meaning); 51 }); 52 53 test('Inkling token parser extracts thinking, tool calls, and clean text', () => { 54 const raw = 55 '<|content_thinking|>Need to inspect PIN.<|end_message|>' + 56 '<|message_model|>omega_pin<|content_invoke_tool_json|>{"name":"omega_pin","args":{}}<|end_message|>' + 57 '<|content_text|>Checking the pin now.<|end_message|><|content_model_end_sampling|>'; 58 const parsed = parseInklingTokens(raw); 59 assert.equal(parsed.thinking, 'Need to inspect PIN.'); 60 assert.equal(parsed.text, 'Checking the pin now.'); 61 assert.equal(parsed.toolCalls.length, 1); 62 assert.equal(parsed.toolCalls[0].name, 'omega_pin'); 63 }); 64 65 test('buildNativeServePayload sanitizes quotes for serve_live.om slFindContent', () => { 66 const body = buildNativeServePayload('inkling-2-mini', 'Say "hello"\nworld'); 67 const parsed = JSON.parse(body) as { messages: Array<{ content: string }> }; 68 assert.equal(parsed.messages[0].content, "Say 'hello' world"); 69 }); 70 71 test('Inkling client talks to native inkling2-serve and retries 503 server_busy', async () => { 72 let chatAttempts = 0; 73 const server = http.createServer((req, res) => { 74 if (req.method === 'GET' && req.url === '/health') { 75 res.writeHead(200, { 'Content-Type': 'application/json' }); 76 res.end(JSON.stringify({ status: 'ok', model: 'inkling-2-mini', slots_max: 8, slots_active: 1 })); 77 return; 78 } 79 if (req.method === 'POST' && req.url === '/v1/chat/completions') { 80 chatAttempts++; 81 if (chatAttempts === 1) { 82 res.writeHead(503, { 'Content-Type': 'application/json', 'Retry-After': '0' }); 83 res.end(JSON.stringify({ error: { type: 'server_busy', slots_max: 8 } })); 84 return; 85 } 86 res.writeHead(200, { 'Content-Type': 'application/json' }); 87 res.end( 88 JSON.stringify({ 89 id: 'cmpl-ik2', 90 object: 'chat.completion', 91 model: 'inkling-2-mini', 92 choices: [ 93 { 94 index: 0, 95 message: { role: 'assistant', content: 'The capital of France is Paris.' }, 96 finish_reason: 'stop', 97 }, 98 ], 99 }) 100 ); 101 return; 102 } 103 res.writeHead(404); 104 res.end(); 105 }); 106 107 await new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve())); 108 const addr = server.address(); 109 assert.ok(addr && typeof addr === 'object'); 110 const endpoint = `http://127.0.0.1:${addr.port}`; 111 112 try { 113 const health = await probeInkling(endpoint); 114 assert.equal(health.online, true); 115 assert.equal(health.engine, 'inkling2-serve'); 116 assert.equal(health.slotsMax, 8); 117 assert.equal(health.slotsActive, 1); 118 119 const agent = new OmegaAgent(); 120 let streamed = ''; 121 const reply = await agent.sendTurn('What is the capital of France?', { 122 provider: 'inkling', 123 endpoint, 124 model: 'inkling-2-mini', 125 systemInstruction: 'sys', 126 toolContext: { cwd: process.cwd(), harnessRoot, approvalMode: 'default' }, 127 callbacks: { 128 onTextDelta: (c) => { 129 streamed += c; 130 }, 131 onToolStart: () => {}, 132 onToolUpdate: () => {}, 133 onRequestApproval: async () => 'allow', 134 }, 135 }); 136 assert.equal(chatAttempts, 2, 'should retry once on 503 server_busy'); 137 assert.equal(reply, 'The capital of France is Paris.'); 138 assert.equal(streamed, 'The capital of France is Paris.'); 139 } finally { 140 server.close(); 141 } 142 }); 143 144 test('Inkling client handles OpenAI-compat SSE streaming and tool calls', async () => { 145 let round = 0; 146 const server = http.createServer((req, res) => { 147 if (req.method === 'GET' && req.url === '/health') { 148 res.writeHead(200, { 'Content-Type': 'application/json' }); 149 res.end(JSON.stringify({ status: 'ok', model: 'inkling-2-mini' })); 150 return; 151 } 152 if (req.method === 'POST' && req.url === '/v1/chat/completions') { 153 round++; 154 res.writeHead(200, { 'Content-Type': 'text/event-stream' }); 155 if (round === 1) { 156 res.write( 157 `data: ${JSON.stringify({ 158 choices: [ 159 { 160 delta: { 161 tool_calls: [ 162 { index: 0, id: 'call_1', function: { name: 'list_skills', arguments: '{}' } }, 163 ], 164 }, 165 }, 166 ], 167 })}\n\n` 168 ); 169 res.write('data: [DONE]\n\n'); 170 res.end(); 171 } else { 172 res.write(`data: ${JSON.stringify({ choices: [{ delta: { content: 'Loaded ' } }] })}\n\n`); 173 res.write(`data: ${JSON.stringify({ choices: [{ delta: { content: 'skills.' } }] })}\n\n`); 174 res.write('data: [DONE]\n\n'); 175 res.end(); 176 } 177 return; 178 } 179 res.writeHead(404); 180 res.end(); 181 }); 182 183 await new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve())); 184 const addr = server.address(); 185 assert.ok(addr && typeof addr === 'object'); 186 const endpoint = `http://127.0.0.1:${addr.port}`; 187 188 try { 189 const agent = new OmegaAgent(); 190 const toolsSeen: string[] = []; 191 const reply = await agent.sendTurn('list skills', { 192 provider: 'inkling', 193 endpoint, 194 model: 'inkling-2-mini', 195 systemInstruction: 'sys', 196 toolContext: { cwd: process.cwd(), harnessRoot, approvalMode: 'default' }, 197 callbacks: { 198 onTextDelta: () => {}, 199 onToolStart: (ev) => toolsSeen.push(ev.name), 200 onToolUpdate: () => {}, 201 onRequestApproval: async () => 'allow', 202 }, 203 }); 204 assert.deepEqual(toolsSeen, ['list_skills']); 205 assert.equal(reply, 'Loaded skills.'); 206 } finally { 207 server.close(); 208 } 209 }); 210 211 test('tools read, write, edit, glob, grep, and enforce omega-only mode', async () => { 212 const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'omega-cli-test-')); 213 try { 214 const ctx = { 215 cwd: tmp, 216 harnessRoot, 217 omcPath: detectOmcPath(), 218 approvalMode: 'default' as const, 219 }; 220 221 const w = await executeTool('write_file', { path: 'hello.txt', content: 'alpha\nbeta\n' }, ctx); 222 assert.equal(w.ok, true); 223 224 const r = await executeTool('read_file', { path: 'hello.txt' }, ctx); 225 assert.equal(r.ok, true); 226 assert.match(r.output, /1: alpha/); 227 228 const e = await executeTool('edit_file', { path: 'hello.txt', target: 'beta', replacement: 'omega' }, ctx); 229 assert.equal(e.ok, true); 230 231 const g = await executeTool('grep_search', { query: 'omega' }, ctx); 232 assert.equal(g.ok, true); 233 assert.match(g.output, /hello\.txt/); 234 235 const gl = await executeTool('glob_files', { pattern: '*.txt' }, ctx); 236 assert.equal(gl.ok, true); 237 assert.match(gl.output, /hello\.txt/); 238 239 const omegaCtx = { ...ctx, approvalMode: 'omega-only' as const }; 240 const blocked = await executeTool('write_file', { path: 'bad.py', content: 'print(1)\n' }, omegaCtx); 241 assert.equal(blocked.ok, false); 242 assert.match(blocked.output, /REFUSED/); 243 } finally { 244 fs.rmSync(tmp, { recursive: true, force: true }); 245 } 246 }); 247 248 test('approval policy classifies read-only vs mutating tools', () => { 249 assert.equal(needsApproval('read_file', 'default'), false); 250 assert.equal(needsApproval('omc_compile', 'default'), false); 251 assert.equal(needsApproval('write_file', 'default'), true); 252 assert.equal(needsApproval('auto-edit', 'auto-edit'), true); 253 assert.equal(needsApproval('write_file', 'auto-edit'), false); 254 assert.equal(needsApproval('run_shell', 'auto-edit'), true); 255 assert.equal(needsApproval('run_shell', 'yolo'), false); 256 }); 257 258 test('@file mention expands attached file context', () => { 259 const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'omega-at-test-')); 260 try { 261 fs.writeFileSync(path.join(tmp, 'sample.om'), 'fn main to int\n ret 0\nend\n'); 262 const res = expandAtMentions('review @sample.om please', tmp); 263 assert.deepEqual(res.attachedFiles, ['sample.om']); 264 assert.match(res.expanded, //); 265 assert.match(res.expanded, /fn main to int/); 266 } finally { 267 fs.rmSync(tmp, { recursive: true, force: true }); 268 } 269 }); 270 271 test('slash command matching works', () => { 272 const m = matchSlashCommands('/st'); 273 assert.ok(m.some((c) => c.name === '/status')); 274 assert.ok(m.some((c) => c.name === '/stats')); 275 assert.equal(matchSlashCommands('hello').length, 0); 276 }); 277 278 test('all 27 modern agent tools are registered and git/todo/memory/web helpers work', async () => { 279 assert.ok(TOOL_DECLARATIONS.length >= 27, `expected >= 27 tools, got ${TOOL_DECLARATIONS.length}`); 280 assert.equal(stripHtmlToText('

Hi

World & Omega

'), 'Hi World & Omega'); 281 282 const sampleHtml = 'Omega MVSeeded Omega compiler'; 283 const ddg = parseDuckDuckGoHtml(sampleHtml, 5); 284 assert.equal(ddg.length, 1); 285 assert.equal(ddg[0].url, 'https://interplane.io/drakestapleton/omega-mv'); 286 assert.equal(ddg[0].snippet, 'Seeded Omega compiler'); 287 288 const state = new SessionState(); 289 const ctx = { cwd: harnessRoot, harnessRoot, approvalMode: 'default' as const, state }; 290 291 const gs = await executeTool('git_status', {}, ctx); 292 assert.equal(gs.ok, true); 293 294 const gl = await executeTool('git_log', { count: 2 }, ctx); 295 assert.equal(gl.ok, true); 296 297 const tw = await executeTool('todo_write', { 298 items: [ 299 { id: '1', title: 'Wire tools', status: 'completed' }, 300 { id: '2', title: 'Test subagents', status: 'in_progress' }, 301 ], 302 }, ctx); 303 assert.equal(tw.ok, true); 304 assert.match(tw.output, /\[x\] \(1\) Wire tools/); 305 306 const tr = await executeTool('todo_read', {}, ctx); 307 assert.equal(tr.ok, true); 308 assert.match(tr.output, /\[~\] \(2\) Test subagents/); 309 310 // Read-only subagent refuses mutating tools 311 const roCtx = { ...ctx, readOnlyOnly: true }; 312 const refused = await executeTool('delete_file', { path: 'README.md' }, roCtx); 313 assert.equal(refused.ok, false); 314 assert.match(refused.output, /REFUSED/); 315 }); 316 317 test('Inkling-2-Mini spawns autonomous subagents, runs parallel subagents, and breaks duplicate tool loops', async () => { 318 let reqNum = 0; 319 const server = http.createServer((req, res) => { 320 if (req.method === 'GET' && req.url === '/health') { 321 res.writeHead(200, { 'Content-Type': 'application/json' }); 322 res.end(JSON.stringify({ status: 'ok', model: 'inkling-2-mini', slots_max: 8, slots_active: 0, arboris_transitions: 48, arboris_top8_hits: 192, arboris_top16_hits: 256 })); 323 return; 324 } 325 if (req.method === 'POST' && req.url === '/v1/chat/completions') { 326 let body = ''; 327 req.on('data', (c) => (body += c)); 328 req.on('end', () => { 329 reqNum++; 330 const parsed = JSON.parse(body) as { messages: Array<{ content: string }> }; 331 const content = parsed.messages[0]?.content || ''; 332 let reply = 'Done.'; 333 if (content.includes('LOOP_TEST')) { 334 // Intentionally emit identical tool call every time to test loop breaker 335 reply = '<|message_model|>omega_pin<|content_invoke_tool_json|>{"name":"omega_pin","args":{}}<|end_message|>'; 336 } else if (content.includes('DELEGATE_TEST') && !content.includes('<|message_tool|>')) { 337 reply = '<|message_model|>spawn_subagent<|content_invoke_tool_json|>{"name":"spawn_subagent","args":{"role":"Researcher","task":"SUBTASK_ALPHA"}}<|end_message|>'; 338 } else if (content.includes('DELEGATE_TEST') && content.includes('<|message_tool|>')) { 339 reply = '<|content_text|>Coordinator received subagent report: omega-harness skills found.<|end_message|>'; 340 } else if (content.includes('SUBTASK_ALPHA') && !content.includes('<|message_tool|>')) { 341 reply = '<|message_model|>list_skills<|content_invoke_tool_json|>{"name":"list_skills","args":{}}<|end_message|>'; 342 } else if (content.includes('SUBTASK_ALPHA') && content.includes('<|message_tool|>')) { 343 reply = '<|content_text|>Subagent found omega-harness skills.<|end_message|>'; 344 } 345 res.writeHead(200, { 'Content-Type': 'application/json' }); 346 res.end( 347 JSON.stringify({ 348 id: `cmpl-${reqNum}`, 349 object: 'chat.completion', 350 model: 'inkling-2-mini', 351 choices: [{ index: 0, message: { role: 'assistant', content: reply }, finish_reason: 'stop' }], 352 }) 353 ); 354 }); 355 return; 356 } 357 res.writeHead(404); 358 res.end(); 359 }); 360 361 await new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve())); 362 const addr = server.address(); 363 assert.ok(addr && typeof addr === 'object'); 364 const endpoint = `http://127.0.0.1:${addr.port}`; 365 366 try { 367 const agent = new OmegaAgent(); 368 const seenTools: string[] = []; 369 const reply = await agent.sendTurn('DELEGATE_TEST', { 370 provider: 'inkling', 371 endpoint, 372 model: 'inkling-2-mini', 373 systemInstruction: 'sys', 374 toolContext: { cwd: harnessRoot, harnessRoot, approvalMode: 'yolo' }, 375 callbacks: { 376 onTextDelta: () => {}, 377 onToolStart: (ev) => seenTools.push(ev.name), 378 onToolUpdate: () => {}, 379 onRequestApproval: async () => 'allow', 380 }, 381 }); 382 assert.ok(seenTools.includes('spawn_subagent'), `expected spawn_subagent in ${seenTools.join(',')}`); 383 assert.ok(seenTools.some((t) => t.endsWith(':list_skills')), `expected subagent list_skills in ${seenTools.join(',')}`); 384 assert.match(reply, /Coordinator received subagent report/); 385 assert.equal(agent.state.subagents.size, 1); 386 387 // Loop-breaker check: identical repeated tool call stops cleanly instead of spinning 10 rounds 388 const beforeReqs = reqNum; 389 const loopReply = await agent.sendTurn('LOOP_TEST', { 390 provider: 'inkling', 391 endpoint, 392 model: 'inkling-2-mini', 393 systemInstruction: 'sys', 394 toolContext: { cwd: harnessRoot, harnessRoot, approvalMode: 'yolo' }, 395 callbacks: { 396 onTextDelta: () => {}, 397 onToolStart: () => {}, 398 onToolUpdate: () => {}, 399 onRequestApproval: async () => 'allow', 400 }, 401 }); 402 assert.ok(reqNum - beforeReqs <= 3, `loop breaker should stop within 2-3 rounds, took ${reqNum - beforeReqs}`); 403 assert.match(loopReply, /PIN omega-mv:/); 404 } finally { 405 server.close(); 406 } 407 }); 408 409 test('CLI binary smoke tests (--version, --help, --skills, --pin)', () => { 410 const bin = path.resolve(harnessRoot, 'cli', 'dist', 'index.js'); 411 const ver = execFileSync(process.execPath, [bin, '--version'], { encoding: 'utf8' }); 412 assert.match(ver, /Ω omega-harness-cli/); 413 414 const help = execFileSync(process.execPath, [bin, '--help'], { encoding: 'utf8' }); 415 assert.match(help, /Inkling-2-Mini/); 416 417 const sk = execFileSync(process.execPath, [bin, '--skills'], { encoding: 'utf8' }); 418 assert.match(sk, /omega-harness/); 419 420 const pinOut = execFileSync(process.execPath, [bin, '--pin'], { encoding: 'utf8' }); 421 assert.match(pinOut, /PIN omega-mv:/); 422 });