Skip to content

Adds AI powered explain feature of a branch#4522

Merged
sergeibbb merged 4 commits intomainfrom
feature/4443-ai-rebase-on-branch
Nov 4, 2025
Merged

Adds AI powered explain feature of a branch#4522
sergeibbb merged 4 commits intomainfrom
feature/4443-ai-rebase-on-branch

Conversation

@sergeibbb
Copy link
Member

@sergeibbb sergeibbb commented Aug 6, 2025

Description

Resolves #4443

Graph:
image

Panel:
image

Checklist

  • I have followed the guidelines in the Contributing document
  • My changes follow the coding style of this project
  • My changes build without any errors or warnings
  • My changes have been formatted and linted
  • My changes include any required corresponding changes to the documentation (including CHANGELOG.md and README.md)
  • My changes have been rebased and squashed to the minimal number (typically 1) of relevant commits
  • My changes have a descriptive commit message with a short title, including a Fixes $XXX - or Closes #XXX - prefix to auto-close the issue that your PR addresses

@sergeibbb sergeibbb marked this pull request as draft August 6, 2025 22:38
sergeibbb added a commit that referenced this pull request Aug 7, 2025
Introduces new AI-assisted commands to recompose all branch commits
and specifically unpushed commits via the graph webview.

(#4443, #4522)
sergeibbb added a commit that referenced this pull request Aug 7, 2025
Updates branch context detection to add a '+recomposable' flag for branches that have commits eligible for recomposition, determined by checking recent merge bases against stored targets. Adjusts menu conditions so the AI rebase command is shown only when a branch can be recomposed, preventing unnecessary options for branches without suitable commits.

(#4443, #4522)
sergeibbb added a commit that referenced this pull request Aug 7, 2025
@sergeibbb sergeibbb force-pushed the feature/4443-ai-rebase-on-branch branch from 3fe767e to 7de9ae3 Compare August 7, 2025 23:23
sergeibbb added a commit that referenced this pull request Aug 7, 2025
sergeibbb added a commit that referenced this pull request Aug 7, 2025
sergeibbb added a commit that referenced this pull request Aug 7, 2025
sergeibbb added a commit that referenced this pull request Aug 7, 2025
This uses the user defined value first and only when it's not set we
fall back to other possible values.
(#4443, #4522)
sergeibbb added a commit that referenced this pull request Aug 7, 2025
Introduces AI-powered branch actions ("Recompose" and "Explain") directly into the branches view, enabling context menu options when branches are recomposable or have unpushed commits. Refactors and centralizes branch recomposability detection to ensure consistent logic across graph and views, improving maintainability and user experience. Enhances discoverability and workflow integration for AI-assisted Git operations.

(#4443, #4522)
sergeibbb added a commit that referenced this pull request Aug 8, 2025
Introduces new AI-assisted commands to recompose all branch commits
and specifically unpushed commits via the graph webview.

(#4443, #4522)
sergeibbb added a commit that referenced this pull request Aug 8, 2025
Updates branch context detection to add a '+recomposable' flag for branches that have commits eligible for recomposition, determined by checking recent merge bases against stored targets. Adjusts menu conditions so the AI rebase command is shown only when a branch can be recomposed, preventing unnecessary options for branches without suitable commits.

(#4443, #4522)
sergeibbb added a commit that referenced this pull request Aug 8, 2025
sergeibbb added a commit that referenced this pull request Aug 8, 2025
@sergeibbb sergeibbb force-pushed the feature/4443-ai-rebase-on-branch branch from 7de9ae3 to 5153fa9 Compare August 8, 2025 00:14
sergeibbb added a commit that referenced this pull request Aug 8, 2025
sergeibbb added a commit that referenced this pull request Aug 8, 2025
sergeibbb added a commit that referenced this pull request Aug 8, 2025
This uses the user defined value first and only when it's not set we
fall back to other possible values.
(#4443, #4522)
sergeibbb added a commit that referenced this pull request Aug 8, 2025
Introduces AI-powered branch actions ("Recompose" and "Explain") directly into the branches view, enabling context menu options when branches are recomposable or have unpushed commits. Refactors and centralizes branch recomposability detection to ensure consistent logic across graph and views, improving maintainability and user experience. Enhances discoverability and workflow integration for AI-assisted Git operations.

(#4443, #4522)
@sergeibbb sergeibbb marked this pull request as ready for review August 8, 2025 00:18
sergeibbb added a commit that referenced this pull request Aug 8, 2025
Introduces new AI-assisted commands to recompose all branch commits
and specifically unpushed commits via the graph webview.

(#4443, #4522)
@sergeibbb sergeibbb force-pushed the feature/4443-ai-rebase-on-branch branch from 5153fa9 to 2094d32 Compare August 8, 2025 00:19
sergeibbb added a commit that referenced this pull request Aug 8, 2025
Updates branch context detection to add a '+recomposable' flag for branches that have commits eligible for recomposition, determined by checking recent merge bases against stored targets. Adjusts menu conditions so the AI rebase command is shown only when a branch can be recomposed, preventing unnecessary options for branches without suitable commits.

(#4443, #4522)
sergeibbb added a commit that referenced this pull request Aug 8, 2025
sergeibbb added a commit that referenced this pull request Aug 8, 2025
@sergeibbb sergeibbb force-pushed the feature/4443-ai-rebase-on-branch branch from 0c7d889 to 61a93c6 Compare August 19, 2025 12:48
sergeibbb added a commit that referenced this pull request Aug 19, 2025
sergeibbb added a commit that referenced this pull request Aug 19, 2025
This uses the user defined value first and only when it's not set we
fall back to other possible values.
(#4443, #4522)
sergeibbb added a commit that referenced this pull request Aug 19, 2025
Introduces AI-powered branch actions ("Recompose" and "Explain") directly into the branches view, enabling context menu options when branches are recomposable or have unpushed commits. Refactors and centralizes branch recomposability detection to ensure consistent logic across graph and views, improving maintainability and user experience. Enhances discoverability and workflow integration for AI-assisted Git operations.

(#4443, #4522)
sergeibbb added a commit that referenced this pull request Sep 3, 2025
Introduces new AI-assisted commands to recompose all branch commits
and specifically unpushed commits via the graph webview.

(#4443, #4522)
sergeibbb added a commit that referenced this pull request Sep 3, 2025
Updates branch context detection to add a '+recomposable' flag for branches that have commits eligible for recomposition, determined by checking recent merge bases against stored targets. Adjusts menu conditions so the AI rebase command is shown only when a branch can be recomposed, preventing unnecessary options for branches without suitable commits.

(#4443, #4522)
sergeibbb added a commit that referenced this pull request Sep 3, 2025
@sergeibbb sergeibbb force-pushed the feature/4443-ai-rebase-on-branch branch from 61a93c6 to aceac5f Compare September 3, 2025 10:41
sergeibbb added a commit that referenced this pull request Sep 3, 2025
sergeibbb added a commit that referenced this pull request Sep 3, 2025
sergeibbb added a commit that referenced this pull request Sep 3, 2025
sergeibbb added a commit that referenced this pull request Sep 3, 2025
This uses the user defined value first and only when it's not set we
fall back to other possible values.
(#4443, #4522)
sergeibbb added a commit that referenced this pull request Sep 3, 2025
Introduces AI-powered branch actions ("Recompose" and "Explain") directly into the branches view, enabling context menu options when branches are recomposable or have unpushed commits. Refactors and centralizes branch recomposability detection to ensure consistent logic across graph and views, improving maintainability and user experience. Enhances discoverability and workflow integration for AI-assisted Git operations.

(#4443, #4522)
Comment on lines +34 to +35
| 'gitlens.ai.aiRebaseBranch:graph'
| 'gitlens.ai.aiRebaseUnpushed:graph'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these listed under InternalGraphWebviewCommands? In contributions it looks like they are fully exposed graph commands?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines +242 to +275
/**
* Selects the most recent merge base from multiple target branches.
* This is the same logic used in graph.ts selectMostRecentMergeBase method.
*/
async function selectMostRecentMergeBase(
branchName: string,
targets: string[],
svc: ReturnType<typeof Container.prototype.git.getRepositoryService>,
): Promise<{ commit: string; branch: string } | undefined> {
const mergeBaseResults = await Promise.allSettled(
targets.map(async target => {
const commit = await svc.refs.getMergeBase(branchName, target);
return {
commit: commit,
branch: target,
};
}),
);
const mergeBases = mergeBaseResults
.map(result => getSettledValue(result))
.filter((r): r is { commit: string; branch: string } => r?.commit != null);

if (mergeBases.length === 0) return undefined;

let mostRecentMergeBase = mergeBases[0];
for (let i = 1; i < mergeBases.length; i++) {
const isCurrentMoreRecent = await svc.commits.isAncestorOf(mostRecentMergeBase?.commit, mergeBases[i].commit);
if (isCurrentMoreRecent) {
mostRecentMergeBase = mergeBases[i];
}
}

return mostRecentMergeBase;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I get a more detailed rundown of what this function is doing? Also, if it already exists in graph.ts, can we just have that import from here so we aren't duplicating logic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@axosoft-ramint
I've added to the explanation and removed the obsolete sentence about the duplication:

/**
 * Selects the most recent merge base from multiple target branches.
 *
 * It gets the merge base for each target, then uses isAncestorOf() to find which one is newest.
 */

The story was that I've implemented originally in graph, then created the dupe here and marked it in the comment. But eventually I refactored to re-use this function everywhere so it's stopped being duplicated, but the explanation phrase has left.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@axosoft-ramint

I've updated the code according to your notes above. Also I've refreshed the branch and fixed the conflicts.

The question now is the following: should I actually call "Rebase" action, or is it better to try to launch the Commit Composer?

cc @justinrobots

@sergeibbb
Copy link
Member Author

@axosoft-ramint , @ericf-axosoft

I've moved "recompose" related part of requirements and the code to another PR draft: #4644

All other review notes has been attended.

cc @justinrobots

Copy link
Contributor

@ramin-t ramin-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context calculations are tanking graph performance. We need to find a lighter way to get that context included.

Comment on lines +352 to +355
const mergeBaseResult =
branch && (await getBranchMergeBaseAndCommonCommit(this.container, branch));
const isRecomposable = Boolean(mergeBaseResult && mergeBaseResult.commit !== branch?.sha);
const mergeBase = isRecomposable ? mergeBaseResult : undefined;
Copy link
Contributor

@ramin-t ramin-t Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems these calculations are expensive in some cases, especially when placed in the main graph loop.

Without these operations (commented out and left out of context), I can load the graph for my test repo (not a very large one) in about 5 seconds:

Image

Same repo, same graph, with these operations, takes nearly 2 minutes to load:

Image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you need any details about my repo/branches/commits that would help with reproducing this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@axosoft-ramint I've moved more changes out to rebase related branch. So, the problem can be handled in a future PR. Now this PR only contains Explain related changes that are not bring new calculations to rendering.

Also adds more item context for new AI-assisted commands to explain
unpushed changes
(#4443, #4522)
Introduces AI-powered branch actions ("Recompose" and "Explain") directly into the branches view, enabling context menu options when branches are recomposable or have unpushed commits. Refactors and centralizes branch recomposability detection to ensure consistent logic across graph and views, improving maintainability and user experience. Enhances discoverability and workflow integration for AI-assisted Git operations.

(#4443, #4522)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an option to explain commits from all changes on a branch

3 participants