Class: KairosMcp::Daemon::CodeGenPhaseHandler
- Inherits:
-
Object
- Object
- KairosMcp::Daemon::CodeGenPhaseHandler
- Defined in:
- lib/kairos_mcp/daemon/code_gen_phase_handler.rb
Overview
CodeGenPhaseHandler — bridges CodeGenAct into the CognitiveLoop ACT phase.
Design (P3.2 v0.2 §4.5, M6):
When CognitiveLoop's DECIDE phase produces a code_edit decision,
the ACT phase delegates to CodeGenAct. If PauseForApproval is raised,
the handler catches it and returns a paused result so the WAL recorder
can mark the step as paused (not failed, not completed).
On subsequent cycles, the handler's `resume_if_pending` is called
before a new OODA cycle begins, checking whether any pending proposal
has been approved.
Constant Summary collapse
- PAUSED_STATUS =
'paused_awaiting_approval'
Instance Attribute Summary collapse
-
#pending_proposal_id ⇒ Object
readonly
Returns the value of attribute pending_proposal_id.
Instance Method Summary collapse
-
#handle_act(decision, mandate) ⇒ Hash
Execute the ACT phase for a code_edit decision.
-
#initialize(code_gen_act:, wal_phase_recorder: nil) ⇒ CodeGenPhaseHandler
constructor
A new instance of CodeGenPhaseHandler.
-
#paused? ⇒ Boolean
True if there’s a pending proposal awaiting human approval.
-
#resume_if_pending ⇒ Hash, ...
Check if a pending proposal has been resolved.
Constructor Details
#initialize(code_gen_act:, wal_phase_recorder: nil) ⇒ CodeGenPhaseHandler
Returns a new instance of CodeGenPhaseHandler.
23 24 25 26 27 |
# File 'lib/kairos_mcp/daemon/code_gen_phase_handler.rb', line 23 def initialize(code_gen_act:, wal_phase_recorder: nil) @cga = code_gen_act @wpr = wal_phase_recorder @pending_proposal_id = nil end |
Instance Attribute Details
#pending_proposal_id ⇒ Object (readonly)
Returns the value of attribute pending_proposal_id.
21 22 23 |
# File 'lib/kairos_mcp/daemon/code_gen_phase_handler.rb', line 21 def pending_proposal_id @pending_proposal_id end |
Instance Method Details
#handle_act(decision, mandate) ⇒ Hash
Execute the ACT phase for a code_edit decision.
34 35 36 37 38 39 40 |
# File 'lib/kairos_mcp/daemon/code_gen_phase_handler.rb', line 34 def handle_act(decision, mandate) @cga.run(decision, mandate) rescue CodeGenAct::PauseForApproval => e @pending_proposal_id = e.proposal_id mark_wal_paused(e.proposal_id) { status: PAUSED_STATUS, proposal_id: e.proposal_id } end |
#paused? ⇒ Boolean
True if there’s a pending proposal awaiting human approval.
67 68 69 |
# File 'lib/kairos_mcp/daemon/code_gen_phase_handler.rb', line 67 def paused? !@pending_proposal_id.nil? end |
#resume_if_pending ⇒ Hash, ...
Check if a pending proposal has been resolved. Call at cycle start.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kairos_mcp/daemon/code_gen_phase_handler.rb', line 46 def resume_if_pending return nil unless @pending_proposal_id result = @cga.resume(@pending_proposal_id) case result when Hash # Applied successfully @pending_proposal_id = nil result when :rejected, :expired, :not_found pid = @pending_proposal_id @pending_proposal_id = nil { status: result.to_s, proposal_id: pid } when :still_pending :still_pending else result end end |