Context 构建系统负责组装发送给 Claude API 的系统提示和用户上下文。包括 git 状态获取、CLAUDE.md 文件发现与加载、系统提示拼装三部分。
| 文件 | 关键导出 |
|---|---|
src/context.ts |
getSystemContext, getUserContext, getGitStatus, setSystemPromptInjection |
src/utils/claudemd.ts |
stripHtmlComments, getClaudeMds, isMemoryFilePath, getLargeMemoryFiles, filterInjectedMemoryFiles, getExternalClaudeMdIncludes, hasExternalClaudeMdIncludes, processMemoryFile, getMemoryFiles |
src/utils/systemPrompt.ts |
buildEffectiveSystemPrompt |
"text <!-- comment --> more" → content 不含注释html\n<!-- not stripped -->\n 内的注释不移除"" → { content: "", stripped: false }"/project/CLAUDE.md" → true"/project/.claude/rules/foo.md" → true"~/.claude/memory/foo.md" → true"/project/src/main.ts" → false"/project/README.md" → false--system-prompt 参数替换默认NODE_ENV=test 时返回 null| 依赖 | Mock 方式 | 用途 |
|---|---|---|
execFileNoThrow |
mock.module |
getGitStatus 中的 git 命令 |
getMemoryFiles |
mock.module |
getUserContext 中的 CLAUDE.md 加载 |
getCwd |
mock.module |
路径解析上下文 |
process.env.NODE_ENV |
直接设置 | 测试环境检测 |
process.env.CLAUDE_CODE_DISABLE_CLAUDE_MDS |
直接设置 | 禁用 CLAUDE.md |
放在 tests/integration/context-build.test.ts: