Class: Insika::Refinement::Edit
- Inherits:
-
Data
- Object
- Data
- Insika::Refinement::Edit
- 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
-
#addresses ⇒ Object
readonly
Returns the value of attribute addresses.
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#anchor ⇒ Object
readonly
Returns the value of attribute anchor.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#op ⇒ Object
readonly
Returns the value of attribute op.
Instance Method Summary collapse
-
#apply_to(content) ⇒ Object
-> the new content, or nil when this edit no longer applies to
content. - #replace? ⇒ Boolean
- #to_h ⇒ Object
Instance Attribute Details
#addresses ⇒ Object (readonly)
Returns the value of attribute addresses
22 23 24 |
# File 'lib/insika/refinement/candidate.rb', line 22 def addresses @addresses end |
#after ⇒ Object (readonly)
Returns the value of attribute after
22 23 24 |
# File 'lib/insika/refinement/candidate.rb', line 22 def after @after end |
#anchor ⇒ Object (readonly)
Returns the value of attribute anchor
22 23 24 |
# File 'lib/insika/refinement/candidate.rb', line 22 def anchor @anchor end |
#before ⇒ Object (readonly)
Returns the value of attribute before
22 23 24 |
# File 'lib/insika/refinement/candidate.rb', line 22 def before @before end |
#file ⇒ Object (readonly)
Returns the value of attribute file
22 23 24 |
# File 'lib/insika/refinement/candidate.rb', line 22 def file @file end |
#op ⇒ Object (readonly)
Returns the value of attribute 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
23 |
# File 'lib/insika/refinement/candidate.rb', line 23 def replace? = op == "replace" |
#to_h ⇒ Object
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 } |