Skip to content

feat: add CodeBuddy CN preset and hook installer (rebased on new framework)#1252

Open
Krishnachaitanyakc wants to merge 1 commit into
git-ai-project:mainfrom
Krishnachaitanyakc:feat/codebuddy-preset-v2
Open

feat: add CodeBuddy CN preset and hook installer (rebased on new framework)#1252
Krishnachaitanyakc wants to merge 1 commit into
git-ai-project:mainfrom
Krishnachaitanyakc:feat/codebuddy-preset-v2

Conversation

@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor

@Krishnachaitanyakc Krishnachaitanyakc commented May 5, 2026

Summary

Adds support for CodeBuddy CN (Tencent's Claude Code-compatible IDE plugin) as requested in #1035, rebased on the new agent presets architecture.

This is a fresh PR replacing #1112 (closed pre-rewrite).

What's added

  • presets/codebuddy.rs — pure parser implementing AgentPreset. Extracts events from CodeBuddy CN's Claude-shaped hook payloads (PreToolUse/PostToolUse, tool_name, tool_input).
  • mdm/agents/codebuddy.rsCodeBuddyInstaller for settings.json hooks. Cross-platform (macOS / Linux / Windows). Mirrors ClaudeCodeInstaller's migration, idempotency, and dedup logic.
  • Claude preset guardis_codebuddy_hook_payload rejects payloads with client: "CodeBuddyIDE" or transcript paths under CodeBuddyExtension, preventing misrouting.
  • AI_AUTHOR_NAMES"codebuddy" added so git-ai blame attributes CodeBuddy commits as AI.

Key differences from Claude Code

Claude Code CodeBuddy CN
tool_input filepath field file_path (snake_case) filePath (camelCase)
cwd Real project dir Always "/" (known CodeBuddy bug)
Transcript layout Single JSONL file index.json + messages/{id}.json directory
Catch-all matcher "*" ".*" (CodeBuddy requires regex)
Identifier (none in payload) client: "CodeBuddyIDE", model: "glm-5.0-turbo"

The cwd: "/" workaround leverages the new orchestrator's design: repo discovery for PreFileEdit/PostFileEdit events uses file_paths[0] (worktree_root_for_path), not cwd. So as long as tool_input.filePath is the absolute path to a file in a git repo, attribution works.

Deferred (not in this PR)

The CodeBuddy CN transcript format (index.json + messages/{id}.json with double-encoded JSON in the message field) needs a dedicated reader. For v1 this PR sets transcript_source to point at index.json with ClaudeJsonl format as a placeholder — the existing reader simply finds no events. Hook-based AI attribution works without it. Fixtures in tests/fixtures/codebuddy-session/ document the layout. A follow-up commit can add the dedicated reader if desired.

Files changed

New:

  • src/commands/checkpoint_agent/presets/codebuddy.rs (~280 lines including 12 unit tests)
  • src/mdm/agents/codebuddy.rs (~640 lines including 16 unit tests covering install/uninstall/check scenarios)
  • tests/integration/codebuddy.rs (~210 lines, 6 tests: 3 in-process routing + 3 E2E with TestRepo)
  • tests/fixtures/codebuddy-session/index.json + messages/msg00{1,2,3}.json

Modified:

  • src/commands/checkpoint_agent/presets/claude.rs — added is_codebuddy_hook_payload guard + 2 tests
  • src/commands/checkpoint_agent/presets/mod.rs — registered preset
  • src/mdm/agents/mod.rs — registered installer
  • tests/integration/main.rs — registered test module
  • tests/integration/repos/test_file.rs — added "codebuddy" to AI_AUTHOR_NAMES
  • tests/integration/repos/test_repo.rs — added "codebuddy" to is_known_checkpoint_preset so the test harness routes args correctly

Test plan

  • cargo fmt --check passes
  • cargo clippy --all-targets -- -D warnings passes
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps passes
  • All 1460 lib unit tests pass (cargo test --lib)
  • cargo test --test integration -- codebuddy — all 6 pass
  • cargo test --test integration -- claude_code::test — all 18 pass (verifies the new Claude guard didn't regress)
  • cargo test --test integration -- windsurf:: — all 16 pass (verifies the test harness change didn't regress)
  • No println!/dbg! in production code
  • Standalone E2E: piped a sample CodeBuddy CN PreToolUse and PostToolUse hook payload through git-ai checkpoint codebuddy --hook-input stdin against a temp git repo; verified the codebuddy preset accepts and the claude preset rejects (with guidance message).

Closes #1035


Open in Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

github-advanced-security[bot]

This comment was marked as resolved.

@Krishnachaitanyakc Krishnachaitanyakc force-pushed the feat/codebuddy-preset-v2 branch 2 times, most recently from 79d3ecf to 5931036 Compare May 5, 2026 05:38
Adds support for CodeBuddy CN (Tencent's Claude Code-compatible IDE
plugin) requested in git-ai-project#1035. Built on the new pure-parser preset
architecture from the agent presets rewrite.

- New `codebuddy` preset (`presets/codebuddy.rs`) — extracts events
  from CodeBuddy CN's Claude-shaped hook payloads. Uses camelCase
  `tool_input.filePath` (CodeBuddy convention) and falls back to the
  parent dir of `transcript_path` for `session_id` since transcripts
  are always named `index.json`. Reuses Claude's tool taxonomy via
  `bash_tool::Agent::Claude` since CodeBuddy mirrors Claude's tool
  names.
- New `CodeBuddyInstaller` (`mdm/agents/codebuddy.rs`) — installs
  PreToolUse/PostToolUse hooks into CodeBuddy CN's settings.json
  using a `.*` regex catch-all matcher (CodeBuddy CN does not
  support a bare `*`). Cross-platform settings dir for macOS,
  Linux, and Windows. Mirrors `ClaudeCodeInstaller`'s migration,
  idempotency, and dedup behavior.
- Claude preset guard `is_codebuddy_hook_payload` — rejects payloads
  with `client: "CodeBuddyIDE"` or transcript paths under
  `CodeBuddyExtension`, preventing misrouting.
- Adds `"codebuddy"` to `AI_AUTHOR_NAMES` so blame correctly
  attributes CodeBuddy commits as AI-authored, and to the test
  harness's `is_known_checkpoint_preset` so checkpoint args route
  correctly during integration tests.

Handles the CodeBuddy CN `cwd: "/"` bug by relying on the absolute
file path in `tool_input.filePath` for repo discovery — the
orchestrator's `worktree_root_for_path` resolves the repo from the
file path, not cwd.

Transcript reading for the directory-based `index.json + messages/`
layout is intentionally deferred — `transcript_source` points at
`index.json` but uses `ClaudeJsonl` format as a placeholder so the
existing reader simply finds no events. Hook attribution works
without it; a dedicated reader can be added in a follow-up.

Tests: 12 preset unit tests, 16 installer unit tests, 6 integration
tests (3 in-process routing + 3 E2E with TestRepo verifying AI
attribution end-to-end including the cwd:"/" workaround), plus 2
new Claude-guard tests. Fixtures in
`tests/fixtures/codebuddy-session/` document the transcript layout.

Closes git-ai-project#1035
@Krishnachaitanyakc Krishnachaitanyakc force-pushed the feat/codebuddy-preset-v2 branch from 5931036 to 1131547 Compare May 5, 2026 06:04
@svarlamov
Copy link
Copy Markdown
Member

Thank you for the PR @Krishnachaitanyakc! Btw you can ignore that Windows test failure -- unrelated and fixed on main.

@xenv
Copy link
Copy Markdown

xenv commented May 22, 2026

CodeBuddy also has another product line: CodeBuddy Code (CLI) at https://www.codebuddy.ai/cli. It shares the same configuration file as CodeBuddy IDE (meaning that install hooks will also affect CodeBuddy CLI), but its hook requests differ somewhat from those of the IDE, especially regarding things like conversation history. I think it’s necessary to consider compatibility for the CLI scenario.

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.

Feature Request: Add CodeBuddy CN preset and extensible adapter architecture for emerging AI coding tools

4 participants