{"record":{"id":"d97fb398fc7b0173","repo":"Yeachan-Heo/oh-my-codex","slug":"leader-workspace-dirty-for-worktrees","errorCode":"leader_workspace_dirty_for_worktrees","errorMessage":"leader_workspace_dirty_for_worktrees:${resolve(cwd)}:${preview}:commit_or_stash_before_omx_team","messagePattern":"leader_workspace_dirty_for_worktrees:(.+?):(.+?):commit_or_stash_before_omx_team","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/team/worktree.ts","lineNumber":156,"sourceCode":"    cwd,\n    encoding: 'utf-8',\n      windowsHide: true,\n    });\n  if (result.status !== 0) {\n    const stderr = (result.stderr || '').trim();\n    throw new Error(stderr || `workspace_status_failed:${cwd}`);\n  }\n  return (result.stdout || '')\n    .split(/\\r?\\n/)\n    .map((line) => line.trimEnd())\n    .filter(Boolean);\n}\n\nexport function assertCleanLeaderWorkspaceForWorkerWorktrees(cwd: string): void {\n  const lines = readWorkspaceStatusLines(cwd);\n  if (lines.length === 0) return;\n  const preview = lines.slice(0, 8).join(' | ');\n  throw new Error(\n    `leader_workspace_dirty_for_worktrees:${resolve(cwd)}:${preview}:commit_or_stash_before_omx_team`,\n  );\n}\n\nfunction listWorktrees(repoRoot: string): GitWorktreeEntry[] {\n  const raw = readGit(repoRoot, ['worktree', 'list', '--porcelain']);\n  if (!raw) return [];\n\n  const entries: GitWorktreeEntry[] = [];\n  const chunks = raw\n    .split(/\\n\\n+/)\n    .map((chunk) => chunk.trim())\n    .filter(Boolean);\n\n  for (const chunk of chunks) {\n    const lines = chunk\n      .split(/\\r?\\n/)\n      .map((line) => line.trim())","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/team/worktree.ts#L138-L174","documentation":"Thrown by assertCleanLeaderWorkspaceForWorkerWorktrees before starting team workers: the leader workspace (cwd) has uncommitted or untracked files, shown as a preview of the first 8 status lines. The library requires a clean leader workspace so worker worktrees branch off a reproducible commit.","triggerScenarios":"Calling startTeam (or the assert directly) while `git status --porcelain --untracked-files=all` in cwd returns any lines — modified files, staged changes, untracked files, or untracked build artifacts all count.","commonSituations":"Running the team command after building locally (dist/, node_modules/ not gitignored); forgetting to commit generated config edits; untracked log files; CI leaving artifacts in the tree; merging/rebasing left unresolved state.","solutions":["Commit or stash all changes including untracked files: `git add -A && git commit` or `git stash --include-untracked`","Add build outputs and logs to .gitignore so untracked artifacts stop blocking the check","If the changes are disposable, clean them: `git checkout -- . && git clean -fd` (verify nothing valuable will be lost)","Make your pipeline run the clean check itself before invoking startTeam and surface a friendly message"],"exampleFix":"# before: dirty workspace blocks startTeam\ngit status --porcelain # shows M src/x.ts, ?? dist/\n\n# after\ngit add -A && git commit -m \"wip before team run\"\n# or: git stash --include-untracked\nprintf 'dist/\\n*.log\\n' >> .gitignore","handlingStrategy":"validation","validationCode":"import { readWorkspaceStatusLines } from './worktree';\n\nfunction assertClean(cwd: string): void {\n  const lines = readWorkspaceStatusLines(cwd);\n  if (lines.length > 0) {\n    throw new Error(`Refusing to start: ${lines.length} uncommitted changes. Commit or stash first.`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try { startTeam(...); } catch (e) { if (String(e?.message).startsWith('leader_workspace_dirty_for_worktrees')) { const [path, preview] = e.message.split(':').slice(1); /* show preview to user, suggest git stash --include-untracked */ } else throw e; }","preventionTips":["Run `git status --porcelain --untracked-files=all` yourself before startTeam and act on it","Keep a comprehensive .gitignore for build outputs and logs","Adopt the habit of committing or stashing before long-running team commands"],"tags":["git","worktree","dirty-workspace","team","precondition"],"backgroundTag":"git-working-tree-dirty","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}