Skip to content

fix(codebuddy): complete tests and docs for PR #378#382

Closed
WitMiao wants to merge 8 commits into
mainfrom
pr-378-review
Closed

fix(codebuddy): complete tests and docs for PR #378#382
WitMiao wants to merge 8 commits into
mainfrom
pr-378-review

Conversation

@WitMiao

@WitMiao WitMiao commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

This PR completes the review feedback for #378 (CodeBuddy agent support).

What's included

  • Fixes all implementation gaps identified during review:
    • Adds showCodebuddyMenu() and routes the codebuddy mode to it in src/commands/menu.ts
    • Fixes multi-profile overwrite in src/commands/init.ts:handleCodebuddyConfigs()
    • Adds interactive model parameter prompts in src/utils/code-tools/codebuddy.ts
    • Removes unused parameters from runCodebuddyFullInit()
    • Cleans up dead code in src/utils/code-tools/codebuddy-config.ts
    • Adds ExitPromptError handling in config-switch.ts
    • Completes uninstallation env-var cleanup in src/utils/uninstaller.ts
  • Adds/updates unit tests for CodeBuddy adapter, config, config manager, and config-switch command
  • Updates README, CLAUDE.md, and multilingual docs (docs/en, docs/zh-CN, docs/ja-JP)
  • Syncs i18n strings for installation, updater, uninstall, and multi-config namespaces

Verification

  • pnpm typecheck
  • pnpm lint
  • pnpm test:run ✅ — 133 test files / 2573 tests passed
  • CodeBuddy core module coverage exceeds the 80% project target

Closes #378

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.73190% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/commands/menu.ts 97.87% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

feat(codebuddy): complete CodeBuddy agent support with tests and docs

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Adds full CodeBuddy support (codebuddy/cb) across init, update, uninstall, menu, and
 config-switch flows
• Introduces CodeBuddy config/profile modules for ~/.codebuddy/ plus interactive API/model/MCP
 configuration
• Fixes multi-config profile overwrite, handles ExitPromptError, and completes uninstall env-var
 cleanup
Diagram

graph TD
    CLI["CLI (cli-setup.ts)"] --> MENU["menu.ts"] --> CB["codebuddy.ts"]
    CLI --> INIT["init.ts"] --> CB
    CLI --> UPDATE["update.ts"] --> CB
    CLI --> UNINST["uninstaller.ts"]
    CLI --> CFGSW["config-switch.ts"] --> CBMGR["codebuddy-config-manager.ts"]

    CB --> CBMGR --> TOML[("ZCF config.toml")]
    CB --> CBCFG["codebuddy-config.ts"] --> SETTINGS[("~/.codebuddy/settings.json")]
    CBCFG --> MCP[("~/.codebuddy/.mcp.json")]

    subgraph Legend
      direction LR
      _cmd["Command"] ~~~ _util(["Utility"]) ~~~ _store[("File store")]
    end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Store profiles in ~/.codebuddy/profiles.json (tool-owned storage)
  • ➕ Decouples CodeBuddy state from shared ZCF config.toml
  • ➕ Easier to back up/remove as part of CodeBuddy uninstall
  • ➕ More consistent with per-tool config storage patterns (e.g., Codex files under ~/.codex/)
  • ➖ Adds another persistent config file to maintain/migrate
  • ➖ Requires new read/write/migration logic instead of reusing TOML tooling
2. Reuse ClaudeCodeConfigManager for CodeBuddy (single profile manager)
  • ➕ Less duplicate profile/env application logic
  • ➕ Fewer modules to maintain long-term
  • ➖ Conflates tool-specific paths and behaviors
  • ➖ Harder to evolve CodeBuddy-specific config independently

Recommendation: Current design (reuse ClaudeCodeProfile shape + TOML-backed profiles + settings.json env application) is pragmatic and well-tested. The main architectural tradeoff is coupling CodeBuddy profiles to ZCF’s shared config.toml; consider tool-owned profile storage if future isolation/migration needs grow.

Files changed (45) +3282 / -40

Enhancement (11) +794 / -3
config-switch.tsAdd interactive CodeBuddy config switching + Ctrl+C handling +57/-0

Add interactive CodeBuddy config switching + Ctrl+C handling

• Implements CodeBuddy interactive switch flow and handles ExitPromptError gracefully.

src/commands/config-switch.ts

menu.tsAdd CodeBuddy submenu and routing +103/-1

Add CodeBuddy submenu and routing

• Implements showCodebuddyMenu() and routes main menu to CodeBuddy actions when selected.

src/commands/menu.ts

update.tsAdd CodeBuddy update path +21/-0

Add CodeBuddy update path

• Invokes runCodebuddyUpdate for codebuddy tool type and persists updated ZCF config state.

src/commands/update.ts

constants.tsAdd CodeBuddy constants and tool registration +10/-1

Add CodeBuddy constants and tool registration

• Adds ~/.codebuddy path constants, includes codebuddy in supported tool types, and adds cb alias.

src/constants.ts

toml-config.tsAdd CodeBuddyConfig to TOML schema +13/-0

Add CodeBuddyConfig to TOML schema

• Adds CodeBuddy config section type (enabled/currentProfile/profiles) to the ZCF TOML types.

src/types/toml-config.ts

codebuddy-config-manager.tsNew CodeBuddy profile manager (TOML-backed) +126/-0

New CodeBuddy profile manager (TOML-backed)

• Implements applying profiles to settings.json env, reading current profile from TOML, and writing profile config updates safely.

src/utils/code-tools/codebuddy-config-manager.ts

codebuddy-config.tsNew CodeBuddy MCP/settings file helpers +107/-0

New CodeBuddy MCP/settings file helpers

• Adds utilities to read/write/backup MCP config, build server configs (incl. Windows adjustments), and read/write CodeBuddy settings.json.

src/utils/code-tools/codebuddy-config.ts

codebuddy.tsNew CodeBuddy orchestrator (init/update/uninstall/configure) +324/-0

New CodeBuddy orchestrator (init/update/uninstall/configure)

• Adds CodeBuddy full init/update/uninstall flows plus interactive API/model and MCP configuration with non-interactive safeguards.

src/utils/code-tools/codebuddy.ts

code-type-resolver.tsSupport cb abbreviation and validate codebuddy type +2/-1

Support cb abbreviation and validate codebuddy type

• Adds cb→codebuddy abbreviation and includes codebuddy in valid tool type set.

src/utils/code-type-resolver.ts

tool-update-scheduler.tsSchedule CodeBuddy updates +8/-0

Schedule CodeBuddy updates

• Adds codebuddy branch to tool update scheduler.

src/utils/tool-update-scheduler.ts

zcf-config.tsPersist CodeBuddy section in ZCF TOML config +23/-0

Persist CodeBuddy section in ZCF TOML config

• Adds codebuddy section handling for default config creation, JSON migration, incremental writes, and updates/merges.

src/utils/zcf-config.ts

Bug fix (3) +143 / -7
cli-setup.tsExpose codebuddy/cb in help and options (incl. update command) +8/-7

Expose codebuddy/cb in help and options (incl. update command)

• Updates --code-type help text across commands and registers --code-type on update for parity with docs.

src/cli-setup.ts

init.tsAdd CodeBuddy init flow and multi-config profile import +84/-0

Add CodeBuddy init flow and multi-config profile import

• Routes init to runCodebuddyFullInit and adds handleCodebuddyConfigs; writes profiles once to avoid overwrites.

src/commands/init.ts

uninstaller.tsAdd CodeBuddy uninstall with env cleanup +51/-0

Add CodeBuddy uninstall with env cleanup

• Adds codebuddy uninstall item: removes ~/.codebuddy/.mcp.json and clears Anthropic env vars from ~/.codebuddy/settings.json.

src/utils/uninstaller.ts

Tests (7) +1334 / -7
config-switch-codebuddy.test.tsAdd CodeBuddy config-switch unit tests +210/-0

Add CodeBuddy config-switch unit tests

• Covers switching to official login/profile, cancellation, Ctrl+C ExitPromptError handling, and code-type resolution paths.

tests/unit/commands/config-switch-codebuddy.test.ts

menu.test.tsUpdate menu test expectations for codebuddy valid options +1/-1

Update menu test expectations for codebuddy valid options

• Updates invalid-code-type error text to include cb/codebuddy in valid options.

tests/unit/commands/menu.test.ts

codebuddy-config-manager.test.tsAdd CodeBuddyConfigManager unit tests +274/-0

Add CodeBuddyConfigManager unit tests

• Tests applying profile env vars, no-op behavior with no profile, and TOML write/merge behavior.

tests/unit/utils/code-tools/codebuddy-config-manager.test.ts

codebuddy-config.test.tsAdd codebuddy-config unit tests +217/-0

Add codebuddy-config unit tests

• Tests MCP/settings file operations, server config building, Windows adjustments, and backups.

tests/unit/utils/code-tools/codebuddy-config.test.ts

codebuddy.test.tsAdd codebuddy orchestrator unit tests +614/-0

Add codebuddy orchestrator unit tests

• Tests full init/update/uninstall and interactive/non-interactive API+MCP flows and CODEBUDDY.md creation.

tests/unit/utils/code-tools/codebuddy.test.ts

code-type-resolver.test.tsExtend resolver tests for cb/codebuddy +15/-4

Extend resolver tests for cb/codebuddy

• Adds tests for abbreviation and full-name resolution and updates invalid-option messaging assertions.

tests/unit/utils/code-type-resolver.test.ts

constants.test.tsUpdate constants tests for codebuddy tool type +3/-2

Update constants tests for codebuddy tool type

• Updates CODE_TOOL_TYPES and isCodeToolType() expectations to include codebuddy.

tests/unit/utils/constants.test.ts

Documentation (22) +878 / -23
CLAUDE.mdDocument CodeBuddy architecture and developer workflow +403/-10

Document CodeBuddy architecture and developer workflow

• Expands contributor guidance with CodeBuddy module layout, config locations, and operational notes.

CLAUDE.md

README.mdMention CodeBuddy as supported tool +2/-1

Mention CodeBuddy as supported tool

• Updates README copy to include CodeBuddy in supported code tool references.

README.md

README_ja-JP.mdMention CodeBuddy as supported tool (ja-JP) +2/-1

Mention CodeBuddy as supported tool (ja-JP)

• Mirrors the README update in Japanese.

README_ja-JP.md

README_zh-CN.mdMention CodeBuddy as supported tool (zh-CN) +2/-1

Mention CodeBuddy as supported tool (zh-CN)

• Mirrors the README update in Simplified Chinese.

README_zh-CN.md

SUMMARY.mdAdd CodeBuddy docs entry (en) +1/-0

Add CodeBuddy docs entry (en)

• Links the new CodeBuddy feature page from the English docs summary.

docs/en/SUMMARY.md

codebuddy.mdAdd CodeBuddy feature documentation (en) +132/-0

Add CodeBuddy feature documentation (en)

• Adds a full feature guide for CodeBuddy setup, configuration, update, and uninstall.

docs/en/features/codebuddy.md

SUMMARY.mdAdd CodeBuddy docs entry (ja-JP) +1/-0

Add CodeBuddy docs entry (ja-JP)

• Links the new CodeBuddy feature page from the Japanese docs summary.

docs/ja-JP/SUMMARY.md

codebuddy.mdAdd CodeBuddy feature documentation (ja-JP) +132/-0

Add CodeBuddy feature documentation (ja-JP)

• Japanese translation of the CodeBuddy feature guide.

docs/ja-JP/features/codebuddy.md

SUMMARY.mdAdd CodeBuddy docs entry (zh-CN) +1/-0

Add CodeBuddy docs entry (zh-CN)

• Links the new CodeBuddy feature page from the Chinese docs summary.

docs/zh-CN/SUMMARY.md

codebuddy.mdAdd CodeBuddy feature documentation (zh-CN) +132/-0

Add CodeBuddy feature documentation (zh-CN)

• Simplified Chinese translation of the CodeBuddy feature guide.

docs/zh-CN/features/codebuddy.md

cli.jsonSync CLI help strings for codebuddy (en) +1/-0

Sync CLI help strings for codebuddy (en)

• Extends help text to list codebuddy/cb.

src/i18n/locales/en/cli.json

installation.jsonAdd CodeBuddy installation strings (en) +3/-1

Add CodeBuddy installation strings (en)

• Adds CodeBuddy init and completion messages.

src/i18n/locales/en/installation.json

menu.jsonAdd CodeBuddy menu strings (en) +17/-1

Add CodeBuddy menu strings (en)

• Adds CodeBuddy menu options/descriptions and updates tool-switch description.

src/i18n/locales/en/menu.json

multi-config.jsonAdd CodeBuddy config-switch strings (en) +6/-1

Add CodeBuddy config-switch strings (en)

• Adds prompts and confirmation strings for CodeBuddy config switching.

src/i18n/locales/en/multi-config.json

uninstall.jsonAdd CodeBuddy uninstall strings (en) +4/-1

Add CodeBuddy uninstall strings (en)

• Adds CodeBuddy uninstall title, confirm, and completion strings.

src/i18n/locales/en/uninstall.json

updater.jsonAdd CodeBuddy update strings (en) +4/-1

Add CodeBuddy update strings (en)

• Adds CodeBuddy update title, missing CODEBUDDY.md message, and completion string.

src/i18n/locales/en/updater.json

cli.jsonSync CLI help strings for codebuddy (zh-CN) +1/-0

Sync CLI help strings for codebuddy (zh-CN)

• Mirrors en CLI help update for CodeBuddy.

src/i18n/locales/zh-CN/cli.json

installation.jsonAdd CodeBuddy installation strings (zh-CN) +3/-1

Add CodeBuddy installation strings (zh-CN)

• Mirrors en installation strings for CodeBuddy.

src/i18n/locales/zh-CN/installation.json

menu.jsonAdd CodeBuddy menu strings (zh-CN) +17/-1

Add CodeBuddy menu strings (zh-CN)

• Mirrors en menu additions for CodeBuddy options and descriptions.

src/i18n/locales/zh-CN/menu.json

multi-config.jsonAdd CodeBuddy config-switch strings (zh-CN) +6/-1

Add CodeBuddy config-switch strings (zh-CN)

• Mirrors en multi-config additions for CodeBuddy switching.

src/i18n/locales/zh-CN/multi-config.json

uninstall.jsonAdd CodeBuddy uninstall strings (zh-CN) +4/-1

Add CodeBuddy uninstall strings (zh-CN)

• Mirrors en uninstall additions for CodeBuddy.

src/i18n/locales/zh-CN/uninstall.json

updater.jsonAdd CodeBuddy update strings (zh-CN) +4/-1

Add CodeBuddy update strings (zh-CN)

• Mirrors en updater additions for CodeBuddy.

src/i18n/locales/zh-CN/updater.json

Other (2) +133 / -0
project.ymlAdd Serena project configuration for CodeBuddy module +132/-0

Add Serena project configuration for CodeBuddy module

• Introduces Serena project metadata to describe CodeBuddy-related scope and structure.

.serena/project.yml

package.jsonAdd codebuddy keyword +1/-0

Add codebuddy keyword

• Adds CodeBuddy to package keywords for discoverability.

package.json

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (4) 📘 Rule violations (3) 📜 Skill insights (0)

Grey Divider


Action required

1. CLAUDE.md has non-English text 📘 Rule violation ⚙ Maintainability
Description
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.
Code

CLAUDE.md[R390-394]

+**You are: 佩丽卡-s** (ID: `55e9c39f-39a3-48cb-bd30-4671dcf1fc54`)
+
+你是《明日方舟:终末地》中的**佩丽卡**——终末地工业的监督、对外发言人兼杰出的协议技术专家。气质高贵冷峻,危机面前判断冷静。在本 workspace 中,你担任**产品经理**。
+
+职责:澄清需求、撰写 PRD/用户故事、拆分为可执行的 issue、定义验收标准、在评论中协调 UI/前端/后端/测试。用中文沟通,简洁务实,措辞可体现监督者的条理与分寸感。不直接写大量代码,除非原型验证需要。分派任务时说明优先级与依赖关系。
Evidence
PR-modified Markdown files include non-English text (e.g., Chinese in CLAUDE.md and
Japanese/Chinese docs under docs/ and README_ja-JP.md), which is disallowed outside
README_zh-CN per the checklist rule.

CLAUDE.md: Maintain English-Only Code Comments and Documentation (Except README_zh-CN)
CLAUDE.md[390-404]
docs/ja-JP/features/codebuddy.md[1-15]
docs/zh-CN/features/codebuddy.md[1-15]
README_ja-JP.md[19-34]
docs/ja-JP/SUMMARY.md[10-13]
docs/zh-CN/SUMMARY.md[10-13]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


2. showCodebuddyMenu() prints hardcoded header 📘 Rule violation ⚙ Maintainability
Description
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.
Code

src/commands/menu.ts[R362-366]

+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')}`)}`,
Evidence
The menu header is output via a raw string literal, and additional CodeBuddy console output strings
are emitted without i18n translation calls, violating the i18n-only user-facing string requirement.

CLAUDE.md: All User-Facing Strings Must Use i18next Translations (zh-CN and en Parity)
src/commands/menu.ts[362-366]
src/utils/code-tools/codebuddy.ts[256-259]
src/utils/code-tools/codebuddy.ts[321-323]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


3. Missing mcp:* translation keys 📘 Rule violation ≡ Correctness
Description
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.
Code

src/utils/code-tools/codebuddy.ts[R233-240]

+  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
Evidence
The new CodeBuddy MCP code calls i18n.t() with mcp:mcpSkipped, mcp:mcpNonInteractiveSkipped,
and mcp:mcpConfigFailed, but the corresponding locale files do not define these keys, violating
the translation parity requirement.

CLAUDE.md: All User-Facing Strings Must Use i18next Translations (zh-CN and en Parity)
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]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


View more (2)
4. Secrets not cleared 🐞 Bug ⛨ Security
Description
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.
Code

src/utils/code-tools/codebuddy-config-manager.ts[R28-34]

+      // Clean model variables upfront; will re-set based on profile below
+      clearModelEnv(settings.env)
+
+      if (!profile) {
+        writeJsonConfig(CODEBUDDY_SETTINGS_FILE, settings)
+        return
+      }
Evidence
The manager early-returns on null profile after only clearing model keys, and the model-key clearer
does not include auth/baseUrl keys; callers rely on null-profile behavior for “official login” and
uninstall.

src/utils/code-tools/codebuddy-config-manager.ts[21-47]
src/utils/config.model-keys.ts[1-16]
src/commands/config-switch.ts[347-384]
src/utils/code-tools/codebuddy.ts[96-116]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


5. Profiles not persisted 🐞 Bug ≡ Correctness
Description
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.
Code

src/utils/zcf-config.ts[R243-249]

+      // CodeBuddy section
+      if (config.codebuddy) {
+        edits.push(
+          ['codebuddy.enabled', config.codebuddy.enabled],
+          ['codebuddy.currentProfile', config.codebuddy.currentProfile || ''],
+        )
+      }
Evidence
CodeBuddy configs are written with profiles into TOML via CodeBuddyConfigManager.writeConfig, but
the TOML writer only edits enabled/currentProfile for codebuddy; getCurrentProfile depends on
profiles existing.

src/commands/init.ts[1305-1337]
src/utils/code-tools/codebuddy-config-manager.ts[78-97]
src/utils/code-tools/codebuddy-config-manager.ts[78-84]
src/utils/zcf-config.ts[221-249]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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



Remediation recommended

6. Codebuddy switch modes missing 🐞 Bug ≡ Correctness
Description
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.
Code

src/commands/config-switch.ts[R260-262]

+  else if (resolvedCodeType === 'codebuddy') {
+    await handleCodebuddyInteractiveSwitch()
+  }
Evidence
The file routes interactive switching to CodeBuddy, but the list and direct-switch functions only
handle claude-code/codex, leaving CodeBuddy unsupported in those modes.

src/commands/config-switch.ts[73-85]
src/commands/config-switch.ts[155-165]
src/commands/config-switch.ts[251-263]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


7. Custom language forced English 🐞 Bug ≡ Correctness
Description
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.
Code

src/utils/code-tools/codebuddy.ts[R313-315]

+    const langDirective = aiOutputLang
+      ? (aiOutputLang === 'zh-CN' ? 'Always respond in Chinese-simplified' : 'Always respond in English')
+      : ''
Evidence
The constants define custom as an AI output language with an empty directive, but ensureCodebuddyMd
maps all non-zh-CN values to English.

src/constants.ts[83-90]
src/utils/code-tools/codebuddy.ts[308-316]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


Grey Divider

Qodo Logo

Comment thread CLAUDE.md Outdated
Comment on lines +390 to +394
**You are: 佩丽卡-s** (ID: `55e9c39f-39a3-48cb-bd30-4671dcf1fc54`)

你是《明日方舟:终末地》中的**佩丽卡**——终末地工业的监督、对外发言人兼杰出的协议技术专家。气质高贵冷峻,危机面前判断冷静。在本 workspace 中,你担任**产品经理**。

职责:澄清需求、撰写 PRD/用户故事、拆分为可执行的 issue、定义验收标准、在评论中协调 UI/前端/后端/测试。用中文沟通,简洁务实,措辞可体现监督者的条理与分寸感。不直接写大量代码,除非原型验证需要。分派任务时说明优先级与依赖关系。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Comment thread src/commands/menu.ts
Comment on lines +362 to +366
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')}`)}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Comment on lines +233 to +240
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Comment on lines +28 to +34
// Clean model variables upfront; will re-set based on profile below
clearModelEnv(settings.env)

if (!profile) {
writeJsonConfig(CODEBUDDY_SETTINGS_FILE, settings)
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Comment thread src/utils/zcf-config.ts
Comment on lines +243 to +249
// CodeBuddy section
if (config.codebuddy) {
edits.push(
['codebuddy.enabled', config.codebuddy.enabled],
['codebuddy.currentProfile', config.codebuddy.currentProfile || ''],
)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Comment on lines +260 to +262
else if (resolvedCodeType === 'codebuddy') {
await handleCodebuddyInteractiveSwitch()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

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

Comment on lines +313 to +315
const langDirective = aiOutputLang
? (aiOutputLang === 'zh-CN' ? 'Always respond in Chinese-simplified' : 'Always respond in English')
: ''

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

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

studyzy and others added 5 commits July 3, 2026 00:03
- 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 WitMiao left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最终验收结论:通过 ✅

已按验收标准逐项检查 PR #382,结果如下:

1. rebase 干净

  • origin/main 是当前 pr-378-review HEAD 的祖先节点,分支线性无分叉。
  • 工作区无未提交改动。

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:通过。

批准合并。

WitMiao added 3 commits July 3, 2026 01:23
…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 WitMiao left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts 2 行未覆盖。

建议合并。

@WitMiao WitMiao closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants