feat: add --auto-init-repository option for empty repositories#1231
feat: add --auto-init-repository option for empty repositories#1231
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #1230
When the solver encounters an empty repository (no commits) with direct write access, branch creation fails because origin/main has no commits. The existing empty repo handling only covered the fork path. This adds: - New --auto-init-repository CLI option (default: false) - Empty repository detection in verifyDefaultBranchAndStatus() - Auto-initialization using existing tryInitializeEmptyRepository() - Improved error messages suggesting --auto-init-repository - Case study documentation in docs/case-studies/issue-1230/ - Tests and experiment scripts Fixes #1230 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This reverts commit 10fb005.
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
|
What about comment to issue? We did have it somewhere in the code? Ensure all changes are correct, consistent and fully meet all discussed requirements (check issue description and all comments in issue and in pull request). |
|
🤖 AI Work Session Started Starting automated work session at 2026-02-07T00:31:13.146Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback. |
When an empty repository is detected in the direct access path (not fork path), post a comment on the issue informing the user about the problem and suggesting solutions, matching the existing behavior in the fork path. - Add tryCommentOnIssueAboutEmptyRepo() helper in solve.repo-setup.lib.mjs - Post comment when --auto-init-repository is not enabled (suggest the flag) - Post comment when --auto-init-repository fails (suggest manual init) - Skip comment when --auto-init-repository succeeds (no user action needed) - Pass issueUrl to verifyDefaultBranchAndStatus() for comment posting - Add 5 new tests (13-17) covering the comment behavior - Update case study documentation Fixes #1230 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
|
Resolve conflicts. We need to ensure all changes are correct, consistent, validated, tested, logged and fully meet all discussed requirements (check issue description and all comments in issue and in pull request). Ensure all CI/CD checks pass. |
|
🤖 AI Work Session Started Starting automated work session at 2026-03-14T14:00:53.233Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback. |
Merge origin/main into issue-1230-f88cfda7aae8, resolving conflicts in src/option-suggestions.lib.mjs and src/solve.config.lib.mjs by keeping both the auto-init-repository option and the new options from main (attach-solution-summary, auto-accept-invite, finalize, etc.). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🤖 Solution Draft LogWork completed:
Summary of changes in this PR:
All requirements from the issue description and PR comments have been addressed. PR is ready for review. |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
Summary
Fixes #1230
When the solver encounters an empty repository (no commits) with direct write access, branch creation fails because
origin/mainhas no commits to branch from. The existing empty repository handling only covered the fork path (HTTP 403 "Empty repositories cannot be forked").This PR adds:
--auto-init-repositoryCLI option (default:false) that automatically creates a simple README.md in empty repositoriesdetectEmptyRepository()tryInitializeEmptyRepository()function--auto-init-repositorywhen empty repos are encountereddocs/case-studies/issue-1230/How it works
verifyDefaultBranchAndStatus()detects the repository is empty (no HEAD, no remote branches)--auto-init-repositoryis enabled and user has write access:tryInitializeEmptyRepository())Issue comment behavior
The comment-to-issue behavior follows the same pattern as the existing fork-path code in
solve.repository.lib.mjs:gh issue commentwhen empty repo is detected and cannot be resolved--auto-init-repositoryflag or manually initializing the repositoryExample usage
# Auto-initialize empty repository before solving solve https://github.com/owner/repo/issues/1 --auto-init-repositoryFiles changed
src/solve.config.lib.mjs--auto-init-repositoryoption definitionsrc/option-suggestions.lib.mjsKNOWN_OPTION_NAMESfor typo detectionsrc/solve.repository.lib.mjstryInitializeEmptyRepositoryfor reusesrc/solve.repo-setup.lib.mjsverifyDefaultBranchAndStatus()src/solve.mjsargv,owner,repo,issueUrltoverifyDefaultBranchAndStatus()src/solve.branch-errors.lib.mjsTest plan
tests/test-auto-init-repository.mjs(17 tests, all passing)experiments/test-auto-init-repository.mjstest-branch-name-validation.mjs,test-malformed-flags.mjs)🤖 Generated with Claude Code