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,197 @@
1
+ # Error Handling
2
+
3
+ PromptManager provides comprehensive error handling to help you identify and resolve issues during prompt processing.
4
+
5
+ ## Common Exceptions
6
+
7
+ ### `PromptNotFoundError`
8
+
9
+ Raised when a prompt cannot be located:
10
+
11
+ ```ruby
12
+ begin
13
+ prompt = PromptManager::Prompt.new(id: 'nonexistent_prompt')
14
+ rescue PromptManager::PromptNotFoundError => e
15
+ puts "Prompt not found: #{e.message}"
16
+ # Handle gracefully - perhaps show available prompts
17
+ end
18
+ ```
19
+
20
+ ### `MissingParametersError`
21
+
22
+ Raised when required parameters are not provided:
23
+
24
+ ```ruby
25
+ begin
26
+ result = prompt.render # Missing required parameters
27
+ rescue PromptManager::MissingParametersError => e
28
+ puts "Missing parameters: #{e.missing_parameters.join(', ')}"
29
+ # Prompt user for missing values
30
+ end
31
+ ```
32
+
33
+ ### `DirectiveProcessingError`
34
+
35
+ Raised when directive processing fails:
36
+
37
+ ```ruby
38
+ begin
39
+ result = prompt.render
40
+ rescue PromptManager::DirectiveProcessingError => e
41
+ puts "Directive error: #{e.message}"
42
+ puts "Line: #{e.line_number}" if e.respond_to?(:line_number)
43
+ end
44
+ ```
45
+
46
+ ### `StorageError`
47
+
48
+ Raised when storage operations fail:
49
+
50
+ ```ruby
51
+ begin
52
+ prompt = PromptManager::Prompt.new(id: 'my_prompt')
53
+ rescue PromptManager::StorageError => e
54
+ puts "Storage error: #{e.message}"
55
+ # Check file permissions, disk space, etc.
56
+ end
57
+ ```
58
+
59
+ ## Error Recovery Strategies
60
+
61
+ ### Graceful Degradation
62
+
63
+ ```ruby
64
+ def safe_render_prompt(prompt_id, params = {})
65
+ begin
66
+ prompt = PromptManager::Prompt.new(id: prompt_id)
67
+ prompt.render(params)
68
+ rescue PromptManager::PromptNotFoundError
69
+ "Default response when prompt is unavailable"
70
+ rescue PromptManager::MissingParametersError => e
71
+ "Please provide: #{e.missing_parameters.join(', ')}"
72
+ rescue => e
73
+ logger.error "Unexpected error rendering prompt: #{e.message}"
74
+ "An error occurred processing your request"
75
+ end
76
+ end
77
+ ```
78
+
79
+ ### Retry Logic
80
+
81
+ ```ruby
82
+ def render_with_retry(prompt, params, max_retries: 3)
83
+ retries = 0
84
+
85
+ begin
86
+ prompt.render(params)
87
+ rescue PromptManager::StorageError => e
88
+ retries += 1
89
+ if retries <= max_retries
90
+ sleep(0.5 * retries) # Exponential backoff
91
+ retry
92
+ else
93
+ raise e
94
+ end
95
+ end
96
+ end
97
+ ```
98
+
99
+ ## Validation and Prevention
100
+
101
+ ### Parameter Validation
102
+
103
+ ```ruby
104
+ def validate_parameters(params, required_params)
105
+ missing = required_params - params.keys
106
+
107
+ unless missing.empty?
108
+ raise PromptManager::MissingParametersError.new(
109
+ "Missing required parameters: #{missing.join(', ')}",
110
+ missing_parameters: missing
111
+ )
112
+ end
113
+ end
114
+
115
+ # Usage
116
+ validate_parameters(user_params, [:customer_name, :order_id])
117
+ ```
118
+
119
+ ### Pre-flight Checks
120
+
121
+ ```ruby
122
+ def preflight_check(prompt_id)
123
+ # Check if prompt exists
124
+ unless PromptManager.storage.exist?(prompt_id)
125
+ raise PromptManager::PromptNotFoundError, "Prompt '#{prompt_id}' not found"
126
+ end
127
+
128
+ # Check for circular includes
129
+ check_circular_includes(prompt_id)
130
+
131
+ # Validate syntax
132
+ validate_prompt_syntax(prompt_id)
133
+ end
134
+ ```
135
+
136
+ ## Logging and Debugging
137
+
138
+ ### Enable Debug Logging
139
+
140
+ ```ruby
141
+ PromptManager.configure do |config|
142
+ config.debug = true
143
+ config.logger = Logger.new(STDOUT)
144
+ end
145
+ ```
146
+
147
+ ### Custom Error Handlers
148
+
149
+ ```ruby
150
+ PromptManager.configure do |config|
151
+ config.error_handler = ->(error, context) {
152
+ # Custom error handling
153
+ ErrorReporter.notify(error, context: context)
154
+
155
+ # Return fallback response
156
+ case error
157
+ when PromptManager::PromptNotFoundError
158
+ "Prompt temporarily unavailable"
159
+ when PromptManager::MissingParametersError
160
+ "Please check your input parameters"
161
+ else
162
+ "Service temporarily unavailable"
163
+ end
164
+ }
165
+ end
166
+ ```
167
+
168
+ ## Testing Error Conditions
169
+
170
+ ### RSpec Examples
171
+
172
+ ```ruby
173
+ describe "Error handling" do
174
+ it "handles missing prompts gracefully" do
175
+ expect {
176
+ PromptManager::Prompt.new(id: 'nonexistent')
177
+ }.to raise_error(PromptManager::PromptNotFoundError)
178
+ end
179
+
180
+ it "validates required parameters" do
181
+ prompt = PromptManager::Prompt.new(id: 'test_prompt')
182
+
183
+ expect {
184
+ prompt.render # No parameters provided
185
+ }.to raise_error(PromptManager::MissingParametersError)
186
+ end
187
+ end
188
+ ```
189
+
190
+ ## Best Practices
191
+
192
+ 1. **Always Handle Exceptions**: Never let PromptManager exceptions bubble up unhandled
193
+ 2. **Provide Meaningful Fallbacks**: Return sensible defaults when prompts fail
194
+ 3. **Log Errors**: Capture error details for debugging and monitoring
195
+ 4. **Validate Early**: Check parameters and conditions before processing
196
+ 5. **Test Error Paths**: Include error scenarios in your test suite
197
+ 6. **Monitor in Production**: Set up alerts for prompt processing failures
@@ -0,0 +1,76 @@
1
+ # Parameter History
2
+
3
+ PromptManager automatically tracks parameter usage history to help you reuse previously entered values and maintain consistency across prompt executions.
4
+
5
+ ## Automatic History Tracking
6
+
7
+ When you use parameters in your prompts, PromptManager automatically saves the values you provide:
8
+
9
+ ```ruby
10
+ prompt = PromptManager::Prompt.new(id: 'customer_email')
11
+ result = prompt.render(customer_name: 'John Doe', product: 'Pro Plan')
12
+ # These values are automatically saved to history
13
+ ```
14
+
15
+ ## History File Location
16
+
17
+ Parameter history is stored in `~/.prompt_manager/parameters_history.yaml` by default.
18
+
19
+ ## Accessing History
20
+
21
+ Previous parameter values are automatically suggested when you use the same parameter names in subsequent prompts:
22
+
23
+ ```ruby
24
+ # First time - you provide values
25
+ prompt.render(api_key: 'sk-123', model: 'gpt-4')
26
+
27
+ # Second time - previous values are available
28
+ prompt.render # Will suggest previously used api_key and model values
29
+ ```
30
+
31
+ ## History Management
32
+
33
+ ### Viewing History
34
+
35
+ ```ruby
36
+ # Access stored parameter values
37
+ history = PromptManager.configuration.parameter_history
38
+ puts history['api_key'] # Shows previously used API keys
39
+ ```
40
+
41
+ ### Clearing History
42
+
43
+ ```ruby
44
+ # Clear all parameter history
45
+ PromptManager.configuration.clear_parameter_history
46
+
47
+ # Clear specific parameter
48
+ PromptManager.configuration.clear_parameter('api_key')
49
+ ```
50
+
51
+ ## Configuration
52
+
53
+ Configure history behavior in your application:
54
+
55
+ ```ruby
56
+ PromptManager.configure do |config|
57
+ config.save_parameter_history = true # Enable/disable history (default: true)
58
+ config.parameter_history_file = 'custom_history.yaml' # Custom file location
59
+ config.max_history_entries = 10 # Limit stored values per parameter
60
+ end
61
+ ```
62
+
63
+ ## Privacy Considerations
64
+
65
+ Parameter history is stored locally and never transmitted. However, be mindful of sensitive data:
66
+
67
+ - API keys and tokens are stored in plain text
68
+ - Consider clearing history for sensitive parameters
69
+ - Use environment variables for truly sensitive data instead of parameter history
70
+
71
+ ## Best Practices
72
+
73
+ 1. **Regular Cleanup**: Periodically clear old parameter values
74
+ 2. **Sensitive Data**: Don't rely on history for secrets - use environment variables
75
+ 3. **Team Sharing**: History files are user-specific, not shared across team members
76
+ 4. **Backup**: Consider backing up important parameter configurations