jeeves-git-commit 3.1.1 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bf456f354f172b140a241db27b10459ae17c6b96748f3cab435f5dd7024c6ad
4
- data.tar.gz: d8764cc9556d4b8e3d220310c43ec7163fa6195e959445240025d7ab94a9ae4d
3
+ metadata.gz: b19331ff70859069a8be98d8ea0347453ef0be84a2addf6f6fd8f6f466493857
4
+ data.tar.gz: c96d7b88ba16998b39462f441a17ba8f86b86a13b09fa4db63af3dc150cd9c0e
5
5
  SHA512:
6
- metadata.gz: 36df36dafc54fd9a2c609d238417f2f8740e7090c255590a84aa87da755726e63a5745f7fc0e8e64653c934f3b3beb3b8417e8f92c388cba2bce43c41c689b6a
7
- data.tar.gz: 50077793c804ab2d87e6681b3c07f18ee4be560487c628b9fa249d6bce4c66a58a50eb3beb4ffbce267e1303deeb5fc8cf1c818fea2cf782d4986f6e994b3dfe
6
+ metadata.gz: 9b83c92129037c0addbc963cc09f0fb366f632c9bd02011af89aa5905a51a376a40072aa670b3712f1125d94e9bfc6ad17a68117d2d5e8d55d76d4794b13d15a
7
+ data.tar.gz: 3de948cdf19bb08a7dc291dd74199144f413b1c91ee4e059b8a0609f223bd83e6c145eaa14b63918a12e8f7019833e487a1283731f22431ad53f4352a2ff948d
data/README.md CHANGED
@@ -4,8 +4,8 @@
4
4
  <img src="assets/jeeves.png" alt="Jeeves Logo" width="200">
5
5
  </p>
6
6
 
7
- Jeeves creates Git commit messages from your changes using OpenRouter or a
8
- local Ollama model. The bundled prompt adds gitmoji and a sarcastic roast of
7
+ Jeeves creates Git commit messages from your changes using OpenRouter, the
8
+ Anthropic API, or a local Ollama model. The bundled prompt adds gitmoji and a sarcastic roast of
9
9
  your engineering choices. Your own prompt can be neutral.
10
10
 
11
11
  ```text
@@ -35,8 +35,21 @@ The checkout must remain available when using this installation method.
35
35
 
36
36
  ## Configure
37
37
 
38
- For OpenRouter, export `OPENROUTER_API_KEY`. Optionally set `GIT_COMMIT_MODEL`
39
- to your preferred model. The provider defaults to OpenRouter.
38
+ For OpenRouter, export `OPENROUTER_API_KEY`. Optionally set
39
+ `GIT_COMMIT_OPENROUTER_MODEL` to your preferred model. The provider defaults to
40
+ OpenRouter.
41
+
42
+ To call Anthropic directly, save these settings. `GIT_COMMIT_ANTHROPIC_MODEL`
43
+ is optional and defaults to `claude-haiku-5-5`:
44
+
45
+ ```dotenv
46
+ GIT_COMMIT_PROVIDER=anthropic
47
+ ANTHROPIC_API_KEY=your-anthropic-key
48
+ GIT_COMMIT_ANTHROPIC_MODEL=claude-haiku-5-5
49
+ ```
50
+
51
+ When the API refuses the key, such as when its credit runs out, Jeeves falls
52
+ back to the `claude` command line on your Claude subscription.
40
53
 
41
54
  To use an installed local Ollama model, save these in your shell's configuration
42
55
  or the environment file your shell already loads:
@@ -50,9 +63,10 @@ Plain `jeeves` then uses local generation; no per-command flag or cloud key is
50
63
  needed. See [configuration](docs/configuration.md) for installation, fish
51
64
  syntax, all settings, prompt customization, and input limits.
52
65
 
53
- Version 3 requires Ruby 3.3 or newer. It validates conventional commit
54
- subjects by default; use `GIT_COMMIT_MESSAGE_FORMAT=plain` for a custom format.
55
- Existing personal prompts are preserved. See the [release notes](docs/releases.md).
66
+ Version 4 renames `GIT_COMMIT_MODEL` to `GIT_COMMIT_OPENROUTER_MODEL`. Jeeves
67
+ requires Ruby 3.3 or newer and validates conventional commit subjects by
68
+ default; use `GIT_COMMIT_MESSAGE_FORMAT=plain` for a custom format. Existing
69
+ personal prompts are preserved. See the [release notes](docs/releases.md).
56
70
 
57
71
  ## Use
58
72
 
@@ -73,8 +87,9 @@ git diff | jeeves
73
87
  # Push only after a successful commit
74
88
  jeeves --push
75
89
 
76
- # Use the saved cloud model for one command
90
+ # Use a saved provider and its model for one command
77
91
  jeeves --provider openrouter
92
+ jeeves --provider anthropic
78
93
 
79
94
  # Override the local model for one command
80
95
  jeeves --local --model another-installed-model
@@ -85,7 +100,7 @@ jeeves --local --model another-installed-model
85
100
  | `-a`, `--all` | Include all working-tree changes |
86
101
  | `-d`, `--dry-run` | Print the message without changing the real index or HEAD |
87
102
  | `-p`, `--push` | Push after a successful commit |
88
- | `--provider openrouter\|ollama` | Override the provider |
103
+ | `--provider openrouter\|anthropic\|ollama` | Override the provider |
89
104
  | `--local` | Use Ollama for this invocation |
90
105
  | `--model MODEL` | Override the selected provider's model |
91
106
  | `--version` | Print the version |
@@ -121,7 +136,7 @@ action; it is never part of normal validation.
121
136
  - [Development workflow](docs/development-workflow.md): setup, validation,
122
137
  runtime policy, and releases.
123
138
  - [Project Starter foundation](docs/foundation/README.md): knowledge search,
124
- worktrees, hooks, task tracking, and shared engineering policy.
139
+ worktrees, hooks, and shared engineering policy.
125
140
  - [Documents](docs/README.md) and [memory](memory/README.md).
126
141
  - [GitHub Issues](https://github.com/jubishop/Jeeves/issues): bugs and planned work.
127
142
  - [Agent instructions](AGENTS.md).
@@ -131,11 +146,3 @@ action; it is never part of normal validation.
131
146
 
132
147
  Jeeves uses the [MIT license](LICENSE). The adopted project foundation retains
133
148
  its separate [license notice](LICENSE.project-starter).
134
-
135
- ## Local task tracking
136
-
137
- Use `td` for local tasks, progress, blockers, and session handoffs. After cloning,
138
- install td and run `td init` in the primary checkout. Use `td status` or
139
- `td monitor` to inspect progress. Follow the [task workflow](docs/foundation/task-tracking.md)
140
- for setup, review, worktrees, and local data. Keep GitHub Issues for shared scope
141
- and acceptance criteria, linked from related td tasks.
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'open3'
5
+
6
+ module Jeeves
7
+ module Providers
8
+ # Writes a message through the claude command line on the user's Claude
9
+ # subscription, for when the Anthropic API refuses the key.
10
+ class ClaudeCommand
11
+ FAMILIES = %w[haiku sonnet opus fable].freeze
12
+ SYSTEM_PROMPT = 'Respond only with the commit message that the user message asks for.'
13
+
14
+ class << self
15
+ attr_accessor :timeout
16
+ end
17
+ self.timeout = 120
18
+
19
+ def initialize(settings)
20
+ @settings = settings
21
+ end
22
+
23
+ def model
24
+ FAMILIES.find { |family| @settings.model.match?(/\b#{family}\b/) } || @settings.model
25
+ end
26
+
27
+ def generate(prompt)
28
+ output, errors, status = run(prompt)
29
+ result = parse(output)
30
+ unless status.success?
31
+ detail = result && result['result'].to_s.strip
32
+ detail = errors.strip if detail.nil? || detail.empty?
33
+ detail = 'no details' if detail.empty?
34
+ raise Error, "claude #{status.exited? ? "exited with status #{status.exitstatus}" : 'stopped'}: #{detail}"
35
+ end
36
+ raise Error, 'claude returned invalid JSON' unless result
37
+ if result['is_error'] != false || result.fetch('subtype', 'success') != 'success'
38
+ raise Error, "claude reported an error: #{result['result'] || result['subtype']}"
39
+ end
40
+
41
+ text = result['result']
42
+ raise Error, 'claude returned an empty message' unless text.is_a?(String) && !text.strip.empty?
43
+
44
+ text
45
+ end
46
+
47
+ private
48
+
49
+ def command
50
+ # No --bare: it reads only API keys, never the subscription's login.
51
+ ['claude', '-p', '--model', model, '--tools', '', '--safe-mode', '--strict-mcp-config',
52
+ '--setting-sources', '', '--system-prompt', SYSTEM_PROMPT, '--no-session-persistence',
53
+ '--output-format', 'json']
54
+ end
55
+
56
+ def run(prompt)
57
+ # Without the refused key, claude authenticates with the subscription.
58
+ env = @settings.env.to_h.except('ANTHROPIC_API_KEY')
59
+ Open3.popen3(env, *command, unsetenv_others: true, pgroup: true) do |stdin, stdout, stderr, wait|
60
+ threads = [wait, Thread.new { read(stdout) }, Thread.new { read(stderr) }, Thread.new { write(stdin, prompt) }]
61
+ deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + self.class.timeout
62
+ finished = threads.all? { |thread| thread.join([deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC), 0].max) }
63
+ raise Error, "claude did not finish within #{self.class.timeout} seconds" unless finished
64
+
65
+ [threads[1].value, threads[2].value, wait.value]
66
+ ensure
67
+ stop(wait) unless finished
68
+ end
69
+ rescue Errno::ENOENT
70
+ raise Error, 'claude is not installed or not on PATH'
71
+ rescue SystemCallError => e
72
+ raise Error, "claude could not run: #{e.message}"
73
+ end
74
+
75
+ def read(io)
76
+ io.read
77
+ rescue IOError
78
+ ''
79
+ end
80
+
81
+ def write(stdin, prompt)
82
+ stdin.write(prompt)
83
+ rescue IOError, Errno::EPIPE
84
+ nil
85
+ ensure
86
+ stdin.close
87
+ end
88
+
89
+ # Stops claude and anything it started, so nothing outlives the run.
90
+ def stop(wait)
91
+ %w[TERM KILL].each do |signal|
92
+ Process.kill(signal, -wait.pid)
93
+ break if wait.join(2)
94
+ rescue Errno::ESRCH
95
+ break
96
+ end
97
+ end
98
+
99
+ def parse(output)
100
+ result = JSON.parse(output)
101
+ result if result.is_a?(Hash)
102
+ rescue JSON::ParserError
103
+ nil
104
+ end
105
+ end
106
+ end
107
+ end
@@ -7,6 +7,25 @@ require 'openssl'
7
7
 
8
8
  module Jeeves
9
9
  module Providers
10
+ # A provider's non-200 HTTP response.
11
+ class APIError < Error
12
+ attr_reader :status, :body
13
+
14
+ def initialize(status, body, hint = '')
15
+ @status = status
16
+ @body = body
17
+ super("API Error (#{status}): #{body}#{hint}")
18
+ end
19
+
20
+ # The provider's own error message, when the body carries one.
21
+ def detail
22
+ message = JSON.parse(body).dig('error', 'message')
23
+ message.is_a?(String) ? message : body
24
+ rescue JSON::ParserError, TypeError, NoMethodError
25
+ body
26
+ end
27
+ end
28
+
10
29
  class HTTP
11
30
  def self.post(uri, body, headers = {}, local: false)
12
31
  http = Net::HTTP.new(uri.host, uri.port, local ? nil : :ENV)
@@ -23,7 +42,7 @@ module Jeeves
23
42
  response = http.request(request)
24
43
  unless response.code == '200'
25
44
  hint = local && response.code == '404' ? " Download the model with: ollama pull #{body[:model]}" : ''
26
- raise Error, "API Error (#{response.code}): #{response.body}#{hint}"
45
+ raise APIError.new(response.code, response.body, hint)
27
46
  end
28
47
  result = JSON.parse(response.body)
29
48
  raise Error, 'Unexpected API response structure' unless result.is_a?(Hash)
@@ -38,7 +57,7 @@ module Jeeves
38
57
  end
39
58
 
40
59
  class OpenRouter
41
- def initialize(settings)
60
+ def initialize(settings, **)
42
61
  @settings = settings
43
62
  @key = settings.env['OPENROUTER_API_KEY']
44
63
  raise Error, 'OPENROUTER_API_KEY environment variable not set' if @key.nil? || @key.empty?
@@ -65,8 +84,54 @@ module Jeeves
65
84
  end
66
85
  end
67
86
 
87
+ class Anthropic
88
+ # Errors that refuse the key itself rather than this one request.
89
+ REFUSED_KEY = /credit balance is too low|\b(?:usage|spend|spending) limits?\b/i
90
+
91
+ def initialize(settings, errors: $stderr)
92
+ @settings = settings
93
+ @errors = errors
94
+ @key = settings.env['ANTHROPIC_API_KEY']
95
+ raise Error, 'ANTHROPIC_API_KEY environment variable not set' if @key.nil? || @key.empty?
96
+ end
97
+
98
+ def generate(prompt)
99
+ request(prompt)
100
+ rescue APIError => e
101
+ raise unless %w[401 403].include?(e.status) || e.body.to_s.match?(REFUSED_KEY)
102
+
103
+ fall_back(prompt, "#{e.status}: #{e.detail}")
104
+ end
105
+
106
+ private
107
+
108
+ def fall_back(prompt, refusal)
109
+ command = ClaudeCommand.new(@settings)
110
+ @errors.puts "Anthropic refused the API key (#{refusal}); falling back to the claude command line with model #{command.model}"
111
+ command.generate(prompt)
112
+ rescue Error => e
113
+ raise Error, "Anthropic refused the API key (#{refusal}), and the claude command line also failed: #{e.message}"
114
+ end
115
+
116
+ def request(prompt)
117
+ # Leave thinking at the model's default: newer models reject disabling it.
118
+ # The limit covers thinking as well as the message.
119
+ body = { model: @settings.model, max_tokens: 16_000, messages: [{ role: 'user', content: prompt }] }
120
+ headers = { 'x-api-key' => @key, 'anthropic-version' => '2023-06-01' }
121
+ result = HTTP.post(URI('https://api.anthropic.com/v1/messages'), body, headers)
122
+ raise Error, 'Anthropic reached its output limit; no commit message was accepted' if result['stop_reason'] == 'max_tokens'
123
+ raise Error, 'Anthropic declined to write this commit message' if result['stop_reason'] == 'refusal'
124
+
125
+ result.fetch('content').select { |block| block.fetch('type') == 'text' }.map { |block| block.fetch('text') }.join
126
+ rescue KeyError, NoMethodError, TypeError
127
+ raise Error, 'Unexpected Anthropic response structure'
128
+ rescue Net::OpenTimeout, Net::ReadTimeout, SocketError, SystemCallError => e
129
+ raise Error, "Anthropic request failed: #{e.message}"
130
+ end
131
+ end
132
+
68
133
  class Ollama
69
- def initialize(settings)
134
+ def initialize(settings, **)
70
135
  @settings = settings
71
136
  host = settings.env.fetch('OLLAMA_HOST', 'http://127.0.0.1:11434')
72
137
  host = "http://#{host}" unless host.include?('://')
@@ -100,5 +165,7 @@ module Jeeves
100
165
  raise Error, 'Ollama timed out. Check the server or try a smaller model or diff.'
101
166
  end
102
167
  end
168
+
169
+ CLIENTS = { 'openrouter' => OpenRouter, 'anthropic' => Anthropic, 'ollama' => Ollama }.freeze
103
170
  end
104
171
  end
@@ -4,15 +4,17 @@ module Jeeves
4
4
  class Settings
5
5
  attr_reader :provider, :model, :context, :max_diff_bytes, :message_format, :env
6
6
 
7
+ PROVIDERS = %w[openrouter anthropic ollama].freeze
8
+
7
9
  def initialize(env, options = {})
8
10
  @env = env
9
11
  @provider = options[:provider] || env.fetch('GIT_COMMIT_PROVIDER', 'openrouter')
10
- raise Error, 'GIT_COMMIT_PROVIDER must be openrouter or ollama' unless %w[openrouter ollama].include?(@provider)
12
+ raise Error, 'GIT_COMMIT_PROVIDER must be openrouter, anthropic, or ollama' unless PROVIDERS.include?(@provider)
11
13
 
12
- @model = options[:model] || if @provider == 'ollama'
13
- env.fetch('GIT_COMMIT_LOCAL_MODEL', 'gemma4:26b')
14
- else
15
- env.fetch('GIT_COMMIT_MODEL', 'x-ai/grok-code-fast-1')
14
+ @model = options[:model] || case @provider
15
+ when 'ollama' then env.fetch('GIT_COMMIT_LOCAL_MODEL', 'gemma4:26b')
16
+ when 'anthropic' then env.fetch('GIT_COMMIT_ANTHROPIC_MODEL', 'claude-haiku-5-5')
17
+ else env.fetch('GIT_COMMIT_OPENROUTER_MODEL', 'anthropic/claude-haiku-5.5')
16
18
  end
17
19
  raise Error, 'The configured model must not be empty' if @model.strip.empty?
18
20
 
@@ -1,3 +1,3 @@
1
1
  module Jeeves
2
- VERSION = '3.1.1'
2
+ VERSION = '4.1.0'
3
3
  end
data/lib/jeeves.rb CHANGED
@@ -14,6 +14,7 @@ require 'jeeves/diff'
14
14
  require 'jeeves/prompt'
15
15
  require 'jeeves/message'
16
16
  require 'jeeves/providers'
17
+ require 'jeeves/claude_command'
17
18
  require 'jeeves/git_repository'
18
19
 
19
20
  module Jeeves
@@ -36,7 +37,7 @@ module Jeeves
36
37
  return show(VERSION) if options[:version]
37
38
 
38
39
  settings = Settings.new(@env, options)
39
- provider = settings.provider == 'ollama' ? Providers::Ollama.new(settings) : Providers::OpenRouter.new(settings)
40
+ provider = Providers::CLIENTS.fetch(settings.provider).new(settings, errors: @errors)
40
41
  piped = !@input.tty? && !@input.closed?
41
42
  if piped
42
43
  diff = (@input.read || +'').force_encoding(Encoding::UTF_8)
@@ -78,7 +79,7 @@ module Jeeves
78
79
  parser.on('-a', '--all', 'Include all working-tree changes') { options[:all] = true }
79
80
  parser.on('-p', '--push', 'Push after a successful commit') { options[:push] = true }
80
81
  parser.on('-d', '--dry-run', 'Print the message without staging or committing') { options[:dry_run] = true }
81
- parser.on('--provider PROVIDER', %w[openrouter ollama], 'Use openrouter or ollama') { |value| options[:provider] = value }
82
+ parser.on('--provider PROVIDER', Settings::PROVIDERS, 'Use openrouter, anthropic, or ollama') { |value| options[:provider] = value }
82
83
  parser.on('--local', 'Use Ollama for this invocation') { options[:provider] = 'ollama' }
83
84
  parser.on('--model MODEL', 'Override the configured model') { |value| options[:model] = value }
84
85
  parser.on('--version', 'Show version') { options[:version] = true }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeeves-git-commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Bishop
@@ -79,6 +79,7 @@ files:
79
79
  - bin/jeeves
80
80
  - config/prompt
81
81
  - lib/jeeves.rb
82
+ - lib/jeeves/claude_command.rb
82
83
  - lib/jeeves/diff.rb
83
84
  - lib/jeeves/git_repository.rb
84
85
  - lib/jeeves/message.rb
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  - !ruby/object:Gem::Version
106
107
  version: '0'
107
108
  requirements: []
108
- rubygems_version: 4.0.20
109
+ rubygems_version: 4.0.23
109
110
  specification_version: 4
110
111
  summary: AI-powered Git commit message generator
111
112
  test_files: []