monkeyspaw 0.0.1 β†’ 0.0.2

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: a1db0335d3959caf2685ba8091103b01117690dc6ef220d3e97179978e9e4378
4
+ data.tar.gz: 9cea5693ddfbce5a195b7eb40f870533850226e44b75132b190640ca0cc54506
5
5
  SHA512:
6
- metadata.gz: 18e5f453eb95c34cc32873bba6a4cfc1ca4572bf47a1315fabe71badf5dd0b830a8d2e857118ca14892617b7388d1ab84113066a69bd8161d1dd1e4e91147079
7
- data.tar.gz: 7bad4ea29d4dc33d18cbf15e723b3c87e07f9680f961865fd8325b0dfdaa625b6c0b9f9c7dbde9351e050d29d77f386b23d9f36182b0324f0ab5c77eeff71eb6
6
+ metadata.gz: f5b484f83ac1a0582ff8eef6039246c6135476236e09fc4a34d3bb089f6487a414a7a7cd8fd74cbfe5c79c9ef02c111e2ddf567755c5ee0f1fb873b4b5725321
7
+ data.tar.gz: 11e986e1d6b3c9f48310a8dab9f8c36b8fef051fb8b51c640bcff0b0d29f72b7bc677adbb5eab07073da04e25b878cfb84a635c609317386215ee22a6e126d6f
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,143 @@
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
+ ## Making Your First Wish
34
+
35
+ Create a simple manifestation with just a few incantations:
36
+
37
+ ```ruby
38
+ require 'monkeyspaw'
39
+
40
+ # Make your wish come true
41
+ MonkeysPaw.pick_up!
42
+ ```
43
+
44
+ That's it! MonkeysPaw will interpret your desires by:
45
+
46
+ 1. Reading prompt files from the `wishes/` directory
47
+ 2. Channeling the AI entity to manifest your content
48
+ 3. Summoning a web server (default: http://localhost:1337)
49
+
50
+ ## Structuring Your Desires
51
+
52
+ MonkeysPaw follows arcane file-based conventions:
53
+
54
+ ```
55
+ your-project/
56
+ β”œβ”€β”€ wishes/ # Your primary desires
57
+ β”‚ β”œβ”€β”€ index.md # Home page (/)
58
+ β”‚ β”œβ”€β”€ about.md # About page (/about)
59
+ β”‚ └── curses/
60
+ β”‚ β”œβ”€β”€ 01-wish.md # First curse (/curses/01-wish)
61
+ β”‚ └── 02-consequence.md # Second curse (/curses/02-consequence)
62
+ β”œβ”€β”€ components/ # Recurring incantations
63
+ β”‚ β”œβ”€β”€ layout.md # The container of all things
64
+ β”‚ └── navigation.md # Pathways between realms
65
+ β”œβ”€β”€ assets/ # Physical manifestations
66
+ β”‚ └── images/
67
+ β”‚ └── paw-mark.png
68
+ └── app.rb # Where the magic begins
69
+ ```
70
+
71
+ ## Crafting Effective Wishes (Prompts)
72
+
73
+ The art of prompt crafting is delicate. Be specific, or face the consequences of ambiguity:
74
+
75
+ ```markdown
76
+ # Page: Introduction to MonkeysPaw
77
+
78
+ ## Content Instructions:
79
+ Create an engaging introduction to a framework that grants web development wishes
80
+ through AI prompts. Emphasize the need for precise language.
81
+
82
+ ## Key Points:
83
+ - The dual nature of wish fulfillment: power and peril
84
+ - How imprecise wishes lead to unexpected outcomes
85
+ - Examples of well-crafted vs. poorly-crafted prompts
86
+
87
+ ## Style:
88
+ - Mysterious yet professional tone
89
+ - Include a cautionary opening statement
90
+ - End with advice for the wish-maker
91
+
92
+ ## Visual Elements:
93
+ - A clear warning header
94
+ - Short, foreboding paragraphs
95
+ - A callout box with "Do's and Don'ts" for prompt crafting
96
+ ```
97
+
98
+ ## Controlling Your Fate
99
+
100
+ Configure the terms of your pact:
101
+
102
+ ```ruby
103
+ MonkeysPaw.configure do |config|
104
+ config.port = 4567
105
+ config.host = 'localhost'
106
+ end
107
+ ```
108
+
109
+ ## Mystical Entities Available for Summoning (TODO)
110
+
111
+ MonkeysPaw can channel various AI entities:
112
+
113
+ ```ruby
114
+ # The Gemini Spirit
115
+ MonkeysPaw.use :gemini, model: :gemini_2_0_flash
116
+
117
+ # The OpenAI Oracle
118
+ MonkeysPaw.use :openai, model: :gpt_4
119
+
120
+ # The Anthropic Sage
121
+ MonkeysPaw.use :anthropic, model: :claude_3_opus
122
+
123
+ # The Mistral Wind
124
+ MonkeysPaw.use :mistral, model: :mistral_large
125
+ ```
126
+
127
+ ## Words of Caution
128
+
129
+ 1. **Be Precise**: Ambiguity is your enemy. The more specific your wishes, the fewer surprises you'll face.
130
+
131
+ 2. **Test Your Wishes**: Always preview the manifestation of your wishes before sharing them with others.
132
+
133
+ 3. **Expect Variations**: Even with careful crafting, each wish may manifest slightly differently on each request.
134
+
135
+ 4. **Mind Your Resources**: Frequent wishes may deplete your API quota. Use caching wisely.
136
+
137
+ ## The Binding Contract (License)
138
+
139
+ MonkeysPaw is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
140
+
141
+ ---
142
+
143
+ *"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
@@ -26,15 +35,16 @@ module MonkeysPaw
26
35
  setup_directories
27
36
 
28
37
  @router ||= Router.new(self)
29
-
30
- @prompt_manager ||= PromptManager.new(self)
38
+
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,74 @@
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
+ private
45
+
46
+ def default_layout_prompt
47
+ <<~LAYOUT
48
+ # Layout Component
49
+
50
+ Create a simple and clean layout with:
51
+ - A responsive header at the top with the page title
52
+ - A main content area that contains the primary content
53
+ - A footer with copyright information
54
+ - Navigation links if appropriate for the context
55
+
56
+ The layout should be responsive and work well on mobile and desktop devices.
57
+ LAYOUT
58
+ end
59
+
60
+ def default_style_prompt
61
+ <<~STYLE
62
+ # Style Component
63
+
64
+ Apply these styling guidelines:
65
+ - Use a clean, minimalist design with ample white space
66
+ - Color scheme: soft blues (#4A90E2) for primary elements, light gray (#F5F5F5) for backgrounds
67
+ - Typography: Sans-serif fonts (system-ui) with good readability
68
+ - Interactive elements should have subtle hover effects
69
+ - Content should be well-structured with clear hierarchy
70
+ - Ensure good contrast for accessibility
71
+ STYLE
72
+ end
14
73
  end
15
- end
74
+ end
@@ -28,7 +28,30 @@ 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
32
55
  end
33
56
 
34
57
  private
@@ -79,5 +102,8 @@ module MonkeysPaw
79
102
  end
80
103
  end
81
104
 
105
+ def generate_error_page(message)
106
+ "<html><body><h1>Error</h1><p>#{message}</p></body></html>"
107
+ end
82
108
  end
83
109
  end
@@ -1,3 +1,3 @@
1
1
  module MonkeysPaw
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
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,7 +1,7 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Werner
@@ -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