Skip to content

Commit be82b71

Browse files
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>
1 parent 88b45e0 commit be82b71

5 files changed

Lines changed: 46 additions & 2 deletions

File tree

DEV-LOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# DEV-LOG
22

3+
## Auto Mode 补全 (2026-04-02)
4+
5+
反编译丢失了 auto mode 分类器的三个 prompt 模板文件,代码逻辑完整但无法运行。
6+
7+
**新增:**
8+
- `yolo-classifier-prompts/auto_mode_system_prompt.txt` — 主系统提示词
9+
- `yolo-classifier-prompts/permissions_external.txt` — 外部权限模板(用户规则替换默认值)
10+
- `yolo-classifier-prompts/permissions_anthropic.txt` — 内部权限模板(用户规则追加)
11+
12+
**改动:**
13+
- `scripts/dev.ts` + `build.ts` — 扫描 `FEATURE_*` 环境变量注入 Bun `--feature`
14+
- `cli.tsx` — 启动时打印已启用的 feature
15+
- `permissionSetup.ts``AUTO_MODE_ENABLED_DEFAULT``feature('TRANSCRIPT_CLASSIFIER')` 决定,开 feature 即开 auto mode
16+
- `docs/safety/auto-mode.mdx` — 补充 prompt 模板章节
17+
18+
**用法:** `FEATURE_TRANSCRIPT_CLASSIFIER=1 bun run dev`
19+
20+
**注意:** prompt 模板为重建产物。
21+
22+
---
23+
324
## USER_TYPE=ant TUI 修复 (2026-04-02)
425

526
`global.d.ts` 声明的全局函数在反编译版本运行时未定义,导致 `USER_TYPE=ant` 时 TUI 崩溃。

build.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ const outdir = "dist";
88
const { rmSync } = await import("fs");
99
rmSync(outdir, { recursive: true, force: true });
1010

11+
// Collect FEATURE_* env vars → Bun.build features
12+
const features = Object.keys(process.env)
13+
.filter(k => k.startsWith("FEATURE_"))
14+
.map(k => k.replace("FEATURE_", ""));
15+
1116
// Step 2: Bundle with splitting
1217
const result = await Bun.build({
1318
entrypoints: ["src/entrypoints/cli.tsx"],
1419
outdir,
1520
target: "bun",
1621
splitting: true,
1722
define: getMacroDefines(),
23+
features,
1824
});
1925

2026
if (!result.success) {

scripts/dev.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@ const defineArgs = Object.entries(defines).flatMap(([k, v]) => [
1313
`${k}:${v}`,
1414
]);
1515

16+
// Bun --feature flags: enable feature() gates at runtime.
17+
// Any env var matching FEATURE_<NAME>=1 will enable that feature.
18+
// e.g. FEATURE_TRANSCRIPT_CLASSIFIER=1 bun run dev
19+
const featureArgs: string[] = Object.entries(process.env)
20+
.filter(([k]) => k.startsWith("FEATURE_"))
21+
.flatMap(([k]) => {
22+
const name = k.replace("FEATURE_", "");
23+
return ["--feature", name];
24+
});
25+
1626
const result = Bun.spawnSync(
17-
["bun", "run", ...defineArgs, "src/entrypoints/cli.tsx", ...process.argv.slice(2)],
27+
["bun", "run", ...defineArgs, ...featureArgs, "src/entrypoints/cli.tsx", ...process.argv.slice(2)],
1828
{ stdio: ["inherit", "inherit", "inherit"] },
1929
);
2030

src/entrypoints/cli.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/usr/bin/env bun
22
import { feature } from 'bun:bundle';
33

4+
// eslint-disable-next-line custom-rules/no-top-level-side-effects
5+
if (feature('TRANSCRIPT_CLASSIFIER')) {
6+
// eslint-disable-next-line custom-rules/no-console, custom-rules/no-top-level-side-effects
7+
console.log('[dev] feature TRANSCRIPT_CLASSIFIER enabled');
8+
}
9+
410
// Bugfix for corepack auto-pinning, which adds yarnpkg to peoples' package.jsons
511
// eslint-disable-next-line custom-rules/no-top-level-side-effects
612
process.env.COREPACK_ENABLE_AUTO_PIN = '0';

src/utils/permissions/permissionSetup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,8 @@ export function getAutoModeUnavailableReason(): AutoModeUnavailableReason | null
13101310
*/
13111311
export type AutoModeEnabledState = 'enabled' | 'disabled' | 'opt-in'
13121312

1313-
const AUTO_MODE_ENABLED_DEFAULT: AutoModeEnabledState = 'disabled'
1313+
const AUTO_MODE_ENABLED_DEFAULT: AutoModeEnabledState =
1314+
feature('TRANSCRIPT_CLASSIFIER') ? 'enabled' : 'disabled'
13141315

13151316
function parseAutoModeEnabledState(value: unknown): AutoModeEnabledState {
13161317
if (value === 'enabled' || value === 'disabled' || value === 'opt-in') {

0 commit comments

Comments
 (0)