Class: Aidp::Execute::InstructionQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/execute/instruction_queue.rb

Overview

Manages queued instructions and plan modifications during work loop execution Instructions are merged into PROMPT.md at the next iteration

Defined Under Namespace

Classes: Instruction

Constant Summary collapse

INSTRUCTION_TYPES =
{
  user_input: "USER_INPUT",           # Direct user instructions
  plan_update: "PLAN_UPDATE",         # Changes to implementation contract
  constraint: "CONSTRAINT",           # New constraints or requirements
  clarification: "CLARIFICATION",     # Clarifications on existing work
  acceptance: "ACCEPTANCE_CRITERIA"   # New acceptance criteria
}.freeze
PRIORITIES =
{
  critical: 1,
  high: 2,
  normal: 3,
  low: 4
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeInstructionQueue

Returns a new instance of InstructionQueue.



25
26
27
# File 'lib/aidp/execute/instruction_queue.rb', line 25

def initialize
  @instructions = []
end

Instance Method Details

#clearObject

Clear all instructions



68
69
70
# File 'lib/aidp/execute/instruction_queue.rb', line 68

def clear
  @instructions.clear
end

#countObject

Get count of queued instructions



58
59
60
# File 'lib/aidp/execute/instruction_queue.rb', line 58

def count
  @instructions.size
end

#dequeue_allObject

Retrieve and remove all instructions (sorted by priority, then time)



46
47
48
49
50
# File 'lib/aidp/execute/instruction_queue.rb', line 46

def dequeue_all
  instructions = @instructions.sort_by { |i| [i.priority, i.timestamp] }
  @instructions.clear
  instructions
end

#empty?Boolean

Check if queue is empty

Returns:

  • (Boolean)


63
64
65
# File 'lib/aidp/execute/instruction_queue.rb', line 63

def empty?
  @instructions.empty?
end

#enqueue(content, type: :user_input, priority: :normal) ⇒ Object

Add instruction to queue



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aidp/execute/instruction_queue.rb', line 30

def enqueue(content, type: :user_input, priority: :normal)
  validate_type!(type)
  validate_priority!(priority)

  instruction = Instruction.new(
    content: content,
    type: type,
    priority: PRIORITIES[priority],
    timestamp: Time.now
  )

  @instructions << instruction
  instruction
end

#format_for_prompt(instructions = nil) ⇒ Object

Format instructions for merging into PROMPT.md



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/aidp/execute/instruction_queue.rb', line 73

def format_for_prompt(instructions = nil)
  instructions ||= peek_all
  return "" if instructions.empty?

  parts = []
  parts << "## 🔄 Queued Instructions from REPL"
  parts << ""
  parts << "The following instructions were added during execution and should be"
  parts << "incorporated into your next iteration:"
  parts << ""

  instructions.group_by(&:type).each do |type, type_instructions|
    parts << "### #{INSTRUCTION_TYPES[type]}"
    type_instructions.each_with_index do |instruction, idx|
      priority_marker = (instruction.priority == 1) ? " 🔴 CRITICAL" : ""
      parts << "#{idx + 1}. #{instruction.content}#{priority_marker}"
    end
    parts << ""
  end

  parts << "**Note**: Address these instructions while continuing your current work."
  parts << "Do not restart from scratch - build on what exists."
  parts << ""

  parts.join("\n")
end

#peek_allObject

Peek at instructions without removing



53
54
55
# File 'lib/aidp/execute/instruction_queue.rb', line 53

def peek_all
  @instructions.sort_by { |i| [i.priority, i.timestamp] }
end

#summaryObject

Summary for display



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/aidp/execute/instruction_queue.rb', line 101

def summary
  return "No queued instructions" if empty?

  by_type = @instructions.group_by(&:type).transform_values(&:size)
  by_priority = @instructions.group_by { |i| priority_name(i.priority) }.transform_values(&:size)

  {
    total: count,
    by_type: by_type,
    by_priority: by_priority
  }
end