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.

fix(arbor): render node IDs in numeric creation order

Timothy Kassis351845e1c72f
diff --git a/skills/arbor/SKILL.md b/skills/arbor/SKILL.md
index 8e57ea09..f99dfd36 100644
--- a/skills/arbor/SKILL.md
+++ b/skills/arbor/SKILL.md
@@ -4,7 +4,7 @@ description: Autonomously improve a real artifact (code, training recipe, agent
allowed-tools: Read Write Edit Bash Agent
license: MIT license
metadata:
- version: "1.4"
+ version: "1.5"
skill-author: K-Dense Inc.
---
diff --git a/skills/arbor/scripts/tree.py b/skills/arbor/scripts/tree.py
index 05e85c0d..af00f36b 100644
--- a/skills/arbor/scripts/tree.py
+++ b/skills/arbor/scripts/tree.py
@@ -87,6 +87,13 @@ def _next_id(tree):
return f"n{n}"
+def _id_sort_key(node_id):
+ """Order generated ids numerically, then any manually assigned ids by name."""
+ if isinstance(node_id, str) and node_id.startswith("n") and node_id[1:].isdecimal():
+ return (0, int(node_id[1:]), node_id)
+ return (1, 0, str(node_id))
+
+
def _node(tree, node_id):
node = tree["nodes"].get(node_id)
if node is None:
@@ -393,7 +400,7 @@ def cmd_observe(args):
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"]):
+ for n in sorted(frontier, key=lambda x: _id_sort_key(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()
@@ -407,7 +414,7 @@ def cmd_observe(args):
print("\n-- Executed / merged nodes (evidence) --")
if not executed:
print(" (none yet)")
- for n in sorted(executed, key=lambda x: x["id"]):
+ for n in sorted(executed, key=lambda x: _id_sort_key(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]}")
@@ -417,7 +424,7 @@ def cmd_observe(args):
print("\n-- Pruned lessons (negative constraints — avoid these) --")
if not pruned:
print(" (none yet)")
- for n in sorted(pruned, key=lambda x: x["id"]):
+ for n in sorted(pruned, key=lambda x: _id_sort_key(x["id"])):
reason = n["metadata"].get("prune_reason", "")
print(f" {n['id']}: {n['hypothesis']}" + (f" — {reason}" if reason else ""))
@@ -448,7 +455,7 @@ def cmd_status(args):
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))
+ kids = sorted(_children(tree, nid), key=_id_sort_key)
for i, c in enumerate(kids):
render(c, prefix + " ")
diff --git a/tests/arbor/test_scripts.py b/tests/arbor/test_scripts.py
index 5b405759..d1665b3c 100644
--- a/tests/arbor/test_scripts.py
+++ b/tests/arbor/test_scripts.py
@@ -16,6 +16,7 @@ from __future__ import annotations
import io
import json
+import re
import sys
import tempfile
import unittest
@@ -446,6 +447,31 @@ class ValidateTests(ArborRunTestCase):
class ProjectionTests(ArborRunTestCase):
+ def test_each_observe_list_uses_numeric_node_order(self) -> None:
+ self.init()
+ ids = [f"n{i}" for i in range(1, 13)]
+ for nid in ids:
+ self.run_command("add-node", "--parent", "n0", "--hypothesis", f"idea {nid}")
+ for status in ("running", "executed", "pruned"):
+ with self.subTest(status=status):
+ for nid in ids:
+ self.run_command("set-status", "--node", nid, "--status", status)
+ before = self.tree
+ out, _ = self.run_command("observe")
+ self.assertEqual(re.findall(r"^\s+(n\d+)\b", out, re.MULTILINE), ids)
+ self.assertEqual(self.tree, before)
+
+ def test_status_preserves_depth_first_order_with_numeric_siblings(self) -> None:
+ self.init()
+ for i in range(11):
+ self.run_command("add-node", "--parent", "n0", "--hypothesis", f"idea {i}")
+ self.run_command("add-node", "--parent", "n2", "--hypothesis", "nested idea")
+ before = self.tree
+ out, _ = self.run_command("status")
+ ids = re.findall(r"^\s*\[.\] (n\d+)\b", out, re.MULTILINE)
+ self.assertEqual(ids, ["n0", "n1", "n2", "n12", *[f"n{i}" for i in range(3, 12)]])
+ self.assertEqual(self.tree, before)
+
def test_observe_reports_the_objective_and_every_node(self) -> None:
self.init(objective="Reduce inference latency")
self.run_command("add-node", "--parent", "n0", "--hypothesis", "quantise weights")