tuieval 0.2.0.dev166__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/CHANGELOG.md +6 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/PKG-INFO +1 -1
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/agent-packs.md +30 -2
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/_version.py +2 -2
- tuieval-0.3.0/src/tuieval/adapters/__init__.py +1 -0
- tuieval-0.3.0/src/tuieval/adapters/pi.py +352 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/agents.py +14 -4
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/builtin.toml +12 -2
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/compare.py +10 -1
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/engine.py +5 -3
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/tests/test_tuieval.py +157 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/.gitignore +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/LICENSE +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/README.md +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/RELEASING.md +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/README.md +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/favicon.ico +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/readme-header.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/social-preview.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-1024.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-128.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-16.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-16.svg +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-256.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-32.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-48.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-512.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-64.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon-animated.svg +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/brand/tuieval-icon.svg +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/tui-answer-reasoning.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/tui-run-reasoning.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/images/tui-setup.png +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/models.md +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/docs/writing-packs.md +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/pyproject.toml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/__init__.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/__main__.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/cli.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/client.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/ctxbench.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/dates.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/doctor.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/export.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/graders/__init__.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/graders/answer.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/graders/code.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/graders/rag.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/graders/reply.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/graders/tool_call.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/insights.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/logs.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/machines.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/onboard.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/packs.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/profiles.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/pta.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/remove.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/run_evals.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/scaffold.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/selftest.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/models.toml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/answer/pack.toml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/answer/system.txt +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/answer/tests.yaml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/code/pack.toml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/code/system.txt +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/code/tests.yaml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/rag/pack.toml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/rag/system.txt +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/rag/tests.yaml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/reply/pack.toml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/reply/system.txt +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/reply/tests.yaml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/tool_call/pack.toml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/tool_call/system.txt +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/tool_call/tests.yaml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/templates/packs/tool_call/tools.yaml +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/tui.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/tune.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/verdict.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/watch_proxy.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/workspace.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/src/tuieval/yamlout.py +0 -0
- {tuieval-0.2.0.dev166 → tuieval-0.3.0}/tests/mock_server.py +0 -0
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.3.0
|
|
6
|
+
|
|
7
|
+
- Built-in pi agents for agent packs: `agent = "pi"` runs bare pi on the served model (sandboxed on macOS, with none of your pi setup), and `agent = "pi-scouts"` adds pi's subagent tool and a read-only `scout` agent on the same model, which the lead may send in parallel. Agent commands can use `{tuieval_python}`, the Python tuieval runs with. Agents can report `subagent_*` stats, and `tuieval compare` shows a **subagent tasks** column when they do. See docs/agent-packs.md.
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
5
11
|
- `tuieval tune --ctx` starts where the model file says the limit is, instead of climbing from a small context: for a GGUF on a llama.cpp-style server it estimates the largest context that fits (weights, buffers, and the KV cache per token with sliding-window layers counted as llama.cpp keeps them), tries that first, and lets the first reading predict whether more fits. Typically 1 or 2 server starts, down from 3 to 6 (Gemma 4 31B: one, at its 262,144 limit, where it took five). The estimate is dropped when a try's memory is more than 25% off it; MLA models, models larger than memory and servers that size their own memory keep the doubling search. The saved measurement records where it started (`started_from`, `estimated_ctx`).
|
|
6
12
|
- Sections: pack.toml `use_case` (default: the pack's `group`) is what a pack's verdict counts toward, so a section (`group`) can hold several use cases. The model list's verdict codes, the Readiness tab and Insights' best model per use case show use cases section by section in pack order, with a divider or heading per section (the Readiness tab was alphabetical).
|
|
7
13
|
- Drafter files: a model can name a separate drafter file (`draft = "…gguf"`), and tune options that use `{draft}` are offered only to models that have one. A server's `[servers.<name>.drafts]` table names kinds of drafter by GGUF metadata, for options that use `{draft_<kind>}`. See docs/models.md.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: tuieval
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Evaluate local and frontier LLMs on your own questions: accuracy, speed, tokens and PASS/FAIL verdicts, in the terminal.
|
|
5
5
|
Project-URL: Homepage, https://github.com/ashe-wb/tuieval
|
|
6
6
|
Project-URL: Issues, https://github.com/ashe-wb/tuieval/issues
|
|
@@ -76,6 +76,33 @@ agent = "my-agent"
|
|
|
76
76
|
|
|
77
77
|
The agent's name and command are part of an agent pack's settings, so changing the command reruns the pack. The agent's version isn't: each answer records it, and `tuieval compare` marks a pack that ran on more than one version as MIXED.
|
|
78
78
|
|
|
79
|
+
### Built in: pi
|
|
80
|
+
|
|
81
|
+
Two agents come built in, for [pi](https://github.com/earendil-works/pi). Name one in a pack (`agent = "pi"`) or in `[defaults]`; pi must be on your PATH. An `[agents.pi]` or `[agents.pi-scouts]` of your own replaces the built-in one.
|
|
82
|
+
|
|
83
|
+
| Agent | What it runs |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `pi` | bare pi on the model tuieval serves |
|
|
86
|
+
| `pi-scouts` | the same, plus pi's subagent tool and a read-only `scout` agent on the same model |
|
|
87
|
+
|
|
88
|
+
```toml
|
|
89
|
+
# what they are (builtin.toml); {tuieval_python} is the Python tuieval runs with
|
|
90
|
+
[agents.pi]
|
|
91
|
+
cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi"]
|
|
92
|
+
|
|
93
|
+
[agents.pi-scouts]
|
|
94
|
+
cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi", "--scouts"]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- **Bare:** pi gets a scratch config folder with one provider, the model tuieval serves, using its context size and sampling. It runs with no extensions, skills, context files, prompt templates, themes, MCP or saved session, so your own pi setup never changes a result. The model's `reasoning_effort` becomes pi's thinking level.
|
|
98
|
+
- **Sandboxed on macOS:** pi and everything it runs can't read your home folder or the temp folders, apart from the task's work folder, the adapter's scratch folder and the pack's Python. They can write only the work folder and the scratch folder. So the model can't look up hidden tests or reference fixes, or leave notes for the next model. `TUIEVAL_NO_SANDBOX=1` turns this off, and the run line then says `sandbox OFF`. Other systems have no sandbox.
|
|
99
|
+
- **Scouts:** `pi-scouts` adds pi's example subagent extension, found next to the pi on your PATH, and one agent, `scout`, with read-only tools (`read`, `grep`, `find`, `ls`) on the same model at thinking `low`.
|
|
100
|
+
- The lead gets one line saying the tool exists; the task text is unchanged, and whether to delegate is the lead's own choice.
|
|
101
|
+
- Scouts run inside the same sandbox.
|
|
102
|
+
- Their turns and tokens are counted in the task's totals and reported as `subagent_*` stats.
|
|
103
|
+
- The turn limit counts the lead's turns only.
|
|
104
|
+
- **Comparing:** a pack whose `tasks/` is a link to another pack's tasks runs the same tasks with another agent. So `agentic-coding` with `agent = "pi"` beside `agentic-coding-scouts` with `agent = "pi-scouts"` shows each model with and without scouts.
|
|
105
|
+
|
|
79
106
|
Most agents need a small **adapter**: a script that reads what tuieval provides, starts the agent with it, and writes the stats file. pi, Aider, Codex CLI, OpenCode and similar agents can all be wrapped this way. The adapter gets everything from its environment:
|
|
80
107
|
|
|
81
108
|
| Variable | Contents |
|
|
@@ -105,6 +132,7 @@ Most agents need a small **adapter**: a script that reads what tuieval provides,
|
|
|
105
132
|
- **`tool_errors`:** count failed edits and malformed tool calls, not commands that exit nonzero.
|
|
106
133
|
- **`stop`:** `done`, `turn limit` or `error`.
|
|
107
134
|
- **`server_error`:** if the model's server failed rather than the model, write this key with the error text. The task isn't counted and is asked again.
|
|
135
|
+
- **`subagent_calls`, `subagent_tasks`, `subagent_failed`, `subagent_turns`, `subagent_input_tokens`, `subagent_output_tokens`:** work the agent handed to subagents. Count those tokens in `input_tokens` and `output_tokens` too.
|
|
108
136
|
|
|
109
137
|
A minimal adapter:
|
|
110
138
|
|
|
@@ -133,10 +161,10 @@ Agent tasks appear wherever other answers do: Per question, Failures, the scorec
|
|
|
133
161
|
- its final message and its changes as a diff;
|
|
134
162
|
- the full transcript, with the test output;
|
|
135
163
|
- under **What's checked**, the visible and hidden tests.
|
|
136
|
-
- **`tuieval compare`:** adds an **Agent tasks** table per model and pack. It shows tasks passed, median minutes and turns, output tokens, tool errors, how often the tests were run, limits hit, tests edited, and the agent version.
|
|
164
|
+
- **`tuieval compare`:** adds an **Agent tasks** table per model and pack. It shows tasks passed, median minutes and turns, output tokens, tool errors, how often the tests were run, limits hit, tests edited, and the agent version. When an agent reports subagent stats, a **subagent tasks** column shows how many tasks it handed out, in how many calls.
|
|
137
165
|
|
|
138
166
|
`tuieval regrade` leaves agent results alone: they're graded when they run, so retest the pack instead.
|
|
139
167
|
|
|
140
168
|
## Safety
|
|
141
169
|
|
|
142
|
-
⚠️ The agent runs commands as you, with your permissions. It works in a scratch folder, but nothing stops it from reaching outside that folder. Run agent packs in a container or VM with no credentials in the environment. The hidden tests and reference fixes live in your pack folder, so an agent that searched your disk could find them. The transcript would show it.
|
|
170
|
+
⚠️ The agent runs commands as you, with your permissions. It works in a scratch folder, but apart from the built-in pi agents' macOS sandbox, nothing stops it from reaching outside that folder. Run agent packs in a container or VM with no credentials in the environment. The hidden tests and reference fixes live in your pack folder, so an agent that searched your disk could find them. The transcript would show it.
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.
|
|
22
|
-
__version_tuple__ = version_tuple = (0,
|
|
21
|
+
__version__ = version = '0.3.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 3, 0)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Adapters that run command-line agents for agent packs (docs/agent-packs.md)."""
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"""The built-in adapter for pi (https://github.com/earendil-works/pi), for agent packs: runs bare pi on the
|
|
2
|
+
model tuieval serves.
|
|
3
|
+
|
|
4
|
+
[agents.pi] cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi"] (built in)
|
|
5
|
+
[agents.pi-scouts] cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi", "--scouts"] (built in)
|
|
6
|
+
|
|
7
|
+
pi gets a scratch config folder with one provider, "tuieval", pointing at TUIEVAL_BASE_URL (context size and
|
|
8
|
+
sampling from tuieval), and runs with no extensions, skills, context files, prompt templates, themes, MCP or saved
|
|
9
|
+
session, so your own pi setup never changes a result. One line per turn and tool call is printed for the live
|
|
10
|
+
view; the stats go to TUIEVAL_STATS_FILE.
|
|
11
|
+
|
|
12
|
+
On macOS pi runs inside a sandbox (sandbox-exec, see sandbox_profile): it can't read your home folder or the temp
|
|
13
|
+
folders, apart from the task's work folder, the adapter's own scratch folder and the pack's Python, and it can
|
|
14
|
+
write only those two folders. So a model can't look up hidden tests or reference fixes, or leave notes for the
|
|
15
|
+
next model. HOME and TMPDIR point into the scratch folder. TUIEVAL_NO_SANDBOX=1 turns the sandbox off (the run
|
|
16
|
+
line then says "sandbox OFF"); without sandbox-exec (other systems) there is none.
|
|
17
|
+
|
|
18
|
+
--scouts adds pi's example subagent extension (the one explicit -e; everything else stays off) and one agent,
|
|
19
|
+
"scout": read-only tools (read, grep, find, ls), the model tuieval serves at thinking "low", and SCOUT_PROMPT.
|
|
20
|
+
The lead gets one appended system line saying the tool exists (SCOUT_HINT); the task text is unchanged, and
|
|
21
|
+
whether to delegate is the lead's own choice. Scouts are child pi processes of the sandboxed pi, so the sandbox
|
|
22
|
+
covers them too, and they use the same scratch config. Their turns and tokens are added to the run's totals and
|
|
23
|
+
also written as subagent_* stats; the turn limit counts the lead's turns only.
|
|
24
|
+
|
|
25
|
+
Standard library only: it runs with tuieval's own Python, whatever the pack's Python is.
|
|
26
|
+
"""
|
|
27
|
+
import json
|
|
28
|
+
import os
|
|
29
|
+
import shutil
|
|
30
|
+
import signal
|
|
31
|
+
import subprocess
|
|
32
|
+
import sys
|
|
33
|
+
import tempfile
|
|
34
|
+
|
|
35
|
+
PI_LEVELS = ("off", "minimal", "low", "medium", "high", "xhigh", "max")
|
|
36
|
+
SAMPLING_KEYS = ("temperature", "top_p", "top_k", "min_p", "presence_penalty", "repeat_penalty")
|
|
37
|
+
# provider errors that are the server's fault, not the model's (tuieval asks the task again)
|
|
38
|
+
SERVER_ERRORS = ("ECONNREFUSED", "ECONNRESET", "socket hang up", "fetch failed", "502", "503",
|
|
39
|
+
"Internal Server Error", "Service Unavailable", "Bad Gateway")
|
|
40
|
+
SUBAGENT_STATS = ("subagent_calls", "subagent_tasks", "subagent_failed", "subagent_turns", "subagent_input_tokens",
|
|
41
|
+
"subagent_output_tokens")
|
|
42
|
+
|
|
43
|
+
SCOUT_HINT = ("You have a `subagent` tool with a read-only `scout` agent (read, grep, find, ls). When a task needs "
|
|
44
|
+
"context from several independent parts of the code, you can send scouts in parallel to gather it "
|
|
45
|
+
"first; edits, commands and tests stay with you.")
|
|
46
|
+
SCOUT_PROMPT = """You are a scout. Quickly investigate a codebase and return structured findings that another agent can use without re-reading everything.
|
|
47
|
+
|
|
48
|
+
Your output will be passed to an agent who has NOT seen the files you explored.
|
|
49
|
+
|
|
50
|
+
Thoroughness (infer from task, default medium):
|
|
51
|
+
- Quick: Targeted lookups, key files only
|
|
52
|
+
- Medium: Follow imports, read critical sections
|
|
53
|
+
- Thorough: Trace all dependencies, check tests/types
|
|
54
|
+
|
|
55
|
+
Strategy:
|
|
56
|
+
1. grep/find to locate relevant code
|
|
57
|
+
2. Read key sections (not entire files)
|
|
58
|
+
3. Identify types, interfaces, key functions
|
|
59
|
+
4. Note dependencies between files
|
|
60
|
+
|
|
61
|
+
Output format:
|
|
62
|
+
|
|
63
|
+
## Files Retrieved
|
|
64
|
+
List with exact line ranges:
|
|
65
|
+
1. `path/to/file.ts` (lines 10-50) - Description of what's here
|
|
66
|
+
2. `path/to/other.ts` (lines 100-150) - Description
|
|
67
|
+
3. ...
|
|
68
|
+
|
|
69
|
+
## Key Code
|
|
70
|
+
Critical types, interfaces, or functions:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
interface Example {
|
|
74
|
+
// actual code from the files
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
function keyFunction() {
|
|
80
|
+
// actual implementation
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Architecture
|
|
85
|
+
Brief explanation of how the pieces connect.
|
|
86
|
+
|
|
87
|
+
## Start Here
|
|
88
|
+
Which file to look at first and why.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def pi_version():
|
|
93
|
+
try:
|
|
94
|
+
out = subprocess.run(["pi", "--version"], capture_output=True, text=True, timeout=30).stdout.strip()
|
|
95
|
+
return f"pi {out}" if out else "pi"
|
|
96
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
97
|
+
return "pi"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def subagent_extension():
|
|
101
|
+
"""pi's example subagent extension, found from the pi on PATH (its package root holds examples/)."""
|
|
102
|
+
d = os.path.dirname(os.path.realpath(shutil.which("pi") or "pi"))
|
|
103
|
+
while d != os.path.dirname(d):
|
|
104
|
+
pkg = os.path.join(d, "package.json")
|
|
105
|
+
if os.path.isfile(pkg):
|
|
106
|
+
try:
|
|
107
|
+
name = json.load(open(pkg)).get("name", "")
|
|
108
|
+
except ValueError:
|
|
109
|
+
name = ""
|
|
110
|
+
if name.endswith("/pi-coding-agent"):
|
|
111
|
+
ext = os.path.join(d, "examples", "extensions", "subagent", "index.ts")
|
|
112
|
+
if os.path.isfile(ext):
|
|
113
|
+
return ext
|
|
114
|
+
break
|
|
115
|
+
d = os.path.dirname(d)
|
|
116
|
+
return None
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def config(dest, sampling, model_id, scouts=False):
|
|
120
|
+
"""A pi config folder with one provider, "tuieval", serving model_id (and, for scouts, the scout agent)."""
|
|
121
|
+
ctx = int(os.environ.get("TUIEVAL_CONTEXT") or 32768)
|
|
122
|
+
params = {k: sampling[k] for k in SAMPLING_KEYS if k in sampling}
|
|
123
|
+
if "enable_thinking" in sampling:
|
|
124
|
+
params["chat_template_kwargs"] = {"enable_thinking": bool(sampling["enable_thinking"])}
|
|
125
|
+
model = {"id": model_id, "name": model_id, "reasoning": True, "input": ["text"], "contextWindow": ctx,
|
|
126
|
+
"maxTokens": min(int(sampling.get("max_tokens") or 16384), ctx), "samplingParams": params,
|
|
127
|
+
# requests like tuieval's own: max_tokens (not max_completion_tokens), and reasoning_effort only
|
|
128
|
+
# when the model sets one (pi would otherwise send its default level)
|
|
129
|
+
"compat": {"maxTokensField": "max_tokens",
|
|
130
|
+
**({} if sampling.get("reasoning_effort") else {"supportsReasoningEffort": False})}}
|
|
131
|
+
providers = {"tuieval": {"baseUrl": os.environ["TUIEVAL_BASE_URL"], "api": "openai-completions",
|
|
132
|
+
"apiKey": os.environ.get("TUIEVAL_API_KEY") or "none", "models": [model]}}
|
|
133
|
+
os.makedirs(dest, mode=0o700, exist_ok=True)
|
|
134
|
+
with open(os.path.join(dest, "models.json"), "w") as f:
|
|
135
|
+
json.dump({"providers": providers}, f, indent=1)
|
|
136
|
+
with open(os.path.join(dest, "settings.json"), "w") as f:
|
|
137
|
+
json.dump({"quietStartup": True}, f)
|
|
138
|
+
if scouts:
|
|
139
|
+
os.makedirs(os.path.join(dest, "agents"), exist_ok=True)
|
|
140
|
+
with open(os.path.join(dest, "agents", "scout.md"), "w") as f:
|
|
141
|
+
f.write("---\nname: scout\ndescription: Fast codebase recon that returns compressed context for handoff "
|
|
142
|
+
f"to other agents\ntools: read, grep, find, ls\nmodel: tuieval/{model_id}:low\n---\n\n"
|
|
143
|
+
+ SCOUT_PROMPT)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def sandbox_profile(work, scratch, python_dirs):
|
|
147
|
+
"""A macOS sandbox (sandbox-exec) profile for pi and everything it runs, so a model can't look up answers
|
|
148
|
+
or leave notes for the next model:
|
|
149
|
+
reads nothing in your home folder, the temp folders or /Volumes, except the task's work folder, the
|
|
150
|
+
adapter's own scratch folder (pi config, HOME, TMPDIR) and the pack's Python
|
|
151
|
+
writes only the work folder, the scratch folder and /dev
|
|
152
|
+
escapes no Apple Events (Office, Terminal, System Events…), no LaunchServices (`open -a …`), no
|
|
153
|
+
launchctl/at/crontab, no ssh to this Mac: each would run code outside the sandbox
|
|
154
|
+
Everything else (the pi install, system libraries, the network to the model server) is allowed."""
|
|
155
|
+
q = lambda p: json.dumps(os.path.realpath(p)) # SBPL strings use the same escapes as JSON
|
|
156
|
+
home = os.path.realpath(os.path.expanduser("~"))
|
|
157
|
+
hidden = [home, "/private/tmp", "/private/var/tmp", "/private/var/folders"]
|
|
158
|
+
hidden += [p for p in ("/Volumes",) if os.path.isdir(p)]
|
|
159
|
+
ok_rw = [work, scratch]
|
|
160
|
+
rules = ["(version 1)", "(allow default)",
|
|
161
|
+
"(deny file-read* " + " ".join(f"(subpath {q(p)})" for p in hidden) + ")",
|
|
162
|
+
"(allow file-read* " + " ".join(f"(subpath {q(p)})" for p in ok_rw + python_dirs) + ")",
|
|
163
|
+
"(allow file-read-metadata)", # stat() on parent folders, which path lookups need; no contents
|
|
164
|
+
"(deny file-write* (require-not (require-any "
|
|
165
|
+
+ " ".join(f"(subpath {q(p)})" for p in ok_rw) + ' (subpath "/dev"))))',
|
|
166
|
+
"(deny appleevent-send)",
|
|
167
|
+
'(deny mach-lookup (global-name "com.apple.coreservices.launchservicesd")'
|
|
168
|
+
' (global-name "com.apple.coreservices.quarantine-resolver"))',
|
|
169
|
+
'(deny process-exec (literal "/bin/launchctl") (literal "/usr/bin/at") (literal "/usr/bin/crontab")'
|
|
170
|
+
' (literal "/usr/bin/open") (literal "/usr/bin/ssh") (literal "/usr/bin/osascript")'
|
|
171
|
+
' (literal "/usr/bin/shortcuts") (literal "/usr/bin/automator"))',
|
|
172
|
+
'(deny network-outbound (remote tcp "localhost:22"))']
|
|
173
|
+
return "\n".join(rules)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def python_dirs():
|
|
177
|
+
"""Folders the pack's Python needs to read: its venv (first on PATH, put there by tuieval) and the base
|
|
178
|
+
install the venv points at."""
|
|
179
|
+
dirs = []
|
|
180
|
+
first = (os.environ.get("PATH") or "").split(os.pathsep)[0]
|
|
181
|
+
venv = os.path.dirname(first)
|
|
182
|
+
cfg = os.path.join(venv, "pyvenv.cfg")
|
|
183
|
+
if os.path.isfile(cfg):
|
|
184
|
+
dirs.append(venv)
|
|
185
|
+
for line in open(cfg):
|
|
186
|
+
k, _, v = line.partition("=")
|
|
187
|
+
if k.strip() == "home" and v.strip():
|
|
188
|
+
dirs.append(os.path.dirname(os.path.realpath(v.strip()))) # …/bin -> the install
|
|
189
|
+
return dirs
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def thinking(sampling):
|
|
193
|
+
if sampling.get("enable_thinking") is False:
|
|
194
|
+
return "off"
|
|
195
|
+
effort = sampling.get("reasoning_effort")
|
|
196
|
+
return effort if effort in PI_LEVELS else None
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def short(v, n=140):
|
|
200
|
+
v = " ".join(str(v).split())
|
|
201
|
+
return v if len(v) <= n else v[:n - 1] + "…"
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def add_subagents(stats, ev):
|
|
205
|
+
"""Count a finished subagent tool call (pi's example extension) into stats; returns its summary line."""
|
|
206
|
+
rs = ((ev.get("result") or {}).get("details") or {}).get("results") or []
|
|
207
|
+
stats["subagent_calls"] += 1
|
|
208
|
+
turns = out = 0
|
|
209
|
+
for r in rs:
|
|
210
|
+
u = r.get("usage") or {}
|
|
211
|
+
stats["subagent_tasks"] += 1
|
|
212
|
+
stats["subagent_failed"] += int(r.get("exitCode") not in (0, None) or r.get("status") == "failed")
|
|
213
|
+
tokens_in = (u.get("input") or 0) + (u.get("cacheRead") or 0)
|
|
214
|
+
stats["subagent_turns"] += u.get("turns") or 0
|
|
215
|
+
stats["subagent_input_tokens"] += tokens_in
|
|
216
|
+
stats["subagent_output_tokens"] += u.get("output") or 0
|
|
217
|
+
stats["input_tokens"] += tokens_in
|
|
218
|
+
stats["output_tokens"] += u.get("output") or 0
|
|
219
|
+
turns += u.get("turns") or 0
|
|
220
|
+
out += u.get("output") or 0
|
|
221
|
+
if ev.get("isError"):
|
|
222
|
+
stats["tool_errors"] += 1
|
|
223
|
+
return f" subagents: {len(rs)} task(s), {turns} turns, {out} output tokens" + (" [error]" if ev.get("isError") else "")
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def build_command(model_id, sampling, prompt, scouts, extension):
|
|
227
|
+
cmd = ["pi", "--mode", "json", "--no-session", "--no-extensions", "--no-skills", "--no-context-files",
|
|
228
|
+
"--no-prompt-templates", "--no-themes", "--no-mcp", "--no-approve", "--offline",
|
|
229
|
+
"--model", "tuieval/" + model_id]
|
|
230
|
+
if scouts:
|
|
231
|
+
cmd += ["-e", extension, "--append-system-prompt", SCOUT_HINT]
|
|
232
|
+
level = thinking(sampling)
|
|
233
|
+
if level:
|
|
234
|
+
cmd += ["--thinking", level]
|
|
235
|
+
return cmd + ["--", prompt], level
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def main(argv=None):
|
|
239
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
240
|
+
scouts = "--scouts" in argv
|
|
241
|
+
sampling = json.loads(os.environ.get("TUIEVAL_SAMPLING") or "{}")
|
|
242
|
+
max_turns = int(os.environ.get("TUIEVAL_MAX_TURNS") or 40)
|
|
243
|
+
prompt = open(os.environ["TUIEVAL_PROMPT_FILE"]).read()
|
|
244
|
+
model_id = os.environ["TUIEVAL_MODEL_ID"]
|
|
245
|
+
stats = {"agent": pi_version() + (" + scouts" if scouts else ""), "turns": 0, "input_tokens": 0,
|
|
246
|
+
"output_tokens": 0, "tool_calls": 0, "tool_errors": 0, "ran_tests": False, "stop": "", "final_message": ""}
|
|
247
|
+
extension = None
|
|
248
|
+
if scouts:
|
|
249
|
+
stats.update(dict.fromkeys(SUBAGENT_STATS, 0))
|
|
250
|
+
extension = subagent_extension()
|
|
251
|
+
if not extension:
|
|
252
|
+
print("pi's examples/extensions/subagent/index.ts wasn't found next to the pi on PATH", flush=True)
|
|
253
|
+
stats.update(stop="error", final_message="no subagent extension")
|
|
254
|
+
save(stats)
|
|
255
|
+
return 1
|
|
256
|
+
tmp = tempfile.mkdtemp(prefix="pi-adapter-")
|
|
257
|
+
cfg_dir = os.path.join(tmp, "pi-config")
|
|
258
|
+
config(cfg_dir, sampling, model_id, scouts)
|
|
259
|
+
cmd, level = build_command(model_id, sampling, prompt, scouts, extension)
|
|
260
|
+
env = dict(os.environ, PI_CODING_AGENT_DIR=cfg_dir, PI_OFFLINE="1", PI_TELEMETRY="0")
|
|
261
|
+
shown = " ".join(cmd[:-1])
|
|
262
|
+
sandbox = os.environ.get("TUIEVAL_NO_SANDBOX") != "1" and shutil.which("sandbox-exec")
|
|
263
|
+
if sandbox:
|
|
264
|
+
fake_home, fake_tmp = os.path.join(tmp, "home"), os.path.join(tmp, "tmp")
|
|
265
|
+
os.makedirs(fake_home)
|
|
266
|
+
os.makedirs(fake_tmp)
|
|
267
|
+
env.update(HOME=fake_home, TMPDIR=fake_tmp + "/", ZDOTDIR=fake_home)
|
|
268
|
+
pi = shutil.which("pi") or "pi"
|
|
269
|
+
cmd = ["sandbox-exec", "-p", sandbox_profile(os.getcwd(), tmp, python_dirs()), pi] + cmd[1:]
|
|
270
|
+
print(f"$ {shown} <task> (thinking {level or 'default'}, max {max_turns} turns, "
|
|
271
|
+
f"sandbox {'on' if sandbox else 'OFF'})", flush=True)
|
|
272
|
+
try:
|
|
273
|
+
proc = subprocess.Popen(cmd, env=env, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
|
|
274
|
+
stderr=subprocess.PIPE, start_new_session=True)
|
|
275
|
+
except OSError as e:
|
|
276
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
277
|
+
stats.update(stop="error", final_message=f"can't start pi: {e}")
|
|
278
|
+
save(stats)
|
|
279
|
+
return 1
|
|
280
|
+
|
|
281
|
+
def stop_pi(*_):
|
|
282
|
+
try:
|
|
283
|
+
os.killpg(proc.pid, signal.SIGKILL)
|
|
284
|
+
except ProcessLookupError:
|
|
285
|
+
pass
|
|
286
|
+
signal.signal(signal.SIGTERM, lambda *a: (stop_pi(), save(stats), sys.exit(1)))
|
|
287
|
+
error = ""
|
|
288
|
+
try:
|
|
289
|
+
for raw in iter(proc.stdout.readline, b""):
|
|
290
|
+
try:
|
|
291
|
+
ev = json.loads(raw)
|
|
292
|
+
except ValueError:
|
|
293
|
+
continue
|
|
294
|
+
kind = ev.get("type")
|
|
295
|
+
if kind == "message_end" and ev.get("message", {}).get("role") == "assistant":
|
|
296
|
+
m = ev["message"]
|
|
297
|
+
u = m.get("usage") or {}
|
|
298
|
+
stats["turns"] += 1
|
|
299
|
+
stats["output_tokens"] += u.get("output") or 0
|
|
300
|
+
stats["input_tokens"] += (u.get("input") or 0) + (u.get("cacheRead") or 0)
|
|
301
|
+
text = "".join(c.get("text", "") for c in m.get("content", []) if c.get("type") == "text").strip()
|
|
302
|
+
if text:
|
|
303
|
+
stats["final_message"] = text
|
|
304
|
+
if m.get("errorMessage"):
|
|
305
|
+
error = str(m["errorMessage"])
|
|
306
|
+
print(f"turn {stats['turns']}: {u.get('output') or 0} tokens, {m.get('stopReason')}"
|
|
307
|
+
+ (f": {short(text)}" if text else "") + (f" [error: {short(error)}]" if error else ""),
|
|
308
|
+
flush=True)
|
|
309
|
+
if stats["turns"] >= max_turns and m.get("stopReason") == "toolUse":
|
|
310
|
+
stats["stop"] = "turn limit"
|
|
311
|
+
print(f"turn limit ({max_turns}) reached", flush=True)
|
|
312
|
+
break
|
|
313
|
+
elif kind == "tool_execution_start":
|
|
314
|
+
stats["tool_calls"] += 1
|
|
315
|
+
args = ev.get("args") or {}
|
|
316
|
+
what = args.get("command") or args.get("path") or json.dumps(args)
|
|
317
|
+
if "pytest" in json.dumps(args) or "unittest" in json.dumps(args):
|
|
318
|
+
stats["ran_tests"] = True
|
|
319
|
+
print(f" {ev.get('toolName')}: {short(what)}", flush=True)
|
|
320
|
+
elif kind == "tool_execution_end" and ev.get("toolName") == "subagent" and scouts:
|
|
321
|
+
print(add_subagents(stats, ev), flush=True)
|
|
322
|
+
elif kind == "tool_execution_end" and ev.get("isError"):
|
|
323
|
+
if ev.get("toolName") != "bash": # a failed edit or a bad call, not a failing command
|
|
324
|
+
stats["tool_errors"] += 1
|
|
325
|
+
out = " ".join(c.get("text", "") for c in (ev.get("result") or {}).get("content", []))
|
|
326
|
+
print(f" ! {ev.get('toolName')} failed: {short(out)}", flush=True)
|
|
327
|
+
elif kind == "agent_settled":
|
|
328
|
+
stats["stop"] = stats["stop"] or ("error" if ev.get("aborted") or error else "done")
|
|
329
|
+
break
|
|
330
|
+
finally:
|
|
331
|
+
stop_pi()
|
|
332
|
+
proc.wait()
|
|
333
|
+
err = proc.stderr.read().decode("utf-8", "replace").strip()
|
|
334
|
+
if err:
|
|
335
|
+
print("pi stderr: " + short(err, 600), flush=True)
|
|
336
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
337
|
+
if not stats["stop"]:
|
|
338
|
+
stats["stop"] = "error"
|
|
339
|
+
error = error or f"pi exited ({proc.returncode})"
|
|
340
|
+
if error and any(s in error for s in SERVER_ERRORS):
|
|
341
|
+
stats["server_error"] = error # the server failed, not the model: tuieval asks the task again
|
|
342
|
+
save(stats)
|
|
343
|
+
return 0
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def save(stats):
|
|
347
|
+
with open(os.environ["TUIEVAL_STATS_FILE"], "w") as f:
|
|
348
|
+
json.dump(stats, f)
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
if __name__ == "__main__":
|
|
352
|
+
sys.exit(main())
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"""Agent packs: coding tasks a command-line agent works on, graded by tests.
|
|
2
2
|
|
|
3
|
-
models.toml says how to start each agent (any program; {root} is the workspace
|
|
3
|
+
models.toml says how to start each agent (any program; {root} is the workspace, {tuieval_python} the Python
|
|
4
|
+
tuieval runs with):
|
|
4
5
|
|
|
5
6
|
[agents.my-agent]
|
|
6
7
|
cmd = ["python3", "{root}/agents/my_agent.py"]
|
|
7
8
|
|
|
9
|
+
Built in (builtin.toml, replaced by an [agents.<name>] of the same name): "pi" and "pi-scouts", pi through
|
|
10
|
+
tuieval/adapters/pi.py.
|
|
11
|
+
|
|
8
12
|
[defaults]
|
|
9
13
|
agent = "my-agent" # for agent packs that don't name one (pack.toml agent = "...")
|
|
10
14
|
|
|
@@ -28,9 +32,11 @@ The agent learns the rest from its environment:
|
|
|
28
32
|
TUIEVAL_STATS_FILE where it may write its stats as JSON when it finishes (all optional):
|
|
29
33
|
agent ("name version"), turns, input_tokens, output_tokens, tool_calls,
|
|
30
34
|
tool_errors (failed edits, bad tool calls; not commands that exit nonzero),
|
|
31
|
-
ran_tests, stop ("done", "turn limit" or "error"), final_message,
|
|
35
|
+
ran_tests, stop ("done", "turn limit" or "error"), final_message,
|
|
32
36
|
server_error: the model's server failed, not the model (the task isn't counted
|
|
33
|
-
and is asked again)
|
|
37
|
+
and is asked again), and subagent_calls, subagent_tasks, subagent_failed,
|
|
38
|
+
subagent_turns, subagent_input_tokens, subagent_output_tokens for work handed to
|
|
39
|
+
subagents (also counted in input_tokens and output_tokens)
|
|
34
40
|
|
|
35
41
|
PATH starts with the pack's Python (pack.toml python, else tuieval's), so `python` runs the tasks'
|
|
36
42
|
code and tests. The agent's exit code decides nothing; the tests do.
|
|
@@ -55,8 +61,12 @@ PROMPT_TAIL = "\n\nYou're working in a project in the current directory. Run Pyt
|
|
|
55
61
|
GRADE_TIMEOUT_S = 300
|
|
56
62
|
DIFF_KEEP = 20_000 # characters of the diff kept in the result (the whole diff is in the log)
|
|
57
63
|
HIDDEN_RE = re.compile(r"\.?_hidden\b") # junit names of the hidden tests (a collection error starts with ".")
|
|
64
|
+
# subagent_*: work the agent handed to subagents (counted in its own input/output tokens too), e.g. the
|
|
65
|
+
# built-in pi-scouts agent's scouts
|
|
66
|
+
SUBAGENT_KEYS = ("subagent_calls", "subagent_tasks", "subagent_failed", "subagent_turns", "subagent_input_tokens",
|
|
67
|
+
"subagent_output_tokens")
|
|
58
68
|
STATS_KEYS = ("agent", "turns", "input_tokens", "output_tokens", "tool_calls", "tool_errors", "ran_tests", "stop",
|
|
59
|
-
"final_message", "server_error")
|
|
69
|
+
"final_message", "server_error", *SUBAGENT_KEYS)
|
|
60
70
|
|
|
61
71
|
|
|
62
72
|
class AgentError(Exception):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Built-in defaults and
|
|
1
|
+
# Built-in defaults, servers and agents, used when a workspace's models.toml doesn't define them.
|
|
2
2
|
# [defaults] fill in key by key; [sampling] only when models.toml has no [sampling] at all (it's part of
|
|
3
|
-
# every result's fingerprint); a server here is replaced whole by one of the same name in models.toml.
|
|
3
|
+
# every result's fingerprint); a server or agent here is replaced whole by one of the same name in models.toml.
|
|
4
4
|
|
|
5
5
|
[defaults]
|
|
6
6
|
repeat = 3
|
|
@@ -85,3 +85,13 @@ pin_endpoint = true
|
|
|
85
85
|
api_key_env = "OPENROUTER_API_KEY"
|
|
86
86
|
thinking_param = "reasoning" # [sampling] enable_thinking -> OpenRouter's reasoning.enabled
|
|
87
87
|
headers = { "X-Title" = "tuieval" }
|
|
88
|
+
|
|
89
|
+
# pi (https://github.com/earendil-works/pi) for agent packs, through the built-in adapter (tuieval/adapters/pi.py):
|
|
90
|
+
# bare pi on the served model, sandboxed on macOS. pi-scouts adds pi's subagent extension and a read-only "scout"
|
|
91
|
+
# agent on the same model, which the lead may send in parallel. pi must be on PATH. {tuieval_python} is the
|
|
92
|
+
# Python tuieval runs with. Use one in a pack with agent = "pi" (pack.toml) or [defaults] agent = "pi".
|
|
93
|
+
[agents.pi]
|
|
94
|
+
cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi"]
|
|
95
|
+
|
|
96
|
+
[agents.pi-scouts]
|
|
97
|
+
cmd = ["{tuieval_python}", "-m", "tuieval.adapters.pi", "--scouts"]
|
|
@@ -639,7 +639,9 @@ def items(rows):
|
|
|
639
639
|
|
|
640
640
|
def agent_table(rows):
|
|
641
641
|
"""(header, table) summing up agent-pack tasks per model and pack, or None without any. A pack run
|
|
642
|
-
by more than one agent version is marked, since a new version can change how models do.
|
|
642
|
+
by more than one agent version is marked, since a new version can change how models do. A
|
|
643
|
+
"subagent tasks" column (tasks handed to subagents, out of the agent's calls) appears only when
|
|
644
|
+
some agent reported subagent stats."""
|
|
643
645
|
groups = collections.defaultdict(list)
|
|
644
646
|
for r in rows:
|
|
645
647
|
if r.get("agent"):
|
|
@@ -648,6 +650,9 @@ def agent_table(rows):
|
|
|
648
650
|
return None
|
|
649
651
|
header = ["model", "pack", "passed", "med min", "med turns", "out tokens", "tool errors", "ran tests",
|
|
650
652
|
"limits hit", "tests edited", "agent"]
|
|
653
|
+
subagents = any("subagent_tasks" in r["agent"] for rs in groups.values() for r in rs)
|
|
654
|
+
if subagents:
|
|
655
|
+
header.insert(-1, "subagent tasks")
|
|
651
656
|
table = []
|
|
652
657
|
for (model, suite), rs in sorted(groups.items()):
|
|
653
658
|
a = [r["agent"] for r in rs]
|
|
@@ -662,6 +667,10 @@ def agent_table(rows):
|
|
|
662
667
|
str(sum(x.get("stop") in ("time limit", "turn limit") for x in a)),
|
|
663
668
|
str(sum(bool(x.get("tests_edited")) for x in a)),
|
|
664
669
|
" + ".join(versions) + (" (MIXED)" if len(versions) > 1 else "")])
|
|
670
|
+
if subagents:
|
|
671
|
+
sub = [x for x in a if "subagent_tasks" in x]
|
|
672
|
+
table[-1].insert(-1, f"{sum(x['subagent_tasks'] for x in sub)} in "
|
|
673
|
+
f"{sum(x.get('subagent_calls') or 0 for x in sub)} calls" if sub else "-")
|
|
665
674
|
return header, table
|
|
666
675
|
|
|
667
676
|
|
|
@@ -45,6 +45,7 @@ import socket
|
|
|
45
45
|
import statistics
|
|
46
46
|
import string
|
|
47
47
|
import subprocess
|
|
48
|
+
import sys
|
|
48
49
|
import tempfile
|
|
49
50
|
import threading
|
|
50
51
|
import time
|
|
@@ -105,7 +106,7 @@ def hosted(cfg, m):
|
|
|
105
106
|
def load_config(path):
|
|
106
107
|
"""Read models.toml, fill in the built-ins it leaves out (builtin.toml) and each model's defaults.
|
|
107
108
|
[defaults] are filled key by key; [sampling] only when models.toml has none (sampling is part of
|
|
108
|
-
every result's fingerprint, so a workspace's own keys are never added to); servers by name."""
|
|
109
|
+
every result's fingerprint, so a workspace's own keys are never added to); servers and agents by name."""
|
|
109
110
|
with open(path, "rb") as f:
|
|
110
111
|
cfg = tomllib.load(f)
|
|
111
112
|
builtin = builtin_config()
|
|
@@ -117,6 +118,7 @@ def load_config(path):
|
|
|
117
118
|
own = cfg.get("servers", {})
|
|
118
119
|
cfg["servers"] = {**builtin["servers"], **own}
|
|
119
120
|
cfg["builtin_servers"] = sorted(set(builtin["servers"]) - set(own)) # not defined in models.toml
|
|
121
|
+
cfg["agents"] = {**builtin.get("agents", {}), **cfg.get("agents", {})}
|
|
120
122
|
cfg.setdefault("models", [])
|
|
121
123
|
seen = set()
|
|
122
124
|
for m in cfg["models"]:
|
|
@@ -2310,7 +2312,7 @@ class Engine:
|
|
|
2310
2312
|
python = agents.python_for(job.pack, self.root)
|
|
2311
2313
|
m, s = job.model, job.sampling
|
|
2312
2314
|
key_env = self.cfg["servers"][m["server"]].get("api_key_env")
|
|
2313
|
-
cmd = [expand(str(a), root=self.root) for a in agent["cmd"]]
|
|
2315
|
+
cmd = [expand(str(a), root=self.root, tuieval_python=sys.executable) for a in agent["cmd"]]
|
|
2314
2316
|
live = os.path.join(self.log_dir, "live")
|
|
2315
2317
|
os.makedirs(live, exist_ok=True)
|
|
2316
2318
|
waits = list(self.SERVER_RETRY_WAITS_S)
|
|
@@ -2377,7 +2379,7 @@ class Engine:
|
|
|
2377
2379
|
"agent": {"name": name, "version": stats.get("agent"), "stop": stop if stop != "exited" else
|
|
2378
2380
|
stats.get("stop") or "exited",
|
|
2379
2381
|
**{k: stats[k] for k in ("turns", "input_tokens", "output_tokens", "tool_calls",
|
|
2380
|
-
"tool_errors", "ran_tests") if k in stats},
|
|
2382
|
+
"tool_errors", "ran_tests", *agents.SUBAGENT_KEYS) if k in stats},
|
|
2381
2383
|
"exit_code": code, "tests_edited": edited, "visible": g["visible"],
|
|
2382
2384
|
"hidden": g["hidden"], "failed": g["failed"], "diff": patch[:agents.DIFF_KEEP],
|
|
2383
2385
|
"diff_cut": len(patch) > agents.DIFF_KEEP}}
|
|
@@ -8,6 +8,7 @@ import json
|
|
|
8
8
|
import math
|
|
9
9
|
import os
|
|
10
10
|
import re
|
|
11
|
+
import shutil
|
|
11
12
|
import socket
|
|
12
13
|
import subprocess
|
|
13
14
|
import sys
|
|
@@ -3877,6 +3878,11 @@ elif mode == "loop":
|
|
|
3877
3878
|
time.sleep(0.3)
|
|
3878
3879
|
elif mode == "crash":
|
|
3879
3880
|
sys.exit(3)
|
|
3881
|
+
elif mode == "subagents": # fixes it, reporting work handed to two subagents
|
|
3882
|
+
src = open("calc.py").read()
|
|
3883
|
+
open("calc.py", "w").write(src.replace("a - b", "a + b").replace("a + a", "a * b"))
|
|
3884
|
+
save(turns=2, ran_tests=True, stop="done", final_message="Fixed with help", subagent_calls=1, subagent_tasks=2,
|
|
3885
|
+
subagent_failed=0, subagent_turns=6, subagent_input_tokens=900, subagent_output_tokens=120)
|
|
3880
3886
|
elif mode == "flaky": # the model's server fails once per task, then the agent fixes it
|
|
3881
3887
|
mark = os.path.join(here, "failed-" + os.environ["TUIEVAL_TASK"])
|
|
3882
3888
|
if not os.path.exists(mark):
|
|
@@ -4111,6 +4117,157 @@ class AgentPacks(unittest.TestCase):
|
|
|
4111
4117
|
p = tuieval(self.ws, "regrade")
|
|
4112
4118
|
self.assertIn("agent pack is graded by its tests when it runs", p.stdout)
|
|
4113
4119
|
|
|
4120
|
+
def test_tuieval_python_placeholder_and_subagent_stats(self):
|
|
4121
|
+
text = read(os.path.join(self.ws, "models.toml")).replace(json.dumps(sys.executable) + ', "{root}',
|
|
4122
|
+
'"{tuieval_python}", "{root}')
|
|
4123
|
+
write(os.path.join(self.ws, "models.toml"), text)
|
|
4124
|
+
self.mode("subagents")
|
|
4125
|
+
p = self.run_pack()
|
|
4126
|
+
self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
|
|
4127
|
+
data, rows = self.rows()
|
|
4128
|
+
self.assertEqual(data["agent"]["cmd"], ["{tuieval_python}", "{root}/agents/fake_agent.py"]) # as written
|
|
4129
|
+
a = rows["add"]["agent"]
|
|
4130
|
+
self.assertTrue(rows["add"]["pass"], rows["add"]["reason"])
|
|
4131
|
+
self.assertEqual((a["subagent_calls"], a["subagent_tasks"], a["subagent_turns"], a["subagent_output_tokens"]),
|
|
4132
|
+
(1, 2, 6, 120))
|
|
4133
|
+
out = tuieval(self.ws, "compare").stdout
|
|
4134
|
+
self.assertIn("subagent tasks", out)
|
|
4135
|
+
self.assertRegex(out, r"\nm\s+agentic\s+2/2\s.*\s4 in 2 calls\s+fake 1.0\n")
|
|
4136
|
+
|
|
4137
|
+
def test_builtin_pi_agents(self):
|
|
4138
|
+
from tuieval import engine
|
|
4139
|
+
cfg = engine.load_config(os.path.join(self.ws, "models.toml"))
|
|
4140
|
+
self.assertEqual(cfg["agents"]["pi"]["cmd"], ["{tuieval_python}", "-m", "tuieval.adapters.pi"])
|
|
4141
|
+
self.assertEqual(cfg["agents"]["pi-scouts"]["cmd"][-1], "--scouts")
|
|
4142
|
+
self.assertIn("fake", cfg["agents"]) # the workspace's own stay
|
|
4143
|
+
with open(os.path.join(self.ws, "models.toml"), "a") as f:
|
|
4144
|
+
f.write('\n[agents.pi]\ncmd = ["my-pi"]\n')
|
|
4145
|
+
self.assertEqual(engine.load_config(os.path.join(self.ws, "models.toml"))["agents"]["pi"]["cmd"], ["my-pi"])
|
|
4146
|
+
|
|
4147
|
+
|
|
4148
|
+
FAKE_PI = r'''
|
|
4149
|
+
"""A fake pi for the adapter tests: records how it was started, then prints a scripted --mode json session."""
|
|
4150
|
+
import json, os, sys
|
|
4151
|
+
|
|
4152
|
+
if sys.argv[1:] == ["--version"]:
|
|
4153
|
+
print("9.9.9")
|
|
4154
|
+
sys.exit(0)
|
|
4155
|
+
cfg = os.environ["PI_CODING_AGENT_DIR"]
|
|
4156
|
+
scout = os.path.join(cfg, "agents", "scout.md")
|
|
4157
|
+
with open(os.environ["FAKE_PI_LOG"], "w") as f:
|
|
4158
|
+
json.dump({"argv": sys.argv[1:], "models": json.load(open(os.path.join(cfg, "models.json"))),
|
|
4159
|
+
"scout": open(scout).read() if os.path.exists(scout) else None}, f)
|
|
4160
|
+
|
|
4161
|
+
|
|
4162
|
+
def emit(ev):
|
|
4163
|
+
print(json.dumps(ev), flush=True)
|
|
4164
|
+
|
|
4165
|
+
|
|
4166
|
+
emit({"type": "tool_execution_start", "toolName": "read", "args": {"path": "calc.py"}})
|
|
4167
|
+
emit({"type": "tool_execution_end", "toolName": "read"})
|
|
4168
|
+
if "-e" in sys.argv:
|
|
4169
|
+
emit({"type": "tool_execution_start", "toolName": "subagent", "args": {"tasks": [{"agent": "scout"}] * 2}})
|
|
4170
|
+
emit({"type": "tool_execution_end", "toolName": "subagent", "result": {"details": {"mode": "parallel", "results": [
|
|
4171
|
+
{"exitCode": 0, "usage": {"turns": 3, "input": 100, "cacheRead": 50, "output": 40}},
|
|
4172
|
+
{"exitCode": 1, "usage": {"turns": 2, "input": 80, "output": 30}}]}}})
|
|
4173
|
+
emit({"type": "tool_execution_start", "toolName": "bash", "args": {"command": "python -m pytest -q"}})
|
|
4174
|
+
emit({"type": "tool_execution_end", "toolName": "bash"})
|
|
4175
|
+
emit({"type": "message_end", "message": {"role": "assistant", "stopReason": "stop",
|
|
4176
|
+
"usage": {"input": 1000, "cacheRead": 200, "output": 70},
|
|
4177
|
+
"content": [{"type": "text", "text": "Fixed calc.py"}]}})
|
|
4178
|
+
emit({"type": "agent_settled"})
|
|
4179
|
+
'''
|
|
4180
|
+
|
|
4181
|
+
|
|
4182
|
+
class PiAdapter(unittest.TestCase):
|
|
4183
|
+
"""The built-in pi adapter (tuieval.adapters.pi): bare pi on the served model, and with --scouts the
|
|
4184
|
+
subagent extension plus a read-only scout agent on the same model, its work counted as subagent_* stats.
|
|
4185
|
+
Runs against a fake pi in a fake pi install (package.json + examples/extensions/subagent/index.ts)."""
|
|
4186
|
+
|
|
4187
|
+
def setUp(self):
|
|
4188
|
+
self.tmp = tempfile.TemporaryDirectory()
|
|
4189
|
+
t = self.tmp.name
|
|
4190
|
+
self.pkg = os.path.join(t, "lib", "pi-coding-agent")
|
|
4191
|
+
for d in ("bin", os.path.join("examples", "extensions", "subagent")):
|
|
4192
|
+
os.makedirs(os.path.join(self.pkg, d))
|
|
4193
|
+
write(os.path.join(self.pkg, "package.json"), '{"name": "@example/pi-coding-agent"}')
|
|
4194
|
+
write(os.path.join(self.pkg, "examples", "extensions", "subagent", "index.ts"), "// fake")
|
|
4195
|
+
pi = os.path.join(self.pkg, "bin", "pi")
|
|
4196
|
+
write(pi, f"#!{sys.executable}\n" + FAKE_PI)
|
|
4197
|
+
os.chmod(pi, 0o755)
|
|
4198
|
+
self.work = os.path.join(t, "work")
|
|
4199
|
+
os.makedirs(self.work)
|
|
4200
|
+
write(os.path.join(t, "task.md"), "Fix calc.py.\n")
|
|
4201
|
+
self.env = dict(os.environ, PATH=os.path.join(self.pkg, "bin") + os.pathsep + os.environ.get("PATH", ""),
|
|
4202
|
+
TUIEVAL_BASE_URL="http://127.0.0.1:9/v1", TUIEVAL_MODEL_ID="m", TUIEVAL_API_KEY="",
|
|
4203
|
+
TUIEVAL_PROMPT_FILE=os.path.join(t, "task.md"), TUIEVAL_STATS_FILE=os.path.join(t, "stats.json"),
|
|
4204
|
+
TUIEVAL_SAMPLING=json.dumps({"temperature": 0.6, "reasoning_effort": "high", "max_tokens": 8192}),
|
|
4205
|
+
TUIEVAL_CONTEXT="65536", TUIEVAL_MAX_TURNS="40", TUIEVAL_NO_SANDBOX="1",
|
|
4206
|
+
FAKE_PI_LOG=os.path.join(t, "pi.json"))
|
|
4207
|
+
|
|
4208
|
+
def tearDown(self):
|
|
4209
|
+
self.tmp.cleanup()
|
|
4210
|
+
|
|
4211
|
+
def run_adapter(self, *args):
|
|
4212
|
+
p = subprocess.run([sys.executable, "-m", "tuieval.adapters.pi", *args], cwd=self.work, env=self.env,
|
|
4213
|
+
capture_output=True, text=True, timeout=120)
|
|
4214
|
+
return (p, json.loads(read(self.env["TUIEVAL_STATS_FILE"])), json.loads(read(self.env["FAKE_PI_LOG"])))
|
|
4215
|
+
|
|
4216
|
+
def test_bare_pi(self):
|
|
4217
|
+
p, stats, seen = self.run_adapter()
|
|
4218
|
+
self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
|
|
4219
|
+
argv = seen["argv"]
|
|
4220
|
+
for flag in ("--no-extensions", "--no-skills", "--no-context-files", "--no-mcp", "--no-session"):
|
|
4221
|
+
self.assertIn(flag, argv)
|
|
4222
|
+
self.assertNotIn("-e", argv)
|
|
4223
|
+
self.assertEqual(argv[argv.index("--model") + 1], "tuieval/m")
|
|
4224
|
+
self.assertEqual(argv[argv.index("--thinking") + 1], "high")
|
|
4225
|
+
self.assertEqual(argv[-2:], ["--", "Fix calc.py.\n"])
|
|
4226
|
+
model = seen["models"]["providers"]["tuieval"]["models"][0]
|
|
4227
|
+
self.assertEqual((model["contextWindow"], model["maxTokens"], model["samplingParams"]["temperature"]),
|
|
4228
|
+
(65536, 8192, 0.6))
|
|
4229
|
+
self.assertIsNone(seen["scout"])
|
|
4230
|
+
self.assertEqual((stats["agent"], stats["turns"], stats["input_tokens"], stats["output_tokens"]),
|
|
4231
|
+
("pi 9.9.9", 1, 1200, 70))
|
|
4232
|
+
self.assertEqual((stats["tool_calls"], stats["ran_tests"], stats["stop"], stats["final_message"]),
|
|
4233
|
+
(2, True, "done", "Fixed calc.py"))
|
|
4234
|
+
self.assertNotIn("subagent_tasks", stats)
|
|
4235
|
+
self.assertIn("sandbox OFF", p.stdout)
|
|
4236
|
+
|
|
4237
|
+
def test_scouts(self):
|
|
4238
|
+
p, stats, seen = self.run_adapter("--scouts")
|
|
4239
|
+
self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
|
|
4240
|
+
argv = seen["argv"]
|
|
4241
|
+
self.assertEqual(argv[argv.index("-e") + 1],
|
|
4242
|
+
os.path.realpath(os.path.join(self.pkg, "examples", "extensions", "subagent", "index.ts")))
|
|
4243
|
+
self.assertIn("--no-extensions", argv) # still bare apart from the one extension
|
|
4244
|
+
self.assertIn("scout", argv[argv.index("--append-system-prompt") + 1])
|
|
4245
|
+
self.assertIn("model: tuieval/m:low", seen["scout"])
|
|
4246
|
+
self.assertIn("tools: read, grep, find, ls", seen["scout"])
|
|
4247
|
+
self.assertEqual(stats["agent"], "pi 9.9.9 + scouts")
|
|
4248
|
+
self.assertEqual({k: stats[k] for k in stats if k.startswith("subagent_")},
|
|
4249
|
+
{"subagent_calls": 1, "subagent_tasks": 2, "subagent_failed": 1, "subagent_turns": 5,
|
|
4250
|
+
"subagent_input_tokens": 230, "subagent_output_tokens": 70})
|
|
4251
|
+
self.assertEqual((stats["input_tokens"], stats["output_tokens"]), (1200 + 230, 70 + 70)) # included
|
|
4252
|
+
self.assertEqual(stats["tool_calls"], 3)
|
|
4253
|
+
self.assertIn("subagents: 2 task(s), 5 turns, 70 output tokens", p.stdout)
|
|
4254
|
+
|
|
4255
|
+
def test_scouts_without_the_extension_is_an_error(self):
|
|
4256
|
+
os.remove(os.path.join(self.pkg, "examples", "extensions", "subagent", "index.ts"))
|
|
4257
|
+
p = subprocess.run([sys.executable, "-m", "tuieval.adapters.pi", "--scouts"], cwd=self.work, env=self.env,
|
|
4258
|
+
capture_output=True, text=True, timeout=60)
|
|
4259
|
+
self.assertNotEqual(p.returncode, 0)
|
|
4260
|
+
self.assertIn("subagent/index.ts wasn't found", p.stdout)
|
|
4261
|
+
self.assertEqual(json.loads(read(self.env["TUIEVAL_STATS_FILE"]))["stop"], "error")
|
|
4262
|
+
|
|
4263
|
+
@unittest.skipUnless(sys.platform == "darwin" and shutil.which("sandbox-exec"), "macOS sandbox")
|
|
4264
|
+
def test_sandbox_profile_hides_home_but_not_the_work_folder(self):
|
|
4265
|
+
from tuieval.adapters import pi
|
|
4266
|
+
prof = pi.sandbox_profile(self.work, self.tmp.name, [])
|
|
4267
|
+
self.assertIn(json.dumps(os.path.realpath(os.path.expanduser("~"))), prof)
|
|
4268
|
+
self.assertIn(json.dumps(os.path.realpath(self.work)), prof)
|
|
4269
|
+
self.assertIn("(deny appleevent-send)", prof)
|
|
4270
|
+
|
|
4114
4271
|
|
|
4115
4272
|
class ContextBench(unittest.TestCase):
|
|
4116
4273
|
"""tuieval tune --ctx: the largest context a server can be started with, found by filling it."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|