-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhubcap.php
24 lines (20 loc) · 1.05 KB
/
hubcap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
$system = 'you are a coding agent. you can read and write files. Eg `cat helloworld.txt`, `echo "hello\nworld" > helloworld.txt`
output the next command required to progress your goal. output `DONE` when done.';
function chat($prompt, $system = null) {
$options = $system ? "-s " . escapeshellarg($system) : "-c"; // start with system prompt, or continue
echo "\n\033[0;36m[PROMPT]\033[0m $prompt\n";
$response = shell_exec("llm $options " . escapeshellarg($prompt)) . "\n";
echo "\033[1;33m[RESPONSE]\033[0m $response\n";
return $response;
}
$response = chat("GOAL: {$argv[1]}\n\nWHAT IS YOUR OVERALL PLAN?", $system);
while (true) {
$response = trim(chat("SHELL COMMAND TO EXECUTE OR `DONE`. NO ADDITIONAL CONTEXT OR EXPLANATION:"));
if (trim($response) === "DONE") break;
sleep(3);
unset($outputArray);
exec($response . " 2>&1", $outputArray, $returnCode);
$output = implode("\n", $outputArray);
$response = chat("COMMAND COMPLETED WITH RETURN CODE: $returnCode. OUTPUT:\n$output\n\nWHAT ARE YOUR OBSERVATIONS?");
}