diff --git a/docs/agent.md b/docs/agent.md index 7d3b963..9913f97 100644 --- a/docs/agent.md +++ b/docs/agent.md @@ -114,6 +114,18 @@ cw account add --token --email user@example.com Stored as `credentials: {"claudeAiOauth":{"accessToken":""}}` and `configJson: {"hasCompletedOnboarding":true}`. +## Auto-Cleanup & Commit Retries + +After an agent completes (status → `idle`), `tryAutoCleanup` checks if its project worktrees have uncommitted changes: + +1. `CleanupManager.getDirtyWorktreePaths()` runs `git status --porcelain` in each project subdirectory (not the parent `agent-workdirs//` dir) +2. If all clean → worktrees and logs removed immediately +3. If dirty → `resumeForCommit()` resumes the agent's session with a prompt listing the specific dirty subdirectories (e.g. `- \`my-project/\``) +4. The agent `cd`s into each listed directory and commits +5. On next completion, cleanup runs again. `MAX_COMMIT_RETRIES` (1) limits retries — after that the workdir is left in place with a warning + +The retry counter is cleaned up on: successful removal, max retries exceeded, or unexpected error. It is **not** cleaned up when a commit retry is successfully launched (so the counter persists across the retry cycle). + ## Log Chunks Agent output is persisted to `agent_log_chunks` table and drives all live streaming: