Class: Insika::Evidence::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/evidence.rb

Overview

Result shaping, stateless — callable from any tool-call fiber (the parallel tool_concurrency path). No shared state in this class.

Class Method Summary collapse

Class Method Details

.build(spec, raw) ⇒ Object

-> [lean, attachments]. Assumes the shape already passed SchemaGuard.violation_output. Items are capped and lines truncated; the model must never see a null where the contract says items.



105
106
107
108
109
110
111
112
113
114
# File 'lib/insika/evidence.rb', line 105

def build(spec, raw)
  items = SchemaGuard.dig(raw, spec.items_path) || []
  lean_items = items.first(MAX_ITEMS).map do |item|
    { "id" => (item["id"] || item[:id]).to_s,
      "line" => Coercion.utf8((item["line"] || item[:line]).to_s)[0, LINE_MAX] }
  end
  lean = { "items" => lean_items }
  attachments = Insika::Evidence.valid_attachments(SchemaGuard.dig(raw, spec.attachments_path))
  [lean, attachments]
end

.raw(spec, result) ⇒ Object

-> the parsed Hash the evidence paths dig into. For evidence_envelope the raw body lives under __insika_body (D3); a code tool returns the object itself. Raises JSON::ParserError on a non-JSON envelope body — the envelope turns that into {error:}, nothing recorded (fail closed: no IDs, no claims to make).



96
97
98
99
100
# File 'lib/insika/evidence.rb', line 96

def raw(spec, result)
  return result unless result.is_a?(Hash) && result.key?("__insika_body")

  JSON.parse(result["__insika_body"].to_s)
end