Class: Insika::Refinement::Edit

Inherits:
Data
  • Object
show all
Defined in:
lib/insika/refinement/candidate.rb

Overview

ONE proposed change to an agent's instruction files. Data, not a diff of free text, and that is the load-bearing decision of the whole phase:

· an ANCHORED edit is reviewable — the operator reads three lines, not a
rewritten file, and can tell in seconds whether to approve it;
· it is ATTRIBUTABLE — when the gate's score moves, it moved because of an
edit you can point at, not because a model rewrote the prompt;
· it is STALE-CHECKABLE — `before` must still match the file, so a proposal
built from a snapshot cannot silently clobber an edit made since.

A candidate arrives from anywhere (a model, the Studio, a JSON payload) and is always built through Candidate.build, which is the only place the bounds and the write allowlist are enforced. An edit that violates one is DROPPED with a reason rather than failing the whole candidate: a proposal with two good edits and one stale one is worth gating, and the operator should see what fell off.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressesObject (readonly)

Returns the value of attribute addresses

Returns:

  • (Object)

    the current value of addresses



22
23
24
# File 'lib/insika/refinement/candidate.rb', line 22

def addresses
  @addresses
end

#afterObject (readonly)

Returns the value of attribute after

Returns:

  • (Object)

    the current value of after



22
23
24
# File 'lib/insika/refinement/candidate.rb', line 22

def after
  @after
end

#anchorObject (readonly)

Returns the value of attribute anchor

Returns:

  • (Object)

    the current value of anchor



22
23
24
# File 'lib/insika/refinement/candidate.rb', line 22

def anchor
  @anchor
end

#beforeObject (readonly)

Returns the value of attribute before

Returns:

  • (Object)

    the current value of before



22
23
24
# File 'lib/insika/refinement/candidate.rb', line 22

def before
  @before
end

#fileObject (readonly)

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



22
23
24
# File 'lib/insika/refinement/candidate.rb', line 22

def file
  @file
end

#opObject (readonly)

Returns the value of attribute op

Returns:

  • (Object)

    the current value of op



22
23
24
# File 'lib/insika/refinement/candidate.rb', line 22

def op
  @op
end

Instance Method Details

#apply_to(content) ⇒ Object

-> the new content, or nil when this edit no longer applies to content. append puts the text at the END of the file: anchor is a LABEL for the reviewer ("## shipping_quote"), never a locator — the locator is before, and inventing a second one would give the same edit two ways to land.



29
30
31
32
33
34
35
# File 'lib/insika/refinement/candidate.rb', line 29

def apply_to(content)
  return nil if content.nil?
  return "#{content.chomp}\n\n#{after}\n" unless replace?
  return nil unless content.include?(before)

  content.sub(before, after)
end

#replace?Boolean

Returns:

  • (Boolean)


23
# File 'lib/insika/refinement/candidate.rb', line 23

def replace? = op == "replace"

#to_hObject



37
38
# File 'lib/insika/refinement/candidate.rb', line 37

def to_h = { "file" => file, "op" => op, "anchor" => anchor, "before" => before,
"after" => after, "addresses" => addresses }