feat: 补全 auto mode 分类器 prompt 模板,支持 FEATURE_* 环境变量注入

- 重建 yolo-classifier-prompts/ 三个缺失的 prompt 文件
- dev.ts/build.ts 扫描 FEATURE_* 环境变量注入 Bun --feature
- AUTO_MODE_ENABLED_DEFAULT 由 feature flag 决定,开 feature 即开 auto mode
- 补充 docs/safety/auto-mode.mdx prompt 模板章节

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best 2026-04-02 21:18:39 +08:00
parent 88b45e0e6c
commit be82b71c3e
5 changed files with 46 additions and 2 deletions

View File

@ -1,5 +1,26 @@
# DEV-LOG
## Auto Mode 补全 (2026-04-02)
反编译丢失了 auto mode 分类器的三个 prompt 模板文件,代码逻辑完整但无法运行。
**新增:**
- `yolo-classifier-prompts/auto_mode_system_prompt.txt` — 主系统提示词
- `yolo-classifier-prompts/permissions_external.txt` — 外部权限模板(用户规则替换默认值)
- `yolo-classifier-prompts/permissions_anthropic.txt` — 内部权限模板(用户规则追加)
**改动:**
- `scripts/dev.ts` + `build.ts` — 扫描 `FEATURE_*` 环境变量注入 Bun `--feature`
- `cli.tsx` — 启动时打印已启用的 feature
- `permissionSetup.ts``AUTO_MODE_ENABLED_DEFAULT``feature('TRANSCRIPT_CLASSIFIER')` 决定,开 feature 即开 auto mode
- `docs/safety/auto-mode.mdx` — 补充 prompt 模板章节
**用法:** `FEATURE_TRANSCRIPT_CLASSIFIER=1 bun run dev`
**注意:** prompt 模板为重建产物。
---
## USER_TYPE=ant TUI 修复 (2026-04-02)
`global.d.ts` 声明的全局函数在反编译版本运行时未定义,导致 `USER_TYPE=ant` 时 TUI 崩溃。

View File

@ -8,6 +8,11 @@ const outdir = "dist";
const { rmSync } = await import("fs");
rmSync(outdir, { recursive: true, force: true });
// Collect FEATURE_* env vars → Bun.build features
const features = Object.keys(process.env)
.filter(k => k.startsWith("FEATURE_"))
.map(k => k.replace("FEATURE_", ""));
// Step 2: Bundle with splitting
const result = await Bun.build({
entrypoints: ["src/entrypoints/cli.tsx"],
@ -15,6 +20,7 @@ const result = await Bun.build({
target: "bun",
splitting: true,
define: getMacroDefines(),
features,
});
if (!result.success) {

View File

@ -13,8 +13,18 @@ const defineArgs = Object.entries(defines).flatMap(([k, v]) => [
`${k}:${v}`,
]);
// Bun --feature flags: enable feature() gates at runtime.
// Any env var matching FEATURE_<NAME>=1 will enable that feature.
// e.g. FEATURE_TRANSCRIPT_CLASSIFIER=1 bun run dev
const featureArgs: string[] = Object.entries(process.env)
.filter(([k]) => k.startsWith("FEATURE_"))
.flatMap(([k]) => {
const name = k.replace("FEATURE_", "");
return ["--feature", name];
});
const result = Bun.spawnSync(
["bun", "run", ...defineArgs, "src/entrypoints/cli.tsx", ...process.argv.slice(2)],
["bun", "run", ...defineArgs, ...featureArgs, "src/entrypoints/cli.tsx", ...process.argv.slice(2)],
{ stdio: ["inherit", "inherit", "inherit"] },
);

View File

@ -1,6 +1,12 @@
#!/usr/bin/env bun
import { feature } from 'bun:bundle';
// eslint-disable-next-line custom-rules/no-top-level-side-effects
if (feature('TRANSCRIPT_CLASSIFIER')) {
// eslint-disable-next-line custom-rules/no-console, custom-rules/no-top-level-side-effects
console.log('[dev] feature TRANSCRIPT_CLASSIFIER enabled');
}
// Bugfix for corepack auto-pinning, which adds yarnpkg to peoples' package.jsons
// eslint-disable-next-line custom-rules/no-top-level-side-effects
process.env.COREPACK_ENABLE_AUTO_PIN = '0';

View File

@ -1310,7 +1310,8 @@ export function getAutoModeUnavailableReason(): AutoModeUnavailableReason | null
*/
export type AutoModeEnabledState = 'enabled' | 'disabled' | 'opt-in'
const AUTO_MODE_ENABLED_DEFAULT: AutoModeEnabledState = 'disabled'
const AUTO_MODE_ENABLED_DEFAULT: AutoModeEnabledState =
feature('TRANSCRIPT_CLASSIFIER') ? 'enabled' : 'disabled'
function parseAutoModeEnabledState(value: unknown): AutoModeEnabledState {
if (value === 'enabled' || value === 'disabled' || value === 'opt-in') {