Skip to content

Turn any AI agent into an AI Scientist. The #1 Agent Skills library for science, used by 250,000+ scientists worldwide. 177 ready-to-use validated skills plus 100+ scientific databases covering biology, chemistry, medicine, and drug discovery. Compatible with Cursor, Claude Code, Codex, Pi, Antigravity, and the open Agent Skills standard.

Add arbor skill

Timothy Kassis9c12fcc25efb
diff --git a/README.md b/README.md
index 9a8c27d8..d101ed99 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.md)
[![Version](https://img.shields.io/badge/Version-2.50.0-blue.svg)](pyproject.toml)
-[![Skills](https://img.shields.io/badge/Skills-146-brightgreen.svg)](#-whats-included)
+[![Skills](https://img.shields.io/badge/Skills-147-brightgreen.svg)](#-whats-included)
[![Databases](https://img.shields.io/badge/Databases-100%2B-orange.svg)](#-whats-included)
[![Agent Skills](https://img.shields.io/badge/Standard-Agent_Skills-blueviolet.svg)](https://agentskills.io/)
[![Security Scan](https://github.com/K-Dense-AI/scientific-agent-skills/actions/workflows/security-scan.yml/badge.svg)](https://github.com/K-Dense-AI/scientific-agent-skills/actions/workflows/security-scan.yml)
@@ -17,11 +17,11 @@
> **🔔 Claude Scientific Skills is now Scientific Agent Skills.** Same skills, broader compatibility — now works with any AI agent that supports the open [Agent Skills](https://agentskills.io/) standard, not just Claude.
-> **New: [K-Dense BYOK](https://github.com/K-Dense-AI/k-dense-byok)** — A free, open-source AI co-scientist that runs on your desktop, powered by Scientific Agent Skills. Bring your own API keys, pick from 40+ models, and get a full research workspace with web search, file handling, 100+ scientific databases, and access to all 146 skills in this repo. Your data stays on your computer, and you can optionally scale to cloud compute via [Modal](https://modal.com/) for heavy workloads. [Get started here.](https://github.com/K-Dense-AI/k-dense-byok)
+> **New: [K-Dense BYOK](https://github.com/K-Dense-AI/k-dense-byok)** — A free, open-source AI co-scientist that runs on your desktop, powered by Scientific Agent Skills. Bring your own API keys, pick from 40+ models, and get a full research workspace with web search, file handling, 100+ scientific databases, and access to all 147 skills in this repo. Your data stays on your computer, and you can optionally scale to cloud compute via [Modal](https://modal.com/) for heavy workloads. [Get started here.](https://github.com/K-Dense-AI/k-dense-byok)
> **Stay up to date:** Follow K-Dense on [X](https://x.com/k_dense_ai), [LinkedIn](https://www.linkedin.com/company/k-dense-inc), and [YouTube](https://www.youtube.com/@K-Dense-Inc) for new skills, release announcements, walkthroughs, research workflow demos, and examples you can use with your own AI agent.
-A comprehensive collection of **146 ready-to-use scientific and research skills** (covering cancer genomics, drug-target binding, molecular dynamics, RNA velocity, geospatial science, time series forecasting, scientific ML resource discovery via Hugging Science, 78+ scientific databases, and more) for any AI agent that supports the open [Agent Skills](https://agentskills.io/) standard, created by [K-Dense](https://k-dense.ai). Works with **Cursor, Claude Code, Codex, Google Antigravity, and more**. Transform your AI agent into a research assistant capable of executing complex multi-step scientific workflows across biology, chemistry, medicine, and beyond.
+A comprehensive collection of **147 ready-to-use scientific and research skills** (covering cancer genomics, drug-target binding, molecular dynamics, RNA velocity, geospatial science, time series forecasting, scientific ML resource discovery via Hugging Science, 78+ scientific databases, and more) for any AI agent that supports the open [Agent Skills](https://agentskills.io/) standard, created by [K-Dense](https://k-dense.ai). Works with **Cursor, Claude Code, Codex, Google Antigravity, and more**. Transform your AI agent into a research assistant capable of executing complex multi-step scientific workflows across biology, chemistry, medicine, and beyond.
> ⭐ **Help make AI for science easier to discover:** If Scientific Agent Skills saves you time, teaches your agent a workflow, or helps your lab move faster, please [star this repository](https://github.com/K-Dense-AI/scientific-agent-skills). A star is a public signal that these open, reusable research skills are worth maintaining: it helps scientists, engineers, and open-source contributors find the project, shows which agent-skill standards are gaining real adoption, and gives us a clear reason to keep expanding the collection for the community.
@@ -55,7 +55,7 @@ These skills enable your AI agent to seamlessly work with specialized scientific
## 📦 What's Included
-This repository provides **146 scientific and research skills** organized into the following categories:
+This repository provides **147 scientific and research skills** organized into the following categories:
- **100+ Scientific & Financial Databases** - A unified database-lookup skill provides direct access to 78 public databases (PubChem, ChEMBL, UniProt, COSMIC, ClinicalTrials.gov, FRED, USPTO, and more), plus dedicated skills for DepMap, Imaging Data Commons, PrimeKG, U.S. Treasury Fiscal Data, and Hugging Science (curated catalog of scientific datasets, models, and demos across 17 scientific domains on Hugging Face). Multi-database packages like BioServices (~40 bioinformatics services), BioPython (38 NCBI sub-databases via Entrez), and gget (20+ genomics databases) add further coverage
- **70+ Optimized Python Package Skills** - Explicitly defined skills for RDKit, Scanpy, PyTorch Lightning, scikit-learn, BioPython, pyzotero, BioServices, PennyLane, Qiskit, Molecular Dynamics (OpenMM/MDAnalysis), scVelo, TimesFM, and others — with curated documentation, examples, and best practices. Note: the agent can write code using *any* Python package, not just these; these skills simply provide stronger, more reliable performance for the packages listed
@@ -100,7 +100,7 @@ Each skill includes:
- **Multi-Step Workflows** - Execute complex pipelines with a single prompt
### 🎯 **Comprehensive Coverage**
-- **146 Skills** - Extensive coverage across all major scientific domains
+- **147 Skills** - Extensive coverage across all major scientific domains
- **100+ Databases** - Unified access to 78+ databases via database-lookup, plus dedicated data access skills and multi-database packages like BioServices, BioPython, and gget
- **70+ Optimized Python Package Skills** - RDKit, Scanpy, PyTorch Lightning, scikit-learn, BioServices, PennyLane, Qiskit, Molecular Dynamics (OpenMM/MDAnalysis), scVelo, TimesFM, and others (the agent can use any Python package; these are the pre-documented, higher-performing paths)
@@ -185,7 +185,7 @@ git clone https://github.com/K-Dense-AI/scientific-agent-skills.git .agents/skil
hermes skills tap add K-Dense-AI/scientific-agent-skills
```
-These skills stay portable across all of them: `metadata` is single-line JSON (so OpenClaw's line-based reader parses it), credentialed skills declare a top-level `required_environment_variables` field (so Hermes prompts for keys), and unknown fields are ignored everywhere else. Because 146 skills add up to a lot of standing context, consider installing a topical subset rather than the whole collection.
+These skills stay portable across all of them: `metadata` is single-line JSON (so OpenClaw's line-based reader parses it), credentialed skills declare a top-level `required_environment_variables` field (so Hermes prompts for keys), and unknown fields are ignored everywhere else. Because 147 skills add up to a lot of standing context, consider installing a topical subset rather than the whole collection.
> **NemoClaw note:** NemoClaw runs agents inside NVIDIA OpenShell with default-deny outbound networking. Skills are discovered and loaded normally, but any skill that needs the network — package installs via `uv`, or API calls (Exa, Parallel, Benchling, NCBI, Materials Project, …) — only works once the operator pre-approves the relevant domains in the OpenShell TUI.
@@ -410,7 +410,7 @@ networks, and search GEO for similar patterns.
## 📚 Available Skills
-This repository contains **146 scientific and research skills** organized across multiple domains. Each skill provides comprehensive documentation, code examples, and best practices for working with scientific libraries, databases, and tools.
+This repository contains **147 scientific and research skills** organized across multiple domains. Each skill provides comprehensive documentation, code examples, and best practices for working with scientific libraries, databases, and tools.
### Skill Categories
@@ -536,8 +536,9 @@ This repository contains **146 scientific and research skills** organized across
- Workflow mining: Autoskill (local screenpipe-based repeated workflow detection and skill drafting)
- Agent platform development: Pi Agent (using Pi as a terminal coding harness and building on it with SDK, RPC/JSONL, extensions, custom providers/models, packages, TUI components, and session tooling)
-#### 🎓 **Research Methodology & Planning** (11 skills)
+#### 🎓 **Research Methodology & Planning** (12 skills)
- Ideation: Scientific Brainstorming, Hypothesis Generation
+- Autonomous optimization: Arbor (Hypothesis Tree Refinement — iteratively improve a code/model/agent-harness/data artifact against a dev evaluator while a held-out test gate guards against overfitting)
- Critical analysis: Scientific Critical Thinking, Scholar Evaluation
- Scenario analysis: What-If Oracle (4–6 branch possibility exploration, contingency planning, decision stress-testing)
- Multi-perspective deliberation: Consciousness Council (diverse expert viewpoints, devil's advocate analysis)
@@ -736,7 +737,7 @@ Recommended practice:
title = {Scientific Agent Skills: A Comprehensive Collection of Scientific Tools for AI Agents},
year = {2026},
url = {https://github.com/K-Dense-AI/scientific-agent-skills},
- note = {146 skills covering databases, packages, integrations, and analysis tools}
+ note = {147 skills covering databases, packages, integrations, and analysis tools}
}
```
diff --git a/docs/skills.md b/docs/skills.md
index 32476220..b3e2ec2d 100644
--- a/docs/skills.md
+++ b/docs/skills.md
@@ -154,6 +154,9 @@
- **Pi Agent** - Build with and use Pi, the minimal terminal coding harness. Covers installing and configuring Pi, authenticating providers, adding custom models and providers, creating Pi skills/extensions/packages/themes/prompt templates, embedding Pi through the Node/TypeScript SDK, integrating over RPC or JSON event streams, parsing session JSONL files, and building custom TUI components. Use cases: building custom agent UIs, exposing Pi from another process or language, wiring private model gateways, packaging reusable Pi workflows, and helping agents operate Pi as a platform rather than only a CLI
- **HypoGeniC** - Automated hypothesis generation and testing using large language models to accelerate scientific discovery. Provides three frameworks: HypoGeniC (data-driven hypothesis generation from observational data), HypoRefine (synergistic approach combining literature insights with empirical patterns through an agentic system), and Union methods (mechanistic combination of literature and data-driven hypotheses). Features iterative refinement that improves hypotheses by learning from challenging examples, Redis caching for API cost reduction, and customizable YAML-based prompt templates. Includes command-line tools for generation (hypogenic_generation) and testing (hypogenic_inference). Research applications have demonstrated 14.19% accuracy improvement in AI-content detection and 7.44% in deception detection. Use cases: deception detection in reviews, AI-generated content identification, mental stress detection, exploratory research without existing literature, hypothesis-driven analysis in novel domains, and systematic exploration of competing explanations
+### Autonomous Research & Optimization Frameworks
+- **Arbor** - Autonomous Optimization (AO) via Hypothesis Tree Refinement (HTR), adapted from the Arbor framework (Jin et al., 2026; RUC-NLPIR/Arbor). Iteratively improves a real artifact — a codebase, model-training recipe, agent/search harness, data-synthesis pipeline, or prompt — against a measurable objective over many experiment cycles, without overfitting to the feedback signal. The agent acts as a long-lived **coordinator** that maintains a persistent **hypothesis tree** (each node binds a falsifiable hypothesis, a distilled reusable insight, and a pointer to the artifact version that realizes it) and runs the six-step loop Observe → Ideate → Select → Dispatch → Backpropagate → Decide; short-lived **executor** subagents each test one hypothesis in an isolated git worktree and return a dev score, factual result, distilled insight, and branch reference. A **held-out merge gate** promotes a candidate to the best artifact only when its improvement transfers to a test evaluator the search never optimized against, separating exploratory dev gains from verified progress. Insights are propagated up the tree so local findings become direction-level constraints and global priors, and falsified branches are pruned with their reasons recorded as negative constraints. Ships a `tree.py` state manager (init/observe/add-node/set-evidence/propagate/prune/merge/status/validate) that keeps the tree consistent and auditable, plus reference docs on the HTR methodology, the executor brief, the final-report template, and how to run the upstream `arbor` CLI instead. Use cases: "improve my model's eval score in fewer steps", optimizing an agent or search harness for higher pass rate/accuracy, tuning a data-generation pipeline judged by downstream model behavior, MLE-bench / Kaggle-style "improve the submission" tasks, and any long-horizon "make this artifact better and don't just memorize the dev set" workflow that needs structured, branching exploration with an audit trail
+
### Scientific Communication & Publishing
- **BGPT Paper Search** - Search scientific papers and retrieve structured experimental data extracted from full-text studies via the BGPT MCP server. Returns 25+ fields per paper including methods, results, sample sizes, quality scores, and conclusions. Use for literature reviews, evidence synthesis, and finding experimental details not available in abstracts alone
- **pyzotero** - Python client for the Zotero Web API v3. Programmatically manage Zotero reference libraries: retrieve, create, update, and delete items, collections, tags, and attachments. Export citations as BibTeX, CSL-JSON, and formatted bibliography HTML. Supports user and group libraries, local mode for offline access, paginated retrieval with `everything()`, full-text content indexing, saved search management, and file upload/download. Optional CLI and built-in MCP server (pyzotero 1.12+) for searching local Zotero 7 libraries including full-text PDF search and Semantic Scholar integration. Use cases: building research automation pipelines that integrate with Zotero, bulk importing references, exporting bibliographies programmatically, managing large reference collections, syncing library metadata, enriching bibliographic data, and connecting LLM agents to a local Zotero library.
diff --git a/pyproject.toml b/pyproject.toml
index 058c4f3c..f431284d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "scientific-agent-skills"
-version = "2.51.0"
+version = "2.52.0"
description = "A set of ready to use Agent Skills for research, science, engineering, analysis, finance and writing."
readme = "README.md"
requires-python = ">=3.13"
diff --git a/skills/arbor/SKILL.md b/skills/arbor/SKILL.md
new file mode 100644
index 00000000..a8bfcfcf
--- /dev/null
+++ b/skills/arbor/SKILL.md
@@ -0,0 +1,150 @@
+---
+name: arbor
+description: Autonomously improve a real artifact (code, training recipe, agent harness, data pipeline, prompt) against an objective and an evaluator, using Hypothesis Tree Refinement (HTR) from the Arbor paper. Use this whenever someone wants to iteratively optimize something over many experiments without overfitting — e.g. "get my model's eval score up", "improve this agent/harness", "tune this pipeline", "beat the baseline on this benchmark", "run a search over approaches and keep the best", "do an MLE-bench / Kaggle-style optimization", or any long-horizon "make this artifact better and don't just memorize the dev set" task. Trigger it even when the user doesn't say "Arbor" or "hypothesis tree" but describes repeated experiment-and-evaluate loops, branching exploration of competing ideas, or worries about a dev/test gap. Runs Claude itself as the coordinator with subagent executors in isolated git worktrees; for the standalone `arbor` CLI tool see references/arbor-upstream.md.
+allowed-tools: Read Write Edit Bash Agent
+license: MIT license
+metadata: {"version": "1.0", "skill-author": "K-Dense Inc."}
+---
+
+# Arbor — Autonomous Optimization via Hypothesis Tree Refinement
+
+## Overview
+
+This skill runs an **Autonomous Optimization (AO)** loop: starting from an existing artifact and a measurable objective, improve it through many rounds of experiment and evaluation — without step-by-step human supervision and without overfitting to the feedback signal. It's the right tool when the bottleneck isn't writing one good change, but *organizing dozens of trials* so that lessons accumulate instead of evaporating.
+
+It implements **Hypothesis Tree Refinement (HTR)** from *Arbor* (Jin et al., 2026). The key idea: keep the research state in a persistent **hypothesis tree** rather than in conversation history. Each node binds a hypothesis, the distilled insight it produced, and a pointer to the artifact version that realizes it. You play the long-lived **coordinator** that owns this tree and decides where to search; short-lived **executor** subagents test one hypothesis each in isolated git worktrees and report back. A **held-out merge gate** admits a change only when it improves on a *test* evaluator the search never optimized against. This is what turns trial-and-error into cumulative, auditable research.
+
+Use the `scripts/tree.py` state manager for all the bookkeeping (creating nodes, writing evidence, propagating insights, pruning, the merge gate, the Observe projection). It keeps the state consistent and frees you to spend judgment on what the evidence *means*.
+
+## When to use this skill
+
+Reach for Arbor when the task is **iterative improvement of a concrete artifact under an evaluator**:
+- Model training: optimizer/architecture/recipe changes to lower loss or hit a target in fewer steps.
+- Harness/agent engineering: raising pass rate or accuracy of an agent loop, search harness, or tool-use scaffold.
+- Data synthesis: improving a generation/filtering pipeline judged by downstream model behavior.
+- Benchmark optimization: MLE-bench / Kaggle-style "improve the submission" tasks.
+- Prompt/system optimization where you can score outputs automatically.
+
+The distinguishing signals: there's an **artifact you can modify**, an **objective**, a way to **score** candidates, and you expect to run **many experiments**. If the user only wants a single fix or a one-shot answer, this is overkill — just do the work directly. If they want open-ended ideation with no evaluator, use `hypothesis-generation` or `scientific-brainstorming` instead.
+
+## The AO setup — pin this down first
+
+Before any experiments, establish the task tuple `(M_0, O, E_dev, E_test)`. Getting this right matters more than any later decision, so confirm it explicitly:
+
+- **M_0 — initial material**: the artifact to improve (a repo, a script, a config, a prompt). Make sure it's under git and currently runs.
+- **O — objective**: the natural-language goal and the metric *direction* (maximize accuracy? minimize loss/steps?).
+- **E_dev — development evaluator**: a command you can run freely during search to score a candidate. Fast, repeatable.
+- **E_test — held-out test evaluator**: a *separate* evaluator (different seeds, different split, or a larger run) used only at the merge gate. It must not be used as a search oracle — that's the whole point.
+
+If the user hasn't given you a clean dev/test split, **construct one and say so**. The dev/test separation is the mechanism that catches overfitting: a candidate that wins on dev but not on test isn't a success, it's a warning that you're exploiting the feedback signal. Without it, autonomous search reliably overfits.
+
+Initialize the run:
+
+```bash
+python scripts/tree.py init \
+ --objective "Improve BrowseComp answer accuracy on the search harness" \
+ --dev-eval "python eval.py --split dev --n 50" \
+ --test-eval "python eval.py --split test --n 300" \
+ --material "." --metric-direction max --branching 3 --max-depth 2 --budget 12
+```
+
+`--branching` is how many sibling hypotheses you propose per parent; `--max-depth 2` keeps directions at depth 1 and concrete interventions at depth 2 (the paper's default); `--budget` is the number of coordinator cycles. Start small (10–20 cycles) — structured search beats brute force, and you can extend if progress is still being made.
+
+## The coordinator loop
+
+You run repeated cycles of six steps. This is the heart of HTR; do not collapse it into ad-hoc editing. Run `python scripts/tree.py cycle` once per cycle to track the budget.
+
+### 1. Observe
+Begin every cycle by re-grounding in the tree, not in your memory of the conversation:
+
+```bash
+python scripts/tree.py observe
+```
+
+This prints the objective, global insights, the active frontier (selectable hypotheses), executed nodes with their evidence, pruned lessons (negative constraints), and the current best artifact. Treating the tree as the source of truth is what keeps you coherent over a long run, after context compression has thrown away the details.
+
+### 2. Ideate
+Pick a promising parent and propose a few child hypotheses under it. **Condition on the tree's evidence** — this is the difference between Arbor and random search:
+- Validated insights are assumptions you can build on.
+- Pruned nodes are dead ends to avoid.
+- A "half-right" result is a *starting point for a sharper hypothesis*, not a reason to abandon the direction.
+
+Each hypothesis should be a **falsifiable claim about how changing the artifact will move the metric**, not a vague intention. Depth-1 nodes are broad directions ("the search harness loses correct answers it already retrieved"); depth-2 nodes are concrete, executable interventions ("run K=5 independent rollouts and aggregate by evidence dossier instead of majority vote").
+
+```bash
+python scripts/tree.py add-node --parent n0 --hypothesis "Verification, not retrieval, is the bottleneck: candidates are found but discarded"
+python scripts/tree.py add-node --parent n4 --hypothesis "Decompose the question into atomic constraints and verify each independently"
+```
+
+### 3. Select
+Choose which pending leaves to run next. **Selection is not pure score-maximization** — pick a hypothesis because it has strong prior evidence, because it would resolve an ambiguity its siblings exposed, or because its failure would clarify an important assumption. Frontier control under delayed feedback rewards informative experiments, not just promising ones.
+
+### 4. Dispatch
+Run each selected hypothesis as an **executor subagent in an isolated worktree** (use the Agent tool with `isolation: "worktree"`, or have the executor create one with `git worktree add`). Isolation matters: parallel experiments must not clobber each other or the current best, and exploratory changes stay quarantined until they pass the merge gate.
+
+Dispatch siblings **in parallel** (multiple Agent calls in one message) when they're independent — comparative evidence within one direction is exactly what makes later pruning and abstraction possible.
+
+Give each executor a tight, **hypothesis-bound** brief. See `references/executor-brief.md` for the full template. The contract that makes HTR work: **the executor may not change the hypothesis when the metric stalls.** It repairs its own code and reruns, but `h_n` is fixed — otherwise the returned score is no longer evidence about the assigned node and the tree's semantics break. The executor returns exactly four things:
+- **dev_score** — the dev evaluator result (for selection);
+- **result** — a factual summary of what happened;
+- **insight** — the distilled, reusable lesson (*why* the result supports, weakens, or bounds the hypothesis);
+- **branch_ref** — the git branch/commit/worktree path holding the artifact.
+
+Mark a node `running` before dispatch (`tree.py set-status --node n5 --status running`) so the Observe projection stays accurate.
+
+### 5. Backpropagate
+When an executor returns, write its report into the node, then **abstract the lesson upward**:
+
+```bash
+python scripts/tree.py set-evidence --node n5 --dev-score 70.0 \
+ --result "K=5 dossier aggregation recovers answers in minority rollouts" \
+ --insight "Correct answers often appear in a minority of rollouts; aggregation beats majority vote" \
+ --branch-ref "wt/n5"
+
+python scripts/tree.py propagate --node n5 \
+ --insight "Candidate coverage, not verification, limits this direction" --to-root
+```
+
+This is the step that makes the tree more than a log. A leaf-level observation ("data-interface mismatch") should become a direction-level constraint and, if it generalizes, a global prior that shapes future ideation. **Insight propagation is the component that drives most of HTR's gains** — in the paper's MLE-Bench Lite ablation, a tree *without* insight feedback scored even lower than a flat experiment queue with no tree at all (54.5% vs. 63.6% any-medal, against 81.8% for the full system). Hierarchy alone isn't enough: the semantic memory is what matters. So spend real thought on the abstraction; don't just copy the leaf insight upward verbatim.
+
+### 6. Decide
+Decide what to do with the new evidence: keep expanding a direction, prune a falsified subtree, or attempt to merge a candidate.
+
+- **Prune** dead ends, recording *why* — the reason becomes a negative constraint:
+ ```bash
+ python scripts/tree.py prune --node n7 --reason "search-augmented judge overfits dev questions; no test transfer"
+ ```
+- **Merge gate** — promote a candidate to the new best **only if it improves on `E_test`**. Run the test evaluator in a *fresh* worktree (not the dev worktree, to avoid leakage), then:
+ ```bash
+ python scripts/tree.py merge --node n5 --test-score 67.67 --branch-ref "wt/n5"
+ ```
+ If the gate rejects it, that's informative: a high-dev / low-test candidate is evidence the direction may be exploiting the dev signal rather than producing a transferable improvement. Record that lesson; don't quietly promote it anyway.
+
+Repeat until the budget is spent, the frontier is exhausted, or progress has clearly stalled.
+
+## Finishing the run
+
+When you stop, produce a short report (see `references/report-template.md`) covering:
+- the final best artifact, its test score, and its delta over `M_0`;
+- the tree (`python scripts/tree.py status`) as the audit trail of what was tried;
+- the main hypothesis shifts — how task understanding deepened across the run (early nodes test broad mechanisms; later nodes find their limits; ancestor insights compress these into the constraints behind the final design);
+- merged vs. explored: many nodes improve dev, far fewer pass the test gate — report that gap honestly rather than overstating dev wins.
+
+Always leave `M_best` as a real, runnable artifact on a named branch, and tell the user how to check it out.
+
+## Principles that make this work (not rote rules)
+
+These come from the paper's analysis; understanding *why* matters more than following them mechanically.
+
+- **The tree is the memory; conversation is not.** Over a long horizon your context gets compressed. Re-Observe each cycle so decisions rest on durable evidence, not a lossy summary.
+- **Structured search, not more sampling.** Arbor's gains come from how the budget is *organized* — maintaining competing hypotheses, comparing siblings, carrying lessons forward — not from spending more tokens. Don't fan out aimlessly; each experiment should be conditioned on what the tree already knows.
+- **Dev guides, test admits.** Use dev feedback freely to steer exploration, but never let a dev win into the final artifact without test confirmation. The dev/test disagreement is itself a signal worth reading.
+- **Executors are hypothesis-bound.** Local engineering flexibility (edit, debug, rerun) is fine; silently changing the hypothesis to chase a better number is not — it destroys the meaning of the evidence.
+- **Failures are constraints, not noise.** A falsified hypothesis tells you what the solution must avoid. Pruned-with-a-reason is more valuable than pruned-and-forgotten.
+
+## Reference files
+
+- `references/htr-methodology.md` — deeper explanation of HTR, the node structure, the six steps, and the paper's empirical lessons (ablations, transfer, cost). Read when you want the rationale behind a design choice.
+- `references/executor-brief.md` — the template for the brief you hand each executor subagent.
+- `references/report-template.md` — the final-report structure.
+- `references/arbor-upstream.md` — how to install and run the standalone `arbor` CLI from RUC-NLPIR/Arbor instead of orchestrating it natively, and when to prefer each.
diff --git a/skills/arbor/references/arbor-upstream.md b/skills/arbor/references/arbor-upstream.md
new file mode 100644
index 00000000..c5646f7a
--- /dev/null
+++ b/skills/arbor/references/arbor-upstream.md
@@ -0,0 +1,91 @@
+# Running the standalone Arbor CLI (upstream tool)
+
+This skill normally runs HTR **natively** — Claude is the coordinator and
+subagents are executors. That's the recommended path: no extra install, no
+separate API keys, and you stay in the loop to read evidence between cycles.
+
+But the paper's authors also ship a full implementation as a CLI. Use it instead
+when the user explicitly wants to run *the published system* (e.g. to reproduce
+paper results), wants Arbor to run fully unattended for many hours via its own
+live dashboard, or wants its built-in report/web-UI tooling.
+
+Source: https://github.com/RUC-NLPIR/Arbor
+
+## Install
+
+Requires Python ≥ 3.10 and Git.
+
+```bash
+git clone https://github.com/RUC-NLPIR/Arbor.git
+cd Arbor
+python -m venv .venv && source .venv/bin/activate
+pip install -e .
+arbor doctor # verify install, PATH, git, API keys
+```
+
+## Configure provider/model/keys
+
+```bash
+arbor setup # writes ~/.arbor/config.yaml (provider, model, base URL, keys)
+```
+
+Supported backends: Anthropic, OpenAI / OpenAI-compatible Responses API, and
+LiteLLM (DeepSeek, Gemini, Qwen, vLLM, Ollama, local gateways). Keys can also be
+set via environment variables.
+
+## Run
+
+1. Prepare a benchmark directory: an initial artifact under a **clean git repo**
+ plus an evaluation script (your `E_dev` / `E_test`).
+2. Author a project `research_config.yaml` (task description, coordinator
+ settings — max cycles, depth, merge thresholds — executor max turns, UI mode).
+ See `examples/research_config.example.yaml` in the repo.
+3. Start the interactive session:
+ ```bash
+ arbor
+ ```
+ Arbor runs an intake conversation, forms a Research Contract, then a live
+ dashboard takes over. Each experiment runs in an isolated git worktree;
+ verified improvements merge into a per-run trunk.
+4. Outputs land in `.arbor/sessions/` with `REPORT.md`, the event log, and
+ results. Re-render a past session's report with `arbor report <session>`.
+
+## Key CLI commands
+
+| Command | Purpose |
+|---|---|
+| `arbor` | Start an interactive research session |
+| `arbor setup` | Configure provider / model / keys |
+| `arbor doctor` | Diagnose install, PATH, git, API keys |
+| `arbor report <session>` | Re-render reports for a past session |
+| `arbor version` | Print installed version |
+
+## Codebase map (for the curious / for debugging)
+
+The implementation lives under `src/` (a src-layout; the CLI installs as
+`arbor`). The package directories are:
+- `core/` — ReAct loop, tools, LLM providers, context management
+- `coordinator/` — coordinator agent, the tree, orchestrator, coordinator tools
+- `executor/` — executor agent and CLI
+- `cli/` — intake, live dashboard, setup, doctor, config
+- `events/` — typed event bus and payloads
+- `report/`, `webui/` — report generation and read-only run monitor
+- `search_agent/` — the minimal ReAct search harness (the `M_0` for the
+ BrowseComp / search-agent tasks)
+- `plugins/` — domain plugins (e.g. `mle_kaggle.yaml`)
+- `skills/` — on-demand markdown playbooks
+
+(top-level `src/` also has `dashboard.py`, `run.py`, `review.py`.)
+
+**Naming note:** the paper and this skill call the persistent state the
+**hypothesis tree**; the tool's code and dashboard call the same structure the
+**Idea Tree**. They are the same thing. The depth convention also matches the
+native skill: root/depth 0 = objective + global insights, depth 1 = research
+directions, depth 2+ = concrete tested methods.
+
+## Native vs. upstream — quick guide
+
+- **Native (this skill)**: best default. Lower setup, transparent, you read and
+ steer between cycles, reuses your existing Claude Code session and worktrees.
+- **Upstream CLI**: choose for paper reproduction, long unattended runs with the
+ official dashboard, or when the user specifically asks for the `arbor` tool.
diff --git a/skills/arbor/references/executor-brief.md b/skills/arbor/references/executor-brief.md
new file mode 100644
index 00000000..ea67a78e
--- /dev/null
+++ b/skills/arbor/references/executor-brief.md
@@ -0,0 +1,68 @@
+# Executor brief template
+
+Each executor is a short-lived subagent that tests **one** hypothesis in an
+isolated git worktree and returns structured evidence. Dispatch it with the
+Agent tool (use `isolation: "worktree"` so it gets its own copy of the repo, or
+instruct it to run `git worktree add` itself). Dispatch independent siblings in
+parallel — multiple Agent calls in one message.
+
+Fill in the bracketed parts. Keep the brief tight: the executor needs the
+hypothesis, the context that lets it implement well, and a crisp contract for
+what to return — nothing more.
+
+---
+
+```
+You are an Arbor executor. Test ONE hypothesis in an isolated git worktree and
+return structured evidence. Do not change the hypothesis — your job is to give
+the coordinator clean evidence about THIS claim, even if it turns out false.
+
+HYPOTHESIS (h_n):
+ [the falsifiable claim, e.g. "Aggregating K=5 independent rollouts by an
+ evidence dossier recovers correct answers that majority vote discards."]
+
+CURRENT BEST ARTIFACT (M_best):
+ [path or git ref of the current best, e.g. branch `arbor/best` — start from this]
+
+RELEVANT INSIGHTS FROM THE TREE (assume these; build on them, don't re-litigate):
+ [ancestor + sibling insights, e.g. "Verification is not the bottleneck;
+ candidate coverage is. Search-augmented judging overfits dev questions."]
+
+OBJECTIVE & METRIC:
+ [O and direction, e.g. "Maximize BrowseComp answer accuracy."]
+
+DEVELOPMENT EVALUATOR (E_dev) — run this to score your candidate:
+ [exact command, e.g. `python eval.py --split dev --n 50`]
+
+WHAT TO DO:
+ 1. Create/confirm an isolated worktree from M_best so you don't touch other
+ experiments or the current best.
+ 2. Implement the MINIMAL change that realizes the hypothesis. You may edit,
+ debug, and rerun freely to get a working implementation — but keep the
+ change bound to this hypothesis. If the metric stalls, fix YOUR code; do
+ not pivot to a different idea.
+ 3. Run E_dev and record the score. Run it more than once if it's noisy.
+ 4. Commit the artifact on a clearly named branch.
+
+RETURN EXACTLY THIS (your final message IS the data the coordinator reads):
+ - dev_score: <number from E_dev>
+ - result: <1-3 sentences of factual outcome — what the change did>
+ - insight: <the reusable lesson: WHY this result supports / weakens /
+ bounds the hypothesis. This is the most valuable output —
+ make it a constraint future experiments can use, not a restatement
+ of the score.>
+ - branch_ref: <git branch/commit/worktree path holding the artifact>
+
+Do NOT run the held-out test evaluator — that is the coordinator's merge gate.
+```
+
+---
+
+After the executor returns, the coordinator records it with:
+
+```bash
+python scripts/tree.py set-evidence --node <id> \
+ --dev-score <n> --result "..." --insight "..." --branch-ref "<ref>"
+```
+
+then abstracts the lesson upward with `tree.py propagate`.
diff --git a/skills/arbor/references/htr-methodology.md b/skills/arbor/references/htr-methodology.md
new file mode 100644
index 00000000..1bcc19f7
--- /dev/null
+++ b/skills/arbor/references/htr-methodology.md
@@ -0,0 +1,177 @@
+# Hypothesis Tree Refinement (HTR) — methodology and evidence
+
+Background reference for the `arbor` skill. Source: *Toward Generalist
+Autonomous Research via Hypothesis-Tree Refinement* (Jin et al., 2026,
+arXiv:2606.11926; code: github.com/RUC-NLPIR/Arbor). Read this when you want
+the reasoning behind a design choice in the main loop.
+
+## The problem: Autonomous Optimization (AO)
+
+AO is the operational core of autonomous research. An agent starts from an
+initial artifact and a research objective, then improves the artifact through
+experimental feedback **without step-level human supervision**. Formally a task
+is a tuple `P = (M_0, O, E_dev, E_test)`:
+
+- `M_0` — mutable initial material (usually a codebase + its data).
+- `O` — objective: what "better" means, as a metric direction over the
+ artifact's output.
+- `E_dev` — development evaluator the agent may use freely during search.
+- `E_test` — held-out test evaluator. Same objective, different evidence.
+
+The goal is to return `M* = argmax over candidates of S_test(M')`, subject to
+the constraint that hypotheses and implementation decisions are made **without
+using `E_test` as an exploration oracle**. A candidate that exploits dev-split
+idiosyncrasies may raise `S_dev` but is not a successful AO solution unless the
+gain also transfers to `S_test`.
+
+Why this is hard: feedback is delayed, experiments are expensive, and failed
+attempts contain information that should guide later search. If an agent treats
+each trial as an independent local attempt, it loses the structure of the
+research process — what was tried, what evidence came back, how each result
+reshapes the space of future hypotheses.
+
+## The three design requirements
+
+HTR is built to satisfy three requirements that ordinary agentic tool use does
+not:
+
+1. **Branching with coherence.** Multiple competing hypotheses can be plausible
+ at once, so exploration must branch — but unrestricted branching degenerates
+ into an unstructured log. The frontier must keep competing directions
+ organized, comparable, and actionable.
+2. **Global strategy with local execution.** Strategic decisions depend on
+ evidence across the whole run; implementing one hypothesis is short-horizon
+ code editing. Separate the two so low-level traces don't obscure the global
+ state, and outcomes stay attributable to the hypotheses that produced them.
+3. **Exploration with held-out admission.** Dev feedback guides search;
+ artifact-level progress is admitted only when it transfers beyond that
+ feedback. The system must distinguish exploratory dev improvement from
+ verified test improvement.
+
+## The hypothesis tree as research state
+
+A rooted tree `T = (V, E)`. Each node is a research unit `n = <h_n, iota_n, mu_n>`:
+
+- **Hypothesis `h_n`** — a verifiable/falsifiable claim about how changing the
+ material improves the objective. Granularity tracks depth: nodes near the root
+ are broad directions; deeper nodes are concrete interventions an executor can
+ implement and evaluate. This organizes exploration as progressive refinement
+ rather than a flat sequence of independent trials.
+- **Insight `iota_n`** — the reusable interpretation of evidence. For an
+ executed leaf: what was tried, what happened, and *why* the result supports,
+ weakens, or constrains the hypothesis. For an internal node: an abstraction
+ over its children's insights — the current understanding of that direction.
+ It is **not** an execution transcript; it is compact semantic memory for later
+ ideation and selection.
+- **Metadata `mu_n`** — connects the semantic hypothesis to executable evidence:
+ node status, dev score, factual result, implementation reference (git branch
+ or commit), optional background. The material itself is **not** duplicated in
+ the tree — only references to external artifact states produced in isolated
+ worktrees. This keeps the state compact while every hypothesis stays grounded
+ in a verifiable implementation.
+
+Internal nodes hold abstract directions and accumulated lessons; leaves hold
+candidate interventions to dispatch. After a leaf executes, its score, result,
+artifact ref, and insight are written back, and the insight is propagated upward
+along the path to the root. Through this abstraction, local outcomes become
+direction-level lessons and eventually a compact global understanding.
+
+The tree therefore plays three roles at once: a **search frontier** (which
+directions are active/validated/pruned), a **long-term memory** (reusable
+evidence from successes *and* failures), and an **auditable record** (each
+artifact change linked to the hypothesis and evidence that motivated it).
+
+## The coordinator–executor split
+
+- A persistent **coordinator** owns the shared tree and decides where to expand,
+ which evidence to trust, what to prune, and when to merge. It sees the whole
+ frontier but does not perform every low-level implementation step.
+- Short-lived **executors** are invoked to test one hypothesis each. An executor
+ gets `h_n`, relevant ancestor insights, and the current best artifact; it
+ creates an isolated git worktree, implements the minimal change `h_n` requires,
+ evaluates on `E_dev`, repairs its own broken/inactive code, and returns
+ structured evidence.
+
+The boundary is the point: exploratory code changes stay isolated until they
+pass the merge gate, and the tree records only decision-relevant evidence
+(scores, factual outcomes, artifact refs, distilled insights) rather than a raw
+log of tool calls. This is how transient execution traces become persistent
+research state.
+
+### Executors are hypothesis-bound (and why)
+
+An executor's local loop may involve many edits and reruns, but it stays bound
+to the assigned hypothesis: `h_n` is fixed. If an executor were allowed to
+change the hypothesis when the metric stalls, the returned score would no longer
+be evidence about the assigned node, and ancestor insights built from it would
+become impossible to interpret. Keeping executors hypothesis-bound preserves the
+semantic meaning of every tree update while still allowing local engineering
+flexibility.
+
+## The six-step cycle (Algorithm 1, HTR)
+
+Each coordinator cycle is a controlled mutation of the tree through a narrow
+interface:
+
+1. **Observe** — re-ground in a structured projection of the tree (frontier,
+ root/global insights, ancestor insights, current best). Makes the tree the
+ authoritative state after context compression, instead of relying on lossy
+ conversation history.
+2. **Ideate** — under a chosen parent, propose `k` child hypotheses, each a
+ refinement/alternative/correction. Ideation is conditioned on tree evidence:
+ validated insights are assumptions to build on, pruned nodes are negative
+ constraints, recent reports suggest what's feasible or under-tested.
+3. **Select** — choose pending nodes to execute. Balance expected utility
+ against the evidence already accumulated around ancestors and siblings. A
+ node may be selected because it has strong prior evidence, because its
+ siblings exposed an unresolved ambiguity, or because its failure would
+ clarify an important assumption. Selection is frontier control under partial,
+ delayed feedback — not raw score maximization.
+4. **Dispatch** — selected hypotheses go to independent executors in fresh
+ worktrees. Parallel sibling execution yields comparative evidence within one
+ direction, which feeds later pruning and abstraction.
+5. **Backpropagate** — write each executor's evidence into its leaf, then update
+ insights along the path to the root. The propagated signal is not just a
+ scalar: it includes causal attributions, applicability conditions, and
+ reusable lessons. A leaf-level data-interface mismatch can become a
+ direction-level constraint and then a global prior.
+6. **Decide** — continue expanding a direction, prune a falsified subtree, or
+ attempt a merge. Promotion is guarded by the **held-out merge gate**: the
+ candidate is evaluated on `E_test` in a fresh worktree and merged into
+ `M_best` only if it improves under `O`. This separates exploratory success on
+ `E_dev` from verified artifact-level progress.
+
+## Empirical lessons (use these to prioritize effort)
+
+From the paper's experiments across six AO tasks (model training, harness
+engineering, data synthesis) plus MLE-Bench Lite:
+
+- **Insight feedback is the dominant component.** Ablating insight propagation
+ while *keeping* the tree caused a larger drop than removing the tree entirely
+ (on MLE-Bench Lite: full 81.82% any-medal vs. 54.54% w/o insight feedback vs.
+ 63.64% w/o tree). Hierarchy alone is not enough — a tree without propagated
+ lessons organizes experiments syntactically but provides no semantic memory.
+ **Invest your judgment in the abstraction at Backpropagate**, not just in
+ generating more hypotheses.
+- **Structured search, not a bigger budget.** Arbor used a comparable token
+ budget to single-trajectory baselines (~20–43M tokens) yet got larger held-out
+ gains. The win is in how the budget is *organized*: maintaining competing
+ hypotheses, isolated execution, comparison, and an updated frontier.
+- **The dev/test split exposes overfitting.** Across tasks, many nodes improved
+ dev but only a subset passed the test gate. On Terminal-Bench, the highest-dev
+ candidate was *not* the best on test. Always report the merged-vs-explored gap
+ honestly; a high-dev/low-test result is evidence of feedback exploitation.
+- **Refinement deepens task understanding.** Early nodes test whether a broad
+ mechanism holds; later nodes localize where it stops working; ancestor
+ insights compress these into the constraints the final design must satisfy.
+ Successful proposals are usually *evidence-conditioned* responses to earlier
+ failures, not fresh guesses.
+- **Lessons transfer.** A harness optimized only on one task's dev feedback
+ improved unrelated held-out tasks, indicating HTR discovers generally useful
+ design changes rather than fitting the source benchmark — when, and only when,
+ the merge gate is enforced.
+- **What HTR does *not* fix.** Arbor is strongest at a sequence of concrete
+ refinements once a runnable solution exists. It is weaker when progress
+ requires a genuinely new high-level formulation only weakly connected to the
+ current tree — that still leans on good human task design (the choice of
+ `M_0`, evaluator, metric, and interface).
diff --git a/skills/arbor/references/report-template.md b/skills/arbor/references/report-template.md
new file mode 100644
index 00000000..2fd0f9dc
--- /dev/null
+++ b/skills/arbor/references/report-template.md
@@ -0,0 +1,39 @@
+# Final report template
+
+Produce this when the run ends (budget spent, frontier exhausted, or progress
+stalled). The point is an honest, auditable account — not a victory lap. Keep it
+concise and grounded in the tree.
+
+```markdown
+# Arbor run report: [objective]
+
+## Result
+- **Best artifact**: [git branch/ref of M_best, e.g. `arbor/best`]
+- **Test score**: [S_test of M_best] vs. initial [S_test of M_0] → delta [Δ]
+- **How to check it out**: `git checkout [ref]`
+- One-line summary of the change that won.
+
+## What was tried (audit trail)
+[Paste `python scripts/tree.py status` — the tree shows every direction,
+which were pruned, which merged, with dev/test scores.]
+
+## How understanding evolved
+2-4 bullets tracing the main hypothesis shifts: which early nodes tested broad
+mechanisms, what they confirmed or ruled out, and how that reshaped later
+hypotheses. The story should explain *why* the final design looks the way it
+does — i.e. the constraints the run discovered.
+
+## Dev vs. test (overfitting check)
+- Nodes that improved **dev**: [count]
+- Nodes that passed the **test merge gate**: [count]
+- Comment on the gap: were there high-dev / low-test candidates? What did
+ rejecting them tell you? An honest gap here is more trustworthy than a clean
+ "everything worked".
+
+## Open directions
+What you'd explore with more budget, and any direction that seemed to need a
+new high-level formulation rather than further refinement (HTR's known weak
+spot — flag it for the human).
+```
+
+Always leave `M_best` as a real, runnable artifact on a named git branch.
diff --git a/skills/arbor/scripts/tree.py b/skills/arbor/scripts/tree.py
new file mode 100644
index 00000000..fc49274d
--- /dev/null
+++ b/skills/arbor/scripts/tree.py
@@ -0,0 +1,564 @@
+#!/usr/bin/env python3
+"""
+tree.py — persistent hypothesis-tree state manager for Arbor-style
+Hypothesis Tree Refinement (HTR).
+
+The hypothesis tree is the durable research state for an Autonomous
+Optimization (AO) run. This script owns the *mechanical* parts of that state
+— creating nodes, writing back evidence, propagating insights up the tree,
+pruning falsified branches, recording the held-out merge gate, and rendering
+an "Observe" projection — so the coordinator (you, the model) can spend its
+judgment on what the evidence *means* rather than on bookkeeping.
+
+Division of labor:
+ - This script keeps the state consistent and auditable. It never decides
+ which hypothesis to try or whether one is good.
+ - The coordinator reads the projection (`observe`), forms hypotheses,
+ interprets executor reports, and calls the mutating commands to record
+ those decisions.
+
+State lives in `.arbor/` under the run directory (default: current dir):
+ .arbor/tree.json — the hypothesis tree (nodes, edges, evidence, insights)
+ .arbor/run.json — run-level config: objective, evaluators, budget, M_best
+
+Node fields mirror the paper's research unit n = <h, iota, mu>:
+ hypothesis (h) — the falsifiable claim this node tests
+ insight (iota) — distilled, reusable lesson (filled after execution)
+ metadata (mu) — status, dev_score, test_score, result, branch_ref, depth
+
+Run `python tree.py --help` or `python tree.py <command> --help`.
+"""
+
+import argparse
+import json
+import os
+import sys
+import time
+from pathlib import Path
+
+# ----------------------------------------------------------------------------
+# Storage helpers
+# ----------------------------------------------------------------------------
+
+VALID_STATUS = {"pending", "running", "executed", "merged", "pruned", "root"}
+
+
+def _dir(run_dir):
+ return Path(run_dir) / ".arbor"
+
+
+def _tree_path(run_dir):
+ return _dir(run_dir) / "tree.json"
+
+
+def _run_path(run_dir):
+ return _dir(run_dir) / "run.json"
+
+
+def _load(path, what):
+ if not path.exists():
+ sys.exit(
+ f"error: no {what} found at {path}. Run `tree.py init` first "
+ f"(from the run directory, or pass --run-dir)."
+ )
+ with open(path) as f:
+ return json.load(f)
+
+
+def _save(path, data):
+ path.parent.mkdir(parents=True, exist_ok=True)
+ tmp = path.with_suffix(".tmp")
+ with open(tmp, "w") as f:
+ json.dump(data, f, indent=2)
+ tmp.replace(path)
+
+
+def _load_tree(run_dir):
+ return _load(_tree_path(run_dir), "hypothesis tree")
+
+
+def _load_run(run_dir):
+ return _load(_run_path(run_dir), "run config")
+
+
+def _next_id(tree):
+ n = tree.get("_counter", 0) + 1
+ tree["_counter"] = n
+ return f"n{n}"
+
+
+def _node(tree, node_id):
+ node = tree["nodes"].get(node_id)
+ if node is None:
+ sys.exit(f"error: no node with id '{node_id}'. Run `tree.py status` to list nodes.")
+ return node
+
+
+def _children(tree, node_id):
+ return [nid for nid, n in tree["nodes"].items() if n.get("parent") == node_id]
+
+
+def _ancestors(tree, node_id):
+ """Path from node up to (and including) root, nearest first."""
+ path = []
+ cur = tree["nodes"][node_id].get("parent")
+ while cur is not None:
+ path.append(cur)
+ cur = tree["nodes"][cur].get("parent")
+ return path
+
+
+def _depth(tree, node_id):
+ return len(_ancestors(tree, node_id))
+
+
+def _stamp(node):
+ node["updated_at"] = int(time.time())
+
+
+# ----------------------------------------------------------------------------
+# Commands
+# ----------------------------------------------------------------------------
+
+
+def cmd_init(args):
+ d = _dir(args.run_dir)
+ if _tree_path(args.run_dir).exists() and not args.force:
+ sys.exit(
+ f"error: a tree already exists at {_tree_path(args.run_dir)}. "
+ f"Use --force to overwrite (this erases the current run)."
+ )
+ root = {
+ "id": "n0",
+ "parent": None,
+ "depth": 0,
+ "status": "root",
+ "hypothesis": args.objective,
+ "insight": "", # global insights accumulate here via backpropagation
+ "metadata": {"dev_score": None, "test_score": None, "result": "", "branch_ref": None},
+ "created_at": int(time.time()),
+ "updated_at": int(time.time()),
+ }
+ tree = {"_counter": 0, "root": "n0", "nodes": {"n0": root}}
+ run = {
+ "objective": args.objective,
+ "metric_direction": args.metric_direction,
+ "dev_eval": args.dev_eval,
+ "test_eval": args.test_eval,
+ "material": args.material,
+ "branching": args.branching,
+ "max_depth": args.max_depth,
+ "budget_cycles": args.budget,
+ "cycles_used": 0,
+ "best_node": None, # node id of current M_best
+ "best_test_score": None, # held-out score of M_best
+ "best_branch_ref": None, # git ref / path of M_best artifact
+ "created_at": int(time.time()),
+ }
+ _save(_tree_path(args.run_dir), tree)
+ _save(_run_path(args.run_dir), run)
+ print(f"Initialized Arbor run in {d}")
+ print(f" objective : {args.objective}")
+ print(f" metric direction: {args.metric_direction} (higher-is-better after orienting)")
+ print(f" dev evaluator : {args.dev_eval}")
+ print(f" test evaluator : {args.test_eval}")
+ print(f" budget : {args.budget} cycles, branching {args.branching}, max depth {args.max_depth}")
+ print("\nNext: `tree.py observe` to read the state, then add direction nodes under n0.")
+
+
+def cmd_add_node(args):
+ tree = _load_tree(args.run_dir)
+ parent = _node(tree, args.parent)
+ run = _load_run(args.run_dir)
+ nid = _next_id(tree)
+ depth = _depth(tree, args.parent) + 1
+ if depth > run["max_depth"]:
+ print(
+ f"warning: node depth {depth} exceeds max_depth {run['max_depth']}. "
+ f"Deep nodes should be concrete, executable interventions.",
+ file=sys.stderr,
+ )
+ node = {
+ "id": nid,
+ "parent": args.parent,
+ "depth": depth,
+ "status": "pending",
+ "hypothesis": args.hypothesis,
+ "insight": "",
+ "metadata": {"dev_score": None, "test_score": None, "result": "", "branch_ref": None},
+ "created_at": int(time.time()),
+ "updated_at": int(time.time()),
+ }
+ tree["nodes"][nid] = node
+ _save(_tree_path(args.run_dir), tree)
+ kind = "direction" if depth == 1 else "intervention"
+ print(f"Added {kind} node {nid} (depth {depth}) under {args.parent}: {args.hypothesis}")
+
+
+def cmd_set_status(args):
+ tree = _load_tree(args.run_dir)
+ node = _node(tree, args.node)
+ if args.status not in VALID_STATUS:
+ sys.exit(f"error: status must be one of {sorted(VALID_STATUS)}")
+ node["status"] = args.status
+ _stamp(node)
+ _save(_tree_path(args.run_dir), tree)
+ print(f"{args.node} -> status={args.status}")
+
+
+def cmd_set_evidence(args):
+ """Write an executor's report back into its node (the Backpropagate step,
+ leaf part). Insight propagation upward is a separate, deliberate call."""
+ tree = _load_tree(args.run_dir)
+ node = _node(tree, args.node)
+ meta = node["metadata"]
+ if args.dev_score is not None:
+ meta["dev_score"] = args.dev_score
+ if args.result is not None:
+ meta["result"] = args.result
+ if args.branch_ref is not None:
+ meta["branch_ref"] = args.branch_ref
+ if args.insight is not None:
+ node["insight"] = args.insight
+ node["status"] = args.status or "executed"
+ _stamp(node)
+ _save(_tree_path(args.run_dir), tree)
+ print(f"Wrote evidence to {args.node}: dev_score={meta['dev_score']} status={node['status']}")
+ if node["insight"]:
+ print(f" insight: {node['insight']}")
+ anc = _ancestors(tree, args.node)
+ if anc:
+ print(
+ "\nReminder: abstract this leaf insight upward. Decide what direction-level "
+ f"lesson it implies for ancestors {anc} and record it with "
+ f"`tree.py propagate --node {args.node} --insight \"...\"` (and update n0 "
+ "global insights if it generalizes)."
+ )
+
+
+def cmd_propagate(args):
+ """Backpropagate a distilled, direction-level lesson up the ancestor path.
+
+ The coordinator decides the abstracted wording; this appends it to the
+ chosen ancestor(s) so later ideation is conditioned on it. By default it
+ updates the immediate parent; --to-root also updates global insights."""
+ tree = _load_tree(args.run_dir)
+ _node(tree, args.node) # validate
+ targets = _ancestors(tree, args.node)
+ if not targets:
+ sys.exit("error: node has no ancestors (is it the root?).")
+ if not args.to_root:
+ targets = targets[:1] # immediate parent only
+ for tid in targets:
+ anc = tree["nodes"][tid]
+ existing = anc.get("insight", "")
+ line = f"[from {args.node}] {args.insight}"
+ anc["insight"] = (existing + "\n" + line).strip() if existing else line
+ _stamp(anc)
+ _save(_tree_path(args.run_dir), tree)
+ print(f"Propagated insight from {args.node} to ancestors {targets}")
+
+
+def cmd_prune(args):
+ """Mark a node (and its subtree) pruned. Pruned hypotheses become negative
+ constraints — record *why* so future ideation avoids the dead end."""
+ tree = _load_tree(args.run_dir)
+ _node(tree, args.node)
+ stack = [args.node]
+ pruned = []
+ while stack:
+ cur = stack.pop()
+ node = tree["nodes"][cur]
+ if node["status"] in ("merged", "root"):
+ continue
+ node["status"] = "pruned"
+ if cur == args.node and args.reason:
+ node["metadata"]["prune_reason"] = args.reason
+ _stamp(node)
+ pruned.append(cur)
+ stack.extend(_children(tree, cur))
+ _save(_tree_path(args.run_dir), tree)
+ print(f"Pruned {pruned}" + (f" — reason: {args.reason}" if args.reason else ""))
+
+
+def cmd_merge(args):
+ """Record a held-out merge gate decision. Only call this AFTER evaluating
+ the candidate on the TEST evaluator in a fresh worktree. Admitting a
+ candidate that only improved dev defeats the purpose of the split."""
+ tree = _load_tree(args.run_dir)
+ run = _load_run(args.run_dir)
+ node = _node(tree, args.node)
+
+ direction = run["metric_direction"]
+ prev = run["best_test_score"]
+
+ def better(new, old):
+ if old is None:
+ return True
+ return new > old if direction == "max" else new < old
+
+ improves = better(args.test_score, prev)
+ node["metadata"]["test_score"] = args.test_score
+ if improves:
+ node["status"] = "merged"
+ run["best_node"] = args.node
+ run["best_test_score"] = args.test_score
+ run["best_branch_ref"] = args.branch_ref or node["metadata"].get("branch_ref")
+ _stamp(node)
+ _save(_tree_path(args.run_dir), tree)
+ _save(_run_path(args.run_dir), run)
+ print(
+ f"MERGE GATE PASSED: {args.node} test={args.test_score} "
+ f"beats previous best={prev}. M_best is now {args.node} "
+ f"(ref: {run['best_branch_ref']})."
+ )
+ else:
+ _stamp(node)
+ _save(_tree_path(args.run_dir), tree)
+ print(
+ f"MERGE GATE REJECTED: {args.node} test={args.test_score} does not beat "
+ f"best={prev} (direction={direction}). This is informative, not a failure: "
+ "a high-dev / low-test gap means the candidate may be exploiting the dev "
+ "signal. Record that lesson and keep M_best unchanged."
+ )
+
+
+def cmd_cycle(args):
+ """Increment the cycle counter (call once per Observe->Decide pass)."""
+ run = _load_run(args.run_dir)
+ run["cycles_used"] += 1
+ _save(_run_path(args.run_dir), run)
+ left = run["budget_cycles"] - run["cycles_used"]
+ print(f"Cycle {run['cycles_used']}/{run['budget_cycles']} ({left} remaining).")
+ if left <= 0:
+ print("Budget exhausted — finish the run: do a final merge-gate check and report.")
+
+
+# ----------------------------------------------------------------------------
+# Read-only projections
+# ----------------------------------------------------------------------------
+
+
+def _fmt_score(node, run):
+ s = node["metadata"].get("dev_score")
+ t = node["metadata"].get("test_score")
+ bits = []
+ if s is not None:
+ bits.append(f"dev={s}")
+ if t is not None:
+ bits.append(f"test={t}")
+ return (" [" + " ".join(bits) + "]") if bits else ""
+
+
+def cmd_observe(args):
+ """The Observe step: a compact projection the coordinator re-grounds on at
+ the start of each cycle, so decisions come from the tree rather than from a
+ lossy conversation history."""
+ tree = _load_tree(args.run_dir)
+ run = _load_run(args.run_dir)
+ nodes = tree["nodes"]
+ root = nodes[tree["root"]]
+
+ print("=" * 72)
+ print("OBSERVE — current research state")
+ print("=" * 72)
+ print(f"Objective : {run['objective']}")
+ print(f"Metric direction: {run['metric_direction']}")
+ print(f"Dev evaluator : {run['dev_eval']}")
+ print(f"Test evaluator : {run['test_eval']}")
+ print(
+ f"Budget : cycle {run['cycles_used']}/{run['budget_cycles']}, "
+ f"branching {run['branching']}, max depth {run['max_depth']}"
+ )
+ print(
+ f"Current best : "
+ + (
+ f"{run['best_node']} (test={run['best_test_score']}, ref={run['best_branch_ref']})"
+ if run["best_node"]
+ else "none yet — M_best is the initial material"
+ )
+ )
+
+ print("\n-- Global insights (root) --")
+ print(root["insight"].strip() if root["insight"].strip() else " (none yet)")
+
+ # Active frontier = pending/running leaves
+ frontier = [
+ n
+ for n in nodes.values()
+ if n["status"] in ("pending", "running") and not _children(tree, n["id"])
+ ]
+ print("\n-- Active frontier (selectable hypotheses) --")
+ if not frontier:
+ print(" (empty — ideate new children under a promising node)")
+ for n in sorted(frontier, key=lambda x: x["id"]):
+ anc = _ancestors(tree, n["id"])
+ anc_ins = " | ".join(
+ nodes[a]["insight"].replace("\n", " ")[:80] for a in anc if nodes[a]["insight"].strip()
+ )
+ print(f" {n['id']} (depth {n['depth']}, {n['status']}): {n['hypothesis']}")
+ if anc_ins:
+ print(f" ancestor insights: {anc_ins}")
+
+ # Validated / executed leaves with evidence
+ executed = [n for n in nodes.values() if n["status"] in ("executed", "merged")]
+ print("\n-- Executed / merged nodes (evidence) --")
+ if not executed:
+ print(" (none yet)")
+ for n in sorted(executed, key=lambda x: x["id"]):
+ print(f" {n['id']} [{n['status']}]{_fmt_score(n, run)}: {n['hypothesis']}")
+ if n["insight"].strip():
+ print(f" insight: {n['insight'].splitlines()[0][:120]}")
+
+ # Pruned lessons (negative constraints)
+ pruned = [n for n in nodes.values() if n["status"] == "pruned"]
+ print("\n-- Pruned lessons (negative constraints — avoid these) --")
+ if not pruned:
+ print(" (none yet)")
+ for n in sorted(pruned, key=lambda x: x["id"]):
+ reason = n["metadata"].get("prune_reason", "")
+ print(f" {n['id']}: {n['hypothesis']}" + (f" — {reason}" if reason else ""))
+
+ print("\n" + "=" * 72)
+ print(
+ "Next: Ideate children under a promising node, Select one or more frontier\n"
+ "leaves, Dispatch each to an executor subagent in an isolated worktree."
+ )
+
+
+def cmd_status(args):
+ """ASCII tree render — useful for reports and quick scans."""
+ tree = _load_tree(args.run_dir)
+ run = _load_run(args.run_dir)
+ nodes = tree["nodes"]
+
+ symbol = {
+ "root": "*",
+ "pending": "o",
+ "running": "~",
+ "executed": "=",
+ "merged": "V",
+ "pruned": "x",
+ }
+
+ def render(nid, prefix=""):
+ n = nodes[nid]
+ sym = symbol.get(n["status"], "?")
+ best = " <== M_best" if nid == run["best_node"] else ""
+ print(f"{prefix}[{sym}] {nid} {n['hypothesis'][:70]}{_fmt_score(n, run)}{best}")
+ kids = sorted(_children(tree, nid))
+ for i, c in enumerate(kids):
+ render(c, prefix + " ")
+
+ print(f"Run: {run['objective']}")
+ print(f"Cycle {run['cycles_used']}/{run['budget_cycles']} | legend: * root o pending ~ running = executed V merged x pruned\n")
+ render(tree["root"])
+
+
+def cmd_validate(args):
+ """Check invariants — catch a corrupted or inconsistent tree early."""
+ tree = _load_tree(args.run_dir)
+ run = _load_run(args.run_dir)
+ nodes = tree["nodes"]
+ problems = []
+ if tree["root"] not in nodes:
+ problems.append("root id not present in nodes")
+ for nid, n in nodes.items():
+ p = n.get("parent")
+ if p is not None and p not in nodes:
+ problems.append(f"{nid}: parent {p} missing")
+ if n["status"] not in VALID_STATUS:
+ problems.append(f"{nid}: invalid status {n['status']}")
+ if run["best_node"] and run["best_node"] not in nodes:
+ problems.append(f"best_node {run['best_node']} missing")
+ merged = [nid for nid, n in nodes.items() if n["status"] == "merged"]
+ if run["best_node"] and run["best_node"] not in merged and run["best_node"] != tree["root"]:
+ problems.append(f"best_node {run['best_node']} is not marked merged")
+ if problems:
+ print("INVALID:")
+ for p in problems:
+ print(f" - {p}")
+ sys.exit(1)
+ print(f"OK — {len(nodes)} nodes, root={tree['root']}, best={run['best_node']}")
+
+
+# ----------------------------------------------------------------------------
+# CLI
+# ----------------------------------------------------------------------------
+
+
+def build_parser():
+ p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
+ p.add_argument("--run-dir", default=".", help="Run directory holding .arbor/ (default: current dir)")
+ sub = p.add_subparsers(dest="command", required=True)
+
+ s = sub.add_parser("init", help="Initialize a new AO run / hypothesis tree")
+ s.add_argument("--objective", required=True, help="Natural-language research objective (root hypothesis)")
+ s.add_argument("--dev-eval", required=True, help="Command/description of the development evaluator")
+ s.add_argument("--test-eval", required=True, help="Command/description of the held-out test evaluator")
+ s.add_argument("--material", default="", help="Path/ref to the initial artifact M_0")
+ s.add_argument("--metric-direction", choices=["max", "min"], default="max", help="Is higher or lower the better score?")
+ s.add_argument("--branching", type=int, default=3, help="Max children proposed per parent (k)")
+ s.add_argument("--max-depth", type=int, default=2, help="Max tree depth (directions at 1, interventions at 2+)")
+ s.add_argument("--budget", type=int, default=20, help="Coordinator cycle budget B")
+ s.add_argument("--force", action="store_true", help="Overwrite an existing run")
+ s.set_defaults(func=cmd_init)
+
+ s = sub.add_parser("observe", help="Print the research-state projection (start of each cycle)")
+ s.set_defaults(func=cmd_observe)
+
+ s = sub.add_parser("add-node", help="Add a pending child hypothesis under a parent (Ideate)")
+ s.add_argument("--parent", required=True, help="Parent node id (n0 for a new research direction)")
+ s.add_argument("--hypothesis", required=True, help="Falsifiable claim this node tests")
+ s.set_defaults(func=cmd_add_node)
+
+ s = sub.add_parser("set-status", help="Set a node's status manually")
+ s.add_argument("--node", required=True)
+ s.add_argument("--status", required=True, help=f"One of {sorted(VALID_STATUS)}")
+ s.set_defaults(func=cmd_set_status)
+
+ s = sub.add_parser("set-evidence", help="Write an executor report into its node (Backpropagate, leaf)")
+ s.add_argument("--node", required=True)
+ s.add_argument("--dev-score", type=float, default=None, help="Dev evaluator score returned by the executor")
+ s.add_argument("--result", default=None, help="Factual result summary")
+ s.add_argument("--insight", default=None, help="Distilled, reusable lesson from this experiment")
+ s.add_argument("--branch-ref", default=None, help="Git branch/commit/worktree path of the artifact")
+ s.add_argument("--status", default=None, help="Override status (default: executed)")
+ s.set_defaults(func=cmd_set_evidence)
+
+ s = sub.add_parser("propagate", help="Abstract a leaf insight up to ancestors (Backpropagate, upward)")
+ s.add_argument("--node", required=True, help="The leaf the lesson came from")
+ s.add_argument("--insight", required=True, help="Direction-level abstraction of the lesson")
+ s.add_argument("--to-root", action="store_true", help="Also record as a global insight on the root")
+ s.set_defaults(func=cmd_propagate)
+
+ s = sub.add_parser("prune", help="Prune a falsified node and its subtree (Decide)")
+ s.add_argument("--node", required=True)
+ s.add_argument("--reason", default="", help="Why this direction is a dead end (becomes a negative constraint)")
+ s.set_defaults(func=cmd_prune)
+
+ s = sub.add_parser("merge", help="Record a held-out merge gate decision (Decide)")
+ s.add_argument("--node", required=True)
+ s.add_argument("--test-score", type=float, required=True, help="Score on the TEST evaluator in a fresh worktree")
+ s.add_argument("--branch-ref", default=None, help="Artifact ref to promote if it passes")
+ s.set_defaults(func=cmd_merge)
+
+ s = sub.add_parser("cycle", help="Increment the coordinator cycle counter")
+ s.set_defaults(func=cmd_cycle)
+
+ s = sub.add_parser("status", help="Render the tree as ASCII (for reports)")
+ s.set_defaults(func=cmd_status)
+
+ s = sub.add_parser("validate", help="Check tree invariants")
+ s.set_defaults(func=cmd_validate)
+
+ return p
+
+
+def main():
+ args = build_parser().parse_args()
+ args.func(args)
+
+
+if __name__ == "__main__":
+ main()