jeeves-git-commit 4.0.0 → 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: e4f59a567e89976f44fabc0d1a41ecd582dd66a803a269a5432e057aaa20ad18
4
- data.tar.gz: e3138daa03b7c885c6b09623e5f74eea3d7d1f6ec4b3d943b8905fd2614a6cf0
3
+ metadata.gz: b19331ff70859069a8be98d8ea0347453ef0be84a2addf6f6fd8f6f466493857
4
+ data.tar.gz: c96d7b88ba16998b39462f441a17ba8f86b86a13b09fa4db63af3dc150cd9c0e
5
5
  SHA512:
6
- metadata.gz: '05096cd1f2f6c01388ea230937c0e6e79635a1ce5108ff738c3140de47e13ef0a1fb8cf22fee08312c360902ed9cfe74e30c47b1756ac89c4acba092bba90c08'
7
- data.tar.gz: ad8ae30b3e57dd9b35b39195dde57d44e141d79881927e13bbadd78372c1128c8d892083e165be54edb2f961a502c7e20c9d9f404f09ce40ae46bf620b3a086a
6
+ metadata.gz: 9b83c92129037c0addbc963cc09f0fb366f632c9bd02011af89aa5905a51a376a40072aa670b3712f1125d94e9bfc6ad17a68117d2d5e8d55d76d4794b13d15a
7
+ data.tar.gz: 3de948cdf19bb08a7dc291dd74199144f413b1c91ee4e059b8a0609f223bd83e6c145eaa14b63918a12e8f7019833e487a1283731f22431ad53f4352a2ff948d
data/README.md CHANGED
@@ -48,6 +48,9 @@ ANTHROPIC_API_KEY=your-anthropic-key
48
48
  GIT_COMMIT_ANTHROPIC_MODEL=claude-haiku-5-5
49
49
  ```
50
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.
53
+
51
54
  To use an installed local Ollama model, save these in your shell's configuration
52
55
  or the environment file your shell already loads:
53
56
 
@@ -133,7 +136,7 @@ action; it is never part of normal validation.
133
136
  - [Development workflow](docs/development-workflow.md): setup, validation,
134
137
  runtime policy, and releases.
135
138
  - [Project Starter foundation](docs/foundation/README.md): knowledge search,
136
- worktrees, hooks, task tracking, and shared engineering policy.
139
+ worktrees, hooks, and shared engineering policy.
137
140
  - [Documents](docs/README.md) and [memory](memory/README.md).
138
141
  - [GitHub Issues](https://github.com/jubishop/Jeeves/issues): bugs and planned work.
139
142
  - [Agent instructions](AGENTS.md).
@@ -143,11 +146,3 @@ action; it is never part of normal validation.
143
146
 
144
147
  Jeeves uses the [MIT license](LICENSE). The adopted project foundation retains
145
148
  its separate [license notice](LICENSE.project-starter).
146
-
147
- ## Local task tracking
148
-
149
- Use `td` for local tasks, progress, blockers, and session handoffs. After cloning,
150
- install td and run `td init` in the primary checkout. Use `td status` or
151
- `td monitor` to inspect progress. Follow the [task workflow](docs/foundation/task-tracking.md)
152
- for setup, review, worktrees, and local data. Keep GitHub Issues for shared scope
153
- 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?
@@ -66,13 +85,35 @@ module Jeeves
66
85
  end
67
86
 
68
87
  class Anthropic
69
- def initialize(settings)
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)
70
92
  @settings = settings
93
+ @errors = errors
71
94
  @key = settings.env['ANTHROPIC_API_KEY']
72
95
  raise Error, 'ANTHROPIC_API_KEY environment variable not set' if @key.nil? || @key.empty?
73
96
  end
74
97
 
75
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)
76
117
  # Leave thinking at the model's default: newer models reject disabling it.
77
118
  # The limit covers thinking as well as the message.
78
119
  body = { model: @settings.model, max_tokens: 16_000, messages: [{ role: 'user', content: prompt }] }
@@ -90,7 +131,7 @@ module Jeeves
90
131
  end
91
132
 
92
133
  class Ollama
93
- def initialize(settings)
134
+ def initialize(settings, **)
94
135
  @settings = settings
95
136
  host = settings.env.fetch('OLLAMA_HOST', 'http://127.0.0.1:11434')
96
137
  host = "http://#{host}" unless host.include?('://')
@@ -1,3 +1,3 @@
1
1
  module Jeeves
2
- VERSION = '4.0.0'
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 = Providers::CLIENTS.fetch(settings.provider).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)
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: 4.0.0
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: []