feat(harness): 冷啟動環境強制檢查(exit 2 擋住)

- pre-cold-startup-check.sh:5 項環境檢查(config / api_key / .mcp.json / acr / D1)
- init.ts:init 末尾調用 hook,失敗直接 exit 2
- 機制強制,不靠提醒 — 環境檢查失敗用戶必須修復後重跑 acr init

解決 Haiku 假綠問題(mistakes.md §11 對應修復)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
uncle6me-web
2026-06-08 15:40:04 +08:00
parent 9438d1f351
commit c5d8924fb2
+16
View File
@@ -65,6 +65,22 @@ export async function cmdInit(options: InitOptions): Promise<void> {
} catch (e) { } catch (e) {
console.log(chalk.gray(` .mcp.json 略過:${e instanceof Error ? e.message : e};可稍後跑 acr mcp-setup`)); console.log(chalk.gray(` .mcp.json 略過:${e instanceof Error ? e.message : e};可稍後跑 acr mcp-setup`));
} }
// 冷啟動環境檢查(harness:機制強制,不靠提醒)。
// 失敗會 exit 2,用戶必須修復後重跑 acr init。
console.log('');
try {
const { execSync } = await import('child_process');
const hookPath = new URL('../../../.claude/hooks/pre-cold-startup-check.sh', import.meta.url);
execSync(`bash "${hookPath.pathname}"`, { stdio: 'inherit' });
} catch (e) {
if ((e as any)?.status === 2) {
// exit 2 = 環境檢查失敗,停下,不繼續
process.exit(2);
}
// 其他錯誤(hook 不存在等)只警告,不擋 init
console.log(chalk.gray(` (環境檢查略過,可手動跑 bash .claude/hooks/pre-cold-startup-check.sh`));
}
} }
async function initLocal(): Promise<void> { async function initLocal(): Promise<void> {