Skip to content

Comments

feat(dev): add AI-generated branch naming for worktrees#416

Merged
basnijholt merged 9 commits intomainfrom
feat/dev-ai-branch-naming
Feb 9, 2026
Merged

feat(dev): add AI-generated branch naming for worktrees#416
basnijholt merged 9 commits intomainfrom
feat/dev-ai-branch-naming

Conversation

@basnijholt
Copy link
Owner

@basnijholt basnijholt commented Feb 9, 2026

Summary

Add AI-generated branch naming for agent-cli dev new when no branch is provided.

What changed

  • Added auto-naming modes for dev new:
    • --branch-name-mode random|auto|ai
    • --branch-name-agent claude|codex|gemini
    • --branch-name-timeout <seconds>
  • AI branch-name generation/parsing pipeline for Claude/Codex/Gemini with normalization and git-validity checks
  • Collision avoidance against both active worktrees and existing git refs (refs/heads/*, refs/remotes/origin/*)
  • Safe fallback: if AI naming fails, random naming is used with a warning
  • When --branch-name-agent is omitted, --with-agent is used for naming if it supports headless mode (claude/codex/gemini)
  • Rich spinner during AI branch name generation for better UX

Code quality improvements

  • Extracted all branch naming logic into agent_cli/dev/_branch_name.py (~370 lines) to keep cli.py focused on CLI commands
  • Deduplicated _branch_exists_in_repo by reusing worktree.check_branch_exists (renamed from private _check_branch_exists)
  • Simplified AI branch naming internals: removed unnecessary wrapper functions, flattened return types from tuples to plain values
  • Config loader (config.py): _replace_dashed_keys made recursive, _flatten_nested_sections preserves scalar options alongside nested subsections

Additional fixes

  • Restored dev clean --force forwarding into merged/no-commits cleanup paths
  • Updated docs: clarified AI naming quick-start example, documented new options and dev clean --force

Test plan

  • pre-commit run --all-files passes (ruff, mypy, jscpd, pylint)
  • pytest tests/ — 970 passed
  • Unit tests for all extractors (Claude, Codex, Gemini output parsing)
  • Unit tests for normalization, prompt construction, uniqueness/dedup
  • Integration tests for dev new with AI naming, fallback, auto mode, config defaults
  • Live smoke test with claude, codex, gemini CLIs

basnijholt and others added 9 commits February 9, 2026 07:30
- Narrow except Exception to except OSError in _is_valid_git_branch_name
- Remove unnecessary .lower().strip() on Literal-typed branch_name_mode
- Remove _run_headless_branch_namer wrapper; use data-driven dispatch
  to deduplicate the per-agent if/elif branches
…heck

Add a Rich status spinner during AI branch name generation so users see
progress instead of a silent wait. Reuse worktree.check_branch_exists
instead of duplicating the git show-ref logic in cli.py. Simplify the
warning message for AI naming fallback.
Remove error-detail machinery (_summarize_agent_error,
_parse_branch_name_agent_result, _extract_json_object) and inline small
helpers (_resolve_branch_name_agents, _is_valid_git_branch_name).
Simplify return types from tuples to plain values. Drop corresponding
tests for removed internals.
The simplification removed the availability loop from the random
fallback path, which could return a duplicate branch name. Restore
the check and add a test covering the collision path.
Move all branch naming logic (word lists, AI agent invocation, output
parsing, normalization, uniqueness checks) from cli.py into a dedicated
_branch_name.py module to reduce cli.py's size and improve cohesion.
@basnijholt basnijholt merged commit c719262 into main Feb 9, 2026
11 of 12 checks passed
@basnijholt basnijholt deleted the feat/dev-ai-branch-naming branch February 9, 2026 20:34
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.

1 participant