diffbroker 0.17.0 → 0.17.2

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: 0301a413f14ac1a2d735cc4e7fd952d1d896117d1ef3e3e013508c38d4d1226c
4
- data.tar.gz: f4bb42f5d0f1aff5bf1301143f34664d34b98e57c601999b2d8e5a07cf74a745
3
+ metadata.gz: 24dbf68bc6fdacb58899e04d69497ed9d0a6980c85a6776c93c134ef7769ed4d
4
+ data.tar.gz: 749d3ae05641bfb67c8bc3d1b15afb65dd92f496a92d23870b73c1926b24f473
5
5
  SHA512:
6
- metadata.gz: d38cc871bedc4af0fed78b15ae74a31c4bf4c7ba4e53117596db9ef3927d7aa709c0c1216db8c648ab24cae3a07253acfef6b1ca30978f5b61c1711d47eeea7e
7
- data.tar.gz: 712a68a04f52259ddf152f714eb15c1655f66721306a7bc91c18e7e7ff5569028dc771ecbb91b61f076242333aae073dc2500fa7d3c16a2deb5aaf86dee1aa5c
6
+ metadata.gz: ff9aa7e95e26b539367997d24c06637db9fa6186b02eff6e8f10eeee9fef518cc07b096c39da3de899a356d190e3c18e8de9beac768091e87a1c5cfd0dd004e4
7
+ data.tar.gz: 617654c889b195d025307e6d6bfb23b02bf692ac8e62f98b73ff7771a9a59bda0a39dc19ceaaff2ddb0214dc5b75976a9e367acca20e9882e302ee2cc20a3467
@@ -12,6 +12,10 @@ module Diffbroker
12
12
  class Unavailable < Error; end
13
13
 
14
14
  SETTLE_ATTEMPTS = 20
15
+ # A login the service cannot read from the Keychain: `claude setup-token` gives a year-long token that only an
16
+ # environment variable carries, and a service starts without the user's shell, so it is copied into the definition
17
+ # (which is then readable by its owner only).
18
+ SECRET_ENV = %w[CLAUDE_CODE_OAUTH_TOKEN].freeze
15
19
  EXE = File.join(Diffbroker::ROOT, "exe", "diffbroker")
16
20
 
17
21
  # What the service and the "Start companion" app run. RubyGems' own wrapper activates the newest installed diffbroker
@@ -85,7 +89,7 @@ module Diffbroker
85
89
  path = definition_path
86
90
  FileUtils.mkdir_p(File.dirname(path))
87
91
  FileUtils.mkdir_p(File.join(@home, "Library", "Logs")) if @platform == "macos"
88
- File.write(path, @platform == "macos" ? plist : unit)
92
+ write_private(path, @platform == "macos" ? plist : unit)
89
93
  path
90
94
  end
91
95
 
@@ -159,7 +163,7 @@ module Diffbroker
159
163
  def plist
160
164
  arguments = [ @ruby, @exe, "start" ].map { " <string>#{xml(_1)}</string>" }.join("\n")
161
165
  environment = { "PATH" => @env["PATH"].to_s, "SHELL" => @env["SHELL"] || "/bin/zsh", "LANG" => @env["LANG"] || "en_US.UTF-8" }
162
- .map { |key, value| " <key>#{key}</key>\n <string>#{xml(value)}</string>" }.join("\n")
166
+ .merge(secret_environment).map { |key, value| " <key>#{key}</key>\n <string>#{xml(value)}</string>" }.join("\n")
163
167
  log = xml(File.join(@home, "Library", "Logs", "diffbroker.log"))
164
168
  <<~XML
165
169
  <?xml version="1.0" encoding="UTF-8"?>
@@ -207,6 +211,7 @@ module Diffbroker
207
211
  RestartSec=5
208
212
  Environment="PATH=#{@env["PATH"]}"
209
213
  Environment="SHELL=#{@env["SHELL"] || "/bin/bash"}"
214
+ #{secret_environment.map { |key, value| %(Environment="#{key}=#{unit_escape(value)}") }.join("\n ")}
210
215
 
211
216
  [Install]
212
217
  WantedBy=default.target
@@ -215,6 +220,21 @@ module Diffbroker
215
220
 
216
221
  private
217
222
 
223
+ # The variables of SECRET_ENV that this process has, empty ones left out.
224
+ def secret_environment = SECRET_ENV.to_h { [ _1, @env[_1].to_s.strip ] }.reject { |_, value| value.empty? }
225
+
226
+ # systemd expands % specifiers and reads quotes and backslashes inside Environment="…".
227
+ def unit_escape(value) = value.gsub(/[\\"%]/) { |char| char == "%" ? "%%" : "\\#{char}" }
228
+
229
+ # The file is born 0600 (a chmod afterwards would leave the token readable for a moment, and an existing file keeps
230
+ # its old mode) and replaces the old one in a single rename.
231
+ def write_private(path, text)
232
+ temp = "#{path}.new"
233
+ FileUtils.rm_f(temp)
234
+ File.open(temp, File::WRONLY | File::CREAT | File::EXCL, 0o600) { _1.write(text) }
235
+ File.rename(temp, path)
236
+ end
237
+
218
238
  def target = "gui/#{@uid}/#{LABEL}"
219
239
 
220
240
  # kickstart fails once the job was booted out (`stop!`): load it again, RunAtLoad starts it.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diffbroker
4
- VERSION = "0.17.0"
4
+ VERSION = "0.17.2"
5
5
  end
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "diffbroker",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "description": "Skills for working on Diff Broker agent tasks: the diffbroker MCP tools, write rules and report_task."
5
5
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diffbroker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.17.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Sidorov (@newstler)