Class: Pikuri::Code::ExitPlanMode

Inherits:
Tool
  • Object
show all
Defined in:
lib/pikuri/code/exit_plan_mode.rb

Overview

The exit_plan_mode tool: presents the finished plan for approval and, on a yes, turns the shared Workspace::ReadOnly flag back off. The plan is shown and the yes/no collected through the same Workspace::Confirmer the +write+/+bash+ tools use, so presentation + attacker-text sanitization live in one place. On approval the flag flips off and the model is told to proceed; on a decline it stays on and the observation steers a refine-and-re-present, never an edit. The LLM-authored plan is passed as the request detail, so the Confirmer neutralizes it before display.

Sharing: as EnterPlanModeP_shared_locked on the flag, and sharing it makes plan mode VM-wide. The Workspace::Confirmer pulls the other way (Confirmer::Terminal is P_one_agent), so a shared instance is only as shareable as the confirmer behind it.

Constant Summary collapse

DESCRIPTION =

Returns:

  • (String)
<<~DESC
  Exit plan mode by presenting your finished implementation plan for the user's approval.

  Usage:
  - Call this only once your plan is complete and unambiguous; pass the full plan as the `plan` argument.
  - The user is shown the plan and asked to approve. On approval you leave plan mode and may implement it; on a decline you stay in plan mode — refine the plan and call this again.
  - If a requirement is still unclear, ask the user directly first (without leaving plan mode) rather than presenting a half-formed plan.
  - Do not use this for pure research tasks — those never enter plan mode in the first place.
DESC

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(read_only:, confirmer:) ⇒ ExitPlanMode

Parameters:

  • read_only (Pikuri::Workspace::ReadOnly)

    the shared read-only flag to deactivate on approval.

  • confirmer (Pikuri::Workspace::Confirmer)

    consulted to present the plan and collect the approval.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pikuri/code/exit_plan_mode.rb', line 36

def initialize(read_only:, confirmer:)
  super(
    name: 'exit_plan_mode',
    description: DESCRIPTION,
    parameters: Parameters.build { |p|
      p.required_string :plan,
                        'Your complete implementation plan, in Markdown, ' \
                        'shown to the user for approval. Cover the files ' \
                        'to change and the changes to each, e.g. ' \
                        '"## Plan\n1. Add X to foo.rb\n2. ...".'
    },
    execute: ->(plan:) {
      ExitPlanMode.run(read_only: read_only, confirmer: confirmer, plan: plan)
    },
    # No legs: flips a local mode flag (behind a confirmer, which grades
    # nothing here — there is no leg to gate).
    trifecta_legs: Pikuri::Tool::TrifectaLegs::NONE
  )
end

Class Method Details

.run(read_only:, confirmer:, plan:) ⇒ String

Present plan for approval; on yes deactivate plan mode, on no keep it active. Returns the observation the model reacts to.

Parameters:

  • read_only (Pikuri::Workspace::ReadOnly)
  • confirmer (Pikuri::Workspace::Confirmer)
  • plan (String)

    the LLM-authored plan to show the user

Returns:

  • (String)

    tool observation



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/pikuri/code/exit_plan_mode.rb', line 63

def self.run(read_only:, confirmer:, plan:)
  unless read_only.active?
    return 'Error: not in plan mode, so there is nothing to exit. ' \
           'Proceed with the work directly.'
  end

  request = Pikuri::Workspace::Confirmer::Request.new(
    question: 'Approve this plan? (approving exits plan mode and lets the agent edit files)',
    detail: plan
  )

  if confirmer.confirm?(request: request)
    read_only.deactivate!
    'Plan approved — you are no longer in plan mode. Implement the plan now.'
  else
    'The user did not approve the plan; you are still in plan mode (read-only). ' \
      'Ask what they would like changed, revise the plan, and call exit_plan_mode ' \
      'again when ready. Do not edit any files.'
  end
end