samagotchi 0.178.0 → 0.179.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.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -1
  3. data/docs/architecture.md +4 -2
  4. data/docs/bundles.md +16 -7
  5. data/docs/cli.md +3 -1
  6. data/docs/context.md +25 -1
  7. data/docs/guardrails.md +2 -1
  8. data/docs/internals/attached-context.md +26 -4
  9. data/docs/internals/background-tasks.md +3 -0
  10. data/docs/internals/block-renderers.md +2 -2
  11. data/docs/internals/bridge.md +11 -2
  12. data/docs/internals/bundles.md +63 -34
  13. data/docs/internals/engine.md +1 -1
  14. data/docs/internals/web-frontend.md +18 -1
  15. data/docs/plugins.md +14 -3
  16. data/docs/releasing.md +3 -3
  17. data/docs/scheduling.md +4 -0
  18. data/docs/sessions.md +8 -2
  19. data/docs/testing.md +4 -1
  20. data/lib/samagotchi/block_renderers.rb +12 -14
  21. data/lib/samagotchi/bootstrap/bundles.rb +2 -2
  22. data/lib/samagotchi/bootstrap_command.rb +1 -1
  23. data/lib/samagotchi/bridge/card_wait.rb +34 -0
  24. data/lib/samagotchi/bridge/turn_accumulator.rb +22 -4
  25. data/lib/samagotchi/bundle_command/check.rb +10 -10
  26. data/lib/samagotchi/bundle_command/installed_check.rb +2 -2
  27. data/lib/samagotchi/bundle_command/try/sandbox.rb +3 -3
  28. data/lib/samagotchi/bundle_command.rb +17 -17
  29. data/lib/samagotchi/bundle_manifest.rb +579 -0
  30. data/lib/samagotchi/bundle_needs.rb +9 -8
  31. data/lib/samagotchi/bundle_settings_check.rb +9 -8
  32. data/lib/samagotchi/bundles/claude-peer/manifest.yml +5 -3
  33. data/lib/samagotchi/bundles/claude-peer/plugin.rb +4 -4
  34. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +11 -6
  35. data/lib/samagotchi/bundles/codex-peer/manifest.yml +5 -3
  36. data/lib/samagotchi/bundles/codex-peer/plugin.rb +4 -3
  37. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +11 -6
  38. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  39. data/lib/samagotchi/bundles/system/memory_guide.md +1 -1
  40. data/lib/samagotchi/config.rb +2 -2
  41. data/lib/samagotchi/context_absorber.rb +36 -6
  42. data/lib/samagotchi/context_note.rb +8 -5
  43. data/lib/samagotchi/context_providers.rb +30 -27
  44. data/lib/samagotchi/context_sources.rb +42 -12
  45. data/lib/samagotchi/engine/messages.rb +1 -1
  46. data/lib/samagotchi/events.rb +6 -5
  47. data/lib/samagotchi/guardrail_wiring.rb +20 -21
  48. data/lib/samagotchi/guardrails/approval.rb +3 -2
  49. data/lib/samagotchi/guardrails/outside.rb +3 -3
  50. data/lib/samagotchi/{memory_bundle → installed_bundles}/bundle_hook.rb +1 -1
  51. data/lib/samagotchi/installed_bundles/dir.rb +129 -0
  52. data/lib/samagotchi/{memory_bundle → installed_bundles}/file_digest.rb +1 -1
  53. data/lib/samagotchi/{memory_bundle → installed_bundles}/file_standing.rb +2 -2
  54. data/lib/samagotchi/{memory_bundle/installed_manifest.rb → installed_bundles/manifest.rb} +21 -21
  55. data/lib/samagotchi/{memory_bundle → installed_bundles}/plugin_ref.rb +2 -2
  56. data/lib/samagotchi/{memory_bundle/installed_bundle.rb → installed_bundles/record.rb} +17 -17
  57. data/lib/samagotchi/installed_bundles/sha.rb +41 -0
  58. data/lib/samagotchi/installed_bundles/standing.rb +45 -0
  59. data/lib/samagotchi/installed_bundles.rb +90 -0
  60. data/lib/samagotchi/memory_bundle/asset_installer.rb +7 -7
  61. data/lib/samagotchi/memory_bundle/builder.rb +13 -13
  62. data/lib/samagotchi/memory_bundle/file_state.rb +9 -9
  63. data/lib/samagotchi/memory_bundle/installed_copy.rb +6 -6
  64. data/lib/samagotchi/memory_bundle/installer.rb +33 -33
  65. data/lib/samagotchi/memory_bundle/listing.rb +5 -5
  66. data/lib/samagotchi/memory_bundle/manifest_standing.rb +7 -7
  67. data/lib/samagotchi/memory_bundle/merger.rb +15 -15
  68. data/lib/samagotchi/memory_bundle/profile.rb +8 -8
  69. data/lib/samagotchi/memory_bundle/provenance.rb +59 -192
  70. data/lib/samagotchi/memory_bundle/remerge.rb +16 -16
  71. data/lib/samagotchi/memory_bundle/shas.rb +2 -2
  72. data/lib/samagotchi/memory_bundle/shipped_history.rb +1 -1
  73. data/lib/samagotchi/memory_bundle/shipped_update.rb +17 -17
  74. data/lib/samagotchi/memory_bundle/status.rb +15 -15
  75. data/lib/samagotchi/memory_bundle/system_bundle.rb +12 -12
  76. data/lib/samagotchi/memory_bundle/trash.rb +2 -2
  77. data/lib/samagotchi/memory_bundle/uninstaller.rb +8 -8
  78. data/lib/samagotchi/memory_bundle.rb +2 -2
  79. data/lib/samagotchi/memory_command.rb +4 -4
  80. data/lib/samagotchi/{memory_bundle → memory_index}/entry_size.rb +8 -8
  81. data/lib/samagotchi/{memory_bundle/index_size.rb → memory_index/size.rb} +6 -6
  82. data/lib/samagotchi/{memory_bundle/index_sync.rb → memory_index/sync.rb} +5 -5
  83. data/lib/samagotchi/{memory_bundle/index_updater.rb → memory_index/updater.rb} +2 -2
  84. data/lib/samagotchi/memory_usage.rb +5 -5
  85. data/lib/samagotchi/muted_memories.rb +1 -1
  86. data/lib/samagotchi/peer_exchanges.rb +76 -0
  87. data/lib/samagotchi/plugin/context.rb +4 -0
  88. data/lib/samagotchi/plugin/loader.rb +35 -33
  89. data/lib/samagotchi/plugin/peer.rb +42 -11
  90. data/lib/samagotchi/project_subfolders.rb +9 -9
  91. data/lib/samagotchi/reply_wait/target.rb +11 -4
  92. data/lib/samagotchi/self_report.rb +14 -14
  93. data/lib/samagotchi/session_access/local.rb +16 -1
  94. data/lib/samagotchi/session_access/remote.rb +2 -1
  95. data/lib/samagotchi/session_config.rb +23 -19
  96. data/lib/samagotchi/session_manager/running_tasks.rb +15 -2
  97. data/lib/samagotchi/session_retention.rb +13 -4
  98. data/lib/samagotchi/session_stores.rb +3 -0
  99. data/lib/samagotchi/system_prompt.rb +4 -4
  100. data/lib/samagotchi/terminal_ui/attach_launcher.rb +5 -1
  101. data/lib/samagotchi/terminal_ui/formatting.rb +2 -2
  102. data/lib/samagotchi/terminal_ui/model_segments_text.rb +5 -5
  103. data/lib/samagotchi/terminal_ui.rb +4 -1
  104. data/lib/samagotchi/testing/bundle.rb +3 -3
  105. data/lib/samagotchi/testing/install.rb +3 -3
  106. data/lib/samagotchi/testing/sandbox.rb +2 -2
  107. data/lib/samagotchi/tool_runner.rb +14 -14
  108. data/lib/samagotchi/tools/memory.rb +22 -22
  109. data/lib/samagotchi/update_command.rb +4 -4
  110. data/lib/samagotchi/version.rb +1 -1
  111. data/lib/samagotchi/web/app.rb +14 -1
  112. data/lib/samagotchi/web/message_display.rb +6 -0
  113. data/lib/samagotchi/web/participant_view.rb +1 -1
  114. data/lib/samagotchi/web/proxy_gate.rb +1 -0
  115. data/lib/samagotchi/web/public/card_kinds.js +8 -3
  116. data/lib/samagotchi/web/public/cards_place.js +15 -1
  117. data/lib/samagotchi/web/public/ctx.js +1 -1
  118. data/lib/samagotchi/web/public/history_shape.js +3 -0
  119. data/lib/samagotchi/web/public/turn_block.js +46 -8
  120. data/lib/samagotchi/web/public/turn_settle.js +117 -0
  121. data/lib/samagotchi/web/push/notifier.rb +2 -2
  122. data/lib/samagotchi/web/session_access_routes.rb +21 -1
  123. data/lib/samagotchi/web/session_hub.rb +20 -4
  124. data/lib/samagotchi/worker_boot.rb +4 -1
  125. metadata +19 -12
  126. data/lib/samagotchi/memory_bundle/manifest.rb +0 -581
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "installed_bundles"
4
+
3
5
  module Samagotchi
6
+ autoload :BundleManifest, File.expand_path("bundle_manifest", __dir__)
4
7
  autoload :InlineWidgets, File.expand_path("inline_widgets", __dir__)
5
8
  autoload :Log, File.expand_path("log", __dir__)
6
- autoload :VERSION, File.expand_path("version", __dir__)
7
- module MemoryBundle
8
- autoload :Manifest, File.expand_path("memory_bundle/manifest", __dir__)
9
- autoload :Provenance, File.expand_path("memory_bundle/provenance", __dir__)
10
- end
11
9
 
12
10
  # Declarative block renderers (docs/plugins.md, docs/internals/block-renderers.md):
13
11
  # a bundle's manifest maps a fenced block's language to the scripts/ files the
@@ -70,7 +68,7 @@ module Samagotchi
70
68
  raise Invalid, "block_renderers: #{lang} is drawn by chi itself; a bundle can't render it" if RESERVED.include?(lang)
71
69
 
72
70
  load = data["load"]
73
- unless load.is_a?(Array) && !load.empty? && load.all? { |file| file.is_a?(String) && file.match?(MemoryBundle::Manifest::SCRIPT_FILE) }
71
+ unless load.is_a?(Array) && !load.empty? && load.all? { |file| file.is_a?(String) && file.match?(BundleManifest::SCRIPT_FILE) }
74
72
  raise Invalid, "block_renderers: #{lang}'s load must be a non-empty list of file names in scripts/, not #{load.inspect}"
75
73
  end
76
74
 
@@ -83,11 +81,11 @@ module Samagotchi
83
81
  # @return [Array<Installed>]
84
82
  def for_installed
85
83
  taken = {}
86
- MemoryBundle::Provenance.each_installed do |bundle, record|
87
- manifest = record.manifest
88
- next if manifest.requires_chi_failure(VERSION)
84
+ InstalledBundles.standings do |standing|
85
+ next if standing.too_new?
89
86
 
90
- renderers(bundle, manifest).each do |renderer|
87
+ bundle = standing.name
88
+ renderers(bundle, standing.record.manifest).each do |renderer|
91
89
  taken[renderer.lang] ||= Installed.new(lang: renderer.lang, bundle: bundle, files: renderer.load)
92
90
  end
93
91
  end
@@ -104,11 +102,11 @@ module Samagotchi
104
102
  def script_path(bundle, file)
105
103
  return nil unless for_installed.any? { |renderer| renderer.bundle == bundle && renderer.files.include?(file) }
106
104
 
107
- provenance = MemoryBundle::Provenance.new(name: bundle)
108
- failure = provenance.script_failure(file, provenance.record&.scripts&.fetch(file, nil))
109
- raise Invalid, failure if failure
105
+ installed = InstalledBundles::Dir.new(name: bundle)
106
+ refusal = installed.file_refusal(:scripts, file, InstalledBundles.standing(bundle)&.record&.scripts&.fetch(file, nil))
107
+ raise Invalid, refusal.text if refusal
110
108
 
111
- File.join(provenance.scripts_dir, file)
109
+ File.join(installed.scripts_dir, file)
112
110
  end
113
111
 
114
112
  # Its parsed renderers; a kept list that doesn't parse is the record's
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../memory_bundle/manifest"
3
+ require_relative "../bundle_manifest"
4
4
  require_relative "../memory_bundle/profile"
5
5
  require_relative "../memory_bundle/source"
6
6
  require_relative "../memory_bundle/system_bundle"
@@ -26,7 +26,7 @@ module Samagotchi
26
26
 
27
27
  # The members installing +profile+ would install now.
28
28
  def to_install(profile)
29
- MemoryBundle::Profile.to_install(MemoryBundle::Manifest.read(dir: dir(profile)))
29
+ MemoryBundle::Profile.to_install(BundleManifest.read(dir: dir(profile)))
30
30
  end
31
31
 
32
32
  private
@@ -478,7 +478,7 @@ module Samagotchi
478
478
 
479
479
  def system_bundle_line(result, dry_run)
480
480
  version = "v#{result.to || result.from}"
481
- standing = MemoryBundle::FileStanding.clauses(MemoryBundle::SystemBundle::BUNDLE_NAME, nil, merged: Array(result.merged),
481
+ standing = InstalledBundles::FileStanding.clauses(MemoryBundle::SystemBundle::BUNDLE_NAME, nil, merged: Array(result.merged),
482
482
  behind: Array(result.behind), dry_run: dry_run).join("; ")
483
483
  text = case result.status
484
484
  when :installed then dry_run ? "would install #{version}" : "#{version} installed"
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Samagotchi
4
+ class Bridge
5
+ # What a running turn's plugin card waits as, from its data: "asks" (an
6
+ # action with a command: check-in's Nudge / Keep going / Stop), else
7
+ # "warn" (level warn: it stays in sight), else nil. The Ruby twin of the
8
+ # page's card_kinds.js cardWait for an in-turn card (TurnAccumulator folds
9
+ # in-turn cards only); spec/shared/card_wait_cases.json pins both.
10
+ module CardWait
11
+ module_function
12
+
13
+ # @param event [Hash] a card event or a drawing's card part event
14
+ # (symbol or string keys)
15
+ # @return [String, nil] "asks", "warn" or nil
16
+ def kind(event)
17
+ return nil unless event.is_a?(Hash)
18
+ return "asks" if Array(field(event, :actions)).any? { |action| command?(action) }
19
+
20
+ field(event, :level).to_s == "warn" ? "warn" : nil
21
+ end
22
+
23
+ # A JavaScript-truthy command (card_kinds.js: `a && a.command`).
24
+ def command?(action)
25
+ return false unless action.is_a?(Hash)
26
+
27
+ command = field(action, :command)
28
+ !(command.nil? || command == false || command == "" || command == 0)
29
+ end
30
+
31
+ def field(hash, key) = hash.key?(key) ? hash[key] : hash[key.to_s]
32
+ end
33
+ end
34
+ end
@@ -6,6 +6,7 @@ require_relative "../steer"
6
6
  require_relative "../tool_output_cut"
7
7
  require_relative "../tool_row_fields"
8
8
  require_relative "../turn_origin"
9
+ require_relative "card_wait"
9
10
  require_relative "turn_notice"
10
11
 
11
12
  module Samagotchi
@@ -149,8 +150,8 @@ module Samagotchi
149
150
  # tool_call_started and, once finished, its tool_call_completed (with
150
151
  # the live activity: action, tool, params, status), a merged_input
151
152
  # (the one synthetic type) per merged prompt, a steer-only
152
- # pending_input_merged per steer, a reminder_injected, and a notice
153
- # part's own event. Card parts only with +cards+ (a finished turn's
153
+ # pending_input_merged per steer, a reminder_injected, a notice
154
+ # part's own event, and a part_settled per settle part. Card parts only with +cards+ (a finished turn's
154
155
  # drawing, chi web's unfold of it): a running turn's join gets its cards
155
156
  # from CardStore's snapshot.
156
157
  # @param started_at [String, nil] the turn's start, on turn_started
@@ -204,6 +205,11 @@ module Samagotchi
204
205
 
205
206
  close_text.call
206
207
  events << part[:event].merge(type: :card, in_turn: true)
208
+ when "settle"
209
+ # Where a card stopped waiting (#fold_card). A join without
210
+ # cards gets it too: a page with no such card ignores it. A
211
+ # mark, not a row: an open text stays open.
212
+ events << { type: :part_settled, of: part[:of], id: part[:id], was: part[:was], now: part[:now] }
207
213
  end
208
214
  end
209
215
  events
@@ -477,11 +483,23 @@ module Samagotchi
477
483
  private_constant :CARD_FIELDS
478
484
 
479
485
  # A card the turn shows in its step; one with an earlier card's id
480
- # replaces that part where it was.
486
+ # replaces that part where it was (its arrival). When that update
487
+ # ends a wait (CardWait: asking, a warning) for another (none, a
488
+ # warning), a settle part marks the place it stopped waiting, where
489
+ # live moved it (cards_place.js upsertCard): { kind: "settle", of:
490
+ # "card", id:, was:, now: }. A card that starts waiting later gets
491
+ # none (live doesn't move it back). A question needs no mark: its own
492
+ # notice parts (question_requested, question_answered /
493
+ # question_cancelled) are its arrival and its settle.
481
494
  def fold_card(parts, event)
482
495
  card = { kind: "card", id: event[:id], event: Marshal.load(Marshal.dump(event.slice(*CARD_FIELDS))) }
483
496
  index = parts.index { |part| part[:kind] == "card" && part[:id] == card[:id] }
484
- index ? parts[index] = card : parts << card
497
+ return parts << card unless index
498
+
499
+ was = CardWait.kind(parts[index][:event])
500
+ parts[index] = card
501
+ now = CardWait.kind(card[:event])
502
+ parts << { kind: "settle", of: "card", id: card[:id], was: was, now: now } if was && was != now && now != "asks"
485
503
  end
486
504
 
487
505
  # The turn's final fold to the hook (#initialize's on_turn_end).
@@ -136,11 +136,11 @@ module Samagotchi
136
136
  @text = File.read(path("manifest.yml"))
137
137
  Dir.mktmpdir("chi-bundle-check-") do |tmp|
138
138
  File.write(File.join(tmp, "manifest.yml"), MemoryBundle::Shas.parseable(@text))
139
- MemoryBundle::Manifest.read(dir: tmp)
140
- rescue MemoryBundle::Manifest::HooksRetired => e
139
+ BundleManifest.read(dir: tmp)
140
+ rescue BundleManifest::HooksRetired => e
141
141
  add(:error, :"hooks-retired", "manifest.yml", e.message, line: manifest_line("hooks"), fix: hooks_fix)
142
142
  nil
143
- rescue MemoryBundle::Manifest::ValidationError => e
143
+ rescue BundleManifest::ValidationError => e
144
144
  add(:error, :manifest, "manifest.yml", e.message.gsub(tmp, display(@dir)))
145
145
  nil
146
146
  end
@@ -149,10 +149,10 @@ module Samagotchi
149
149
  # A source with hooks/*.rb (listed or not) can't be installed: the run
150
150
  # stops there, as after a manifest error (Manifest::HooksRetired.refuse_source_files).
151
151
  def hooks_retired?
152
- files = MemoryBundle::Manifest::HooksRetired.files_in(@dir)
152
+ files = BundleManifest::HooksRetired.files_in(@dir)
153
153
  return false if files.empty?
154
154
 
155
- add(:error, :"hooks-retired", "hooks/", MemoryBundle::Manifest::HooksRetired.for_files(files).message, fix: hooks_fix)
155
+ add(:error, :"hooks-retired", "hooks/", BundleManifest::HooksRetired.for_files(files).message, fix: hooks_fix)
156
156
  true
157
157
  end
158
158
 
@@ -173,7 +173,7 @@ module Samagotchi
173
173
  # only the unknown-key line, as check_floor's call floor does today.
174
174
  def check_keys(manifest)
175
175
  manifest.unknown_keys.each do |key|
176
- add(:warn, :"unknown-key", "manifest.yml", MemoryBundle::Manifest.unknown_key_line(key), line: manifest_line(key),
176
+ add(:warn, :"unknown-key", "manifest.yml", BundleManifest.unknown_key_line(key), line: manifest_line(key),
177
177
  fix: "update chi, or remove #{key}: if it's a typo")
178
178
  end
179
179
  check_key_floor(manifest) unless @installed
@@ -268,7 +268,7 @@ module Samagotchi
268
268
 
269
269
  def check_requires_chi(manifest)
270
270
  line = manifest_line("requires_chi")
271
- if (failure = MemoryBundle::Manifest.requires_chi_failure(manifest.requires_chi, VERSION))
271
+ if (failure = BundleManifest.requires_chi_failure(manifest.requires_chi, VERSION))
272
272
  @too_new = true
273
273
  add(:error, :"requires-chi", "manifest.yml", "this chi can't load it: #{failure}", line: line,
274
274
  fix: "chi update, or lower requires_chi")
@@ -338,11 +338,11 @@ module Samagotchi
338
338
  end
339
339
 
340
340
  # The installed same-named bundle's record; an unreadable one as
341
- # InstalledBundle.unreadable.
341
+ # InstalledBundles::Record.unreadable.
342
342
  def installed_record(name)
343
343
  MemoryBundle::Provenance.new(name: name).record
344
344
  rescue JSON::ParserError, SystemCallError => e
345
- MemoryBundle::InstalledBundle.unreadable(name, "#{e.class}: #{e.message.lines.first&.strip}")
345
+ InstalledBundles::Record.unreadable(name, "#{e.class}: #{e.message.lines.first&.strip}")
346
346
  end
347
347
 
348
348
  def unreadable_clash(name, error)
@@ -373,7 +373,7 @@ module Samagotchi
373
373
  # The loaders refuse a bundle requires_chi rules out: that's the requires-chi error.
374
374
  result.failures.each { |failure| install_failure(failure) unless @too_new && failure.reason.include?("it requires chi") }
375
375
  report_registered(manifest, result.registered)
376
- rescue MemoryBundle::Installer::InstallError, MemoryBundle::Manifest::ValidationError => e
376
+ rescue MemoryBundle::Installer::InstallError, BundleManifest::ValidationError => e
377
377
  add(:error, :install, "manifest.yml", e.message)
378
378
  rescue StandardError => e
379
379
  # Whatever else the install or the load raised: one finding, not a trace.
@@ -24,7 +24,7 @@ module Samagotchi
24
24
 
25
25
  module_function
26
26
 
27
- # @param bundle [MemoryBundle::InstalledBundle]
27
+ # @param bundle [InstalledBundles::Record]
28
28
  # @return [Array<Found>] its warnings and errors; never raises for the bundle
29
29
  def run(bundle)
30
30
  $stdout.flush
@@ -59,7 +59,7 @@ module Samagotchi
59
59
 
60
60
  # What the child sends: an edited file, which the copy's own shas can't
61
61
  # tell, a manifest key that doesn't parse (the copy holds the mirror's
62
- # value or none: InstalledManifest#key_problems), and Check's warnings
62
+ # value or none: InstalledBundles::Manifest#key_problems), and Check's warnings
63
63
  # and errors, naming the installed bundle's folder rather than the copy's.
64
64
  def answer_of(bundle)
65
65
  edited = MemoryBundle::ShippedUpdate.edited_executables(bundle.name, bundle).map do |file|
@@ -109,7 +109,7 @@ module Samagotchi
109
109
  # Installs the tried bundle, then the shipped guardrails and
110
110
  # cost-cap (unless it is one of them), each as `chi bundle install
111
111
  # PATH --force` in one child chi with the sandbox's environment.
112
- # @return [MemoryBundle::Manifest]
112
+ # @return [BundleManifest]
113
113
  # @raise [Error] what the first install that failed printed
114
114
  def install
115
115
  paths = [@path] + %w[guardrails cost-cap].reject { |name| @manifest.name == name }
@@ -171,13 +171,13 @@ module Samagotchi
171
171
  raise Error, "chi bundle try: stale or placeholder sha256 in manifest.yml; run chi bundle check --fix"
172
172
  end
173
173
 
174
- @manifest = MemoryBundle::Manifest.read(dir: @path)
174
+ @manifest = BundleManifest.read(dir: @path)
175
175
  if @manifest.meta?
176
176
  raise Error.new("chi bundle try: profile bundles cannot be tried directly", status: CLI::Exit::USAGE)
177
177
  end
178
178
 
179
179
  @manifest
180
- rescue MemoryBundle::Manifest::ValidationError => e
180
+ rescue BundleManifest::ValidationError => e
181
181
  raise Error, "chi bundle try: #{e.message}"
182
182
  rescue MemoryBundle::Shas::Error => e
183
183
  raise Error, "chi bundle try: #{e.message}"
@@ -282,10 +282,10 @@ module Samagotchi
282
282
  # @return [Array(MemoryBundle::PreparedSource, String), nil]
283
283
  def prepare_or_fail(expanded_source, word)
284
284
  prepared = Samagotchi::MemoryBundle::PreparedSource.prepare(expanded_source)
285
- Samagotchi::MemoryBundle::Manifest::HooksRetired.refuse_source_files(prepared.dir)
286
- named = [prepared, Samagotchi::MemoryBundle::Manifest.read(dir: prepared.dir).name]
285
+ Samagotchi::BundleManifest::HooksRetired.refuse_source_files(prepared.dir)
286
+ named = [prepared, Samagotchi::BundleManifest.read(dir: prepared.dir).name]
287
287
  rescue Samagotchi::MemoryBundle::SourceNormalizer::UnknownSourceError,
288
- Samagotchi::MemoryBundle::Manifest::ValidationError => e
288
+ Samagotchi::BundleManifest::ValidationError => e
289
289
  @stderr.puts "#{word} failed: #{e.message}"
290
290
  ensure
291
291
  # Any failure (an unexpected error too) removes the extract.
@@ -305,7 +305,7 @@ module Samagotchi
305
305
  identity = Samagotchi::MemoryBundle::SourceIdentity.of(expanded_source)
306
306
  return false unless identity
307
307
 
308
- other, = Samagotchi::MemoryBundle::Provenance.each_installed.find do |name, bundle|
308
+ other, = Samagotchi::InstalledBundles.each.find do |name, bundle|
309
309
  name != bundle_name && !bundle.error? && Samagotchi::MemoryBundle::SourceIdentity.of(bundle.source) == identity
310
310
  end
311
311
  return false unless other
@@ -343,13 +343,13 @@ module Samagotchi
343
343
  return unless plugin && manifest&.plugin
344
344
 
345
345
  # Installed with --force past its requires_chi: the Engine won't load it.
346
- failure = Samagotchi::MemoryBundle::Manifest.requires_chi_failure(manifest.requires_chi, Samagotchi::VERSION)
346
+ failure = Samagotchi::BundleManifest.requires_chi_failure(manifest.requires_chi, Samagotchi::VERSION)
347
347
  @stdout.puts "Plugin: #{manifest.plugin[:file]} (#{failure ? "won't load on this chi: #{failure}" : "loads at the next chi start"})"
348
348
  end
349
349
 
350
350
  # @return [Integer] 0
351
351
  def print_provenance(bundle_name, manifest)
352
- @stdout.puts "Provenance written to: #{Samagotchi::MemoryBundle::Provenance.bundles_dir}/#{bundle_name}/" if manifest
352
+ @stdout.puts "Provenance written to: #{Samagotchi::InstalledBundles.dir}/#{bundle_name}/" if manifest
353
353
  0
354
354
  end
355
355
 
@@ -370,9 +370,9 @@ module Samagotchi
370
370
  # result, with how many sessions and the command for each. Nothing when the
371
371
  # plugin is unchanged or there never was one, nothing with no worker that
372
372
  # can be restarted.
373
- # @param before [InstalledBundle, nil] the bundle's record as it was before
373
+ # @param before [InstalledBundles::Record, nil] the bundle's record as it was before
374
374
  # the run (an uninstall deletes it, so take it first)
375
- # @param manifest [MemoryBundle::Manifest, nil] the manifest this run
375
+ # @param manifest [BundleManifest, nil] the manifest this run
376
376
  # installed; nil for an uninstall
377
377
  # @param installer [Installer, nil] the run, for what it wrote to the plugin
378
378
  def restart_hint(before, manifest = nil, installer = nil)
@@ -402,7 +402,7 @@ module Samagotchi
402
402
 
403
403
  # @return [Integer] 0 all resolved, CONFLICTS_KEPT kept some edits
404
404
  def upgrade_conflicts(installer, bundle_name, expanded_source, agent)
405
- standing = Samagotchi::MemoryBundle::FileStanding
405
+ standing = Samagotchi::InstalledBundles::FileStanding
406
406
  @stdout.puts "\n#{standing.stay_behind(installer.behind.size)}: #{installer.behind.map(&:file).join(", ")}"
407
407
  launch = if agent.nil? && @stdin.tty?
408
408
  @stdout.print "Launch an interactive agent to merge them? [y/N] "
@@ -444,7 +444,7 @@ module Samagotchi
444
444
  marked, clean = changed.partition { |_, info| merger.markers?(info[:current]) }
445
445
  settled = Samagotchi::MemoryBundle::Provenance.new(name: bundle_name).resolve_conflicts(clean.to_h)
446
446
  gone = clean.map(&:first) - settled
447
- standing = Samagotchi::MemoryBundle::FileStanding
447
+ standing = Samagotchi::InstalledBundles::FileStanding
448
448
  untouched.each { |key, _| @stdout.puts standing.still_behind(:untouched, key) }
449
449
  marked.each { |key, _| @stdout.puts standing.still_behind(:markers, key) }
450
450
  gone.each { |key| @stdout.puts standing.still_behind(:incoming_gone, key) }
@@ -508,7 +508,7 @@ module Samagotchi
508
508
  lines.each { |line| @stdout.puts " #{line}" }
509
509
  @stdout.puts "(dry-run: no changes written)" if dry_run
510
510
  result.failed? ? 1 : 0
511
- rescue Samagotchi::MemoryBundle::Manifest::ValidationError => e
511
+ rescue Samagotchi::BundleManifest::ValidationError => e
512
512
  @stderr.puts "#{word} failed: #{e.message}"
513
513
  1
514
514
  end
@@ -558,7 +558,7 @@ module Samagotchi
558
558
  else
559
559
  @stdout.puts "Target: #{st.target_dir}"
560
560
  end
561
- standing = Samagotchi::MemoryBundle::FileStanding
561
+ standing = Samagotchi::InstalledBundles::FileStanding
562
562
  st.files.each do |k, info|
563
563
  next @stdout.puts(" #{k}: unchecked") if info[:unchecked]
564
564
 
@@ -595,7 +595,7 @@ module Samagotchi
595
595
  @stdout.puts " includes #{member} [#{state}]"
596
596
  end
597
597
  else
598
- bundles = Samagotchi::MemoryBundle::Provenance.each_installed.to_a
598
+ bundles = Samagotchi::InstalledBundles.each.to_a
599
599
  @stdout.puts "No installed bundles." if bundles.empty?
600
600
  bundles.each do |bname, record|
601
601
  next @stdout.puts(" #{bname} (manifest.json unreadable)") if record.error?
@@ -708,9 +708,9 @@ module Samagotchi
708
708
  # A rule or script keeps no base text: its recorded and current sha256.
709
709
  def diff_asset(asset)
710
710
  @stdout.puts "=== #{asset.label} ==="
711
- current = File.file?(asset.path) ? Samagotchi::MemoryBundle::Provenance.file_sha(asset.path) : "(missing)"
711
+ current = File.file?(asset.path) ? Samagotchi::InstalledBundles::Sha.of_file(asset.path) : "(missing)"
712
712
  edited = asset.edited? ? " (edited after install: the next install replaces it, a copy kept in the trash)" : ""
713
- @stdout.puts "--- recorded sha256=#{Samagotchi::MemoryBundle::Provenance.recorded_sha(asset.recorded)} current sha256=#{current}#{edited}"
713
+ @stdout.puts "--- recorded sha256=#{Samagotchi::InstalledBundles::Sha.recorded(asset.recorded)} current sha256=#{current}#{edited}"
714
714
  end
715
715
 
716
716
  # The base and the file; a marked one also the bundle's text it stays
@@ -779,7 +779,7 @@ module Samagotchi
779
779
  "#{b.includes ? profile_members(b.includes, installed) : "files=#{b.files}"} installed=#{b.installed_at || "?"}"
780
780
  line += " (shipped v#{b.upgrade.version}: chi bundle upgrade #{b.upgrade.source})" if b.upgrade
781
781
  if b.behind&.any?
782
- count = Samagotchi::MemoryBundle::FileStanding.behind_count(b.behind.size, unsure: b.behind.any?(&:unsure))
782
+ count = Samagotchi::InstalledBundles::FileStanding.behind_count(b.behind.size, unsure: b.behind.any?(&:unsure))
783
783
  line += " (#{count}: chi bundle status #{b.name})"
784
784
  end
785
785
  @stdout.puts line
@@ -1068,7 +1068,7 @@ module Samagotchi
1068
1068
  # A dev install is refused (it already follows its source), and a record
1069
1069
  # whose source is relative, empty or gone says so. nil after such a
1070
1070
  # refusal, written to stderr.
1071
- # @return [Array(String, InstalledBundle, nil), nil] [the source, the
1071
+ # @return [Array(String, InstalledBundles::Record, nil), nil] [the source, the
1072
1072
  # record that named it (nil for a source as given)]
1073
1073
  def upgrade_source(source)
1074
1074
  normalizer = Samagotchi::MemoryBundle::SourceNormalizer