feat: add CodeBuddy CN preset and hook installer (rebased on new framework)#1252
Open
Krishnachaitanyakc wants to merge 1 commit into
Open
feat: add CodeBuddy CN preset and hook installer (rebased on new framework)#1252Krishnachaitanyakc wants to merge 1 commit into
Krishnachaitanyakc wants to merge 1 commit into
Conversation
79d3ecf to
5931036
Compare
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
5931036 to
1131547
Compare
Member
|
Thank you for the PR @Krishnachaitanyakc! Btw you can ignore that Windows test failure -- unrelated and fixed on main. |
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 implementingAgentPreset. Extracts events from CodeBuddy CN's Claude-shaped hook payloads (PreToolUse/PostToolUse,tool_name,tool_input).mdm/agents/codebuddy.rs—CodeBuddyInstallerforsettings.jsonhooks. Cross-platform (macOS / Linux / Windows). MirrorsClaudeCodeInstaller's migration, idempotency, and dedup logic.is_codebuddy_hook_payloadrejects payloads withclient: "CodeBuddyIDE"or transcript paths underCodeBuddyExtension, preventing misrouting."codebuddy"added sogit-ai blameattributes CodeBuddy commits as AI.Key differences from Claude Code
tool_inputfilepath fieldfile_path(snake_case)filePath(camelCase)cwd"/"(known CodeBuddy bug)index.json+messages/{id}.jsondirectory"*"".*"(CodeBuddy requires regex)client: "CodeBuddyIDE",model: "glm-5.0-turbo"The
cwd: "/"workaround leverages the new orchestrator's design: repo discovery forPreFileEdit/PostFileEditevents usesfile_paths[0](worktree_root_for_path), notcwd. So as long astool_input.filePathis 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}.jsonwith double-encoded JSON in themessagefield) needs a dedicated reader. For v1 this PR setstranscript_sourceto point atindex.jsonwithClaudeJsonlformat as a placeholder — the existing reader simply finds no events. Hook-based AI attribution works without it. Fixtures intests/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}.jsonModified:
src/commands/checkpoint_agent/presets/claude.rs— addedis_codebuddy_hook_payloadguard + 2 testssrc/commands/checkpoint_agent/presets/mod.rs— registered presetsrc/mdm/agents/mod.rs— registered installertests/integration/main.rs— registered test moduletests/integration/repos/test_file.rs— added"codebuddy"toAI_AUTHOR_NAMEStests/integration/repos/test_repo.rs— added"codebuddy"tois_known_checkpoint_presetso the test harness routes args correctlyTest plan
cargo fmt --checkpassescargo clippy --all-targets -- -D warningspassesRUSTDOCFLAGS="-D warnings" cargo doc --no-depspassescargo test --lib)cargo test --test integration -- codebuddy— all 6 passcargo 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)println!/dbg!in production codegit-ai checkpoint codebuddy --hook-input stdinagainst a temp git repo; verified the codebuddy preset accepts and the claude preset rejects (with guidance message).Closes #1035