prompt_manager 0.5.7 → 0.5.8

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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/COMMITS.md +196 -0
  4. data/README.md +485 -203
  5. data/docs/.keep +0 -0
  6. data/docs/advanced/custom-keywords.md +421 -0
  7. data/docs/advanced/dynamic-directives.md +535 -0
  8. data/docs/advanced/performance.md +612 -0
  9. data/docs/advanced/search-integration.md +635 -0
  10. data/docs/api/configuration.md +355 -0
  11. data/docs/api/directive-processor.md +431 -0
  12. data/docs/api/prompt-class.md +354 -0
  13. data/docs/api/storage-adapters.md +462 -0
  14. data/docs/assets/favicon.ico +1 -0
  15. data/docs/assets/logo.svg +24 -0
  16. data/docs/core-features/comments.md +48 -0
  17. data/docs/core-features/directive-processing.md +38 -0
  18. data/docs/core-features/erb-integration.md +68 -0
  19. data/docs/core-features/error-handling.md +197 -0
  20. data/docs/core-features/parameter-history.md +76 -0
  21. data/docs/core-features/parameterized-prompts.md +500 -0
  22. data/docs/core-features/shell-integration.md +79 -0
  23. data/docs/development/architecture.md +544 -0
  24. data/docs/development/contributing.md +425 -0
  25. data/docs/development/roadmap.md +234 -0
  26. data/docs/development/testing.md +822 -0
  27. data/docs/examples/advanced.md +523 -0
  28. data/docs/examples/basic.md +688 -0
  29. data/docs/examples/real-world.md +776 -0
  30. data/docs/examples.md +337 -0
  31. data/docs/getting-started/basic-concepts.md +318 -0
  32. data/docs/getting-started/installation.md +97 -0
  33. data/docs/getting-started/quick-start.md +256 -0
  34. data/docs/index.md +230 -0
  35. data/docs/migration/v0.9.0.md +459 -0
  36. data/docs/migration/v1.0.0.md +591 -0
  37. data/docs/storage/activerecord-adapter.md +348 -0
  38. data/docs/storage/custom-adapters.md +176 -0
  39. data/docs/storage/filesystem-adapter.md +236 -0
  40. data/docs/storage/overview.md +427 -0
  41. data/examples/advanced_integrations.rb +52 -0
  42. data/examples/prompts_dir/advanced_demo.txt +79 -0
  43. data/examples/prompts_dir/directive_example.json +1 -0
  44. data/examples/prompts_dir/directive_example.txt +8 -0
  45. data/examples/prompts_dir/todo.json +1 -1
  46. data/improvement_plan.md +996 -0
  47. data/lib/prompt_manager/storage/file_system_adapter.rb +8 -2
  48. data/lib/prompt_manager/version.rb +1 -1
  49. data/mkdocs.yml +146 -0
  50. data/prompt_manager_logo.png +0 -0
  51. metadata +46 -3
  52. data/LICENSE.txt +0 -21
@@ -0,0 +1,459 @@
1
+ # Migration Guide: Version 0.9.0
2
+
3
+ This guide helps you migrate from PromptManager v0.8.x to v0.9.0.
4
+
5
+ ## Overview
6
+
7
+ Version 0.9.0 introduces several breaking changes to improve consistency, performance, and usability. The main changes include:
8
+
9
+ - Unified configuration system
10
+ - Improved storage adapter interface
11
+ - Enhanced error handling
12
+ - Streamlined directive processing
13
+
14
+ ## Breaking Changes
15
+
16
+ ### 1. Configuration System Changes
17
+
18
+ #### Old Configuration (v0.8.x)
19
+ ```ruby
20
+ PromptManager.setup do |config|
21
+ config.prompts_directory = '/path/to/prompts'
22
+ config.enable_caching = true
23
+ config.cache_duration = 300
24
+ config.default_storage = :filesystem
25
+ end
26
+ ```
27
+
28
+ #### New Configuration (v0.9.0)
29
+ ```ruby
30
+ PromptManager.configure do |config|
31
+ config.storage = PromptManager::Storage::FileSystemAdapter.new(
32
+ prompts_dir: '/path/to/prompts'
33
+ )
34
+ config.cache_prompts = true
35
+ config.cache_ttl = 300
36
+ end
37
+ ```
38
+
39
+ #### Migration Steps
40
+ 1. Replace `PromptManager.setup` with `PromptManager.configure`
41
+ 2. Replace `config.prompts_directory` with explicit storage adapter configuration
42
+ 3. Update cache configuration keys:
43
+ - `enable_caching` → `cache_prompts`
44
+ - `cache_duration` → `cache_ttl`
45
+
46
+ ### 2. Storage Adapter Interface
47
+
48
+ #### Old Interface (v0.8.x)
49
+ ```ruby
50
+ class CustomAdapter
51
+ def get_prompt(id)
52
+ # Old method name
53
+ end
54
+
55
+ def save_prompt(id, content)
56
+ # Old method name
57
+ end
58
+
59
+ def prompt_exists?(id)
60
+ # Old method name
61
+ end
62
+ end
63
+ ```
64
+
65
+ #### New Interface (v0.9.0)
66
+ ```ruby
67
+ class CustomAdapter < PromptManager::Storage::Base
68
+ def read(prompt_id)
69
+ # New method name and inheritance requirement
70
+ end
71
+
72
+ def write(prompt_id, content)
73
+ # New method name
74
+ end
75
+
76
+ def exist?(prompt_id)
77
+ # New method name
78
+ end
79
+
80
+ def delete(prompt_id)
81
+ # New required method
82
+ end
83
+
84
+ def list
85
+ # New required method
86
+ end
87
+ end
88
+ ```
89
+
90
+ #### Migration Steps
91
+ 1. Make your adapter inherit from `PromptManager::Storage::Base`
92
+ 2. Rename methods:
93
+ - `get_prompt` → `read`
94
+ - `save_prompt` → `write`
95
+ - `prompt_exists?` → `exist?`
96
+ 3. Implement new required methods: `delete` and `list`
97
+ 4. Update method signatures to use `prompt_id` parameter name
98
+
99
+ ### 3. Error Class Changes
100
+
101
+ #### Old Error Classes (v0.8.x)
102
+ ```ruby
103
+ begin
104
+ prompt.render
105
+ rescue PromptManager::PromptMissingError => e
106
+ # Handle missing prompt
107
+ rescue PromptManager::ParameterMissingError => e
108
+ # Handle missing parameters
109
+ end
110
+ ```
111
+
112
+ #### New Error Classes (v0.9.0)
113
+ ```ruby
114
+ begin
115
+ prompt.render
116
+ rescue PromptManager::PromptNotFoundError => e
117
+ # Handle missing prompt
118
+ rescue PromptManager::MissingParametersError => e
119
+ # Handle missing parameters
120
+ puts "Missing: #{e.missing_parameters.join(', ')}"
121
+ end
122
+ ```
123
+
124
+ #### Migration Steps
125
+ 1. Update exception class names:
126
+ - `PromptMissingError` → `PromptNotFoundError`
127
+ - `ParameterMissingError` → `MissingParametersError`
128
+ 2. Use the new `missing_parameters` method for detailed parameter information
129
+
130
+ ### 4. Prompt Initialization
131
+
132
+ #### Old Initialization (v0.8.x)
133
+ ```ruby
134
+ prompt = PromptManager::Prompt.new('prompt_id')
135
+ prompt.storage_adapter = custom_adapter
136
+ ```
137
+
138
+ #### New Initialization (v0.9.0)
139
+ ```ruby
140
+ prompt = PromptManager::Prompt.new(
141
+ id: 'prompt_id',
142
+ storage: custom_adapter
143
+ )
144
+ ```
145
+
146
+ #### Migration Steps
147
+ 1. Use keyword arguments in `Prompt.new`
148
+ 2. Pass storage adapter during initialization instead of setting it afterward
149
+
150
+ ## Feature Updates
151
+
152
+ ### 1. Enhanced Parameter Support
153
+
154
+ #### New Features
155
+ - Nested parameter access: `[USER.NAME]`, `[ORDER.ITEMS.0.NAME]`
156
+ - Array parameter formatting
157
+ - Better error messages for missing parameters
158
+
159
+ #### Migration Recommendation
160
+ Review your prompts for any parameter names that might conflict with the new nested syntax.
161
+
162
+ ### 2. Improved Directive Processing
163
+
164
+ #### Changes
165
+ - More robust `//include` processing
166
+ - Better error handling for circular includes
167
+ - New directive registration system
168
+
169
+ #### Migration Steps
170
+ No changes required for basic `//include` usage. Custom directive implementations may need updates.
171
+
172
+ ### 3. Enhanced Caching
173
+
174
+ #### New Caching Options
175
+ ```ruby
176
+ PromptManager.configure do |config|
177
+ config.cache_prompts = true
178
+ config.cache_ttl = 3600
179
+ config.cache_store = ActiveSupport::Cache::RedisStore.new(
180
+ url: ENV['REDIS_URL']
181
+ )
182
+ end
183
+ ```
184
+
185
+ ## Database Schema Changes (ActiveRecord Adapter)
186
+
187
+ ### Schema Updates Required
188
+
189
+ If you're using the ActiveRecord adapter, run this migration:
190
+
191
+ ```ruby
192
+ class UpdatePromptsForPromptManagerV09 < ActiveRecord::Migration[7.0]
193
+ def change
194
+ # Add new columns
195
+ add_column :prompts, :metadata, :json, default: {}
196
+ add_column :prompts, :version, :integer, default: 1
197
+ add_column :prompts, :created_by, :string
198
+ add_column :prompts, :updated_by, :string
199
+
200
+ # Add indexes for better performance
201
+ add_index :prompts, :metadata, using: :gin
202
+ add_index :prompts, :version
203
+ add_index :prompts, :updated_at
204
+
205
+ # Update existing records
206
+ execute <<-SQL
207
+ UPDATE prompts
208
+ SET metadata = '{}', version = 1
209
+ WHERE metadata IS NULL OR version IS NULL
210
+ SQL
211
+ end
212
+
213
+ def down
214
+ remove_column :prompts, :metadata
215
+ remove_column :prompts, :version
216
+ remove_column :prompts, :created_by
217
+ remove_column :prompts, :updated_by
218
+ end
219
+ end
220
+ ```
221
+
222
+ ## Step-by-Step Migration Process
223
+
224
+ ### 1. Update Dependencies
225
+
226
+ ```ruby
227
+ # Gemfile
228
+ gem 'prompt_manager', '~> 0.9.0'
229
+ ```
230
+
231
+ Run `bundle update prompt_manager`
232
+
233
+ ### 2. Update Configuration
234
+
235
+ ```ruby
236
+ # Before (v0.8.x)
237
+ PromptManager.setup do |config|
238
+ config.prompts_directory = Rails.root.join('app', 'prompts')
239
+ config.enable_caching = true
240
+ config.cache_duration = 1800
241
+ end
242
+
243
+ # After (v0.9.0)
244
+ PromptManager.configure do |config|
245
+ config.storage = PromptManager::Storage::FileSystemAdapter.new(
246
+ prompts_dir: Rails.root.join('app', 'prompts')
247
+ )
248
+ config.cache_prompts = true
249
+ config.cache_ttl = 1800
250
+ end
251
+ ```
252
+
253
+ ### 3. Update Custom Storage Adapters
254
+
255
+ ```ruby
256
+ # Before (v0.8.x)
257
+ class RedisAdapter
258
+ def get_prompt(id)
259
+ @redis.get("prompt:#{id}")
260
+ end
261
+
262
+ def save_prompt(id, content)
263
+ @redis.set("prompt:#{id}", content)
264
+ end
265
+
266
+ def prompt_exists?(id)
267
+ @redis.exists?("prompt:#{id}")
268
+ end
269
+ end
270
+
271
+ # After (v0.9.0)
272
+ class RedisAdapter < PromptManager::Storage::Base
273
+ def read(prompt_id)
274
+ content = @redis.get(key_for(prompt_id))
275
+ raise PromptManager::PromptNotFoundError.new("Prompt '#{prompt_id}' not found") unless content
276
+ content
277
+ end
278
+
279
+ def write(prompt_id, content)
280
+ @redis.set(key_for(prompt_id), content)
281
+ true
282
+ end
283
+
284
+ def exist?(prompt_id)
285
+ @redis.exists?(key_for(prompt_id)) > 0
286
+ end
287
+
288
+ def delete(prompt_id)
289
+ @redis.del(key_for(prompt_id)) > 0
290
+ end
291
+
292
+ def list
293
+ keys = @redis.keys("prompts:*")
294
+ keys.map { |key| key.sub('prompts:', '') }
295
+ end
296
+
297
+ private
298
+
299
+ def key_for(prompt_id)
300
+ "prompts:#{prompt_id}"
301
+ end
302
+ end
303
+ ```
304
+
305
+ ### 4. Update Error Handling
306
+
307
+ ```ruby
308
+ # Before (v0.8.x)
309
+ begin
310
+ result = prompt.render(params)
311
+ rescue PromptManager::PromptMissingError
312
+ render json: { error: 'Prompt not found' }, status: 404
313
+ rescue PromptManager::ParameterMissingError => e
314
+ render json: { error: 'Missing parameters' }, status: 400
315
+ end
316
+
317
+ # After (v0.9.0)
318
+ begin
319
+ result = prompt.render(params)
320
+ rescue PromptManager::PromptNotFoundError
321
+ render json: { error: 'Prompt not found' }, status: 404
322
+ rescue PromptManager::MissingParametersError => e
323
+ render json: {
324
+ error: 'Missing parameters',
325
+ missing: e.missing_parameters
326
+ }, status: 400
327
+ end
328
+ ```
329
+
330
+ ### 5. Update Prompt Creation
331
+
332
+ ```ruby
333
+ # Before (v0.8.x)
334
+ prompt = PromptManager::Prompt.new('welcome_email')
335
+ prompt.enable_erb = true
336
+
337
+ # After (v0.9.0)
338
+ prompt = PromptManager::Prompt.new(
339
+ id: 'welcome_email',
340
+ erb_flag: true
341
+ )
342
+ ```
343
+
344
+ ### 6. Run Database Migrations (if using ActiveRecord)
345
+
346
+ ```bash
347
+ rails generate migration UpdatePromptsForPromptManagerV09
348
+ # Edit the migration file with the schema changes shown above
349
+ rails db:migrate
350
+ ```
351
+
352
+ ### 7. Update Tests
353
+
354
+ ```ruby
355
+ # Update test setup
356
+ RSpec.configure do |config|
357
+ config.before(:each) do
358
+ # Clear configuration between tests
359
+ PromptManager.reset_configuration!
360
+
361
+ # Setup test configuration
362
+ PromptManager.configure do |config|
363
+ config.storage = PromptManager::Storage::FileSystemAdapter.new(
364
+ prompts_dir: 'spec/fixtures/prompts'
365
+ )
366
+ end
367
+ end
368
+ end
369
+ ```
370
+
371
+ ## Validation & Testing
372
+
373
+ ### 1. Configuration Validation
374
+
375
+ Add this to verify your configuration:
376
+
377
+ ```ruby
378
+ # In your application's initialization
379
+ begin
380
+ PromptManager.validate_configuration!
381
+ puts "✅ PromptManager configuration is valid"
382
+ rescue PromptManager::ConfigurationError => e
383
+ puts "❌ Configuration error: #{e.message}"
384
+ exit 1
385
+ end
386
+ ```
387
+
388
+ ### 2. Migration Test Script
389
+
390
+ Create a test script to validate the migration:
391
+
392
+ ```ruby
393
+ #!/usr/bin/env ruby
394
+
395
+ require 'prompt_manager'
396
+
397
+ # Test basic functionality
398
+ begin
399
+ PromptManager.configure do |config|
400
+ config.storage = PromptManager::Storage::FileSystemAdapter.new(
401
+ prompts_dir: 'test_prompts'
402
+ )
403
+ end
404
+
405
+ # Create test prompt
406
+ prompt = PromptManager::Prompt.new(id: 'test')
407
+ prompt.write('Hello [NAME]!')
408
+
409
+ # Test rendering
410
+ result = prompt.render(name: 'World')
411
+
412
+ if result == 'Hello World!'
413
+ puts "✅ Migration successful - basic functionality works"
414
+ else
415
+ puts "❌ Migration failed - unexpected result: #{result}"
416
+ end
417
+
418
+ # Cleanup
419
+ prompt.delete
420
+
421
+ rescue => e
422
+ puts "❌ Migration failed with error: #{e.message}"
423
+ puts e.backtrace
424
+ end
425
+ ```
426
+
427
+ ## Rollback Plan
428
+
429
+ If you need to rollback to v0.8.x:
430
+
431
+ 1. **Update Gemfile**: `gem 'prompt_manager', '~> 0.8.0'`
432
+ 2. **Run**: `bundle install`
433
+ 3. **Revert configuration changes** to the old format
434
+ 4. **Revert database migrations** (if using ActiveRecord):
435
+ ```bash
436
+ rails db:rollback STEP=1
437
+ ```
438
+
439
+ ## Getting Help
440
+
441
+ - **Documentation**: Check the updated documentation at https://madbomber.github.io/prompt_manager
442
+ - **GitHub Issues**: Report migration issues at https://github.com/MadBomber/prompt_manager/issues
443
+ - **Discussions**: Ask questions in GitHub Discussions
444
+
445
+ ## Post-Migration Checklist
446
+
447
+ - [ ] Updated Gemfile and ran `bundle install`
448
+ - [ ] Updated configuration format
449
+ - [ ] Updated custom storage adapters (if any)
450
+ - [ ] Updated error handling code
451
+ - [ ] Ran database migrations (if using ActiveRecord)
452
+ - [ ] Updated tests
453
+ - [ ] Validated configuration with test script
454
+ - [ ] Deployed to staging and tested thoroughly
455
+ - [ ] Updated documentation and team
456
+
457
+ ---
458
+
459
+ **Need help?** The migration should be straightforward for most applications. If you encounter issues, please open a GitHub issue with details about your setup and the specific problems you're experiencing.