samagotchi 0.178.0 → 0.180.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 (141) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +58 -1
  3. data/docs/architecture.md +4 -2
  4. data/docs/bundles.md +48 -8
  5. data/docs/cli.md +3 -1
  6. data/docs/configuration.md +1 -1
  7. data/docs/context.md +32 -1
  8. data/docs/guardrails.md +2 -1
  9. data/docs/internals/attached-context.md +26 -4
  10. data/docs/internals/background-tasks.md +5 -1
  11. data/docs/internals/block-renderers.md +4 -3
  12. data/docs/internals/bridge.md +11 -2
  13. data/docs/internals/bundles.md +65 -34
  14. data/docs/internals/engine.md +1 -1
  15. data/docs/internals/web-frontend.md +81 -3
  16. data/docs/plugins.md +20 -5
  17. data/docs/releasing.md +3 -3
  18. data/docs/scheduling.md +4 -0
  19. data/docs/sessions.md +8 -2
  20. data/docs/testing.md +8 -1
  21. data/lib/samagotchi/block_renderers.rb +33 -16
  22. data/lib/samagotchi/bootstrap/bundles.rb +2 -2
  23. data/lib/samagotchi/bootstrap_command.rb +1 -1
  24. data/lib/samagotchi/bridge/card_wait.rb +34 -0
  25. data/lib/samagotchi/bridge/turn_accumulator.rb +22 -4
  26. data/lib/samagotchi/bundle_command/check.rb +10 -10
  27. data/lib/samagotchi/bundle_command/installed_check.rb +2 -2
  28. data/lib/samagotchi/bundle_command/try/sandbox.rb +3 -3
  29. data/lib/samagotchi/bundle_command.rb +22 -18
  30. data/lib/samagotchi/bundle_manifest.rb +579 -0
  31. data/lib/samagotchi/bundle_needs.rb +9 -8
  32. data/lib/samagotchi/bundle_settings_check.rb +13 -9
  33. data/lib/samagotchi/bundles/claude-peer/manifest.yml +5 -3
  34. data/lib/samagotchi/bundles/claude-peer/plugin.rb +4 -4
  35. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +11 -6
  36. data/lib/samagotchi/bundles/codex-peer/manifest.yml +5 -3
  37. data/lib/samagotchi/bundles/codex-peer/plugin.rb +4 -3
  38. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +11 -6
  39. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  40. data/lib/samagotchi/bundles/system/memory_guide.md +1 -1
  41. data/lib/samagotchi/config.rb +2 -2
  42. data/lib/samagotchi/context_absorber.rb +36 -6
  43. data/lib/samagotchi/context_note.rb +8 -5
  44. data/lib/samagotchi/context_providers.rb +30 -29
  45. data/lib/samagotchi/context_sources.rb +42 -12
  46. data/lib/samagotchi/engine/messages.rb +1 -1
  47. data/lib/samagotchi/events.rb +6 -5
  48. data/lib/samagotchi/guardrail_wiring.rb +20 -21
  49. data/lib/samagotchi/guardrails/approval.rb +3 -2
  50. data/lib/samagotchi/guardrails/outside.rb +3 -3
  51. data/lib/samagotchi/{memory_bundle → installed_bundles}/bundle_hook.rb +1 -1
  52. data/lib/samagotchi/installed_bundles/dir.rb +91 -0
  53. data/lib/samagotchi/{memory_bundle → installed_bundles}/file_digest.rb +1 -1
  54. data/lib/samagotchi/{memory_bundle → installed_bundles}/file_standing.rb +2 -2
  55. data/lib/samagotchi/{memory_bundle/installed_manifest.rb → installed_bundles/manifest.rb} +21 -21
  56. data/lib/samagotchi/{memory_bundle → installed_bundles}/plugin_ref.rb +2 -2
  57. data/lib/samagotchi/{memory_bundle/installed_bundle.rb → installed_bundles/record.rb} +17 -17
  58. data/lib/samagotchi/installed_bundles/sha.rb +41 -0
  59. data/lib/samagotchi/installed_bundles/standing.rb +65 -0
  60. data/lib/samagotchi/installed_bundles.rb +105 -0
  61. data/lib/samagotchi/memory_bundle/asset_installer.rb +7 -7
  62. data/lib/samagotchi/memory_bundle/builder.rb +13 -13
  63. data/lib/samagotchi/memory_bundle/file_state.rb +9 -9
  64. data/lib/samagotchi/memory_bundle/installed_copy.rb +6 -6
  65. data/lib/samagotchi/memory_bundle/installer.rb +33 -33
  66. data/lib/samagotchi/memory_bundle/listing.rb +5 -5
  67. data/lib/samagotchi/memory_bundle/manifest_standing.rb +7 -7
  68. data/lib/samagotchi/memory_bundle/merger.rb +15 -15
  69. data/lib/samagotchi/memory_bundle/profile.rb +8 -8
  70. data/lib/samagotchi/memory_bundle/provenance.rb +59 -192
  71. data/lib/samagotchi/memory_bundle/remerge.rb +16 -16
  72. data/lib/samagotchi/memory_bundle/shas.rb +2 -2
  73. data/lib/samagotchi/memory_bundle/shipped_history.rb +1 -1
  74. data/lib/samagotchi/memory_bundle/shipped_update.rb +17 -17
  75. data/lib/samagotchi/memory_bundle/status.rb +19 -16
  76. data/lib/samagotchi/memory_bundle/system_bundle.rb +12 -12
  77. data/lib/samagotchi/memory_bundle/trash.rb +2 -2
  78. data/lib/samagotchi/memory_bundle/uninstaller.rb +8 -8
  79. data/lib/samagotchi/memory_bundle.rb +2 -2
  80. data/lib/samagotchi/memory_command.rb +4 -4
  81. data/lib/samagotchi/{memory_bundle → memory_index}/entry_size.rb +8 -8
  82. data/lib/samagotchi/{memory_bundle/index_size.rb → memory_index/size.rb} +6 -6
  83. data/lib/samagotchi/{memory_bundle/index_sync.rb → memory_index/sync.rb} +5 -5
  84. data/lib/samagotchi/{memory_bundle/index_updater.rb → memory_index/updater.rb} +2 -2
  85. data/lib/samagotchi/memory_usage.rb +5 -5
  86. data/lib/samagotchi/muted_memories.rb +1 -1
  87. data/lib/samagotchi/peer_exchanges.rb +76 -0
  88. data/lib/samagotchi/plugin/context.rb +4 -0
  89. data/lib/samagotchi/plugin/loader.rb +35 -33
  90. data/lib/samagotchi/plugin/peer.rb +42 -11
  91. data/lib/samagotchi/project_subfolders.rb +9 -9
  92. data/lib/samagotchi/reply_wait/target.rb +11 -4
  93. data/lib/samagotchi/self_report.rb +14 -14
  94. data/lib/samagotchi/session_access/local.rb +16 -1
  95. data/lib/samagotchi/session_access/remote.rb +2 -1
  96. data/lib/samagotchi/session_config.rb +29 -19
  97. data/lib/samagotchi/session_manager/running_tasks.rb +15 -2
  98. data/lib/samagotchi/session_retention.rb +13 -4
  99. data/lib/samagotchi/session_stores.rb +3 -0
  100. data/lib/samagotchi/system_prompt.rb +4 -4
  101. data/lib/samagotchi/terminal_ui/attach_launcher.rb +5 -1
  102. data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
  103. data/lib/samagotchi/terminal_ui/formatting.rb +15 -5
  104. data/lib/samagotchi/terminal_ui/join_replay.rb +1 -1
  105. data/lib/samagotchi/terminal_ui/model_segments_text.rb +5 -5
  106. data/lib/samagotchi/terminal_ui.rb +4 -1
  107. data/lib/samagotchi/testing/bundle.rb +3 -3
  108. data/lib/samagotchi/testing/install.rb +3 -3
  109. data/lib/samagotchi/testing/sandbox.rb +2 -2
  110. data/lib/samagotchi/tool_runner.rb +14 -14
  111. data/lib/samagotchi/tools/memory.rb +22 -22
  112. data/lib/samagotchi/tools/task_runtime.rb +12 -3
  113. data/lib/samagotchi/update_command.rb +4 -4
  114. data/lib/samagotchi/version.rb +1 -1
  115. data/lib/samagotchi/web/app.rb +14 -1
  116. data/lib/samagotchi/web/message_display.rb +6 -0
  117. data/lib/samagotchi/web/participant_view.rb +1 -1
  118. data/lib/samagotchi/web/proxy_gate.rb +1 -0
  119. data/lib/samagotchi/web/public/app.js +13 -1
  120. data/lib/samagotchi/web/public/card_kinds.js +8 -3
  121. data/lib/samagotchi/web/public/cards_place.js +15 -1
  122. data/lib/samagotchi/web/public/context_chips.js +184 -49
  123. data/lib/samagotchi/web/public/ctx.js +1 -1
  124. data/lib/samagotchi/web/public/history_shape.js +8 -3
  125. data/lib/samagotchi/web/public/index.html +66 -0
  126. data/lib/samagotchi/web/public/peer_chip.js +171 -0
  127. data/lib/samagotchi/web/public/peer_data.js +119 -0
  128. data/lib/samagotchi/web/public/peer_exchange.js +83 -0
  129. data/lib/samagotchi/web/public/peer_links.js +161 -0
  130. data/lib/samagotchi/web/public/peer_note.js +49 -0
  131. data/lib/samagotchi/web/public/session_view.js +6 -1
  132. data/lib/samagotchi/web/public/stream_handlers.js +17 -4
  133. data/lib/samagotchi/web/public/turn_block.js +46 -8
  134. data/lib/samagotchi/web/public/turn_html.js +11 -2
  135. data/lib/samagotchi/web/public/turn_settle.js +117 -0
  136. data/lib/samagotchi/web/push/notifier.rb +2 -2
  137. data/lib/samagotchi/web/session_access_routes.rb +21 -1
  138. data/lib/samagotchi/web/session_hub.rb +20 -4
  139. data/lib/samagotchi/worker_boot.rb +4 -1
  140. metadata +24 -12
  141. data/lib/samagotchi/memory_bundle/manifest.rb +0 -581
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require_relative "memory_paths"
5
+ require_relative "installed_bundles/file_digest"
6
+ require_relative "installed_bundles/sha"
7
+ require_relative "installed_bundles/record"
8
+ require_relative "installed_bundles/dir"
9
+ require_relative "installed_bundles/standing"
10
+
11
+ module Samagotchi
12
+ # What is installed (the records under <system memories>/.bundles/, see
13
+ # MemoryPaths) and what the runtime reads of it: each record (Record), its
14
+ # manifest (Manifest), one bundle's folder (Dir) and the shas its files are
15
+ # checked against (Sha). The read side only: installing, upgrading and
16
+ # removing a bundle is MemoryBundle's, which builds on this and never the
17
+ # reverse (docs/internals/bundles.md).
18
+ module InstalledBundles
19
+ # What reading a manifest.json may raise: it doesn't parse, it holds a
20
+ # key that isn't UTF-8 (which can't be a symbol), or it can't be read.
21
+ UNREADABLE = [JSON::ParserError, EncodingError, SystemCallError].freeze
22
+
23
+ def self.dir
24
+ MemoryPaths.bundles_dir
25
+ end
26
+
27
+ # Yields [name, bundle] for each installed bundle (a dir under
28
+ # .dir holding a manifest.json, dot dirs aside), by name. bundle
29
+ # is its Record, one with error set when manifest.json doesn't
30
+ # parse or isn't an object; the rest still come.
31
+ #
32
+ # With holding: (:hooks, :guardrails or :plugin) only the bundles
33
+ # whose manifest has a non-empty mapping under that key come, and a
34
+ # manifest that doesn't parse comes (with error) only when its bundle
35
+ # has that dir (hooks/, guardrails/, plugin/): what it would load
36
+ # can't be checked. One that isn't an object is skipped there.
37
+ # @param dir [String] the bundles dir (.dir by default)
38
+ def self.each(holding: nil, dir: InstalledBundles.dir)
39
+ return enum_for(:each, holding: holding, dir: dir) unless block_given?
40
+ return unless ::Dir.exist?(dir)
41
+
42
+ ::Dir.children(dir).reject { |e| e.start_with?(".") }.sort.each do |name|
43
+ mjson = File.join(dir, name, "manifest.json")
44
+ next unless File.exist?(mjson)
45
+
46
+ begin
47
+ data = JSON.parse(File.read(mjson), symbolize_names: true)
48
+ rescue *UNREADABLE => e
49
+ yield name, unreadable(name, e) if holding.nil? || ::Dir.exist?(File.join(dir, name, holding.to_s))
50
+ next
51
+ end
52
+ next if holding && !(data.is_a?(Hash) && data[holding].is_a?(Hash) && !data[holding].empty?)
53
+
54
+ yield name, Record.parse(name, data, File.join(dir, name))
55
+ end
56
+ end
57
+
58
+ # Each installed bundle's Standing (.each's walk and holding:, by name):
59
+ # whether chi may use it, before any of its files is looked at.
60
+ # @yieldparam standing [Standing]
61
+ # @return [Enumerator<Standing>] without a block
62
+ def self.standings(holding: nil, dir: InstalledBundles.dir)
63
+ return enum_for(:standings, holding: holding, dir: dir) unless block_given?
64
+
65
+ each(holding: holding, dir: dir) { |name, record| yield Standing.of(name, record) }
66
+ end
67
+
68
+ # One installed bundle's Standing, by name (one record read, no walk); a
69
+ # manifest.json that doesn't read is :unreadable, in .each's words.
70
+ # @return [Standing, nil] nil when it isn't installed
71
+ def self.standing(name, dir: InstalledBundles.dir)
72
+ record = begin
73
+ Dir.new(name: name, dir: dir).record
74
+ rescue *UNREADABLE => e
75
+ unreadable(name, e)
76
+ end
77
+ record && Standing.of(name, record)
78
+ end
79
+
80
+ # The one record of a manifest.json that raised +error+ when read.
81
+ def self.unreadable(name, error) = Record.unreadable(name, "manifest.json is unreadable: #{error.message}")
82
+ private_class_method :unreadable
83
+
84
+ # The other installed bundles of +scope+ whose record lists the memory
85
+ # file +file_key+, by name (a manifest that doesn't read is left out).
86
+ # A project-scoped record doesn't say which project: one from another
87
+ # repo counts too, which errs on keeping the file.
88
+ # A record that doesn't read is skipped off the record itself (warned of
89
+ # once, as Standing.of does): a claimant check reads no manifest
90
+ # (Standing's requires_chi is no question here).
91
+ def self.claimants(file_key, scope:, except: nil, dir: InstalledBundles.dir)
92
+ each(dir: dir).filter_map do |name, record|
93
+ next if name == except
94
+
95
+ if record.error?
96
+ Standing.warn_unreadable(name, record.error)
97
+ next
98
+ end
99
+ next unless record.effective_scope == scope.to_s && record.owns?(file_key)
100
+
101
+ name
102
+ end
103
+ end
104
+ end
105
+ end
@@ -3,8 +3,8 @@
3
3
  require "fileutils"
4
4
  require_relative "asset_state"
5
5
  require_relative "file_actions"
6
- require_relative "file_digest"
7
- require_relative "manifest"
6
+ require_relative "../installed_bundles/file_digest"
7
+ require_relative "../bundle_manifest"
8
8
  require_relative "provenance"
9
9
  require_relative "../version"
10
10
 
@@ -42,8 +42,8 @@ module Samagotchi
42
42
  DRY_WORDS = { installed: :would_install, updated: :would_update, up_to_date: :up_to_date }.freeze
43
43
 
44
44
  # @param source_dir [String] the normalized bundle source
45
- # @param manifest [Manifest, nil] nil for a non-strict install without one
46
- # @param existing [InstalledBundle, nil] the record before this install
45
+ # @param manifest [BundleManifest, nil] nil for a non-strict install without one
46
+ # @param existing [InstalledBundles::Record, nil] the record before this install
47
47
  # @param results, warnings, conflicts the Installer's (results and
48
48
  # warnings are added to)
49
49
  # @param trash [Trash] the Installer's
@@ -170,7 +170,7 @@ module Samagotchi
170
170
  return {} unless plugin
171
171
 
172
172
  src = plugin_source
173
- if (failure = Manifest.requires_chi_failure(@manifest.requires_chi, @chi_version))
173
+ if (failure = BundleManifest.requires_chi_failure(@manifest.requires_chi, @chi_version))
174
174
  @warnings << "Plugin #{plugin[:file]} won't load: #{failure}"
175
175
  end
176
176
  { plugin[:file] => src }
@@ -259,7 +259,7 @@ module Samagotchi
259
259
  @results[result_key(kind_of_file, name)] = results[name]
260
260
  FileUtils.chmod(0o755, dest) if kind_of_file == :script && !@dev
261
261
  if (declared = declared_sha(kind_of_file, name)) && results[name].action.do == :write_incoming && @strict && !@dev
262
- warning = FileDigest.mismatch("#{kind_of_file} #{name}", dest, declared)
262
+ warning = InstalledBundles::FileDigest.mismatch("#{kind_of_file} #{name}", dest, declared)
263
263
  @warnings << warning if warning
264
264
  end
265
265
  [name, dest]
@@ -320,7 +320,7 @@ module Samagotchi
320
320
  def warn_rules_requires_chi(rule_files)
321
321
  return if @manifest.nil? || rule_files.empty?
322
322
 
323
- if (failure = Manifest.requires_chi_failure(@manifest.requires_chi, @chi_version))
323
+ if (failure = BundleManifest.requires_chi_failure(@manifest.requires_chi, @chi_version))
324
324
  @warnings << "Bundle #{@name}: its guardrail rules won't load: #{failure}; until chi is updated " \
325
325
  "(chi update), guarded tool calls are refused"
326
326
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "digest"
4
- require_relative "file_digest"
4
+ require_relative "../installed_bundles/file_digest"
5
5
  require "fileutils"
6
6
  require "tmpdir"
7
- require_relative "manifest"
7
+ require_relative "../bundle_manifest"
8
8
  require_relative "placeholder"
9
9
  require_relative "../memory_paths"
10
10
  require_relative "../model_overlay"
@@ -16,7 +16,7 @@ module Samagotchi
16
16
  # record's hooks/ isn't built).
17
17
  #
18
18
  # Inverse of Installer: reads from the resolved scope directory,
19
- # computes SHA256 checksums, writes manifest.yml via Manifest.write,
19
+ # computes SHA256 checksums, writes manifest.yml via BundleManifest.write,
20
20
  # and optionally zips/tars the staging directory.
21
21
  class Builder
22
22
  class BuildError < StandardError; end
@@ -26,7 +26,7 @@ module Samagotchi
26
26
 
27
27
  # What a build takes from the installed bundle of the same name (its
28
28
  # record and its dir), else from the scope dir:
29
- # record the InstalledBundle, nil when none is installed (or
29
+ # record the InstalledBundles::Record, nil when none is installed (or
30
30
  # it doesn't read)
31
31
  # rules guardrails/*.yml paths
32
32
  # plugin the installed plugin file, nil without one
@@ -139,7 +139,7 @@ module Samagotchi
139
139
  end
140
140
 
141
141
  # The installed bundle's guardrail rules, plugin, scripts, context
142
- # providers and block renderers (its InstalledManifest's). Without
142
+ # providers and block renderers (its InstalledBundles::Manifest's). Without
143
143
  # rules in a record, the scope dir's guardrails/*.yml (building from a
144
144
  # raw bundle dir that is also the memories dir).
145
145
  # @return [InstalledParts]
@@ -187,7 +187,7 @@ module Samagotchi
187
187
  end
188
188
 
189
189
  # manifest.yml for the staged bundle: requires_chi, needs, session_settings and settings (typed) and the
190
- # file descriptions come from the installed bundle's manifest (InstalledManifest), the
190
+ # file descriptions come from the installed bundle's manifest (InstalledBundles::Manifest), the
191
191
  # trust_level and description from the CLI else that manifest. A key of its kept manifest.yml
192
192
  # this chi doesn't know is carried as installed (the build is the bundle again), with a warning.
193
193
  def write_manifest(staging, name, version, files_map, parts)
@@ -195,7 +195,7 @@ module Samagotchi
195
195
  trust_level = @trust_level
196
196
  trust_level = manifest.trust_level if (trust_level.nil? || trust_level.empty?) && manifest&.trust_level
197
197
  description = @description.empty? && manifest&.description ? manifest.description : @description
198
- Manifest.write(
198
+ BundleManifest.write(
199
199
  dir: staging,
200
200
  name: name,
201
201
  version: version,
@@ -203,11 +203,11 @@ module Samagotchi
203
203
  description: description,
204
204
  files: files_map,
205
205
  trust_level: trust_level,
206
- plugin: parts.plugin && { file: File.basename(parts.plugin), sha256: FileDigest.sha256(parts.plugin),
206
+ plugin: parts.plugin && { file: File.basename(parts.plugin), sha256: InstalledBundles::FileDigest.sha256(parts.plugin),
207
207
  required: manifest&.plugin_required },
208
208
  requires_chi: manifest&.requires_chi,
209
209
  needs: manifest&.needs,
210
- scripts: parts.scripts.transform_values { |src| FileDigest.sha256(src) },
210
+ scripts: parts.scripts.transform_values { |src| InstalledBundles::FileDigest.sha256(src) },
211
211
  context_providers: parts.context_providers,
212
212
  block_renderers: parts.block_renderers,
213
213
  file_descriptions: manifest ? manifest.file_descriptions.slice(*files_map.keys) : {},
@@ -224,7 +224,7 @@ module Samagotchi
224
224
  kept = YAML.load_file(record.kept_manifest_path) || {}
225
225
  File.write(path, YAML.dump(YAML.load_file(path).merge(kept.slice(*manifest.unknown_keys))))
226
226
  manifest.unknown_keys.each do |key|
227
- @warnings << "#{Manifest.unknown_key_line(key)}; the build carries it as installed"
227
+ @warnings << "#{BundleManifest.unknown_key_line(key)}; the build carries it as installed"
228
228
  end
229
229
  end
230
230
 
@@ -258,10 +258,10 @@ module Samagotchi
258
258
  return unless Profile.installed_meta?(name, record)
259
259
 
260
260
  shipped = File.join(SourceNormalizer::SHIPPED_DIR, name)
261
- members = Profile.recorded(record, File.file?(File.join(shipped, "manifest.yml")) ? Manifest.read(dir: shipped) : nil)
261
+ members = Profile.recorded(record, File.file?(File.join(shipped, "manifest.yml")) ? BundleManifest.read(dir: shipped) : nil)
262
262
  raise BuildError, "#{name} is an installed profile (includes: #{members.join(", ")}): it ships only its includes, " \
263
263
  "so a build can't remake it; pick another --name for these memories"
264
- rescue JSON::ParserError, SystemCallError, Manifest::ValidationError
264
+ rescue JSON::ParserError, SystemCallError, BundleManifest::ValidationError
265
265
  nil
266
266
  end
267
267
 
@@ -280,7 +280,7 @@ module Samagotchi
280
280
  def leave_out_owned(candidates, name)
281
281
  require_relative "provenance"
282
282
  owners = candidates.to_h do |path|
283
- [path, Provenance.claimants(File.basename(path), scope: @scope, except: name)]
283
+ [path, InstalledBundles.claimants(File.basename(path), scope: @scope, except: name)]
284
284
  end
285
285
  left_out = owners.reject { |_, names| names.empty? }
286
286
  left_out.each do |path, names|
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "file_digest"
4
- require_relative "installed_bundle"
3
+ require_relative "../installed_bundles/file_digest"
4
+ require_relative "../installed_bundles/record"
5
5
  require_relative "provenance"
6
6
 
7
7
  module Samagotchi
@@ -41,7 +41,7 @@ module Samagotchi
41
41
  # from #edited? alone.
42
42
  #
43
43
  # mark: :none, :current (a mark this chi wrote) or :legacy (an older
44
- # chi's, InstalledBundle.legacy_mark?).
44
+ # chi's, InstalledBundles::Record.legacy_mark?).
45
45
  FileState = Data.define(:key, :kind, :mark, :digests, :entry, :paths, :claimants) do
46
46
  # Provenance.unchanged?'s answer negated: the one edited rule (checksum
47
47
  # first, then the base). A file it can't read counts as edited.
@@ -63,7 +63,7 @@ module Samagotchi
63
63
  end
64
64
 
65
65
  # The other installed bundles that list the file too. Asked lazily: only
66
- # a dropped file and an uninstall need it (Provenance.claimants reads
66
+ # a dropped file and an uninstall need it (InstalledBundles.claimants reads
67
67
  # every record).
68
68
  def shared_with = claimants.call
69
69
  end
@@ -75,12 +75,12 @@ module Samagotchi
75
75
  FileState::Digests = Data.define(:disk, :base, :incoming, :recorded, :marked_incoming)
76
76
 
77
77
  class << FileState
78
- # @param record [InstalledBundle, nil] the bundle's record
78
+ # @param record [InstalledBundles::Record, nil] the bundle's record
79
79
  # @param provenance [Provenance] the record's (for the base path)
80
80
  # @param source_dir [String, nil] the bundle's incoming dir; nil: the
81
81
  # source-less kinds
82
82
  # @param claimants [#call, nil] key => other bundles listing it
83
- # (Provenance.claimants), called at most once
83
+ # (InstalledBundles.claimants), called at most once
84
84
  # @param shipped [Boolean] false: the bundle no longer ships the key
85
85
  # (a dropped kind), whatever its source dir holds by that name
86
86
  # @return [FileState]
@@ -92,7 +92,7 @@ module Samagotchi
92
92
  mark = mark_of(entry)
93
93
  digests = FileState::Digests.new(
94
94
  disk: digest(paths[:current]), base: entry ? digest(paths[:base]) : nil,
95
- incoming: source_dir && shipped ? digest(paths[:incoming]) : nil, recorded: entry && Provenance.recorded_sha(entry[:checksum]),
95
+ incoming: source_dir && shipped ? digest(paths[:incoming]) : nil, recorded: entry && InstalledBundles::Sha.recorded(entry[:checksum]),
96
96
  marked_incoming: mark == :none ? nil : entry[:incoming_sha]
97
97
  )
98
98
  if !pending.empty? && pending.include?(digests.disk)
@@ -112,11 +112,11 @@ module Samagotchi
112
112
  def mark_of(entry)
113
113
  return :none unless entry && entry[:conflict]
114
114
 
115
- InstalledBundle.legacy_mark?(entry) ? :legacy : :current
115
+ InstalledBundles::Record.legacy_mark?(entry) ? :legacy : :current
116
116
  end
117
117
 
118
118
  def digest(path)
119
- FileDigest.hex(path)
119
+ InstalledBundles::FileDigest.hex(path)
120
120
  rescue SystemCallError
121
121
  :unreadable
122
122
  end
@@ -3,7 +3,7 @@
3
3
  require "fileutils"
4
4
  require "tmpdir"
5
5
  require "yaml"
6
- require_relative "manifest"
6
+ require_relative "../bundle_manifest"
7
7
  require_relative "provenance"
8
8
 
9
9
  module Samagotchi
@@ -20,7 +20,7 @@ module Samagotchi
20
20
  # It has no hooks: and no hooks/, whatever the record or the kept
21
21
  # manifest says: class-file hooks don't load (InstalledCheck names a
22
22
  # record's once). Every other key is the kept
23
- # manifest.yml's when it is read (InstalledManifest origin :kept), so the
23
+ # manifest.yml's when it is read (InstalledBundles::Manifest origin :kept), so the
24
24
  # check sees its unknown keys too; else the record's mirror's.
25
25
  #
26
26
  # The shas are the files' own, so an edited plugin is checked as written.
@@ -29,7 +29,7 @@ module Samagotchi
29
29
  module InstalledCopy
30
30
  module_function
31
31
 
32
- # @param bundle [InstalledBundle] a readable one, not a profile
32
+ # @param bundle [InstalledBundles::Record] a readable one, not a profile
33
33
  # @yieldparam dir [String] the folder, removed after the block
34
34
  def with(bundle)
35
35
  Dir.mktmpdir("chi-installed-copy-") do |tmp|
@@ -42,7 +42,7 @@ module Samagotchi
42
42
 
43
43
  def write(bundle, provenance, dir)
44
44
  manifest = bundle.manifest
45
- Manifest.write(
45
+ BundleManifest.write(
46
46
  dir: dir, name: bundle.name, version: bundle.version.to_s.empty? ? "0" : bundle.version, trust_level: manifest.trust_level,
47
47
  files: memories(bundle, provenance, dir),
48
48
  file_descriptions: manifest.file_descriptions,
@@ -63,7 +63,7 @@ module Samagotchi
63
63
  INSTALLED_KEYS = %w[name version files hooks plugin scripts].freeze
64
64
 
65
65
  # The written manifest's INSTALLED_KEYS and +failed+ keys (the value
66
- # InstalledManifest fell back to: InstalledCheck already names the
66
+ # InstalledBundles::Manifest fell back to: InstalledCheck already names the
67
67
  # problem, and the raw value would name it again), then the kept
68
68
  # manifest's other keys. A kept file of comments only holds none.
69
69
  def keep_manifest_keys(kept, written, failed)
@@ -102,7 +102,7 @@ module Samagotchi
102
102
 
103
103
  FileUtils.mkdir_p(File.dirname(to))
104
104
  FileUtils.cp(from, to)
105
- "sha256:#{Provenance.file_sha(to)}"
105
+ "sha256:#{InstalledBundles::Sha.of_file(to)}"
106
106
  end
107
107
  private_class_method :copy
108
108
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "fileutils"
4
- require_relative "file_digest"
4
+ require_relative "../installed_bundles/file_digest"
5
5
  require_relative "../memory_paths"
6
6
  require_relative "provenance"
7
- require_relative "manifest"
7
+ require_relative "../bundle_manifest"
8
8
  require_relative "source"
9
9
  require_relative "placeholder"
10
- require_relative "index_updater"
10
+ require_relative "../memory_index/updater"
11
11
  require_relative "merger"
12
12
  require_relative "trash"
13
13
  require_relative "asset_installer"
@@ -50,7 +50,7 @@ module Samagotchi
50
50
 
51
51
  attr_reader :results, :warnings, :placeholder_warnings, :conflicts
52
52
 
53
- # Each file this run left behind (FileStanding::Behind).
53
+ # Each file this run left behind (InstalledBundles::FileStanding::Behind).
54
54
  attr_reader :behind
55
55
 
56
56
  # prepared: the source already normalized (a PreparedSource, which the
@@ -183,8 +183,8 @@ module Samagotchi
183
183
  lines << "Would install: #{would_install.join(", ")}" unless would_install.empty?
184
184
  lines << "Would update: #{would_update.join(", ")}" unless would_update.empty?
185
185
  lines << "Fast-forward: #{fast_forward.join(", ")}" unless fast_forward.empty?
186
- lines << FileStanding.merged_line(merged, @manifest&.version) unless merged.empty?
187
- lines << FileStanding.merged_line(would_merge, @manifest&.version, dry_run: true) unless would_merge.empty?
186
+ lines << InstalledBundles::FileStanding.merged_line(merged, @manifest&.version) unless merged.empty?
187
+ lines << InstalledBundles::FileStanding.merged_line(would_merge, @manifest&.version, dry_run: true) unless would_merge.empty?
188
188
  lines << "Removed (no longer in the bundle): #{removed.join(", ")}#{" (moved to #{trash_dir})" if trash_dir}" unless removed.empty?
189
189
  lines << "Would remove (no longer in the bundle): #{would_remove.join(", ")}" unless would_remove.empty?
190
190
  lines << "Removed (#{AssetInstaller::RETIRED}): #{retired.join(", ")}" unless retired.empty?
@@ -226,7 +226,7 @@ module Samagotchi
226
226
  # @param label [String] "a.md", "plugin plugin.rb", "script s.sh"
227
227
  # @param upgrade [Boolean] which command the hint names
228
228
  def self.mismatch_refusal(label, path, expected, upgrade:)
229
- warning = FileDigest.mismatch(label, path, expected)
229
+ warning = InstalledBundles::FileDigest.mismatch(label, path, expected)
230
230
  warning && "#{warning}; chi bundle #{upgrade ? "upgrade" : "install"} --force installs it anyway"
231
231
  end
232
232
 
@@ -289,9 +289,9 @@ module Samagotchi
289
289
  def write_pending
290
290
  return if @dry_run || @manifest.nil?
291
291
 
292
- incoming = memory_files.to_h { |key| [key, FileDigest.hex(File.join(@bundle_dir, key))] }
292
+ incoming = memory_files.to_h { |key| [key, InstalledBundles::FileDigest.hex(File.join(@bundle_dir, key))] }
293
293
  incoming.reject! do |key, sha|
294
- sha.nil? || sha == FileDigest.hex(File.join(@target_dir, key))
294
+ sha.nil? || sha == InstalledBundles::FileDigest.hex(File.join(@target_dir, key))
295
295
  rescue SystemCallError
296
296
  true
297
297
  end
@@ -351,7 +351,7 @@ module Samagotchi
351
351
  # bundle's dir on a case-insensitive file system (macOS): BTW would
352
352
  # replace btw. Refused, --force too.
353
353
  def refuse_case_twin
354
- twin, = Provenance.each_installed.find { |name, _| name != @name && name.casecmp?(@name) }
354
+ twin, = InstalledBundles.each.find { |name, _| name != @name && name.casecmp?(@name) }
355
355
  raise InstallError, "#{@name} differs only in case from the installed #{twin}" if twin
356
356
  end
357
357
 
@@ -403,8 +403,8 @@ module Samagotchi
403
403
  # samagotchi-system and profiles included.
404
404
  def shipped_names
405
405
  Dir.glob(File.join(@shipped_dir, "*", "manifest.yml")).filter_map do |path|
406
- Manifest.read(dir: File.dirname(path)).name
407
- rescue Manifest::ValidationError
406
+ BundleManifest.read(dir: File.dirname(path)).name
407
+ rescue BundleManifest::ValidationError
408
408
  nil
409
409
  end
410
410
  end
@@ -417,16 +417,16 @@ module Samagotchi
417
417
  @bundle_dir = @source_dir = prepared.dir
418
418
  @source_owned = prepared.owned
419
419
  @source_commit = prepared.commit
420
- Manifest::HooksRetired.refuse_source_files(@bundle_dir)
421
- @manifest = Manifest.read(dir: @bundle_dir)
420
+ BundleManifest::HooksRetired.refuse_source_files(@bundle_dir)
421
+ @manifest = BundleManifest.read(dir: @bundle_dir)
422
422
  clash = @manifest.session_settings_clash
423
423
  raise InstallError, clash if clash
424
424
  rescue SourceNormalizer::UnknownSourceError => e
425
425
  raise InstallError, "Source normalization failed: #{e.message}"
426
- rescue Manifest::HooksRetired => e
426
+ rescue BundleManifest::HooksRetired => e
427
427
  # A rule, not a strictness option: refused strict or not, a dry run too.
428
428
  raise InstallError, e.message
429
- rescue Manifest::ValidationError => e
429
+ rescue BundleManifest::ValidationError => e
430
430
  raise InstallError, e.message if @strict
431
431
 
432
432
  @warnings << "No manifest found — proceeding without strict manifest validation"
@@ -435,11 +435,11 @@ module Samagotchi
435
435
  # A bundle whose requires_chi this chi doesn't meet is not installed at
436
436
  # all: --force is what installs it, and its plugin and rules then
437
437
  # warn that they won't load (AssetInstaller). The words come from
438
- # Manifest.requires_chi_failure, so the requirement is said one way.
438
+ # BundleManifest.requires_chi_failure, so the requirement is said one way.
439
439
  # A dry run is refused the same way: nothing there would load either.
440
440
  # @raise [InstallError]
441
441
  def refuse_too_new
442
- failure = Manifest.requires_chi_failure(@manifest&.requires_chi, @chi_version)
442
+ failure = BundleManifest.requires_chi_failure(@manifest&.requires_chi, @chi_version)
443
443
  return if failure.nil? || @force
444
444
 
445
445
  raise InstallError, "#{@name} can't be installed: #{failure} (chi update, or --force to install it anyway)"
@@ -551,7 +551,7 @@ module Samagotchi
551
551
  end
552
552
  when :skip
553
553
  @results[file_key] = result.with(note: "already exists")
554
- @warnings << "Skipped #{file_key} (already exists; #{FileStanding::FORCE_TAKES})"
554
+ @warnings << "Skipped #{file_key} (already exists; #{InstalledBundles::FileStanding::FORCE_TAKES})"
555
555
  when :refuse then refuse_unreadable(file_key, target_path)
556
556
  else raise ArgumentError, "no install step for #{action.do.inspect} (#{file_key})" # the base would move with nothing written
557
557
  end
@@ -562,7 +562,7 @@ module Samagotchi
562
562
  # run stops (the read raises; Trash.failure_message says nothing was
563
563
  # lost).
564
564
  def refuse_unreadable(file_key, target_path)
565
- FileDigest.hex(target_path)
565
+ InstalledBundles::FileDigest.hex(target_path)
566
566
  raise InstallError, "#{file_key} can't be read"
567
567
  end
568
568
 
@@ -574,7 +574,7 @@ module Samagotchi
574
574
  @results[file_key] = FileResult.new(word: :conflict, state: state, action: state && FileActions::BEHIND,
575
575
  note: behind.state(dry_run: @dry_run))
576
576
  @conflicts[file_key] = upgrade_view.paths(file_key)
577
- @warnings << "#{behind.line(dry_run: @dry_run)} (#{FileStanding::FORCE_TAKES})"
577
+ @warnings << "#{behind.line(dry_run: @dry_run)} (#{InstalledBundles::FileStanding::FORCE_TAKES})"
578
578
  end
579
579
 
580
580
  # What merged, on the record, a run that failed later too: the file holds the
@@ -652,7 +652,7 @@ module Samagotchi
652
652
  result = @results[file_key]
653
653
  next unless result&.action&.takes_source?
654
654
 
655
- warning = FileDigest.mismatch(file_key, result.state.paths[:incoming], @manifest.checksum_for(file_key))
655
+ warning = InstalledBundles::FileDigest.mismatch(file_key, result.state.paths[:incoming], @manifest.checksum_for(file_key))
656
656
  @warnings << warning if warning
657
657
  end
658
658
  end
@@ -708,7 +708,7 @@ module Samagotchi
708
708
  # Provenance#write rebuilds their entries, and a file it left alone has
709
709
  # missed the bundle's change as much as before (its version may move on
710
710
  # all the same). One with the incoming bytes has nothing left to miss.
711
- # @return [Array<FileStanding::Behind>]
711
+ # @return [Array<InstalledBundles::FileStanding::Behind>]
712
712
  def held_conflict_marks
713
713
  return [] if @upgrade || @existing.nil?
714
714
 
@@ -721,11 +721,11 @@ module Samagotchi
721
721
  # so one from an older chi, which can't name sections, keeps its own words.
722
722
  def held_mark(key)
723
723
  entry = @existing.files.fetch(key)
724
- return @existing.behind_entry(key, entry).with(version: @manifest.version) if InstalledBundle.legacy_mark?(entry)
724
+ return @existing.behind_entry(key, entry).with(version: @manifest.version) if InstalledBundles::Record.legacy_mark?(entry)
725
725
 
726
726
  upgrade_view.behind(key, Merger::CONFLICT, @manifest.version)
727
727
  rescue SystemCallError
728
- FileStanding::Behind.new(file: key, version: @manifest.version)
728
+ InstalledBundles::FileStanding::Behind.new(file: key, version: @manifest.version)
729
729
  end
730
730
 
731
731
  # file key => the file whose content becomes its base: the one its
@@ -803,7 +803,7 @@ module Samagotchi
803
803
 
804
804
  target = File.join(target_dir, key)
805
805
  state = FileState.of(key, record: @existing, provenance: provenance, target_dir: target_dir, source_dir: @bundle_dir,
806
- shipped: false, claimants: ->(k) { Provenance.claimants(k, scope: scope, except: @name) })
806
+ shipped: false, claimants: ->(k) { InstalledBundles.claimants(k, scope: scope, except: @name) })
807
807
  action = if state.kind == :unreadable
808
808
  unreadable_dropped(state, target)
809
809
  else
@@ -823,7 +823,7 @@ module Samagotchi
823
823
  remove_target_index(scope, key)
824
824
  when :kept_pruned
825
825
  @results[key] = result.with(note: "local edits preserved")
826
- @warnings << "Kept #{key}: no longer in the bundle but edited locally (#{FileStanding::FORCE_MOVES})"
826
+ @warnings << "Kept #{key}: no longer in the bundle but edited locally (#{InstalledBundles::FileStanding::FORCE_MOVES})"
827
827
  end
828
828
  end
829
829
  end
@@ -836,7 +836,7 @@ module Samagotchi
836
836
  return FileActions::KEPT_SHARED if state.shared_with.any?
837
837
  return FileActions::REMOVE if @force
838
838
 
839
- FileDigest.hex(target)
839
+ InstalledBundles::FileDigest.hex(target)
840
840
  raise InstallError, "#{state.key} can't be read"
841
841
  end
842
842
 
@@ -845,15 +845,15 @@ module Samagotchi
845
845
  # too: the key is in the manifest either way.
846
846
  def warn_unknown_keys(manifest)
847
847
  manifest.unknown_keys.each do |key|
848
- @warnings << "#{Manifest.unknown_key_line(key)}; a newer chi reads it from the installed manifest " \
848
+ @warnings << "#{BundleManifest.unknown_key_line(key)}; a newer chi reads it from the installed manifest " \
849
849
  "(chi update, then chi bundle status #{manifest.name} says whether it needs chi bundle upgrade #{manifest.name})"
850
850
  end
851
851
  end
852
852
 
853
853
  # Not fatal, like update_target_index: a warning says so.
854
854
  def remove_target_index(scope, file_key)
855
- IndexUpdater.remove_index(scope, file_key.delete_suffix(".md"), target_dir: @target_dir)
856
- IndexUpdater.remove_index(scope, file_key, target_dir: @target_dir) # legacy "name.md" line
855
+ MemoryIndex::Updater.remove_index(scope, file_key.delete_suffix(".md"), target_dir: @target_dir)
856
+ MemoryIndex::Updater.remove_index(scope, file_key, target_dir: @target_dir) # legacy "name.md" line
857
857
  rescue StandardError => e
858
858
  @warnings << "index.md: line for #{file_key.delete_suffix(".md")} not removed (#{e.message})"
859
859
  end
@@ -904,10 +904,10 @@ module Samagotchi
904
904
  begin
905
905
  # Index lines use the entry name (as memory_write does); drop the
906
906
  # legacy "name.md" line older installs wrote.
907
- IndexUpdater.remove_index(scope, file_key) unless entry_name == file_key
907
+ MemoryIndex::Updater.remove_index(scope, file_key) unless entry_name == file_key
908
908
  # A manifest's description: for the file; nil keeps the line's.
909
909
  description = owned ? @file_descriptions&.[](file_key) : nil
910
- IndexUpdater.update_index(scope, entry_name, byte_count, description, source: owned ? @name : nil)
910
+ MemoryIndex::Updater.update_index(scope, entry_name, byte_count, description, source: owned ? @name : nil)
911
911
  rescue StandardError => e
912
912
  # Not fatal (the file is in place): a warning says so.
913
913
  @warnings << "index.md: line for #{entry_name} not updated (#{e.message})"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "manifest"
3
+ require_relative "../bundle_manifest"
4
4
  require_relative "source"
5
5
  require_relative "provenance"
6
6
  require_relative "system_bundle"
@@ -16,7 +16,7 @@ module Samagotchi
16
16
  module Listing
17
17
  # error is set (and the rest nil) when the provenance manifest.json
18
18
  # can't be read; includes is a profile's recorded members, else nil;
19
- # behind is its files that stay behind (InstalledBundle#behind_files).
19
+ # behind is its files that stay behind (InstalledBundles::Record#behind_files).
20
20
  Installed = Struct.new(:name, :version, :scope, :files, :installed_at, :upgrade, :error, :includes, :behind, keyword_init: true)
21
21
  # source is the name `chi bundle install` takes (the shipped dir's
22
22
  # name); includes is a profile's members ([] for a plain bundle).
@@ -32,11 +32,11 @@ module Samagotchi
32
32
  Dir.children(dir).sort.filter_map do |source|
33
33
  next unless File.file?(File.join(dir, source, "manifest.yml"))
34
34
 
35
- m = Manifest.read(dir: File.join(dir, source))
35
+ m = BundleManifest.read(dir: File.join(dir, source))
36
36
  next if m.name == SystemBundle::BUNDLE_NAME
37
37
 
38
38
  Shipped.new(name: m.name, source: source, version: m.version, description: m.description, includes: m.includes)
39
- rescue Manifest::ValidationError, Psych::Exception
39
+ rescue BundleManifest::ValidationError, Psych::Exception
40
40
  nil
41
41
  end.sort_by(&:name)
42
42
  end
@@ -44,7 +44,7 @@ module Samagotchi
44
44
  # @return [Array<Installed>] by name; upgrade is the Shipped when it is newer
45
45
  def installed(shipped: self.shipped)
46
46
  by_name = shipped.to_h { |s| [s.name, s] }
47
- Provenance.each_installed.map do |name, bundle|
47
+ InstalledBundles.each.map do |name, bundle|
48
48
  next Installed.new(name: name, error: "manifest.json unreadable") if bundle.error?
49
49
 
50
50
  ship = by_name[name]