From 0b59ca6023f947e03513de7cacadfdff4d370cc6 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Mon, 29 Jun 2026 10:49:22 +0000 Subject: [PATCH] =?UTF-8?q?refactor(LLM=20CLI):=20=E6=98=8E=E7=A2=BA?= =?UTF-8?q?=E5=8C=96=20CLI=20=E5=8F=83=E6=95=B8=E8=88=87=E9=A9=97=E8=AD=89?= =?UTF-8?q?=E8=BC=B8=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/config.js | 3 +++ app/llm.js | 4 ++-- app/preflight.js | 9 ++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/config.js b/app/config.js index 4c8db14..d03191e 100644 --- a/app/config.js +++ b/app/config.js @@ -1,6 +1,8 @@ import https from 'https'; import { execFileSync } from 'child_process'; +// 本 action 會連接自架 Gitea / OpenCode,部署環境可能使用內部 CA 或自簽憑證。 +// 對外部服務請優先使用預設 TLS 驗證;需要內部服務相容時才使用 getInsecureHttpsAgent()。 process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; export const GITEA_TOKEN = process.env.GITEA_TOKEN || ''; @@ -29,6 +31,7 @@ export function getInsecureHttpsAgent() { return (_insecureHttpsAgent ??= new https.Agent({ rejectUnauthorized: false })); } +// 過渡別名:既有呼叫端仍可用 OpenCode 語意名稱;新程式碼請直接使用 getInsecureHttpsAgent。 export const getOpenCodeHttpsAgent = getInsecureHttpsAgent; const CLI_CANDIDATES = [ diff --git a/app/llm.js b/app/llm.js index 0226b0a..cfde26e 100644 --- a/app/llm.js +++ b/app/llm.js @@ -23,7 +23,7 @@ function buildPrompt(systemPrompt, userContent) { ].join('\n'); } -function cliArgs(provider, model, promptFile = null, prompt = null) { +function cliArgs({ provider, model, promptFile = null, prompt = null }) { if (provider === 'codex') { 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'); 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 timeout = Number(process.env.AI_ASSISTANT_TIMEOUT_MS || 15 * 60 * 1000); try { diff --git a/app/preflight.js b/app/preflight.js index e707238..d5b3cc8 100644 --- a/app/preflight.js +++ b/app/preflight.js @@ -100,8 +100,11 @@ export async function verifyCommentToken(token = GITEA_COMMENT_TOKEN) { * * 確認目前環境可偵測到支援的 CLI,且已解析出 model。實際模型可用性由 CLI * 在正式呼叫時回報;preflight 不主動送 prompt,避免額外消耗額度。 - * @returns {Promise<{ok: true, provider: string}|{ok: false, provider?: string, error: string}>} - * 通過時含 provider;未設定 provider 的失敗分支不含 provider 欄位。 + * @returns {Promise< + * {ok: true, provider: string, command: string, model: string} | + * {ok: false, provider?: string, error: string} + * >} + * 通過時含 provider、command 與 model;未設定 provider 的失敗分支不含 provider 欄位。 * @remarks 設定來源為 config.js 的 getLLMConfig()。 */ export async function verifyLLM() { @@ -170,7 +173,7 @@ export async function runPreflight(workspace = process.env.GITHUB_WORKSPACE || ' error(`LLM 驗證失敗: ${llm.error}`); return false; } - ok(`LLM provider=${llm.provider} CLI 可用`); + ok(`LLM CLI 可用(command=${llm.command}, provider=${llm.provider}, model=${llm.model})`); result(true, '前置驗證通過'); return true;