struct

Smith::Tools::Rule

Inherits Struct < Value < Object

One tool(pattern) entry. What pattern means depends on the tool: for bash it matches the command, for the file tools the path.

Constants

MCP_PREFIX = "mcp__"

read_file on its own would silently widen to read_file(*), which is not what anyone writing a path rule means. Two forms are unambiguous enough to accept bare: anything carrying a wildcard, and any MCP tool โ€” smith cannot interpret a server's arguments, so its name is the only thing a rule could ever match on.

PATH_TOOLS = ["read_file", "write_file", "edit_file", "glob", "grep"] of ::String

Tools whose pattern is a path glob rather than a shell command.

Constructors

new(tool : String, pattern : String)
Source

Class methods

command_regex(pattern : String) : Regex

Everything is escaped except *, which becomes .*. The trailing group is what makes bash(git status) cover git status --short while still rejecting git statuses.

Source
expand_pattern(pattern : String, project_dir : String) : String

A pattern starting with ** stays unanchored, so read_file(**/.ssh/**) can catch a key outside the project. Anything else relative is resolved against the project directory.

Source
parse(str : String) : Rule | Nil

A malformed entry yields nil rather than raising: a typo in a config file must not stop smith from starting.

Source

Instance methods

covers?(tool_name : String) : Bool

mcp__filesystem__* covers every tool of that server. Anchored at both ends, so mcp__fs__read cannot be matched by a rule meant for another server whose name merely starts the same way.

Source
matches?(tool_name : String, args : JSON::Any, project_dir : String, all : Bool) : Bool

all distinguishes the two halves of shell-command matching, and the distinction is security-critical:

allow โ€” every segment must match, so an allowed prefix cannot smuggle a second command in behind it deny โ€” any segment matching is enough, so a denied command cannot hide behind a harmless one

Source
path_tool?
Source
pattern
Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
tool
Source
wildcard?

Whether the rule names a family of tools rather than one.

Source