Skip to content

Add CodeBuddy AI coding agent support with checkpoint preset and hook installation#1600

Open
pengyq wants to merge 2 commits into
git-ai-project:mainfrom
pengyq:main
Open

Add CodeBuddy AI coding agent support with checkpoint preset and hook installation#1600
pengyq wants to merge 2 commits into
git-ai-project:mainfrom
pengyq:main

Conversation

@pengyq

@pengyq pengyq commented Jun 23, 2026

Copy link
Copy Markdown

Summary

This PR adds first-class support for CodeBuddy as a new AI coding agent, enabling git-ai to track AI-authored code changes made through the CodeBuddy IDE.

Changes

1. Checkpoint Preset (src/commands/checkpoint_agent/presets/codebuddy.rs)

A new CodeBuddyPreset that parses CodeBuddy hook input (JSON) and produces checkpoint events:

  • Pre-file-edit and Post-file-edit for Write/Edit tools — extracts file_path from tool input and associates edits with the correct session and tool use
  • Pre-bash-call and Post-bash-call for Bash tools — captures shell command attribution
  • Supports PreToolUse / PostToolUse hook event names and the camelCase field aliases (toolName, hookEventName, toolUseId) that CodeBuddy emits
  • Falls back to deriving the session ID from the transcript filename when session_id is absent
  • Model extraction from CodeBuddy's Claude-format JSONL transcript files
  • Includes comprehensive unit tests covering all four event types, session ID fallback, and camelCase field handling

2. Bash Tool Classification (src/commands/checkpoint_agent/bash_tool.rs)

Extended classify_tool() to recognize the CodeBuddy agent, mapping BashToolClass::Bash and everything else → ToolClass::Other.

3. Hook Installer (src/mdm/agents/codebuddy.rs)

A full HookInstaller implementation for CodeBuddy that manages hooks in ~/.codebuddy/settings.json:

  • Install: Injects git-ai checkpoint codebuddy --hook-input stdin as PreToolUse and PostToolUse hooks into the "*" catch-all matcher block
  • Uninstall: Removes git-ai checkpoint commands while preserving user hooks
  • Migration: Automatically moves existing git-ai hooks from old non-catch-all matcher blocks (e.g. "Write|Edit") to the "*" catch-all block, removing empty legacy blocks
  • Idempotent: No-op when hooks are already correctly configured
  • User hook preservation: Existing user-defined hooks in the catch-all block are never removed or reordered
  • Existing settings preservation: Non-hook keys (e.g. model, permissions) in settings.json are left untouched
  • Check: Reports whether CodeBuddy is installed and whether hooks are present/up-to-date
  • Extensive tests covering: fresh install, idempotent re-install, migration from old matchers (with and without user hooks), preserving existing catch-all hooks and non-hook settings, uninstall (with and without git-ai present), and Windows path normalization

4. Dependency Update (Cargo.toml)

Minor version bump for a transitive dependency (Cargo.lock updated).

Files Changed

File Changes
src/commands/checkpoint_agent/presets/codebuddy.rs +213 (new)
src/mdm/agents/codebuddy.rs +722 (new)
src/commands/checkpoint_agent/bash_tool.rs +7
src/commands/checkpoint_agent/presets/mod.rs +2
src/commands/checkpoint_agent/presets/parse.rs +1
src/mdm/agents/mod.rs +3
Cargo.toml +1/-1
Total +949 / -1

Testing

  • All existing tests continue to pass
  • New unit tests cover the checkpoint preset (5 scenarios) and hook installer (10 scenarios including install, migration, uninstall, idempotency, user hook preservation, and path normalization)

Open in Devin Review

@CLAassistant

CLAassistant commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ pengyq
❌ testx-demo
You have signed the CLA already but the status is still pending? Let us recheck it.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

Open in Devin Review

Comment on lines +365 to +370
Agent::CodeBuddy => match tool_name {
"Write" | "write_to_file" | "Edit" | "replace_in_file" | "MultiEdit"
| "multi_edit" | "NotebookEdit" | "notebook_edit" => ToolClass::FileEdit,
"Bash" => ToolClass::Bash,
_ => ToolClass::Skip,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 Asymmetric casing for Bash tool classification vs file-edit tools

The CodeBuddy classify_tool arm at src/commands/checkpoint_agent/bash_tool.rs:365-370 includes both PascalCase and snake_case variants for file-edit tools ("Write" | "write_to_file" | "Edit" | "replace_in_file" | "MultiEdit" | "multi_edit" | "NotebookEdit" | "notebook_edit"), but only PascalCase "Bash" for the bash tool — no "bash" lowercase variant. If CodeBuddy can send tool names in snake_case (as suggested by write_to_file, replace_in_file, multi_edit, notebook_edit), then a lowercase "bash" would be classified as ToolClass::Skip instead of ToolClass::Bash, causing bash-based file changes to be missed by the stat-diff system. This depends on what tool names CodeBuddy actually emits, which I cannot verify from the codebase alone.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Open in Devin Review

Comment on lines +62 to +68
let stream_source = Some(StreamSource {
path: transcript_path_buf,
format: StreamFormat::ClaudeJsonl,
session_id: generate_session_id(&session_id, "codebuddy"),
external_session_id: session_id.clone(),
external_parent_session_id: None,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 CodeBuddy not registered in ALL_AGENT_TYPES — no sweep/discovery support

CodeBuddy is not added to ALL_AGENT_TYPES in src/streams/agent.rs:179-192 or the get_agent function (src/streams/agent.rs:197-214), and there is no corresponding stream agent implementation in src/streams/agents/. This means the sweep coordinator will not independently discover CodeBuddy sessions for background transcript ingestion. Transcript streaming will only work when triggered inline via the stream_source field in checkpoint hook events. This is consistent with firebender (which also lacks sweep support), but differs from most other agents (Claude, Cursor, Codex, etc.) that have full sweep implementations. If background sweep is desired for CodeBuddy, a stream agent would need to be added.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

3 participants