feat(git): extend source control with worktrees, stashes, conflicts and identities

- Create a worktree from a new or existing branch
- Integrate a worktree branch into a target branch by merge commit or cherry-pick, with continue/abort on conflicts
- Delete a worktree with keep, delete-local, or delete-local-and-remote branch options, using safe branch deletion for unmerged branches
- Add a stash tab (list, push, apply, pop, drop) shared across a repository and its worktrees
- Rename and delete branches, optionally deleting the remote branch and updating scheduled base branches
- Detect in-progress merge, rebase, cherry-pick and revert operations and hand conflicts to an agent session
- Generate commit messages from staged changes with the default model
- Add a default git identity and saved per-repository identities written to git config
- Unify git error mapping behind a typed error and one route helper; consolidate git mutations and cache invalidation
- Update repository docs
This commit is contained in:
Chris Scott committed 2026-10-03 21:59:00 -04:00
1 parent 52b6147ed3
commit 53238a6324
89 files changed
+7704 -793

No files matched your search

@@ -0,0 +1,49 @@
export const MAX_COMMIT_PROMPT_DIFF_CHARS = 60_000
export interface CommitMessageContext {
stagedStat: string
stagedDiff: string
recentSubjects: string[]
}
function truncateDiff(diff: string): string {
if (diff.length <= MAX_COMMIT_PROMPT_DIFF_CHARS) {
return diff
}
return `${diff.slice(0, MAX_COMMIT_PROMPT_DIFF_CHARS)}\n[diff truncated]`
}
export function buildCommitMessagePrompt({ stagedStat, stagedDiff, recentSubjects }: CommitMessageContext): string {
const subjects = recentSubjects.length > 0
? recentSubjects.map(subject => `- ${subject}`).join('\n')
: '(no recent commits)'
return [
'Write a single commit message for the staged changes below.',
'Match the style of the recent commit subjects when they establish a convention, such as a conventional-commit prefix.',
'Use a subject line of 72 characters or fewer, followed by an optional short body separated by a blank line.',
'Return only the commit message text. Do not wrap it in code fences and do not prefix it with a label.',
'',
'Recent commit subjects:',
subjects,
'',
'Staged changes (stat):',
stagedStat.trim(),
'',
'Staged diff:',
truncateDiff(stagedDiff),
].join('\n')
}
const COMMIT_MESSAGE_LABEL = /^(?:commit message|message)\s*:\s*/i
export function normalizeGeneratedCommitMessage(text: string): string {
let normalized = text.trim().replace(COMMIT_MESSAGE_LABEL, '')
const fenced = normalized.match(/^```[^\n]*\n?([\s\S]*?)\n?```$/)
if (fenced) {
normalized = (fenced[1] ?? '').trim()
}
return normalized.replace(COMMIT_MESSAGE_LABEL, '').trim()
}