Module: Textus::Role

Defined in:
lib/textus/role.rb

Constant Summary collapse

PATTERN =
/\A[a-z][a-z0-9_-]*\z/
DEFAULT =
"human".freeze
AGENT =

The default acting identity for the MCP transport (ADR 0040): an agent over stdio proposes; it does not inherit the human’s authority. CLI callers keep the ‘human` DEFAULT.

"agent".freeze

Class Method Summary collapse

Class Method Details

.read_file(root) ⇒ Object



17
18
19
20
21
22
# File 'lib/textus/role.rb', line 17

def self.read_file(root)
  path = File.join(root, "role")
  return nil unless File.exist?(path)

  File.read(path).strip.then { |s| s.empty? ? nil : s }
end

.resolve(root:, flag: nil, env: ENV, default: DEFAULT) ⇒ Object

Raises:



10
11
12
13
14
15
# File 'lib/textus/role.rb', line 10

def self.resolve(root:, flag: nil, env: ENV, default: DEFAULT)
  candidate = flag || env["TEXTUS_ROLE"] || read_file(root) || default
  raise InvalidRole.new(candidate) unless candidate.match?(PATTERN)

  candidate
end