n2b 0.7.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.
- checksums.yaml +4 -4
- data/README.md +291 -118
- data/bin/branch-audit.sh +397 -0
- data/bin/n2b-test-github +22 -0
- data/lib/n2b/base.rb +207 -37
- data/lib/n2b/cli.rb +53 -400
- data/lib/n2b/github_client.rb +391 -0
- data/lib/n2b/jira_client.rb +236 -37
- data/lib/n2b/llm/claude.rb +1 -1
- data/lib/n2b/llm/gemini.rb +1 -1
- data/lib/n2b/llm/open_ai.rb +1 -1
- data/lib/n2b/merge_cli.rb +1771 -136
- data/lib/n2b/message_utils.rb +59 -0
- data/lib/n2b/templates/diff_system_prompt.txt +40 -20
- data/lib/n2b/templates/github_comment.txt +67 -0
- data/lib/n2b/templates/jira_comment.txt +7 -0
- data/lib/n2b/templates/merge_conflict_prompt.txt +2 -2
- data/lib/n2b/version.rb +1 -1
- metadata +8 -3
@@ -0,0 +1,59 @@
|
|
1
|
+
module N2B
|
2
|
+
module MessageUtils
|
3
|
+
MAX_MESSAGE_LENGTH = 500
|
4
|
+
TRUNCATION_NOTICE = "... (truncated)"
|
5
|
+
|
6
|
+
# Validates the message length.
|
7
|
+
# Truncates if it exceeds MAX_MESSAGE_LENGTH.
|
8
|
+
def self.validate_message(message_str)
|
9
|
+
return nil if message_str.nil?
|
10
|
+
# Ensure message is a string before calling length
|
11
|
+
message = String(message_str)
|
12
|
+
if message.length > MAX_MESSAGE_LENGTH
|
13
|
+
return message[0...(MAX_MESSAGE_LENGTH - TRUNCATION_NOTICE.length)] + TRUNCATION_NOTICE
|
14
|
+
end
|
15
|
+
message
|
16
|
+
end
|
17
|
+
|
18
|
+
# Performs basic sanitization on the message.
|
19
|
+
def self.sanitize_message(message_str)
|
20
|
+
return nil if message_str.nil?
|
21
|
+
message = String(message_str) # Ensure it's a string
|
22
|
+
|
23
|
+
# Strip leading/trailing whitespace
|
24
|
+
sanitized = message.strip
|
25
|
+
|
26
|
+
# Replace triple backticks with single backticks to prevent code block formatting issues in prompts
|
27
|
+
sanitized.gsub!('```', '`')
|
28
|
+
|
29
|
+
# Remove multiple consecutive newlines, leaving only single newlines
|
30
|
+
# This helps prevent prompt injection or excessive spacing.
|
31
|
+
sanitized.gsub!(/\n{2,}/, "\n")
|
32
|
+
|
33
|
+
# Example: Escape specific control characters if needed, e.g., null bytes
|
34
|
+
# sanitized.gsub!(/\x00/, '') # Remove null bytes
|
35
|
+
|
36
|
+
# Add more sanitization rules here as needed, e.g.:
|
37
|
+
# - Removing or escaping other characters that might break formatting or cause security issues.
|
38
|
+
# - For now, keeping it relatively simple.
|
39
|
+
|
40
|
+
sanitized
|
41
|
+
end
|
42
|
+
|
43
|
+
# Logs the message to STDOUT.
|
44
|
+
# level can be :info, :debug, :warn, :error
|
45
|
+
def self.log_message(message, level = :info)
|
46
|
+
return if message.nil? || message.strip.empty?
|
47
|
+
|
48
|
+
prefix = case level
|
49
|
+
when :debug then "[N2B Message DEBUG]"
|
50
|
+
when :warn then "[N2B Message WARN]"
|
51
|
+
when :error then "[N2B Message ERROR]"
|
52
|
+
else "[N2B Message INFO]" # Default to info
|
53
|
+
end
|
54
|
+
|
55
|
+
output_stream = (level == :error || level == :warn) ? $stderr : $stdout
|
56
|
+
output_stream.puts "#{prefix} #{message}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,23 +1,43 @@
|
|
1
|
+
|
1
2
|
You are a senior software developer reviewing a code diff.
|
3
|
+
|
2
4
|
Your task is to provide a constructive and detailed analysis of the changes.
|
3
5
|
Focus on identifying potential bugs, suggesting improvements in code quality, style, performance, and security.
|
4
|
-
Also, provide a concise summary of the changes.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
This helps
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
6
|
+
Also, provide a concise summary of the changes at the beginning.
|
7
|
+
|
8
|
+
Important guidelines for your review:
|
9
|
+
• When referring to specific issues or improvements, always include:
|
10
|
+
• The exact file path (e.g., lib/n2b/cli.rb)
|
11
|
+
• The specific line numbers or line ranges (e.g., “line 42” or “lines 15-20”)
|
12
|
+
• The exact code snippet you’re referring to when possible
|
13
|
+
This helps the recipient quickly locate and understand the issues you identify.
|
14
|
+
• Be pragmatic and balanced:
|
15
|
+
• Highlight genuinely critical issues, but avoid excessive speculation or alarmism.
|
16
|
+
• Only flag a security or architectural problem as high-priority if there is clear evidence or reasonable suspicion based on the diff and provided context.
|
17
|
+
• If you notice patterns that could be problematic (e.g., use of deprecated libraries or unclear data handling), mention them, but avoid assuming issues in unseen code unless the context clearly suggests a risk.
|
18
|
+
• Limit your review to the provided context:
|
19
|
+
• Do not assume missing methods or classes are absent or incorrectly implemented if they are simply not visible in the diff.
|
20
|
+
• Focus your analysis on the code changes and their direct surroundings.
|
21
|
+
• If code relies on methods or classes not included in the diff, you can briefly note that the implementation or contract is not visible, but do not speculate about their correctness unless the usage is clearly problematic.
|
22
|
+
|
23
|
+
Special Focus: Test Coverage
|
24
|
+
• Pay special attention to whether the developer has provided adequate test coverage for the changes:
|
25
|
+
• Look for new test files or modifications to existing test files.
|
26
|
+
• Check if new functionality is covered by corresponding tests.
|
27
|
+
• Evaluate if edge cases and error conditions are tested.
|
28
|
+
• Assess if the tests are meaningful and comprehensive.
|
29
|
+
• Note any missing test coverage that should reasonably be added.
|
30
|
+
|
31
|
+
Tone and Focus
|
32
|
+
• Be clear, direct, and actionable, but keep a professional and supportive tone.
|
33
|
+
• Prioritize feedback on issues that would materially affect the codebase, such as maintainability, correctness, reliability, and realistic security concerns.
|
34
|
+
• Encourage improvements, but avoid nitpicking on trivial or subjective style points unless they significantly affect readability or consistency.
|
35
|
+
|
36
|
+
⸻
|
37
|
+
|
38
|
+
Summary:
|
39
|
+
Provide a balanced, practical review of the visible code diff, focusing on genuine issues and actionable improvements. Avoid speculation about unseen code, and maintain a pragmatic and professional approach, especially regarding potential security concerns and architectural risks.
|
40
|
+
|
41
|
+
⸻
|
42
|
+
|
43
|
+
Let me know if you want any additional points, or further simplification!
|
@@ -0,0 +1,67 @@
|
|
1
|
+
### N2B Code Analysis Report
|
2
|
+
|
3
|
+
**Implementation Summary**
|
4
|
+
{implementation_summary}
|
5
|
+
|
6
|
+
{{#if custom_analysis_focus}}
|
7
|
+
---
|
8
|
+
|
9
|
+
**Custom Analysis Focus**
|
10
|
+
> {{custom_analysis_focus}}
|
11
|
+
{{/if}}
|
12
|
+
---
|
13
|
+
|
14
|
+
{#if critical_errors_empty}
|
15
|
+
_No critical issues found._
|
16
|
+
{#else}
|
17
|
+
**Critical Issues**
|
18
|
+
{#each critical_errors}
|
19
|
+
- {file_reference} - {description}
|
20
|
+
{/each}
|
21
|
+
{/if}
|
22
|
+
|
23
|
+
{#if important_errors_empty}
|
24
|
+
_No important issues found._
|
25
|
+
{#else}
|
26
|
+
**Important Issues**
|
27
|
+
{#each important_errors}
|
28
|
+
- {file_reference} - {description}
|
29
|
+
{/each}
|
30
|
+
{/if}
|
31
|
+
|
32
|
+
{#if improvements_empty}
|
33
|
+
_No suggested improvements._
|
34
|
+
{#else}
|
35
|
+
**Improvements**
|
36
|
+
{#each improvements}
|
37
|
+
- {file_reference} - {description}
|
38
|
+
{/each}
|
39
|
+
{/if}
|
40
|
+
|
41
|
+
{#if missing_tests_empty}
|
42
|
+
_No missing tests identified._
|
43
|
+
{#else}
|
44
|
+
**Missing Tests**
|
45
|
+
{#each missing_tests}
|
46
|
+
- {description}
|
47
|
+
{/each}
|
48
|
+
{/if}
|
49
|
+
|
50
|
+
**Requirements Status**
|
51
|
+
{#each requirements}
|
52
|
+
{#if status == 'IMPLEMENTED'}
|
53
|
+
- ✅ {description}
|
54
|
+
{/if}
|
55
|
+
{#if status == 'PARTIALLY_IMPLEMENTED'}
|
56
|
+
- ⚠️ {description}
|
57
|
+
{/if}
|
58
|
+
{#if status == 'NOT_IMPLEMENTED'}
|
59
|
+
- ❌ {description}
|
60
|
+
{/if}
|
61
|
+
{#if status == 'UNCLEAR'}
|
62
|
+
- 🔍 {description}
|
63
|
+
{/if}
|
64
|
+
{/each}
|
65
|
+
|
66
|
+
*Generated on {timestamp} | Branch: {branch_name} | Files changed: {files_changed} | Lines: +{lines_added} -{lines_removed}*
|
67
|
+
|
@@ -3,7 +3,7 @@ You are a merge assistant. Combine the following conflict into a single version
|
|
3
3
|
FULL FILE CONTENT FOR CONTEXT:
|
4
4
|
{full_file_content}
|
5
5
|
|
6
|
-
CONFLICT TO RESOLVE:
|
6
|
+
CONFLICT TO RESOLVE (Lines {start_line}-{end_line}):
|
7
7
|
Context before:
|
8
8
|
{context_before}
|
9
9
|
|
@@ -17,4 +17,4 @@ Context after:
|
|
17
17
|
{context_after}
|
18
18
|
{user_comment}
|
19
19
|
|
20
|
-
Respond in JSON with keys "merged_code" and "reason".
|
20
|
+
Respond in JSON with keys "merged_code" and "reason". In your reason, reference the specific line numbers ({start_line}-{end_line}) that were affected by the conflict resolution.
|
data/lib/n2b/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: n2b
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Nothegger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-06-
|
11
|
+
date: 2025-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -81,14 +81,17 @@ extensions: []
|
|
81
81
|
extra_rdoc_files: []
|
82
82
|
files:
|
83
83
|
- README.md
|
84
|
+
- bin/branch-audit.sh
|
84
85
|
- bin/n2b
|
85
86
|
- bin/n2b-diff
|
87
|
+
- bin/n2b-test-github
|
86
88
|
- bin/n2b-test-jira
|
87
89
|
- lib/n2b.rb
|
88
90
|
- lib/n2b/base.rb
|
89
91
|
- lib/n2b/cli.rb
|
90
92
|
- lib/n2b/config/models.yml
|
91
93
|
- lib/n2b/errors.rb
|
94
|
+
- lib/n2b/github_client.rb
|
92
95
|
- lib/n2b/irb.rb
|
93
96
|
- lib/n2b/jira_client.rb
|
94
97
|
- lib/n2b/llm/claude.rb
|
@@ -98,10 +101,12 @@ files:
|
|
98
101
|
- lib/n2b/llm/open_router.rb
|
99
102
|
- lib/n2b/merge_cli.rb
|
100
103
|
- lib/n2b/merge_conflict_parser.rb
|
104
|
+
- lib/n2b/message_utils.rb
|
101
105
|
- lib/n2b/model_config.rb
|
102
106
|
- lib/n2b/template_engine.rb
|
103
107
|
- lib/n2b/templates/diff_json_instruction.txt
|
104
108
|
- lib/n2b/templates/diff_system_prompt.txt
|
109
|
+
- lib/n2b/templates/github_comment.txt
|
105
110
|
- lib/n2b/templates/jira_comment.txt
|
106
111
|
- lib/n2b/templates/merge_conflict_prompt.txt
|
107
112
|
- lib/n2b/version.rb
|
@@ -128,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
133
|
- !ruby/object:Gem::Version
|
129
134
|
version: '0'
|
130
135
|
requirements: []
|
131
|
-
rubygems_version: 3.5.
|
136
|
+
rubygems_version: 3.5.3
|
132
137
|
signing_key:
|
133
138
|
specification_version: 4
|
134
139
|
summary: AI-powered development toolkit with merge conflict resolution and Jira integration
|