# Class LittleGhost::Harnesses::Result

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Harnesses/Result.html

The outcome of one Harnesses::Base#run.

`status` is one of:

`:completed`
:   The tool finished its task.

`:failed`
:   The tool reported an error or exited unsuccessfully.

`:timed_out`
:   The request's `timeout` elapsed and the process was stopped.

`:budget_exceeded`
:   The tool or the harness stopped because spending exceeded `budget_usd`.

`:turns_exceeded`
:   The tool or the harness stopped because work exceeded `max_turns`.

Any of `text`, `session_id`, `cost_usd`, `turns`, and `stop_reason` may be nil
when the tool did not report them. A Result contains the tool's output, which
can include repository content; treat it as untrusted.

## Inheritance

`LittleGhost::Harnesses::Result < Data.define(
      :harness, :status, :text, :session_id, :cost_usd, :usage, :turns, :exit_code, :stop_reason, :stderr_tail
    )`

## Attributes

<a id="attribute-i-cost_usd"></a>
### `cost_usd` (R)

Reported spend in US dollars, or nil when the tool does not report it.

<a id="attribute-i-exit_code"></a>
### `exit_code` (R)

Process exit status, or nil when the process was stopped by a signal.

<a id="attribute-i-harness"></a>
### `harness` (R)

Identifier of the harness that produced the result, such as
`:codex`.

<a id="attribute-i-session_id"></a>
### `session_id` (R)

Session identifier that a later Request can resume, or nil.

<a id="attribute-i-status"></a>
### `status` (R)

One of `:completed`, `:failed`, `:timed_out`,
`:budget_exceeded`, or `:turns_exceeded`.

<a id="attribute-i-stderr_tail"></a>
### `stderr_tail` (R)

The last few kilobytes of standard error.

<a id="attribute-i-stop_reason"></a>
### `stop_reason` (R)

The tool's own reason for stopping, as a String, or nil.

<a id="attribute-i-text"></a>
### `text` (R)

The tool's final answer, or nil.

<a id="attribute-i-turns"></a>
### `turns` (R)

Number of agent turns, or nil.

<a id="attribute-i-usage"></a>
### `usage` (R)

Token counts as a LittleGhost::Usage.

## Class methods

<a id="method-c-new"></a>
### `.new`

```ruby
.new(harness:, status:, usage: Usage.new, text: nil, session_id: nil, cost_usd: nil, turns: nil,
        exit_code: nil, stop_reason: nil, stderr_tail: "")
```

Builds a result. Raises ArgumentError for an unknown `status`.

## Instance methods

<a id="method-i-completed-3F"></a>
### `#completed?`

```ruby
#completed?()
```

Whether the tool finished its task.

<a id="method-i-to_h"></a>
### `#to_h`

```ruby
#to_h()
```

Returns a JSON-compatible Hash with usage expanded.
