monkeyspaw 0.0.1 β†’ 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ce5d0090a65680d9d35a3db4165f9b1ecaa9a07da2077e109c69d00b0696773
4
- data.tar.gz: 95657a5e46c0070e16ee55adb4ecbbffb0252f297760b695b83c7dc930001063
3
+ metadata.gz: b67b97f684213086c17471f075dde93921f0d4a1eee84a45ced514c3898e8560
4
+ data.tar.gz: 4cfab7ee1409f7c26b022ce5309c732b9926eb10b4e2ac0352463b011bb7d676
5
5
  SHA512:
6
- metadata.gz: 18e5f453eb95c34cc32873bba6a4cfc1ca4572bf47a1315fabe71badf5dd0b830a8d2e857118ca14892617b7388d1ab84113066a69bd8161d1dd1e4e91147079
7
- data.tar.gz: 7bad4ea29d4dc33d18cbf15e723b3c87e07f9680f961865fd8325b0dfdaa625b6c0b9f9c7dbde9351e050d29d77f386b23d9f36182b0324f0ab5c77eeff71eb6
6
+ metadata.gz: a0c21ece19b4917de4efb25647f957e973eb9206c40bd5f5b46d1dc6f88f31cbc51dadcdeb9becedaddd4b13ce2568ce0e0ab362d87f3527992c5256df6f64be
7
+ data.tar.gz: bf75e89ca31dc48dea52e2570d65cd97109239af28b4eb91d04fea4f07acd1a0b5d244221e126377126ba67d8c35a9d990679fc1d01d85688feaf467e306606c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sublayer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,161 @@
1
+ # MonkeysPaw πŸ’βœ‹
2
+
3
+ > *Be careful what you wish for...*
4
+
5
+ A prompt-driven web framework for Ruby that grants your web development wishes through the power of AI. Like the legendary monkey's paw, it will fulfill your requests exactly as statedβ€”for better or worse.
6
+
7
+ ## The Curse and the Gift
8
+
9
+ MonkeysPaw removes traditional web development constraints by allowing you to express your intentions through prompts rather than code. But remember, with great power comes the responsibility to be precise. Your words shape reality here.
10
+
11
+ The quality of what you receive depends entirely on how carefully you phrase your wishes.
12
+
13
+ ## Installation
14
+
15
+ Summon the paw into your application:
16
+
17
+ ```ruby
18
+ gem 'monkeyspaw'
19
+ ```
20
+
21
+ Then invoke the ritual:
22
+
23
+ ```bash
24
+ $ bundle install
25
+ ```
26
+
27
+ Or bind it directly:
28
+
29
+ ```bash
30
+ $ gem install monkeyspaw
31
+ ```
32
+
33
+ ## AI Provider
34
+
35
+ MonkeysPaw is currently set up to only commune with Gemini by default. Other AI
36
+ entities will be supported shortly.
37
+
38
+ To use Gemini set up your environment variable:
39
+
40
+ OSX/Linux:
41
+ ```bash
42
+ export GEMINI_API_KEY=your_gemini_api_key
43
+ ```
44
+
45
+ Windows:
46
+
47
+ ```bash
48
+ Set-Item -Path env:GEMINI_API_KEY -Value "YourKeyHere"
49
+ ```
50
+
51
+ ## Making Your First Wish
52
+
53
+ Create a simple manifestation with just a few incantations:
54
+
55
+ ```ruby
56
+ require 'monkeyspaw'
57
+
58
+ # Make your wish come true
59
+ MonkeysPaw.pick_up!
60
+ ```
61
+
62
+ That's it! MonkeysPaw will interpret your desires by:
63
+
64
+ 1. Reading prompt files from the `wishes/` directory
65
+ 2. Channeling the AI entity to manifest your content
66
+ 3. Summoning a web server (default: http://localhost:1337)
67
+
68
+ ## Structuring Your Desires
69
+
70
+ MonkeysPaw follows arcane file-based conventions:
71
+
72
+ ```
73
+ your-project/
74
+ β”œβ”€β”€ wishes/ # Your primary desires
75
+ β”‚ β”œβ”€β”€ index.md # Home page (/)
76
+ β”‚ β”œβ”€β”€ about.md # About page (/about)
77
+ β”‚ └── curses/
78
+ β”‚ β”œβ”€β”€ 01-wish.md # First curse (/curses/01-wish)
79
+ β”‚ └── 02-consequence.md # Second curse (/curses/02-consequence)
80
+ β”œβ”€β”€ components/ # Recurring incantations
81
+ β”‚ β”œβ”€β”€ layout.md # The container of all things
82
+ β”‚ └── navigation.md # Pathways between realms
83
+ β”œβ”€β”€ assets/ # Physical manifestations
84
+ β”‚ └── images/
85
+ β”‚ └── paw-mark.png
86
+ └── app.rb # Where the magic begins
87
+ ```
88
+
89
+ ## Crafting Effective Wishes (Prompts)
90
+
91
+ The art of prompt crafting is delicate. Be specific, or face the consequences of ambiguity:
92
+
93
+ ```markdown
94
+ # Page: Introduction to MonkeysPaw
95
+
96
+ ## Content Instructions:
97
+ Create an engaging introduction to a framework that grants web development wishes
98
+ through AI prompts. Emphasize the need for precise language.
99
+
100
+ ## Key Points:
101
+ - The dual nature of wish fulfillment: power and peril
102
+ - How imprecise wishes lead to unexpected outcomes
103
+ - Examples of well-crafted vs. poorly-crafted prompts
104
+
105
+ ## Style:
106
+ - Mysterious yet professional tone
107
+ - Include a cautionary opening statement
108
+ - End with advice for the wish-maker
109
+
110
+ ## Visual Elements:
111
+ - A clear warning header
112
+ - Short, foreboding paragraphs
113
+ - A callout box with "Do's and Don'ts" for prompt crafting
114
+ ```
115
+
116
+ ## Controlling Your Fate
117
+
118
+ Configure the terms of your pact:
119
+
120
+ ```ruby
121
+ MonkeysPaw.configure do |config|
122
+ config.port = 4567
123
+ config.host = 'localhost'
124
+ end
125
+ ```
126
+
127
+ ## Mystical Entities Available for Summoning (TODO)
128
+
129
+ MonkeysPaw can channel various AI entities:
130
+
131
+ ```ruby
132
+ # The Gemini Spirit
133
+ MonkeysPaw.use :gemini, model: :gemini_2_0_flash
134
+
135
+ # The OpenAI Oracle
136
+ MonkeysPaw.use :openai, model: :gpt_4
137
+
138
+ # The Anthropic Sage
139
+ MonkeysPaw.use :anthropic, model: :claude_3_opus
140
+
141
+ # The Mistral Wind
142
+ MonkeysPaw.use :mistral, model: :mistral_large
143
+ ```
144
+
145
+ ## Words of Caution
146
+
147
+ 1. **Be Precise**: Ambiguity is your enemy. The more specific your wishes, the fewer surprises you'll face.
148
+
149
+ 2. **Test Your Wishes**: Always preview the manifestation of your wishes before sharing them with others.
150
+
151
+ 3. **Expect Variations**: Even with careful crafting, each wish may manifest slightly differently on each request.
152
+
153
+ 4. **Mind Your Resources**: Frequent wishes may deplete your API quota. Use caching wisely.
154
+
155
+ ## The Binding Contract (License)
156
+
157
+ MonkeysPaw is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
158
+
159
+ ---
160
+
161
+ *"The paw grants exactly what you request, not what you intend."*
@@ -11,6 +11,15 @@ module MonkeysPaw
11
11
  @server = nil
12
12
  @router = nil
13
13
  @prompt_manager = nil
14
+ @cache_manager = nil
15
+ end
16
+
17
+ def prompt_manager
18
+ @prompt_manager ||= PromptManager.new(self)
19
+ end
20
+
21
+ def cache_manager
22
+ @cache_manager ||= CacheManager.new(self)
14
23
  end
15
24
 
16
25
  def configure
@@ -27,14 +36,15 @@ module MonkeysPaw
27
36
 
28
37
  @router ||= Router.new(self)
29
38
 
30
- @prompt_manager ||= PromptManager.new(self)
39
+ # Initialize prompt manager
40
+ prompt_manager
31
41
 
32
42
  @server ||= Server.new(self, **options)
33
43
  @server.start
34
44
  end
35
45
 
36
46
  def pages_dir
37
- root.join(config.pages_dir || 'pages')
47
+ root.join(config.pages_dir || 'wishes')
38
48
  end
39
49
 
40
50
  def components_dir
@@ -0,0 +1,98 @@
1
+ require 'digest'
2
+ require 'fileutils'
3
+
4
+ module MonkeysPaw
5
+ class CacheManager
6
+ attr_reader :app, :cache_dir
7
+
8
+ def initialize(app)
9
+ @app = app
10
+ @cache_dir = app.root.join('.monkeyspaw_cache')
11
+ @cache_dir.mkpath unless @cache_dir.exist?
12
+ end
13
+
14
+ def get_cached_page(path, prompt_file)
15
+ cache_key = generate_cache_key(path, prompt_file)
16
+ cache_file = cache_dir.join("#{cache_key}.html")
17
+
18
+ return nil unless cache_file.exist?
19
+
20
+ # If the cache exists, check if any dependencies have changed
21
+ if dependencies_changed?(path, prompt_file)
22
+ puts "Dependencies changed for #{path}, regenerating..."
23
+ return nil
24
+ end
25
+
26
+ puts "Using cached version of #{path}"
27
+ File.read(cache_file)
28
+ end
29
+
30
+ def cache_page(path, prompt_file, html_content)
31
+ cache_key = generate_cache_key(path, prompt_file)
32
+ cache_file = cache_dir.join("#{cache_key}.html")
33
+
34
+ # Save the HTML content
35
+ File.write(cache_file, html_content)
36
+
37
+ # Save dependency information
38
+ save_dependencies(path, prompt_file)
39
+
40
+ puts "Cached page #{path}"
41
+ end
42
+
43
+ def clear_cache
44
+ FileUtils.rm_rf(cache_dir)
45
+ cache_dir.mkpath
46
+ puts "Cache cleared"
47
+ end
48
+
49
+ private
50
+
51
+ def generate_cache_key(path, prompt_file)
52
+ # Create a unique but readable key based on the path
53
+ safe_path = path.gsub(/[^a-zA-Z0-9_-]/, '_')
54
+ safe_path = 'index' if safe_path == '_'
55
+ safe_path
56
+ end
57
+
58
+ def dependencies_changed?(path, prompt_file)
59
+ deps_file = cache_dir.join("#{generate_cache_key(path, prompt_file)}.deps")
60
+ return true unless deps_file.exist?
61
+
62
+ current_deps = get_current_dependencies(path, prompt_file)
63
+ stored_deps = JSON.parse(File.read(deps_file))
64
+
65
+ # Compare the stored and current dependencies
66
+ current_deps != stored_deps
67
+ end
68
+
69
+ def get_current_dependencies(path, prompt_file)
70
+ deps = {}
71
+
72
+ # Page content dependency
73
+ deps["page"] = file_signature(prompt_file)
74
+
75
+ # Layout component dependency
76
+ layout_file = app.prompt_manager.get_component_prompt('layout')
77
+ deps["layout"] = layout_file ? file_signature(layout_file) : app.prompt_manager.default_layout_prompt
78
+
79
+ # Style component dependency
80
+ style_file = app.prompt_manager.get_component_prompt('style')
81
+ deps["style"] = style_file ? file_signature(style_file) : app.prompt_manager.default_style_prompt
82
+
83
+ deps
84
+ end
85
+
86
+ def save_dependencies(path, prompt_file)
87
+ deps_file = cache_dir.join("#{generate_cache_key(path, prompt_file)}.deps")
88
+ deps = get_current_dependencies(path, prompt_file)
89
+
90
+ File.write(deps_file, JSON.generate(deps))
91
+ end
92
+
93
+ def file_signature(file_path)
94
+ content = File.read(file_path)
95
+ Digest::MD5.hexdigest(content)
96
+ end
97
+ end
98
+ end
@@ -6,16 +6,18 @@ module MonkeysPaw
6
6
  :components_dir,
7
7
  :assets_dir,
8
8
  :port,
9
- :host
9
+ :host,
10
+ :caching_enabled
10
11
 
11
12
  def initialize
12
13
  @provider = nil
13
14
  @model = nil
14
- @pages_dir = 'pages'
15
+ @pages_dir = 'wishes'
15
16
  @components_dir = 'components'
16
17
  @assets_dir = 'assets'
17
18
  @port = 1337
18
19
  @host = "localhost"
20
+ @caching_enabled = true
19
21
  end
20
22
 
21
23
  def to_h
@@ -4,24 +4,68 @@ module MonkeysPaw
4
4
  name: "html_code",
5
5
  description: "The generated HTML code for the web page"
6
6
 
7
- def initialize(description:)
7
+ def initialize(description:, layout_prompt: nil, style_prompt: nil)
8
8
  @description = description
9
+ @layout_prompt = layout_prompt
10
+ @style_prompt = style_prompt
9
11
  end
10
12
 
11
13
  def generate
12
- super
14
+ max_retries = 3
15
+ retry_count = 0
16
+
17
+ begin
18
+ super
19
+ rescue => e
20
+ retry_count += 1
21
+ if retry_count <= max_retries
22
+ puts "Generator attempt #{retry_count}/#{max_retries} failed: #{e.message}. Retrying..."
23
+ sleep(1) # Add a small delay between retries
24
+ retry
25
+ else
26
+ puts "Generator failed after #{max_retries} attempts. Last error: #{e.message}"
27
+ raise
28
+ end
29
+ end
13
30
  end
14
31
 
15
32
  def prompt
16
- <<-PROMPT
33
+ layout_section = ""
34
+ style_section = ""
35
+
36
+ if @layout_prompt
37
+ layout_section = <<~LAYOUT_SECTION
38
+ ## Layout Requirements:
39
+ #{@layout_prompt}
40
+ LAYOUT_SECTION
41
+ end
42
+
43
+ if @style_prompt
44
+ style_section = <<~STYLE_SECTION
45
+ ## Style Guidelines:
46
+ #{@style_prompt}
47
+ STYLE_SECTION
48
+ end
49
+
50
+ <<~PROMPT
17
51
  You are an expert HTML developer.
18
52
 
19
53
  You are tasked with writing HTML code based on the following description:
20
54
 
21
55
  #{@description}
22
56
 
57
+ #{layout_section}
58
+ #{style_section}
59
+
23
60
  Take a deep breath and think step by step before you start coding. Ensure the HTML is well-formed and valid.
61
+
62
+ The three components work together as follows:
63
+ 1. The page description provides the specific content and features this page should have
64
+ 2. The layout requirements define the structural organization and placement of elements
65
+ 3. The style guidelines inform the visual presentation and aesthetic choices
66
+
67
+ Harmonize these elements to create a cohesive and effective web page that fulfills the intended purpose.
24
68
  PROMPT
25
69
  end
26
70
  end
27
- end
71
+ end
@@ -1,15 +1,72 @@
1
1
  module MonkeysPaw
2
2
  class PromptManager
3
3
  attr_reader :app
4
+ attr_accessor :layout_prompt, :style_prompt
4
5
 
5
6
  def initialize(app)
6
7
  @app = app
8
+ load_default_components
7
9
  end
8
10
 
9
11
  def get_page_prompt(path)
10
12
  path = "/" if path.empty?
11
-
12
13
  app.router.get_file(path)
13
14
  end
15
+
16
+ def get_component_prompt(component_name)
17
+ component_file = app.components_dir.join("#{component_name}.md")
18
+ component_file if component_file.exist?
19
+ end
20
+
21
+ def load_layout_prompt
22
+ layout_file = get_component_prompt('layout')
23
+ if layout_file
24
+ @layout_prompt = File.read(layout_file)
25
+ else
26
+ @layout_prompt = default_layout_prompt
27
+ end
28
+ end
29
+
30
+ def load_style_prompt
31
+ style_file = get_component_prompt('style')
32
+ if style_file
33
+ @style_prompt = File.read(style_file)
34
+ else
35
+ @style_prompt = default_style_prompt
36
+ end
37
+ end
38
+
39
+ def load_default_components
40
+ load_layout_prompt
41
+ load_style_prompt
42
+ end
43
+
44
+ def default_layout_prompt
45
+ <<~LAYOUT
46
+ # Layout Component
47
+
48
+ Create a simple and clean layout with:
49
+ - A responsive header at the top with the page title
50
+ - A main content area that contains the primary content
51
+ - A footer with copyright information
52
+ - Navigation links if appropriate for the context
53
+
54
+ The layout should be responsive and work well on mobile and desktop devices.
55
+ LAYOUT
56
+ end
57
+
58
+ def default_style_prompt
59
+ <<~STYLE
60
+ # Style Component
61
+
62
+ Apply these styling guidelines:
63
+ - Use a clean, minimalist design with ample white space
64
+ - Color scheme: soft blues (#4A90E2) for primary elements, light gray (#F5F5F5) for backgrounds
65
+ - Typography: Sans-serif fonts (system-ui) with good readability
66
+ - Interactive elements should have subtle hover effects
67
+ - Content should be well-structured with clear hierarchy
68
+ - Ensure good contrast for accessibility
69
+ STYLE
70
+ end
14
71
  end
15
72
  end
@@ -28,7 +28,34 @@ module MonkeysPaw
28
28
  end
29
29
 
30
30
  def generate_page(path, prompt_file)
31
- HtmlFromDescriptionGenerator.new(description: File.read(prompt_file)).generate
31
+ if app.config.caching_enabled
32
+ # Try to get from cache first
33
+ cached_content = app.cache_manager.get_cached_page(path, prompt_file)
34
+ return cached_content if cached_content
35
+ end
36
+
37
+ # Cache miss or caching disabled, generate the page
38
+ # Reload layout and style prompts to pick up changes
39
+ app.prompt_manager.load_default_components
40
+ layout_prompt = app.prompt_manager.layout_prompt
41
+ style_prompt = app.prompt_manager.style_prompt
42
+
43
+ html_content = HtmlFromDescriptionGenerator.new(
44
+ description: File.read(prompt_file),
45
+ layout_prompt: layout_prompt,
46
+ style_prompt: style_prompt
47
+ ).generate
48
+
49
+ # Store in cache if enabled
50
+ if app.config.caching_enabled
51
+ app.cache_manager.cache_page(path, prompt_file, html_content)
52
+ end
53
+
54
+ html_content
55
+ end
56
+
57
+ def generate_error_page(message)
58
+ "<html><body><h1>Error</h1><p>#{message}</p></body></html>"
32
59
  end
33
60
 
34
61
  private
@@ -1,3 +1,3 @@
1
1
  module MonkeysPaw
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/monkeyspaw.rb CHANGED
@@ -6,6 +6,7 @@ require "monkeyspaw/config"
6
6
  require "monkeyspaw/server"
7
7
  require "monkeyspaw/router"
8
8
  require "monkeyspaw/prompt_manager"
9
+ require "monkeyspaw/cache_manager"
9
10
 
10
11
  Dir[File.expand_path("../monkeyspaw/generators/*.rb", __FILE__)].each { |f| require f }
11
12
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkeyspaw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Werner
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rack
@@ -117,9 +117,12 @@ executables:
117
117
  extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
+ - LICENSE
121
+ - README.md
120
122
  - exe/monkeyspaw
121
123
  - lib/monkeyspaw.rb
122
124
  - lib/monkeyspaw/application.rb
125
+ - lib/monkeyspaw/cache_manager.rb
123
126
  - lib/monkeyspaw/config.rb
124
127
  - lib/monkeyspaw/generators/html_from_description_generator.rb
125
128
  - lib/monkeyspaw/prompt_manager.rb
@@ -145,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
148
  - !ruby/object:Gem::Version
146
149
  version: '0'
147
150
  requirements: []
148
- rubygems_version: 3.6.6
151
+ rubygems_version: 3.6.7
149
152
  specification_version: 4
150
153
  summary: A prompt-driven web framework for Ruby - be careful what you wish for
151
154
  test_files: []