"<!DOCTYPE html>\n<html lang=\"zh\" data-theme=\"light\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>fulltext.txt — Vercel Design System</title>\n<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n<link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n<link href=\"https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap\" rel=\"stylesheet\">\n<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css\">\n<style>\n\n:root {\n  /* Vercel Palette */\n  --geist-foreground: #171717;\n  --geist-background: #ffffff;\n  --geist-secondary: #4d4d4d;\n  --geist-tertiary: #666666;\n  --geist-quaternary: #808080;\n  --geist-border: #ebebeb;\n  --geist-surface-tint: #fafafa;\n  \n  /* Workflow Accents */\n  --develop-blue: #0a72ef;\n  --preview-pink: #de1d8d;\n  --ship-red: #ff5b4f;\n  \n  /* Interactive & Status */\n  --link-blue: #0072f5;\n  --ds-focus-color: hsla(212, 100%, 48%, 1);\n  --badge-blue-bg: #ebf5ff;\n  --badge-blue-text: #0068d6;\n  \n  /* Shadow-as-Border Philosophy */\n  --shadow-border: rgba(0, 0, 0, 0.08) 0px 0px 0px 1px;\n  --shadow-border-hover: rgba(0, 0, 0, 0.16) 0px 0px 0px 1px;\n  --shadow-card: rgba(0, 0, 0, 0.08) 0px 0px 0px 1px, rgba(0, 0, 0, 0.04) 0px 2px 2px, #fafafa 0px 0px 0px 1px;\n  --shadow-card-hover: rgba(0, 0, 0, 0.12) 0px 0px 0px 1px, rgba(0, 0, 0, 0.06) 0px 4px 6px, #fafafa 0px 0px 0px 1px;\n  --shadow-card-full: rgba(0, 0, 0, 0.08) 0px 0px 0px 1px, rgba(0, 0, 0, 0.04) 0px 2px 2px, rgba(0, 0, 0, 0.04) 0px 8px 8px -8px, #fafafa 0px 0px 0px 1px;\n  --shadow-ring: rgb(235, 235, 235) 0px 0px 0px 1px;\n  \n  /* Radius Scale */\n  --radius-xs: 2px;\n  --radius-sm: 4px;\n  --radius-md: 6px;\n  --radius-lg: 8px;\n  --radius-xl: 12px;\n  --radius-pill: 9999px;\n}\n\n[data-theme=\"dark\"] {\n  --geist-foreground: #ededed;\n  --geist-background: #000000;\n  --geist-secondary: #a1a1a1;\n  --geist-tertiary: #888888;\n  --geist-quaternary: #666666;\n  --geist-border: #222222;\n  --geist-surface-tint: #0a0a0a;\n  \n  --shadow-border: rgba(255, 255, 255, 0.14) 0px 0px 0px 1px;\n  --shadow-border-hover: rgba(255, 255, 255, 0.28) 0px 0px 0px 1px;\n  --shadow-card: rgba(255, 255, 255, 0.12) 0px 0px 0px 1px, rgba(0, 0, 0, 0.4) 0px 2px 4px, #111111 0px 0px 0px 1px;\n  --shadow-card-hover: rgba(255, 255, 255, 0.2) 0px 0px 0px 1px, rgba(0, 0, 0, 0.5) 0px 6px 12px, #111111 0px 0px 0px 1px;\n  --shadow-card-full: rgba(255, 255, 255, 0.12) 0px 0px 0px 1px, rgba(0, 0, 0, 0.5) 0px 8px 16px -4px, #111111 0px 0px 0px 1px;\n  --shadow-ring: rgb(40, 40, 40) 0px 0px 0px 1px;\n  \n  --badge-blue-bg: rgba(10, 114, 239, 0.15);\n  --badge-blue-text: #70b5ff;\n}\n\n* { box-sizing: border-box; }\nhtml { scroll-behavior: smooth; }\nbody {\n  margin: 0;\n  font-family: \"Geist\", Arial, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n  background-color: var(--geist-background);\n  color: var(--geist-foreground);\n  font-feature-settings: \"liga\" 1;\n  -webkit-font-smoothing: antialiased;\n  min-height: 100vh;\n}\n\na {\n  color: inherit;\n  text-decoration: none;\n  transition: color 0.15s ease;\n}\n\n/* 导航栏 (Vercel Clean Sticky Nav) */\n.vercel-nav {\n  position: sticky;\n  top: 0;\n  background-color: var(--geist-background);\n  box-shadow: var(--shadow-border);\n  z-index: 100;\n  padding: 0 24px;\n  height: 64px;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n}\n.nav-brand {\n  display: flex;\n  align-items: center;\n  gap: 12px;\n}\n.vercel-triangle {\n  width: 22px;\n  height: 19px;\n  fill: var(--geist-foreground);\n}\n.nav-title {\n  font-size: 16px;\n  font-weight: 600;\n  letter-spacing: -0.32px;\n  color: var(--geist-foreground);\n}\n.nav-badge-pill {\n  font-family: \"Geist Mono\", ui-monospace, monospace;\n  font-size: 11px;\n  font-weight: 500;\n  text-transform: uppercase;\n  background: var(--badge-blue-bg);\n  color: var(--badge-blue-text);\n  padding: 2px 8px;\n  border-radius: var(--radius-pill);\n}\n\n.nav-links {\n  display: flex;\n  align-items: center;\n  gap: 24px;\n}\n.nav-link {\n  font-size: 14px;\n  font-weight: 500;\n  color: var(--geist-secondary);\n  text-decoration: none;\n  transition: color 0.15s;\n}\n.nav-link:hover, .nav-link.active {\n  color: var(--geist-foreground);\n}\n.nav-link.active {\n  font-weight: 600;\n}\n\n.nav-actions {\n  display: flex;\n  align-items: center;\n  gap: 12px;\n}\n\n/* 按钮规范 */\n.btn-primary-dark {\n  background: var(--geist-foreground);\n  color: var(--geist-background);\n  border: none;\n  padding: 8px 16px;\n  border-radius: var(--radius-md);\n  font-size: 14px;\n  font-weight: 500;\n  cursor: pointer;\n  text-decoration: none;\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  transition: opacity 0.15s;\n}\n.btn-primary-dark:hover {\n  opacity: 0.9;\n}\n.btn-secondary-white {\n  background: var(--geist-background);\n  color: var(--geist-foreground);\n  box-shadow: var(--shadow-border);\n  border: none;\n  padding: 8px 16px;\n  border-radius: var(--radius-md);\n  font-size: 14px;\n  font-weight: 500;\n  cursor: pointer;\n  text-decoration: none;\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  transition: background 0.15s, box-shadow 0.15s;\n}\n.btn-secondary-white:hover {\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border-hover);\n}\n.theme-toggle-btn {\n  background: transparent;\n  border: none;\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  width: 36px;\n  height: 36px;\n  cursor: pointer;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  color: var(--geist-foreground);\n}\n\n/* 核心容器 */\n.vercel-container {\n  max-width: 1200px;\n  margin: 0 auto;\n  padding: 56px 24px 100px;\n}\n\n/* Hero Section (Gallery Emptiness + Negative Letter-spacing) */\n.vercel-hero {\n  text-align: center;\n  max-width: 860px;\n  margin: 0 auto 56px;\n}\n.hero-stage-badge {\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border);\n  padding: 4px 14px;\n  border-radius: var(--radius-pill);\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-secondary);\n  margin-bottom: 24px;\n}\n.stage-dot {\n  width: 7px;\n  height: 7px;\n  border-radius: 50%;\n}\n.vercel-hero h1 {\n  font-size: 48px;\n  font-weight: 600;\n  line-height: 1.05;\n  letter-spacing: -2.4px;\n  color: var(--geist-foreground);\n  margin: 0 0 16px;\n}\n.vercel-hero p {\n  font-size: 20px;\n  font-weight: 400;\n  line-height: 1.80;\n  color: var(--geist-secondary);\n  margin: 0 auto 28px;\n}\n\n/* Workflow Pipeline (Develop -> Preview -> Ship) */\n.workflow-pipeline {\n  display: grid;\n  grid-template-columns: repeat(3, 1fr);\n  gap: 16px;\n  margin-bottom: 48px;\n}\n@media (max-width: 768px) {\n  .workflow-pipeline { grid-template-columns: 1fr; }\n}\n.workflow-step {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 20px 22px;\n  transition: box-shadow 0.2s;\n}\n.workflow-step:hover {\n  box-shadow: var(--shadow-card-hover);\n}\n.step-mono-label {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 12px;\n  font-weight: 500;\n  text-transform: uppercase;\n  letter-spacing: 0.5px;\n  margin-bottom: 8px;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n}\n.step-title {\n  font-size: 20px;\n  font-weight: 600;\n  letter-spacing: -0.96px;\n  color: var(--geist-foreground);\n  margin-bottom: 6px;\n}\n.step-desc {\n  font-size: 14px;\n  color: var(--geist-secondary);\n  line-height: 1.5;\n}\n\n/* Metric Cards (Section 4 Spec) */\n.metric-grid {\n  display: grid;\n  grid-template-columns: repeat(4, 1fr);\n  gap: 16px;\n  margin-bottom: 48px;\n}\n@media (max-width: 900px) {\n  .metric-grid { grid-template-columns: repeat(2, 1fr); }\n}\n.metric-card {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 20px;\n}\n.metric-number {\n  font-size: 40px;\n  font-weight: 600;\n  line-height: 1.0;\n  letter-spacing: -2.4px;\n  color: var(--geist-foreground);\n  margin-bottom: 8px;\n  font-feature-settings: \"tnum\" 1;\n}\n.metric-label {\n  font-size: 14px;\n  color: var(--geist-secondary);\n  line-height: 1.4;\n}\n\n/* VAD 专栏 Banner (Ship Red & Vercel Clean) */\n.vad-showcase {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card-full);\n  border-radius: var(--radius-xl);\n  padding: 32px;\n  margin-bottom: 48px;\n  position: relative;\n}\n.vad-header-row {\n  display: flex;\n  align-items: baseline;\n  justify-content: space-between;\n  flex-wrap: wrap;\n  gap: 12px;\n  margin-bottom: 12px;\n}\n.vad-header-row h2 {\n  font-size: 32px;\n  font-weight: 600;\n  letter-spacing: -1.28px;\n  color: var(--geist-foreground);\n  margin: 0;\n}\n.vad-pillars-grid {\n  display: grid;\n  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));\n  gap: 14px;\n  margin-top: 24px;\n}\n.vad-pillar-item {\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  padding: 14px 16px;\n}\n.vad-pillar-title {\n  font-size: 14px;\n  font-weight: 600;\n  color: var(--ship-red);\n  margin-bottom: 4px;\n}\n.vad-pillar-text {\n  font-size: 13px;\n  color: var(--geist-secondary);\n  line-height: 1.5;\n}\n.vad-filter-bar {\n  display: flex;\n  flex-wrap: wrap;\n  align-items: center;\n  justify-content: space-between;\n  gap: 12px;\n  margin: 24px 0 16px;\n  padding: 12px 16px;\n  background: var(--geist-surface-tint);\n  border-radius: var(--radius-md);\n  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);\n}\n.vad-filter-btn {\n  font-family: 'Geist', sans-serif;\n  font-size: 13px;\n  font-weight: 500;\n  padding: 6px 14px;\n  border-radius: 9999px;\n  border: none;\n  background: transparent;\n  color: var(--geist-secondary);\n  cursor: pointer;\n  transition: all 0.15s ease;\n}\n.vad-filter-btn:hover {\n  color: var(--geist-foreground);\n  background: rgba(0,0,0,0.05);\n}\n.vad-filter-btn.active {\n  background: #171717;\n  color: #ffffff;\n}\n.vad-search-input {\n  font-family: 'Geist', sans-serif;\n  font-size: 13px;\n  padding: 7px 12px;\n  border-radius: 6px;\n  border: 1px solid var(--geist-border);\n  background: #ffffff;\n  color: var(--geist-foreground);\n  width: 280px;\n  outline: none;\n  transition: border-color 0.15s, box-shadow 0.15s;\n}\n.vad-search-input:focus {\n  border-color: #0a72ef;\n  box-shadow: 0 0 0 2px rgba(10, 114, 239, 0.2);\n}\n\n/* 控制栏：搜索、视图、筛选 */\n.control-bar {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 16px;\n  margin-bottom: 24px;\n  flex-wrap: wrap;\n}\n.search-input-wrap {\n  position: relative;\n  flex: 1;\n  max-width: 480px;\n}\n.search-input {\n  width: 100%;\n  height: 40px;\n  padding: 0 38px 0 14px;\n  font-family: \"Geist\", sans-serif;\n  font-size: 14px;\n  color: var(--geist-foreground);\n  background: var(--geist-background);\n  box-shadow: var(--shadow-border);\n  border: none;\n  border-radius: var(--radius-md);\n  outline: none;\n  transition: box-shadow 0.15s;\n}\n.search-input:focus {\n  outline: 2px solid var(--ds-focus-color);\n  box-shadow: none;\n}\n.search-kbd {\n  position: absolute;\n  right: 12px;\n  top: 50%;\n  transform: translateY(-50%);\n  font-family: \"Geist Mono\", monospace;\n  font-size: 11px;\n  color: var(--geist-quaternary);\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border);\n  padding: 2px 6px;\n  border-radius: var(--radius-sm);\n}\n\n.view-switcher {\n  display: flex;\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  background: var(--geist-background);\n  padding: 2px;\n}\n.view-btn {\n  background: transparent;\n  border: none;\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-tertiary);\n  padding: 6px 12px;\n  border-radius: var(--radius-sm);\n  cursor: pointer;\n  transition: color 0.15s, background 0.15s;\n}\n.view-btn.active {\n  background: var(--geist-surface-tint);\n  color: var(--geist-foreground);\n  font-weight: 600;\n}\n\n/* 筛选芯片行 (Filter Pill Strip) */\n.filter-group-strip {\n  display: flex;\n  flex-direction: column;\n  gap: 12px;\n  margin-bottom: 28px;\n  padding: 16px 20px;\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-lg);\n}\n.filter-row {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  flex-wrap: wrap;\n}\n.filter-label-mono {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 11px;\n  font-weight: 500;\n  text-transform: uppercase;\n  color: var(--geist-quaternary);\n  min-width: 68px;\n}\n.pill-badge {\n  background: var(--geist-background);\n  color: var(--geist-secondary);\n  box-shadow: var(--shadow-border);\n  border: none;\n  padding: 3px 12px;\n  border-radius: var(--radius-pill);\n  font-size: 12px;\n  font-weight: 500;\n  cursor: pointer;\n  transition: all 0.15s;\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n}\n.pill-badge:hover {\n  color: var(--geist-foreground);\n  box-shadow: var(--shadow-border-hover);\n}\n.pill-badge.active {\n  background: var(--geist-foreground);\n  color: var(--geist-background);\n  font-weight: 600;\n  box-shadow: none;\n}\n.pill-badge.active-blue {\n  background: var(--develop-blue);\n  color: #ffffff;\n  box-shadow: none;\n}\n.pill-badge.active-red {\n  background: var(--ship-red);\n  color: #ffffff;\n  box-shadow: none;\n}\n\n/* Bento Grid Cards (Section 4 & 6 Spec) */\n.card-grid-bento {\n  display: grid;\n  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));\n  gap: 16px;\n}\n.vercel-card {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 20px;\n  display: flex;\n  flex-direction: column;\n  justify-content: space-between;\n  transition: box-shadow 0.2s, transform 0.2s;\n  text-decoration: none;\n  color: inherit;\n  overflow: hidden;\n  min-width: 0;\n  word-break: break-word;\n}\n.vercel-card:hover {\n  box-shadow: var(--shadow-card-hover);\n  transform: translateY(-2px);\n}\n.card-top {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  margin-bottom: 12px;\n  gap: 8px;\n}\n.card-tag-mono {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 11px;\n  font-weight: 500;\n  text-transform: uppercase;\n  color: var(--geist-quaternary);\n  letter-spacing: 0.5px;\n}\n.status-pill-badge {\n  padding: 2px 8px;\n  border-radius: var(--radius-pill);\n  font-size: 11px;\n  font-weight: 500;\n  flex-shrink: 0;\n}\n.pub-accepted { background: #ebfdf2; color: #027a48; }\n.pub-workshop { background: #eff8ff; color: #175cd3; }\n.pub-submitted { background: #fff8e6; color: #b54708; }\n.pub-preprint { background: #f2f4f7; color: #475467; }\n.pub-other { background: #f9f5ff; color: #6941c6; }\n\n[data-theme=\"dark\"] .pub-accepted { background: rgba(2, 122, 72, 0.2); color: #32d583; }\n[data-theme=\"dark\"] .pub-workshop { background: rgba(23, 92, 211, 0.2); color: #84caff; }\n[data-theme=\"dark\"] .pub-submitted { background: rgba(181, 71, 8, 0.2); color: #fec84b; }\n[data-theme=\"dark\"] .pub-preprint { background: rgba(71, 84, 103, 0.2); color: #98a2b3; }\n[data-theme=\"dark\"] .pub-other { background: rgba(105, 65, 198, 0.2); color: #d6bbfb; }\n\n/* 必读标杆徽章 (Vercel Amber Accent) */\n.milestone-badge {\n  display: inline-flex;\n  align-items: center;\n  gap: 3px;\n  padding: 2px 7px;\n  border-radius: var(--radius-pill);\n  font-size: 11px;\n  font-weight: 600;\n  white-space: nowrap;\n  flex-shrink: 0;\n  transition: all 0.15s ease;\n}\n.milestone-badge.ms-idea, .milestone-badge:not([class*=\"ms-\"]) {\n  color: #b54708;\n  background: #fff8e6;\n  border: 1px solid rgba(247, 144, 9, 0.35);\n  box-shadow: 0 1px 2px rgba(181, 71, 8, 0.05);\n}\n[data-theme=\"dark\"] .milestone-badge.ms-idea, [data-theme=\"dark\"] .milestone-badge:not([class*=\"ms-\"]) {\n  color: #fec84b;\n  background: rgba(181, 71, 8, 0.22);\n  border-color: rgba(254, 200, 75, 0.35);\n}\n.milestone-badge.ms-writing {\n  color: #6941c6;\n  background: #f9f5ff;\n  border: 1px solid rgba(105, 65, 198, 0.3);\n  box-shadow: 0 1px 2px rgba(105, 65, 198, 0.05);\n}\n[data-theme=\"dark\"] .milestone-badge.ms-writing {\n  color: #d6bbfb;\n  background: rgba(105, 65, 198, 0.22);\n  border-color: rgba(214, 187, 251, 0.35);\n}\n.milestone-badge.ms-value {\n  color: #027a48;\n  background: #ebfdf2;\n  border: 1px solid rgba(2, 122, 72, 0.3);\n  box-shadow: 0 1px 2px rgba(2, 122, 72, 0.05);\n}\n[data-theme=\"dark\"] .milestone-badge.ms-value {\n  color: #32d583;\n  background: rgba(2, 122, 72, 0.22);\n  border-color: rgba(50, 213, 131, 0.35);\n}\n\n/* 论文正文图表与插图卡片样式 (Geist Design) */\n.paper-figure, .article-body figure {\n  margin: 32px auto;\n  text-align: center;\n  max-width: 100%;\n}\n.paper-figure img, .article-body img {\n  max-width: 96%;\n  height: auto;\n  border-radius: var(--radius-md);\n  border: 1px solid var(--geist-border);\n  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);\n  background: #ffffff;\n  transition: transform 0.2s ease, box-shadow 0.2s ease;\n  display: block;\n  margin: 0 auto;\n}\n.paper-figure img:hover, .article-body img:hover {\n  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);\n}\n.paper-figure figcaption, .article-body figcaption {\n  font-size: 13px;\n  color: var(--geist-secondary);\n  margin-top: 10px;\n  line-height: 1.6;\n  font-style: italic;\n  max-width: 850px;\n  margin-left: auto;\n  margin-right: auto;\n}\n\n/* VAD 视图切换器 View Switcher */\n.vad-view-switcher {\n  display: inline-flex;\n  padding: 3px;\n  background: var(--geist-secondary-bg);\n  border: 1px solid var(--geist-border);\n  border-radius: 8px;\n  margin-bottom: 20px;\n  gap: 2px;\n}\n.view-switch-btn {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  padding: 6px 14px;\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-secondary);\n  border-radius: 6px;\n  text-decoration: none;\n  transition: all 0.15s ease;\n}\n.view-switch-btn:hover {\n  color: var(--geist-foreground);\n  background: rgba(0, 0, 0, 0.04);\n}\n[data-theme=\"dark\"] .view-switch-btn:hover {\n  background: rgba(255, 255, 255, 0.06);\n}\n.view-switch-btn.active {\n  background: var(--geist-background);\n  color: var(--geist-foreground);\n  font-weight: 600;\n  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);\n}\n\n/* 关系图谱 Graph View Styles */\n.graph-container {\n  position: relative;\n  width: 100%;\n  height: 720px;\n  background: var(--geist-background);\n  border: 1px solid var(--geist-border);\n  border-radius: var(--radius-lg);\n  overflow: hidden;\n  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);\n  margin-bottom: 40px;\n}\n.graph-toolbar {\n  position: absolute;\n  top: 14px;\n  left: 14px;\n  right: 14px;\n  z-index: 10;\n  display: flex;\n  justify-content: space-between;\n  align-items: center;\n  background: var(--geist-background);\n  border: 1px solid var(--geist-border);\n  padding: 8px 14px;\n  border-radius: 8px;\n  box-shadow: 0 4px 16px rgba(0,0,0,0.06);\n  flex-wrap: wrap;\n  gap: 8px;\n}\n.graph-tool-title {\n  font-size: 13px;\n  font-weight: 700;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  color: var(--geist-foreground);\n}\n.graph-filter-group {\n  display: flex;\n  gap: 6px;\n  align-items: center;\n  flex-wrap: wrap;\n}\n.graph-chip {\n  font-size: 11px;\n  padding: 3px 8px;\n  border-radius: 4px;\n  border: 1px solid var(--geist-border);\n  background: var(--geist-background);\n  color: var(--geist-foreground);\n  cursor: pointer;\n  transition: all 0.15s ease;\n}\n.graph-chip:hover { background: var(--geist-secondary-bg); }\n.graph-chip.active {\n  background: var(--geist-foreground);\n  color: var(--geist-background);\n  border-color: var(--geist-foreground);\n}\n.graph-search-input {\n  padding: 3px 8px;\n  font-size: 11px;\n  border-radius: 4px;\n  border: 1px solid var(--geist-border);\n  background: var(--geist-background);\n  color: var(--geist-foreground);\n  outline: none;\n  width: 150px;\n}\n#vad-graph-svg {\n  width: 100%;\n  height: 100%;\n  cursor: grab;\n}\n#vad-graph-svg:active { cursor: grabbing; }\n.graph-legend {\n  position: absolute;\n  bottom: 14px;\n  left: 14px;\n  background: var(--geist-background);\n  border: 1px solid var(--geist-border);\n  border-radius: 8px;\n  padding: 10px 14px;\n  font-size: 11px;\n  box-shadow: 0 4px 16px rgba(0,0,0,0.06);\n  z-index: 10;\n  line-height: 1.6;\n  pointer-events: none;\n}\n.graph-legend-row { display: flex; align-items: center; gap: 8px; }\n.graph-legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }\n.graph-info-drawer {\n  position: absolute;\n  top: 66px;\n  right: 14px;\n  width: 310px;\n  max-height: 620px;\n  background: var(--geist-background);\n  border: 1px solid var(--geist-border);\n  border-radius: 8px;\n  box-shadow: 0 8px 30px rgba(0,0,0,0.12);\n  z-index: 10;\n  padding: 16px;\n  overflow-y: auto;\n  display: none;\n  backdrop-filter: blur(10px);\n  transition: transform 0.2s ease, opacity 0.2s ease;\n}\n.graph-drawer-close {\n  position: absolute;\n  top: 10px;\n  right: 12px;\n  cursor: pointer;\n  font-size: 16px;\n  color: var(--geist-tertiary);\n}\n.graph-drawer-badge {\n  display: inline-block;\n  padding: 2px 6px;\n  border-radius: 4px;\n  font-size: 10px;\n  font-weight: 600;\n  margin-bottom: 6px;\n}\n.graph-drawer-title {\n  font-size: 13px;\n  font-weight: 700;\n  line-height: 1.4;\n  margin-bottom: 8px;\n  color: var(--geist-foreground);\n}\n.graph-drawer-meta {\n  font-size: 11px;\n  color: var(--geist-secondary);\n  margin-bottom: 12px;\n}\n.graph-drawer-core {\n  font-size: 12px;\n  line-height: 1.6;\n  color: var(--geist-foreground);\n  background: var(--geist-secondary-bg);\n  padding: 8px 10px;\n  border-radius: 6px;\n  margin-bottom: 12px;\n  border: 1px solid var(--geist-border);\n}\n.graph-drawer-link {\n  display: block;\n  text-align: center;\n  padding: 7px 12px;\n  background: var(--geist-foreground);\n  color: var(--geist-background);\n  border-radius: 6px;\n  font-size: 12px;\n  font-weight: 600;\n  text-decoration: none;\n  transition: opacity 0.15s ease;\n  margin-bottom: 6px;\n}\n.graph-drawer-link:hover { opacity: 0.85; }\n.graph-drawer-pdf-link {\n  display: block;\n  text-align: center;\n  padding: 6px 12px;\n  background: var(--geist-secondary-bg);\n  color: var(--geist-foreground);\n  border: 1px solid var(--geist-border);\n  border-radius: 6px;\n  font-size: 11px;\n  font-weight: 500;\n  text-decoration: none;\n  transition: all 0.15s ease;\n}\n.graph-drawer-pdf-link:hover { background: var(--geist-border); }\n.node-circle {\n  cursor: pointer;\n  transition: r 0.2s, stroke-width 0.2s;\n}\n.node-label {\n  font-size: 10px;\n  font-weight: 600;\n  fill: var(--geist-foreground);\n  pointer-events: none;\n  text-shadow: 0 1px 2px var(--geist-background);\n}\n.link-line {\n  stroke: var(--geist-border);\n  stroke-opacity: 0.6;\n  stroke-width: 1.2;\n  transition: stroke 0.2s, stroke-width 0.2s, stroke-opacity 0.2s;\n}\n.link-label {\n  font-size: 9px;\n  fill: var(--geist-tertiary);\n  pointer-events: none;\n  text-anchor: middle;\n}\n\n/* 引用框与警示框 Alerts */\n.callout-alert {\n  margin: 20px 0;\n  padding: 14px 18px;\n  border-radius: var(--radius-md);\n  transition: all 0.15s ease;\n}\n.callout-important, .callout-idea {\n  border-left: 4px solid #b54708;\n  background: rgba(181, 71, 8, 0.06);\n  box-shadow: inset 0 0 0 1px rgba(247, 144, 9, 0.3);\n}\n[data-theme=\"dark\"] .callout-important, [data-theme=\"dark\"] .callout-idea {\n  border-left-color: #fec84b;\n  background: rgba(181, 71, 8, 0.18);\n  box-shadow: inset 0 0 0 1px rgba(254, 200, 75, 0.25);\n}\n.callout-writing {\n  border-left: 4px solid #6941c6;\n  background: rgba(105, 65, 198, 0.06);\n  box-shadow: inset 0 0 0 1px rgba(105, 65, 198, 0.3);\n}\n[data-theme=\"dark\"] .callout-writing {\n  border-left-color: #d6bbfb;\n  background: rgba(105, 65, 198, 0.18);\n  box-shadow: inset 0 0 0 1px rgba(214, 187, 251, 0.25);\n}\n.callout-value {\n  border-left: 4px solid #027a48;\n  background: rgba(2, 122, 72, 0.06);\n  box-shadow: inset 0 0 0 1px rgba(2, 122, 72, 0.3);\n}\n[data-theme=\"dark\"] .callout-value {\n  border-left-color: #32d583;\n  background: rgba(2, 122, 72, 0.18);\n  box-shadow: inset 0 0 0 1px rgba(50, 213, 131, 0.25);\n}\n\n.card-title {\n  font-size: 16.5px;\n  font-weight: 600;\n  line-height: 1.42;\n  letter-spacing: -0.4px;\n  color: var(--geist-foreground);\n  margin: 0 0 10px;\n  word-break: break-word;\n  overflow-wrap: anywhere;\n  hyphens: auto;\n}\n.card-title a {\n  color: var(--geist-foreground);\n  text-decoration: none;\n  display: inline;\n  transition: color 0.15s ease;\n}\n.card-title a:hover {\n  color: var(--develop-blue);\n  text-decoration: none;\n}\n.card-id-mono {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-quaternary);\n  margin-right: 5px;\n}\n.card-meta-row {\n  display: flex;\n  gap: 6px;\n  flex-wrap: wrap;\n  margin-bottom: 12px;\n}\n.meta-token {\n  font-size: 12px;\n  color: var(--geist-tertiary);\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-ring);\n  padding: 2px 7px;\n  border-radius: var(--radius-sm);\n  white-space: nowrap;\n}\n.card-body-text {\n  font-size: 13.5px;\n  color: var(--geist-secondary);\n  line-height: 1.6;\n  margin-bottom: 16px;\n  flex-grow: 1;\n  word-break: break-word;\n  overflow-wrap: anywhere;\n}\n.card-body-text strong {\n  color: var(--geist-foreground);\n  font-weight: 600;\n}\n\n.card-footer {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  border-top: 1px solid var(--geist-border);\n  padding-top: 14px;\n}\n.card-link-action {\n  font-size: 13.5px;\n  font-weight: 500;\n  color: var(--link-blue);\n  display: inline-flex;\n  align-items: center;\n  gap: 4px;\n  text-decoration: none;\n  transition: all 0.15s ease;\n}\n.card-link-action:hover {\n  opacity: 0.85;\n  transform: translateX(2px);\n}\na.meta-token {\n  transition: all 0.15s ease;\n  cursor: pointer;\n  text-decoration: none;\n}\na.meta-token:hover {\n  background: var(--geist-selection);\n  color: var(--geist-foreground);\n  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);\n}\n\n/* 紧凑列表视图 (List View) */\n.card-list-view {\n  display: flex;\n  flex-direction: column;\n  gap: 8px;\n}\n.list-row-item {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-md);\n  padding: 12px 18px;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 16px;\n  transition: box-shadow 0.15s;\n}\n.list-row-item:hover {\n  box-shadow: var(--shadow-card-hover);\n}\n\n/* 阅读详情页 (Report Detail) */\n.reading-container {\n  display: grid;\n  grid-template-columns: minmax(0, 1fr) 260px;\n  gap: 40px;\n  align-items: start;\n}\n@media (max-width: 960px) {\n  .reading-container { grid-template-columns: 1fr; }\n  .reading-sidebar { display: none; }\n}\n\n.report-header-card {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 28px 32px;\n  margin-bottom: 28px;\n}\n.crumb-bar {\n  font-size: 13px;\n  color: var(--geist-tertiary);\n  margin-bottom: 10px;\n}\n.report-title {\n  font-size: 32px;\n  font-weight: 600;\n  letter-spacing: -1.28px;\n  margin: 0 0 16px;\n  color: var(--geist-foreground);\n}\n.report-action-buttons {\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  flex-wrap: wrap;\n  border-top: 1px solid var(--geist-border);\n  padding-top: 16px;\n  margin-top: 16px;\n}\n\n.article-body {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card-full);\n  border-radius: var(--radius-lg);\n  padding: 36px 42px 80px;\n  font-size: 16px;\n  line-height: 1.75;\n  color: var(--geist-foreground);\n}\n.article-body h1, .article-body h2, .article-body h3 {\n  color: var(--geist-foreground);\n  scroll-margin-top: 80px;\n}\n.article-body h1 { font-size: 28px; font-weight: 600; letter-spacing: -1.28px; border-bottom: 1px solid var(--geist-border); padding-bottom: 8px; margin-top: 32px; }\n.article-body h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.96px; border-bottom: 1px solid var(--geist-border); padding-bottom: 6px; margin-top: 36px; }\n.article-body h3 { font-size: 18px; font-weight: 600; letter-spacing: -0.32px; margin-top: 26px; }\n.article-body table {\n  width: 100%;\n  border-collapse: collapse;\n  margin: 24px 0;\n  font-size: 14px;\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  overflow: hidden;\n}\n.article-body th, .article-body td {\n  padding: 10px 14px;\n  text-align: left;\n  border-bottom: 1px solid var(--geist-border);\n}\n.article-body th {\n  background: var(--geist-surface-tint);\n  font-weight: 600;\n  color: var(--geist-foreground);\n}\n.article-body blockquote {\n  border-left: 2px solid var(--geist-foreground);\n  margin: 20px 0;\n  padding: 8px 18px;\n  color: var(--geist-secondary);\n  font-style: normal;\n}\n.article-body code {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 13.5px;\n  box-shadow: var(--shadow-ring);\n  background: var(--geist-surface-tint);\n  padding: 2px 6px;\n  border-radius: var(--radius-sm);\n}\n.article-body pre {\n  position: relative;\n  background: #000000;\n  color: #ededed;\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  padding: 18px;\n  margin: 24px 0;\n  overflow-x: auto;\n}\n.article-body pre code {\n  background: transparent;\n  box-shadow: none;\n  padding: 0;\n  color: inherit;\n  font-size: 13px;\n}\n.copy-code-btn {\n  position: absolute;\n  top: 8px;\n  right: 10px;\n  font-family: \"Geist Mono\", monospace;\n  font-size: 11px;\n  background: #171717;\n  color: #ffffff;\n  border: 1px solid #333333;\n  padding: 3px 8px;\n  border-radius: var(--radius-sm);\n  cursor: pointer;\n}\n\n/* 侧边大纲 (TOC) */\n.reading-sidebar {\n  position: sticky;\n  top: 80px;\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 20px;\n  max-height: calc(100vh - 100px);\n  overflow-y: auto;\n}\n.sidebar-toc-title {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 12px;\n  font-weight: 500;\n  text-transform: uppercase;\n  letter-spacing: 0.5px;\n  color: var(--geist-quaternary);\n  margin-bottom: 12px;\n}\n.reading-sidebar ul {\n  list-style: none;\n  padding-left: 0;\n  margin: 0;\n  font-size: 13px;\n}\n.reading-sidebar li {\n  margin: 6px 0;\n}\n.reading-sidebar ul ul {\n  padding-left: 14px;\n}\n.reading-sidebar a {\n  color: var(--geist-secondary);\n  text-decoration: none;\n  transition: color 0.15s;\n}\n.reading-sidebar a:hover, .reading-sidebar a.active {\n  color: var(--geist-foreground);\n  font-weight: 600;\n}\n\n/* 后台管理 (/admin) */\n.admin-card-container {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card-full);\n  border-radius: var(--radius-lg);\n  padding: 32px;\n  margin-bottom: 32px;\n}\n.form-row-2 {\n  display: grid;\n  grid-template-columns: 1fr 1fr;\n  gap: 16px;\n  margin-bottom: 16px;\n}\n@media (max-width: 600px) {\n  .form-row-2 { grid-template-columns: 1fr; }\n}\n.form-field {\n  display: flex;\n  flex-direction: column;\n  gap: 6px;\n  margin-bottom: 16px;\n}\n.form-field label {\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-foreground);\n}\n.form-field input, .form-field select, .form-field textarea {\n  font-family: \"Geist\", sans-serif;\n  font-size: 14px;\n  padding: 9px 12px;\n  background: var(--geist-background);\n  box-shadow: var(--shadow-border);\n  border: none;\n  border-radius: var(--radius-md);\n  color: var(--geist-foreground);\n  outline: none;\n}\n.form-field input:focus, .form-field select:focus, .form-field textarea:focus {\n  outline: 2px solid var(--ds-focus-color);\n  box-shadow: none;\n}\n\n/* 语法高亮 (Console Blue / Purple / Pink) */\n.codehilite .k, .codehilite .kd, .codehilite .kn { color: #eb367f; font-weight: 500; }\n.codehilite .s, .codehilite .s1, .codehilite .s2 { color: #0070f3; }\n.codehilite .nf, .codehilite .na { color: #7928ca; font-weight: 500; }\n.codehilite .c, .codehilite .c1 { color: #666666; font-style: italic; }\n.codehilite .mi, .codehilite .mf { color: #ff5b4f; }\n\n</style>\n\n</head>\n<body>\n\n    <nav class=\"vercel-nav\">\n      <div class=\"nav-brand\">\n        <a href=\"/\" style=\"display:flex;align-items:center;gap:10px;text-decoration:none\">\n          <svg class=\"vercel-triangle\" viewBox=\"0 0 76 65\" fill=\"none\">\n            <path d=\"M37.5274 0L75.0548 65H0L37.5274 0Z\" fill=\"currentColor\"/>\n          </svg>\n          <span class=\"nav-title\">Agent Harness KB</span>\n        </a>\n        <span class=\"nav-badge-pill\">Geist 2.0</span>\n      </div>\n\n      <div class=\"nav-links\">\n        <a class=\"nav-link \" href=\"/\">全景总览</a>\n        <a class=\"nav-link \" href=\"/vad\" style=\"color:var(--ship-red)\">🎯 VAD 专栏 (144)</a>\n        <a class=\"nav-link\" href=\"https://m0rtzz.github.io/paper-notes/\" target=\"_blank\" rel=\"noopener\">顶会 669 篇 ↗</a>\n        <a class=\"nav-link\" href=\"/download/all\">整库打包</a>\n        \n      </div>\n\n      <div class=\"nav-actions\">\n        \n        <button class=\"theme-toggle-btn\" id=\"theme-toggle-btn\" onclick=\"toggleTheme()\" title=\"切换亮暗主题\">🌙</button>\n      </div>\n    </nav>\n    \n<main class=\"vercel-container\">\n\n        <div class=\"report-header-card\">\n          <div class=\"crumb-bar\"><a href=\"/\">Home</a> / <b>fulltext.txt</b></div>\n          <h1 class=\"report-title\">fulltext.txt</h1>\n          <div class=\"report-action-buttons\">\n            <a class=\"btn-primary-dark\" href=\"?dl=1\">Download Text</a>\n          </div>\n        </div>\n        <article class=\"article-body\"><pre><code>AutoHarness: improving LLM agents by automatically\nsynthesizing a code harness\n\narXiv:2603.03329v1 [cs.CL] 10 Feb 2026\n\nXinghua Lou, Miguel Lázaro-Gredilla, Antoine Dedieu,\nCarter Wendelken, Wolfgang Lehrach, Kevin P. Murphy\nGoogle DeepMind\n{xinghua,lazarogredilla,adedieu,cwendelken,wpl,kpmurphy}@deepmind.com\nMarch 5, 2026\nAbstract\nDespite significant strides in language models in the last few years, when used as agents, such models\noften try to perform actions that are not just suboptimal for a given state, but are strictly prohibited\nby the external environment. For example, in the recent Kaggle GameArena chess competition, 78% of\nGemini-2.5-Flash losses were attributed to illegal moves. Often people manually write \"harnesses\" around\nLLMs to prevent such failures. In this paper, we demonstrate that Gemini-2.5-Flash can automatically\nsynthesize such a code harness, using a small number of rounds of iterative code refinement given feedback\nfrom the (game) environment. The resulting harness prevents all illegal moves in 145 different TextArena\ngames (both 1-player and 2-player), enabling the smaller Gemini-2.5-Flash model to outperform larger\nmodels, such as Gemini-2.5-Pro. Pushing our technique to the limit, we can get Gemini-2.5-Flash to\ngenerate the entire policy in code, thus eliminating the need to use the LLM at decision making time.\nThe resulting code-policy receives a higher average reward than Gemini-2.5-Pro and GPT-5.2-High on\n16 TextArena 1-player games. Our results show that using a smaller model to synthesize a custom code\nharness (or entire policy) can outperform a much larger model, while also being more cost effective.\n\n1\n\nIntroduction\n\nLarge language models (LLMs) have demonstrated remarkable capabilities in code synthesis and solving\nmath problems (see e.g., Chervonyi et al. (2025); Huang &amp; Yang (2025)). However, their planning and\nreasoning performance can be brittle (see e.g., (Valmeekam et al., 2023a; Petrov et al., 2025). For example,\nin the recent Kaggle GameArena (Kaggle, 2025) chess competition, 78% of losses by Gemini 2.5 Flash were\nattributed not to strategic blunders, but to simple illegal moves.\nThis failure mode highlights a disconnect between the model’s apparent understanding of the game and\nits ability to actually follow the rules (see e.g. Fig. A16 in (Ruoss et al., 2024)).1 Traditional approaches to\nmitigate this involve fine-tuning on game trajectories or using hand-coded harnesses that verify the validity\nof a move. Fine-tuning LLMs, particularly at the scale of current flagship models, is neither fast nor cost\neffective, and can degrade model performance on other tasks, e.g. instruction following. Hand-designed\nharnesses are brittle and labor-intensive, requiring additional work for every new game. A more scalable\nsolution — which we pursue in this paper — is to leverage the LLM’s own code-generation capabilities to\nbridge this gap.\nAn agent is often defined as the combination of a specific LLM and a harness that acts as the “glue”\nor “plumbing” between the model and the task that needs to be solved. In this work, we propose “code as\nharness”, a framework where the LLM itself completes the agent by coding its own harness. In its simplest\nincarnation, the harness can be seen as a control loop that calls the LLM and rejects unacceptable answers.\nThe definition of what is acceptable is itself learned. This essentially results in a rejection sampler for LLMs\nin which the conditioning is learned based on the task.\n1 The general problem of knowing which actions are valid in a given state is called the \"action applicability\" problem, and\nhas been studied in the AI planning community (Kokel et al., 2025).\n\n1\n\n\fWe formulate the generation of this harness as a search problem over the space of programs. Unlike simple\niterative prompting, we employ a tree search guided by Thompson sampling (Tang et al., 2024) to efficiently\nexplore the landscape of potential harnesses. In this setup, the LLM acts as a mutation operator, proposing\nrefinements to the code based on feedback from execution. The search algorithm balances exploration (trying\ndistinct logic structures) and exploitation (refining a partially working harness) to converge on a robust\ncontrol loop. The harness template can be more constrained (e.g., a fixed rejection sampling loop where\nwe only learn a conditioning function with signature def is_legal_action()), or less so, with maximum\nflexibility resulting in a code-as-policy setup (Liang et al., 2023) in which code proposes the next action\ndirectly and no LLM calls are needed at execution time.\n\n2\n\nRelated work\n\nLLMs for game playing and reasoning The use of LLMs as agents in game environments has been\nwidely studied, ranging from text-based adventure games to complex strategy games like Minecraft and chess\n(Shinn et al., 2023; Wang et al., 2023). Early works focused on “chain-of-thought” prompting (Wei et al.,\n2022) to improve strategic planning. However, recent benchmarks reveal that even advanced models struggle\nwith state tracking and validity in strictly defined environments (Valmeekam et al., 2023b). Techniques like\n“tree of thoughts” (Yao et al., 2023) utilize search during inference to simulate lookahead, but they rely on the\nLLM’s internal world model, which is prone to hallucination regarding valid transitions. Our work differs by\noffloading the state-transition validity checker to an external, verifiable program rather than relying on the\nmodel’s internal simulation. LLMs can also be used to generate code for the entire state transition function\n(i.e. world model) for a game (Lehrach et al., 2025), but that is unnecessarily onerous for complex games\nin which a comparatively simple strategy can be applied. In addition, this approach does not leverage the\nstrategic abilities of the LLM to select between valid actions.\nCode as policy Our approach builds upon the growing body of work using code generation for action\nplanning. Voyager (Wang et al., 2023) demonstrated that LLMs could continuously learn Minecraft skills by\nstoring executable code in a library. Similarly, Eureka (Ma et al., 2024) showed that LLMs could perform\nevolutionary search to generate reward functions for reinforcement learning. Closer to our work, code as\npolicies (Liang et al., 2023) formulated robot control directly as code generation. Our approach is related,\nbut uses iterative code refinement, based on tree search and rich environment feedback, to generate a hybrid\ncode+LLM harness.\nRefinement and search As mentioned, iterative refinement is crucial for code generation. Reflexion\n(Shinn et al., 2023) introduced a verbal reinforcement learning loop where agents reflect on failure logs. In\nthe domain of program synthesis, methods like AlphaCode (Li et al., 2022) utilize large-scale sampling and\nfiltering, whereas AlphaEvolve (Novikov et al., 2025) applies an evolutionary algorithm to entire codebases\nusing an LLM as a mutation function. Our method integrates these concepts into a structured tree search\nusing Thompson sampling, following (Tang et al., 2024), but applies it in an online, multi-turn setup, where\nthe goal is to create a code harness.\n\n3\n\nMethod\n\nInspired by Tang et al. (2024), our approach maintains multiple code hypotheses in a tree structure, and\nuses Thompson sampling to choose which node to refine next, where the heuristic value for each node is the\naverage legal move accuracy. The refinement (gradient-free code optimizer) is done with a base LLM, given\nfeedback from the environment (critic) about whether the previous attempted moves were legal or not, and\nwhat reward they produced (if any), see Fig.1. If is_legal_action() returns True but the action is invalid,\nwe refine both functions; while if is_legal_action() returns False and the action is invalid, we only refine\npropose_action().\nWe can use this approach to generate different kinds of code harnesses: harness-as-action-filter calls\npropose_action() to generate a set of legal moves, and leverages the LLM to rank them (potentially using\n\n2\n\n\fdef propose_action(obs):\n\n0.1\n\ndef is_legal_action(obs, action):\n0.2\n\n0.3\n\nOld Code\n\n0.5\n\n0.4\n\n0.6\n\n?\n\nRefiner\n\nCritic\n\nEvaluator\n\nNew Code\n\nEnvs\n\nRollout\n\nNew H\n\nFigure 1: Code-as-harness learning process.\nchain of thought reasoning); harness-as-action-verifier first calls the LLM to generate an action, verifies\nit by is_legal_action(), and, if invalid, repeats the process with a new prompt that includes an “illegal\naction” warning message; harness-as-policy uses code to choose the action; the code could in principle\ncall an LLM, but in our setting, the policy just uses primitive Python functions and standard libraries such\nas numpy, so we do not need to invoke an LLM at inference time. In this paper, we mostly focus on the\nharness-as-action-verifier, but in Sec.4.3, we also report preliminary results on harness-as-policy.\n\n4\n\nExperimental results\n\nFor our experiments we select all the 1-player (1P) and 2-player (2P) games from TextArena (Guertler et al.,\n2025), a large collection of complex and diverse text games, but exclude the 9 games whose action space\nis free-form text / dialog (such as \"Mafia\" and \"Codenames\"). This leaves us with 145 games, including\nwell-known games — such as Chess, Checkers, Blackjack and Sudoku — as well as novel variants of these\ngames. A full list of the games we use is in Appendix Table 1.\nTo make the problem more challenging for our harness, we modified some games by manually removing\nany form of “Available Moves” hints in the observation string (see Appendix Sec. A.4 for an example). We\nbelieve this better reflects many real-world scenarios where the agent needs to deduce legal actions from\nenvironmental feedback, rather than being told them explicitly. (Without this modification, the harness\ncan just copy the list of legal actions from the prompt. This gives better results, but we show that it is\nunnecessary.)\n\n4.1\n\nTraining\n\nOur training setup (for harness-as-action-verifier) is as follows. At each iteration, we use 10 parallel environments and roll out to at most 1000 steps (with auto environment resetting). Rollout is terminated whenever\nan illegal move is made by the code or code execution fails. At most 5 failed steps are sampled and fed to\nthe Critic, which consolidates various types of errors. These steps with error messages, together with the\noriginal code, are fed into the Refiner to generate new (hopefully improved) code. We set heuristic weight\nto 1.0 for Thompson sampling. Training ends when the heuristic value (i.e. the legal action success rate)\nreaches 1.0, or we time out. We use Gemini-2.5-Flash for training.\nOn average, training ends after 14.5 tree search iterations, while 19/32 games end in less than 10 iterations.\nThe games that required the most number of LLM calls to learn are are GermanWhist-v0 (2P), Cryptarithmv0 (1P), Othello-v0 (2P) and Chess-v0 (2P), as shown in Fig 2. We measure the accuracy of the action\nfilter by applying it to novel test rollouts (of length 1000, across 10 random random seeds per game), and\nmeasuring the fraction of legal actions. We achieved 100% legal action success rate for all the games as\nshown in Appendix Table 1. See Appendix Sec. D for examples of the generated code harness.\n\n3\n\n\fHeuristic Value\n\n1.0\n0.8\n0.6\n\n2048-v0\nChess-v0\nCryptarithm-v0\nFrozenLake-v0\nGermanWhist-v0\nOthello-v0\n\n0.4\n0.2\n0.0\n\n0\n\n10\n\n20\n30\n40\nSynthesis Iteration\n\n50\n\n60\n\nFigure 2: Fraction of legal moves vs number of code refinements for a selection of 6 games.\n\n4.2\n\nEvaluation\n\nWe now turn to evaluating performance of agents during actual game play. For reasons of efficiency, we\nfocus our results on 16 1P games and 16 2P games, rather than using all 145 games. We evaluate the\nfollowing agents: Gemini-2.5-Flash, Gemini-2.5-Pro and Gemini-2.5-Flash+Harness (ours).2 We use the\nsame optimized prompt in all experiments. For 1P games, we run 20 matches and use the reward as the\nevaluation metric. For 2P games, we run 40 matches with random seeds, split evenly between our method\nbeing the first or second player, and we use the average win/draw/loss rate as the evaluation metrics.\n\n1.00\n0.75\n0.50\n0.25\n0.00\n\nLosses\n\nDraws\n\nWins\n\n-v0 ak-v0 oe-v0\n-v0\n-v0\n-v0\n-v0\n-v0\n-v0\n-v0\n-v0\n-v0\n-v0\n-v0\n-v0\n-v0\nT\nque rough eckers Chess psticks rusade nWhist Golf rsDice fAction ecruit thello Malice ratego\ncT\nr\ne\nO And\nia esO\nicTa\nC rma\nSt\nwR\nCh\nL\nT\nho\ne\nAlqu reakth\ne\nC\nt\nN\ne\nB\nGe\nLin\nma\nSpit\nUlti\nFigure 3: Win/lose/draw rate of our method vs Gemini-2.5-Pro for each of the 16 2P games.\nWe show results for 2P games in Fig. 3. We see that our approach enables a much smaller Gemini-2.5Flash to win 9/16 games (overall win rate of 56.3%) against a much larger Gemini-2.5-Pro (overall win rate\nof 38.2%). When playing against (vanilla) Gemini-2.5-Flash, we win 12/16 games, and the overall win rate\nrises to 64.8%.\nWe show results for 1P games in Fig. 4. We see that our approach achieves a higher reward than Gemini2.5-Pro in 8/16 games, and ties in 5/16 games. On average, we achieve 0.745 reward, in comparison to 0.707\n(Gemini-2.5-Pro) and 0.673 (Gemini-2.5-Flash).\n2 Note that our method first uses an LLM (here Gemini-2.5-Flash) to generate the action verifier code harness, and then uses\nthis harness to filter proposals from the same LLM.\n\n4\n\n\fGemini-2.5-Pro\n\n1.0\n\nGemini-2.5-Flash+Harness\n\n0.5\n0.0\n\n8-v0 ndit-v0 jack-v0 thm-v0 zzle-v0 ake-v0 ber-v0 Out-v0 ind-v0 eper-v0 ump-v0 our-v0 tary-v0 ban-v0 oku-v0 anoi-v0\nBa Black ptari enPu ozenL eNum Lights sterm eswe PegJ RushH Secre Soko\nSud erOfH\na Min\nFr ssTh\nM\nCry Fifte\nTow\nGue\nenv_id\n\n204\n\nFigure 4: Average reward of our method and Gemini-2.5-Pro for each of the 16 1P games.\n\n4.3\n\nHarness-as-Policy\n\nReward\n\nAs an extreme case, we consider learning the entire policy as code, dispensing with the need to use an LLM\nat test time. We evaluate this on 16 1P games (since it is much harder to learn an entire policy in code\nform for 2P games3 .) In addition to the above agents, we evaluate three new agents: GPT-5.2 (no thinking),\nGPT-5.2-High (high thinking) and Harness-as-Policy (ours). All agents are evaluated 20 times per game, as\nbefore, except for GPT-5.2 and GPT-5.2-High, which are repeated 10 and 5 times, for cost reasons.\n\n1.0\n0.8\n0.6\n0.4\n0.2\n0.0\n\n)\n-Pro\nlash\nurs\n5\n.\nO\n2\n(\nini\ness\nGem\narn\n\n-F\ni-2.5\n\nin\nGem\n\n)\nh\n-5.2\nurs\nHig\nO\n2\n(\n.\nGPT\n-5\nlicy\nGPT\n-Po\n\n+H\n\nHa\n\n.5\n\nni-2\ni\nm\ne\n\n-as\n\nss\nrne\n\nsh\n-Fla\n\nG\n\nAgent\n\nFigure 5: Average reward of different agents across 16 TextArena 1P games.\nFor training, we modify the heuristic value to include the reward. Specifially we set H = 0 if an illegal\naction is taken, and H = 0.5 + 0.5r otherwise, where r ∈ [0.0, 1.0] is the environment reward, which is only\navailable at the end of the trajectory (sparse reward setting). We train Harness-as-Policy using our code\nsynthesis method with Gemini-2.5-Flash to a maximum of 256 iterations. On average, training takes 89.4\niterations and achieves a heuristic value of 0.939.\nAs shown in Fig. 5, our approach achieves the highest average reward (0.870), outperforming all other\nagents including GPT-5.2 (0.635), Gemini-2.5-Pro (0.707), and GPT-5.2-High (0.844). Per game, we win\n3/16 games while GPT-5.2-High wins 5/16, and we tie the remaining 8/16 (details in the appendix). Since\nHarness-as-Policy generates pure (Python) code, our test time cost is nearly zero, while the GPT-5.2 and\nGPT-5.2-High experiments cost approximately $640.\n3 Two-player games require strategic reasoning about the opponent’s policy which often requires MCTS-like methods at run\ntime (see e.g., (Duan et al., 2024)). While in principle our code synthesis method could generate such a policy, it would also\nneed to learn a code world model to search over, as in (Lehrach et al., 2025), which is challenging for text games.\n\n5\n\n\f5\n\nConclusion and Future Work\n\nWe developed a novel approach for improving the performance of an LLM agent, based on automatically\nsynthesizing a code harness. Currently we generate a separate harness for each environment (game). In the\nfuture, we would like to distill the resulting domain specific experts (agents) back into the base LLM, so\nthat the whole system becomes recursively self-improving. We also hope to explore building up a library of\nreusable harnesses, and to apply our method to more challenging multimodal games, such as Craftax 4 and\nTerra Nova5 .\n\nReferences\nYuri Chervonyi, Trieu H Trinh, Miroslav Olšák, Xiaomeng Yang, Hoang H Nguyen, Marcelo Menegali,\nJunehyuk Jung, Junsu Kim, Vikas Verma, Quoc V Le, et al. Gold-medalist performance in solving\nolympiad geometry with alphageometry2. JMLR, 26(241):1–39, 2025.\nJinhao Duan, Renming Zhang, James Diffenderfer, Bhavya Kailkhura, Lichao Sun, Elias Stengel-Eskin,\nMohit Bansal, Tianlong Chen, and Kaidi Xu. GTBench: Uncovering the strategic reasoning limitations\nof LLMs via game-theoretic evaluations. arXiv [cs.CL], February 2024.\nLeon Guertler, Bobby Cheng, Simon Yu, Bo Liu, Leshem Choshen, and Cheston Tan. Textarena.\narXiv:2504.11442, 2025.\nYichen Huang and Lin F Yang. Winning gold at imo 2025 with a model-agnostic verification-and-refinement\npipeline. arXiv:2507.15855, 2025.\nKaggle. Kaggle game arena: A benchmarking platform for ai models. https://www.kaggle.com/\ngame-arena, 2025.\nHarsha Kokel, Michael Katz, Kavitha Srinivas, and Shirin Sohrabi. ACPBench hard: Unrestrained reasoning\nabout action, change, and planning. In AAAI 2025 Workshop LM4Plan, February 2025.\nWolfgang Lehrach, Daniel Hennes, Miguel Lazaro-Gredilla, Xinghua Lou, Carter Wendelken, Zun Li, Antoine\nDedieu, Jordi Grau-Moya, Marc Lanctot, Atil Iscen, et al. Code world models for general game playing.\narXiv:2510.04542, 2025.\nYujia Li, David Choi, Junyoung Chung, Nate Kushman, Julian Schrittwieser, Rémi Leblond, Tom Eccles,\nJames Keeling, Felix Gimeno, Agustin Dal Lago, et al. Competition-level code generation with alphacode.\nScience, 378(6624):1092–1097, 2022.\nJacky Liang, Wenlong Huang, Fei Xia, Peng Xu, Karol Hausman, Brian Ichter, Pete Florence, and Andy\nZeng. Code as policies: Language model programs for embodied control. In ICRA, pp. 9493–9500. IEEE,\n2023. doi: 10.1109/ICRA48891.2023.10160591.\nYecheng Jason Ma, William Liang, Guanzhi Wang, De-An Huang, Osbert Bastani, Dinesh Jayaraman, Yuke\nZhu, Linxi Fan, and Anima Anandkumar. Eureka: Human-level reward design via coding large language\nmodels. In ICLR, 2024.\nAlexander Novikov, Ngân Vũ, Marvin Eisenberger, Emilien Dupont, Po-Sen Huang, Adam Zsolt Wagner,\nSergey Shirobokov, Borislav Kozlovskii, Francisco JR Ruiz, Abbas Mehrabian, et al. Alphaevolve: A\ncoding agent for scientific and algorithmic discovery. arXiv:2506.13131, 2025.\nIvo Petrov, Jasper Dekoninck, Lyuben Baltadzhiev, Maria Drencheva, Kristian Minchev, Mislav Balunović,\nNikola Jovanović, and Martin Vechev. Proof or bluff? evaluating llms on 2025 usa math olympiad.\narXiv:2503.21934, 2025.\nAnian Ruoss, Fabio Pardo, Harris Chan, Bonnie Li, Volodymyr Mnih, and Tim Genewein. LMAct: A\nbenchmark for in-context imitation learning with long multimodal demonstrations. December 2024. URL\nhttp://arxiv.org/abs/2412.01441.\nNoah Shinn, Federico Cassano, Ashwin Gopinath, Karthik Narasimhan, and Shunyu Yao. Reflexion: Language agents with verbal reinforcement learning. NeurIPS, 36:8634–8652, 2023.\nHao Tang, Keya Hu, Jin Zhou, Si Cheng Zhong, Wei-Long Zheng, Xujie Si, and Kevin Ellis. Code repair\nwith llms gives an exploration-exploitation tradeoff. NeurIPS, 37:117954–117996, 2024.\n4 https://github.com/MichaelTMatthews/Craftax\n5 https://github.com/trevormcinroe/terra_nova/\n\n6\n\n\fKarthik Valmeekam, Matthew Marquez, Sarath Sreedharan, and Subbarao Kambhampati. On the planning\nabilities of large language models - a critical investigation. In NeurIPS, November 2023a.\nKarthik Valmeekam, Matthew Marquez, Sarath Sreedharan, and Subbarao Kambhampati. On the planning\nabilities of large language models-a critical investigation. NeurIPS, 36:75993–76005, 2023b.\nGuanzhi Wang, Yuqi Xie, Yunfan Jiang, Ajay Mandlekar, Chaowei Xiao, Yuke Zhu, Linxi Fan, and Anima\nAnandkumar. Voyager: An open-ended embodied agent with large language models. arXiv preprint\narXiv:2305.16291, 2023.\nJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Fei Xia, Ed Chi, Quoc V Le, Denny Zhou,\net al. Chain-of-thought prompting elicits reasoning in large language models. NeurIPS, 35:24824–24837,\n2022.\nShunyu Yao, Dian Yu, Jeffrey Zhao, Izhak Shafran, Tom Griffiths, Yuan Cao, and Karthik Narasimhan. Tree\nof thoughts: Deliberate problem solving with large language models. NeurIPS, 36:11809–11822, 2023.\n\n7\n\n\fA\n\nTextArena games\n\nA.1\n\nList of all 145 games\nTable 1: List of all 145 TextArena games, with accuracy of learned\nharness, and number of LLM calls needed to achieve this. The 32\ngames used for end-to-end agent eval are marked with *.\n\nIndex\n0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n\nGame\n2048-v0*\n2048-v0-easy\n2048-v0-extreme\n2048-v0-hard\n2048-v0-mega-easy\n2048-v0-super-easy\n2048-v0-ultra-easy\n2048-v0-very-easy\n2048-v0-very-hard\nAlquerque-v0*\nBandit-v0*\nBandit-v0-hard\nBattleship-v0\nBattleship-v0-extreme\nBattleship-v0-large\nBattleship-v0-standard\nBlackjack-v0*\nBlackjack-v0-long\nBreakthrough-v0*\nBreakthrough-v0-blind\nBreakthrough-v0-large\nBreakthrough-v0-long\nBreakthrough-v0-small\nBreakthrough-v0-tiny\nBriscola-v0\nCheckers-v0*\nCheckers-v0-long\nChess-v0*\nChess-v0-blind\nChess-v0-long\nChopsticks-v0*\nChopsticks-v0-long\nChopsticks-v0-medium\nColonelBlotto-v0\nColonelBlotto-v0-extreme\nColonelBlotto-v0-large\nColonelBlotto-v0-small\nConnectFour-v0\nConnectFour-v0-blind\nConnectFour-v0-large\nCrusade-v0*\nCryptarithm-v0*\nFifteenPuzzle-v0*\n\n# Players\n1\n1\n1\n1\n1\n1\n1\n1\n1\n2\n1\n1\n2\n2\n2\n2\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n1\n\n8\n\n# Learning Steps Legal Action Rate\n27\n1.0\n4\n1.0\n44\n1.0\n47\n1.0\n31\n1.0\n6\n1.0\n2\n1.0\n57\n1.0\n7\n1.0\n4\n1.0\n2\n1.0\n1\n1.0\n4\n1.0\n32\n1.0\n9\n1.0\n6\n1.0\n2\n1.0\n1\n1.0\n2\n1.0\n20\n1.0\n9\n1.0\n7\n1.0\n136\n1.0\n5\n1.0\n2\n1.0\n7\n1.0\n3\n1.0\n64\n1.0\n19\n1.0\n16\n1.0\n15\n1.0\n7\n1.0\n15\n1.0\n1\n1.0\n1\n1.0\n1\n1.0\n1\n1.0\n10\n1.0\n2\n1.0\n1\n1.0\n4\n1.0\n45\n1.0\n3\n1.0\nContinued on next page\n\n\fIndex\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n\nTable 1 – continued from previous page\nGame\n# Players # Learning Steps Legal Action Rate\nFrozenLake-v0*\n1\n19\n1.0\nFrozenLake-v0-hardcore\n1\n4\n1.0\nFrozenLake-v0-random\n1\n22\n1.0\nGameOfPureStrategy-v0\n2\n3\n1.0\nGermanWhist-v0*\n2\n43\n1.0\nGolf-v0*\n2\n8\n1.0\nGolf-v0-medium\n2\n9\n1.0\nGuessTheNumber-v0*\n1\n2\n1.0\nGuessTheNumber-v0-hardcore\n1\n2\n1.0\nHighSociety-v0\n2\n3\n1.0\nIndianPoker-v0\n2\n11\n1.0\nIndianPoker-v0-extreme\n2\n2\n1.0\nIndianPoker-v0-long\n2\n26\n1.0\nIndianPoker-v0-medium\n2\n7\n1.0\nIndianPoker-v0-short\n2\n2\n1.0\nIteratedMatchingPennies-v0\n2\n1\n1.0\nIteratedRockPaperScissors-v0\n2\n1\n1.0\nIteratedTwoThirdsAverage-v0\n2\n1\n1.0\nKuhnPoker-v0\n2\n5\n1.0\nKuhnPoker-v0-extreme\n2\n3\n1.0\nKuhnPoker-v0-long\n2\n2\n1.0\nKuhnPoker-v0-medium\n2\n2\n1.0\nKuhnPoker-v0-short\n2\n3\n1.0\nLiarsDice-v0*\n2\n4\n1.0\nLiarsDice-v0-large\n2\n6\n1.0\nLiarsDice-v0-small\n2\n5\n1.0\nLightsOut-v0*\n1\n1\n1.0\nLinesOfAction-v0*\n2\n23\n1.0\nMastermind-v0*\n1\n2\n1.0\nMastermind-v0-extreme\n1\n1\n1.0\nMastermind-v0-hard\n1\n2\n1.0\nMemoryGame-v0\n2\n3\n1.0\nMemoryGame-v0-hard\n2\n2\n1.0\nMemoryGame-v0-medium\n2\n2\n1.0\nMinesweeper-v0*\n1\n11\n1.0\nMinesweeper-v0-hard\n1\n6\n1.0\nMinesweeper-v0-medium\n1\n10\n1.0\nMinesweeper-v0-small\n1\n2\n1.0\nNewRecruit-v0*\n2\n2\n1.0\nNim-v0\n2\n1\n1.0\nNim-v0-large\n2\n2\n1.0\nNim-v0-medium\n2\n2\n1.0\nOthello-v0*\n2\n62\n1.0\nOthello-v0-big\n2\n2\n1.0\nOthello-v0-hard\n2\n30\n1.0\nOthello-v0-huge\n2\n12\n1.0\nOthello-v0-small\n2\n5\n1.0\nOthello-v0-tiny\n2\n13\n1.0\nPegJump-v0*\n1\n1\n1.0\nPigDice-v0\n2\n1\n1.0\nPigDice-v0-100\n2\n1\n1.0\nContinued on next page\n\n9\n\n\fIndex\n94\n95\n96\n97\n98\n99\n100\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n\nTable 1 – continued from previous page\nGame\n# Players # Learning Steps\nPigDice-v0-150\n2\n1\nPigDice-v0-200\n2\n1\nPigDice-v0-250\n2\n1\nPigDice-v0-300\n2\n1\nPigDice-v0-350\n2\n1\nPigDice-v0-400\n2\n1\nPigDice-v0-450\n2\n1\nPigDice-v0-50\n2\n1\nPigDice-v0-500\n2\n1\nPigDice-v0-long\n2\n1\nPigDice-v0-short\n2\n1\nPoker-v0\n2\n17\nPoker-v0-extreme\n2\n7\nPoker-v0-long\n2\n5\nPoker-v0-small\n2\n29\nQuantumTicTacToe-v0\n2\n12\nReverseTicTacToe-v0\n2\n3\nRushHour-v0*\n1\n3\nSantoriniBaseFixed-v0\n2\n30\nSecretary-v0*\n1\n1\nSecretary-v0-long\n1\n1\nSimpleTak-v0\n2\n4\nSimpleTak-v0-extreme\n2\n8\nSimpleTak-v0-large\n2\n12\nSimpleTak-v0-medium\n2\n5\nSnake-v0\n2\n1\nSnake-v0-large\n2\n1\nSnake-v0-standard\n2\n1\nSokoban-v0*\n1\n5\nSokoban-v0-medium\n1\n1\nSpiteAndMalice-v0*\n2\n33\nStratego-v0*\n2\n23\nSudoku-v0*\n1\n5\nSudoku-v0-easy\n1\n5\nSudoku-v0-hard\n1\n9\nSudoku-v0-medium\n1\n4\nSudoku-v0-very-easy\n1\n4\nSurround-v0\n2\n1\nSurround-v0-large\n2\n1\nSurround-v0-standard\n2\n1\nTak-v0*\n2\n21\nTak-v0-hard\n2\n53\nTak-v0-medium\n2\n6\nTicTacToe-v0\n2\n4\nTowerOfHanoi-v0*\n1\n7\nTowerOfHanoi-v0-extreme\n1\n44\nTowerOfHanoi-v0-hard\n1\n7\nTowerOfHanoi-v0-hardcore\n1\n2\nTowerOfHanoi-v0-medium\n1\n7\nUltimateTicTacToe-v0*\n2\n13\nWildTicTacToe-v0\n2\n10\n\n10\n\nLegal Action Rate\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n1.0\n\n\fA.2\n\nPer-game reward\n\nFigure 6: TextArena 1P per-game reward.\n\nA.3\n\nPer-game Legal Action Rate\n\nFigure 7: TextArena 1P per-game legal action success rate.\n\nA.4\n\nExample game: Chess-v0\n\nIn this section, we illustrate how we remove the list of legal actions from the observation.\nA.4.1\n\nOriginal Chess-v0 observation\n\n11\n\n\f[GAME] You are playing White in a game of Chess.\nMake your moves in UCI format enclosed in square brackets (e.g., [e2e4]).\n[GAME] Current board:\n+-----------------+\n8 | r n b q k b n r |\n7 | p p p p p p p p |\n6 | . . . . . . . . |\n5 | . . . . . . . . |\n4 | . . . . . . . . |\n3 | . . . . . . . . |\n2 | P P P P P P P P |\n1 | R N B Q K B N R |\n+-----------------+\na b c d e f g h\nValid moves: [g1h3], [g1f3], [b1c3], [b1a3], [h2h3], [g2g3], [f2f3], [e2e3], [d2d3], [c2c3], [b2b3\n], [a2a3], [h2h4], [g2g4], [f2f4], [e2e4], [d2d4], [c2c4], [b2b4], [a2a4]\n\nA.5\n\nModified Chess-v0 observation with “valid moves” removed\n\n[GAME] You are playing White in a game of Chess.\nMake your moves in UCI format enclosed in square brackets (e.g., [e2e4]).\n[GAME] Current board:\n+-----------------+\n8 | r n b q k b n r |\n7 | p p p p p p p p |\n6 | . . . . . . . . |\n5 | . . . . . . . . |\n4 | . . . . . . . . |\n3 | . . . . . . . . |\n2 | P P P P P P P P |\n1 | R N B Q K B N R |\n+-----------------+\na b c d e f g h\n\nB\n\nPrompts\n\nB.1\n\nLLM-as-policy prompt\n\nYou are an expert, logical, and strategic AI game player. Your task is to analyze the following\ngame information and determine the single best move to make.\nRead the game rules, your player role, the current game state, and all available moves carefully.\nYour objective is to play optimally to maximize your chances of winning the game.\nYou are now player {player_id}.\nThe game information is as follows:\n{observation}\n**YOUR TASK:**\nYou must now analyze the situation and provide your move. Follow these two steps precisely.\n**Step 1: Think**\nFirst, provide your step-by-step reasoning. Analyze the current game state, your goal, and the\navailable moves. Evaluate the pros and cons of the most promising options and explain why you are\nselecting your final move.\n\n12\n\n\f**Step 2: Move**\nAfter your thinking block, provide *only* the single best move you have chosen. The move must be\none of the valid moves listed in the game information.\nEnclose your final move in `&lt;move&gt;&lt;/move&gt;` tags. Do not add any other text, explanation, or\npunctuation after the closing `&lt;/move&gt;` tag.\nExample of a correct response format:\n&lt;move&gt;\n[Your chosen move]\n&lt;/move&gt;\n\nB.2\n\nCode Refinement Prompt\n\nYou are a python programmer with expertise in text games.\nYou are given a text game with the following name: {name}\nHere is a description of the game.\n{description}\nHere is a description of the action space of the game.\n{action_space}\nYou are observing the following game boards as text with error feedback.\n{tasks_with_feedback}\nYour task is to write or refine the following python functions.\n```python\n{code}\n```\nMake sure to follow these function signatures.\n```python\n{code_signatures}\n```\nMake sure to follow these instructions.\n* Think step by step about the code, the game boards and the error feedback.\n* Reason about each action through the game board and write down critical failure steps.\n* Reason about code refinements that can help fix the failure steps.\n* Reason about the entire sequence of actions and write down the progress of the game as a value\nbetween 0 and 1.\n* Reason about code refinements that can help improve the game progress.\n* Reason about code refinements that can avoid running in loops.\n* Write down your thoughts before writing the code.\n* Make sure to follow the given function signatures.\n* Make sure the new code can satisfy all the observed game boards.\n\n13\n\n\f* Make sure the new code can fix all the current errors.\n* Make sure to only produce code that is safe to execute.\n* Make sure the code is concise and precise.\n* If necessary, randomply sample one of the best legal actions and return it as the proposed action\n.\n* Do not use any the try-except blocks.\n* Write your functions in a python code block enclosed in ```python\n\nC\n\nHarness Function Signatures\n\nC.1\n\nCode-as-action-verifier\n\ndef propose_action(board: str) -&gt; str:\n\"\"\"Propose a valid random action given the game board as text\nArgs:\nboard (str): Game board as text.\nReturns:\nstr: A valid random action as string.\nRaises:\nException: If fail to propose a valid random action.\n\"\"\"\nraise NotImplementedError()\ndef is_legal_action(board: str, action: str) -&gt; bool:\n\"\"\"Check if an action string is valid given the game board as text\nArgs:\nboard (str): Game board as text.\naction (str): Input action as string.\nReturns:\nbool: If the input action string is valid.\nRaises:\nException: If fail to check if the action string is valid.\n\"\"\"\nraise NotImplementedError()\n\nC.2\n\nHarness-as-policy\n\nWe use the same function signatures as above, except the docstring of propose_action():\nPropose one of the best legal actions given the game board as text such that the final reward is\nmaximized.\n\n14\n\n\fD\n\nSample Harness Code Snippets\n\nD.1\n\nMinesweeper-v0\n\nThe propose_action() code snippet for Minesweeper-v0 breaks down the strategy by checking the first\nmove, finding guaranteed safe cells by logic deduction, and applying probabilistic heuristic for best guesses.\nNot that not the whole code harness is shown here.\ndef propose_action(board: str) -&gt; str:\n\"\"\"Propose one of the best legal actions given the game board as text such that the final reward\nis maximized.\nArgs:\nboard (str): Game board as text.\nReturns:\nstr: A string representing one of the best legal actions.\nRaises:\nException: If fail to propose any legal action.\n\"\"\"\ngrid = parse_board_to_grid(board)\nif not grid:\nraise Exception(\"Failed to parse the board or board is empty, cannot propose an action.\")\nnum_rows, num_cols = get_board_dimensions(grid)\nif num_rows == 0 or num_cols == 0:\nraise Exception(\"Board dimensions are zero, cannot propose an action.\")\n# Check if this is the very first move (all cells are unrevealed)\nall_cells_unrevealed = True\nfor r_check in range(num_rows):\nfor c_check in range(num_cols):\nif grid[r_check][c_check] != '.':\nall_cells_unrevealed = False\nbreak\nif not all_cells_unrevealed:\nbreak\n# Strategy 1: First move (if all cells are unrevealed)\n# Pick a central cell to maximize the initial revealed area for a safe start.\nif all_cells_unrevealed:\n# For an 8x8 board, (3,3) is a common safe starting point.\nfirst_move_row = num_rows // 2 - (1 if num_rows % 2 == 0 and num_rows // 2 &gt; 0 else 0)\nfirst_move_col = num_cols // 2 - (1 if num_cols % 2 == 0 and num_cols // 2 &gt; 0 else 0)\nreturn f\"[{first_move_row} {first_move_col}]\"\n# Strategy 2: Logic Deduction for Guaranteed Safe Cells and Mines\n# board_mines stores: True for known mine, False for known safe, None for unknown.\nboard_mines: list[list[bool | None]] = [[None for _ in range(num_cols)] for _ in range(num_rows)]\n# Initialize board_mines based on currently revealed cells\nfor r in range(num_rows):\nfor c in range(num_cols):\nif grid[r][c].isdigit():\n# Revealed cells are definitely not mines.\nboard_mines[r][c] = False\n# Unrevealed cells '.' are initially None (unknown)\n\n15\n\n\fsafe_to_reveal: list[tuple[int, int]] = [] # Cells that are deduced to be safe to click\nsafe_cells_set = set() # Use a set to track already added safe cells to avoid duplicates\n# Propagate deductions multiple times until no new deductions are made\nmax_deduction_iterations = num_rows * num_cols # Safety limit to ensure termination\nfor _ in range(max_deduction_iterations):\nnew_deductions_made_this_iteration = False # Track deductions per iteration\n# --- Simple Deduction Rules (Rule A &amp; B) --for r in range(num_rows):\nfor c in range(num_cols):\nif grid[r][c].isdigit():\nN = int(grid[r][c])\nunrevealed_unknown_neighbors = [] # Neighbors that are '.' and NOT yet marked as\nmine/safe (None in board_mines)\nknown_mine_neighbors_count = 0\nfor dr in [-1, 0, 1]:\nfor dc in [-1, 0, 1]:\nif dr == 0 and dc == 0:\ncontinue\nnr, nc = r + dr, c + dc\nif 0 &lt;= nr &lt; num_rows and 0 &lt;= nc &lt; num_cols:\nif board_mines[nr][nc] is True:\nknown_mine_neighbors_count += 1\nelif grid[nr][nc] == '.' and board_mines[nr][nc] is None:\nunrevealed_unknown_neighbors.append((nr, nc))\nnum_unrevealed_and_unknown = len(unrevealed_unknown_neighbors)\nmines_to_deduce = N - known_mine_neighbors_count\n# Rule A: Deduce Mines\n# If (clue N - known_mine_neighbors_count) equals the number of unrevealed and\nunknown neighbors,\n# then all these unrevealed and unknown neighbors must be mines.\nif mines_to_deduce &gt; 0 and mines_to_deduce == num_unrevealed_and_unknown:\nfor (ur, uc) in unrevealed_unknown_neighbors:\nif board_mines[ur][uc] is None: # Only mark if not already marked\nboard_mines[ur][uc] = True\nnew_deductions_made_this_iteration = True\n# Rule B: Deduce Safe Cells\n# If clue N equals the number of known mine neighbors,\n# then all other unrevealed and unknown neighbors must be safe.\nelif mines_to_deduce == 0 and num_unrevealed_and_unknown &gt; 0:\nfor (ur, uc) in unrevealed_unknown_neighbors:\nif board_mines[ur][uc] is None: # Only mark if not already marked\nboard_mines[ur][uc] = False # Mark as safe\nif (ur, uc) not in safe_cells_set: # Add to safe list only if new\nsafe_to_reveal.append((ur, uc))\nsafe_cells_set.add((ur, uc))\nnew_deductions_made_this_iteration = True\n# --- Advanced Deduction Rules (Subset Rule) --# Collect all clue constraints that have unknown neighbors\nclue_constraints = [] # List of (mines_needed, set_of_unknown_neighbors)\nfor r_clue in range(num_rows):\n\n16\n\n\ffor c_clue in range(num_cols):\nif grid[r_clue][c_clue].isdigit():\nN_clue = int(grid[r_clue][c_clue])\nunknown_neighbors_set = set()\nknown_mines_around_clue = 0\nfor dr_clue in [-1, 0, 1]:\nfor dc_clue in [-1, 0, 1]:\nif dr_clue == 0 and dc_clue == 0:\ncontinue\nnr_clue, nc_clue = r_clue + dr_clue, c_clue + dc_clue\nif 0 &lt;= nr_clue &lt; num_rows and 0 &lt;= nc_clue &lt; num_cols:\nif board_mines[nr_clue][nc_clue] is True:\nknown_mines_around_clue += 1\nelif grid[nr_clue][nc_clue] == '.' and board_mines[nr_clue][nc_clue] is\nNone:\nunknown_neighbors_set.add((nr_clue, nc_clue))\nmines_needed = N_clue - known_mines_around_clue\n# Only add valid constraints where mines_needed is positive and there are unknown\ncells to consider.\n# If mines_needed &lt;= 0, Rule B (safe cells) would have already covered it or it\nmeans too many mines are already identified.\nif mines_needed &gt; 0 and unknown_neighbors_set:\nclue_constraints.append((mines_needed, unknown_neighbors_set))\n# Apply subset rule to all pairs of clue constraints\nfor i in range(len(clue_constraints)):\nfor j in range(len(clue_constraints)):\nif i == j: # Don't compare a constraint with itself\ncontinue\nnm1, s1 = clue_constraints[i] # mines_needed_1, set_of_unknown_neighbors_1\nnm2, s2 = clue_constraints[j] # mines_needed_2, set_of_unknown_neighbors_2\nif s1.issubset(s2) and s1 != s2: # If s1 is a proper subset of s2\ns_diff = s2 - s1 # Cells in s2 but not in s1\nnm_diff = nm2 - nm1 # Difference in needed mines\nif nm_diff == 0 and s_diff: # If difference in mines is 0, then s_diff cells must\nbe safe\nfor (sr, sc) in s_diff:\nif board_mines[sr][sc] is None:\nboard_mines[sr][sc] = False\nif (sr, sc) not in safe_cells_set:\nsafe_to_reveal.append((sr, sc))\nsafe_cells_set.add((sr, sc))\nnew_deductions_made_this_iteration = True\nelif nm_diff == len(s_diff) and s_diff: # If difference in mines equals number of\ncells in s_diff, they are all mines\nfor (sr, sc) in s_diff:\nif board_mines[sr][sc] is None:\nboard_mines[sr][sc] = True\nnew_deductions_made_this_iteration = True\nif not new_deductions_made_this_iteration:\nbreak # No new deductions this iteration (neither simple nor advanced), stop propagating\n# If guaranteed safe cells are found, choose one randomly.\n\n17\n\n\fif safe_to_reveal:\nchosen_move = random.choice(safe_to_reveal)\nreturn f\"[{chosen_move[0]} {chosen_move[1]}]\"\n# Strategy 3: Probabilistic Heuristic for Best Guess (when no guaranteed safe cells are found)\npotential_moves_with_risks = [] # Stores (risk_score, row, col)\ntotal_unrevealed_unknown_dots = 0\nidentified_mines_count = 0\nfor r in range(num_rows):\nfor c in range(num_cols):\nif board_mines[r][c] is True:\nidentified_mines_count += 1\nelif grid[r][c] == '.' and board_mines[r][c] is None:\ntotal_unrevealed_unknown_dots += 1\n# Assuming a standard 8x8 Minesweeper board has 10 mines. This is a common setup.\ntotal_mines_on_board = 10\nglobal_mine_prob = 0.0\nif total_unrevealed_unknown_dots &gt; 0:\nremaining_mines_to_place = max(0, total_mines_on_board - identified_mines_count)\nglobal_mine_prob = remaining_mines_to_place / total_unrevealed_unknown_dots\n# Clamp global probability between 0 and 1\nglobal_mine_prob = max(0.0, min(1.0, global_mine_prob))\n# Iterate over all unrevealed cells that are not known mines to calculate risk scores\nfor r in range(num_rows):\nfor c in range(num_cols):\n# Only consider truly unknown cells ('.') for guessing that are not marked as mines\nif grid[r][c] == '.' and board_mines[r][c] is None:\ncurrent_cell_risk_sum = 0.0\nnum_adjacent_clues_influencing = 0\n# Analyze neighbors of the candidate cell (r, c)\nfor dr_adj in [-1, 0, 1]:\nfor dc_adj in [-1, 0, 1]:\nif dr_adj == 0 and dc_adj == 0:\ncontinue\nnr_adj, nc_adj = r + dr_adj, c + dc_adj\nif 0 &lt;= nr_adj &lt; num_rows and 0 &lt;= nc_adj &lt; num_cols:\nif grid[nr_adj][nc_adj].isdigit(): # If adjacent to a revealed clue\nnum_adjacent_clues_influencing += 1\nN_clue = int(grid[nr_adj][nc_adj])\nmines_around_clue = 0\nunknown_around_clue_for_clue = 0 # Unknown neighbors specifically for\nTHIS clue's context\nfor dr_sub in [-1, 0, 1]:\nfor dc_sub in [-1, 0, 1]:\nif dr_sub == 0 and dc_sub == 0:\ncontinue\nsnr, snc = nr_adj + dr_sub, nc_adj + dc_sub\nif 0 &lt;= snr &lt; num_rows and 0 &lt;= snc &lt; num_cols:\nif board_mines[snr][snc] is True:\nmines_around_clue += 1\n\n18\n\n\felif grid[snr][snc] == '.' and board_mines[snr][snc] is None:\nunknown_around_clue_for_clue += 1\nremaining_mines_for_clue = N_clue - mines_around_clue\nif unknown_around_clue_for_clue &gt; 0:\n# Probability of an unknown cell being a mine given this clue\nprob_from_clue = max(0.0, min(1.0, remaining_mines_for_clue /\nunknown_around_clue_for_clue))\ncurrent_cell_risk_sum += prob_from_clue\nif num_adjacent_clues_influencing &gt; 0:\n# Average the probabilities from all influencing clues\ncurrent_risk_score = current_cell_risk_sum / num_adjacent_clues_influencing\nelse: # If the candidate cell is isolated from any revealed numbers, use global\nprobability\ncurrent_risk_score = global_mine_prob\npotential_moves_with_risks.append((current_risk_score, r, c))\n# Select the move(s) with the minimum risk score\nif potential_moves_with_risks:\n# Find the minimum risk score among all potential moves\nmin_risk_score = float('inf')\nfor risk, _, _ in potential_moves_with_risks:\nmin_risk_score = min(min_risk_score, risk)\n# Collect all moves that have this minimum risk score\nbest_moves = [(r, c) for risk, r, c in potential_moves_with_risks if risk == min_risk_score]\nif best_moves:\n# Randomly choose one of the best (lowest risk) moves\nchosen_move = random.choice(best_moves)\nreturn f\"[{chosen_move[0]} {chosen_move[1]}]\"\n# Final Fallback: If no moves passed the filters (e.g., all remaining cells are considered mines,\n# or no logically safe/guessable moves were found from the current state),\n# but there are still unrevealed cells, pick one randomly from truly unknown cells.\nunrevealed_cells_remaining = []\nfor r in range(num_rows):\nfor c in range(num_cols):\nif grid[r][c] == '.':\n# Only pick truly unrevealed cells that are not yet marked as mines (is None)\nif board_mines[r][c] is None:\nunrevealed_cells_remaining.append((r,c))\nif unrevealed_cells_remaining:\nchosen_move = random.choice(unrevealed_cells_remaining)\nreturn f\"[{chosen_move[0]} {chosen_move[1]}]\"\nraise Exception(\"No legal actions can be proposed. All non-mine cells might be revealed or no\nsafe/guessable moves found.\")\n\nD.2\n\nChess-v0\n\nInteresting code snippets for Chess-v0 including Universal Chess Interface (UCI) parsing and formatting,\npiece localizing and attack checking. Note that not the whole code harness is shown here.\ndef _to_uci_coord(row: int, col: int) -&gt; str:\n\n19\n\n\f\"\"\"Converts 0-indexed grid coordinates (row, col) to UCI string (e.g., 'e2').\"\"\"\nfile_char = chr(ord('a') + col)\nrank_char = str(8 - row) # Grid row 0 is rank 8, grid row 7 is rank 1\nreturn file_char + rank_char\ndef _from_uci_coord(coord_str: str) -&gt; tuple[int, int] | None:\n\"\"\"Converts UCI string (e.g., 'e2') to 0-indexed grid coordinates (row, col). Returns None on\ninvalid input.\"\"\"\nif not (len(coord_str) == 2 and 'a' &lt;= coord_str[0] &lt;= 'h' and '1' &lt;= coord_str[1] &lt;= '8'):\nreturn None\ncol = ord(coord_str[0]) - ord('a')\nrow = 8 - int(coord_str[1]) # Rank 8 is grid row 0, rank 1 is grid row 7\nreturn row, col\ndef _find_king(grid: list[list[str]], king_color: str) -&gt; tuple[int, int] | None:\n\"\"\"Finds the coordinates of the king of the specified color.\"\"\"\nfor r in range(8):\nfor c in range(8):\npiece = grid[r][c]\nif (king_color == 'w' and piece == 'K') or \\\n(king_color == 'b' and piece == 'k'):\nreturn r, c\nreturn None # King not found (should ideally not happen in a valid game state)\ndef _is_square_attacked(grid: list[list[str]], r: int, c: int, by_white: bool) -&gt; bool:\n\"\"\"Checks if square (r, c) is attacked by any piece of the color 'by_white' (True for White,\nFalse for Black).\"\"\"\n# Helper to check if a piece at (pr, pc) is of the attacking_color\ndef is_attacker(piece_sym: str, is_white_attacker: bool) -&gt; bool:\nif piece_sym == '.': return False\nreturn (is_white_attacker and piece_sym.isupper()) or \\\n(not is_white_attacker and piece_sym.islower())\n# 1. Pawn attacks (diagonal 1 step)\n# If checking attack *by* White, White pawns attack \"up\" (decreasing row index). So a white\npawn attacking (r,c) would be at (r+1, c-1) or (r+1, c+1).\n# If checking attack *by* Black, Black pawns attack \"down\" (increasing row index). So a black\npawn attacking (r,c) would be at (r-1, c-1) or (r-1, c+1).\npawn_attacker_dr_from_target = 1 if by_white else -1\nfor dc_pawn in [-1, 1]:\npr, pc = r + pawn_attacker_dr_from_target, c + dc_pawn\nif 0 &lt;= pr &lt; 8 and 0 &lt;= pc &lt; 8 and grid[pr][pc].upper() == 'P':\nif is_attacker(grid[pr][pc], by_white):\nreturn True\n# 2. Knight attacks (L-shape)\nknight_moves_deltas = [(-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)]\nfor dr_k, dc_k in knight_moves_deltas:\nkr, kc = r + dr_k, c + dc_k\nif 0 &lt;= kr &lt; 8 and 0 &lt;= kc &lt; 8 and grid[kr][kc].upper() == 'N':\nif is_attacker(grid[kr][kc], by_white):\nreturn True\n# 3. King attacks (1 step in any direction)\n# A king cannot move into a square attacked by another king, but for simplicity of check\ndetection, we consider a king's direct vicinity as attacked by an opposing king.\nfor dr_k, dc_k in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]:\nkr, kc = r + dr_k, c + dc_k\n\n20\n\n\fif 0 &lt;= kr &lt; 8 and 0 &lt;= kc &lt; 8 and grid[kr][kc].upper() == 'K':\nif is_attacker(grid[kr][kc], by_white):\nreturn True\n# 4. Rook/Queen attacks (straight lines)\nstraight_directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] # Up, Down, Left, Right\nfor dr_s, dc_s in straight_directions:\nfor step in range(1, 8):\nsr, sc = r + dr_s * step, c + dc_s * step\nif not (0 &lt;= sr &lt; 8 and 0 &lt;= sc &lt; 8): break # Out of bounds\npiece_at_sr_sc = grid[sr][sc]\nif piece_at_sr_sc == '.': continue # Path clear\nif is_attacker(piece_at_sr_sc, by_white) and \\\n(piece_at_sr_sc.upper() == 'R' or piece_at_sr_sc.upper() == 'Q'):\nreturn True\nelse:\nbreak # Blocking piece is not an attacker or is own piece, or another piece\n# 5. Bishop/Queen attacks (diagonal lines)\ndiagonal_directions = [(-1, -1), (-1, 1), (1, -1), (1, 1)] # Up-Left, Up-Right, Down-Left, Down\n-Right\nfor dr_d, dc_d in diagonal_directions:\nfor step in range(1, 8):\nsr, sc = r + dr_d * step, c + dc_d * step\nif not (0 &lt;= sr &lt; 8 and 0 &lt;= sc &lt; 8): break # Out of bounds\npiece_at_sr_sc = grid[sr][sc]\nif piece_at_sr_sc == '.': continue # Path clear\nif is_attacker(piece_at_sr_sc, by_white) and \\\n(piece_at_sr_sc.upper() == 'B' or piece_at_sr_sc.upper() == 'Q'):\nreturn True\nelse:\nbreak # Blocking piece is not an attacker or is own piece, or another piece\nreturn False\n\n21\n\n\f</code></pre></article>\n        \n</main>\n\n<script src=\"https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.js\"></script>\n<script src=\"https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/contrib/auto-render.min.js\"></script>\n<script>\n\nfunction initTheme() {\n  const saved = localStorage.getItem('kb-theme') || 'light';\n  document.documentElement.setAttribute('data-theme', saved);\n  updateThemeIcon(saved);\n}\nfunction toggleTheme() {\n  const cur = document.documentElement.getAttribute('data-theme') || 'light';\n  const next = cur === 'light' ? 'dark' : 'light';\n  document.documentElement.setAttribute('data-theme', next);\n  localStorage.setItem('kb-theme', next);\n  updateThemeIcon(next);\n}\nfunction updateThemeIcon(t) {\n  const btn = document.getElementById('theme-toggle-btn');\n  if (btn) btn.innerHTML = t === 'dark' ? '☀️' : '🌙';\n}\ndocument.addEventListener('DOMContentLoaded', initTheme);\n\nfunction setViewMode(m) {\n  const grid = document.getElementById('bento-grid-view');\n  const list = document.getElementById('list-table-view');\n  const bGrid = document.getElementById('view-grid-btn');\n  const bList = document.getElementById('view-list-btn');\n  if (m === 'list') {\n    if (grid) grid.style.display = 'none';\n    if (list) list.style.display = 'flex';\n    if (bGrid) bGrid.classList.remove('active');\n    if (bList) bList.classList.add('active');\n  } else {\n    if (grid) grid.style.display = 'grid';\n    if (list) list.style.display = 'none';\n    if (bGrid) bGrid.classList.add('active');\n    if (bList) bList.classList.remove('active');\n  }\n  localStorage.setItem('kb-view', m);\n}\ndocument.addEventListener('DOMContentLoaded', () => {\n  const s = localStorage.getItem('kb-view') || 'grid';\n  setViewMode(s);\n});\n\ndocument.addEventListener('DOMContentLoaded', () => {\n  document.querySelectorAll('pre').forEach(pre => {\n    const b = document.createElement('button');\n    b.className = 'copy-code-btn';\n    b.innerText = 'Copy';\n    b.onclick = () => {\n      const c = pre.querySelector('code') ? pre.querySelector('code').innerText : pre.innerText;\n      navigator.clipboard.writeText(c).then(() => {\n        b.innerText = 'Copied!';\n        setTimeout(() => { b.innerText = 'Copy'; }, 2000);\n      });\n    };\n    pre.appendChild(b);\n  });\n});\n\nwindow.addEventListener('keydown', (e) => {\n  if ((e.key === '/' || (e.metaKey && e.key === 'k')) && document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA') {\n    e.preventDefault();\n    const q = document.getElementById('global-search-input');\n    if (q) q.focus();\n  }\n});\n\n// Scrollspy for TOC\nwindow.addEventListener('scroll', () => {\n  const headers = document.querySelectorAll('.article-body h1, .article-body h2, .article-body h3');\n  const scrollPos = window.scrollY + 100;\n  headers.forEach(h => {\n    if (h.offsetTop <= scrollPos) {\n      const id = h.getAttribute('id');\n      if (id) {\n        document.querySelectorAll('.reading-sidebar a').forEach(a => {\n          a.classList.toggle('active', a.getAttribute('href') === '#' + id);\n        });\n      }\n    }\n  });\n});\n\ndocument.addEventListener(\"DOMContentLoaded\", function() {\n  if (window.renderMathInElement) {\n    renderMathInElement(document.body, {\n      delimiters: [\n        {left: '$$', right: '$$', display: true},\n        {left: '$', right: '$', display: false},\n      ],\n      throwOnError : false\n    });\n  }\n});\n</script>\n\n</body>\n</html>\n"