<?php
require 'examples/boot.php';
$controller = __DIR__.'/controller.sh';
$command = [
'bash',
$controller,
'Inspect this project and report one actionable risk.',
];
$process = proc_open(
$command,
[0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']],
$pipes,
dirname(__DIR__, 3),
);
if (! is_resource($process)) {
throw new RuntimeException('Unable to start the Tell shell controller.');
}
fclose($pipes[0]);
while (($line = fgets($pipes[1])) !== false) {
$frame = json_decode($line, true, flags: JSON_THROW_ON_ERROR);
echo $frame['sequence'].' '.$frame['type']."\n";
}
$errors = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$exit = proc_close($process);
if ($errors !== '') {
fwrite(STDERR, $errors);
}
if ($exit !== 0) {
throw new RuntimeException("Tell agent protocol exited with {$exit}.");
}