samagotchi 0.88.0 → 0.90.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 +4 -4
- data/CHANGELOG.md +37 -1
- data/bin/chi +28 -3
- data/docs/architecture.md +24 -2
- data/docs/bundle-authoring.md +46 -21
- data/docs/cli.md +41 -2
- data/docs/internals/bundles.md +10 -0
- data/docs/internals/engine.md +2 -2
- data/lib/samagotchi/bridge/client_event.rb +15 -7
- data/lib/samagotchi/bundle_command/test_run.rb +2 -2
- data/lib/samagotchi/bundle_command/try/run.rb +162 -0
- data/lib/samagotchi/bundle_command/try/sandbox.rb +159 -0
- data/lib/samagotchi/bundle_command/try/trace.rb +152 -0
- data/lib/samagotchi/bundle_command.rb +216 -10
- data/lib/samagotchi/bundle_session_settings.rb +2 -0
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/context_providers.rb +1 -2
- data/lib/samagotchi/hooks/bundle_loader.rb +2 -0
- data/lib/samagotchi/installed_gem.rb +11 -0
- data/lib/samagotchi/llm/model_result.rb +2 -2
- data/lib/samagotchi/memory_bundle/asset_installer.rb +25 -13
- data/lib/samagotchi/memory_bundle/installed_bundle.rb +6 -3
- data/lib/samagotchi/memory_bundle/installer.rb +22 -3
- data/lib/samagotchi/memory_bundle/provenance.rb +21 -6
- data/lib/samagotchi/session_manager.rb +2 -10
- data/lib/samagotchi/tool_runner.rb +1 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/public/turn_events.js +3 -7
- metadata +24 -1
|
@@ -126,6 +126,8 @@ module Samagotchi
|
|
|
126
126
|
# Why the file doesn't match the sha256 recorded at install, or nil.
|
|
127
127
|
# With none recorded, only a required hook counts as a mismatch.
|
|
128
128
|
def sha_mismatch(file, recorded, required:)
|
|
129
|
+
return nil if MemoryBundle::Provenance.unchecked?(recorded)
|
|
130
|
+
|
|
129
131
|
expected = MemoryBundle::Provenance.recorded_sha(recorded)
|
|
130
132
|
return (required ? "no sha256 recorded for it (reinstall the bundle)" : nil) if expected.empty?
|
|
131
133
|
|
|
@@ -29,6 +29,17 @@ module Samagotchi
|
|
|
29
29
|
File.file?(path) ? path : nil
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# What Bundler changed in ENV, mapped back to the values from before it
|
|
33
|
+
# (nil: unset); {} outside Bundler. Child chi commands use this in gem
|
|
34
|
+
# mode so they load the same installed gem without inheriting this app's
|
|
35
|
+
# bundle.
|
|
36
|
+
def unbundled_env_changes(env = ENV.to_h)
|
|
37
|
+
return {} unless defined?(::Bundler) && ::Bundler.respond_to?(:unbundled_env)
|
|
38
|
+
|
|
39
|
+
clean = ::Bundler.unbundled_env
|
|
40
|
+
(env.keys | clean.keys).each_with_object({}) { |key, changes| changes[key] = clean[key] unless clean[key] == env[key] }
|
|
41
|
+
end
|
|
42
|
+
|
|
32
43
|
def real_path(path)
|
|
33
44
|
File.realpath(path)
|
|
34
45
|
rescue SystemCallError
|
|
@@ -4,8 +4,8 @@ module Samagotchi
|
|
|
4
4
|
module LLM
|
|
5
5
|
# Normalized result returned by every ModelBackend downstream of the agentic
|
|
6
6
|
# loop (the loop lives inside the backend). What Engine#run_turn and the
|
|
7
|
-
# renderers (TerminalUI / Bridge) read: .output (= .text, and .to_s
|
|
8
|
-
#
|
|
7
|
+
# renderers (TerminalUI / Bridge) read: .output (= .text, and .to_s: the
|
|
8
|
+
# Engine's :turn_completed `result:`; clients get turn_summary.output), .conversation,
|
|
9
9
|
# .canceled?, .cancellation_reason, .exhausted?, .resumable?,
|
|
10
10
|
# .empty_answer?, plus the native loop's .tool_activity, .context_status
|
|
11
11
|
# and .pending_tool_calls, which the interactive renderer needs.
|
|
@@ -17,6 +17,8 @@ module Samagotchi
|
|
|
17
17
|
# scripts/*. Each replaces what an earlier version installed. Installer
|
|
18
18
|
# runs it after the memories; it adds to the installer's results and
|
|
19
19
|
# warnings, and #run returns what the record (Provenance#write) keeps.
|
|
20
|
+
# A dev install (+dev+, `chi bundle install --dev`) links each file to
|
|
21
|
+
# the source instead of copying it, and warns of no checksum mismatch.
|
|
20
22
|
class AssetInstaller
|
|
21
23
|
# What was installed: the paths Provenance#write records (each
|
|
22
24
|
# empty / nil on a dry run).
|
|
@@ -32,7 +34,7 @@ module Samagotchi
|
|
|
32
34
|
# @param results, warnings, conflicts the Installer's (results and
|
|
33
35
|
# warnings are added to)
|
|
34
36
|
def initialize(name:, source_dir:, manifest:, provenance:, existing:, results:, warnings:, conflicts:,
|
|
35
|
-
force: false, strict: true, upgrade: false, dry_run: false)
|
|
37
|
+
force: false, strict: true, upgrade: false, dry_run: false, dev: false)
|
|
36
38
|
@name = name
|
|
37
39
|
@bundle_dir = source_dir
|
|
38
40
|
@manifest = manifest
|
|
@@ -45,6 +47,7 @@ module Samagotchi
|
|
|
45
47
|
@strict = strict
|
|
46
48
|
@upgrade = upgrade
|
|
47
49
|
@dry_run = dry_run
|
|
50
|
+
@dev = dev
|
|
48
51
|
end
|
|
49
52
|
|
|
50
53
|
# @return [Installed]
|
|
@@ -52,8 +55,8 @@ module Samagotchi
|
|
|
52
55
|
# script the bundle doesn't have
|
|
53
56
|
def run
|
|
54
57
|
install_hooks
|
|
55
|
-
prune_dropped_hooks if @upgrade && @existing && !@dry_run
|
|
56
|
-
verify_hook_checksums if @manifest && @strict
|
|
58
|
+
prune_dropped_hooks if (@upgrade || (@dev && @existing&.dev)) && @existing && !@dry_run
|
|
59
|
+
verify_hook_checksums if @manifest && @strict && !@dev
|
|
57
60
|
incoming_rules = Dir.glob(File.join(@bundle_dir, "guardrails", "*.yml")).sort
|
|
58
61
|
.reject { |src| linked_out?(src, "guardrails/#{File.basename(src)}") }
|
|
59
62
|
guardrail_files = install_guardrails(incoming_rules)
|
|
@@ -109,7 +112,7 @@ module Samagotchi
|
|
|
109
112
|
|
|
110
113
|
FileUtils.mkdir_p(@provenance.hooks_dir)
|
|
111
114
|
unchanged = File.exist?(dest) && FileUtils.identical?(src, dest)
|
|
112
|
-
|
|
115
|
+
place(src, dest)
|
|
113
116
|
@results[basename] = if unchanged
|
|
114
117
|
{ status: "skipped", reason: "already up to date" }
|
|
115
118
|
elsif @upgrade && @existing
|
|
@@ -132,7 +135,7 @@ module Samagotchi
|
|
|
132
135
|
else
|
|
133
136
|
FileUtils.mkdir_p(@provenance.hooks_dir)
|
|
134
137
|
dest = File.join(@provenance.hooks_dir, basename)
|
|
135
|
-
|
|
138
|
+
place(src, dest)
|
|
136
139
|
@results[basename] = { status: "installed" }
|
|
137
140
|
@hook_files[basename] = dest
|
|
138
141
|
end
|
|
@@ -140,13 +143,13 @@ module Samagotchi
|
|
|
140
143
|
end
|
|
141
144
|
|
|
142
145
|
# An upgrade removes the hooks the previous version shipped and this
|
|
143
|
-
# one doesn't (a local file too, with a warning).
|
|
146
|
+
# one doesn't (a local file too, with a warning; a dev link silently).
|
|
144
147
|
def prune_dropped_hooks
|
|
145
148
|
@existing.hooks.each_key do |old_key_str|
|
|
146
149
|
next if @bundle_hooks.include?(old_key_str)
|
|
147
150
|
|
|
148
151
|
old_dest = File.join(@provenance.hooks_dir, old_key_str)
|
|
149
|
-
if File.exist?(old_dest) && !@force
|
|
152
|
+
if File.exist?(old_dest) && !@force && !File.symlink?(old_dest)
|
|
150
153
|
@warnings << "Bundle no longer includes hook #{old_key_str} but local file exists — removing"
|
|
151
154
|
end
|
|
152
155
|
FileUtils.rm_f(old_dest)
|
|
@@ -193,7 +196,7 @@ module Samagotchi
|
|
|
193
196
|
FileUtils.mkdir_p(target)
|
|
194
197
|
incoming_rules.to_h do |src|
|
|
195
198
|
dest = File.join(target, File.basename(src))
|
|
196
|
-
|
|
199
|
+
place(src, dest)
|
|
197
200
|
@results["guardrails/#{File.basename(src)}"] =
|
|
198
201
|
unchanged.include?(src) ? { status: "skipped", reason: "already up to date" } : { status: "installed" }
|
|
199
202
|
[File.basename(src), dest]
|
|
@@ -227,7 +230,7 @@ module Samagotchi
|
|
|
227
230
|
unchanged = File.file?(dest) && FileUtils.identical?(src, dest)
|
|
228
231
|
FileUtils.rm_rf(@provenance.plugin_dir)
|
|
229
232
|
FileUtils.mkdir_p(@provenance.plugin_dir)
|
|
230
|
-
|
|
233
|
+
place(src, dest)
|
|
231
234
|
@results[plugin[:file]] = if unchanged
|
|
232
235
|
{ status: "skipped", reason: "already up to date" }
|
|
233
236
|
elsif @upgrade && @provenance.installed?
|
|
@@ -237,7 +240,7 @@ module Samagotchi
|
|
|
237
240
|
end
|
|
238
241
|
expected = @manifest.checksum_for_plugin
|
|
239
242
|
actual = Digest::SHA256.hexdigest(File.binread(dest))
|
|
240
|
-
if @strict && expected && actual != expected
|
|
243
|
+
if @strict && !@dev && expected && actual != expected
|
|
241
244
|
@warnings << "Checksum mismatch for plugin #{plugin[:file]}: expected #{expected[0..7]}..., got #{actual[0..7]}..."
|
|
242
245
|
end
|
|
243
246
|
dest
|
|
@@ -253,6 +256,8 @@ module Samagotchi
|
|
|
253
256
|
src = File.join(@bundle_dir, "scripts", file)
|
|
254
257
|
raise Installer::InstallError, "the manifest names scripts/#{file}, which the bundle doesn't have" unless File.file?(src)
|
|
255
258
|
raise Installer::InstallError, "scripts/#{file} is a symlink (not installed)" if linked?(src)
|
|
259
|
+
|
|
260
|
+
@warnings << "scripts/#{file} is not executable; chmod +x #{src}" if @dev && !File.executable?(src)
|
|
256
261
|
end
|
|
257
262
|
return {} if @dry_run
|
|
258
263
|
|
|
@@ -266,21 +271,28 @@ module Samagotchi
|
|
|
266
271
|
FileUtils.mkdir_p(@provenance.scripts_dir)
|
|
267
272
|
scripts.to_h do |file, declared|
|
|
268
273
|
dest = File.join(@provenance.scripts_dir, file)
|
|
269
|
-
|
|
274
|
+
place(File.join(@bundle_dir, "scripts", file), dest)
|
|
270
275
|
@results["scripts/#{file}"] = if unchanged.include?(file) then { status: "skipped", reason: "already up to date" }
|
|
271
276
|
elsif @upgrade && @provenance.installed? then { status: "updated" }
|
|
272
277
|
else { status: "installed" }
|
|
273
278
|
end
|
|
274
|
-
FileUtils.chmod(0o755, dest)
|
|
279
|
+
FileUtils.chmod(0o755, dest) unless @dev
|
|
275
280
|
actual = Digest::SHA256.hexdigest(File.binread(dest))
|
|
276
281
|
expected = declared.to_s.delete_prefix("sha256:")
|
|
277
|
-
if @strict && !expected.empty? && actual != expected
|
|
282
|
+
if @strict && !@dev && !expected.empty? && actual != expected
|
|
278
283
|
@warnings << "Checksum mismatch for script #{file}: expected #{expected[0..7]}..., got #{actual[0..7]}..."
|
|
279
284
|
end
|
|
280
285
|
[file, dest]
|
|
281
286
|
end
|
|
282
287
|
end
|
|
283
288
|
|
|
289
|
+
# Copies +src+ to +dest+, or (a dev install) links +dest+ to it. An
|
|
290
|
+
# existing link goes first: a copy over it would write into the source.
|
|
291
|
+
def place(src, dest)
|
|
292
|
+
FileUtils.rm_f(dest) if File.symlink?(dest)
|
|
293
|
+
@dev ? File.symlink(File.realpath(src), dest) : FileUtils.cp(src, dest)
|
|
294
|
+
end
|
|
295
|
+
|
|
284
296
|
# Whether the bundle file +src+ reads through a symlink: it is one, or
|
|
285
297
|
# it (or its dir, hooks/ say) resolves outside the bundle dir. A tar,
|
|
286
298
|
# zip or git repo keeps links; copying through one would install any
|
|
@@ -22,13 +22,15 @@ module Samagotchi
|
|
|
22
22
|
# includes a profile's recorded members, nil for a plain bundle
|
|
23
23
|
# session_settings
|
|
24
24
|
# the keys a session may set (chi --set), [] when none
|
|
25
|
+
# dev a dev install (`chi bundle install --dev`): its source is
|
|
26
|
+
# the folder it links to and its files carry Provenance::DEV_SHA
|
|
25
27
|
# error why manifest.json couldn't be read (the rest empty), else nil
|
|
26
28
|
class InstalledBundle < Data.define(:name, :version, :scope, :source, :installed_at, :trust_level, :source_commit,
|
|
27
29
|
:requires_chi, :files, :hooks, :guardrails, :scripts, :plugin, :needs,
|
|
28
|
-
:includes, :context_providers, :session_settings, :error)
|
|
30
|
+
:includes, :context_providers, :session_settings, :dev, :error)
|
|
29
31
|
OPTIONAL = { version: nil, scope: nil, source: nil, installed_at: nil, trust_level: nil, source_commit: nil,
|
|
30
32
|
requires_chi: nil, files: {}, hooks: {}, guardrails: {}, scripts: {}, plugin: nil, needs: nil,
|
|
31
|
-
includes: nil, context_providers: nil, session_settings: [], error: nil }.freeze
|
|
33
|
+
includes: nil, context_providers: nil, session_settings: [], dev: false, error: nil }.freeze
|
|
32
34
|
|
|
33
35
|
def initialize(name:, **fields)
|
|
34
36
|
super(name: name, **OPTIONAL, **fields)
|
|
@@ -60,7 +62,8 @@ module Samagotchi
|
|
|
60
62
|
scripts: mapping(h["scripts"]) { |meta| sha(meta) },
|
|
61
63
|
plugin: PluginRef.parse(h["plugin"]), needs: h["needs"], context_providers: h["context_providers"],
|
|
62
64
|
includes: h["includes"].is_a?(Array) ? h["includes"].map(&:to_s) : nil,
|
|
63
|
-
session_settings: h["session_settings"].is_a?(Array) ? h["session_settings"].map(&:to_s) : []
|
|
65
|
+
session_settings: h["session_settings"].is_a?(Array) ? h["session_settings"].map(&:to_s) : [],
|
|
66
|
+
dev: h["dev"] == true)
|
|
64
67
|
end
|
|
65
68
|
|
|
66
69
|
def self.string(value) = value&.to_s
|
|
@@ -40,7 +40,7 @@ module Samagotchi
|
|
|
40
40
|
# installs from a dir in it only, unless force); ShippedUpdate,
|
|
41
41
|
# Profile and SystemBundle pass the one they install from.
|
|
42
42
|
def initialize(source:, name:, scope: nil, force: false, strict: true, upgrade: false, dry_run: false, prepared: nil,
|
|
43
|
-
shipped_dir: SourceNormalizer::SHIPPED_DIR)
|
|
43
|
+
shipped_dir: SourceNormalizer::SHIPPED_DIR, dev: false)
|
|
44
44
|
@source = source
|
|
45
45
|
@shipped_dir = shipped_dir
|
|
46
46
|
@prepared = prepared
|
|
@@ -50,6 +50,7 @@ module Samagotchi
|
|
|
50
50
|
@strict = strict
|
|
51
51
|
@upgrade = upgrade
|
|
52
52
|
@dry_run = dry_run
|
|
53
|
+
@dev = dev
|
|
53
54
|
@results = {}
|
|
54
55
|
@warnings = []
|
|
55
56
|
@placeholder_warnings = []
|
|
@@ -98,7 +99,7 @@ module Samagotchi
|
|
|
98
99
|
installed = AssetInstaller.new(
|
|
99
100
|
name: @name, source_dir: @bundle_dir, manifest: @manifest, provenance: @provenance, existing: @existing,
|
|
100
101
|
results: @results, warnings: @warnings, conflicts: @conflicts,
|
|
101
|
-
force: @force, strict: @strict, upgrade: @upgrade, dry_run: @dry_run
|
|
102
|
+
force: @force, strict: @strict, upgrade: @upgrade, dry_run: @dry_run, dev: @dev
|
|
102
103
|
).run
|
|
103
104
|
|
|
104
105
|
# Files the previous version shipped and this one doesn't.
|
|
@@ -172,10 +173,14 @@ module Samagotchi
|
|
|
172
173
|
def check_source
|
|
173
174
|
refuse_case_twin
|
|
174
175
|
refuse_shipped_name
|
|
176
|
+
refuse_dev_mismatch
|
|
175
177
|
now = incoming_identity
|
|
176
178
|
return if now.nil?
|
|
177
179
|
|
|
178
180
|
was = @existing && SourceIdentity.of(@existing.source)
|
|
181
|
+
if @dev && @existing&.dev && was != now
|
|
182
|
+
raise InstallError, "#{@name} is a dev install of #{@existing.source}; uninstall it before installing from #{@source}"
|
|
183
|
+
end
|
|
179
184
|
return if was.nil? || was == now
|
|
180
185
|
return @source_change = [@existing.source, @source.to_s] if @upgrade
|
|
181
186
|
|
|
@@ -191,6 +196,19 @@ module Samagotchi
|
|
|
191
196
|
raise InstallError, "#{@name} differs only in case from the installed #{twin}" if twin
|
|
192
197
|
end
|
|
193
198
|
|
|
199
|
+
# A dev install (--dev, linked to its source) and a normal one don't
|
|
200
|
+
# replace each other: neither an upgrade nor a plain install over a
|
|
201
|
+
# dev bundle, nor --dev over a normal one.
|
|
202
|
+
def refuse_dev_mismatch
|
|
203
|
+
return if @existing.nil? || @existing.dev == @dev
|
|
204
|
+
|
|
205
|
+
if @existing.dev
|
|
206
|
+
raise InstallError, "#{@name} is a dev install of #{@existing.source}: it follows its source already " \
|
|
207
|
+
"(to leave dev mode: chi bundle uninstall #{@name}, then chi bundle install without --dev)"
|
|
208
|
+
end
|
|
209
|
+
raise InstallError, "#{@name} is installed normally; `chi bundle uninstall #{@name}` first, then chi bundle install --dev"
|
|
210
|
+
end
|
|
211
|
+
|
|
194
212
|
# A shipped name (in any case) from anything but this chi's own
|
|
195
213
|
# shipped dir. A recorded source may be an older gem's (SourceIdentity
|
|
196
214
|
# matches the path); an incoming one must be a dir in SHIPPED_DIR, so
|
|
@@ -421,7 +439,8 @@ module Samagotchi
|
|
|
421
439
|
scripts_files: installed.script_files,
|
|
422
440
|
context_providers: @manifest.context_providers,
|
|
423
441
|
file_descriptions: @manifest.file_descriptions,
|
|
424
|
-
session_settings: @manifest.session_settings
|
|
442
|
+
session_settings: @manifest.session_settings,
|
|
443
|
+
dev: @dev
|
|
425
444
|
)
|
|
426
445
|
end
|
|
427
446
|
|
|
@@ -116,9 +116,20 @@ module Samagotchi
|
|
|
116
116
|
Digest::SHA256.hexdigest(File.binread(path))
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
-
#
|
|
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
|
|
@@ -76,6 +76,7 @@ module Samagotchi
|
|
|
76
76
|
call = verdict.call
|
|
77
77
|
params = ToolActivity.tool_activity_params(call[:name], call, registry: tools)
|
|
78
78
|
label = plugin_label(call[:name])
|
|
79
|
+
# Kept on the raw event for in-worker hooks and metrics, not sent to SSE clients.
|
|
79
80
|
started = { type: :tool_call_started, iteration: iteration, call_count: call_count, call_index: call_index,
|
|
80
81
|
tool: call[:name], call: call.dup, params: params }
|
|
81
82
|
started[:label] = label if label
|
data/lib/samagotchi/version.rb
CHANGED
|
@@ -3,15 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import { ACTIVITY_FIELDS, EVENT_FIELDS, pickFields } from "./activity.js";
|
|
5
5
|
|
|
6
|
-
//
|
|
7
|
-
// contract; `result` is the KernelLoop result, which reaches the wire as its
|
|
8
|
-
// string form (older servers, other clients' fixtures).
|
|
6
|
+
// Read turn_summary.output; Bridge::ClientEvent omits result for clients.
|
|
9
7
|
export function turnOutput(data) {
|
|
10
8
|
if (!data) return "";
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const out = [summary, result, data.content, data.output].find((v) => typeof v === "string" && v.trim());
|
|
14
|
-
return out ? out.trim() : "";
|
|
9
|
+
const output = data.turn_summary?.output;
|
|
10
|
+
return typeof output === "string" ? output.trim() : "";
|
|
15
11
|
}
|
|
16
12
|
|
|
17
13
|
// The end line for a turn whose worker went away mid-turn (the footer's
|
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.
|
|
4
|
+
version: 0.90.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
|