Class: Airb::Systems::Governance

Inherits:
VSM::Governance
  • Object
show all
Defined in:
lib/airb/systems/governance.rb

Instance Method Summary collapse

Constructor Details

#initialize(workspace_root:) ⇒ Governance

Returns a new instance of Governance.



5
6
7
8
# File 'lib/airb/systems/governance.rb', line 5

def initialize(workspace_root:)
  @workspace_root = File.expand_path(workspace_root)
  @pending = {}   # corr_id => original :tool_call message
end

Instance Method Details

#enforce(message, &pass) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/airb/systems/governance.rb', line 13

def enforce(message, &pass)
  case message.kind
  when :tool_call
    if risky?(message)
      ensure_corr_id!(message)
      @pending[message.corr_id] = message
      @bus.emit VSM::Message.new(
        kind: :confirm_request,
        payload: confirm_text(message),
        meta: message.meta.merge({ corr_id: message.corr_id }),
        path: [:airb, :governance]
      )
      return true # swallow for now; will resume on confirm_response
    else
      check_paths!(message)
    end
  when :confirm_response
    corr = message.meta&.fetch(:corr_id, nil)
    if corr && (orig = @pending.delete(corr))
      if message.payload[:accepted]
        # proceed with original tool_call
        return pass.call(orig)
      else
        # inform user and drop
        @bus.emit VSM::Message.new(
          kind: :assistant,
          payload: "Cancelled.",
          meta: orig.meta,
          path: [:airb, :governance]
        )
        return true
      end
    end
  end

  pass.call(message)
end

#observe(bus) ⇒ Object

Capture bus reference for emitting confirm requests, etc.



11
# File 'lib/airb/systems/governance.rb', line 11

def observe(bus) = (@bus = bus)