Repository navigation
Expand file tree
/
Copy pathloop.php
More file actions
95 lines (66 loc) · 2.32 KB
/
Copy pathloop.php
File metadata and controls
95 lines (66 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
const MAX_TRIES = 3;
function claude(string $prompt, string $extra = '', bool $capture = false): string
{
$cmd = 'claude -p '.escapeshellarg($prompt)
.' --dangerously-skip-permissions --output-format text '
.$extra.' < /dev/null';
if (! $capture) {
passthru($cmd);
return '';
}
return (string) shell_exec($cmd.' 2>&1');
}
$file = file_get_contents('.spec/init/project-phases.md');
$phases = preg_match_all(
'/^## Phase \d+:.*?(?=^## Phase \d+:|\z)/ms',
$file,
$matches,
);
$phases = $matches[0];
foreach ($phases as $phase) {
echo preg_split("/\n/", $phase)[0].PHP_EOL;
}
foreach ($phases as $phase) {
$title = ltrim(preg_split("/\n/", $phase)[0], '# ');
$reason = '';
for ($attempt = 1; $attempt <= MAX_TRIES; $attempt++) {
echo "Iniciando (tentativa $attempt/".MAX_TRIES."): $title".PHP_EOL;
$prompt = <<<PROMPT
Voce e um desenvolvedor senior. Implemente COMPLETAMENTE a fase abaixo.
Sem TODOs, sem placeholders.
$reason
$phase
PROMPT;
echo $prompt;
claude($prompt);
$output = [];
$code = 0;
exec('./vendor/bin/sail pest'.' < /dev/null 2>&1', $output, $code);
if ($code !== 0) {
$reason = "A tentativa anterior falhou nos testes:\n"
.implode("\n", array_slice($output, -30));
echo " testes FALHARAM\n";
continue;
}
$prompt = <<<PROMPT
Voce e um verificador independente. NAO escreva nem edite nenhum arquivo.
Leia o codigo real e responda EXATAMENTE UMA linha, sem mais nada:
DONE
FALTA — <o que ainda nao esta implementado>
Na duvida, FALTA.
$phase
PROMPT;
$veridct = claude($prompt, '--allowedTools "Read,Glob,Grep"', true);
if (preg_match('/^DONE/m', $veridct)) {
echo " avaliador OK\n";
exec('git add -A && git commit -q -m '.escapeshellarg("feat: $title").' 2>&1');
break;
}
$reason = "A tentativa anterior foi reprovada pelo avaliador: $veridct";
echo " avaliador REPROVOU: $veridct\n";
if ($attempt === MAX_TRIES) {
echo " DESISTINDO de: $title\n";
}
}
}