diff --git a/cli/src/commands/init.ts b/cli/src/commands/init.ts index 63395de..23306a6 100644 --- a/cli/src/commands/init.ts +++ b/cli/src/commands/init.ts @@ -65,6 +65,22 @@ export async function cmdInit(options: InitOptions): Promise { } catch (e) { 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 {