n2b 0.5.1 โ†’ 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -2,36 +2,87 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/n2b.svg)](https://badge.fury.io/rb/n2b)
4
4
 
5
- **Transform your development workflow with intelligent code analysis and seamless Jira integration.** N2B is an AI-powered development tool that revolutionizes code review, requirements compliance, and project management through automated analysis and smart ticket integration.
5
+ **Transform your development workflow with intelligent command translation, code analysis, and seamless Jira/GitHub integration.** N2B provides a suite of tools to enhance productivity.
6
+
7
+ > **IMPORTANT: Command Restructuring in v2.0**
8
+ >
9
+ > The `n2b` and `n2b-diff` commands have been restructured in version 2.0.
10
+ > * `n2b` is now solely for natural language to shell command translation.
11
+ > * `n2b-diff` handles both AI-powered merge conflict resolution AND AI-powered code diff analysis (previously `n2b --diff`).
12
+ >
13
+ > Please see our [MIGRATION.md](MIGRATION.md) for details on adapting your commands and workflows.
14
+
15
+ **Transform your development workflow with intelligent code analysis and seamless Jira integration.** N2B is an AI-powered development tool that revolutionizes code review, requirements compliance, and project management through automated diff analysis, smart merge conflict resolution, and intelligent ticket integration.
6
16
 
7
17
  ## ๐Ÿš€ **Key Features**
8
18
 
9
- ### ๐ŸŽฏ **Smart Jira Integration**
10
- - **Automated Ticket Analysis**: Fetch requirements from Jira tickets and analyze code changes against them
11
- - **Intelligent Updates**: Post beautifully formatted analysis results directly to Jira with collapsible sections
12
- - **Requirements Extraction**: Automatically identify acceptance criteria, tasks, and requirements from tickets and comments
13
- - **Real-time Feedback**: Get instant compliance checking and implementation guidance
19
+ ### ๐ŸŽฏ **Smart Jira & GitHub Integration (via `n2b-diff --analyze`)**
20
+ - **Automated Ticket/Issue Analysis**: Fetch requirements from Jira tickets or GitHub issues and analyze code changes against them using `n2b-diff --analyze`.
21
+ - **Intelligent Updates**: Post beautifully formatted analysis results directly to Jira or GitHub.
22
+ - **Requirements Extraction**: Automatically identify acceptance criteria and tasks.
23
+ - **Real-time Feedback**: Get instant compliance checking.
24
+
25
+ ### ๐Ÿ” **AI-Powered Code Diff Analysis (via `n2b-diff --analyze`)**
26
+ - **Context-Aware Diff Review**: Intelligent analysis of `git`/`hg` changes.
27
+ - **Requirements Compliance**: Automated verification against project requirements.
28
+ - **Test Coverage Assessment**: Evaluate test completeness.
29
+ - **Security & Quality Insights**: Identify potential issues and improvements.
30
+ - **Custom Instructions**: Guide the AI analysis with the `-m/--message` option.
14
31
 
15
- ### ๐Ÿ” **AI-Powered Code Analysis**
16
- - **Context-Aware Diff Review**: Intelligent analysis of git/hg changes with comprehensive insights
17
- - **Requirements Compliance**: Automated verification against project requirements and acceptance criteria
18
- - **Test Coverage Assessment**: Evaluate test completeness and suggest improvements
19
- - **Security & Quality Insights**: Identify potential issues, risks, and improvement opportunities
32
+ ### ใ‚ณใƒžใƒณใƒ‰ๅค‰ๆ› (via `n2b`)
33
+ - **Natural Language to Shell**: Convert descriptions to executable shell commands.
20
34
 
21
35
  ### ๐Ÿค– **Flexible AI Support**
22
- - **Multiple LLM Providers**: Claude, OpenAI, Gemini, OpenRouter, Ollama
23
- - **Latest Models**: OpenAI O3/O4 series, Gemini 2.5, Claude Sonnet 4.0
24
- - **Custom Models**: Support for fine-tuned models, beta releases, and custom deployments
36
+ - **Multiple LLM Providers**: Claude, OpenAI, Gemini, OpenRouter, Ollama.
37
+ - **Latest Models**: Support for cutting-edge models from various providers.
38
+ - **Custom Models**: Use fine-tuned models and custom deployments.
25
39
 
26
40
  ### ๐Ÿ’ป **Development Workflow**
27
- - **Natural Language Commands**: Convert descriptions to executable bash commands
28
- - **Ruby Code Generation**: Generate Ruby code from natural language instructions
29
- - **VCS Integration**: Full Git and Mercurial support with branch comparison
30
- - **Errbit Integration**: Analyze errors and generate actionable reports
41
+ - **AI Merge Conflict Resolution (via `n2b-diff`)**: Interactive merge conflict resolver with HTML audit logs.
42
+ - **HTML Merge Logs**: Beautiful 4-column audit trails with base/incoming/resolution/reasoning.
43
+ - **Ruby Code Generation (IRB/Console)**: Generate Ruby code from natural language.
44
+ - **VCS Integration**: Git and Mercurial support in `n2b-diff`.
45
+ - **Errbit Integration (IRB/Console)**: Analyze errors and generate reports.
46
+
47
+ ## ๐Ÿ” **AI-Powered Diff Analysis with `n2b-diff --analyze`** โšก *Beta Feature*
48
+
49
+ **Get instant, intelligent code review for every change you make.** The `n2b-diff --analyze` command provides comprehensive insights into your code changes, helping you catch issues early and maintain high code quality.
50
+
51
+ ### โœจ **What Makes It Special**
52
+
53
+ - **๐Ÿง  Context-Aware Analysis**: Understands your codebase patterns and architectural decisions
54
+ - **๐ŸŽฏ Requirements Compliance**: Automatically checks if changes meet specified requirements
55
+ - **๐Ÿ” Deep Code Review**: Identifies potential bugs, security issues, and performance problems
56
+ - **๐Ÿ’ก Smart Suggestions**: Provides actionable improvement recommendations with file/line references
57
+ - **๐Ÿ“Š Test Coverage**: Evaluates test completeness and suggests missing test scenarios
58
+ - **๐Ÿš€ Lightning Fast**: Get comprehensive analysis in seconds, not hours
59
+
60
+ ### ๐Ÿš€ **Quick Start**
61
+
62
+ ```bash
63
+ # Analyze your current changes
64
+ n2b-diff --analyze
65
+
66
+ # Compare against main branch with requirements checking and a custom message
67
+ n2b-diff --analyze --branch main --requirements requirements.md -m "Focus on security aspects"
68
+
69
+ # Full workflow with Jira integration
70
+ n2b-diff --analyze --jira PROJ-123 --update
71
+ ```
31
72
 
32
- ## ๐ŸŽฏ **Jira Integration - Get Started in 2 Minutes**
73
+ ### ๐Ÿ’ฌ **We Want Your Feedback!**
74
+
75
+ This is a **beta feature** and we're actively improving it based on real-world usage. Your feedback is invaluable! Please share your experience:
76
+
77
+ - ๐Ÿ› **Found a bug?** [Report it here](https://github.com/stefan-kp/n2b/issues)
78
+ - ๐Ÿ’ก **Have suggestions?** [Share your ideas](https://github.com/stefan-kp/n2b/discussions)
79
+ - โญ **Love it?** [Star the repo](https://github.com/stefan-kp/n2b) and spread the word!
80
+
81
+ ---
33
82
 
34
- Transform your development workflow with intelligent Jira integration:
83
+ ## ๐ŸŽฏ **Jira & GitHub Integration with `n2b-diff --analyze`**
84
+
85
+ Transform your development workflow with intelligent Jira and GitHub issue integration:
35
86
 
36
87
  ### Quick Setup
37
88
 
@@ -41,10 +92,13 @@ gem install n2b
41
92
  n2b --advanced-config # Set up Jira credentials
42
93
 
43
94
  # Test your connection
44
- n2b-test-jira
95
+ n2b-test-jira # (This command might need review if its scope changes)
45
96
 
46
97
  # Analyze code against ticket requirements
47
- n2b --diff --jira PROJ-123 --jira-update
98
+ n2b-diff --analyze --jira PROJ-123 --update
99
+
100
+ # Analyze code against GitHub issue requirements
101
+ n2b-diff --analyze --github your-org/your-repo/issues/42 --update
48
102
  ```
49
103
 
50
104
  ### What You Get
@@ -59,64 +113,215 @@ n2b --diff --jira PROJ-123 --jira-update
59
113
  ```bash
60
114
  # Working on ticket PROJ-123
61
115
  git add .
62
- n2b --diff --jira PROJ-123 --jira-update
116
+ n2b-diff --analyze --jira PROJ-123 --update
63
117
  ```
64
118
 
65
- **Result**: Your Jira ticket gets updated with a professional analysis comment showing implementation progress, technical insights, and compliance status.
119
+ **Result**: Your Jira ticket (or GitHub issue) gets updated with a professional analysis comment showing implementation progress, technical insights, and compliance status.
120
+
121
+ ## ๐Ÿ“Š **HTML Merge Logs - Professional Audit Trails**
122
+
123
+ N2B now generates beautiful HTML merge logs that provide complete audit trails of your merge conflict resolutions:
66
124
 
67
- ## ๐Ÿ” **AI-Powered Code Analysis**
125
+ ### โœจ **4-Column Layout**
126
+ - **Base Branch Code**: The code from your target branch
127
+ - **Incoming Branch Code**: The code from the branch being merged
128
+ - **Final Resolution**: The actual resolved code that was chosen
129
+ - **Resolution Details**: Method used, timestamps, and LLM reasoning
68
130
 
69
- Get comprehensive code review and insights:
131
+ ### ๐ŸŽจ **Professional Features**
132
+ - **Color-Coded Sections**: Red for base, blue for incoming, green for resolution
133
+ - **Method Badges**: Visual indicators for LLM vs Manual vs Skip vs Abort
134
+ - **Statistics Dashboard**: Total conflicts, resolved count, success rates
135
+ - **Responsive Design**: Works perfectly on desktop and mobile
136
+ - **Browser-Ready**: Open directly in any web browser
70
137
 
138
+ ### ๐Ÿ“‹ **Perfect for Teams**
139
+ - **Code Reviews**: Share merge decisions with your team
140
+ - **Compliance**: Complete audit trail for regulated environments
141
+ - **Learning**: See how AI suggestions compare to manual choices
142
+ - **Debugging**: Understand why conflicts were resolved specific ways
143
+
144
+ ### ๐Ÿš€ **Usage**
71
145
  ```bash
72
- # Analyze uncommitted changes
73
- n2b --diff
146
+ # Enable merge logging in config (if not already enabled)
147
+ n2b -c
74
148
 
75
- # Compare against specific branch with requirements
76
- n2b --diff --branch main --requirements requirements.md
149
+ # Resolve conflicts - HTML log automatically generated
150
+ n2b-diff conflicted_file.rb
77
151
 
78
- # Full workflow with Jira integration
79
- n2b --diff --jira PROJ-123 --requirements specs.md
152
+ # Find your logs
153
+ open .n2b_merge_log/2025-01-08-143022.html
80
154
  ```
81
155
 
82
- ## ๐Ÿ†• **What's New in v0.5.0**
83
-
84
- - **๐ŸŽฏ Full Jira Integration**: Real API integration with ticket fetching and automated updates
85
- - **๐Ÿ“ Structured Comments**: Beautifully formatted Jira comments with collapsible sections
86
- - **๐Ÿ” Smart Requirements Extraction**: AI identifies requirements from tickets and comments
87
- - **๐Ÿงช Connection Testing**: Built-in `n2b-test-jira` utility for troubleshooting
88
- - **๐Ÿ“‹ Permission Validation**: Verifies all required Jira API permissions
89
- - **โšก Enhanced Analysis**: Improved code review with better context and insights
156
+ ## ๐Ÿ” **AI-Powered Code Analysis & Command Translation**
157
+
158
+ N2B offers two primary commands for different aspects of your workflow:
159
+
160
+ **1. `n2b` (Natural Language to Shell Commands)**
161
+ Use `n2b` for translating your plain English (or other language) descriptions into shell commands.
162
+ ```bash
163
+ n2b "list all ruby files modified in the last 2 days"
164
+ n2b -x "create a backup of my_app.log"
165
+ ```
166
+
167
+ **2. `n2b-diff` (Merge Conflict Resolution & Diff Analysis)**
168
+ Use `n2b-diff` for AI-assisted merge conflict resolution and for detailed AI-powered analysis of your code changes (diffs).
169
+
170
+ **Diff Analysis Examples:**
171
+ ```bash
172
+ # Analyze uncommitted changes
173
+ n2b-diff --analyze
174
+
175
+ # Compare against specific branch with requirements and custom message
176
+ n2b-diff --analyze --branch main --requirements requirements.md -m "Ensure all new functions are documented."
177
+
178
+ # Full workflow with Jira integration
179
+ n2b-diff --analyze --jira PROJ-123 --requirements specs.md --update
180
+ ```
181
+
182
+ ## ๐Ÿ†• **What's New in v2.0.1 (Latest)**
183
+ * **๐Ÿ“Š HTML Merge Logs**: Beautiful 4-column audit trails with professional styling and team collaboration features
184
+ * **๐ŸŽฏ Enhanced Jira Integration**: Template-based formatting, collapsible sections, and clean professional comments
185
+ * **๐Ÿ”ง Debug Environment**: `N2B_DEBUG=true` for detailed troubleshooting when needed
186
+ * **โšก Better Context Display**: Shows surrounding code context for better conflict understanding
187
+ * **๐Ÿงช Robust Testing**: All core functionality thoroughly tested and passing
188
+
189
+ ## ๐Ÿ†• **What's New in v2.0 (Major Release)**
190
+ * **Command Restructuring**: `n2b` for command translation, `n2b-diff` for merge conflicts and all-new AI diff analysis. See [MIGRATION.md](MIGRATION.md).
191
+ * **Custom Messages for Analysis**: Guide the AI's focus during diff analysis using the `-m/--message` option with `n2b-diff --analyze`.
192
+ * **Enhanced `n2b-diff`**: Now the central hub for code analysis, supporting branches, requirements files, Jira/GitHub integration, and custom analysis instructions.
193
+
194
+ - **๐Ÿ”— GitHub Integration**: Full GitHub issue support with fetch and comment functionality
195
+ - **๐Ÿ” Enhanced AI Diff Analysis**: Comprehensive code review with context-aware insights (Beta)
196
+ - **โ˜ Interactive Jira Checklists**: Native checkboxes for team collaboration and progress tracking
197
+ - **๐ŸŽฏ Full Template Engine**: Variables, loops, conditionals for maximum customization
198
+ - **๐Ÿšจ Smart Error Classification**: Automatic severity detection (Critical/Important/Low)
199
+ - **๐Ÿ“ Editor Integration**: Open conflicted files in your preferred editor with change detection
200
+ - **๐Ÿ›ก๏ธ JSON Auto-Repair**: Automatically fixes malformed LLM responses
201
+ - **โœ… VCS Auto-Resolution**: Automatically marks resolved conflicts in Git/Mercurial
202
+ - **๐ŸŽจ Collapsible Sections**: Organized Jira comments with expand/collapse functionality
203
+ - **๐Ÿงช Comprehensive Tests**: 103+ tests ensuring bulletproof reliability
204
+ - **โšก Enhanced Context**: Full file content sent to AI for better merge decisions
205
+ - **๐Ÿ”„ Robust Error Handling**: Multiple recovery options when AI responses fail
90
206
 
91
207
  ## Installation
92
208
 
209
+ ### **Basic Installation**
210
+
211
+ ```bash
212
+ gem install n2b
213
+ ```
214
+
215
+ ### **Global Installation with rbenv**
216
+
217
+ For users with rbenv (Ruby version manager), install globally to make n2b available across all Ruby versions:
218
+
93
219
  ```bash
220
+ # Option 1: Install in system Ruby (Recommended)
221
+ rbenv global system
222
+ gem install n2b
223
+ rbenv rehash
224
+
225
+ # Option 2: Install in a dedicated Ruby version
226
+ rbenv install 3.3.0
227
+ rbenv global 3.3.0
94
228
  gem install n2b
229
+ rbenv rehash
230
+
231
+ # Verify installation works across Ruby versions
232
+ rbenv shell 3.1.0 && n2b --version
233
+ rbenv shell 3.2.0 && n2b --version
234
+ ```
235
+
236
+ ### **Fix rbenv Shim Issues**
237
+
238
+ If `n2b-diff` command is not found after installation:
239
+
240
+ ```bash
241
+ # Remove corrupted shim and regenerate
242
+ rm ~/.rbenv/shims/.rbenv-shim
243
+ rm -rf ~/.rbenv/shims/*
244
+ rbenv rehash
245
+
246
+ # Verify both commands are available
247
+ which n2b
248
+ which n2b-diff
249
+ ```
250
+
251
+ ### **Configure as Default Merge Tool**
252
+
253
+ #### **Git Integration**
254
+
255
+ Add to your `~/.gitconfig`:
256
+
257
+ ```ini
258
+ [merge]
259
+ tool = n2b-diff
260
+
261
+ [mergetool "n2b-diff"]
262
+ cmd = n2b-diff "$MERGED"
263
+ trustExitCode = true
264
+ keepBackup = false
265
+ ```
266
+
267
+ Usage:
268
+ ```bash
269
+ git merge feature-branch
270
+ # CONFLICT (content): Merge conflict in file.rb
271
+ git mergetool # Uses n2b-diff automatically
272
+ ```
273
+
274
+ #### **Mercurial (hg) Integration**
275
+
276
+ Add to your `~/.hgrc`:
277
+
278
+ ```ini
279
+ [ui]
280
+ merge = n2b-diff
281
+
282
+ [merge-tools]
283
+ n2b-diff.executable = n2b-diff
284
+ n2b-diff.args = $output
285
+ n2b-diff.premerge = keep
286
+ n2b-diff.priority = 100
287
+ ```
288
+
289
+ Usage:
290
+ ```bash
291
+ hg merge
292
+ # conflict in file.rb
293
+ # n2b-diff launches automatically
95
294
  ```
96
295
 
97
296
  ## Quick Start
98
297
 
99
- ### ๐ŸŽฏ **For Jira Users** (Most Popular)
298
+ ### ๐Ÿ” **AI-Powered Code Review (using `n2b-diff --analyze`)** (โšก Beta - Try It Now!)
100
299
 
101
300
  ```bash
102
- # Set up Jira integration
103
- n2b --advanced-config
301
+ # Get instant AI analysis of your changes
302
+ n2b-diff --analyze
104
303
 
105
- # Analyze code changes against ticket
106
- n2b --diff --jira PROJ-123 --jira-update
304
+ # Compare against main branch with requirements checking and custom message
305
+ n2b-diff --analyze --branch main --requirements specs.md -m "Check for API compatibility."
306
+
307
+ # Full workflow with Jira integration
308
+ n2b-diff --analyze --jira PROJ-123 --update
107
309
  ```
108
310
 
109
- ### ๐Ÿ” **For Code Review**
311
+ ### ๐ŸŽฏ **For Jira & GitHub Users (Code Analysis)**
110
312
 
111
313
  ```bash
112
- # AI-powered diff analysis
113
- n2b --diff
314
+ # Set up Jira/GitHub integration (done once via n2b's config)
315
+ n2b --advanced-config
316
+
317
+ # Analyze code changes against a Jira ticket
318
+ n2b-diff --analyze --jira PROJ-123 --update
114
319
 
115
- # Compare against main branch with requirements
116
- n2b --diff --branch main --requirements specs.md
320
+ # Analyze code changes against a GitHub issue
321
+ n2b-diff --analyze --github your-org/your-repo/issues/42 --update
117
322
  ```
118
323
 
119
- ### ๐Ÿ’ป **For Command Generation**
324
+ ### ๐Ÿ’ป **For Command Generation (using `n2b`)**
120
325
 
121
326
  ```bash
122
327
  # Generate bash commands
@@ -235,6 +440,56 @@ You can also set the history file location using the `N2B_HISTORY_FILE` environm
235
440
  export N2B_HISTORY_FILE=/path/to/your/history
236
441
  ```
237
442
 
443
+ ### Debug Mode
444
+
445
+ For troubleshooting Jira integration or other issues, enable debug mode:
446
+ ```bash
447
+ export N2B_DEBUG=true
448
+ n2b-diff --analyze --jira PROJ-123 --update
449
+ ```
450
+
451
+ This will show detailed information about:
452
+ - Template content generation
453
+ - API request/response details
454
+ - ADF structure for Jira comments
455
+ - Error diagnostics
456
+
457
+ ### Custom Prompt Templates
458
+
459
+ N2B uses text templates for AI prompts. To override them, specify paths in your configuration:
460
+
461
+ ```yaml
462
+ templates:
463
+ diff_system_prompt: /path/to/my_system_prompt.txt
464
+ diff_json_instruction: /path/to/my_json_instruction.txt
465
+ merge_conflict_prompt: /path/to/my_merge_prompt.txt
466
+ ```
467
+
468
+ When these paths are not provided, the built-in templates located in `lib/n2b/templates/` are used.
469
+
470
+ **Available Templates:**
471
+ - `diff_system_prompt.txt` - Main diff analysis prompt
472
+ - `diff_json_instruction.txt` - JSON formatting instructions for diff analysis
473
+ - `merge_conflict_prompt.txt` - Merge conflict resolution prompt
474
+
475
+ ### Editor Configuration
476
+
477
+ N2B allows you to configure your preferred text editor or visual diff tool for use with the `[e]` (Edit) option during merge conflict resolution. This can be set up during the advanced configuration flow (run `n2b --advanced-config` or `n2b -c` and choose to configure advanced settings).
478
+
479
+ You will be prompted to choose from a list of auto-detected editors (like `nano`, `vim`, `code` - VS Code) and diff tools (like `meld`, `kdiff3`, `vimdiff`). You can also provide a custom command.
480
+
481
+ The chosen editor is stored in your `~/.n2b/config.yml` file under the `editor` key:
482
+
483
+ ```yaml
484
+ editor:
485
+ command: "meld"
486
+ type: "diff_tool" # Can be "text_editor" or "diff_tool"
487
+ configured: true
488
+ ```
489
+
490
+ * If a **text editor** is configured, the `[e]` option will open the conflicted file directly for manual editing using the specified editor command.
491
+ * If a **diff tool** is configured, N2B will prepare temporary files for the base, incoming, and current (LLM suggested) versions of the conflict and open them in your chosen 3-way merge tool. After you've used the tool, N2B will use the content from your successfully merged file.
492
+
238
493
  ## Quick Example N2B
239
494
 
240
495
  ```
@@ -320,19 +575,39 @@ Configuration is stored in `~/.n2b/config.yml`.
320
575
 
321
576
  Basic usage:
322
577
 
323
- n2b [options] your natural language instruction
578
+ n2b [options] "your natural language instruction"
579
+
580
+ **`n2b` Options:**
581
+ - `-x`, `--execute`: Execute the translated commands after confirmation.
582
+ - `-c`, `--config`: Configure N2B (API key, model, privacy settings, etc.).
583
+ - `--advanced-config`: Access advanced configuration options.
584
+ - `-v`, `--version`: Show version information.
585
+ - `-h`, `--help`: Display help information for `n2b`.
586
+
587
+ **`n2b-diff` Command Usage:**
324
588
 
325
- Options:
326
- - `-x` or `--execute`: Execute the generated commands after confirmation
327
- - `-d` or `--diff`: Analyze git/hg diff with AI-powered code review
328
- - `-b` or `--branch [BRANCH]`: Compare against specific branch (auto-detects main/master/default)
329
- - `-r` or `--requirements FILE`: Requirements file for compliance checking
330
- - `-j` or `--jira TICKET`: Jira ticket ID or URL for context and updates
331
- - `--jira-update`: Automatically update Jira ticket with analysis (no prompt)
332
- - `--jira-no-update`: Skip Jira ticket update (analyze only)
333
- - `-c` or `--config`: Reconfigure the tool
334
- - `--advanced-config`: Advanced configuration including Jira setup
335
- - `-h` or `--help`: Display help information
589
+ `n2b-diff [FILE] [options]` (for merge conflicts)
590
+ `n2b-diff --analyze [options]` (for code diff analysis)
591
+
592
+ **`n2b-diff` Options:**
593
+ *Merge Conflict Mode (when FILE is provided and not --analyze):*
594
+ - `--context N`: Number of context lines to display around a merge conflict.
595
+ *Diff Analysis Mode (`--analyze`):*
596
+ - `-a`, `--analyze`: Activate AI-powered diff analysis.
597
+ - `--branch [BRANCH_NAME]`: Specify branch to compare against (e.g., 'main', 'develop'). Defaults to auto-detected primary branch.
598
+ - `-j`, `--jira JIRA_ID_OR_URL`: Link a Jira ticket for context or updates.
599
+ - `--github GITHUB_ISSUE_URL`: Link a GitHub issue for context or updates (e.g., 'owner/repo/issues/123').
600
+ - `-r`, `--requirements FILE_PATH`: Provide a requirements file for the AI.
601
+ - `-m`, `--message "TEXT"`: Add custom instructions for the AI analysis.
602
+ - `--update`: If -j or --github is used, attempt to update the ticket/issue with the analysis (prompts for confirmation by default unless this flag is used for auto-yes).
603
+ - `--no-update`: Prevent updating the ticket/issue.
604
+ *Common for `n2b-diff`:*
605
+ - `-h`, `--help`: Display help information for `n2b-diff`.
606
+ - `-v`, `--version`: Show version information.
607
+
608
+
609
+ **Other Commands:**
610
+ - `n2b-test-jira`: Test Jira API connection and permissions (functionality might be reviewed/updated).
336
611
 
337
612
  Examples:
338
613
 
@@ -348,36 +623,32 @@ Examples:
348
623
 
349
624
  ```n2b -c ```
350
625
 
351
- ## ๐Ÿ” AI-Powered Diff Analysis
626
+ ## ๐Ÿ” AI-Powered Diff Analysis (using `n2b-diff --analyze`)
352
627
 
353
- N2B provides comprehensive AI-powered code review for your git and mercurial repositories.
628
+ `n2b-diff --analyze` provides comprehensive AI-powered code review for your Git and Mercurial repositories.
354
629
 
355
630
  ### Basic Diff Analysis
356
631
 
357
632
  ```bash
358
- # Analyze uncommitted changes
359
- n2b --diff
360
-
361
- # Analyze changes against specific branch
362
- n2b --diff --branch main
363
- n2b --diff --branch feature/auth
633
+ # Analyze uncommitted changes (against HEAD or default compare target)
634
+ n2b-diff --analyze
364
635
 
365
- # Auto-detect default branch (main/master/default)
366
- n2b --diff --branch
636
+ # Analyze changes against a specific branch
637
+ n2b-diff --analyze --branch main
638
+ n2b-diff --analyze --branch feature/auth
367
639
 
368
- # Short form
369
- n2b -d -b main
640
+ # Auto-detect default branch (main/master/default) if --branch is provided without a value
641
+ n2b-diff --analyze --branch
370
642
  ```
371
643
 
372
- ### Requirements Compliance Checking
644
+ ### Requirements Compliance Checking & Custom Instructions
373
645
 
374
646
  ```bash
375
- # Check if changes meet requirements
376
- n2b --diff --requirements requirements.md
377
- n2b -d -r req.md
647
+ # Check if changes meet requirements from a file
648
+ n2b-diff --analyze --requirements requirements.md
378
649
 
379
- # Combine with branch comparison
380
- n2b --diff --branch main --requirements requirements.md
650
+ # Combine with branch comparison and add a custom message for the AI
651
+ n2b-diff --analyze --branch main --requirements requirements.md -m "Pay special attention to the new UserProfile class."
381
652
  ```
382
653
 
383
654
  ### What You Get
@@ -425,9 +696,9 @@ Requirements Evaluation:
425
696
  - **Git**: Full support with auto-detection of main/master branches
426
697
  - **Mercurial (hg)**: Full support with auto-detection of default branch
427
698
 
428
- ## ๐ŸŽฏ Jira Integration
699
+ ## ๐ŸŽฏ Jira & GitHub Integration (with `n2b-diff --analyze`)
429
700
 
430
- N2B provides seamless integration with Jira for automated ticket analysis and updates.
701
+ `n2b-diff --analyze` provides seamless integration with Jira and GitHub for automated ticket/issue analysis and updates.
431
702
 
432
703
  ### Setup
433
704
 
@@ -442,28 +713,40 @@ You'll need:
442
713
  - **Email**: Your Jira account email
443
714
  - **API Token**: Generate from [Atlassian Account Settings](https://id.atlassian.com/manage-profile/security/api-tokens)
444
715
 
445
- ### Required Jira Permissions
716
+ ### Required Jira API Scopes
446
717
 
447
- Your API token needs these permissions:
448
- - **Browse Projects** - Access project list
449
- - **Browse Issues** - Read ticket details
450
- - **View Comments** - Read ticket comments
451
- - **Add Comments** - Post analysis results
718
+ Your API token needs these specific scopes:
719
+
720
+ **Essential Scopes:**
721
+ - `read:project:jira` - View projects (access project list)
722
+ - `read:issue:jira` - View issues (fetch ticket details)
723
+ - `read:comment:jira` - View comments (fetch ticket comments for context)
724
+ - `write:comment:jira` - Create and update comments (post analysis results)
725
+
726
+ **Optional but Recommended:**
727
+ - `read:issue-details:jira` - View detailed issue information
728
+ - `read:issue.property:jira` - View issue properties (comprehensive ticket data)
729
+
730
+ **Legacy Permission Names (for older Jira versions):**
731
+ - Browse Projects, Browse Issues, View Comments, Add Comments
452
732
 
453
733
  ### Usage
454
734
 
455
735
  ```bash
456
736
  # Analyze code changes against Jira ticket requirements
457
- n2b --diff --jira PROJ-123
737
+ n2b-diff --analyze --jira PROJ-123
458
738
 
459
739
  # Use full Jira URL
460
- n2b --diff --jira https://company.atlassian.net/browse/PROJ-123
740
+ n2b-diff --analyze --jira https://company.atlassian.net/browse/PROJ-123
461
741
 
462
- # Auto-update ticket without prompt
463
- n2b --diff --jira PROJ-123 --jira-update
742
+ # Auto-update Jira ticket without prompt (if configured and supported by client)
743
+ n2b-diff --analyze --jira PROJ-123 --update
464
744
 
465
- # Analyze only (no ticket update)
466
- n2b --diff --jira PROJ-123 --jira-no-update
745
+ # Analyze only, do not offer to update Jira ticket
746
+ n2b-diff --analyze --jira PROJ-123 --no-update
747
+
748
+ # Analyze code changes against GitHub issue, with custom message and update
749
+ n2b-diff --analyze --github your-org/your-repo/issues/42 -m "Focus on UI changes" --update
467
750
  ```
468
751
 
469
752
  ### What It Does
@@ -534,6 +817,214 @@ This will verify:
534
817
  - Required permissions
535
818
  - Specific ticket access (if provided)
536
819
 
820
+ ## ๐Ÿ”ง **AI-Powered Merge Conflict Resolution (n2b-diff)**
821
+
822
+ Resolve Git and Mercurial merge conflicts with intelligent AI assistance.
823
+
824
+ ### Quick Start
825
+
826
+ ```bash
827
+ # Resolve conflicts in a file
828
+ n2b-diff conflicted_file.rb
829
+
830
+ # With more context lines
831
+ n2b-diff conflicted_file.rb --context 20
832
+
833
+ # Get help
834
+ n2b-diff --help
835
+ ```
836
+
837
+ ### How It Works
838
+
839
+ 1. **๐Ÿ” Detects Conflicts**: Automatically finds `<<<<<<<`, `=======`, `>>>>>>>` markers
840
+ 2. **๐Ÿ“‹ Extracts Context**: Shows surrounding code for better understanding
841
+ 3. **๐Ÿค– AI Analysis**: LLM analyzes both sides and suggests optimal merge
842
+ 4. **๐ŸŽจ Interactive Review**: Colorized display with Accept/Skip/Comment/Abort options
843
+ 5. **โœ… Applies Changes**: Updates file with accepted merges
844
+
845
+ ### Interactive Workflow
846
+
847
+ For each conflict, you can:
848
+ - **[y] Accept** - Apply the AI suggestion
849
+ - **[n] Skip** - Keep the conflict as-is
850
+ - **[c] Comment** - Add context to improve AI suggestions
851
+ - **[s] Refresh Preview** - Regenerate the HTML preview with the latest suggestion
852
+ - **[a] Abort** - Stop processing and keep file unchanged
853
+
854
+ ### Features
855
+
856
+ #### **๐ŸŒ 3-Way HTML Conflict Preview**
857
+
858
+ When resolving merge conflicts with `n2b-diff`, N2B now automatically generates a 3-way HTML preview of the conflict.
859
+
860
+ * **Automatic Opening**: The preview is automatically opened in your default web browser.
861
+ * **Terminal Link**: A clickable `file:///` link to the preview is also displayed in your terminal.
862
+ ```
863
+ ๐ŸŒ Opening conflict preview in browser...
864
+ ๐Ÿ“ Preview: file:///Users/user/.n2b_merge_log/conflict_preview_your_file.rb_20231027_103045.html
865
+
866
+ Actions: [y] Accept, [n] Skip, [c] Comment, [e] Edit, [s] Refresh Preview, [a] Abort
867
+ (Preview link above can be cmd/ctrl+clicked if your terminal supports it)
868
+ Your choice:
869
+ ```
870
+ * **Layout**: The preview features a three-column layout:
871
+ * **Base Branch**: Content from the base branch (e.g., HEAD).
872
+ * **Incoming Branch**: Content from the incoming branch (e.g., your feature branch).
873
+ * **Current Resolution**: The current LLM suggestion or your edited version, showing how the conflict would be resolved.
874
+ * **Full File View**: Each column displays the *entire* file content, with the specific conflicting lines highlighted within their context. This allows for a comprehensive understanding of the changes.
875
+ * **Syntax Highlighting**: Code is professionally syntax-highlighted using Highlight.js for improved readability across various programming languages.
876
+ * **Dynamic Updates**: The preview is regenerated and reopened if the LLM suggestion changes (e.g., after you add a comment or use the `[e]` edit option and a new suggestion is fetched) or if you use the `[s]` (Refresh Preview) option.
877
+ * **Temporary Files**: Preview files are stored temporarily in the `.n2b_merge_log/` directory and are automatically cleaned up after the conflict is resolved or skipped for that particular block.
878
+
879
+ #### **๐ŸŽจ Colorized Display**
880
+ - ๐Ÿ”ด **Red**: Base/HEAD content (`<<<<<<< HEAD`)
881
+ - ๐ŸŸข **Green**: Incoming content (`>>>>>>> feature`)
882
+ - ๐ŸŸก **Yellow**: Conflict markers (`=======`)
883
+ - ๐Ÿ”ต **Blue**: AI suggestions
884
+ - โšช **Gray**: Reasoning explanations
885
+
886
+ #### **๐Ÿค– Smart AI Analysis**
887
+ - **Context Awareness**: Understands surrounding code patterns
888
+ - **Quality Decisions**: Chooses enhanced implementations over simple ones
889
+ - **Consistency**: Maintains coding patterns and architectural decisions
890
+ - **User Feedback**: Incorporates comments to improve suggestions
891
+
892
+ #### **โš™๏ธ Configurable Options**
893
+ - **Context Lines**: `--context N` (default: 10)
894
+ - **Merge Logging**: Optional JSON logs in `.n2b_merge_log/`
895
+ - **Custom Templates**: Configurable merge prompts
896
+
897
+ ### Example Session
898
+
899
+ ```bash
900
+ $ n2b-diff user_service.rb
901
+
902
+ <<<<<<< HEAD
903
+ def create_user(name, email)
904
+ # Basic validation
905
+ raise "Invalid" if name.empty?
906
+ User.create(name: name, email: email)
907
+ end
908
+ =======
909
+ def create_user(name, email, age = nil)
910
+ # Enhanced validation
911
+ validate_name(name)
912
+ validate_email(email)
913
+ User.create(name: name.titleize, email: email.downcase, age: age)
914
+ end
915
+ >>>>>>> feature/enhanced-validation
916
+
917
+ --- Suggestion ---
918
+ def create_user(name, email, age = nil)
919
+ # Enhanced validation with fallback
920
+ validate_name(name) if respond_to?(:validate_name)
921
+ validate_email(email) if respond_to?(:validate_email)
922
+ User.create(name: name.titleize, email: email.downcase, age: age)
923
+ end
924
+
925
+ Reason: Combined enhanced validation from feature branch with safety checks
926
+ for method existence, maintaining backward compatibility while adding new features.
927
+
928
+ Accept [y], Skip [n], Comment [c], Abort [a]: y
929
+ ```
930
+
931
+ ### Custom Templates
932
+
933
+ Customize merge prompts by adding to your config:
934
+
935
+ ```yaml
936
+ templates:
937
+ merge_conflict_prompt: /path/to/my_merge_prompt.txt
938
+ ```
939
+
940
+ Template variables available:
941
+ - `{full_file_content}` - Complete file content for full context understanding
942
+ - `{context_before}` - Code before the conflict
943
+ - `{context_after}` - Code after the conflict
944
+ - `{base_label}` - Base branch label (e.g., "HEAD")
945
+ - `{base_content}` - Base branch content
946
+ - `{incoming_label}` - Incoming branch label (e.g., "feature/auth")
947
+ - `{incoming_content}` - Incoming branch content
948
+ - `{user_comment}` - User-provided comment (if any)
949
+
950
+ ### Use Cases
951
+
952
+ - **Feature Branch Merges**: Resolve conflicts when merging feature branches
953
+ - **Code Reviews**: Get AI assistance for complex merge decisions
954
+ - **Refactoring**: Handle conflicts during large refactoring efforts
955
+ - **Team Collaboration**: Standardize merge conflict resolution approaches
956
+ - **Learning Tool**: Understand best practices for conflict resolution
957
+
958
+ ### **Daily Workflow Integration**
959
+
960
+ #### **Git Workflow**
961
+ ```bash
962
+ # During merge conflicts
963
+ git merge feature-branch
964
+ # CONFLICT (content): Merge conflict in file.rb
965
+
966
+ # Use configured merge tool
967
+ git mergetool
968
+
969
+ # Or call directly
970
+ n2b-diff file.rb
971
+
972
+ # Continue merge
973
+ git add file.rb
974
+ git commit -m "Resolve merge conflicts"
975
+ ```
976
+
977
+ #### **Mercurial Workflow**
978
+ ```bash
979
+ # During hg merge conflicts
980
+ hg merge
981
+ # conflict in file.rb
982
+
983
+ # Resolve with n2b-diff (auto-launches if configured)
984
+ n2b-diff file.rb
985
+
986
+ # Mark as resolved and commit
987
+ hg resolve --mark file.rb
988
+ hg commit -m "Resolve merge conflicts"
989
+ ```
990
+
991
+ #### **Rebase Conflicts**
992
+ ```bash
993
+ # Git rebase conflicts
994
+ git rebase -i main
995
+ # CONFLICT: Merge conflict in user_service.rb
996
+
997
+ n2b-diff user_service.rb
998
+ git add user_service.rb
999
+ git rebase --continue
1000
+ ```
1001
+
1002
+ #### **Batch Conflict Resolution**
1003
+ ```bash
1004
+ # Find and resolve all conflicts
1005
+ find . -name "*.rb" -exec grep -l "<<<<<<< HEAD" {} \; | while read file; do
1006
+ echo "Resolving conflicts in $file"
1007
+ n2b-diff "$file"
1008
+ done
1009
+ ```
1010
+
1011
+ #### **Shell Aliases for Convenience**
1012
+ Add to your `.zshrc` or `.bashrc`:
1013
+ ```bash
1014
+ # Quick aliases for n2b tools
1015
+ alias resolve-conflicts='n2b-diff' # For merge conflicts
1016
+ alias test-jira='n2b-test-jira' # For testing Jira connection
1017
+ alias ai-diff='n2b-diff --analyze' # For AI diff analysis
1018
+
1019
+ # Function to resolve all conflict files
1020
+ resolve-all-conflicts() {
1021
+ find . -name "*.rb" -exec grep -l "<<<<<<< HEAD" {} \; | while read file; do
1022
+ echo "Resolving conflicts in $file"
1023
+ n2b-diff "$file"
1024
+ done
1025
+ }
1026
+ ```
1027
+
537
1028
  n2r in ruby or rails console
538
1029
  n2r "your question", files:['file1.rb', 'file2.rb'], exception: AnError
539
1030
  only question is mandatory
@@ -595,24 +1086,57 @@ This project is licensed under the MIT License.
595
1086
 
596
1087
  ## Version History
597
1088
 
598
- ### ๐Ÿš€ **v0.5.0 - Jira Integration & Enhanced Analysis**
599
- - Full Jira API integration with real ticket fetching and comment posting
600
- - Structured Jira comments using ADF with collapsible sections
601
- - Smart requirements extraction from ticket descriptions and comments
602
- - Built-in connection testing with `n2b-test-jira` utility
603
- - Enhanced configuration validation and error handling
1089
+ ### โœจ **v2.0.0 (Planned) - Command Restructure & Enhanced Diff Analysis**
1090
+ - **Command Restructuring**: `n2b` is now for natural language to shell command translation only. `n2b-diff` handles merge conflicts and all AI-powered diff/code analysis. See [MIGRATION.md](MIGRATION.md).
1091
+ - **Enhanced `n2b-diff --analyze`**:
1092
+ - Added `--github` option for GitHub Issue integration (fetching details, updating issues).
1093
+ - Added `-m, --message, --msg` option for providing custom instructions to the AI during diff analysis.
1094
+ - Streamlined Jira integration options (`--jira`, `--update`, `--no-update`).
1095
+ - Diff analysis features (branch comparison, requirements files) now exclusively under `n2b-diff --analyze`.
1096
+ - **Documentation Overhaul**: Updated README, help texts, and added `MIGRATION.md`.
1097
+ - **Test Suite Updates**: Refactored tests for `n2b` and significantly enhanced tests for `n2b-diff`.
1098
+ - **Internal Refinements**: Created `N2B::MessageUtils` for message handling.
1099
+
1100
+ ### ๐Ÿ”ง **v0.7.2 - GitHub Integration & Enhanced AI Diff Analysis (as `n2b --diff`)** (Pre-Restructure)
1101
+ - **๐Ÿ”— GitHub Integration**: Full GitHub issue support with fetch and comment functionality
1102
+ - **๐Ÿ” Enhanced AI Diff Analysis**: Comprehensive code review with context-aware insights (Beta)
1103
+ - **โ˜ Interactive Jira Checklists**: Native checkboxes for team collaboration and progress tracking
1104
+ - **๐ŸŽฏ Full Template Engine**: Variables, loops, conditionals for maximum customization
1105
+ - **๐Ÿšจ Smart Error Classification**: Automatic severity detection (Critical/Important/Low)
1106
+ - **๐Ÿ“ Editor Integration**: Open conflicted files in your preferred editor with change detection
1107
+ - **๐Ÿ›ก๏ธ JSON Auto-Repair**: Automatically fixes malformed LLM responses
1108
+ - **โœ… VCS Auto-Resolution**: Automatically marks resolved conflicts in Git/Mercurial
1109
+ - **๐ŸŽจ Collapsible Sections**: Organized Jira comments with expand/collapse functionality
1110
+ - **๐Ÿงช Comprehensive Tests**: 103+ tests ensuring bulletproof reliability
1111
+ - **โšก Enhanced Context**: Full file content sent to AI for better merge decisions
1112
+ - **๐Ÿ”„ Robust Error Handling**: Multiple recovery options when AI responses fail
1113
+
1114
+
1115
+ ### ๐Ÿ”ง **v0.5.4 - AI-Powered Merge Conflict Resolver (Introducing `n2b-diff`)**
1116
+ - **NEW: n2b-diff command** - Interactive AI-powered merge conflict resolution.
1117
+ - Colorized conflict display with Accept/Skip/Comment/Abort workflow.
1118
+ - Smart AI suggestions with detailed reasoning and user feedback integration.
1119
+ - Custom templates for merge prompts and configurable context lines.
1120
+ - Merge logging and Git/Mercurial support.
1121
+
1122
+ ### ๐Ÿš€ **v0.5.0 - Jira Integration & Enhanced Analysis (as `n2b --diff`)**
1123
+ - Full Jira API integration with real ticket fetching and comment posting.
1124
+ - Structured Jira comments using ADF with collapsible sections.
1125
+ - Smart requirements extraction from ticket descriptions and comments.
1126
+ - Built-in connection testing with `n2b-test-jira` utility.
1127
+ - Enhanced configuration validation and error handling.
604
1128
 
605
1129
  ### ๐Ÿ”ง **v0.4.0 - Flexible Model Configuration**
606
- - Multiple LLM providers: Claude, OpenAI, Gemini, OpenRouter, Ollama
607
- - Custom model support for fine-tunes and beta releases
608
- - Latest models: OpenAI O3/O4 series, Gemini 2.5, Claude Sonnet 4.0
609
- - Backward compatible configuration system
610
-
611
- ### ๐Ÿ” **v0.3.0 - AI-Powered Diff Analysis**
612
- - Git/Mercurial diff analysis with context extraction
613
- - Requirements compliance checking
614
- - Test coverage assessment
615
- - Branch comparison with auto-detection
1130
+ - Multiple LLM providers: Claude, OpenAI, Gemini, OpenRouter, Ollama.
1131
+ - Custom model support for fine-tunes and beta releases.
1132
+ - Latest models: OpenAI O3/O4 series, Gemini 2.5, Claude Sonnet 4.0.
1133
+ - Backward compatible configuration system.
1134
+
1135
+ ### ๐Ÿ” **v0.3.0 - AI-Powered Diff Analysis (as `n2b --diff`)**
1136
+ - Git/Mercurial diff analysis with context extraction.
1137
+ - Requirements compliance checking.
1138
+ - Test coverage assessment.
1139
+ - Branch comparison with auto-detection.
616
1140
 
617
1141
  ## Support
618
1142