Class: PromptObjects::Env::Importer
- Inherits:
-
Object
- Object
- PromptObjects::Env::Importer
- Defined in:
- lib/prompt_objects/environment/importer.rb
Overview
Imports an environment from a git bundle (.dump file — Declarative Unified Memory Package; legacy .poenv bundles work too). Handles security concerns around custom primitives.
Defined Under Namespace
Classes: InspectResult
Instance Method Summary collapse
-
#has_primitives? ⇒ Boolean
Check if a bundle contains custom primitives.
-
#import(manager:, name:, trust_primitives: false) ⇒ Hash
Import the bundle as a new environment.
-
#initialize(bundle_path) ⇒ Importer
constructor
A new instance of Importer.
-
#inspect_bundle ⇒ InspectResult
Inspect the bundle without importing it.
Constructor Details
#initialize(bundle_path) ⇒ Importer
Returns a new instance of Importer.
25 26 27 |
# File 'lib/prompt_objects/environment/importer.rb', line 25 def initialize(bundle_path) @bundle_path = File.(bundle_path) end |
Instance Method Details
#has_primitives? ⇒ Boolean
Check if a bundle contains custom primitives.
99 100 101 102 |
# File 'lib/prompt_objects/environment/importer.rb', line 99 def has_primitives? result = inspect_bundle result.valid && result.primitives.any? end |
#import(manager:, name:, trust_primitives: false) ⇒ Hash
Import the bundle as a new environment.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/prompt_objects/environment/importer.rb', line 56 def import(manager:, name:, trust_primitives: false) inspect_result = inspect_bundle unless inspect_result.valid return { success: false, error: inspect_result.error } end # Check if environment already exists if manager.environment_exists?(name) return { success: false, error: "Environment '#{name}' already exists" } end # Clone bundle to environment location env_path = manager.environment_path(name) unless Git.clone_bundle(@bundle_path, env_path) return { success: false, error: "Failed to clone bundle" } end # Update manifest with new name if different update_manifest(env_path, name) # Build result with warnings about primitives warnings = [] if inspect_result.primitives.any? && !trust_primitives warnings << "This environment contains #{inspect_result.primitives.count} custom primitive(s):" inspect_result.primitives.each do |prim| warnings << " - #{prim}" end warnings << "Custom primitives will be sandboxed by default." warnings << "Review the code before trusting: #{File.join(env_path, 'primitives')}" end { success: true, path: env_path, name: name, objects: inspect_result.objects, primitives: inspect_result.primitives, warnings: warnings } end |
#inspect_bundle ⇒ InspectResult
Inspect the bundle without importing it. Use this to show the user what's in the bundle before importing.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/prompt_objects/environment/importer.rb', line 32 def inspect_bundle unless File.exist?(@bundle_path) return InspectResult.new(valid: false, error: "Bundle file not found: #{@bundle_path}") end unless valid_bundle? return InspectResult.new(valid: false, error: "Invalid git bundle file") end # Clone to temp dir to inspect contents Dir.mktmpdir("dump_inspect_") do |temp_dir| unless Git.clone_bundle(@bundle_path, temp_dir) return InspectResult.new(valid: false, error: "Failed to extract bundle") end gather_inspect_result(temp_dir) end end |