[Bug] Auto-commit on a detached HEAD gives no warning, and agent commits carry no marker
Description
commitFile in source/services/auto-commit.ts skips a merge, rebase, cherry-pick or revert in progress (isOperationInProgress, line 129), but not a detached HEAD. A commit made there belongs to no branch and is easy to lose at the next checkout, and the user is not told. Auto-commits also use the user's own git identity and a plain chore: update <file> message, so they cannot be found later for squashing or review.
Environment
- OS: Windows 11 (10.0.26300)
- Node version: 22.22.3
- Nanocoder version: 1.31.0 (main at 9d88dda7)
- Git: 2.55.0.windows.3
- Provider / Model: not relevant (reproduced by calling
maybeAutoCommit)
Steps to Reproduce
- Make a repo with two commits and turn on
nanocoder.autoCommit. - Run
git checkout --detach HEAD~1. - Let the agent edit a file.
- Run
git status -sb,git log -1 --format=%B, andgit branch --contains HEAD.
Expected Behavior
A warning that HEAD is detached (or the commit is skipped), and the commit message includes a trailer such as Nanocoder-Auto-Commit: true.
Actual Behavior
## HEAD (no branch)
tool-result note: "[auto-commit] 98b97b1 chore: update a.txt"
user sees only: "Auto-committed a.txt (98b97b1): chore: update a.txt"
commit message: "chore: update a.txt"
author: T <[email protected]> (the user's own identity)
branches containing the commit: none (only reachable from HEAD)
Suggested Fix
- In
commitFile, checkgit symbolic-ref -q HEADbefore committing. If it fails, warn once (or skip). - Append a trailer to the message (line 187-188, where
generateMessageandgit commit -mare called) sogit log --grep "Nanocoder-Auto-Commit"finds them. - Add tests for both.
Additional Context
- Auto-commit came from #1512 (#1482). Related fixes: #1653, #1654.
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder
AI-assisted: I’d like to work on #1747. I’ll add a fail-safe HEAD check so auto-commit skips detached HEAD before touching the index and logs a warning, plus a Nanocoder-Auto-Commit: true commit trailer. I’ll add focused regression tests for both and open a PR after they pass.
Hey @ducanhnguyen223, Assigned this one to you! Just a heads-up for next time: please wait for the assignment before opening a PR. Thanks!