20 lines
1.3 KiB
JavaScript
20 lines
1.3 KiB
JavaScript
// The human CLI started as a direct child of an agent run is refused.
|
|
import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { spawn, execFileSync } from 'node:child_process';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { startBroker } from '../src/runtime.mjs';
|
|
const businesses = { demo: { id: 'demo', human: 'jason', arbiters: { technical: 'cto', delivery: 'cto' }, roles: { cto: { authority: { withinRole: ['message.send'], crossRole: [] } } } } };
|
|
const root = mkdtempSync(join(tmpdir(), 'dw-human-')); mkdirSync(join(root, 'data'));
|
|
const rt = await startBroker({ dataRoot: join(root, 'data'), businesses });
|
|
const cli = fileURLToPath(new URL('../src/human-cli.mjs', import.meta.url));
|
|
const req = JSON.stringify({ business: 'demo', verb: 'launch.revoke' });
|
|
try {
|
|
const child = spawn(process.execPath, [cli, rt.path]); let text = '';
|
|
child.stdout.on('data', (b) => (text += b)); child.stderr.on('data', (b) => (text += b)); child.stdin.end(req);
|
|
const status = await new Promise((r) => child.on('close', r));
|
|
console.log('direct child of this agent run:', status, text.trim());
|
|
} catch (e) { console.log('error', e.code ?? e.message); }
|
|
finally { await rt.close(); rmSync(root, { recursive: true, force: true }); }
|