Skip to content

refactor(atelier): expose default-branch detection as CLI subcommand, drop ported scripts#798

Merged
kys0213 merged 3 commits into
mainfrom
refactor/scripts-to-cli-default-branch
Jun 14, 2026
Merged

refactor(atelier): expose default-branch detection as CLI subcommand, drop ported scripts#798
kys0213 merged 3 commits into
mainfrom
refactor/scripts-to-cli-default-branch

Conversation

@kys0213

@kys0213 kys0213 commented Jun 14, 2026

Copy link
Copy Markdown
Owner

  • atelier scripts/에 git-utils → Rust CLI 포팅 후 안 지운 .sh 중복이 남아 있었어요 (commit.sh·create-pr.sh·create-branch.sh·detect-jira-ticket.sh — 전부 atelier git commit/branch/pr + core/jira.rs와 1:1 중복, 실행처 0).
  • detect-default-branch.sh만 setup이 실제로 쓰는데, 그 출력은 branch-guard hook 설정값으로 baking돼요. 모델이 추측하면 안 되는 결정적 값인데(틀리면 가드 오설정), 정작 그 로직(git.rs:detect_default_branch())은 이미 Rust CLI 안에 있고 standalone 노출만 안 돼 있었어요.

무엇을

  • 신규 atelier git default-branch: 기존 detect_default_branch()(set-head 포함 Method 1/2/3)를 얇게 노출. 출력은 평문 스칼라(다른 git 서브커맨드의 JSON과 달리) — setup의 $(...) 소비 + 토큰 최소. 실패 시 stderr Error: + exit 1.
  • setup.md: detect-default-branch.shatelier git default-branch (Step 0 ensure-binary가 바이너리 선보장).
  • 삭제: 중복 .sh 5개. ensure-binary.sh(CLI를 빌드하는 부트스트랩)만 유지.
  • 테스트: git_cli.rs에 평문 출력(main\n, JSON 아님 exact match) + 무remote 실패(exit 1) 블랙박스 테스트. 코어는 git_core_git.rs가 기존 커버.
  • 정리: agent-design-principles 예시 create-branch.shatelier git branch(doctrine "결정적 로직은 도구로 캡슐화" 취지 유지), guard 픽스처 dead-file 참조 정리, cli-reference §7 문서화.

어떻게

  • "누가 출력을 소비하나"가 기준: 결정적 hook 설정이 의존하므로 프롬프트가 아니라 코드(CLAUDE.md 책임 경계). 단, 새 로직은 쓰지 않고 이미 있는 Rust 함수를 서브커맨드로 relocate → 결정성 + DRY + loose-script 제거 동시 충족.
  • 디스패치 arm은 thin(output() JSON 헬퍼 우회, git.detect_default_branch() 직접 + 평문 println), guard arm의 --project-dir/create_git_service(Some(..)) 패턴 재사용.

확인 방법

  • cd plugins/atelier/cli && cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test → 전부 green (신규 git_default_branch_* 포함, 36 모듈 0 failed)
  • 수동: git repo에서 atelier git default-branch → 기본 브랜치 평문 1줄 + exit 0 / 무remote → exit 1
  • make validate-ci → 0 failed
  • dangling: grep -rn "create-branch.sh\|detect-default-branch.sh\|..." plugins/atelier → scripts/ 외 0

Follow-up (별도 PR)

  • CLI 전역 토큰 최적화 출력 (mod.rs:144 to_string_pretty chokepoint) — compact-JSON quick-win vs custom 포맷, 소비자 영향 분석 포함해 별도 interview.

🤖 Generated with Claude Code

김용성 and others added 3 commits June 14, 2026 13:01
… drop ported scripts

포팅 후 남은 git 워크플로 .sh 중복을 CLI로 통합.

- 신규: atelier git default-branch — 기존 core/git.rs detect_default_branch()(set-head 포함 Method 1/2/3)를 얇게 노출. 출력은 평문 스칼라(JSON 헬퍼 우회) — setup 의 $(...) 소비 + branch-guard 설정값 baking 에 맞춤. 실패 시 exit 1
- setup.md: detect-default-branch.sh 호출 → atelier git default-branch (Step 0 ensure-binary 가 바이너리 선보장)
- 삭제: scripts/{commit,create-pr,create-branch,detect-jira-ticket,detect-default-branch}.sh — atelier git commit/branch/pr + core/jira.rs 와 1:1 중복, 실행처 없음. ensure-binary.sh(부트스트랩)만 유지
- 테스트: git_cli.rs 에 평문 출력(main\n, JSON 아님) + 실패 exit 1 블랙박스 테스트. 코어는 git_core_git.rs 기존 커버
- 정리: agent-design-principles 예시 create-branch.sh→atelier git branch, guard 픽스처 dead-file 참조 정리, cli-reference 에 §7 문서화

Follow-up(별도 PR): CLI 전역 토큰 최적화 출력(mod.rs to_string_pretty chokepoint).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
…h test fixture

/simplify findings 적용:
- output_plain(Result<String,String>) 추출 — DefaultBranch arm 의 eprintln!+exit1 이 output() Err arm 중복 + 다른 arm 은 전부 output() one-liner 인데 이것만 14줄 inline 이었음. arm 을 one-liner 로 일관화 + mutating detect 선택 이유 주석화
- git_cli.rs repo_with_default_branch 단순화 — bare-remote+commit+push(~10 subprocess) 제거. 검증은 origin/HEAD→main resolve 만 필요(Method 1 symbolic-ref 읽기)라 'git init -b main' + symbolic-ref 2줄로 충분. 2nd TempDir 제거

Simplify findings (skipped): git_core_git.rs::setup() 공유 모듈 추출 — diff 밖 19개 call site 리팩터 필요 + 픽스처 단순화로 새 헬퍼가 3줄 달라져 중복 해소되어 out-of-scope.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
…st empty value

/code-review 가 잡은 high-severity setup↔guard 통합 버그 수정.

문제: remote 없는 repo 에서 setup 시 detect 실패 → DEFAULT_BRANCH='' → guard hook 에 bare '--default-branch '(값 없음) 가 박혀 → 런타임에 (a) clap exit 2 로 모든 Write/Edit/Bash 차단되거나 (b) 빈 브랜치로 guard 가 main 미보호. 주석은 '생략'이라 했지만 코드는 항상 플래그를 붙였음. 이 PR 의 2>/dev/null 이 detect 실패까지 삼켜 악화.

- setup.md: DB_FLAG 로 DEFAULT_BRANCH 비면 --default-branch 플래그 통째로 생략 (주석대로). detect 의 2>/dev/null 제거 — 실패를 operator 에게 노출
- core/guard.rs: default_branch 가 빈/공백 문자열이면 absence 로 취급 → readonly 감지 fallback (protected_branches 의 empty-filter 와 동일 방어). Some("") 가 main 을 silent 미보호하던 것 차단 (defense-in-depth: 손편집 settings.json 등)
- git_core_guard.rs: 재현 테스트 empty_default_branch_falls_back_to_detection (수정 전 RED: main 미보호 allowed=true / 수정 후 GREEN: blocked)

Review findings (deferred, 사유):
- Method 2 set-head ~75s 무한대기: pre-existing(.sh 동일), git 자체 동작이라 별도 타임아웃 작업 필요 → 범위 밖
- default-branch --project-dir None→cwd: setup 단일 호출자라 오늘 정상, non-setup 호출자 생기면 그때 pin
- dangling-symref 테스트: ubuntu-latest git 에서 안정 통과(CI finder 검증), simplify 의도 유지
- no-remote 테스트 메시지 본문 미검증: 저비용이나 별도

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
@kys0213 kys0213 merged commit 66b39d7 into main Jun 14, 2026
1 check passed
@kys0213 kys0213 deleted the refactor/scripts-to-cli-default-branch branch June 14, 2026 05:07
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