Skip to content

Commit cdd0eb9

Browse files
author
ityaozm@gmail.com
committed
fix(Generators): 修复 GithubCopilotCliGenerator 输出格式
- 修复 `generate` 方法的输出格式 - 添加调试语句以输出生成的 `$output` 变量 - 使用 `dump()` 方法来调试输出 - 清理输出中的控制字符
1 parent 8cb568f commit cdd0eb9

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

app/Generators/GithubCopilotCliGenerator.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,23 @@ public function __construct(array $config)
4343
*/
4444
public function generate(string $prompt): string
4545
{
46-
$output = <<<'EOF'
47-
48-
Welcome to GitHub Copilot in the CLI!
49-
version 1.0.5 (2024-09-12)
50-
51-
I'm powered by AI, so surprises and mistakes are possible. Make sure to verify any generated code or suggestions, and share feedback so that we can learn and improve. For more information, see https://gh.io/gh-copilot-transparency
52-
53-
54-
# Explanation:
55-
56-
{
57-
"subject": "feat(Generators): update GithubCopilotCliGenerator to include binary command",
58-
"body": "- Change the command array in the `resolve` function call to include `['binary', 'copilot', 'explain', $prompt]` as the command\n- Update the `mustRun` function
59-
callback to handle output formatting\n- Add debug statements to output the generated `$output` variable and perform a `dd()` call\n- Return the generated `$output` variable"
60-
}
61-
62-
63-
64-
EOF;
6546
$output = resolve(
6647
Process::class,
6748
['command' => [$this->config['binary'], 'copilot', 'explain', $prompt]] + $this->config['parameters']
6849
)->mustRun(function (string $type, string $data): void {
6950
Process::OUT === $type ? $this->outputStyle->write($data) : $this->outputStyle->write("<fg=red>$data</>");
7051
})->getOutput();
7152

72-
return str($output)->match('/\{.*\}/s')->__toString();
53+
return (string) str($output)
54+
->dump()
55+
->match('/\{.*\}/s')
56+
->dump()
57+
// ->replace(
58+
// ["\\'", PHP_EOL],
59+
// ["'", '']
60+
// )
61+
->dump()
62+
->replaceMatches('/[[:cntrl:]]/mu', '')
63+
->dump();
7364
}
7465
}

0 commit comments

Comments
 (0)