agentic examples

The Wat Museum

The Wat Museum: seven exhibits of genuine Ruby strangeness, each one a task that PROVES its own placard before you're allowed to gasp at it. Museums of programming wat usually run on hearsay - screenshots of someone else's REPL, half-remembered semantics from a conference talk. This museum has a strict acquisitions policy: every placard is executed, every claim is checked, and an exhibit that cannot demonstrate itself is DEACCESSIONED on the spot. There is no magic; there is …

Fun & Strange Round 19 Konstantin Haase exit 0

source on github

bundle exec ruby examples/wat_museum.rb

a real captured run

THE WAT MUSEUM (no exhibit without a demonstration)

  Exhibit 1: The Flip-Flop
    | (i==3)..(i==5) inside an `if` is a RANGE ACROSS TIME: it turns
    | on at 3, off after 5. Deprecated in 2.6; the community demanded
    | it back.
    demonstrated: [3, 4, 5]

  Exhibit 2: Some Integers Are More Equal
    | 1.equal?(1) is true (immediates ARE their object), but
    | (2**100).equal?(2**100) is false - bignums are mortal like the
    | rest of us.
    demonstrated: small: true, big: false

  Exhibit 3: The Sum That Isn't
    | 0.1 + 0.2 != 0.3. The floats did nothing wrong; base 2 simply
    | cannot say 'one tenth' in finitely many words.
    demonstrated: 0.30000000000000004

  Exhibit 4: Multiplication Is Join
    | [1,2,3] * ',' joins. Array#* with an Integer repeats; with a
    | String it becomes #join. One operator, two personalities.
    demonstrated: "1-2-3"

  Exhibit 5: defined? Leaves Footprints
    | defined?(zz = 1) returns 'assignment' WITHOUT assigning - yet zz
    | now exists, as nil. The parser declared the local while merely
    | being asked about it.
    demonstrated: ["assignment", "nil"]

  Exhibit 6: The Banana Constructor
    | 'ba' + 'na' * 2 is 'banana'. Precedence: * binds tighter than +,
    | so 'na' doubles first. Fruit follows.
    demonstrated: "banana"

  Exhibit 7: The Literal That Is Everyone
    | Under frozen_string_literal, every 'wat' in this file is the
    | SAME OBJECT - the literal was deduplicated at compile time.
    demonstrated: a.equal?(b): true

  acquisitions report: 7/7 exhibits verified, 0 deaccessioned.

  the curatorial position: none of these are bugs, and 'wat' is
  not an accusation - it's the sound a mental model makes when it
  updates. the flip-flop is sed's heritage; integer identity is
  the immediate-value optimization wearing a mask; the float sum
  is arithmetic being honest about base 2; defined?'s footprint
  is the parser doing its job earlier than you expected. a museum
  that executes its placards can afford to exhibit the strange,
  because it never has to retract - there is no magic, only
  semantics you haven't met yet, and now you've met seven.

source

# frozen_string_literal: true

# The Wat Museum: seven exhibits of genuine Ruby strangeness, each
# one a task that PROVES its own placard before you're allowed to
# gasp at it. Museums of programming wat usually run on hearsay -
# screenshots of someone else's REPL, half-remembered semantics from
# a conference talk. This museum has a strict acquisitions policy:
# every placard is executed, every claim is checked, and an exhibit
# that cannot demonstrate itself is DEACCESSIONED on the spot. There
# is no magic; there is only semantics you haven't met yet.
#
#   bundle exec ruby examples/wat_museum.rb
#
# Runs offline; exits 1 if the museum contains a single lie.

require class="s">"bundler/setup"
require class="s">"agentic"

Agentic.logger.level = class="y">:fatal

EXHIBITS = [
  {name: class="s">"The Flip-Flop",
   placard: class="s">"(i==3)..(i==5) inside an `if` is a RANGE ACROSS TIME: it turns on at 3, off after 5. Deprecated in 2.6; the community demanded it back.",
   prove: -> {
     picks = (1..10).select { |i| if (i == 3)..(i == 5) then true end } # rubocop:disable Style/IfWithBooleanLiteralBranches, Lint/FlipFlop -- the flip-flop IS the exhibit
     [picks.inspect, picks == [3, 4, 5]]
   }},
  {name: class="s">"Some Integers Are More Equal",
   placard: class="s">"1.equal?(1) is true (immediates ARE their object), but (2**100).equal?(2**100) is false - bignums are mortal like the rest of us.",
   prove: -> { [class="s">"small: #{1.equal?(1)}, big: #{(2**100).equal?(2**100)}", 1.equal?(1) && !(2**100).equal?(2**100)] }},
  {name: class="s">"The Sum That Isn't",
   placard: class="s">"0.1 + 0.2 != 0.3. The floats did nothing wrong; base 2 simply cannot say 'one tenth' in finitely many words.",
   prove: -> { [(0.1 + 0.2).inspect, 0.1 + 0.2 != 0.3 && (0.1 + 0.2 - 0.3).abs < 1e-15] }}, # rubocop:disable Lint/FloatComparison -- the unreliability IS the exhibit
  {name: class="s">"Multiplication Is Join",
   placard: class="s">"[1,2,3] * ',' joins. Array#* with an Integer repeats; with a String it becomes #join. One operator, two personalities.",
   # the * IS the exhibit; the linter once rewrote it into join() and nearly deaccessioned the wat
   prove: -> { [([1, 2, 3] * class="s">"-").inspect, [1, 2, 3] * class="s">"-" == class="s">"1-2-3" && [1, 2] * 2 == [1, 2, 1, 2]] }}, # rubocop:disable Style/ArrayJoin
  {name: class="s">"defined? Leaves Footprints",
   placard: class="s">"defined?(zz = 1) returns 'assignment' WITHOUT assigning - yet zz now exists, as nil. The parser declared the local while merely being asked about it.",
   prove: -> { [eval(class="s">"[defined?(zz = 1), zz.inspect]").inspect, eval(class="s">"[defined?(zz = 1), zz.inspect]") == [class="s">"assignment", class="s">"nil"]] }}, # rubocop:disable Security/Eval, Style/EvalWithLocation -- the exhibit needs a pristine local scope
  {name: class="s">"The Banana Constructor",
   placard: class="s">"'ba' + 'na' * 2 is 'banana'. Precedence: * binds tighter than +, so 'na' doubles first. Fruit follows.",
   prove: -> { [(class="s">"ba" + class="s">"na" * 2).inspect, class="s">"ba" + class="s">"na" * 2 == class="s">"banana"] }},
  {name: class="s">"The Literal That Is Everyone",
   placard: class="s">"Under frozen_string_literal, every 'wat' in this file is the SAME OBJECT - the literal was deduplicated at compile time.",
   prove: -> {
     a = class="s">"wat"
     b = class="s">"wat"
     [class="s">"a.equal?(b): #{a.equal?(b)}", a.equal?(b)]
   }}
].freeze

# --- the museum runs its own acquisitions committee, in parallel --------------------
orchestrator = Agentic:class="y">:PlanOrchestrator.new(concurrency_limit: 4)
exhibit_tasks = EXHIBITS.to_h do |exhibit|
  task = Agentic:class="y">:Task.new(description: exhibit[class="y">:name], agent_spec: {class="s">"name" => exhibit[class="y">:name], class="s">"instructions" => class="s">"prove"})
  orchestrator.add_task(task, agent: ->(_t) {
    observed, verdict = exhibit[class="y">:prove].call
    {observed: observed, verdict: verdict}
  })
  [exhibit[class="y">:name], task]
end
result = orchestrator.execute_plan

puts class="s">"THE WAT MUSEUM (no exhibit without a demonstration)"
puts
lies = []
EXHIBITS.each_with_index do |exhibit, i|
  proof = result.task_result(exhibit_tasks[exhibit[class="y">:name]].id).output
  lies << exhibit[class="y">:name] unless proof[class="y">:verdict]
  puts class="s">"  Exhibit #{i + 1}: #{exhibit[class="y">:name]} #{proof[class="y">:verdict] ? "class="s">" : "  ** DEACCESSIONED - PLACARD FALSE **class="s">"}"
  exhibit[class="y">:placard].scan(/.{1,64}(?:\s|$)/).each { |line| puts class="s">"    | #{line.strip}" }
  puts class="s">"    demonstrated: #{proof[class="y">:observed]}"
  puts
end

puts class="s">"  acquisitions report: #{EXHIBITS.size - lies.size}/#{EXHIBITS.size} exhibits verified, #{lies.size} deaccessioned."
puts
puts class="s">"  the curatorial position: none of these are bugs, and 'wat' is"
puts class="s">"  not an accusation - it's the sound a mental model makes when it"
puts class="s">"  updates. the flip-flop is sed's heritage; integer identity is"
puts class="s">"  the immediate-value optimization wearing a mask; the float sum"
puts class="s">"  is arithmetic being honest about base 2; defined?'s footprint"
puts class="s">"  is the parser doing its job earlier than you expected. a museum"
puts class="s">"  that executes its placards can afford to exhibit the strange,"
puts class="s">"  because it never has to retract - there is no magic, only"
puts class="s">"  semantics you haven't met yet, and now you've met seven."
exit(lies.empty? ? 0 : 1)