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,97 @@
1
+ # Installation
2
+
3
+ ## System Requirements
4
+
5
+ PromptManager requires:
6
+
7
+ - **Ruby**: 2.7 or higher (3.0+ recommended)
8
+ - **Operating System**: Linux, macOS, or Windows
9
+ - **Dependencies**: No additional system dependencies required
10
+
11
+ ## Install the Gem
12
+
13
+ ### Using Bundler (Recommended)
14
+
15
+ Add PromptManager to your project's `Gemfile`:
16
+
17
+ ```ruby
18
+ # Gemfile
19
+ gem 'prompt_manager'
20
+ ```
21
+
22
+ Then install:
23
+
24
+ ```bash
25
+ bundle install
26
+ ```
27
+
28
+ ### Using RubyGems
29
+
30
+ Install directly with gem:
31
+
32
+ ```bash
33
+ gem install prompt_manager
34
+ ```
35
+
36
+ ### Development Installation
37
+
38
+ For development or to get the latest features:
39
+
40
+ ```bash
41
+ git clone https://github.com/MadBomber/prompt_manager.git
42
+ cd prompt_manager
43
+ bundle install
44
+ ```
45
+
46
+ ## Verify Installation
47
+
48
+ Test that PromptManager is installed correctly:
49
+
50
+ ```ruby
51
+ require 'prompt_manager'
52
+ puts PromptManager::VERSION
53
+ ```
54
+
55
+ ## Dependencies
56
+
57
+ PromptManager has minimal dependencies and automatically installs:
58
+
59
+ - **No external system dependencies**
60
+ - **Pure Ruby dependencies** only
61
+ - **Lightweight footprint** for easy integration
62
+
63
+ ## Troubleshooting
64
+
65
+ ### Common Issues
66
+
67
+ !!! warning "Ruby Version"
68
+
69
+ If you see compatibility errors, ensure you're running Ruby 2.7+:
70
+
71
+ ```bash
72
+ ruby --version
73
+ ```
74
+
75
+ !!! tip "Bundler Issues"
76
+
77
+ If bundle install fails, try updating bundler:
78
+
79
+ ```bash
80
+ gem update bundler
81
+ bundle install
82
+ ```
83
+
84
+ ### Getting Help
85
+
86
+ If you encounter installation issues:
87
+
88
+ 1. Check the [GitHub Issues](https://github.com/MadBomber/prompt_manager/issues)
89
+ 2. Search for similar problems in [Discussions](https://github.com/MadBomber/prompt_manager/discussions)
90
+ 3. Create a new issue with:
91
+ - Ruby version (`ruby --version`)
92
+ - Gem version (`gem list prompt_manager`)
93
+ - Error message and full stack trace
94
+
95
+ ## Next Steps
96
+
97
+ Once installed, continue to the [Quick Start](quick-start.md) guide to begin using PromptManager.
@@ -0,0 +1,256 @@
1
+ # Quick Start
2
+
3
+ This guide will get you up and running with PromptManager in just a few minutes.
4
+
5
+ ## 1. Install PromptManager
6
+
7
+ ```bash
8
+ gem install prompt_manager
9
+ ```
10
+
11
+ ## 2. Set Up Your First Prompt
12
+
13
+ Create a directory for your prompts and your first prompt file:
14
+
15
+ ```bash
16
+ mkdir ~/.prompts
17
+ ```
18
+
19
+ Create your first prompt file:
20
+
21
+ === "~/.prompts/greeting.txt"
22
+
23
+ ```text
24
+ # Description: A friendly greeting prompt
25
+ # Keywords: NAME, LANGUAGE
26
+
27
+ Hello [NAME]!
28
+
29
+ I'm here to help you today. Please let me know how I can assist you,
30
+ and I'll respond in [LANGUAGE].
31
+
32
+ What would you like to know about?
33
+ ```
34
+
35
+ === "~/.prompts/greeting.json"
36
+
37
+ ```json
38
+ {
39
+ "[NAME]": ["Alice", "Bob", "Charlie"],
40
+ "[LANGUAGE]": ["English", "Spanish", "French"]
41
+ }
42
+ ```
43
+
44
+ ## 3. Basic Usage
45
+
46
+ Create a simple Ruby script to use your prompt:
47
+
48
+ ```ruby title="quick_example.rb"
49
+ #!/usr/bin/env ruby
50
+
51
+ require 'prompt_manager'
52
+
53
+ # Configure the FileSystem storage adapter
54
+ PromptManager::Prompt.storage_adapter =
55
+ PromptManager::Storage::FileSystemAdapter.config do |config|
56
+ config.prompts_dir = File.expand_path('~/.prompts')
57
+ end.new
58
+
59
+ # Load your prompt
60
+ prompt = PromptManager::Prompt.new(id: 'greeting')
61
+
62
+ # Set parameter values
63
+ prompt.parameters = {
64
+ "[NAME]" => "Alice",
65
+ "[LANGUAGE]" => "English"
66
+ }
67
+
68
+ # Generate the final prompt text
69
+ puts "=== Generated Prompt ==="
70
+ puts prompt.to_s
71
+
72
+ # Save any parameter changes
73
+ prompt.save
74
+ ```
75
+
76
+ Run it:
77
+
78
+ ```bash
79
+ ruby quick_example.rb
80
+ ```
81
+
82
+ Expected output:
83
+ ```
84
+ === Generated Prompt ===
85
+ Hello Alice!
86
+
87
+ I'm here to help you today. Please let me know how I can assist you,
88
+ and I'll respond in English.
89
+
90
+ What would you like to know about?
91
+ ```
92
+
93
+ ## 4. Understanding the Workflow
94
+
95
+ The basic PromptManager workflow involves:
96
+
97
+ ```mermaid
98
+ graph LR
99
+ A[Create Prompt File] --> B[Configure Storage]
100
+ B --> C[Load Prompt]
101
+ C --> D[Set Parameters]
102
+ D --> E[Generate Text]
103
+ E --> F[Save Changes]
104
+ ```
105
+
106
+ ### Step by Step:
107
+
108
+ 1. **Create Prompt File**: Write your template with `[KEYWORDS]`
109
+ 2. **Configure Storage**: Choose FileSystem or ActiveRecord adapter
110
+ 3. **Load Prompt**: Create a Prompt instance with an ID
111
+ 4. **Set Parameters**: Provide values for your keywords
112
+ 5. **Generate Text**: Call `to_s` to get the final prompt
113
+ 6. **Save Changes**: Persist parameter updates
114
+
115
+ ## 5. Advanced Quick Start
116
+
117
+ Here's a more advanced example showing multiple features:
118
+
119
+ ```ruby title="advanced_example.rb"
120
+ require 'prompt_manager'
121
+
122
+ # Configure storage
123
+ PromptManager::Prompt.storage_adapter =
124
+ PromptManager::Storage::FileSystemAdapter.config do |config|
125
+ config.prompts_dir = File.expand_path('~/.prompts')
126
+ end.new
127
+
128
+ # Create a prompt with directives and ERB
129
+ prompt = PromptManager::Prompt.new(
130
+ id: 'advanced_greeting',
131
+ erb_flag: true,
132
+ envar_flag: true
133
+ )
134
+
135
+ # Set parameters
136
+ prompt.parameters = {
137
+ "[USER_NAME]" => "Alice",
138
+ "[TASK_TYPE]" => "translation",
139
+ "[URGENCY]" => "high"
140
+ }
141
+
142
+ # Display available keywords
143
+ puts "Available keywords: #{prompt.keywords.join(', ')}"
144
+
145
+ # Generate and display the result
146
+ puts "\n=== Final Prompt ==="
147
+ puts prompt.to_s
148
+
149
+ # Save changes
150
+ prompt.save
151
+ puts "\nPrompt saved successfully!"
152
+ ```
153
+
154
+ === "~/.prompts/advanced_greeting.txt"
155
+
156
+ ```text
157
+ # Advanced greeting with directives and ERB
158
+ //include common/header.txt
159
+
160
+ Dear [USER_NAME],
161
+
162
+ <% if '[URGENCY]' == 'high' %>
163
+ 🚨 URGENT: This [TASK_TYPE] request requires immediate attention.
164
+ <% else %>
165
+ 📋 Standard [TASK_TYPE] request for processing.
166
+ <% end %>
167
+
168
+ Current system time: <%= Time.now.strftime('%Y-%m-%d %H:%M:%S') %>
169
+ Working directory: <%= Dir.pwd %>
170
+
171
+ __END__
172
+ This section is ignored - useful for notes and documentation.
173
+ ```
174
+
175
+ ## 6. Next Steps
176
+
177
+ Now that you have PromptManager working, explore these areas:
178
+
179
+ ### Learn Core Features
180
+ - [Parameterized Prompts](../core-features/parameterized-prompts.md) - Master keyword substitution
181
+ - [Directive Processing](../core-features/directive-processing.md) - Include files and process commands
182
+ - [ERB Integration](../core-features/erb-integration.md) - Dynamic templating
183
+
184
+ ### Storage Options
185
+ - [FileSystem Adapter](../storage/filesystem-adapter.md) - File-based storage
186
+ - [ActiveRecord Adapter](../storage/activerecord-adapter.md) - Database storage
187
+ - [Custom Adapters](../storage/custom-adapters.md) - Build your own
188
+
189
+ ### Advanced Usage
190
+ - [Custom Keywords](../advanced/custom-keywords.md) - Define your own keyword patterns
191
+ - [Search Integration](../advanced/search-integration.md) - Find prompts quickly
192
+ - [Performance Tips](../advanced/performance.md) - Optimize for large collections
193
+
194
+ ### Real Examples
195
+ - [Basic Examples](../examples/basic.md) - Simple use cases
196
+ - [Advanced Examples](../examples/advanced.md) - Complex scenarios
197
+ - [Real World Cases](../examples/real-world.md) - Production examples
198
+
199
+ ## Common Patterns
200
+
201
+ Here are some common patterns you'll use frequently:
202
+
203
+ ### Parameter History
204
+ ```ruby
205
+ # Access parameter history (since v0.3.0)
206
+ prompt.parameters["[NAME]"] # Returns ["Alice", "Bob", "Charlie"]
207
+ latest_name = prompt.parameters["[NAME]"].last # "Charlie"
208
+ ```
209
+
210
+ ### Error Handling
211
+ ```ruby
212
+ begin
213
+ prompt = PromptManager::Prompt.new(id: 'missing')
214
+ rescue PromptManager::StorageError => e
215
+ puts "Storage error: #{e.message}"
216
+ rescue PromptManager::ParameterError => e
217
+ puts "Parameter error: #{e.message}"
218
+ end
219
+ ```
220
+
221
+ ### Search and Discovery
222
+ ```ruby
223
+ # List all available prompts
224
+ prompts = PromptManager::Prompt.list
225
+ puts "Available prompts: #{prompts.join(', ')}"
226
+
227
+ # Search for prompts (requires search_proc configuration)
228
+ results = PromptManager::Prompt.search('greeting')
229
+ ```
230
+
231
+ ## Troubleshooting
232
+
233
+ ### File Not Found
234
+ If you get "file not found" errors, check:
235
+
236
+ 1. **Prompt directory exists**: `ls ~/.prompts`
237
+ 2. **File has correct extension**: Should be `.txt` by default
238
+ 3. **Prompt ID matches filename**: `greeting` looks for `greeting.txt`
239
+
240
+ ### Parameter Errors
241
+ If parameters aren't substituting:
242
+
243
+ 1. **Check keyword format**: Must be `[UPPERCASE]` by default
244
+ 2. **Verify parameter keys match**: Case-sensitive matching
245
+ 3. **Ensure parameters are set**: Call `prompt.parameters = {...}`
246
+
247
+ ### Permission Issues
248
+ If you can't write to the prompts directory:
249
+
250
+ ```bash
251
+ chmod 755 ~/.prompts
252
+ chmod 644 ~/.prompts/*.txt
253
+ chmod 644 ~/.prompts/*.json
254
+ ```
255
+
256
+ Need help? Check our [testing guide](../development/testing.md) or [open an issue](https://github.com/MadBomber/prompt_manager/issues).
data/docs/index.md ADDED
@@ -0,0 +1,230 @@
1
+ # PromptManager Documentation
2
+
3
+ <div align="center" style="background-color: #fff3cd; color: #856404; padding: 20px; margin: 20px 0; border: 2px solid #ffeaa7; border-radius: 5px; font-size: 18px; font-weight: bold;">
4
+ ⚠️ CAUTION ⚠️<br />
5
+ Breaking Changes are Coming<br />
6
+ See <a href="development/roadmap/">Roadmap</a> for details
7
+ </div>
8
+
9
+ <div align="center">
10
+ <table>
11
+ <tr>
12
+ <td width="40%" align="center" valign="top">
13
+ <img src="../prompt_manager_logo.png" alt="PromptManager - The Enchanted Librarian of AI Prompts" width="400">
14
+ </td>
15
+ <td width="60%" align="left" valign="top">
16
+ <p><strong>Like an enchanted librarian organizing floating books of knowledge, PromptManager helps you masterfully orchestrate and organize your AI prompts through wisdom and experience.</strong></p>
17
+
18
+ <p>Each prompt becomes a living entity that can be categorized, parameterized, and interconnected with golden threads of relationships.</p>
19
+
20
+ <h3>Key Features</h3>
21
+ <ul>
22
+ <li><strong>📚 <a href="storage/overview/">Multiple Storage Adapters</a></strong></li>
23
+ <li><strong>🔧 <a href="core-features/parameterized-prompts/">Parameterized Prompts</a></strong></li>
24
+ <li><strong>📋 <a href="core-features/directive-processing/">Directive Processing</a></strong></li>
25
+ <li><strong>🎨 <a href="core-features/erb-integration/">ERB Integration</a></strong></li>
26
+ <li><strong>🌍 <a href="core-features/shell-integration/">Shell Integration</a></strong></li>
27
+ <li><strong>📖 <a href="core-features/comments/">Inline Documentation</a></strong></li>
28
+ <li><strong>📊 <a href="core-features/parameter-history/">Parameter History</a></strong></li>
29
+ <li><strong>⚡ <a href="core-features/error-handling/">Error Handling</a></strong></li>
30
+ <li><strong>🔌 <a href="advanced/custom-keywords/">Extensible Architecture</a></strong></li>
31
+ </ul>
32
+ </td>
33
+ </tr>
34
+ </table>
35
+ </div>
36
+
37
+ ## What is PromptManager?
38
+
39
+ PromptManager is a Ruby gem designed for managing parameterized prompts used in generative AI applications. It provides a sophisticated system for organizing, templating, and processing prompts with support for multiple storage backends, directive processing, and advanced templating features.
40
+
41
+ Think of it as your personal AI prompt librarian - organizing your prompts, managing their parameters, processing their directives, and ensuring they're always ready when you need them.
42
+
43
+ ## Quick Start
44
+
45
+ Get up and running with PromptManager in minutes:
46
+
47
+ === "Installation"
48
+
49
+ ```bash
50
+ gem install prompt_manager
51
+ # or add to Gemfile
52
+ bundle add prompt_manager
53
+ ```
54
+
55
+ === "Basic Usage"
56
+
57
+ ```ruby
58
+ require 'prompt_manager'
59
+
60
+ # Configure storage
61
+ PromptManager::Prompt.storage_adapter =
62
+ PromptManager::Storage::FileSystemAdapter.config do |config|
63
+ config.prompts_dir = '~/.prompts'
64
+ end.new
65
+
66
+ # Use a prompt
67
+ prompt = PromptManager::Prompt.new(id: 'greeting')
68
+ prompt.parameters = {
69
+ "[NAME]" => "Alice",
70
+ "[LANGUAGE]" => "English"
71
+ }
72
+
73
+ puts prompt.to_s
74
+ ```
75
+
76
+ === "Create a Prompt"
77
+
78
+ ```text
79
+ # ~/.prompts/greeting.txt
80
+ # Description: A friendly greeting prompt
81
+
82
+ Hello [NAME]! How can I assist you today?
83
+ Please respond in [LANGUAGE].
84
+ ```
85
+
86
+ ## Architecture Overview
87
+
88
+ PromptManager follows a modular architecture designed for flexibility and extensibility:
89
+
90
+ ```mermaid
91
+ graph TB
92
+ subgraph "Application Layer"
93
+ A[Your Application]
94
+ P[PromptManager::Prompt]
95
+ end
96
+
97
+ subgraph "Processing Layer"
98
+ D[Directive Processor]
99
+ E[ERB Engine]
100
+ K[Keyword Substitution]
101
+ end
102
+
103
+ subgraph "Storage Layer"
104
+ FS[FileSystem Adapter]
105
+ AR[ActiveRecord Adapter]
106
+ CA[Custom Adapter]
107
+ end
108
+
109
+ A --> P
110
+ P --> D
111
+ P --> E
112
+ P --> K
113
+ P --> FS
114
+ P --> AR
115
+ P --> CA
116
+
117
+ D --> |includes| FS
118
+ E --> |templates| P
119
+ K --> |substitutes| P
120
+ ```
121
+
122
+ ## Core Concepts
123
+
124
+ ### Parameterized Prompts
125
+
126
+ Transform static prompts into dynamic templates:
127
+
128
+ ```ruby
129
+ # Template with parameters
130
+ prompt_text = "Translate '[TEXT]' from [SOURCE_LANG] to [TARGET_LANG]"
131
+
132
+ # Filled with values
133
+ prompt.parameters = {
134
+ "[TEXT]" => "Hello world",
135
+ "[SOURCE_LANG]" => "English",
136
+ "[TARGET_LANG]" => "Spanish"
137
+ }
138
+
139
+ # Result: "Translate 'Hello world' from English to Spanish"
140
+ ```
141
+
142
+ ### Directive Processing
143
+
144
+ Use JCL-style directives for prompt composition:
145
+
146
+ ```text
147
+ # Common header for all customer service prompts
148
+ //include common/customer_service_header.txt
149
+
150
+ # Dynamic template inclusion
151
+ //include templates/[TEMPLATE_TYPE].txt
152
+
153
+ Handle this customer inquiry about [TOPIC].
154
+ ```
155
+
156
+ ### Storage Adapters
157
+
158
+ Choose your preferred storage backend:
159
+
160
+ - **FileSystemAdapter**: Store prompts as text files
161
+ - **ActiveRecordAdapter**: Store prompts in a database
162
+ - **Custom Adapters**: Build your own storage solution
163
+
164
+ ## Why PromptManager?
165
+
166
+ ### 🎯 **Organized Prompts**
167
+ Keep your prompts organized in a structured, searchable format instead of scattered across your codebase.
168
+
169
+ ### 🔄 **Reusable Templates**
170
+ Create parameterized templates that can be reused across different contexts and applications.
171
+
172
+ ### 🛠️ **Powerful Processing**
173
+ Advanced features like directive processing, ERB templating, and environment variable substitution.
174
+
175
+ ### 📈 **Scalable Architecture**
176
+ Modular design supports everything from simple scripts to enterprise applications.
177
+
178
+ ### 🔍 **Easy Management**
179
+ Built-in search capabilities and parameter history make prompt management effortless.
180
+
181
+ ## Getting Started
182
+
183
+ Ready to dive in? Here are some great places to start:
184
+
185
+ <div class="grid cards" markdown>
186
+
187
+ - :fontawesome-solid-rocket:{ .lg .middle } __Quick Start__
188
+
189
+ ---
190
+
191
+ Get PromptManager running in your project within minutes
192
+
193
+ [:octicons-arrow-right-24: Quick Start](getting-started/quick-start.md)
194
+
195
+ - :fontawesome-solid-book:{ .lg .middle } __Core Features__
196
+
197
+ ---
198
+
199
+ Learn about parameterized prompts, directives, and more
200
+
201
+ [:octicons-arrow-right-24: Core Features](core-features/parameterized-prompts.md)
202
+
203
+ - :fontawesome-solid-database:{ .lg .middle } __Storage Adapters__
204
+
205
+ ---
206
+
207
+ Choose the right storage solution for your needs
208
+
209
+ [:octicons-arrow-right-24: Storage Options](storage/overview.md)
210
+
211
+ - :fontawesome-solid-code:{ .lg .middle } __API Reference__
212
+
213
+ ---
214
+
215
+ Complete reference for all classes and methods
216
+
217
+ [:octicons-arrow-right-24: API Docs](api/prompt-class.md)
218
+
219
+ </div>
220
+
221
+ ## Community & Support
222
+
223
+ - **GitHub**: [MadBomber/prompt_manager](https://github.com/MadBomber/prompt_manager)
224
+ - **RubyGems**: [prompt_manager](https://rubygems.org/gems/prompt_manager)
225
+ - **Issues**: [Report bugs or request features](https://github.com/MadBomber/prompt_manager/issues)
226
+ - **Discussions**: [Community discussions](https://github.com/MadBomber/prompt_manager/discussions)
227
+
228
+ ## License
229
+
230
+ PromptManager is released under the [MIT License](https://opensource.org/licenses/MIT).