Skip to content

Commit 7dfbcd0

Browse files
feat: 更新 buddy 的一些功能
1 parent 0d0304d commit 7dfbcd0

4 files changed

Lines changed: 28 additions & 44 deletions

File tree

DEV-LOG.md

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

3+
## Buddy 命令合入 + Feature Flag 规范修正 (2026-04-02)
4+
5+
合入 `pr/smallflyingpig/36` 分支(支持 buddy 命令 + 修复 rehatch),并修正 feature flag 使用方式。
6+
7+
**合入内容(来自 PR):**
8+
- `src/commands/buddy/buddy.ts` — 新增 `/buddy` 命令,支持 hatch / rehatch / pet / mute / unmute 子命令
9+
- `src/commands/buddy/index.ts` — 从 stub 改为正确的 `Command` 类型导出
10+
- `src/buddy/companion.ts` — 新增 `generateSeed()``getCompanion()` 支持 seed 驱动的可复现 rolling
11+
- `src/buddy/types.ts``CompanionSoul` 增加 `seed?` 字段
12+
13+
**合并后修正:**
14+
- `src/entrypoints/cli.tsx` — PR 硬编码了 `const feature = (name) => name === "BUDDY"`,违反 feature flag 规范,恢复为标准 `import { feature } from 'bun:bundle'`
15+
- `src/commands.ts` — PR 用静态 `import buddy` 绕过了 feature gate,恢复为 `feature('BUDDY') ? require(...) : null` + 条件展开
16+
- `src/commands/buddy/buddy.ts` — 删除未使用的 `companionInfoText` 函数和多余的 `Roll`/`SPECIES` import
17+
- `CLAUDE.md` — 重写 Feature Flag System 章节,明确规范:代码中统一用 `import { feature } from 'bun:bundle'`,启用走环境变量 `FEATURE_<NAME>=1`
18+
19+
**用法:** `FEATURE_BUDDY=1 bun run dev`
20+
21+
---
22+
323
## Auto Mode 补全 (2026-04-02)
424

525
反编译丢失了 auto mode 分类器的三个 prompt 模板文件,代码逻辑完整但无法运行。

src/commands.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ const forkCmd = feature('FORK_SUBAGENT')
115115
require('./commands/fork/index.js') as typeof import('./commands/fork/index.js')
116116
).default
117117
: null
118-
// buddy loaded directly (not feature-gated) for this build
119-
import buddy from './commands/buddy/index.js'
118+
const buddy = feature('BUDDY')
119+
? (
120+
require('./commands/buddy/index.js') as typeof import('./commands/buddy/index.js')
121+
).default
122+
: null
120123
/* eslint-enable @typescript-eslint/no-require-imports */
121124
import thinkback from './commands/thinkback/index.js'
122125
import thinkbackPlay from './commands/thinkback-play/index.js'
@@ -316,7 +319,7 @@ const COMMANDS = memoize((): Command[] => [
316319
vim,
317320
...(webCmd ? [webCmd] : []),
318321
...(forkCmd ? [forkCmd] : []),
319-
buddy,
322+
...(buddy ? [buddy] : []),
320323
...(proactive ? [proactive] : []),
321324
...(briefCommand ? [briefCommand] : []),
322325
...(assistantCommand ? [assistantCommand] : []),

src/commands/buddy/buddy.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import {
22
getCompanion,
33
rollWithSeed,
44
generateSeed,
5-
type Roll,
65
} from '../../buddy/companion.js'
76
import {
87
type StoredCompanion,
98
RARITY_STARS,
109
STAT_NAMES,
11-
SPECIES,
1210
} from '../../buddy/types.js'
1311
import { renderSprite } from '../../buddy/sprites.js'
1412
import { getGlobalConfig, saveGlobalConfig } from '../../utils/config.js'
@@ -71,25 +69,6 @@ function renderStats(stats: Record<string, number>): string {
7169
return lines.join('\n')
7270
}
7371

74-
function companionInfoText(roll: Roll): string {
75-
const { bones } = roll
76-
const sprite = renderSprite(bones, 0)
77-
const stars = RARITY_STARS[bones.rarity]
78-
const name = SPECIES_NAMES[bones.species] ?? 'Buddy'
79-
const shiny = bones.shiny ? ' ✨ Shiny!' : ''
80-
81-
return [
82-
sprite.join('\n'),
83-
'',
84-
` ${name} the ${speciesLabel(bones.species)}${shiny}`,
85-
` Rarity: ${stars} (${bones.rarity})`,
86-
` Eye: ${bones.eye} Hat: ${bones.hat}`,
87-
'',
88-
' Stats:',
89-
renderStats(bones.stats),
90-
].join('\n')
91-
}
92-
9372
export const call: LocalCommandCall = async (args, _context) => {
9473
const sub = args.trim().toLowerCase()
9574
const config = getGlobalConfig()
@@ -177,15 +156,14 @@ export const call: LocalCommandCall = async (args, _context) => {
177156
}
178157
}
179158

180-
// Import setAppState dynamically to update companionPetAt
181159
try {
182160
const { setAppState } = await import('../../state/AppStateStore.js')
183161
setAppState(prev => ({
184162
...prev,
185163
companionPetAt: Date.now(),
186164
}))
187165
} catch {
188-
// If AppState is not available (non-interactive), just show text
166+
// non-interactive mode — AppState not available
189167
}
190168

191169
return {

src/entrypoints/cli.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
#!/usr/bin/env bun
2-
3-
// Runtime polyfill for bun:bundle (build-time macros)
4-
const feature = (name: string) => name === "BUDDY";
5-
if (typeof globalThis.MACRO === "undefined") {
6-
(globalThis as any).MACRO = {
7-
VERSION: "2.1.888",
8-
BUILD_TIME: new Date().toISOString(),
9-
FEEDBACK_CHANNEL: "",
10-
ISSUES_EXPLAINER: "",
11-
NATIVE_PACKAGE_URL: "",
12-
PACKAGE_URL: "",
13-
VERSION_CHANGELOG: "",
14-
};
15-
}
16-
// Build-time constants — normally replaced by Bun bundler at compile time
17-
(globalThis as any).BUILD_TARGET = "external";
18-
(globalThis as any).BUILD_ENV = "production";
19-
(globalThis as any).INTERFACE_TYPE = "stdio";
2+
import { feature } from 'bun:bundle';
203

214
// Bugfix for corepack auto-pinning, which adds yarnpkg to peoples' package.jsons
225
// eslint-disable-next-line custom-rules/no-top-level-side-effects

0 commit comments

Comments
 (0)