internator 0.1.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +43 -0
- data/bin/internator +10 -0
- data/internator.gemspec +17 -0
- data/lib/internator/cli.rb +135 -0
- data/lib/internator/codex_service.rb +24 -0
- data/lib/internator/version.rb +3 -0
- data/lib/internator.rb +6 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e4ae44204ee0786b5dd4ed826a8daf69534ade2353a655f7c196a39b0f6d017b
|
4
|
+
data.tar.gz: f4cac1536e6d5eeabd7cefe3313cdf5b2c9a39306ebfef4fd520913e04b65c3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f8e353a5520663e029c550d3f0bab96bfedadb28fd85737cd6fd688f072b5aed04a1e79b1027e1ca39012a5fad50617f78014f53e262f7193c2ff3a7b38b7da
|
7
|
+
data.tar.gz: 31c4a19ef58ca781139367b6638fc1181f13bccccadbac7c148b0b3b75f7ca2f012cf565cca15776b118052155fab20978442117feceadb4473d127e98353c15
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 AlexLarra
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Internator
|
2
|
+
|
3
|
+
Internator is a Ruby-based CLI tool that automates iterative pull request improvements using OpenAI's Codex. It cycles through objectives, makes incremental changes, automatically commits and pushes each update, and optionally waits between iterations.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
- Ruby (>= 2.5)
|
8
|
+
- [Codex CLI](https://github.com/openai/codex) installed and in your PATH
|
9
|
+
- Environment variable `OPENAI_API_KEY` set to your OpenAI API key
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install internator
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Run the `internator` command:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
internator "<PR Objectives>" [delay_mins]
|
23
|
+
```
|
24
|
+
|
25
|
+
- `<PR Objectives>`: Description of what the pull request should achieve.
|
26
|
+
- `[delay_mins]`: (Optional) Minutes to wait between iterations (default: 0).
|
27
|
+
|
28
|
+
Example:
|
29
|
+
```bash
|
30
|
+
internator "Refactor authentication flow and add tests" 10
|
31
|
+
```
|
32
|
+
## Tmux
|
33
|
+
|
34
|
+
If you use tmux ensure `OPENAI_API_KEY` is forwarded into tmux sessions. Add the following to your `~/.tmux.conf`:
|
35
|
+
|
36
|
+
```tmux
|
37
|
+
# Ensure OPENAI_API_KEY is passed into tmux sessions if you use it.
|
38
|
+
set -g update-environment "OPENAI_API_KEY"
|
39
|
+
set-environment -g OPENAI_API_KEY "#{ENV:OPENAI_API_KEY}"
|
40
|
+
```
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Feel free to open issues or submit pull requests.
|
data/bin/internator
ADDED
data/internator.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative "lib/internator/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "internator"
|
5
|
+
spec.version = Internator::VERSION
|
6
|
+
spec.authors = ["AlexLarra"]
|
7
|
+
spec.email = ["clausrybnic@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "CLI tool that automates iterative pull request improvements using OpenAI's Codex"
|
10
|
+
spec.description = "Internator cycles through objectives, makes incremental changes, commits via your shell functions, and optionally waits between iterations."
|
11
|
+
spec.homepage = "https://github.com/your-username/internator"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = Dir.glob("lib/**/*.rb") + ["README.md", "LICENSE", "internator.gemspec", "bin/internator"]
|
15
|
+
spec.executables = ["internator"]
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require "internator/codex_service"
|
2
|
+
require "net/http"
|
3
|
+
require "uri"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Internator
|
7
|
+
# Command-line interface for the Internator gem
|
8
|
+
class CLI
|
9
|
+
def self.run(args = ARGV)
|
10
|
+
unless system("which codex > /dev/null 2>&1")
|
11
|
+
abort "❌ 'codex' CLI is not installed or not in PATH. Please install it from https://github.com/openai/codex"
|
12
|
+
end
|
13
|
+
|
14
|
+
if ENV["OPENAI_API_KEY"].to_s.strip.empty?
|
15
|
+
abort "❌ OPENAI_API_KEY not set. Please set the environment variable."
|
16
|
+
end
|
17
|
+
|
18
|
+
if args.empty? || args.size > 2
|
19
|
+
abort "❌ Usage: internator \"<PR Objectives>\" [delay_mins]"
|
20
|
+
end
|
21
|
+
|
22
|
+
objectives = args[0]
|
23
|
+
delay_mins = if args[1]
|
24
|
+
Integer(args[1]) rescue abort("❌ Invalid delay_mins: must be an integer")
|
25
|
+
else
|
26
|
+
0
|
27
|
+
end
|
28
|
+
|
29
|
+
iteration = 1
|
30
|
+
Signal.trap("INT") do
|
31
|
+
puts "\n🛑 Interrupt received. Exiting cleanly..."
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
loop do
|
37
|
+
puts "\n🌀 Iteration ##{iteration} - #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
38
|
+
exit_code = codex_cycle(objectives, iteration)
|
39
|
+
if exit_code != 0
|
40
|
+
puts "🚨 Codex process exited with code #{exit_code}. Stopping."
|
41
|
+
break
|
42
|
+
end
|
43
|
+
|
44
|
+
if `git status --porcelain`.strip.empty?
|
45
|
+
puts "🎉 Objectives completed; no new changes. Exiting loop..."
|
46
|
+
break
|
47
|
+
end
|
48
|
+
|
49
|
+
auto_commit
|
50
|
+
puts "⏳ Waiting #{delay_mins} minutes for next iteration... Current time: #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
51
|
+
sleep(delay_mins * 60)
|
52
|
+
iteration += 1
|
53
|
+
end
|
54
|
+
rescue => e
|
55
|
+
puts "🚨 Critical error: #{e.message}"
|
56
|
+
ensure
|
57
|
+
puts "\n🏁 Process completed - #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.codex_cycle(objectives, iteration)
|
62
|
+
current_diff = `git diff master 2>/dev/null`
|
63
|
+
current_diff = "No initial changes" if current_diff.strip.empty?
|
64
|
+
prompt = <<~PROMPT
|
65
|
+
Objectives: #{objectives}
|
66
|
+
Iteration: #{iteration}
|
67
|
+
Current Pull Request: #{current_diff}
|
68
|
+
|
69
|
+
Instructions:
|
70
|
+
1. If there are changes in the PR, first check if it has already been completed; if so, do nothing.
|
71
|
+
2. Make ONLY one incremental change.
|
72
|
+
3. Prioritize completing main objectives.
|
73
|
+
4. Do not overuse code comments; if the method name says it all, comments are not necessary.
|
74
|
+
5. Do not add a blank line at the end of each file.
|
75
|
+
PROMPT
|
76
|
+
|
77
|
+
CodexService.new(prompt).call
|
78
|
+
end
|
79
|
+
|
80
|
+
# Generate a concise commit message for the given diff using OpenAI
|
81
|
+
def self.generate_commit_message(diff)
|
82
|
+
api_key = ENV["OPENAI_API_KEY"]
|
83
|
+
uri = URI("https://api.openai.com/v1/chat/completions")
|
84
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
85
|
+
http.use_ssl = true
|
86
|
+
headers = {
|
87
|
+
"Content-Type" => "application/json",
|
88
|
+
"Authorization" => "Bearer #{api_key}"
|
89
|
+
}
|
90
|
+
body = {
|
91
|
+
model: "gpt-4o-mini",
|
92
|
+
messages: [
|
93
|
+
{ role: "system", content: "You are a helpful assistant that generates concise git commit messages." },
|
94
|
+
{ role: "user", content: "Generate a concise commit message for the following diff:\n\n#{diff}" }
|
95
|
+
],
|
96
|
+
temperature: 0.3
|
97
|
+
}
|
98
|
+
response = http.post(uri.request_uri, JSON.generate(body), headers)
|
99
|
+
if response.is_a?(Net::HTTPSuccess)
|
100
|
+
json = JSON.parse(response.body)
|
101
|
+
msg = json.dig("choices", 0, "message", "content")
|
102
|
+
return msg.strip if msg
|
103
|
+
end
|
104
|
+
rescue
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
|
108
|
+
def auto_commit
|
109
|
+
system('git', 'add', '-A')
|
110
|
+
status = `git diff --cached --name-status`
|
111
|
+
content = `git diff --cached`
|
112
|
+
diff = "File status:\n#{status}\n\nDiff:\n#{content}"
|
113
|
+
commit_msg = generate_commit_message(diff) || ''
|
114
|
+
|
115
|
+
# Write full commit message to a temp file and commit via -F
|
116
|
+
Tempfile.create('internator-commit') do |file|
|
117
|
+
file.write(commit_msg)
|
118
|
+
file.flush
|
119
|
+
file.close
|
120
|
+
if system('git', 'commit', '-F', file.path)
|
121
|
+
first_line = commit_msg.lines.first.to_s.strip
|
122
|
+
puts "✅ Commit made: #{first_line}"
|
123
|
+
else
|
124
|
+
puts "❌ Error committing"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
if system('git', 'push')
|
129
|
+
puts "✅ Push successful"
|
130
|
+
else
|
131
|
+
puts "❌ Error pushing to remote"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Internator
|
2
|
+
# Service for executing the Codex CLI with full-auto mode
|
3
|
+
class CodexService
|
4
|
+
# @param instruction [String] Text instruction for Codex
|
5
|
+
def initialize(instruction)
|
6
|
+
@instruction = instruction
|
7
|
+
end
|
8
|
+
|
9
|
+
# Executes `codex --full-auto` with the provided instruction.
|
10
|
+
# @return [Integer] Exit code of the Codex process
|
11
|
+
def call
|
12
|
+
command = [
|
13
|
+
"codex",
|
14
|
+
"--full-auto",
|
15
|
+
"--quiet",
|
16
|
+
"--writable-root", Dir.pwd,
|
17
|
+
"--full-stdout",
|
18
|
+
@instruction
|
19
|
+
]
|
20
|
+
system(*command)
|
21
|
+
$?.exitstatus
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/internator.rb
ADDED
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: internator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- AlexLarra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-06-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Internator cycles through objectives, makes incremental changes, commits
|
14
|
+
via your shell functions, and optionally waits between iterations.
|
15
|
+
email:
|
16
|
+
- clausrybnic@gmail.com
|
17
|
+
executables:
|
18
|
+
- internator
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- bin/internator
|
25
|
+
- internator.gemspec
|
26
|
+
- lib/internator.rb
|
27
|
+
- lib/internator/cli.rb
|
28
|
+
- lib/internator/codex_service.rb
|
29
|
+
- lib/internator/version.rb
|
30
|
+
homepage: https://github.com/your-username/internator
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubygems_version: 3.4.10
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: CLI tool that automates iterative pull request improvements using OpenAI's
|
53
|
+
Codex
|
54
|
+
test_files: []
|