ruby-mana 0.1.0 → 0.3.0

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.
@@ -5,6 +5,13 @@ require "binding_of_caller"
5
5
  class String
6
6
  # ~"natural language prompt" → execute via Mana engine
7
7
  def ~@
8
- Mana::Engine.run(self, binding.of_caller(1))
8
+ return self if Thread.current[:mana_running]
9
+
10
+ Thread.current[:mana_running] = true
11
+ begin
12
+ Mana::Engine.run(self, binding.of_caller(1))
13
+ ensure
14
+ Thread.current[:mana_running] = false
15
+ end
9
16
  end
10
17
  end
data/lib/mana/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mana
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/mana.rb CHANGED
@@ -2,8 +2,14 @@
2
2
 
3
3
  require_relative "mana/version"
4
4
  require_relative "mana/config"
5
- require_relative "mana/effects"
5
+ require_relative "mana/effect_registry"
6
+ require_relative "mana/namespace"
7
+ require_relative "mana/memory_store"
8
+ require_relative "mana/context_window"
9
+ require_relative "mana/memory"
6
10
  require_relative "mana/engine"
11
+ require_relative "mana/introspect"
12
+ require_relative "mana/compiler"
7
13
  require_relative "mana/string_ext"
8
14
  require_relative "mana/mixin"
9
15
 
@@ -32,6 +38,38 @@ module Mana
32
38
 
33
39
  def reset!
34
40
  @config = Config.new
41
+ EffectRegistry.clear!
42
+ Thread.current[:mana_memory] = nil
43
+ end
44
+
45
+ # Define a custom effect that becomes an LLM tool
46
+ def define_effect(name, description: nil, &handler)
47
+ EffectRegistry.define(name, description: description, &handler)
48
+ end
49
+
50
+ # Remove a custom effect
51
+ def undefine_effect(name)
52
+ EffectRegistry.undefine(name)
53
+ end
54
+
55
+ # Access current thread's memory
56
+ def memory
57
+ Memory.current
58
+ end
59
+
60
+ # Run a block in incognito mode (no memory)
61
+ def incognito(&block)
62
+ Memory.incognito(&block)
63
+ end
64
+
65
+ # View generated source for a mana-compiled method
66
+ def source(method_name, owner: nil)
67
+ Compiler.source(method_name, owner: owner)
68
+ end
69
+
70
+ # Cache directory for compiled methods
71
+ def cache_dir=(dir)
72
+ Compiler.cache_dir = dir
35
73
  end
36
74
  end
37
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mana
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-20 00:00:00.000000000 Z
11
+ date: 2026-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -37,12 +37,16 @@ files:
37
37
  - LICENSE
38
38
  - README.md
39
39
  - lib/mana.rb
40
+ - lib/mana/compiler.rb
40
41
  - lib/mana/config.rb
41
- - lib/mana/effects.rb
42
+ - lib/mana/context_window.rb
43
+ - lib/mana/effect_registry.rb
42
44
  - lib/mana/engine.rb
43
- - lib/mana/llm/anthropic.rb
44
- - lib/mana/llm/base.rb
45
+ - lib/mana/introspect.rb
46
+ - lib/mana/memory.rb
47
+ - lib/mana/memory_store.rb
45
48
  - lib/mana/mixin.rb
49
+ - lib/mana/namespace.rb
46
50
  - lib/mana/string_ext.rb
47
51
  - lib/mana/version.rb
48
52
  homepage: https://github.com/carlnoah6/ruby-mana
@@ -67,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
71
  - !ruby/object:Gem::Version
68
72
  version: '0'
69
73
  requirements: []
70
- rubygems_version: 3.4.20
74
+ rubygems_version: 3.5.22
71
75
  signing_key:
72
76
  specification_version: 4
73
77
  summary: Embed LLM as native Ruby — write natural language, it just runs
data/lib/mana/effects.rb DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mana
4
- module Effects
5
- ReadVar = Struct.new(:name)
6
- WriteVar = Struct.new(:name, :value)
7
- ReadAttr = Struct.new(:obj_name, :attr)
8
- WriteAttr = Struct.new(:obj_name, :attr, :value)
9
- CallFunc = Struct.new(:name, :args)
10
- Done = Struct.new(:result)
11
- end
12
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "net/http"
4
- require "uri"
5
- require "json"
6
-
7
- module Mana
8
- module LLM
9
- class Anthropic < Base
10
- API_URL = "https://api.anthropic.com/v1/messages"
11
- API_VERSION = "2023-06-01"
12
-
13
- def initialize(config = Mana.config)
14
- super(config)
15
- @api_key = config.api_key
16
- @model = config.model
17
- end
18
-
19
- def chat(system:, messages:, tools:)
20
- raise Mana::Error, "Anthropic API key not set" unless @api_key
21
-
22
- body = {
23
- model: @model,
24
- max_tokens: 4096,
25
- temperature: @config.temperature,
26
- system: system,
27
- messages: messages,
28
- tools: tools
29
- }
30
-
31
- response = post(body)
32
-
33
- unless response.is_a?(Net::HTTPSuccess)
34
- parsed = JSON.parse(response.body) rescue nil
35
- error_msg = parsed&.dig("error", "message") || response.body
36
- raise Mana::Error, "Anthropic API error (#{response.code}): #{error_msg}"
37
- end
38
-
39
- parsed = JSON.parse(response.body)
40
- parsed["content"].map { |block| symbolize_keys(block) }
41
- end
42
-
43
- private
44
-
45
- def post(body)
46
- uri = URI(API_URL)
47
- http = Net::HTTP.new(uri.host, uri.port)
48
- http.use_ssl = true
49
- http.open_timeout = 30
50
- http.read_timeout = 120
51
- http.write_timeout = 30
52
-
53
- request = Net::HTTP::Post.new(uri)
54
- request["x-api-key"] = @api_key
55
- request["anthropic-version"] = API_VERSION
56
- request["content-type"] = "application/json"
57
- request.body = JSON.generate(body)
58
-
59
- http.request(request)
60
- end
61
-
62
- def symbolize_keys(hash)
63
- hash.each_with_object({}) do |(k, v), acc|
64
- acc[k.to_sym] = v.is_a?(Hash) ? symbolize_keys(v) : v
65
- end
66
- end
67
- end
68
- end
69
- end
data/lib/mana/llm/base.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mana
4
- module LLM
5
- # Base interface for LLM clients.
6
- # Subclass and implement #chat to add new providers.
7
- class Base
8
- def initialize(config)
9
- @config = config
10
- end
11
-
12
- # Send a chat request with tools.
13
- # Returns an array of content blocks (tool_use / text).
14
- def chat(system:, messages:, tools:)
15
- raise NotImplementedError, "#{self.class}#chat not implemented"
16
- end
17
- end
18
- end
19
- end