refactor(LLM CLI): 明確化 CLI 參數與驗證輸出

This commit is contained in:
2026-06-29 10:49:22 +00:00
parent 68ce92b0e5
commit 0b59ca6023
3 changed files with 11 additions and 5 deletions
+3
View File
@@ -1,6 +1,8 @@
import https from 'https'; import https from 'https';
import { execFileSync } from 'child_process'; import { execFileSync } from 'child_process';
// 本 action 會連接自架 Gitea / OpenCode,部署環境可能使用內部 CA 或自簽憑證。
// 對外部服務請優先使用預設 TLS 驗證;需要內部服務相容時才使用 getInsecureHttpsAgent()。
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
export const GITEA_TOKEN = process.env.GITEA_TOKEN || ''; export const GITEA_TOKEN = process.env.GITEA_TOKEN || '';
@@ -29,6 +31,7 @@ export function getInsecureHttpsAgent() {
return (_insecureHttpsAgent ??= new https.Agent({ rejectUnauthorized: false })); return (_insecureHttpsAgent ??= new https.Agent({ rejectUnauthorized: false }));
} }
// 過渡別名:既有呼叫端仍可用 OpenCode 語意名稱;新程式碼請直接使用 getInsecureHttpsAgent。
export const getOpenCodeHttpsAgent = getInsecureHttpsAgent; export const getOpenCodeHttpsAgent = getInsecureHttpsAgent;
const CLI_CANDIDATES = [ const CLI_CANDIDATES = [
+2 -2
View File
@@ -23,7 +23,7 @@ function buildPrompt(systemPrompt, userContent) {
].join('\n'); ].join('\n');
} }
function cliArgs(provider, model, promptFile = null, prompt = null) { function cliArgs({ provider, model, promptFile = null, prompt = null }) {
if (provider === 'codex') { if (provider === 'codex') {
return ['exec', '--model', model, '--sandbox', 'read-only', '--skip-git-repo-check', '-']; return ['exec', '--model', model, '--sandbox', 'read-only', '--skip-git-repo-check', '-'];
} }
@@ -53,7 +53,7 @@ async function runAssistantCLI({ provider, command, model }, prompt) {
promptFile = join(tempDir, 'prompt.md'); promptFile = join(tempDir, 'prompt.md');
await writeFile(promptFile, prompt); await writeFile(promptFile, prompt);
} }
const args = cliArgs(provider, model, promptFile, prompt); const args = cliArgs({ provider, model, promptFile, prompt });
const maxBuffer = Number(process.env.AI_ASSISTANT_MAX_BUFFER || 20 * 1024 * 1024); const maxBuffer = Number(process.env.AI_ASSISTANT_MAX_BUFFER || 20 * 1024 * 1024);
const timeout = Number(process.env.AI_ASSISTANT_TIMEOUT_MS || 15 * 60 * 1000); const timeout = Number(process.env.AI_ASSISTANT_TIMEOUT_MS || 15 * 60 * 1000);
try { try {
+6 -3
View File
@@ -100,8 +100,11 @@ export async function verifyCommentToken(token = GITEA_COMMENT_TOKEN) {
* *
* 確認目前環境可偵測到支援的 CLI,且已解析出 model。實際模型可用性由 CLI * 確認目前環境可偵測到支援的 CLI,且已解析出 model。實際模型可用性由 CLI
* 在正式呼叫時回報;preflight 不主動送 prompt,避免額外消耗額度。 * 在正式呼叫時回報;preflight 不主動送 prompt,避免額外消耗額度。
* @returns {Promise<{ok: true, provider: string}|{ok: false, provider?: string, error: string}>} * @returns {Promise<
* 通過時含 provider;未設定 provider 的失敗分支不含 provider 欄位。 * {ok: true, provider: string, command: string, model: string} |
* {ok: false, provider?: string, error: string}
* >}
* 通過時含 provider、command 與 model;未設定 provider 的失敗分支不含 provider 欄位。
* @remarks 設定來源為 config.js 的 getLLMConfig()。 * @remarks 設定來源為 config.js 的 getLLMConfig()。
*/ */
export async function verifyLLM() { export async function verifyLLM() {
@@ -170,7 +173,7 @@ export async function runPreflight(workspace = process.env.GITHUB_WORKSPACE || '
error(`LLM 驗證失敗: ${llm.error}`); error(`LLM 驗證失敗: ${llm.error}`);
return false; return false;
} }
ok(`LLM provider=${llm.provider} CLI 可用`); ok(`LLM CLI 可用(command=${llm.command}, provider=${llm.provider}, model=${llm.model}`);
result(true, '前置驗證通過'); result(true, '前置驗證通過');
return true; return true;