Class: Ask::CodingHarness::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/coding_harness/runner.rb

Overview

Headless run of a prompt against the workspace: drives the same AgentRunner as the web server, prints a readable transcript, and returns a Result. This is the dogfooding path — the harness builds itself with ach run.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(config:, store: nil, runner: nil, approval: :off) ⇒ Runner

Returns a new instance of Runner.

Parameters:

  • config (Config)

    harness configuration (duped; approval mode is overridden for headless operation)

  • store (Store, nil) (defaults to: nil)

    conversation store (defaults to a fresh Store on config.db_path)

  • runner (AgentRunner, nil) (defaults to: nil)

    agent runner (defaults to a fresh AgentRunner on the store)

  • approval (Symbol) (defaults to: :off)

    approval mode for headless runs; :off by default so nothing blocks on human review



25
26
27
28
29
30
# File 'lib/ask/coding_harness/runner.rb', line 25

def initialize(config:, store: nil, runner: nil, approval: :off)
  @config = config.dup
  @config.approval = approval
  @store = store || Store.new(db_path: @config.db_path)
  @runner = runner || AgentRunner.new(config: @config, store: @store)
end

Instance Method Details

#run(prompt, workspace: nil, model: nil, quiet: false) ⇒ Result

Run a prompt and wait for the turn to finish.

Parameters:

  • prompt (String)

    the task

  • workspace (String, nil) (defaults to: nil)

    override config.workspace

  • model (String, nil) (defaults to: nil)

    model override

  • quiet (Boolean) (defaults to: false)

    suppress the transcript output

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ask/coding_harness/runner.rb', line 39

def run(prompt, workspace: nil, model: nil, quiet: false)
  @config.workspace = workspace if workspace
  conversation = @store.build(directory: @config.workspace)
  conversation = @store.save(conversation)

  events = []
  response = +""
  error = nil

  thread = @runner.start_turn(conversation, prompt, model: model) do |ev|
    events << ev
    case ev[:type]
    when "message.delta" then response << ev[:data][:delta].to_s
    when "turn.failed" then error = ev[:data][:error]
    end
    print_transcript(ev) unless quiet
  end
  thread.join

  Result.new(
    success: error.nil?,
    response: response,
    events: events,
    conversation_id: conversation["id"],
    error: error
  )
end