Class: PromptObjects::Env::Manifest
- Inherits:
-
Object
- Object
- PromptObjects::Env::Manifest
- Defined in:
- lib/prompt_objects/environment/manifest.rb
Overview
Handles environment manifest files (manifest.yml). Contains metadata about the environment: name, description, timestamps, UI customization, and stats.
Constant Summary collapse
- FILENAME =
"manifest.yml"- FORMAT_VERSION =
Increment when manifest schema changes
1
Instance Attribute Summary collapse
-
#archived_at ⇒ Object
Returns the value of attribute archived_at.
-
#color ⇒ Object
Returns the value of attribute color.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#default_po ⇒ Object
Returns the value of attribute default_po.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#description ⇒ Object
Returns the value of attribute description.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#imported_at ⇒ Object
Returns the value of attribute imported_at.
-
#imported_from ⇒ Object
Returns the value of attribute imported_from.
-
#last_opened ⇒ Object
Returns the value of attribute last_opened.
-
#llm ⇒ Object
Returns the value of attribute llm.
-
#name ⇒ Object
Returns the value of attribute name.
-
#runtime_model ⇒ Object
Returns the value of attribute runtime_model.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.from_hash(data) ⇒ Manifest
Create manifest from a hash (parsed YAML).
-
.load(path) ⇒ Manifest
Load manifest from a file path.
-
.load_from_dir(env_dir) ⇒ Manifest
Load manifest from an environment directory.
-
.parse_time(value) ⇒ Time?
Parse time from various formats.
Instance Method Summary collapse
-
#archived? ⇒ Boolean
Check if this environment was archived.
-
#imported? ⇒ Boolean
Check if this environment was imported.
-
#increment_messages! ⇒ Object
Increment message count.
-
#info ⇒ String
Detailed info string.
-
#initialize(name:, description: nil, created_at: nil, updated_at: nil, last_opened: nil, icon: nil, color: nil, tags: nil, default_po: nil, stats: nil, version: nil, archived_at: nil, imported_from: nil, imported_at: nil, dependencies: nil, runtime_model: nil, llm: nil) ⇒ Manifest
constructor
A new instance of Manifest.
-
#mark_archived! ⇒ Object
Mark as archived with timestamp.
-
#save(path) ⇒ Object
Save manifest to a file.
-
#save_to_dir(env_dir) ⇒ Object
Save manifest to an environment directory.
-
#to_hash ⇒ Hash
Convert to hash for YAML serialization.
-
#to_s ⇒ String
Display string.
-
#touch_opened! ⇒ Object
Mark environment as opened and update timestamp.
-
#update_stats(po_count: nil, session_count: nil, message_count: nil) ⇒ Object
Update stats from environment data.
Constructor Details
#initialize(name:, description: nil, created_at: nil, updated_at: nil, last_opened: nil, icon: nil, color: nil, tags: nil, default_po: nil, stats: nil, version: nil, archived_at: nil, imported_from: nil, imported_at: nil, dependencies: nil, runtime_model: nil, llm: nil) ⇒ Manifest
Returns a new instance of Manifest.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/prompt_objects/environment/manifest.rb', line 20 def initialize( name:, description: nil, created_at: nil, updated_at: nil, last_opened: nil, icon: nil, color: nil, tags: nil, default_po: nil, stats: nil, version: nil, archived_at: nil, imported_from: nil, imported_at: nil, dependencies: nil, runtime_model: nil, llm: nil ) @name = name @description = description @created_at = created_at || Time.now @updated_at = updated_at || Time.now @last_opened = last_opened @icon = icon || "📦" @color = color || "#4A90D9" @tags = || [] @default_po = default_po @stats = stats || { "total_messages" => 0, "total_sessions" => 0, "po_count" => 0 } @version = version || FORMAT_VERSION @archived_at = archived_at @imported_from = imported_from @imported_at = imported_at @dependencies = dependencies || {} @runtime_model = runtime_model || "runs" @llm = llm || {} end |
Instance Attribute Details
#archived_at ⇒ Object
Returns the value of attribute archived_at.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def archived_at @archived_at end |
#color ⇒ Object
Returns the value of attribute color.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def color @color end |
#created_at ⇒ Object
Returns the value of attribute created_at.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def created_at @created_at end |
#default_po ⇒ Object
Returns the value of attribute default_po.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def default_po @default_po end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def dependencies @dependencies end |
#description ⇒ Object
Returns the value of attribute description.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def description @description end |
#icon ⇒ Object
Returns the value of attribute icon.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def icon @icon end |
#imported_at ⇒ Object
Returns the value of attribute imported_at.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def imported_at @imported_at end |
#imported_from ⇒ Object
Returns the value of attribute imported_from.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def imported_from @imported_from end |
#last_opened ⇒ Object
Returns the value of attribute last_opened.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def last_opened @last_opened end |
#llm ⇒ Object
Returns the value of attribute llm.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def llm @llm end |
#name ⇒ Object
Returns the value of attribute name.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def name @name end |
#runtime_model ⇒ Object
Returns the value of attribute runtime_model.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def runtime_model @runtime_model end |
#stats ⇒ Object
Returns the value of attribute stats.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def stats @stats end |
#tags ⇒ Object
Returns the value of attribute tags.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def @tags end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def updated_at @updated_at end |
#version ⇒ Object
Returns the value of attribute version.
15 16 17 |
# File 'lib/prompt_objects/environment/manifest.rb', line 15 def version @version end |
Class Method Details
.from_hash(data) ⇒ Manifest
Create manifest from a hash (parsed YAML).
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/prompt_objects/environment/manifest.rb', line 78 def self.from_hash(data) new( name: data["name"], description: data["description"], created_at: parse_time(data["created_at"]), updated_at: parse_time(data["updated_at"]), last_opened: parse_time(data["last_opened"]), icon: data["icon"], color: data["color"], tags: data["tags"], default_po: data["default_po"], stats: data["stats"], version: data["version"], archived_at: parse_time(data["archived_at"]), imported_from: data["imported_from"], imported_at: parse_time(data["imported_at"]), dependencies: data["dependencies"], runtime_model: data["runtime_model"], llm: data["llm"] ) end |
.load(path) ⇒ Manifest
Load manifest from a file path.
61 62 63 64 65 66 |
# File 'lib/prompt_objects/environment/manifest.rb', line 61 def self.load(path) raise Error, "Manifest not found: #{path}" unless File.exist?(path) data = YAML.safe_load(File.read(path), permitted_classes: [Time, Symbol]) from_hash(data) end |
.load_from_dir(env_dir) ⇒ Manifest
Load manifest from an environment directory.
71 72 73 |
# File 'lib/prompt_objects/environment/manifest.rb', line 71 def self.load_from_dir(env_dir) load(File.join(env_dir, FILENAME)) end |
.parse_time(value) ⇒ Time?
Parse time from various formats.
103 104 105 106 107 108 109 110 |
# File 'lib/prompt_objects/environment/manifest.rb', line 103 def self.parse_time(value) return nil if value.nil? return value if value.is_a?(Time) Time.parse(value) rescue ArgumentError nil end |
Instance Method Details
#archived? ⇒ Boolean
Check if this environment was archived.
185 186 187 |
# File 'lib/prompt_objects/environment/manifest.rb', line 185 def archived? !@archived_at.nil? end |
#imported? ⇒ Boolean
Check if this environment was imported.
179 180 181 |
# File 'lib/prompt_objects/environment/manifest.rb', line 179 def imported? !@imported_from.nil? end |
#increment_messages! ⇒ Object
Increment message count.
167 168 169 |
# File 'lib/prompt_objects/environment/manifest.rb', line 167 def @stats["total_messages"] = (@stats["total_messages"] || 0) + 1 end |
#info ⇒ String
Detailed info string.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/prompt_objects/environment/manifest.rb', line 197 def info lines = [] lines << "#{@icon} #{@name}" lines << " #{@description}" if @description lines << "" lines << " Created: #{@created_at&.strftime('%Y-%m-%d %H:%M')}" lines << " Last opened: #{@last_opened&.strftime('%Y-%m-%d %H:%M')}" if @last_opened lines << " Updated: #{@updated_at&.strftime('%Y-%m-%d %H:%M')}" if @updated_at lines << " LLM: #{@llm['provider']} / #{@llm['model']}" if @llm&.any? if imported? lines << "" lines << " Imported from: #{@imported_from}" lines << " Imported at: #{@imported_at&.strftime('%Y-%m-%d %H:%M')}" end if archived? lines << "" lines << " Archived at: #{@archived_at&.strftime('%Y-%m-%d %H:%M')}" end lines << "" lines << " Stats:" lines << " Objects: #{@stats['po_count'] || 0}" lines << " Sessions: #{@stats['total_sessions'] || 0}" lines << " Messages: #{@stats['total_messages'] || 0}" if @dependencies&.dig("gems")&.any? lines << "" lines << " Dependencies:" @dependencies["gems"].each do |gem_info| lines << " #{gem_info['name']} (#{gem_info['version']}) — #{gem_info['purpose']}" end end lines << "" lines << " Tags: #{@tags.join(', ')}" if @tags&.any? lines << " Format version: #{@version}" lines.join("\n") end |
#mark_archived! ⇒ Object
Mark as archived with timestamp.
172 173 174 175 |
# File 'lib/prompt_objects/environment/manifest.rb', line 172 def mark_archived! @archived_at = Time.now @updated_at = Time.now end |
#save(path) ⇒ Object
Save manifest to a file.
138 139 140 141 |
# File 'lib/prompt_objects/environment/manifest.rb', line 138 def save(path) @updated_at = Time.now File.write(path, to_hash.to_yaml) end |
#save_to_dir(env_dir) ⇒ Object
Save manifest to an environment directory.
145 146 147 |
# File 'lib/prompt_objects/environment/manifest.rb', line 145 def save_to_dir(env_dir) save(File.join(env_dir, FILENAME)) end |
#to_hash ⇒ Hash
Convert to hash for YAML serialization.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/prompt_objects/environment/manifest.rb', line 114 def to_hash { "version" => @version, "name" => @name, "description" => @description, "created_at" => @created_at&.iso8601, "updated_at" => @updated_at&.iso8601, "last_opened" => @last_opened&.iso8601, "archived_at" => @archived_at&.iso8601, "imported_from" => @imported_from, "imported_at" => @imported_at&.iso8601, "icon" => @icon, "color" => @color, "tags" => @tags.any? ? @tags : nil, "default_po" => @default_po, "stats" => @stats, "dependencies" => @dependencies&.any? ? @dependencies : nil, "runtime_model" => @runtime_model, "llm" => @llm&.any? ? @llm : nil }.compact end |
#to_s ⇒ String
Display string.
191 192 193 |
# File 'lib/prompt_objects/environment/manifest.rb', line 191 def to_s "#{@icon} #{@name}" end |
#touch_opened! ⇒ Object
Mark environment as opened and update timestamp.
150 151 152 153 |
# File 'lib/prompt_objects/environment/manifest.rb', line 150 def touch_opened! @last_opened = Time.now @updated_at = Time.now end |
#update_stats(po_count: nil, session_count: nil, message_count: nil) ⇒ Object
Update stats from environment data.
159 160 161 162 163 164 |
# File 'lib/prompt_objects/environment/manifest.rb', line 159 def update_stats(po_count: nil, session_count: nil, message_count: nil) @stats["po_count"] = po_count if po_count @stats["total_sessions"] = session_count if session_count @stats["total_messages"] = if @updated_at = Time.now end |