Three-stage fail-fast validator for LLM-generated bot candidates: - syntax.go: language-aware parse (go/parser for Go; py_compile, rustfmt, tsc, javac, php -l for others; brace-balance fallback) - schema.go: regex detection of /health + /turn endpoints and "moves" field - sandbox.go: nsjail-isolated smoke test — builds bot, polls /health, sends 5 signed /turn requests, verifies JSON moves responses - validator.go: orchestrates stages with fail-fast short-circuit DB layer: - programs table + CRUD (create, get, list, updateFitness, setPromoted) - validation_log table with RecordValidation, IslandPassRates, IslandValidationStats for per-island pass-rate tracking - seed.go: 6 generation-0 bots across alpha/beta/gamma/delta islands MAP-Elites grid (mapelites/grid.go): 2-D behavior grid on aggression×economy axes; TryPlace keeps the fittest occupant per niche. acb-evolver CLI gains two new subcommands: validate <file> -lang <lang> [-island <island>] [-nsjail] [-nolog] validation-stats (tabular per-island pass-rate breakdown) cmd/acb-api/db.go: add programs table to API schema so the API can query promoted evolved bots. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
89 lines
3 KiB
Go
89 lines
3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const schemaSQL = `
|
|
CREATE TABLE IF NOT EXISTS bots (
|
|
bot_id VARCHAR(16) PRIMARY KEY,
|
|
name VARCHAR(32) UNIQUE NOT NULL,
|
|
owner VARCHAR(128) NOT NULL,
|
|
endpoint_url TEXT NOT NULL,
|
|
shared_secret TEXT NOT NULL,
|
|
status VARCHAR(16) NOT NULL DEFAULT 'pending',
|
|
rating_mu DOUBLE PRECISION NOT NULL DEFAULT 1500.0,
|
|
rating_phi DOUBLE PRECISION NOT NULL DEFAULT 350.0,
|
|
rating_sigma DOUBLE PRECISION NOT NULL DEFAULT 0.06,
|
|
evolved BOOLEAN NOT NULL DEFAULT FALSE,
|
|
island VARCHAR(16),
|
|
generation INTEGER,
|
|
parent_ids JSONB,
|
|
description TEXT,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
last_active TIMESTAMPTZ,
|
|
consec_fails INTEGER NOT NULL DEFAULT 0
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS matches (
|
|
match_id VARCHAR(32) PRIMARY KEY,
|
|
map_id VARCHAR(32) NOT NULL,
|
|
map_seed BIGINT,
|
|
status VARCHAR(16) NOT NULL DEFAULT 'pending',
|
|
winner INTEGER,
|
|
condition VARCHAR(32),
|
|
turn_count INTEGER,
|
|
scores_json JSONB,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
completed_at TIMESTAMPTZ
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS match_participants (
|
|
match_id VARCHAR(32) NOT NULL REFERENCES matches(match_id),
|
|
bot_id VARCHAR(16) NOT NULL REFERENCES bots(bot_id),
|
|
player_slot INTEGER NOT NULL,
|
|
score INTEGER,
|
|
status VARCHAR(16),
|
|
PRIMARY KEY (match_id, bot_id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS jobs (
|
|
job_id VARCHAR(32) PRIMARY KEY,
|
|
match_id VARCHAR(32) NOT NULL REFERENCES matches(match_id),
|
|
status VARCHAR(16) NOT NULL DEFAULT 'pending',
|
|
worker_id VARCHAR(64),
|
|
config_json JSONB NOT NULL,
|
|
claimed_at TIMESTAMPTZ,
|
|
completed_at TIMESTAMPTZ
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS rating_history (
|
|
bot_id VARCHAR(16) NOT NULL REFERENCES bots(bot_id),
|
|
match_id VARCHAR(32) NOT NULL REFERENCES matches(match_id),
|
|
rating DOUBLE PRECISION NOT NULL,
|
|
recorded_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
PRIMARY KEY (bot_id, match_id)
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_rating_history_bot ON rating_history(bot_id, recorded_at);
|
|
|
|
CREATE TABLE IF NOT EXISTS programs (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
code TEXT NOT NULL,
|
|
language VARCHAR(32) NOT NULL,
|
|
island VARCHAR(16) NOT NULL,
|
|
generation INTEGER NOT NULL DEFAULT 0,
|
|
parent_ids JSONB NOT NULL DEFAULT '[]',
|
|
behavior_vector DOUBLE PRECISION[] NOT NULL DEFAULT '{}',
|
|
fitness DOUBLE PRECISION NOT NULL DEFAULT 0.0,
|
|
promoted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_programs_island ON programs(island);
|
|
CREATE INDEX IF NOT EXISTS idx_programs_island_fitness ON programs(island, fitness DESC);
|
|
`
|
|
|
|
func ensureSchema(ctx context.Context, db *sql.DB) error {
|
|
_, err := db.ExecContext(ctx, schemaSQL)
|
|
return err
|
|
}
|