diff --git a/internal/gitengine/collector.go b/internal/gitengine/collector.go index efebc4c..0f0194a 100644 --- a/internal/gitengine/collector.go +++ b/internal/gitengine/collector.go @@ -587,6 +587,7 @@ type ghMergedPRPayload struct { Number int `json:"number"` HeadRefName string `json:"headRefName"` Title string `json:"title"` + Body string `json:"body"` URL string `json:"url"` Author struct { Login string `json:"login"` @@ -697,7 +698,7 @@ func fetchGHMergedPRs(ctx context.Context, repoPath string, nodes []model.Commit ghCtx, cancel := context.WithTimeout(ctx, 4*time.Second) defer cancel() out, _, err := runCmd(ghCtx, repoPath, "gh", "pr", "list", "--state", "merged", "--limit", "60", - "--json", "number,headRefName,title,author,mergeCommit,url") + "--json", "number,headRefName,title,body,author,mergeCommit,url") if err != nil || strings.TrimSpace(out) == "" { return mergedMap, nil } @@ -711,6 +712,7 @@ func fetchGHMergedPRs(ctx context.Context, repoPath string, nodes []model.Commit prObj := model.PRStatus{ Number: it.Number, Title: it.Title, + Body: it.Body, Author: it.Author.Login, URL: it.URL, ReviewState: "MERGED", @@ -1039,6 +1041,16 @@ func isSquashMerged(ctx context.Context, repoPath, branchName, defaultBranch, ba return false } +func isAncestor(ctx context.Context, repoPath, branchName, baseBranch string) bool { + if branchName == "" || baseBranch == "" || branchName == baseBranch { + return false + } + if _, _, err := runCmd(ctx, repoPath, "git", "merge-base", "--is-ancestor", branchName, baseBranch); err == nil { + return true + } + return false +} + func collectLocalBranches(ctx context.Context, repoPath, defaultBranch, baseRef, baseTipSHA, curBranchName, currentUser string, nodes []model.CommitNode, shaToIdx map[string]int, dirtyCount int, dirtyFiles []string, ghPRs, mergedPRs map[string]model.PRStatus, mergedArches []model.BranchArc) ([]model.BranchArc, int) { out, _, err := runCmd(ctx, repoPath, "git", "for-each-ref", "--sort=-committerdate", @@ -1114,7 +1126,8 @@ func collectLocalBranches(ctx context.Context, repoPath, defaultBranch, baseRef, // (aheadMain > 0 olsa bile) PR 'merged' ise dalı "birleşmiş (squash)" say: // çakışma, Cross-PR ve uyarı hesaplarına katma; yalnız temizleme adayı göster. mergedPR, isGHMerged := mergedPRs[name] - isActuallyMerged := isGHMerged || (originGone && isSquashMerged(ctx, repoPath, name, defaultBranch, baseRef)) || (originGone && aheadMain == 0) + isAncest := isAncestor(ctx, repoPath, name, defaultBranch) + isActuallyMerged := isGHMerged || (isAncest && aheadMain == 0) || (originGone && isSquashMerged(ctx, repoPath, name, defaultBranch, baseRef)) || (originGone && aheadMain == 0) if prPtr == nil && isActuallyMerged { if archIdx, exists := mergedArchByName[name]; exists { mergedArches[archIdx].HasLocal = true diff --git a/internal/mcp/server.go b/internal/mcp/server.go index 386321a..a7b7ad8 100644 --- a/internal/mcp/server.go +++ b/internal/mcp/server.go @@ -151,7 +151,7 @@ func listTools() []toolDefinition { return []toolDefinition{ { Name: "gitarc_status", - Description: "Aktif Git deposunun main omurga farkını, üst raydaki açık PR'ları, alt raydaki yerel dalları ve temizlenebilir dalları özetler.", + Description: "GitArc kokpitindeki anlık tam durumu, aktif HEAD dalını, çalışma alanı kirli dosyalarını, açık PR'ları (başlık ve açıklamalarıyla), yerel dalları ve son birleşmiş PR'ları detaylıca döndürür.", InputSchema: emptySchema, }, { @@ -551,44 +551,143 @@ func buildScanSecretsPayload(paths []string, mgr *gitengine.Manager) map[string] func buildStatusPayload(snap model.CockpitSnapshot) map[string]any { type branchBrief struct { - Name string `json:"name"` - Hemisphere string `json:"hemisphere"` - State string `json:"state"` - IsHEAD bool `json:"isHead"` - PRNumber int `json:"prNumber,omitempty"` - CIState string `json:"ciState,omitempty"` - OriginGone bool `json:"originGone,omitempty"` - HasConflict bool `json:"hasConflict,omitempty"` - CrossPRCount int `json:"crossPrCount,omitempty"` - SuggestedCmd string `json:"suggestedCmd,omitempty"` + Name string `json:"name"` + Hemisphere string `json:"hemisphere"` + State string `json:"state"` + IsHEAD bool `json:"isHead"` + PRNumber int `json:"prNumber,omitempty"` + PRTitle string `json:"prTitle,omitempty"` + PRBody string `json:"prBody,omitempty"` + ReviewState string `json:"reviewState,omitempty"` + CIState string `json:"ciState,omitempty"` + LastCommitMsg string `json:"lastCommitMsg,omitempty"` + DraftPRTitle string `json:"draftPrTitle,omitempty"` + DraftPRBody string `json:"draftPrBody,omitempty"` + AheadMain int `json:"aheadMain,omitempty"` + BehindMain int `json:"behindMain,omitempty"` + UncommittedCount int `json:"uncommittedCount,omitempty"` + ChangedFiles []string `json:"changedFiles,omitempty"` + OriginGone bool `json:"originGone,omitempty"` + HasConflict bool `json:"hasConflict,omitempty"` + CrossPRCount int `json:"crossPrCount,omitempty"` + SuggestedCmd string `json:"suggestedCmd,omitempty"` + } + + type openPRItem struct { + Number int `json:"number"` + Branch string `json:"branch"` + Title string `json:"title"` + Body string `json:"body,omitempty"` + Author string `json:"author,omitempty"` + ReviewState string `json:"reviewState,omitempty"` + CIState string `json:"ciState,omitempty"` + URL string `json:"url,omitempty"` + ChangedFiles []string `json:"changedFiles,omitempty"` + } + + type localBranchItem struct { + Name string `json:"name"` + IsHEAD bool `json:"isHead"` + AheadMain int `json:"aheadMain"` + BehindMain int `json:"behindMain"` + UncommittedCount int `json:"uncommittedCount"` + LastCommitMsg string `json:"lastCommitMsg,omitempty"` + DraftPRTitle string `json:"draftPrTitle,omitempty"` + DraftPRBody string `json:"draftPrBody,omitempty"` + ChangedFiles []string `json:"changedFiles,omitempty"` + } + + type mergedPRItem struct { + Number int `json:"number"` + Branch string `json:"branch"` + Title string `json:"title"` + Body string `json:"body,omitempty"` + Author string `json:"author,omitempty"` + ReviewState string `json:"reviewState,omitempty"` + URL string `json:"url,omitempty"` } + var briefs []branchBrief + var openPRs []openPRItem + var localBranches []localBranchItem + var recentMergedPRs []mergedPRItem + openPRCount := 0 localBranchCount := 0 mergedCount := 0 for _, b := range snap.Branches { br := branchBrief{ - Name: b.Name, - Hemisphere: b.Hemisphere, - State: b.State, - IsHEAD: b.IsHEAD, - OriginGone: b.OriginGone, - HasConflict: b.Conflict != nil && b.Conflict.HasConflict && !b.Conflict.Resolved, - CrossPRCount: len(b.CrossPR), - SuggestedCmd: b.SuggestedCmd, + Name: b.Name, + Hemisphere: b.Hemisphere, + State: b.State, + IsHEAD: b.IsHEAD, + LastCommitMsg: b.LastCommitMsg, + DraftPRTitle: b.DraftPRTitle, + DraftPRBody: b.DraftPRBody, + AheadMain: b.AheadMain, + BehindMain: b.BehindMain, + UncommittedCount: b.UncommittedCount, + ChangedFiles: b.ChangedFiles, + OriginGone: b.OriginGone, + HasConflict: b.Conflict != nil && b.Conflict.HasConflict && !b.Conflict.Resolved, + CrossPRCount: len(b.CrossPR), + SuggestedCmd: b.SuggestedCmd, } if b.PR != nil { br.PRNumber = b.PR.Number + br.PRTitle = b.PR.Title + br.PRBody = b.PR.Body + br.ReviewState = b.PR.ReviewState if b.PR.CI != nil { br.CIState = b.PR.CI.State } if b.State == "open" && b.PR.Number > 0 && b.PR.ReviewState != "MERGED" { openPRCount++ + ciSt := "" + if b.PR.CI != nil { + ciSt = b.PR.CI.State + } + openPRs = append(openPRs, openPRItem{ + Number: b.PR.Number, + Branch: b.Name, + Title: b.PR.Title, + Body: b.PR.Body, + Author: b.PR.Author, + ReviewState: b.PR.ReviewState, + CIState: ciSt, + URL: b.PR.URL, + ChangedFiles: b.ChangedFiles, + }) + } else if b.State == "merged" || b.PR.ReviewState == "MERGED" { + if len(recentMergedPRs) < 15 { + recentMergedPRs = append(recentMergedPRs, mergedPRItem{ + Number: b.PR.Number, + Branch: b.Name, + Title: b.PR.Title, + Body: b.PR.Body, + Author: b.PR.Author, + ReviewState: b.PR.ReviewState, + URL: b.PR.URL, + }) + } } } if b.HasLocal && !strings.HasPrefix(b.ID, "gh-merged-") { localBranchCount++ + if b.ID != "local-wip-working-tree" { + localBranches = append(localBranches, localBranchItem{ + Name: b.Name, + IsHEAD: b.IsHEAD, + AheadMain: b.AheadMain, + BehindMain: b.BehindMain, + UncommittedCount: b.UncommittedCount, + LastCommitMsg: b.LastCommitMsg, + DraftPRTitle: b.DraftPRTitle, + DraftPRBody: b.DraftPRBody, + ChangedFiles: b.ChangedFiles, + }) + } } if b.State == "merged" || b.OriginGone { mergedCount++ @@ -599,11 +698,40 @@ func buildStatusPayload(snap model.CockpitSnapshot) map[string]any { if mode == "" { mode = "live" } + + currentBranch := snap.Repo.DefaultBranch + var dirtyFiles []string + for _, b := range snap.Branches { + if b.IsHEAD { + currentBranch = b.Name + } + if b.ID == "local-wip-working-tree" || (b.IsHEAD && b.UncommittedCount > 0) { + if len(dirtyFiles) == 0 { + dirtyFiles = b.ChangedFiles + } + } + } + + activeContext := map[string]any{ + "currentBranch": currentBranch, + "defaultBranch": snap.Repo.DefaultBranch, + "isWorkingTreeClean": snap.Repo.DirtyCount == 0, + "dirtyCount": snap.Repo.DirtyCount, + "dirtyFiles": dirtyFiles, + "openPRs": openPRs, + "localBranches": localBranches, + "recentMergedPRs": recentMergedPRs, + } + if snap.PendingProposal != nil { + activeContext["pendingProposal"] = snap.PendingProposal + } + return map[string]any{ "mode": mode, "openPRCount": openPRCount, "localBranchCount": localBranchCount, "mergedCount": mergedCount, + "activeContext": activeContext, "metricsGlossary": map[string]string{ "openPRCount": "GitHub üzerinde açık (state=open) ve henüz birleştirilmemiş Pull Request sayısı.", "localBranchCount": "Yerel Git deposunda fiziksel olarak var olan dalların sayısı (hasLocal=true).", diff --git a/internal/mcp/server_test.go b/internal/mcp/server_test.go index fb6bf2b..9e5cb85 100644 --- a/internal/mcp/server_test.go +++ b/internal/mcp/server_test.go @@ -65,6 +65,11 @@ func TestMCPServeStdioTools(t *testing.T) { t.Fatalf("expected 9 MCP tools, got %d", len(r2.Result.Tools)) } + // Verify gitarc_status includes activeContext and openPRs for AI assistance + if !strings.Contains(lines[2], "activeContext") || !strings.Contains(lines[2], "openPRs") { + t.Fatalf("expected gitarc_status to contain activeContext and openPRs, got: %s", lines[2]) + } + // Verify gitarc_check_conflicts mentions CHANGELOG.md and conflictHunks if !strings.Contains(lines[3], "CHANGELOG.md") || !strings.Contains(lines[3], "conflictHunks") { t.Fatalf("expected gitarc_check_conflicts output to mention CHANGELOG.md and conflictHunks, got: %s", lines[3]) diff --git a/web/app.js b/web/app.js index 71d2c9b..387e935 100644 --- a/web/app.js +++ b/web/app.js @@ -1272,6 +1272,8 @@ let badgeTone = 'sky'; let badgePulse = false; let badgeText = b.pr ? `PR #${b.pr.number} · ${b.pr.reviewState}` : 'Remote Ray'; + const isFreshLocal = isLower && !isWorkingTreeWip && b.aheadMain === 0; + const isSyncedLocal = isLower && !isWorkingTreeWip && b.aheadMain === 0 && (b.uncommittedCount || 0) === 0; if (isFailed) { badgeTone = 'danger'; badgeText = `PR #${b.pr.number} · CI Failed`; @@ -1287,18 +1289,24 @@ badgeText = 'origin: gone'; } else if (isLower) { badgeTone = 'purple'; - const isFreshLocal = b.aheadMain === 0 && (b.uncommittedCount === 0 || !b.isHead); - badgeText = isWorkingTreeWip - ? 'Yerel Taslak · Uncommitted' - : (isFreshLocal ? '🌱 Yeni Yerel Dal' : 'Yarım Parabol · Local'); + if (isWorkingTreeWip) { + badgeText = 'Yerel Taslak · Uncommitted'; + } else if (isSyncedLocal) { + badgeText = '✓ main ile Senkronize'; + } else if (isFreshLocal) { + badgeText = '🌱 Yeni Yerel Dal'; + } else { + badgeText = 'Yarım Parabol · Local'; + } } - const isFreshLocal = isLower && !isWorkingTreeWip && b.aheadMain === 0; const subText = isWorkingTreeWip ? `${b.uncommittedCount || 0} dosya bekliyor · İncelemek için tıklayın` - : (isFreshLocal - ? 'main omurgasında taze dal · İlk commitinizi bekliyor' - : (b.lastCommitMsg ? b.lastCommitMsg : (isLower ? `↑${b.aheadMain || 0} yerel · ${b.uncommittedCount || 0} dirty` : `↑${b.aheadMain || 0} ↓${b.behindMain || 0}`))); + : (isSyncedLocal + ? 'main omurgasıyla eşitlendi · Yeni commit veya değişiklik yok' + : (isFreshLocal + ? 'main omurgasında taze dal · İlk commitinizi bekliyor' + : (b.lastCommitMsg ? b.lastCommitMsg : (isLower ? `↑${b.aheadMain || 0} yerel · ${b.uncommittedCount || 0} dirty` : `↑${b.aheadMain || 0} ↓${b.behindMain || 0}`)))); const card = document.createElementNS(XHTML_NS, 'div'); card.className = `cap-card ${tone} ${isSelected ? 'selected' : ''}`; @@ -1341,12 +1349,20 @@ } } else { const hasOpenPR = Boolean(b.pr && b.pr.number > 0 && b.pr.reviewState !== 'MERGED'); - actionRowHtml = ` - - ${hasOpenPR ? `` : ''} - ${checkoutBtn} - - `; + const isSynced = b.aheadMain === 0 && (b.uncommittedCount || 0) === 0; + if (isSynced) { + actionRowHtml = ` + ${b.isHead ? '' : checkoutBtn} + + `; + } else { + actionRowHtml = ` + + ${hasOpenPR ? `` : ''} + ${checkoutBtn} + + `; + } } } else if (isRunning) { actionRowHtml = ` @@ -1381,6 +1397,7 @@ const act = btn.getAttribute('data-act'); if (act === 'inspect') selectBranch(b.id); else if (act === 'checkout') handleCheckoutBranch(b.id, btn); + else if (act === 'checkout-main') handleCheckoutBranch('main', btn); else if (act === 'merge') handleMergeBranch(b.id, btn); else if (act === 'promote') handlePromoteBranch(b.id, undefined, undefined, btn); else if (act === 'resolve') openConflictStudio(b.id); @@ -1796,7 +1813,8 @@ const isRunning = ciState === 'RUNNING'; const isQueued = Boolean(state.pendingAutoMerge[b.id]); const canCommitWorkingTree = isVirtualWip || (b.uncommittedCount || 0) > 0 || (b.isHead && (state.snapshot?.repo?.dirtyCount || 0) > 0); - const canPromote = isOpen && b.hemisphere === 'lower' && !isVirtualWip && !canCommitWorkingTree; + const isAlreadySynced = b.aheadMain === 0 && (b.uncommittedCount || 0) === 0 && !isVirtualWip; + const canPromote = isOpen && b.hemisphere === 'lower' && !isVirtualWip && !canCommitWorkingTree && !isAlreadySynced; const hasOpenPR = Boolean(b.pr && b.pr.number > 0 && b.pr.reviewState !== 'MERGED'); const canMerge = isOpen && hasOpenPR && !hasConflict && !isVirtualWip && ciState !== 'FAILURE'; @@ -1812,7 +1830,7 @@

${isVirtualWip ? '✏️ Çalışma Alanı (Kaydedilmemiş Değişiklikler)' : esc(b.name)}

- ${isVirtualWip ? 'Yerel Taslak · Uncommitted' : (b.state === 'merged' ? 'Tam Parabol' : (b.hemisphere === 'lower' && b.aheadMain === 0 ? '🌱 Yeni Yerel Dal' : b.hemisphere === 'lower' ? 'Alt Ray · Local' : 'Üst Ray · PR'))} + ${isVirtualWip ? 'Yerel Taslak · Uncommitted' : (b.state === 'merged' ? 'Tam Parabol' : (isAlreadySynced ? '✓ main ile Eşit (Kalıntı Dal)' : (b.hemisphere === 'lower' && b.aheadMain === 0 ? '🌱 Yeni Yerel Dal' : b.hemisphere === 'lower' ? 'Alt Ray · Local' : 'Üst Ray · PR')))}
@@ -1825,6 +1843,7 @@
${!b.isHead && isOpen && !isVirtualWip ? `` : ''} + ${b.isHead && isAlreadySynced && !isVirtualWip ? `` : ''} ${canPromote && !hasOpenPR ? `` : ''} ${hasOpenPR && !isVirtualWip ? `
@@ -2077,6 +2096,22 @@
`; + } else if (isAlreadySynced && b.hemisphere === 'lower') { + html += ` +
+

+ ✓ main Omurgası ile Senkronize + Kalıntı Dal +

+
+ Bu dal (${esc(b.name)}) GitHub main omurgasıyla tamamen eşitlendi. Push edilecek yeni bir commit veya kaydedilmemiş açık değişiklik bulunmuyor. +
+
+ ${b.isHead ? '' : ''} + +
+
+ `; } if (b.changedFiles?.length) { @@ -2106,6 +2141,21 @@
`; + } else if (b.pr && !isOpen) { + html += ` +
+

+ 📜 PR #${b.pr.number} Detayı + ${esc(b.pr.reviewState || 'MERGED')} +

+
Başlık: ${esc(b.pr.title)}
+ ${b.pr.author ? `
Yazar: @${esc(b.pr.author)}
` : ''} + ${b.pr.body ? ` +
PR Açıklaması
+
${esc(b.pr.body)}
+ ` : '
Bu PR için GitHub açıklaması kaydedilmemiş veya gövde boş.
'} +
+ `; } if (b.canAmendCommit) { @@ -2204,6 +2254,10 @@ state.mergeStrategy = ev.target.value; }); document.getElementById('act-merge')?.addEventListener('click', (ev) => handleMergeBranch(b.id, ev.currentTarget)); + document.getElementById('act-checkout')?.addEventListener('click', (ev) => handleCheckoutBranch(b.id, ev.currentTarget)); + document.getElementById('act-checkout-main')?.addEventListener('click', (ev) => handleCheckoutBranch('main', ev.currentTarget)); + document.getElementById('act-checkout-main-synced')?.addEventListener('click', (ev) => handleCheckoutBranch('main', ev.currentTarget)); + document.getElementById('act-delete-synced')?.addEventListener('click', (ev) => handleDeleteBranch(b.id, ev.currentTarget)); document.getElementById('act-resolve')?.addEventListener('click', () => openConflictStudio(b.id)); document.getElementById('act-resolve-card')?.addEventListener('click', () => openConflictStudio(b.id)); document.getElementById('act-fix-ci')?.addEventListener('click', () => handleFixCI(b.id)); diff --git a/web/fallback.js b/web/fallback.js index 0f269dc..2ed74cc 100644 --- a/web/fallback.js +++ b/web/fallback.js @@ -88,21 +88,21 @@ id: 'br-merged-412', name: 'feat/vault-idle-lock', hemisphere: 'upper', state: 'merged', startSpineIndex: 0, endSpineIndex: 2, baseSha: '19a4c01', mergeSha: '3c19e44', hasRemote: true, remoteRef: 'origin/feat/vault-idle-lock', originGone: false, - pr: { number: 412, title: 'feat(vault): idle timeout lock', author: 'ziya', reviewState: 'MERGED', ci: { state: 'SUCCESS', workflow: 'ci.yml', duration: '1m 24s' } }, + pr: { number: 412, title: 'feat(vault): idle timeout lock', body: '## Neler Değişti?\n- Boşta kalma süresinde vault otomatik kilitlenir.', author: 'ziya', reviewState: 'MERGED', ci: { state: 'SUCCESS', workflow: 'ci.yml', duration: '1m 24s' } }, changedFiles: ['go/internal/vault/vault.go'], }, { id: 'br-merged-415', name: 'fix/usb-exfat-update', hemisphere: 'upper', state: 'merged', startSpineIndex: 3, endSpineIndex: 4, baseSha: '4b70a89', mergeSha: '5e02b11', hasRemote: false, remoteRef: 'origin/fix/usb-exfat-update', originGone: true, - pr: { number: 415, title: 'fix(selfupdate): exFAT update', author: 'ziya', reviewState: 'MERGED', ci: { state: 'SUCCESS', workflow: 'ci.yml', duration: '1m 11s' } }, + pr: { number: 415, title: 'fix(selfupdate): exFAT update', body: '## Neler Değişti?\n- exFAT dosya sisteminde güncelleme kilidi düzeltildi.', author: 'ziya', reviewState: 'MERGED', ci: { state: 'SUCCESS', workflow: 'ci.yml', duration: '1m 11s' } }, hasLocal: true, localSha: '5e02b11', changedFiles: ['go/internal/selfupdate/update.go'], }, { id: 'br-merged-418', name: 'feat/utility-items-catalog', hemisphere: 'upper', state: 'merged', startSpineIndex: 1, endSpineIndex: 6, baseSha: '2f81d12', mergeSha: '7a91c33', hasRemote: false, remoteRef: 'origin/feat/utility-items-catalog', originGone: true, - pr: { number: 418, title: 'feat(manifest): item_var catalog', author: 'ziya', reviewState: 'MERGED', ci: { state: 'SUCCESS', workflow: 'ci.yml', duration: '2m 03s' } }, + pr: { number: 418, title: 'feat(manifest): item_var catalog', body: '## Neler Değişti?\n- Dinamik manifest değişken kataloğu eklendi.', author: 'ziya', reviewState: 'MERGED', ci: { state: 'SUCCESS', workflow: 'ci.yml', duration: '2m 03s' } }, hasLocal: true, localSha: '7a91c33', changedFiles: ['go/internal/manifest/items.go'], }, { diff --git a/web/tasarim.css b/web/tasarim.css index 07b5aa7..5207432 100644 --- a/web/tasarim.css +++ b/web/tasarim.css @@ -2148,6 +2148,22 @@ body { margin-top: 6px; } +.pr-body-box { + background: var(--surface-card); + color: var(--text); + border: 1px solid var(--border); + border-radius: var(--radius-sm); + padding: 8px 10px; + font-family: inherit; + font-size: 11px; + line-height: 1.5; + max-height: 240px; + overflow-y: auto; + white-space: pre-wrap; + word-break: break-word; + margin-top: 6px; +} + .file-list { display: flex; flex-wrap: wrap;