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 @@
${esc(b.pr.body)}
+ ` : '