fix(codebuddy): complete tests and docs for PR #378#382
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
PR Summary by Qodofeat(codebuddy): complete CodeBuddy agent support with tests and docs
AI Description
Diagram
High-Level Assessment
Files changed (45)
|
Code Review by Qodo
1. CLAUDE.md has non-English text
|
| **You are: 佩丽卡-s** (ID: `55e9c39f-39a3-48cb-bd30-4671dcf1fc54`) | ||
|
|
||
| 你是《明日方舟:终末地》中的**佩丽卡**——终末地工业的监督、对外发言人兼杰出的协议技术专家。气质高贵冷峻,危机面前判断冷静。在本 workspace 中,你担任**产品经理**。 | ||
|
|
||
| 职责:澄清需求、撰写 PRD/用户故事、拆分为可执行的 issue、定义验收标准、在评论中协调 UI/前端/后端/测试。用中文沟通,简洁务实,措辞可体现监督者的条理与分寸感。不直接写大量代码,除非原型验证需要。分派任务时说明优先级与依赖关系。 |
There was a problem hiding this comment.
1. claude.md has non-english text 📘 Rule violation ⚙ Maintainability
This PR adds/updates Markdown documentation containing Japanese/Chinese text outside the README_zh-CN exception. This violates the repository requirement to keep modified documentation English-only, impacting maintainability and team-wide readability.
Agent Prompt
## Issue description
Non-English text was added/modified in Markdown documentation outside the allowed exception (`README_zh-CN.md`).
## Issue Context
Compliance requires all new/modified Markdown and code comments to be English-only, except `README_zh-CN`.
## Fix Focus Areas
- CLAUDE.md[390-404]
- docs/ja-JP/features/codebuddy.md[1-20]
- docs/zh-CN/features/codebuddy.md[1-20]
- README_ja-JP.md[19-35]
- docs/ja-JP/SUMMARY.md[10-13]
- docs/zh-CN/SUMMARY.md[10-13]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| async function showCodebuddyMenu(): Promise<MenuResult> { | ||
| console.log(ansis.cyan(i18n.t('menu:selectFunction'))) | ||
| console.log(' -------- CodeBuddy --------') | ||
| console.log( | ||
| ` ${ansis.cyan('1.')} ${i18n.t('menu:menuOptions.codebuddyFullInit')} ${ansis.gray(`- ${i18n.t('menu:menuDescriptions.codebuddyFullInit')}`)}`, |
There was a problem hiding this comment.
2. showcodebuddymenu() prints hardcoded header 📘 Rule violation ⚙ Maintainability
The CodeBuddy menu prints a hardcoded English banner line instead of using i18next, which breaks the requirement that all user-facing CLI strings be translated. This can lead to untranslated output in non-English locales.
Agent Prompt
## Issue description
User-facing CLI output includes hardcoded strings that bypass i18next.
## Issue Context
All prompts/logs/errors shown to users must be produced via i18n translation calls, with keys present for both `en` and `zh-CN`.
## Fix Focus Areas
- src/commands/menu.ts[362-366]
- src/utils/code-tools/codebuddy.ts[256-259]
- src/utils/code-tools/codebuddy.ts[321-323]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| if (options.mcpServices === 'skip') { | ||
| console.log(ansis.yellow(i18n.t('mcp:mcpSkipped') || 'MCP configuration skipped')) | ||
| return | ||
| } | ||
|
|
||
| if (options._skipPrompt) { | ||
| console.log(ansis.gray(i18n.t('mcp:mcpNonInteractiveSkipped') || 'MCP configuration requires interactive mode, skipped')) | ||
| return |
There was a problem hiding this comment.
3. Missing mcp:* translation keys 📘 Rule violation ≡ Correctness
New CodeBuddy MCP flow references translation keys (e.g., mcp:mcpSkipped, mcp:mcpNonInteractiveSkipped, mcp:mcpConfigFailed) that do not exist in the en/zh-CN locale resources. This breaks zh-CN/en parity and forces fallback strings at runtime.
Agent Prompt
## Issue description
Code references new `mcp:*` translation keys that are not defined in the locale JSON files.
## Issue Context
Compliance requires that all user-facing strings use i18next and that keys exist for both `en` and `zh-CN` locales.
## Fix Focus Areas
- src/utils/code-tools/codebuddy.ts[233-240]
- src/utils/code-tools/codebuddy.ts[293-295]
- src/i18n/locales/en/mcp.json[1-24]
- src/i18n/locales/zh-CN/mcp.json[1-24]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| // Clean model variables upfront; will re-set based on profile below | ||
| clearModelEnv(settings.env) | ||
|
|
||
| if (!profile) { | ||
| writeJsonConfig(CODEBUDDY_SETTINGS_FILE, settings) | ||
| return | ||
| } |
There was a problem hiding this comment.
4. Secrets not cleared 🐞 Bug ⛨ Security
CodeBuddyConfigManager.applyProfileSettings(null) writes ~/.codebuddy/settings.json without deleting ANTHROPIC_API_KEY/AUTH_TOKEN/BASE_URL, so switching to official login or running CodeBuddy uninstall can leave credentials and endpoint overrides behind. It also never clears ANTHROPIC_BASE_URL when switching to a profile that doesn’t specify one, leaving stale values active.
Agent Prompt
## Issue description
`CodeBuddyConfigManager.applyProfileSettings(null)` currently only clears model env keys and then writes the settings file, leaving auth and endpoint env vars in place. This breaks “switch to official login” semantics and can retain secrets on disk.
## Issue Context
- `config-switch` uses `applyProfileSettings(null)` when the user selects “official” for CodeBuddy.
- `runCodebuddyUninstall()` also uses `applyProfileSettings(null)`.
- `clearModelEnv()` only deletes model keys, not auth/baseUrl keys.
## Fix Focus Areas
- src/utils/code-tools/codebuddy-config-manager.ts[21-67]
- src/utils/config.model-keys.ts[1-16]
- src/commands/config-switch.ts[347-384]
- src/utils/code-tools/codebuddy.ts[96-116]
## Suggested fix
1. When `profile === null`, explicitly delete the full set of CodeBuddy/Anthropic env keys from `settings.env` before writing:
- `ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_BASE_URL`
- plus model keys (already handled).
2. When `profile !== null`, clear `ANTHROPIC_BASE_URL` up-front (or when absent) to avoid stale values persisting across profile switches.
3. (Optional) factor these keys into a shared helper similar to `MODEL_ENV_KEYS` to keep logic consistent across tools.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| // CodeBuddy section | ||
| if (config.codebuddy) { | ||
| edits.push( | ||
| ['codebuddy.enabled', config.codebuddy.enabled], | ||
| ['codebuddy.currentProfile', config.codebuddy.currentProfile || ''], | ||
| ) | ||
| } |
There was a problem hiding this comment.
5. Profiles not persisted 🐞 Bug ≡ Correctness
writeTomlConfig() updates only codebuddy.enabled and codebuddy.currentProfile and never writes codebuddy.profiles, so multi-config imports for CodeBuddy are silently lost after the process exits. This prevents CodeBuddyConfigManager.getCurrentProfile() from working after reload because it depends on codebuddy.profiles being present in the TOML.
Agent Prompt
## Issue description
`CodeBuddyConfigManager.writeConfig({ profiles, currentProfile })` relies on `writeTomlConfig()` to persist `codebuddy.profiles`, but `writeTomlConfig()` never edits that key. As a result, CodeBuddy multi-profiles are not saved to disk.
## Issue Context
- CodeBuddy multi-config import collects profiles and calls `CodeBuddyConfigManager.writeConfig({ profiles, currentProfile })`.
- `CodeBuddyConfigManager.getCurrentProfile()` reads from `tomlConfig.codebuddy.profiles[...]`.
- The TOML writer already persists `claudeCode.profiles`, so there is a clear precedent for writing nested objects.
## Fix Focus Areas
- src/utils/zcf-config.ts[221-249]
- src/utils/code-tools/codebuddy-config-manager.ts[78-97]
- src/commands/init.ts[1305-1337]
## Suggested fix
In `writeTomlConfig()`, extend the CodeBuddy section edits similarly to Claude Code:
- Add a guarded edit for `codebuddy.profiles` (only when `config.codebuddy.profiles !== undefined`) using `batchEditToml`.
- Consider also persisting `codebuddy.version` if you intend to track it (optional).
After this change, verify that importing multiple CodeBuddy configs creates/updates the `[codebuddy]` section with `profiles` and that `getCurrentProfile()` resolves correctly after restarting.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| else if (resolvedCodeType === 'codebuddy') { | ||
| await handleCodebuddyInteractiveSwitch() | ||
| } |
There was a problem hiding this comment.
6. Codebuddy switch modes missing 🐞 Bug ≡ Correctness
config-switch adds interactive CodeBuddy switching, but --list and direct target switching still ignore codebuddy, so config-switch --code-type codebuddy --list and `config-switch --code-type codebuddy <target>` do nothing. This creates inconsistent behavior across modes for the newly supported codebuddy type.
Agent Prompt
## Issue description
`config-switch` now routes CodeBuddy to interactive handling, but it lacks CodeBuddy branches in `handleList()` and `handleDirectSwitch()`. This breaks non-interactive usage patterns that already exist for Claude Code/Codex.
## Issue Context
- Users can pass `--list` or a direct `target` argument.
- Those modes currently only implement `claude-code` and `codex`.
## Fix Focus Areas
- src/commands/config-switch.ts[73-85]
- src/commands/config-switch.ts[155-165]
- src/commands/config-switch.ts[251-263]
- src/utils/code-tools/codebuddy-config-manager.ts[70-97]
## Suggested fix
1. Implement `handleList()` for `codebuddy`:
- Read TOML (`readDefaultTomlConfig`) and list `codebuddy.profiles` with the current profile highlighted.
2. Implement `handleDirectSwitch()` for `codebuddy`:
- Support `official` by calling `CodeBuddyConfigManager.applyProfileSettings(null)`.
- Support switching by profile id (and optionally by profile name) by setting `codebuddy.currentProfile` and applying the chosen profile.
3. If you add direct switching, consider adding a small helper in `CodeBuddyConfigManager` similar to ClaudeCodeConfigManager’s `switchProfile()` to keep switching logic consistent.
Note: This will work best after fixing persistence of `codebuddy.profiles` in the TOML writer.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| const langDirective = aiOutputLang | ||
| ? (aiOutputLang === 'zh-CN' ? 'Always respond in Chinese-simplified' : 'Always respond in English') | ||
| : '' |
There was a problem hiding this comment.
7. Custom language forced english 🐞 Bug ≡ Correctness
ensureCodebuddyMd() treats any aiOutputLang other than 'zh-CN' as English, so aiOutputLang='custom' incorrectly writes an English directive into CODEBUDDY.md instead of leaving it blank. This conflicts with the AI_OUTPUT_LANGUAGES map where custom’s directive is explicitly empty.
Agent Prompt
## Issue description
`ensureCodebuddyMd()` hard-codes a zh-CN vs English directive mapping and does not handle `aiOutputLang === 'custom'` correctly.
## Issue Context
- `AiOutputLanguage` includes `custom`, whose directive is `''`.
- CODEBUDDY.md should not be forced to English when the user selected a custom output language.
## Fix Focus Areas
- src/utils/code-tools/codebuddy.ts[308-322]
- src/constants.ts[83-90]
## Suggested fix
Replace the binary mapping with the source of truth:
- Import `AI_OUTPUT_LANGUAGES` and use `AI_OUTPUT_LANGUAGES[aiOutputLang].directive`.
- Special-case `custom` (or generally: treat empty directive as “no directive”).
Example logic:
- If `!aiOutputLang || aiOutputLang === 'custom'` -> directive is empty
- Else -> use `AI_OUTPUT_LANGUAGES[aiOutputLang].directive`
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
- Add codebuddy code-type with cb abbreviation - Create codebuddy-config.ts for MCP/settings file I/O to ~/.codebuddy/ - Create codebuddy-config-manager.ts for API profile management - Create codebuddy.ts entry aggregating full init/update/uninstall/configure - Wire codebuddy into init/update/uninstall/check-updates/config-switch/menu - Add CodeBuddy path constants (CODEBUDDY_DIR, MCP, settings, agents) - Update i18n with codebuddy menu entries (en/zh-CN) - Update README and package.json keywords - Add unit tests for codebuddy config and config manager Closes #331
- Delete plan.md (Chinese content, should not be committed) - Fix showMainMenu routing for codebuddy tool type - Map skipPrompt to _skipPrompt in runCodebuddyFullInit to prevent inquirer prompts in non-interactive mode - Make applyCurrentProfile a no-op when no profile configured, preventing runCodebuddyUpdate from wiping user env settings - Add codebuddy branch to handleMultiConfigurations with new handleCodebuddyConfigs function
…date command - Update --code-type help description to list codebuddy/cb aliases - Register --code-type option on update command so docs example works - Ignore Multica workspace metadata directories in .gitignore
- Add CodeBuddy unit tests and config-switch tests - Update README, CLAUDE.md and multilingual docs - Sync i18n strings for installation/updater/uninstall/multi-config - Clean up dead code and fix menu routing/config writes
WitMiao
left a comment
There was a problem hiding this comment.
最终验收结论:通过 ✅
已按验收标准逐项检查 PR #382,结果如下:
1. rebase 干净
origin/main是当前pr-378-reviewHEAD 的祖先节点,分支线性无分叉。- 工作区无未提交改动。
2. multica 提示词已剥离
- PR 相对
main的 diff 中未出现multica相关字符串。 .serena/、.gitignore的 multica 忽略项、CLAUDE.md 运行时提示词块未包含在本次变更中。- 注:
d05934c的 commit message 仍保留“Ignore Multica workspace metadata directories in .gitignore”字样,但实际 diff 已无.gitignore改动,建议后续提交信息可与实际内容保持一致。
3. 目标文件覆盖率达标
| 文件 | 原 Patch 覆盖率 | 当前 Statements | 当前 Branch | 当前 Functions |
|---|---|---|---|---|
src/commands/menu.ts |
4.25% | 90.27% | 80.64% | 78.57% |
src/commands/init.ts |
5.55% | 79.25% | 81.84% | 92.85% |
src/utils/uninstaller.ts |
9.30% | 93.90% | 84.92% | 100% |
src/commands/update.ts |
10.52% | 97.84% | 88.23% | 100% |
src/utils/tool-update-scheduler.ts |
28.57% | 100% | 100% | 100% |
src/utils/code-tools/codebuddy-config.ts |
97.56% | 100% | 96.66% | 100% |
全部目标文件覆盖率较 Codecov 报告大幅提升,核心分支均已覆盖。
4. 质量门禁
pnpm test:run:135 个测试文件、2606 条测试全部通过。pnpm test:coverage:通过,整体覆盖率 90.79%(Statements)。pnpm lint:通过。pnpm typecheck:通过。
批准合并。
…Windows CI The tests asserted command: 'npx' without accounting for Windows platform adaptation (npx -> cmd /c npx). Mock platform as non-Windows so assertions are cross-platform stable.
- Replace ANTHROPIC_* env keys with CODEBUDDY_* in codebuddy-config-manager. - Add dedicated CodeBuddyProfile type to avoid Claude-specific model fields. - Split clearCodeBuddyEnv from clearModelEnv for uninstall/reset paths. - Update init, codebuddy prompts, i18n keys, and related tests.
WitMiao
left a comment
There was a problem hiding this comment.
QA 验收结论:通过 ✅
已重新核对 PR #382 的 CodeBuddy 配置修正与覆盖率补充:
src/utils/code-tools/codebuddy-config-manager.ts已全面改用CODEBUDDY_*环境变量键,不再使用ANTHROPIC_*。- 新增独立
CodeBuddyProfile类型(src/types/codebuddy-config.ts),与ClaudeCodeProfile完全解耦。 src/utils/config.model-keys.ts新增CODEBUDDY_ENV_KEYS/clearCodeBuddyEnv,卸载/重置路径正确清理 CodeBuddy 环境键。- rebase 干净(HEAD 包含 origin/main),提交中未发现 multica/agent 提示词注入。
- 本地
pnpm lint/pnpm typecheck/pnpm test:run(2634 通过) /pnpm test:coverage(91.27%)全部通过。 - CI 全绿:lint + test(macOS/Ubuntu/Windows);Codecov patch coverage 99.73%,仅剩
src/commands/menu.ts2 行未覆盖。
建议合并。
This PR completes the review feedback for #378 (CodeBuddy agent support).
What's included
showCodebuddyMenu()and routes thecodebuddymode to it insrc/commands/menu.tssrc/commands/init.ts:handleCodebuddyConfigs()src/utils/code-tools/codebuddy.tsrunCodebuddyFullInit()src/utils/code-tools/codebuddy-config.tsExitPromptErrorhandling inconfig-switch.tssrc/utils/uninstaller.tsdocs/en,docs/zh-CN,docs/ja-JP)installation,updater,uninstall, andmulti-confignamespacesVerification
pnpm typecheck✅pnpm lint✅pnpm test:run✅ — 133 test files / 2573 tests passedCloses #378