- Add optional globalDir parameter to resolveProject(), getDefaultProject(), setDefaultProject(), and clearDefaultProject() for test isolation - Remove ESLint suppression by using void operator for intentionally unused var - Update all tests to use isolated globalDir parameter - Complete tests for default project resolution
12 KiB
Task: KB-030 - Add Git Management Component to Dashboard
Created: 2026-03-30 Size: L
Review Level: 3 (Full)
Assessment: This task involves creating a comprehensive git management UI with server-side git operations, branch management, worktree visualization, and remote operations. It touches both backend API routes and frontend React components with significant security implications (executing git commands server-side).
Score: 6/8 — Blast radius: 2 (multiple files, new API surface), Pattern novelty: 1 (follows existing modal patterns), Security: 2 (exec git commands, input validation critical), Reversibility: 1 (database migrations not needed, but API changes persist)
Mission
Build a comprehensive Git Management component for the kb dashboard that gives users full visibility and control over their repository state. The component will be accessible via a new button in the header and open as a modal with tabbed sections for: recent commits (with diff viewing), branch management (list, checkout, create, delete), worktree visualization (showing which tasks own which worktrees), and remote operations (fetch, pull, push). This eliminates the need for users to drop to the command line for routine git operations while working with kb tasks.
Dependencies
- None
Context to Read First
packages/dashboard/src/routes.ts— Existing API route patterns, especiallygetGitHubRemotes()function and git-related endpointspackages/dashboard/app/api.ts— API client patterns and existing type definitionspackages/dashboard/app/components/SettingsModal.tsx— Reference for tabbed modal implementation with sidebar navigationpackages/dashboard/app/components/GitHubImportModal.tsx— Reference for git-related modal with loading statespackages/dashboard/app/components/Header.tsx— Where to add the Git Manager buttonpackages/dashboard/app/App.tsx— How modals are integrated and state managedpackages/engine/src/scheduler.ts— Understanding of worktree management and how tasks relate to worktreespackages/dashboard/app/hooks/useTasks.ts— How task data flows through the UI
File Scope
Backend (packages/dashboard/src/):
routes.ts— Add new git management API endpointsroutes.test.ts— Add tests for new git endpoints
Frontend (packages/dashboard/app/):
api.ts— Add git API client functions and typescomponents/GitManagerModal.tsx— New git management modal componentcomponents/__tests__/GitManagerModal.test.tsx— Tests for the modalcomponents/Header.tsx— Add button to open Git ManagerApp.tsx— Integrate GitManagerModal and manage its state
Shared types are already defined in:
@kb/coretypes for Task, TaskDetail (worktree field)
Steps
Step 1: Backend API - Git Information Endpoints
- Add
GET /api/git/statusendpoint inroutes.ts— returns current branch, clean/dirty status, ahead/behind counts - Add
GET /api/git/commitsendpoint — returns recent commits (default 20, configurable limit) with hash, message, author, date, and parent hashes - Add
GET /api/git/commits/:hash/diffendpoint — returns diff for a specific commit (stat + patch) - Add
GET /api/git/branchesendpoint — returns all local branches with current indicator, remote tracking info, and last commit date - Add
GET /api/git/worktreesendpoint — returns all worktrees with path, branch, isMain, and associated task ID (lookup by worktree path matching) - All git operations use
execSyncwith 10s timeout and proper error handling - Add tests in
routes.test.tsfor all new endpoints
Artifacts:
packages/dashboard/src/routes.ts(modified)packages/dashboard/src/routes.test.ts(modified)
Step 2: Backend API - Git Action Endpoints
- Add
POST /api/git/branchesendpoint — create new branch from current HEAD or specified base, validates branch name format (no spaces, valid git ref characters) - Add
POST /api/git/branches/:name/checkoutendpoint — checkout existing branch, error if uncommitted changes would be lost - Add
DELETE /api/git/branches/:nameendpoint — delete branch, error if it's the current branch or has unmerged commits - Add
POST /api/git/fetchendpoint — fetch from origin (or specified remote), returns summary of fetched refs - Add
POST /api/git/pullendpoint — pull current branch, returns result summary or error on conflict - Add
POST /api/git/pushendpoint — push current branch, returns result summary - All action endpoints validate we're in a git repo before executing
- Add tests for action endpoints with mocked git commands
- Add validation to prevent command injection in branch names (sanitize/validate all user inputs)
Artifacts:
packages/dashboard/src/routes.ts(modified)packages/dashboard/src/routes.test.ts(modified)
Step 3: Frontend API Client
- Add types in
api.ts:GitStatus,GitCommit,GitBranch,GitWorktree,GitFetchResult,GitPullResult,GitPushResult - Add
fetchGitStatus(): Promise<GitStatus>function - Add
fetchGitCommits(limit?: number): Promise<GitCommit[]>function - Add
fetchCommitDiff(hash: string): Promise<string>function - Add
fetchGitBranches(): Promise<GitBranch[]>function - Add
fetchGitWorktrees(): Promise<GitWorktree[]>function - Add
createBranch(name: string, base?: string): Promise<void>function - Add
checkoutBranch(name: string): Promise<void>function - Add
deleteBranch(name: string): Promise<void>function - Add
fetchRemote(remote?: string): Promise<GitFetchResult>function - Add
pullBranch(): Promise<GitPullResult>function - Add
pushBranch(): Promise<GitPushResult>function - Add tests in
api.test.tsfor all new functions
Artifacts:
packages/dashboard/app/api.ts(modified)packages/dashboard/app/api.test.ts(modified)
Step 4: Git Manager Modal Component
- Create
GitManagerModal.tsxwith tabbed layout following SettingsModal pattern - Define sections:
"status","commits","branches","worktrees","remotes" - Implement Status tab: show current branch, commit hash, dirty status with indicator color, ahead/behind display
- Implement Commits tab: list recent commits with hash (short), message summary, author, date; clickable to expand and show diff in panel below; "Load more" button for pagination
- Implement Branches tab: list all branches with current indicator, create branch input with validation, checkout/delete buttons (with confirmation for delete), switch-to-branch on click
- Implement Worktrees tab: list all worktrees with path, branch, main indicator, and associated task badge (if worktree path matches task worktree field); show free/used worktree count
- Implement Remotes tab: show configured remotes, Fetch/Pull/Push buttons with loading states, display last operation result
- All tabs show loading states and handle errors with toast notifications via
addToastprop - Add keyboard support: Escape to close, Tab navigation within modal
- Auto-refresh status when modal opens and on tab switch
Artifacts:
packages/dashboard/app/components/GitManagerModal.tsx(new)
Step 5: Integrate Git Manager into App
- Add
gitManagerOpenstate toAppInnercomponent - Add
handleOpenGitManagerandhandleCloseGitManagercallbacks - Import
GitBranchicon from lucide-react in Header.tsx - Add git manager button to Header between GitHub Import and Pause buttons
- Add
onOpenGitManagerprop to Header component and wire it up - Add
GitManagerModalto App.tsx withisOpen,onClose,tasks,addToastprops - Pass current
tasksto GitManagerModal so it can correlate worktrees with tasks - Verify modal opens/closes correctly and doesn't interfere with other modals
Artifacts:
packages/dashboard/app/App.tsx(modified)packages/dashboard/app/components/Header.tsx(modified)
Step 6: Testing & Verification
ZERO test failures allowed. Full test suite as quality gate.
- Run
pnpm testinpackages/dashboard— all existing tests must pass - New tests pass:
routes.test.tsadditions (8+ new test cases for git endpoints) - New tests pass:
api.test.tsadditions (11+ new test cases for git API functions) - New tests pass:
GitManagerModal.test.tsxwith coverage for:- Rendering all tabs
- Tab switching
- Loading states
- Error handling
- Commit selection and diff display
- Branch creation validation
- Worktree task correlation display
- Manual verification: open Git Manager, verify commits load, verify branches list, verify worktrees show (create a task to test worktree display)
- Run
pnpm build— dashboard package builds without errors
Artifacts:
packages/dashboard/app/components/__tests__/GitManagerModal.test.tsx(new)
Step 7: Documentation & Delivery
- Update
packages/dashboard/README.mdwith section documenting Git Manager feature - Document the new API endpoints in a "Git API" section
- Verify no out-of-scope features were added
- Create changeset file for the feature:
.changeset/add-git-manager.mdwith minor bump (new dashboard feature)
Changeset content:
---
"@dustinbyrne/kb": minor
---
Add Git Manager to dashboard for repository visualization and management. View commits with diffs, manage branches, see worktree/task associations, and perform fetch/pull/push operations directly from the web UI.
Artifacts:
packages/dashboard/README.md(modified).changeset/add-git-manager.md(new)
Documentation Requirements
Must Update:
packages/dashboard/README.md— Add "Git Manager" section under Features describing the new component and its capabilities
Check If Affected:
packages/dashboard/README.md— Verify API documentation section if it exists and add git endpoints
Completion Criteria
- All steps complete
- All tests passing (
pnpm testin dashboard package) - Build passes (
pnpm build) - Git Manager modal opens from header button
- Status tab shows current branch and repository state
- Commits tab lists commits and shows diffs when clicked
- Branches tab lists branches with create/checkout/delete functionality
- Worktrees tab shows all worktrees with task associations
- Remotes tab provides fetch/pull/push buttons
- Documentation updated
- Changeset created
Git Commit Convention
Commits at step boundaries. All commits include the task ID:
- Step completion:
feat(KB-030): complete Step N — description - Bug fixes:
fix(KB-030): description - Tests:
test(KB-030): description
Example commits:
feat(KB-030): complete Step 1 — add git info API endpointsfeat(KB-030): complete Step 2 — add git action endpointsfeat(KB-030): complete Step 3 — add git API client functionsfeat(KB-030): complete Step 4 — create GitManagerModal componentfeat(KB-030): complete Step 5 — integrate Git Manager into App and Headertest(KB-030): add GitManagerModal testsfeat(KB-030): complete Step 7 — documentation and changeset
Do NOT
- Execute destructive git commands without confirmation (branch delete, force push)
- Allow arbitrary command injection through branch names (validate all inputs)
- Modify the actual git repository during tests (mock all git operations)
- Create new core types when existing Task types suffice
- Add server-sent events for git status updates (poll on open/tab switch only)
- Support merge conflict resolution in the UI (show error, direct to CLI)
- Create worktrees through the UI (worktrees are managed by the scheduler)
- Support multiple remotes beyond origin for MVP (fetch/pull/push use origin)
- Implement staging/commit functionality (out of scope — scheduler handles commits)
- Skip writing tests for any new API endpoint or component