Files
Arcrun/cli/src/commands/config.ts
T
uncle6me-web 5f381a44a6 fix(self-hosted): 修壓測四阻斷項 + 設定分層 + init 非互動
壓測(docs/壓測報告.md)發現 acr init --self-hosted 對任何非官方 CF
帳號都裝不起來,且設定寫死全域單檔 + 強制 TTY。本次一併修:

R2 dead storage 全清(#3#4,registry-canon Phase 1.5 補完):
- cypher-executor wrangler.toml/test.toml/types.ts 移除 WASM_BUCKET binding
- CLI deploy.ts/init.ts/cf-api.ts/config.ts 移除 R2 建立邏輯與 wasm_bucket
- R2 綁信用卡違背「開源免費自架」核心;bucket 名 WASM_BUCKET 本就非法
  → self-hosted 改為只需 Workers + KV(皆免費額度、不綁卡)

fork 帳號部署阻斷(#1#2):
- deploy.ts 新增 stripOfficialOnlyBindings(),注入暫存副本時移除
  [[routes]]/zone_name/[[r2_buckets]]/[ai](fork 沒有 arcrun.dev zone)
- 不刪 repo 內 toml(官方 prod CI 部署仍需 routes),只在 CLI self-hosted 路徑 strip

設定分層 + 非互動(#7#8):
- config.ts loadConfig 改三層:env > 專案層 .arcrun.yaml(就近往上找)> 全域
- init 支援 --account-id/--api-token flag + CLOUDFLARE_* env,缺才互動
- 新增 acr config --where 顯示每個值的來源層(token 自動遮罩)
- gitignore 一併排除 .arcrun.yaml

驗收:tsc 全綠;三層 merge 端對端測試 8/8;strip 對真實 toml 驗證
routes/R2/AI 移除而 name/workers_dev/KV 保留。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 07:22:37 +08:00

50 lines
1.7 KiB
TypeScript

/**
* acr config [--where] — 顯示目前生效的設定與每個值的來源層。
* 解壓測 §1.2 建議 #3:讓使用者一眼確認「現在這個資料夾正用哪個帳號」,避免用錯帳號部署。
* SDD: sdk-and-website/config-layering.md §3.1
*/
import chalk from 'chalk';
import {
resolveConfigSources,
activeProjectConfigPath,
type ConfigSource,
} from '../lib/config.js';
const SOURCE_LABEL: Record<ConfigSource, string> = {
env: 'env 變數',
project: '專案層 .arcrun.yaml',
global: '全域 ~/.arcrun/config.yaml',
default: '預設值',
};
/** 敏感欄位只印前綴,避免把 token 完整印到終端 / log。*/
const SENSITIVE = new Set(['api_key', 'encryption_key', 'cf_api_token']);
function mask(field: string, value: string): string {
if (SENSITIVE.has(field) && value.length > 8) return `${value.slice(0, 8)}…`;
return value;
}
export async function cmdConfig(_options: { where?: boolean }): Promise<void> {
const rows = resolveConfigSources();
const projectPath = activeProjectConfigPath();
console.log(chalk.bold('\n arcrun 目前生效的設定\n'));
if (projectPath) {
console.log(chalk.gray(` 專案層設定:${projectPath}(覆蓋全域)`));
} else {
console.log(chalk.gray(' 專案層設定:無(此資料夾未放 .arcrun.yaml,使用全域)'));
}
console.log('');
const fieldWidth = Math.max(...rows.map(r => r.field.length), 4);
for (const { field, value, source } of rows) {
const name = field.padEnd(fieldWidth);
console.log(
` ${chalk.cyan(name)} ${mask(field, value)} ${chalk.gray(`← ${SOURCE_LABEL[source]}`)}`,
);
}
console.log(chalk.gray('\n 優先序:env 變數 > 專案層 .arcrun.yaml > 全域 ~/.arcrun/config.yaml\n'));
}