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,355 @@
1
+ # Configuration API Reference
2
+
3
+ PromptManager provides comprehensive configuration options to customize behavior for your specific needs.
4
+
5
+ ## Basic Configuration
6
+
7
+ ```ruby
8
+ PromptManager.configure do |config|
9
+ # Storage adapter (default: FileSystemAdapter)
10
+ config.storage = PromptManager::Storage::FileSystemAdapter.new
11
+
12
+ # Default prompts directory (default: ~/prompts_dir/)
13
+ config.prompts_dir = '/path/to/your/prompts'
14
+
15
+ # Enable debug logging (default: false)
16
+ config.debug = true
17
+
18
+ # Custom logger (default: Rails.logger or Logger.new(STDOUT))
19
+ config.logger = Logger.new('/var/log/prompt_manager.log')
20
+ end
21
+ ```
22
+
23
+ ## Configuration Options
24
+
25
+ ### Core Settings
26
+
27
+ #### `storage`
28
+ **Type:** `PromptManager::Storage::Base`
29
+ **Default:** `FileSystemAdapter.new`
30
+
31
+ The storage adapter to use for reading and writing prompts.
32
+
33
+ ```ruby
34
+ # FileSystem storage
35
+ config.storage = PromptManager::Storage::FileSystemAdapter.new(
36
+ prompts_dir: '/custom/prompts/path'
37
+ )
38
+
39
+ # ActiveRecord storage
40
+ config.storage = PromptManager::Storage::ActiveRecordAdapter.new(
41
+ model_class: Prompt
42
+ )
43
+
44
+ # Custom storage
45
+ config.storage = MyCustomAdapter.new
46
+ ```
47
+
48
+ #### `prompts_dir`
49
+ **Type:** `String` or `Array<String>`
50
+ **Default:** `File.join(Dir.home, 'prompts_dir')`
51
+
52
+ Directory path(s) to search for prompt files when using FileSystemAdapter.
53
+
54
+ ```ruby
55
+ # Single directory
56
+ config.prompts_dir = '/app/prompts'
57
+
58
+ # Multiple directories (search in order)
59
+ config.prompts_dir = [
60
+ '/app/prompts',
61
+ '/shared/prompts',
62
+ '/system/default_prompts'
63
+ ]
64
+ ```
65
+
66
+ #### `debug`
67
+ **Type:** `Boolean`
68
+ **Default:** `false`
69
+
70
+ Enable debug logging for troubleshooting.
71
+
72
+ ```ruby
73
+ config.debug = true
74
+ ```
75
+
76
+ #### `logger`
77
+ **Type:** `Logger`
78
+ **Default:** `Rails.logger` or `Logger.new(STDOUT)`
79
+
80
+ Custom logger instance for PromptManager output.
81
+
82
+ ```ruby
83
+ config.logger = Logger.new('/var/log/prompt_manager.log')
84
+ config.logger.level = Logger::DEBUG
85
+ ```
86
+
87
+ ### Parameter Processing
88
+
89
+ #### `save_parameter_history`
90
+ **Type:** `Boolean`
91
+ **Default:** `true`
92
+
93
+ Whether to save parameter values for reuse in future prompt renderings.
94
+
95
+ ```ruby
96
+ config.save_parameter_history = false
97
+ ```
98
+
99
+ #### `parameter_history_file`
100
+ **Type:** `String`
101
+ **Default:** `~/.prompt_manager/parameters_history.yaml`
102
+
103
+ File path for storing parameter history.
104
+
105
+ ```ruby
106
+ config.parameter_history_file = '/app/data/prompt_history.yaml'
107
+ ```
108
+
109
+ #### `max_history_entries`
110
+ **Type:** `Integer`
111
+ **Default:** `10`
112
+
113
+ Maximum number of historical values to store per parameter.
114
+
115
+ ```ruby
116
+ config.max_history_entries = 5
117
+ ```
118
+
119
+ ### ERB Processing
120
+
121
+ #### `erb_timeout`
122
+ **Type:** `Numeric`
123
+ **Default:** `30` (seconds)
124
+
125
+ Timeout for ERB template processing to prevent infinite loops.
126
+
127
+ ```ruby
128
+ config.erb_timeout = 60 # 1 minute
129
+ ```
130
+
131
+ #### `erb_safe_level`
132
+ **Type:** `Integer`
133
+ **Default:** `0`
134
+
135
+ Ruby safe level for ERB evaluation (0-4, higher = more restrictive).
136
+
137
+ ```ruby
138
+ config.erb_safe_level = 1 # Slightly more restrictive
139
+ ```
140
+
141
+ ### Directive Processing
142
+
143
+ #### `max_include_depth`
144
+ **Type:** `Integer`
145
+ **Default:** `10`
146
+
147
+ Maximum depth for nested `//include` directives to prevent circular includes.
148
+
149
+ ```ruby
150
+ config.max_include_depth = 5
151
+ ```
152
+
153
+ #### `directive_timeout`
154
+ **Type:** `Numeric`
155
+ **Default:** `30` (seconds)
156
+
157
+ Timeout for directive processing.
158
+
159
+ ```ruby
160
+ config.directive_timeout = 60
161
+ ```
162
+
163
+ ### Caching
164
+
165
+ #### `cache_prompts`
166
+ **Type:** `Boolean`
167
+ **Default:** `false`
168
+
169
+ Enable in-memory caching of prompt content.
170
+
171
+ ```ruby
172
+ config.cache_prompts = true
173
+ ```
174
+
175
+ #### `cache_ttl`
176
+ **Type:** `Numeric`
177
+ **Default:** `300` (5 minutes)
178
+
179
+ Time-to-live for cached prompt content in seconds.
180
+
181
+ ```ruby
182
+ config.cache_ttl = 600 # 10 minutes
183
+ ```
184
+
185
+ #### `cache_store`
186
+ **Type:** `ActiveSupport::Cache::Store`
187
+ **Default:** `ActiveSupport::Cache::MemoryStore.new`
188
+
189
+ Custom cache store for prompt content.
190
+
191
+ ```ruby
192
+ config.cache_store = ActiveSupport::Cache::RedisStore.new(
193
+ url: ENV['REDIS_URL']
194
+ )
195
+ ```
196
+
197
+ ### Error Handling
198
+
199
+ #### `error_handler`
200
+ **Type:** `Proc`
201
+ **Default:** `nil`
202
+
203
+ Custom error handler for prompt processing errors.
204
+
205
+ ```ruby
206
+ config.error_handler = ->(error, context) {
207
+ Rails.logger.error "Prompt error: #{error.message}"
208
+ ErrorReporter.notify(error, context: context)
209
+
210
+ # Return fallback content
211
+ "Service temporarily unavailable"
212
+ }
213
+ ```
214
+
215
+ #### `raise_on_missing_prompts`
216
+ **Type:** `Boolean`
217
+ **Default:** `true`
218
+
219
+ Whether to raise exceptions for missing prompts or return nil.
220
+
221
+ ```ruby
222
+ config.raise_on_missing_prompts = false
223
+ ```
224
+
225
+ #### `raise_on_missing_parameters`
226
+ **Type:** `Boolean`
227
+ **Default:** `true`
228
+
229
+ Whether to raise exceptions for missing parameters or substitute with placeholders.
230
+
231
+ ```ruby
232
+ config.raise_on_missing_parameters = false
233
+ ```
234
+
235
+ ## Environment-based Configuration
236
+
237
+ ### Rails Configuration
238
+
239
+ ```ruby
240
+ # config/environments/development.rb
241
+ Rails.application.configure do
242
+ config.prompt_manager.debug = true
243
+ config.prompt_manager.prompts_dir = Rails.root.join('app', 'prompts')
244
+ config.prompt_manager.save_parameter_history = true
245
+ end
246
+
247
+ # config/environments/production.rb
248
+ Rails.application.configure do
249
+ config.prompt_manager.debug = false
250
+ config.prompt_manager.cache_prompts = true
251
+ config.prompt_manager.cache_ttl = 3600 # 1 hour
252
+
253
+ config.prompt_manager.error_handler = ->(error, context) {
254
+ Rollbar.error(error, context)
255
+ "Service temporarily unavailable"
256
+ }
257
+ end
258
+ ```
259
+
260
+ ### Environment Variables
261
+
262
+ PromptManager respects these environment variables:
263
+
264
+ ```bash
265
+ # Storage configuration
266
+ PROMPT_MANAGER_PROMPTS_DIR="/app/prompts"
267
+ PROMPT_MANAGER_DEBUG="true"
268
+
269
+ # Cache configuration
270
+ PROMPT_MANAGER_CACHE_PROMPTS="true"
271
+ PROMPT_MANAGER_CACHE_TTL="600"
272
+
273
+ # Database URL for ActiveRecord adapter
274
+ DATABASE_URL="postgres://user:pass@localhost/prompts_db"
275
+ ```
276
+
277
+ ## Configuration Validation
278
+
279
+ Validate your configuration:
280
+
281
+ ```ruby
282
+ PromptManager.configure do |config|
283
+ config.storage = MyAdapter.new
284
+ config.debug = true
285
+ end
286
+
287
+ # Validate configuration
288
+ begin
289
+ PromptManager.validate_configuration!
290
+ puts "Configuration valid"
291
+ rescue PromptManager::ConfigurationError => e
292
+ puts "Configuration error: #{e.message}"
293
+ end
294
+ ```
295
+
296
+ ## Runtime Configuration
297
+
298
+ Access current configuration:
299
+
300
+ ```ruby
301
+ # Get current storage adapter
302
+ storage = PromptManager.configuration.storage
303
+
304
+ # Check debug mode
305
+ if PromptManager.configuration.debug
306
+ puts "Debug mode enabled"
307
+ end
308
+
309
+ # Access logger
310
+ PromptManager.configuration.logger.info("Processing prompt...")
311
+ ```
312
+
313
+ ## Configuration Best Practices
314
+
315
+ ### Development
316
+ ```ruby
317
+ PromptManager.configure do |config|
318
+ config.debug = true
319
+ config.prompts_dir = './prompts'
320
+ config.save_parameter_history = true
321
+ config.cache_prompts = false # Always reload for development
322
+ end
323
+ ```
324
+
325
+ ### Production
326
+ ```ruby
327
+ PromptManager.configure do |config|
328
+ config.debug = false
329
+ config.cache_prompts = true
330
+ config.cache_ttl = 3600
331
+
332
+ config.error_handler = ->(error, context) {
333
+ ErrorService.notify(error, context)
334
+ "Service temporarily unavailable"
335
+ }
336
+
337
+ # Use database storage for high availability
338
+ config.storage = PromptManager::Storage::ActiveRecordAdapter.new
339
+ end
340
+ ```
341
+
342
+ ### Testing
343
+ ```ruby
344
+ # spec/spec_helper.rb
345
+ RSpec.configure do |config|
346
+ config.before(:each) do
347
+ PromptManager.configure do |config|
348
+ config.prompts_dir = Rails.root.join('spec', 'fixtures', 'prompts')
349
+ config.save_parameter_history = false
350
+ config.cache_prompts = false
351
+ config.raise_on_missing_prompts = true
352
+ end
353
+ end
354
+ end
355
+ ```