-
Notifications
You must be signed in to change notification settings - Fork 0
fix: hook improvements and init defaults (GIT-85) #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f0a5ae
docs: add smart commit analysis to changelog
TonyCasey 3bf8016
docs: test smart commit analysis
TonyCasey 5f1bedb
Revert "docs: test smart commit analysis"
TonyCasey 2ebd2e3
fix: install all hooks by default and fix hook chaining
TonyCasey acdb090
fix: prevent duplicate Agent/Model trailers
TonyCasey 8e87265
feat: auto-configure git to push notes with commits
TonyCasey cdeccea
fix: address PR review comments (GIT-73)
TonyCasey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,16 +42,16 @@ export class CommitMsgHandler implements IEventHandler<ICommitMsgEvent> { | |
| // 1. Read the commit message file | ||
| const message = readFileSync(event.commitMsgPath, 'utf8'); | ||
|
|
||
| // 2. Check if AI-Agent trailer already exists (avoid duplicates from prepare-commit-msg) | ||
| if (message.includes('AI-Agent:')) { | ||
| this.logger.debug('AI trailers already present, skipping analysis'); | ||
| // 2. Check if full analysis already done (AI-Memory-Id indicates commit-msg hook has run) | ||
| if (message.includes('AI-Memory-Id:')) { | ||
| this.logger.debug('Full analysis already done, skipping'); | ||
| return { handler: 'CommitMsgHandler', success: true }; | ||
| } | ||
|
|
||
| // 3. Check autoAnalyze config - if false, only add basic Agent/Model trailers | ||
| if (!config.autoAnalyze) { | ||
| this.logger.debug('autoAnalyze is false, adding only Agent/Model trailers'); | ||
| const basicTrailers = this.buildBasicTrailers(); | ||
| const basicTrailers = this.buildBasicTrailers(message); | ||
| await this.appendTrailers(event.commitMsgPath, basicTrailers, event.cwd); | ||
| return { handler: 'CommitMsgHandler', success: true }; | ||
| } | ||
|
|
@@ -70,8 +70,8 @@ export class CommitMsgHandler implements IEventHandler<ICommitMsgEvent> { | |
| return { handler: 'CommitMsgHandler', success: true }; | ||
| } | ||
|
|
||
| // 7. Build trailers (skip tags if inferTags is false) | ||
| const trailers = this.buildTrailers(analysis, config); | ||
| // 7. Build trailers (skip Agent/Model if already present from prepare-commit-msg) | ||
| const trailers = this.buildTrailers(analysis, config, message); | ||
|
|
||
| // 8. Append trailers to the commit message using git interpret-trailers | ||
| await this.appendTrailers(event.commitMsgPath, trailers, event.cwd); | ||
|
|
@@ -99,40 +99,55 @@ export class CommitMsgHandler implements IEventHandler<ICommitMsgEvent> { | |
|
|
||
| /** | ||
| * Build basic AI-Agent and AI-Model trailers only (when autoAnalyze is false). | ||
| * Skips if already present from prepare-commit-msg. | ||
| */ | ||
| private buildBasicTrailers(): ITrailer[] { | ||
| private buildBasicTrailers(existingMessage: string): ITrailer[] { | ||
| const trailers: ITrailer[] = []; | ||
| const agent = this.agentResolver.resolveAgent(); | ||
| const model = this.agentResolver.resolveModel(); | ||
| const hasAgent = existingMessage.includes('AI-Agent:'); | ||
| const hasModel = existingMessage.includes('AI-Model:'); | ||
|
|
||
| if (agent) { | ||
| trailers.push({ key: AI_TRAILER_KEYS.AGENT, value: agent }); | ||
| if (!hasAgent) { | ||
| const agent = this.agentResolver.resolveAgent(); | ||
| if (agent) { | ||
| trailers.push({ key: AI_TRAILER_KEYS.AGENT, value: agent }); | ||
| } | ||
| } | ||
| if (model) { | ||
| trailers.push({ key: AI_TRAILER_KEYS.MODEL, value: model }); | ||
| if (!hasModel) { | ||
| const model = this.agentResolver.resolveModel(); | ||
| if (model) { | ||
| trailers.push({ key: AI_TRAILER_KEYS.MODEL, value: model }); | ||
| } | ||
| } | ||
|
|
||
| return trailers; | ||
| } | ||
|
|
||
| /** | ||
| * Build all AI-* trailers from the analysis result. | ||
| * Skips Agent/Model if they already exist (from prepare-commit-msg). | ||
| */ | ||
| private buildTrailers( | ||
| analysis: ReturnType<ICommitAnalyzer['analyze']>, | ||
| config: ICommitMsgConfig | ||
| config: ICommitMsgConfig, | ||
| existingMessage: string | ||
| ): ITrailer[] { | ||
| const trailers: ITrailer[] = []; | ||
|
|
||
| // Always add Agent and Model via injected resolver | ||
| const agent = this.agentResolver.resolveAgent(); | ||
| const model = this.agentResolver.resolveModel(); | ||
| // Only add Agent and Model if not already present (prepare-commit-msg may have added them) | ||
| const hasAgent = existingMessage.includes('AI-Agent:'); | ||
| const hasModel = existingMessage.includes('AI-Model:'); | ||
|
|
||
| if (agent) { | ||
| trailers.push({ key: AI_TRAILER_KEYS.AGENT, value: agent }); | ||
| if (!hasAgent) { | ||
| const agent = this.agentResolver.resolveAgent(); | ||
| if (agent) { | ||
| trailers.push({ key: AI_TRAILER_KEYS.AGENT, value: agent }); | ||
| } | ||
| } | ||
| if (model) { | ||
| trailers.push({ key: AI_TRAILER_KEYS.MODEL, value: model }); | ||
| if (!hasModel) { | ||
| const model = this.agentResolver.resolveModel(); | ||
| if (model) { | ||
| trailers.push({ key: AI_TRAILER_KEYS.MODEL, value: model }); | ||
| } | ||
| } | ||
|
Comment on lines
100
to
151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Optional: dedupe Agent/Model trailer construction. Both trailer builders reimplement the same Agent/Model logic; a small helper would prevent divergence. ♻️ Possible refactor+ private buildAgentModelTrailers(existingMessage: string): ITrailer[] {
+ const trailers: ITrailer[] = [];
+ const hasAgent = existingMessage.includes('AI-Agent:');
+ const hasModel = existingMessage.includes('AI-Model:');
+
+ if (!hasAgent) {
+ const agent = this.agentResolver.resolveAgent();
+ if (agent) trailers.push({ key: AI_TRAILER_KEYS.AGENT, value: agent });
+ }
+ if (!hasModel) {
+ const model = this.agentResolver.resolveModel();
+ if (model) trailers.push({ key: AI_TRAILER_KEYS.MODEL, value: model });
+ }
+ return trailers;
+ }
+
private buildBasicTrailers(existingMessage: string): ITrailer[] {
- const trailers: ITrailer[] = [];
- const hasAgent = existingMessage.includes('AI-Agent:');
- const hasModel = existingMessage.includes('AI-Model:');
- ...
- return trailers;
+ return this.buildAgentModelTrailers(existingMessage);
}
private buildTrailers(..., existingMessage: string): ITrailer[] {
- const trailers: ITrailer[] = [];
- const hasAgent = existingMessage.includes('AI-Agent:');
- const hasModel = existingMessage.includes('AI-Model:');
- ...
- return trailers;
+ const trailers: ITrailer[] = [
+ ...this.buildAgentModelTrailers(existingMessage),
+ ];
+ ...
+ return trailers;
}🤖 Prompt for AI Agents |
||
|
|
||
| // Add type-specific trailer if we detected a type | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.