summaryrefslogtreecommitdiff
path: root/plugins/claude-security/scripts/views/term/main.mjs
blob: 77bee11ccd4617d2602487c87f812d19653aa905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { readSync, writeSync } from 'node:fs';
import { App } from './app.mjs';
const LENGTH_BYTES = 4;
function move(step, fd, bytes) {
	for (let at = 0; at < bytes.length;) {
		const moved = step(fd, bytes, at, bytes.length - at, null);
		if (!moved)
			process.exit(0);
		at += moved;
	}
	return bytes;
}
const app = new App();
for (;;) {
	const size = move(readSync, 0, Buffer.allocUnsafe(LENGTH_BYTES)).readUInt32LE(0);
	const answer = app.answer(move(readSync, 0, Buffer.allocUnsafe(size)));
	const framed = Buffer.allocUnsafe(LENGTH_BYTES + answer.length);
	framed.writeUInt32LE(answer.length, 0);
	framed.set(answer, LENGTH_BYTES);
	move(writeSync, 1, framed);
}