Repository navigation
feat(worktrees): copy .env* files and run setup hooks for trusted repos - #54
Merged
Merged
Conversation
4 of 5 tasks
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.
요약
start_thread로 Git worktree를 생성할 때,config.json의worktrees.trustedRepos에 명시적으로 등록된 신뢰 레포에서만.env*파일 복사와.openmybot/worktree.json의setup훅 명령을 실행합니다.왜 필요한가
start_threadworktree 생성 시 추적 파일 체크아웃과 macOS APFSnode_modulesclone만 수행되어, 로컬.env*파일이나 코드 생성/초기화 명령이 필요한 프로젝트는 새 worktree에서 바로 실행·검증하기 어려웠습니다. 반대로 비신뢰 저장소에서 훅이나 비밀 파일 복사를 무조건 실행하면 RCE·비밀 유출 위험이 있습니다.worktrees.trustedRepos에 canonicalrepoRoot(realpathSync일치)가 등록된 레포에서만.env*복사와setup훅이 실행됩니다..env*나.openmybot/worktree.json이 있는 경우worktreeWarning으로 이유와 활성화 방법을 안내합니다.주요 변경
server/config.ts:worktrees: { trustedRepos?: string[] }스키마·타입·저장 머지 키 추가server/worktrees.ts:isTrustedWorktreeRepo:realpathSync기반 canonical 레포 루트 일치 판정readWorktreeHooksConfig:.openmybot/worktree.json파싱·검증(copyEnv,envFiles,setup,timeoutMs), 심볼릭 링크·알 수 없는 필드 차단copyEnvFiles: 일반 파일만 복사(lstatSync().isFile()), 경로 탈출(../절대경로/심볼릭 링크 부모) 차단,COPYFILE_EXCL로 기존 추적 파일(.env.example등) 덮어쓰기 방지runWorktreeSetupCommands:OMB_WORKTREE_PATH,OMB_WORKTREE_REPO,OMB_WORKTREE_BRANCH,OMB_WORKTREE_BASE환경변수를 주입해 순차 실행, 타임아웃(1s–300s, 기본60s) 및 실패 시 즉시 중단·stderr 요약 반환server/index.ts,server/drivers/agents-call.ts:configStatus()에worktrees.trustedRepos노출,/api/internal/threads에서trustedRepos전달 및worktreeSetup/worktreeWarning반환검증
pnpm typecheck,pnpm lint(oxlint --deny-warnings .),pnpm build,pre-push훅 모두 통과npx vitest run server/drivers/agents-catalog-wire.test.ts server/drivers/agents-proxy.test.ts server/config.test.ts: 3 files / 467 tests 통과OPENMAUSBOT_DATA_DIR에서 8개 시나리오 직접 실행 확인:case1_untrusted_blocked: 비신뢰 레포에서.env*미복사 +setup미실행 +trustedRepos안내 경고 확인case2_trusted_env_and_setup:saveConfig/loadConfig왕복 후.env,.env.local복사 및setup2개 명령 순차 실행 +OMB_WORKTREE_*환경변수 주입 확인case3_clean_remove_after_hooks: gitignore된.env*/산출물 생성 후에도removeThreadWorktree깨끗하게 삭제 확인case4_symlink_trust_match: 심볼릭 링크 경로 alias 등록 시 canonical 경로 일치 확인case5_env_security_guards:../outside.env,/etc/hosts, 심볼릭 링크.env.symlink차단 및 하위 경로apps/web/.env.local정상 복사 확인case6_symlink_config_rejected: 심볼릭 링크.openmybot/worktree.json거부 및 명령 미실행 확인case7_setup_failure_stops_and_copyEnv_false:copyEnv: false및 실패 명령 즉시 중단·후속 명령 미실행·stderr 경고 확인case8_setup_timeout:timeoutMs: 1000초과 시 강제 종료 및timed out경고 확인