samagotchi 0.88.0 → 0.89.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.
@@ -116,9 +116,20 @@ module Samagotchi
116
116
  Digest::SHA256.hexdigest(File.binread(path))
117
117
  end
118
118
 
119
- # Whether the file's content is the one recorded (either format).
119
+ # What a dev install (`chi bundle install --dev`) records instead of
120
+ # a sha256: its files are links to the source, which change under it.
121
+ # Not a hex digest, so no file can be mistaken for it.
122
+ DEV_SHA = "sha256:dev"
123
+
124
+ # Whether +recorded+ is DEV_SHA: the file isn't checked.
125
+ def self.unchecked?(recorded)
126
+ recorded_sha(recorded) == recorded_sha(DEV_SHA)
127
+ end
128
+
129
+ # Whether the file's content is the one recorded (either format); a
130
+ # dev install's (DEV_SHA) always is.
120
131
  def self.sha_matches?(path, recorded)
121
- file_sha(path) == recorded_sha(recorded)
132
+ unchecked?(recorded) || file_sha(path) == recorded_sha(recorded)
122
133
  end
123
134
 
124
135
  # Writes provenance for an installation: merges into existing manifest.json
@@ -139,9 +150,11 @@ module Samagotchi
139
150
  # @param scripts_files [Hash] file name => installed script; the
140
151
  # sha256 of each is recorded (ContextFetch checks it before a run)
141
152
  # @param context_providers [Array<ContextProviders::Provider>]
153
+ # @param dev [Boolean] a dev install: its files are links to the
154
+ # source, recorded as DEV_SHA (no sha256 check) with "dev": true
142
155
  def write(files:, scope:, version:, source_path:, hooks: {}, trust_level: nil, source_commit: nil, hooks_files: {},
143
156
  guardrails_files: {}, plugin_file: nil, requires_chi: nil, needs: nil, conflicts: [], includes: nil,
144
- scripts_files: {}, context_providers: [], file_descriptions: {}, session_settings: [])
157
+ scripts_files: {}, context_providers: [], file_descriptions: {}, session_settings: [], dev: false)
145
158
  FileUtils.mkdir_p(@bundle_dir)
146
159
  bases_dir = File.join(@bundle_dir, "bases")
147
160
  FileUtils.mkdir_p(bases_dir)
@@ -196,6 +209,7 @@ module Samagotchi
196
209
  normalized_hooks.each do |k, hook|
197
210
  src = hooks_files[k] || hooks_files[k.to_sym]
198
211
  hook = hook.with(sha256: BundleHook.of_file(src.to_s).sha256) if src && File.exist?(src.to_s)
212
+ hook = hook.with(sha256: DEV_SHA) if dev
199
213
  hooks_map[k] = hook.to_record
200
214
  next unless src && File.exist?(src.to_s)
201
215
 
@@ -216,9 +230,10 @@ module Samagotchi
216
230
  "hooks" => hooks_map
217
231
  }
218
232
  manifest_data["trust_level"] = trust_level.to_s if trust_level && !trust_level.to_s.empty?
233
+ manifest_data["dev"] = true if dev
219
234
  if guardrails_files.is_a?(Hash) && !guardrails_files.empty?
220
235
  manifest_data["guardrails"] = guardrails_files.sort.to_h do |basename, path|
221
- [basename.to_s, { "sha256" => "sha256:#{Digest::SHA256.hexdigest(File.read(path.to_s))}" }]
236
+ [basename.to_s, { "sha256" => dev ? DEV_SHA : "sha256:#{Digest::SHA256.hexdigest(File.read(path.to_s))}" }]
222
237
  end
223
238
  end
224
239
  manifest_data["source_commit"] = source_commit.to_s if source_commit && !source_commit.to_s.empty?
@@ -226,7 +241,7 @@ module Samagotchi
226
241
  if plugin_file
227
242
  content = File.binread(plugin_file.to_s)
228
243
  manifest_data["plugin"] = { "file" => File.basename(plugin_file.to_s),
229
- "sha256" => "sha256:#{Digest::SHA256.hexdigest(content)}" }
244
+ "sha256" => dev ? DEV_SHA : "sha256:#{Digest::SHA256.hexdigest(content)}" }
230
245
  FileUtils.mkdir_p(File.join(bases_dir, "plugin"))
231
246
  File.binwrite(plugin_base_path(File.basename(plugin_file.to_s)), content)
232
247
  end
@@ -235,7 +250,7 @@ module Samagotchi
235
250
  manifest_data["includes"] = includes.map(&:to_s) if includes.is_a?(Array)
236
251
  unless scripts_files.empty?
237
252
  manifest_data["scripts"] = scripts_files.sort.to_h do |file, path|
238
- [file.to_s, { "sha256" => "sha256:#{Digest::SHA256.hexdigest(File.binread(path.to_s))}" }]
253
+ [file.to_s, { "sha256" => dev ? DEV_SHA : "sha256:#{Digest::SHA256.hexdigest(File.binread(path.to_s))}" }]
239
254
  end
240
255
  end
241
256
  manifest_data["context_providers"] = context_providers.map(&:to_h) unless context_providers.empty?
@@ -263,21 +263,13 @@ module Samagotchi
263
263
  # A gem-mode worker activates the newest installed chi itself: under
264
264
  # `bundle exec` (a Gemfile that has samagotchi) Bundler's RUBYOPT would
265
265
  # hold it to the bundle's version, and its badge would never clear.
266
- child_env.merge!(unbundled_env_changes) if InstalledGem.spec
266
+ child_env.merge!(InstalledGem.unbundled_env_changes) if InstalledGem.spec
267
267
  opts[:env] = child_env unless child_env.empty?
268
268
  opts
269
269
  end
270
270
 
271
- # What Bundler changed in ENV (RUBYOPT, BUNDLE_*), mapped back to the
272
- # values from before it (nil: unset); {} outside Bundler.
273
- private_class_method def self.unbundled_env_changes(env = ENV.to_h)
274
- return {} unless defined?(::Bundler) && ::Bundler.respond_to?(:unbundled_env)
275
-
276
- clean = ::Bundler.unbundled_env
277
- (env.keys | clean.keys).each_with_object({}) { |key, changes| changes[key] = clean[key] unless clean[key] == env[key] }
278
- end
279
-
280
271
  GUARDRAILS_ENV_PREFIX = "SAMAGOTCHI_GUARDRAILS_"
272
+ WORKER_ENV_PREFIX = "SAMAGOTCHI_WORKER_"
281
273
  # Tools::Builtins.parent_env's (Tools::TaskRuntime::MARKER_ENV_KEYS).
282
274
  SESSION_MARKER_ENV = %w[SAMAGOTCHI_PARENT_SESSION SAMAGOTCHI_SESSION_MODEL SAMAGOTCHI_SESSION_THINKING
283
275
  SAMAGOTCHI_SESSION_REASONING_HISTORY].freeze
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Samagotchi
4
- VERSION = "0.88.0"
4
+ VERSION = "0.89.0"
5
5
  # Sent as the User-Agent of every HTTP request chi makes.
6
6
  USER_AGENT = "chi/#{VERSION}"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samagotchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.88.0
4
+ version: 0.89.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov
@@ -23,6 +23,26 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '2.9'
26
+ - !ruby/object:Gem::Dependency
27
+ name: minitest
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '5.20'
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '7'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '5.20'
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '7'
26
46
  - !ruby/object:Gem::Dependency
27
47
  name: nokogiri
28
48
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +204,9 @@ files:
184
204
  - lib/samagotchi/bundle_command/check.rb
185
205
  - lib/samagotchi/bundle_command/scaffold.rb
186
206
  - lib/samagotchi/bundle_command/test_run.rb
207
+ - lib/samagotchi/bundle_command/try/run.rb
208
+ - lib/samagotchi/bundle_command/try/sandbox.rb
209
+ - lib/samagotchi/bundle_command/try/trace.rb
187
210
  - lib/samagotchi/bundle_needs.rb
188
211
  - lib/samagotchi/bundle_session_settings.rb
189
212
  - lib/samagotchi/bundles/agents-md/manifest.yml