fix: 修复 BriefTool 循环依赖导致 isBriefEnabled 未定义

将模块顶层 require() 改为懒加载函数 getBriefToolModule(),
延迟到实际调用时才加载模块,避免循环依赖时模块尚未完成初始化。
This commit is contained in:
claude-code-best
2026-05-22 21:04:17 +08:00
parent 897c186f28
commit d4a601475f

View File

@@ -82,10 +82,11 @@ const BRIEF_PROACTIVE_SECTION: string | null =
require('@claude-code-best/builtin-tools/tools/BriefTool/prompt.js') as typeof import('@claude-code-best/builtin-tools/tools/BriefTool/prompt.js') require('@claude-code-best/builtin-tools/tools/BriefTool/prompt.js') as typeof import('@claude-code-best/builtin-tools/tools/BriefTool/prompt.js')
).BRIEF_PROACTIVE_SECTION ).BRIEF_PROACTIVE_SECTION
: null : null
const briefToolModule = function getBriefToolModule() {
feature('KAIROS') || feature('KAIROS_BRIEF') return feature('KAIROS') || feature('KAIROS_BRIEF')
? (require('@claude-code-best/builtin-tools/tools/BriefTool/BriefTool.js') as typeof import('@claude-code-best/builtin-tools/tools/BriefTool/BriefTool.js')) ? (require('@claude-code-best/builtin-tools/tools/BriefTool/BriefTool.js') as typeof import('@claude-code-best/builtin-tools/tools/BriefTool/BriefTool.js'))
: null : null
}
const DISCOVER_SKILLS_TOOL_NAME: string | null = feature( const DISCOVER_SKILLS_TOOL_NAME: string | null = feature(
'EXPERIMENTAL_SKILL_SEARCH', 'EXPERIMENTAL_SKILL_SEARCH',
) )
@@ -800,7 +801,7 @@ function getBriefSection(): string | null {
// Whenever the tool is available, the model is told to use it. The // Whenever the tool is available, the model is told to use it. The
// /brief toggle and --brief flag now only control the isBriefOnly // /brief toggle and --brief flag now only control the isBriefOnly
// display filter — they no longer gate model-facing behavior. // display filter — they no longer gate model-facing behavior.
if (!briefToolModule?.isBriefEnabled()) return null if (!getBriefToolModule()?.isBriefEnabled()) return null
// When proactive is active, getProactiveSection() already appends the // When proactive is active, getProactiveSection() already appends the
// section inline. Skip here to avoid duplicating it in the system prompt. // section inline. Skip here to avoid duplicating it in the system prompt.
if ( if (
@@ -864,5 +865,5 @@ Do not narrate each step, list every file you read, or explain routine actions.
The user context may include a \`terminalFocus\` field indicating whether the user's terminal is focused or unfocused. Use this to calibrate how autonomous you are: The user context may include a \`terminalFocus\` field indicating whether the user's terminal is focused or unfocused. Use this to calibrate how autonomous you are:
- **Unfocused**: The user is away. Lean heavily into autonomous action — make decisions, explore, commit, push. Only pause for genuinely irreversible or high-risk actions. - **Unfocused**: The user is away. Lean heavily into autonomous action — make decisions, explore, commit, push. Only pause for genuinely irreversible or high-risk actions.
- **Focused**: The user is watching. Be more collaborative — surface choices, ask before committing to large changes, and keep your output concise so it's easy to follow in real time.${BRIEF_PROACTIVE_SECTION && briefToolModule?.isBriefEnabled() ? `\n\n${BRIEF_PROACTIVE_SECTION}` : ''}` - **Focused**: The user is watching. Be more collaborative — surface choices, ask before committing to large changes, and keep your output concise so it's easy to follow in real time.${BRIEF_PROACTIVE_SECTION && getBriefToolModule()?.isBriefEnabled() ? `\n\n${BRIEF_PROACTIVE_SECTION}` : ''}`
} }