nexo_ai 0.12.0 → 0.13.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.
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Nexo
6
+ module Skills
7
+ # One skill package read from disk: a folder holding a `SKILL.md` (YAML front
8
+ # matter + Markdown body) and, optionally, `scripts/`, `assets/` and
9
+ # `references/`.
10
+ #
11
+ # This is a deliberately small reader. `ruby_llm` ships its own
12
+ # `RubyLLM::Skill`, but it enforces the Agent Skills naming rule (lowercase
13
+ # words joined by hyphens, equal to the folder name), which rejects the
14
+ # underscore names Nexo has always resolved from a symbol (`skills
15
+ # :email_triage`). Nexo only ever needs the body text and the file listings,
16
+ # so it reads those itself rather than force every host to rename its skills.
17
+ class Skill
18
+ # The file that makes a folder a skill.
19
+ FILE = "SKILL.md"
20
+
21
+ # The bundled-file folders a skill may ship.
22
+ KINDS = %w[scripts assets references].freeze
23
+
24
+ FRONT_MATTER = /\A---[ \t]*\r?\n(.*?)^---[ \t]*(?:\r?\n|\z)/m
25
+ private_constant :FRONT_MATTER
26
+
27
+ # The skill's folder, as an absolute path String.
28
+ attr_reader :path
29
+
30
+ # The front matter as a Hash with String keys.
31
+ attr_reader :metadata
32
+
33
+ # The `SKILL.md` body: the instructions injected into the chat.
34
+ attr_reader :content
35
+
36
+ # Reads the skill in the folder `path`. Raises Nexo::Error naming the file
37
+ # when `SKILL.md` is missing, has no front matter, or its front matter is
38
+ # not a YAML mapping.
39
+ def initialize(path)
40
+ @path = File.expand_path(path.to_s)
41
+ file = File.join(@path, FILE)
42
+ raise Error, "skill not found: #{file}" unless File.file?(file)
43
+
44
+ @metadata, @content = parse(File.read(file, encoding: "UTF-8"), file)
45
+ end
46
+
47
+ # The skill's declared name.
48
+ def name = metadata["name"]
49
+
50
+ # The one-line summary of when to use the skill.
51
+ def description = metadata["description"]
52
+
53
+ # What the skill needs from its environment, or nil when it declares nothing.
54
+ def compatibility = metadata["compatibility"]
55
+
56
+ # Host paths of the files under `scripts/`, sorted.
57
+ def scripts = files("scripts")
58
+
59
+ # Host paths of the files under `assets/`, sorted.
60
+ def assets = files("assets")
61
+
62
+ # Host paths of the files under `references/`, sorted.
63
+ def references = files("references")
64
+
65
+ private
66
+
67
+ # Splits `text` into its front matter Hash and its Markdown body.
68
+ def parse(text, file)
69
+ match = FRONT_MATTER.match(text.delete_prefix("\u{FEFF}"))
70
+ raise Error, "#{file} must start with YAML front matter between --- lines" unless match
71
+
72
+ front_matter = YAML.safe_load(match[1], permitted_classes: [Date, Time], aliases: false)
73
+ raise Error, "#{file} front matter must be a YAML mapping" unless front_matter.is_a?(Hash)
74
+
75
+ [front_matter.transform_keys(&:to_s), match.post_match.strip]
76
+ rescue Psych::Exception => e
77
+ raise Error, "#{file} has invalid YAML front matter: #{e.message}"
78
+ end
79
+
80
+ # The files under one of the skill's folders, as sorted host paths.
81
+ def files(kind)
82
+ dir = File.join(path, kind)
83
+ return [] unless File.directory?(dir)
84
+
85
+ Dir.glob(File.join(dir, "**", "*")).select { |f| File.file?(f) && File.basename(f) != ".keep" }.sort
86
+ end
87
+ end
88
+ end
89
+ end
data/lib/nexo/skills.rb CHANGED
@@ -1,14 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nexo
4
- # Composes the `ruby_llm-skills` gem so a developer can drop a SKILL.md package
5
- # into `app/skills/<name>/` and attach it to an agent with a single `skills`
6
- # class macro — no loader wiring.
7
- #
8
- # `ruby_llm-skills` is a SOFT (optional) runtime dependency: it is required
9
- # lazily by load! the first time a skill is used. With the gem absent,
10
- # `require "nexo"` still loads cleanly; only touching a skill raises
11
- # MissingDependencyError with install guidance.
4
+ # Skills: drop a SKILL.md package into `app/skills/<name>/` and attach it to an
5
+ # agent with a single `skills` class macro — no loader wiring, and no extra gem.
12
6
  #
13
7
  # A loaded skill contributes its **instructions** (the SKILL.md body) to a chat.
14
8
  # It ships no independent tools, so attaching a skill never widens the agent's
@@ -19,41 +13,20 @@ module Nexo
19
13
  # its own working directory, and nothing bridges the two. To let an agent read or
20
14
  # run a skill's bundled files, copy them into the sandbox first — through the
21
15
  # sandbox's own `#write`, so it works on every tier. They are then reached through
22
- # Nexo's permission-gated tools like any other workspace file. See the
23
- # spec's "Verified APIs" / safety resolution for why the gem's progressive
24
- # disclosure `SkillTool` (which does ungated `File.read`) is deliberately not
25
- # attached.
16
+ # Nexo's permission-gated tools like any other workspace file.
17
+ #
18
+ # `ruby_llm` has its own skills (`Chat#with_skills`, which adds a `load_skill`
19
+ # tool). Nexo does not attach it: skill text goes in as instructions, and a
20
+ # skill's files are reached only through the gated sandbox tools.
26
21
  module Skills
27
22
  class << self
28
- # Lazily loads the `ruby_llm-skills` gem. Idempotent (a second call is a
29
- # cheap no-op once the gem is loaded). Raises MissingDependencyError —
30
- # naming the gem and the exact remedy — when the gem is not installed.
31
- def load!
32
- require "ruby_llm/skills"
33
- rescue LoadError
34
- raise MissingDependencyError,
35
- 'Skills require the `ruby_llm-skills` gem. Add `gem "ruby_llm-skills"` to your Gemfile.'
36
- end
37
-
38
- # Resolves a skill `name` (symbol or string) to a loaded skill object read
39
- # from the filesystem under Nexo.config.skills_path. The filesystem is the
40
- # only skill source in v1 — zip/DB/remote loading is deferred entirely to
41
- # `ruby_llm-skills`.
23
+ # Resolves a skill `name` (symbol or string) to a Skills::Skill read from
24
+ # `<skills_path>/<name>/SKILL.md` under Nexo.config.skills_path. The
25
+ # filesystem is the only skill source.
42
26
  #
43
- # Calls load! first (so an absent gem surfaces MissingDependencyError),
44
- # then resolves `<skills_path>/<name>/SKILL.md`. A missing file raises
45
- # Error whose message names the resolved path.
46
- #
47
- # Returns the loaded `RubyLLM::Skills::Skill` (exposes `#content`, `#name`,
48
- # `#description`).
27
+ # A missing file raises Error whose message names the resolved path.
49
28
  def find(name)
50
- load!
51
-
52
- dir = File.join(Nexo.config.skills_path.to_s, name.to_s)
53
- skill_md = File.join(dir, "SKILL.md")
54
- raise Error, "skill not found: #{skill_md}" unless File.exist?(skill_md)
55
-
56
- RubyLLM::Skills.load(dir)
29
+ Skill.new(File.join(Nexo.config.skills_path.to_s, name.to_s))
57
30
  end
58
31
 
59
32
  # Copies a skill's bundled files INTO a sandbox, so an agent can read or run
@@ -101,8 +74,8 @@ module Nexo
101
74
 
102
75
  private
103
76
 
104
- # A skill's files of one kind, as host paths. Virtual (database-backed) skills
105
- # have no filesystem resources and answer with an empty list.
77
+ # A skill's files of one kind, as host paths. An object that does not answer
78
+ # the kind (a skill double with no bundled files) yields an empty list.
106
79
  def resources(skill, kind)
107
80
  return [] unless %i[scripts assets references].include?(kind.to_sym)
108
81
  return [] unless skill.respond_to?(kind)
@@ -22,7 +22,7 @@ module Nexo
22
22
  # `{ error: <message> }`.
23
23
  class Fetch < RubyLLM::Tool
24
24
  description "Fetch the text of a web page by URL (HTTP/HTTPS GET only)."
25
- param :url, type: :string, required: true, desc: "Absolute http(s) URL to fetch"
25
+ parameter :url, type: :string, required: true, description: "Absolute http(s) URL to fetch"
26
26
 
27
27
  # Bodies are truncated to this many bytes (byteslice) before returning.
28
28
  MAX_BYTES = 200_000
@@ -6,7 +6,7 @@ module Nexo
6
6
  # a denial is returned as `{ error: ... }`.
7
7
  class Glob < RubyLLM::Tool
8
8
  description "List files in the workspace matching a glob pattern."
9
- param :pattern, type: :string, required: true, desc: "Glob pattern, e.g. **/*.rb"
9
+ parameter :pattern, type: :string, required: true, description: "Glob pattern, e.g. **/*.rb"
10
10
 
11
11
  # `sandbox` performs the match; `permissions` gates the `:glob` capability.
12
12
  def initialize(sandbox:, permissions:)
@@ -11,7 +11,7 @@ module Nexo
11
11
  # the model can adapt instead of the loop crashing.
12
12
  class ReadFile < RubyLLM::Tool
13
13
  description "Read a file from the workspace."
14
- param :path, type: :string, required: true, desc: "Path to the file to read"
14
+ parameter :path, type: :string, required: true, description: "Path to the file to read"
15
15
 
16
16
  # Returned content is capped to this many bytes (head), matching Tools::Fetch,
17
17
  # so a single huge file can't blow a small context window. The read-before-write
@@ -7,7 +7,7 @@ module Nexo
7
7
  # returned as `{ error: ... }` rather than raised into the loop.
8
8
  class Shell < RubyLLM::Tool
9
9
  description "Run a shell command in the agent's workspace."
10
- param :command, type: :string, required: true, desc: "The command to execute"
10
+ parameter :command, type: :string, required: true, description: "The command to execute"
11
11
 
12
12
  # `sandbox` runs the command; `permissions` gates the `:shell` capability.
13
13
  def initialize(sandbox:, permissions:)
@@ -21,7 +21,7 @@ module Nexo
21
21
  # rows); any denial or error is `{ error: <message> }`.
22
22
  class WebSearch < RubyLLM::Tool
23
23
  description "Search the web for a query; returns titles, URLs, and snippets."
24
- param :query, type: :string, required: true, desc: "The search query"
24
+ parameter :query, type: :string, required: true, description: "The search query"
25
25
 
26
26
  # At most this many result rows are returned.
27
27
  MAX_RESULTS = 8
@@ -6,8 +6,8 @@ module Nexo
6
6
  # a denial is returned as `{ error: ... }` (and nothing is written).
7
7
  class WriteFile < RubyLLM::Tool
8
8
  description "Write content to a file in the workspace."
9
- param :path, type: :string, required: true, desc: "Path to the file to write"
10
- param :content, type: :string, required: true, desc: "Content to write"
9
+ parameter :path, type: :string, required: true, description: "Path to the file to write"
10
+ parameter :content, type: :string, required: true, description: "Content to write"
11
11
 
12
12
  # `tracker:` is an optional ReadTracker shared with Tools::ReadFile.
13
13
  # Default `nil` ⇒ the read-before-write + stale guard is off, preserving
data/lib/nexo/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nexo
4
4
  # The gem version (also used as `spec.version` in the gemspec).
5
- VERSION = "0.12.0"
5
+ VERSION = "0.13.0"
6
6
  end
data/lib/nexo/workflow.rb CHANGED
@@ -901,7 +901,7 @@ module Nexo
901
901
  # and degrades gracefully — a missing field falls back to `to_s` rather than
902
902
  # raising, so observability never breaks the run.
903
903
  #
904
- # Field mapping (VERIFIED Group 0, ruby_llm 1.16.0):
904
+ # Field mapping (VERIFIED against the real loop, ruby_llm 2.2.3):
905
905
  # - `:tool_call` → `ToolCall#name` + `#arguments` (or a plain `{name:, args:}` Hash).
906
906
  # - `:tool_result` → the tool's return value: a String (ok), or a `{error:}`/
907
907
  # `{content:}` Hash from a Nexo gated tool (`ok` derived from `error`).
@@ -926,11 +926,16 @@ module Nexo
926
926
  end
927
927
  end
928
928
 
929
+ # ruby_llm 2.x hands tool arguments over with Symbol keys. Events are stored
930
+ # string-keyed (an AR json column round-trips that way anyway), so normalize
931
+ # here and the Memory and ActiveRecord stores agree.
929
932
  def tool_call_args(payload)
930
- return payload.arguments if payload.respond_to?(:arguments)
931
- return payload.args if payload.respond_to?(:args)
932
-
933
- nil
933
+ args = if payload.respond_to?(:arguments)
934
+ payload.arguments
935
+ elsif payload.respond_to?(:args)
936
+ payload.args
937
+ end
938
+ args.is_a?(Hash) ? args.transform_keys(&:to_s) : args
934
939
  end
935
940
 
936
941
  def reduce_tool_result(payload)
data/lib/nexo.rb CHANGED
@@ -114,12 +114,10 @@ end
114
114
  # for_gem (called from lib/nexo.rb) roots the loader at lib/ and treats
115
115
  # lib/nexo.rb as the gem's main file.
116
116
  loader = Zeitwerk::Loader.for_gem
117
- # Loop-backend filenames carry acronyms Zeitwerk can't infer on its own:
118
- # lib/nexo/loops/ruby_llm.rb -> Nexo::Loops::RubyLLM and
119
- # lib/nexo/loops/agent_sdk.rb -> Nexo::Loops::AgentSDK (Spec 4).
117
+ # Filenames carrying acronyms Zeitwerk can't infer on its own:
118
+ # lib/nexo/loops/ruby_llm.rb -> Nexo::Loops::RubyLLM and lib/nexo/mcp.rb -> Nexo::MCP.
120
119
  loader.inflector.inflect(
121
120
  "ruby_llm" => "RubyLLM",
122
- "agent_sdk" => "AgentSDK",
123
121
  "mcp" => "MCP"
124
122
  )
125
123
  # The require-shim is not a managed constant — Zeitwerk must not infer a constant
data/sig/nexo/agent.rbs CHANGED
@@ -17,7 +17,7 @@ module Nexo
17
17
  attr_reader instructions: String?
18
18
 
19
19
  def initialize: (?cwd: String, ?model: untyped, ?sandbox: untyped, ?permissions: untyped) -> void
20
- def chat: () -> RubyLLM::Chat
20
+ def chat: (?base: untyped) -> RubyLLM::Chat
21
21
  def prompt: (String text) ?{ (untyped) -> void } -> untyped
22
22
  end
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexo_ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Alberto Chávez
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '1.16'
18
+ version: 2.2.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '1.16'
25
+ version: 2.2.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: zeitwerk
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -37,20 +37,6 @@ dependencies:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '2.6'
40
- - !ruby/object:Gem::Dependency
41
- name: ruby_llm-test
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
- type: :development
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
40
  - !ruby/object:Gem::Dependency
55
41
  name: standard
56
42
  requirement: !ruby/object:Gem::Requirement
@@ -65,20 +51,6 @@ dependencies:
65
51
  - - ">="
66
52
  - !ruby/object:Gem::Version
67
53
  version: '0'
68
- - !ruby/object:Gem::Dependency
69
- name: ruby_llm-skills
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '0'
75
- type: :development
76
- prerelease: false
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '0'
82
54
  - !ruby/object:Gem::Dependency
83
55
  name: rails
84
56
  requirement: !ruby/object:Gem::Requirement
@@ -184,7 +156,6 @@ files:
184
156
  - lib/nexo/configuration.rb
185
157
  - lib/nexo/engine.rb
186
158
  - lib/nexo/loop.rb
187
- - lib/nexo/loops/agent_sdk.rb
188
159
  - lib/nexo/loops/ruby_llm.rb
189
160
  - lib/nexo/mcp.rb
190
161
  - lib/nexo/mcp/gated_tool.rb
@@ -200,6 +171,7 @@ files:
200
171
  - lib/nexo/sandboxes/virtual.rb
201
172
  - lib/nexo/session.rb
202
173
  - lib/nexo/skills.rb
174
+ - lib/nexo/skills/skill.rb
203
175
  - lib/nexo/tools/fetch.rb
204
176
  - lib/nexo/tools/glob.rb
205
177
  - lib/nexo/tools/read_file.rb
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nexo
4
- module Loops
5
- # An opt-in, Anthropic-oriented loop that delegates to `ruby_llm-agent_sdk`'s
6
- # own engine: native `max_turns`, permission modes, and the SDK's built-in
7
- # tools. It is NOT the default and is not provider-neutral — choose it
8
- # explicitly with `loop: Nexo::Loops::AgentSDK.new` when you are on Anthropic
9
- # and want the Claude fast path.
10
- #
11
- # The trade vs. Loops::RubyLLM: this leans on the SDK's own built-in tools
12
- # and runs in the host process, so it does NOT execute through Nexo's
13
- # pluggable sandbox. That is the documented cost of the native `max_turns`
14
- # hard cap (see the turn-cap caveat in the README).
15
- #
16
- # `ruby_llm-agent_sdk` is a SOFT dependency: it is required lazily inside
17
- # `#run` and, when absent, surfaces as a Nexo::MissingDependencyError with
18
- # install guidance — `require "nexo"` without the gem never raises.
19
- #
20
- # VERIFY-on-install: the gem is not installed in this environment, so
21
- # `RubyLLM::AgentSDK.query`'s exact signature and the `:result` terminal
22
- # message shape below remain provisional (per references.md). Confirm them
23
- # against the `ruby_llm-agent_sdk` README the moment the gem is added and
24
- # record the result under "Verified APIs".
25
- class AgentSDK < Nexo::Loop
26
- def run(agent:, prompt:, max_turns: 25, chat: nil, &on_event)
27
- unless chat.nil?
28
- raise Nexo::ConfigurationError,
29
- "Loops::AgentSDK runs its own in-process loop and cannot continue a persisted Nexo::Session chat — use the default Loops::RubyLLM for sessions."
30
- end
31
-
32
- load_sdk!
33
-
34
- result = nil
35
- ::RubyLLM::AgentSDK.query(
36
- prompt,
37
- model: agent.model,
38
- max_turns: max_turns,
39
- permission_mode: agent.permission_mode, # Nexo mode mapped by the agent
40
- allowed_tools: agent.allowed_tools # %w[Read Write Edit Bash Glob Grep]
41
- ) do |message|
42
- on_event&.call(message.type, message)
43
- result = message if message.type == :result
44
- end
45
- # Emit the contract's terminal :done event (the base Loop advertises
46
- # :tool_call/:tool_result/:done) so a Workflow#run_agent driving THIS
47
- # backend records an `agent_done` just like the default loop does. The
48
- # SDK's INTERMEDIATE event types stay backend-native (:assistant/:result/…)
49
- # — this loop is opt-in and its per-message vocabulary is the SDK's.
50
- on_event&.call(:done, result)
51
- result
52
- end
53
-
54
- private
55
-
56
- # Lazily loads the opt-in `ruby_llm-agent_sdk` gem. The rescue wraps ONLY the
57
- # require (mirroring Skills.load!/MCP.load!), so a LoadError raised from
58
- # inside the SDK's own `query` or the caller's block is NOT mislabeled as a
59
- # missing-gem error.
60
- def load_sdk!
61
- require "ruby_llm/agent_sdk" # VERIFY exact require path on install
62
- rescue LoadError
63
- raise Nexo::MissingDependencyError,
64
- "Loops::AgentSDK requires the `ruby_llm-agent_sdk` gem. Add `gem \"ruby_llm-agent_sdk\"` to your Gemfile and run `bundle install`."
65
- end
66
- end
67
- end
68
- end