python-yama 0.4.0__py3-none-any.whl → 0.6.0__py3-none-any.whl
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.
- {python_yama-0.4.0.dist-info → python_yama-0.6.0.dist-info}/METADATA +16 -2
- {python_yama-0.4.0.dist-info → python_yama-0.6.0.dist-info}/RECORD +13 -10
- yama/assertions.py +32 -3
- yama/cli.py +298 -27
- yama/dashboard.py +320 -0
- yama/llm.py +52 -18
- yama/preview.py +384 -0
- yama/report.py +741 -243
- yama/runner.py +221 -18
- yama/thread_case.py +401 -0
- {python_yama-0.4.0.dist-info → python_yama-0.6.0.dist-info}/WHEEL +0 -0
- {python_yama-0.4.0.dist-info → python_yama-0.6.0.dist-info}/entry_points.txt +0 -0
- {python_yama-0.4.0.dist-info → python_yama-0.6.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-yama
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: A reproducible evaluation runner for tool-using Agent skills
|
|
5
5
|
Project-URL: Repository, https://github.com/world-sim-dev/yama
|
|
6
6
|
Project-URL: Issues, https://github.com/world-sim-dev/yama/issues
|
|
@@ -19,6 +19,7 @@ Requires-Dist: fastapi>=0.139.0
|
|
|
19
19
|
Requires-Dist: jinja2>=3.1
|
|
20
20
|
Requires-Dist: litellm<2.0,>=1.80
|
|
21
21
|
Requires-Dist: orjson>=3.11.9
|
|
22
|
+
Requires-Dist: python-dotenv>=1.0
|
|
22
23
|
Requires-Dist: pyyaml>=6.0
|
|
23
24
|
Requires-Dist: rich<15.0,>=14.1
|
|
24
25
|
Description-Content-Type: text/markdown
|
|
@@ -40,6 +41,8 @@ OPENAI_API_KEY=... uv run --project yama yama
|
|
|
40
41
|
OPENAI_API_KEY=... uv run --project yama yama --plugin dingding-simple
|
|
41
42
|
```
|
|
42
43
|
|
|
44
|
+
Instead of prefixing every command, you can put credentials in a `.env` file: on startup the CLI loads the nearest `.env` found from the working directory upward (variables already set in the environment are not overridden).
|
|
45
|
+
|
|
43
46
|
## Writing a Case
|
|
44
47
|
|
|
45
48
|
A Case is a YAML file organized as `context` (what the model sees) → `mocks` (how tool calls get executed) → `steps` (user turns sent in order, each with assertions) → `outcome` (the pass bar for the whole Case):
|
|
@@ -96,11 +99,22 @@ uv run --project yama yama --plugin dingding-simple --report
|
|
|
96
99
|
| `-k, --filter PATTERN` (repeatable) | Only run cases whose case key (path relative to the plugin root) matches — a substring, or an fnmatch glob when the pattern contains `*` `?` `[`; with several patterns a case runs if any matches |
|
|
97
100
|
| `--result-dir PATH` | Override the artifact root (default `<plugin_root>/.yama/runs`) |
|
|
98
101
|
| `--concurrency N` | Maximum number of cases running in parallel (default 10; `1` runs cases one at a time) |
|
|
99
|
-
| `--report [PATH]` | Also generate a single-file HTML report (
|
|
102
|
+
| `--report [PATH]` | Also generate a single-file HTML report. Without PATH it writes a timestamped `.yama/reports/report-<ts>.html` (history accumulates) and keeps `.yama/reports/latest.html` as a symlink to the newest one; an explicit PATH writes exactly that file |
|
|
103
|
+
| `--preview` | Don't run anything (no LLM calls): resolve the collected Cases and write an HTML case preview (default `.yama/reports/preview.html`; `--report PATH` overrides), or print a JSON preview to stdout when combined with `--json` |
|
|
100
104
|
| `--list` | Only print the collected Cases, without running them |
|
|
101
105
|
| `--no-artifacts` | Write no artifact files at all |
|
|
102
106
|
| `--json` | Emit machine-readable JSON instead of Rich tables |
|
|
103
107
|
|
|
104
108
|
`--plugin`, `--all-plugins`, and `--plugin-root` are mutually exclusive. When none of them is given, yama walks up from the current directory to the nearest directory containing `yama.toml` and uses it as the workspace root (falling back to the cwd), running it as a single plugin root.
|
|
105
109
|
|
|
110
|
+
### Dashboard
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
uv run --project yama yama dashboard --plugin dingding-simple
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`yama dashboard` starts a local HTTP server (default `http://127.0.0.1:8765/`, change with `--host`/`--port`; it also accepts the same plugin selection flags as the main command plus `-k/--filter` and `--result-dir`). The index page lists the historical HTML reports accumulated under `.yama/reports/` (newest first, with the `latest` one flagged), `/reports/<name>` serves each report, and `/preview` renders the same case preview as `--preview` — re-collecting and re-resolving the case files on every refresh (collection errors render as an error page), so you can edit a Case YAML and just reload the browser. No LLM calls are ever made by the dashboard.
|
|
117
|
+
|
|
118
|
+
### Output
|
|
119
|
+
|
|
106
120
|
Cases run in parallel, up to 10 at a time by default (`--concurrency` changes the cap); runs within one case stay sequential, and results keep collection order regardless of completion order. While several cases run concurrently, a transient dashboard at the bottom of the terminal shows one row per case, updated in place — waiting, then a spinner with the run/step currently executing, then its ✓/✗ verdict — and each case's full run/step detail is printed above the dashboard as one block the moment it finishes, so blocks of different cases never interleave. With `--concurrency 1` (or a single collected case) it streams instead — a spinner marks the step currently executing (on a terminal), and each case, run, and assertion result is printed the moment it completes. Either way a per-case summary table closes the output, and with `--json` the progress stream goes to stderr so stdout stays valid JSON.
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
yama/__init__.py,sha256=UYhoZTSu1HiMT54LOZCdvLKMQ_L0qec8RT8jDfde_cY,1156
|
|
2
2
|
yama/__main__.py,sha256=k1ocEWawweo1qCJWNFAAvyxz3tcY13dzvCenHszij30,48
|
|
3
|
-
yama/assertions.py,sha256=
|
|
4
|
-
yama/cli.py,sha256=
|
|
5
|
-
yama/
|
|
3
|
+
yama/assertions.py,sha256=9tp_fuoFxqHPrClq_D1WF4i58TxgZUMnTdc-Kc9uKiw,23000
|
|
4
|
+
yama/cli.py,sha256=ipNWX1_2o7jy5NmYU3LyKmoPo68VF-LO6A2F8QQw9Tk,34699
|
|
5
|
+
yama/dashboard.py,sha256=0yxRh-j_5Mk6Ug_xgv9-VyBSEr1aVKxX-zJwxGfd_TU,11601
|
|
6
|
+
yama/llm.py,sha256=JzQ4YHhBLd1WE8W_ipTVcoNK6f-nSqRKDzqEl5kmuis,16085
|
|
6
7
|
yama/mocks.py,sha256=YyiU6Y7NgttxHYJBsqGPILKYlTsM4IMTIilMNRkUuzs,14973
|
|
7
8
|
yama/models.py,sha256=0BMCWku5zWDOESrFUibiJShlfEhOAGlVKaNxfPB-9OM,4020
|
|
8
|
-
yama/
|
|
9
|
-
yama/
|
|
9
|
+
yama/preview.py,sha256=gVTMqArXQqOLktGnactK9c0kfX6oHd6fWGjhkB7-QLQ,14220
|
|
10
|
+
yama/report.py,sha256=GyJ7oMKYwrLlt3hFXw6915er-6SWU4nr_Qhx37UJA2c,59590
|
|
11
|
+
yama/runner.py,sha256=zACo6shEqV-9Y_bu4bZs2vjdgaPPr5qj0KylTlqevEs,33549
|
|
12
|
+
yama/thread_case.py,sha256=ZaQvuu1uj9o9adTIbYghYp9iXEVqhEmoG4_b6duHYy0,13147
|
|
10
13
|
yama/workspace.py,sha256=4GAe36Uj1-gjROMPwrQfTIg1TkzEIk9-gHEuezjbY_I,4614
|
|
11
14
|
yama/loaders/__init__.py,sha256=DIwfa8QlIlKt6NpFMZJ_OcqbJPPrmKLBzd9_e-BCuBs,174
|
|
12
15
|
yama/loaders/case.py,sha256=5uUpXm1t9EOmee2BZe7vDGXCrc4CSgcFGApSkuFe5tc,13954
|
|
@@ -20,8 +23,8 @@ yama/tools/bash/bash.py,sha256=4GlFvmqTUS4k6DgJ5Io91YF5fB6wF6e3e7p2P-pmbEQ,10358
|
|
|
20
23
|
yama/tools/bash/fs.py,sha256=GChDwGe_Sgn73btZJDNp5nOwlVDhLfZyaMVqWSQwfOw,21859
|
|
21
24
|
yama/tools/skill/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
25
|
yama/tools/skill/skill.py,sha256=H2KdIBLkYhecYX7M2xbn79csDpDvougpRcAmlrwigEM,2235
|
|
23
|
-
python_yama-0.
|
|
24
|
-
python_yama-0.
|
|
25
|
-
python_yama-0.
|
|
26
|
-
python_yama-0.
|
|
27
|
-
python_yama-0.
|
|
26
|
+
python_yama-0.6.0.dist-info/METADATA,sha256=z4vYMlK6PlFbY6ydnGbCKwJFHDFSfDxc2UyAMeJZnvA,7515
|
|
27
|
+
python_yama-0.6.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
28
|
+
python_yama-0.6.0.dist-info/entry_points.txt,sha256=N5se3y1FflUcDU3TmUrH2Tu9dzsrBBo7sUP-Gu_2cVs,39
|
|
29
|
+
python_yama-0.6.0.dist-info/licenses/LICENSE,sha256=cMAJJAs7R1lemJPPc7qMNv4w_sqn5QncFf4aXKYyEc4,1067
|
|
30
|
+
python_yama-0.6.0.dist-info/RECORD,,
|
yama/assertions.py
CHANGED
|
@@ -16,6 +16,28 @@ class AssertionConfigurationError(ValueError):
|
|
|
16
16
|
pass
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
DEFAULT_HARD_ASSERTION_TAG = "must_pass"
|
|
20
|
+
HARD_ASSERTION_TAG_THRESHOLDS: dict[str, float] = {
|
|
21
|
+
"must_pass": 1.0,
|
|
22
|
+
"high_confidence": 0.9,
|
|
23
|
+
"tolerant": 0.8,
|
|
24
|
+
"informational": 0.0,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def normalize_hard_assertion_tag(tag: Any) -> str:
|
|
29
|
+
if tag is None:
|
|
30
|
+
return DEFAULT_HARD_ASSERTION_TAG
|
|
31
|
+
if not isinstance(tag, str):
|
|
32
|
+
raise AssertionConfigurationError("hard assertion 'tag' must be a string")
|
|
33
|
+
if tag not in HARD_ASSERTION_TAG_THRESHOLDS:
|
|
34
|
+
allowed = ", ".join(HARD_ASSERTION_TAG_THRESHOLDS)
|
|
35
|
+
raise AssertionConfigurationError(
|
|
36
|
+
f"unknown hard assertion tag {tag!r}; expected one of: {allowed}"
|
|
37
|
+
)
|
|
38
|
+
return tag
|
|
39
|
+
|
|
40
|
+
|
|
19
41
|
_MISSING = object()
|
|
20
42
|
|
|
21
43
|
|
|
@@ -165,11 +187,18 @@ async def run_hard_assertions(
|
|
|
165
187
|
) -> list[dict[str, Any]]:
|
|
166
188
|
checks: list[dict[str, Any]] = []
|
|
167
189
|
for assertion in assertions:
|
|
168
|
-
if not isinstance(assertion, dict)
|
|
190
|
+
if not isinstance(assertion, dict):
|
|
169
191
|
raise AssertionConfigurationError(
|
|
170
192
|
"each hard assertion must contain exactly one type"
|
|
171
193
|
)
|
|
172
|
-
|
|
194
|
+
tag = normalize_hard_assertion_tag(assertion.get("tag"))
|
|
195
|
+
type_items = {key: value for key, value in assertion.items() if key != "tag"}
|
|
196
|
+
if len(type_items) != 1:
|
|
197
|
+
raise AssertionConfigurationError(
|
|
198
|
+
"each hard assertion must contain exactly one type, plus an "
|
|
199
|
+
"optional string 'tag'"
|
|
200
|
+
)
|
|
201
|
+
kind, config = next(iter(type_items.items()))
|
|
173
202
|
diagnostic = await _run_one(
|
|
174
203
|
kind,
|
|
175
204
|
config,
|
|
@@ -179,7 +208,7 @@ async def run_hard_assertions(
|
|
|
179
208
|
plugin_root=plugin_root,
|
|
180
209
|
relative_root=relative_root,
|
|
181
210
|
)
|
|
182
|
-
checks.append({"type": kind, **diagnostic})
|
|
211
|
+
checks.append({"type": kind, "tag": tag, **diagnostic})
|
|
183
212
|
return checks
|
|
184
213
|
|
|
185
214
|
|
yama/cli.py
CHANGED
|
@@ -8,6 +8,7 @@ from io import StringIO
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from typing import Any
|
|
10
10
|
|
|
11
|
+
from dotenv import find_dotenv, load_dotenv
|
|
11
12
|
from rich import box
|
|
12
13
|
from rich.console import Console, Group
|
|
13
14
|
from rich.live import Live
|
|
@@ -24,10 +25,24 @@ from .workspace import (
|
|
|
24
25
|
load_workspace_config,
|
|
25
26
|
resolve_plugin_root,
|
|
26
27
|
)
|
|
28
|
+
from .dashboard import create_dashboard_server
|
|
27
29
|
from .llm import LLMError, LiteLLMClient
|
|
28
30
|
from .loaders import CollectionError, resolve_case
|
|
29
|
-
from .
|
|
31
|
+
from .preview import preview_payload, write_preview_html
|
|
32
|
+
from .report import write_html_report, write_timestamped_report
|
|
30
33
|
from .runner import YamaRunner, combine_usage
|
|
34
|
+
from .thread_case import (
|
|
35
|
+
ThreadCaseError,
|
|
36
|
+
build_case_dict,
|
|
37
|
+
build_response_preview,
|
|
38
|
+
dump_case_yaml,
|
|
39
|
+
fetch_dsl_at_commit,
|
|
40
|
+
fetch_model_records,
|
|
41
|
+
parse_record_id,
|
|
42
|
+
resolve_dsl_remote_base_dir,
|
|
43
|
+
resolve_dsl_ssh_host,
|
|
44
|
+
select_record,
|
|
45
|
+
)
|
|
31
46
|
|
|
32
47
|
DEFAULT_REPORT = Path("__yama_default_report__")
|
|
33
48
|
|
|
@@ -154,6 +169,8 @@ def build_case_tree(result: Any) -> Tree:
|
|
|
154
169
|
" ",
|
|
155
170
|
(f"Run {run.run_index}", "bold"),
|
|
156
171
|
)
|
|
172
|
+
if getattr(run, "label", None):
|
|
173
|
+
run_label.append(f" · {run.label}", style="cyan")
|
|
157
174
|
run_usage = run.usage()
|
|
158
175
|
if run_usage:
|
|
159
176
|
run_label.append(f" {_usage_label(run_usage)}", style="dim")
|
|
@@ -266,15 +283,13 @@ class ProgressPrinter:
|
|
|
266
283
|
Padding(Text(payload["description"], style="dim"), (0, 0, 0, 2))
|
|
267
284
|
)
|
|
268
285
|
elif event == "run_start":
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
f"Run {payload['run_index']}/{payload['repeat']}",
|
|
273
|
-
style="bold",
|
|
274
|
-
),
|
|
275
|
-
(0, 0, 0, 2),
|
|
276
|
-
)
|
|
286
|
+
run_line = Text(
|
|
287
|
+
f"Run {payload['run_index']}/{payload['repeat']}",
|
|
288
|
+
style="bold",
|
|
277
289
|
)
|
|
290
|
+
if payload.get("label"):
|
|
291
|
+
run_line.append(f" · {payload['label']}", style="cyan")
|
|
292
|
+
self.console.print(Padding(run_line, (0, 0, 0, 2)))
|
|
278
293
|
elif event == "step_end":
|
|
279
294
|
self.console.print(Padding(build_step_tree(payload["step"]), (0, 0, 0, 4)))
|
|
280
295
|
elif event == "run_end":
|
|
@@ -385,6 +400,8 @@ class ParallelProgressPrinter:
|
|
|
385
400
|
progress = ""
|
|
386
401
|
if row.get("run_index"):
|
|
387
402
|
progress = f" Run {row['run_index']}/{row['repeat']}"
|
|
403
|
+
if row.get("label"):
|
|
404
|
+
progress += f" · {row['label']}"
|
|
388
405
|
if row.get("step_id"):
|
|
389
406
|
progress += f" · {row['step_id']}"
|
|
390
407
|
grid.add_row(
|
|
@@ -434,6 +451,7 @@ class ParallelProgressPrinter:
|
|
|
434
451
|
if event == "run_start":
|
|
435
452
|
row["run_index"] = payload["run_index"]
|
|
436
453
|
row["repeat"] = payload["repeat"]
|
|
454
|
+
row["label"] = payload.get("label")
|
|
437
455
|
row["step_id"] = None
|
|
438
456
|
else:
|
|
439
457
|
row["step_id"] = payload["step_id"]
|
|
@@ -473,7 +491,12 @@ def _positive_int(value: str) -> int:
|
|
|
473
491
|
|
|
474
492
|
def _parser() -> argparse.ArgumentParser:
|
|
475
493
|
parser = argparse.ArgumentParser(
|
|
476
|
-
prog="yama",
|
|
494
|
+
prog="yama",
|
|
495
|
+
description="Run Agent Skill eval cases",
|
|
496
|
+
epilog=(
|
|
497
|
+
"Subcommand: `yama dashboard` serves historical reports and a"
|
|
498
|
+
" live case preview over HTTP (see `yama dashboard --help`)."
|
|
499
|
+
),
|
|
477
500
|
)
|
|
478
501
|
parser.add_argument("paths", nargs="*", type=Path, help="Explicit YAML case paths")
|
|
479
502
|
parser.add_argument(
|
|
@@ -515,8 +538,20 @@ def _parser() -> argparse.ArgumentParser:
|
|
|
515
538
|
const=DEFAULT_REPORT,
|
|
516
539
|
metavar="PATH",
|
|
517
540
|
help=(
|
|
518
|
-
"Write a standalone HTML execution report"
|
|
519
|
-
"
|
|
541
|
+
"Write a standalone HTML execution report (default: a timestamped"
|
|
542
|
+
" report-<ts>.html under reports/ beside the artifact runs"
|
|
543
|
+
" directory, with latest.html as a symlink to it)"
|
|
544
|
+
),
|
|
545
|
+
)
|
|
546
|
+
parser.add_argument(
|
|
547
|
+
"--preview",
|
|
548
|
+
action="store_true",
|
|
549
|
+
help=(
|
|
550
|
+
"Do not run anything; resolve the collected cases and emit a"
|
|
551
|
+
" case preview instead -- an HTML page styled like the report"
|
|
552
|
+
" (default: reports/preview.html beside the artifact runs"
|
|
553
|
+
" directory; --report PATH overrides the target), or JSON on"
|
|
554
|
+
" stdout when combined with --json"
|
|
520
555
|
),
|
|
521
556
|
)
|
|
522
557
|
parser.add_argument(
|
|
@@ -529,7 +564,12 @@ def _parser() -> argparse.ArgumentParser:
|
|
|
529
564
|
return parser
|
|
530
565
|
|
|
531
566
|
|
|
532
|
-
|
|
567
|
+
def _resolve_targets(
|
|
568
|
+
args: argparse.Namespace,
|
|
569
|
+
) -> tuple[Any, list[tuple[str | None, Path, dict[str, Any]]]]:
|
|
570
|
+
"""Expand the plugin-selection flags (--plugin-root / --plugin /
|
|
571
|
+
--all-plugins / cwd fallback) into concrete plugin roots. Shared by the
|
|
572
|
+
run command and the dashboard."""
|
|
533
573
|
workspace = load_workspace_config(Path.cwd())
|
|
534
574
|
targets: list[tuple[str | None, Path, dict[str, Any]]] = []
|
|
535
575
|
if args.plugin_root:
|
|
@@ -550,18 +590,30 @@ async def _run(args: argparse.Namespace) -> int:
|
|
|
550
590
|
else:
|
|
551
591
|
root, plugin_config = resolve_plugin_root(workspace)
|
|
552
592
|
targets.append((None, root, plugin_config))
|
|
593
|
+
return workspace, targets
|
|
553
594
|
|
|
595
|
+
|
|
596
|
+
def _collect_cases(args: argparse.Namespace) -> tuple[Any, list[Any]]:
|
|
597
|
+
"""Re-resolve everything the CLI selection addresses, from scratch --
|
|
598
|
+
the dashboard calls this per /preview request so edits to yama.toml and
|
|
599
|
+
the case files are picked up without a restart."""
|
|
600
|
+
workspace, targets = _resolve_targets(args)
|
|
554
601
|
collected = []
|
|
555
602
|
for _, plugin_root, plugin_config in targets:
|
|
556
603
|
paths = collect_case_paths(
|
|
557
604
|
plugin_root,
|
|
558
605
|
workspace,
|
|
559
606
|
plugin_config,
|
|
560
|
-
explicit_paths=args
|
|
607
|
+
explicit_paths=getattr(args, "paths", None) or None,
|
|
561
608
|
filters=args.filters,
|
|
562
609
|
)
|
|
563
610
|
for path in paths:
|
|
564
611
|
collected.append(resolve_case(path, plugin_root, workspace, plugin_config))
|
|
612
|
+
return workspace, collected
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
async def _run(args: argparse.Namespace) -> int:
|
|
616
|
+
workspace, collected = _collect_cases(args)
|
|
565
617
|
if args.list:
|
|
566
618
|
for case in collected:
|
|
567
619
|
print(case.case_key)
|
|
@@ -575,6 +627,34 @@ async def _run(args: argparse.Namespace) -> int:
|
|
|
575
627
|
Console(stderr=True).print(f"[bold red]{message}[/bold red]")
|
|
576
628
|
return 2
|
|
577
629
|
|
|
630
|
+
result_roots = [
|
|
631
|
+
args.result_dir.resolve()
|
|
632
|
+
if args.result_dir
|
|
633
|
+
else case.plugin_root / workspace.result_dir
|
|
634
|
+
for case in collected
|
|
635
|
+
]
|
|
636
|
+
if args.preview:
|
|
637
|
+
if args.json:
|
|
638
|
+
print(
|
|
639
|
+
json.dumps(
|
|
640
|
+
[preview_payload(case) for case in collected],
|
|
641
|
+
ensure_ascii=False,
|
|
642
|
+
indent=2,
|
|
643
|
+
)
|
|
644
|
+
)
|
|
645
|
+
return 0
|
|
646
|
+
target = args.report
|
|
647
|
+
if target is None or target == DEFAULT_REPORT:
|
|
648
|
+
target = result_roots[0].parent / "reports" / "preview.html"
|
|
649
|
+
preview_path = write_preview_html(collected, target)
|
|
650
|
+
Console().print(
|
|
651
|
+
Text.assemble(
|
|
652
|
+
("Case preview: ", "bold"),
|
|
653
|
+
(str(preview_path), f"cyan link {preview_path.as_uri()}"),
|
|
654
|
+
)
|
|
655
|
+
)
|
|
656
|
+
return 0
|
|
657
|
+
|
|
578
658
|
# With --json, stdout must stay valid JSON, so live progress moves to
|
|
579
659
|
# stderr instead of disappearing.
|
|
580
660
|
progress_console = Console(stderr=args.json)
|
|
@@ -584,12 +664,6 @@ async def _run(args: argparse.Namespace) -> int:
|
|
|
584
664
|
if parallel
|
|
585
665
|
else ProgressPrinter(progress_console, total_cases=len(collected))
|
|
586
666
|
)
|
|
587
|
-
result_roots = [
|
|
588
|
-
args.result_dir.resolve()
|
|
589
|
-
if args.result_dir
|
|
590
|
-
else case.plugin_root / workspace.result_dir
|
|
591
|
-
for case in collected
|
|
592
|
-
]
|
|
593
667
|
semaphore = asyncio.Semaphore(args.concurrency)
|
|
594
668
|
|
|
595
669
|
async def run_one(case: Any, result_root: Path) -> Any:
|
|
@@ -623,12 +697,17 @@ async def _run(args: argparse.Namespace) -> int:
|
|
|
623
697
|
all_results = list(outcomes)
|
|
624
698
|
report_target = args.report
|
|
625
699
|
if report_target == DEFAULT_REPORT:
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
700
|
+
# Default reports accumulate as history: a timestamped file per
|
|
701
|
+
# execution, with latest.html left as a symlink to the newest one
|
|
702
|
+
# (the dashboard's index lists that history). An explicit --report
|
|
703
|
+
# PATH still writes exactly the requested file.
|
|
704
|
+
report_path = write_timestamped_report(
|
|
705
|
+
collected, all_results, result_roots[0].parent / "reports"
|
|
706
|
+
)
|
|
707
|
+
elif report_target:
|
|
708
|
+
report_path = write_html_report(collected, all_results, report_target)
|
|
709
|
+
else:
|
|
710
|
+
report_path = None
|
|
632
711
|
if args.json:
|
|
633
712
|
print(
|
|
634
713
|
json.dumps(
|
|
@@ -651,9 +730,193 @@ async def _run(args: argparse.Namespace) -> int:
|
|
|
651
730
|
return 0 if all(result.passed for result in all_results) else 1
|
|
652
731
|
|
|
653
732
|
|
|
733
|
+
def _dashboard_parser() -> argparse.ArgumentParser:
|
|
734
|
+
parser = argparse.ArgumentParser(
|
|
735
|
+
prog="yama dashboard",
|
|
736
|
+
description=(
|
|
737
|
+
"Serve a local dashboard over HTTP: the index lists the"
|
|
738
|
+
" historical HTML reports (written by `yama --report`), and"
|
|
739
|
+
" /preview renders a live case preview that re-resolves the"
|
|
740
|
+
" case files on every refresh -- no LLM calls are made."
|
|
741
|
+
),
|
|
742
|
+
)
|
|
743
|
+
parser.add_argument(
|
|
744
|
+
"--plugin-root", type=Path, help="Serve a single plugin by root path"
|
|
745
|
+
)
|
|
746
|
+
parser.add_argument(
|
|
747
|
+
"--plugin", action="append", help="Plugin name from yama.toml"
|
|
748
|
+
)
|
|
749
|
+
parser.add_argument(
|
|
750
|
+
"--all-plugins", action="store_true", help="Preview all configured plugins"
|
|
751
|
+
)
|
|
752
|
+
parser.add_argument(
|
|
753
|
+
"-k",
|
|
754
|
+
"--filter",
|
|
755
|
+
action="append",
|
|
756
|
+
dest="filters",
|
|
757
|
+
metavar="PATTERN",
|
|
758
|
+
help="Only include matching cases in the preview page",
|
|
759
|
+
)
|
|
760
|
+
parser.add_argument(
|
|
761
|
+
"--result-dir",
|
|
762
|
+
type=Path,
|
|
763
|
+
help=(
|
|
764
|
+
"Override the artifact directory; reports are served from the"
|
|
765
|
+
" reports/ directory beside it"
|
|
766
|
+
),
|
|
767
|
+
)
|
|
768
|
+
parser.add_argument(
|
|
769
|
+
"--host", default="127.0.0.1", help="Bind address (default: 127.0.0.1)"
|
|
770
|
+
)
|
|
771
|
+
parser.add_argument(
|
|
772
|
+
"--port",
|
|
773
|
+
type=int,
|
|
774
|
+
default=8765,
|
|
775
|
+
help="Port to listen on (default: 8765; 0 picks a free port)",
|
|
776
|
+
)
|
|
777
|
+
return parser
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
def _run_dashboard(args: argparse.Namespace) -> int:
|
|
781
|
+
workspace, targets = _resolve_targets(args)
|
|
782
|
+
result_root = (
|
|
783
|
+
args.result_dir.resolve()
|
|
784
|
+
if args.result_dir
|
|
785
|
+
else targets[0][1] / workspace.result_dir
|
|
786
|
+
)
|
|
787
|
+
reports_dir = result_root.parent / "reports"
|
|
788
|
+
server = create_dashboard_server(
|
|
789
|
+
host=args.host,
|
|
790
|
+
port=args.port,
|
|
791
|
+
reports_dir=reports_dir,
|
|
792
|
+
collect_cases=lambda: _collect_cases(args)[1],
|
|
793
|
+
)
|
|
794
|
+
host, port = server.server_address[0], server.server_address[1]
|
|
795
|
+
url = f"http://{host}:{port}/"
|
|
796
|
+
console = Console()
|
|
797
|
+
console.print(
|
|
798
|
+
Text.assemble(("Yama dashboard: ", "bold"), (url, f"cyan link {url}"))
|
|
799
|
+
)
|
|
800
|
+
console.print(Text(f"Reports directory: {reports_dir}", style="dim"))
|
|
801
|
+
console.print(Text("Press Ctrl+C to stop.", style="dim"))
|
|
802
|
+
try:
|
|
803
|
+
server.serve_forever()
|
|
804
|
+
finally:
|
|
805
|
+
server.server_close()
|
|
806
|
+
return 0
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
_THREAD_TYPES = (
|
|
810
|
+
"one_shot",
|
|
811
|
+
"interactive",
|
|
812
|
+
"streaming",
|
|
813
|
+
"adventurer",
|
|
814
|
+
"gamer",
|
|
815
|
+
"atelier",
|
|
816
|
+
)
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
def _thread_case_parser() -> argparse.ArgumentParser:
|
|
820
|
+
parser = argparse.ArgumentParser(
|
|
821
|
+
prog="yama from-thread",
|
|
822
|
+
description=(
|
|
823
|
+
"Fetch one model-call record for a thread message and print a"
|
|
824
|
+
" single Case YAML skeleton to stdout, auto-populating one step when"
|
|
825
|
+
" DSL and request history make that possible."
|
|
826
|
+
),
|
|
827
|
+
)
|
|
828
|
+
parser.add_argument(
|
|
829
|
+
"--record-id",
|
|
830
|
+
required=True,
|
|
831
|
+
help=(
|
|
832
|
+
"Composite record ID, comma-separated with thread_id first and"
|
|
833
|
+
" message_id second (e.g. '<thread_id>, <message_id>, ,"
|
|
834
|
+
" <completion_id>'); only the first two parts are used"
|
|
835
|
+
),
|
|
836
|
+
)
|
|
837
|
+
parser.add_argument("--token", required=True, help="Bearer token")
|
|
838
|
+
parser.add_argument(
|
|
839
|
+
"--env",
|
|
840
|
+
default="dev",
|
|
841
|
+
help=(
|
|
842
|
+
"Target environment: dev, staging, or prod (default: dev)."
|
|
843
|
+
" Selects the admin API base URL and, when --commit-id is set,"
|
|
844
|
+
" the DSL SSH host and remote base dir"
|
|
845
|
+
),
|
|
846
|
+
)
|
|
847
|
+
parser.add_argument(
|
|
848
|
+
"--thread-type",
|
|
849
|
+
choices=_THREAD_TYPES,
|
|
850
|
+
default=None,
|
|
851
|
+
help=(
|
|
852
|
+
"Thread type query param (default: let the server fall back to"
|
|
853
|
+
" the Thread's own stored type)"
|
|
854
|
+
),
|
|
855
|
+
)
|
|
856
|
+
parser.add_argument(
|
|
857
|
+
"--record-index",
|
|
858
|
+
type=int,
|
|
859
|
+
default=-1,
|
|
860
|
+
metavar="N",
|
|
861
|
+
help="Which record to use from the message's records array (default: -1, the last one)",
|
|
862
|
+
)
|
|
863
|
+
parser.add_argument(
|
|
864
|
+
"--commit-id",
|
|
865
|
+
default=None,
|
|
866
|
+
help=(
|
|
867
|
+
"Git commit to read dsl.json from via SSH (git show <commit>:dsl.json);"
|
|
868
|
+
" omit to skip fetching dsl entirely"
|
|
869
|
+
),
|
|
870
|
+
)
|
|
871
|
+
return parser
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
def _run_thread_case(args: argparse.Namespace) -> int:
|
|
875
|
+
thread_id, message_id = parse_record_id(args.record_id)
|
|
876
|
+
payload = fetch_model_records(
|
|
877
|
+
thread_id, message_id, args.token, args.thread_type, env=args.env
|
|
878
|
+
)
|
|
879
|
+
record = select_record(payload.get("records", []), args.record_index)
|
|
880
|
+
stderr = Console(stderr=True)
|
|
881
|
+
stderr.print(
|
|
882
|
+
Text(
|
|
883
|
+
f"record: provider_file={record.get('provider_file')}"
|
|
884
|
+
f" line_no={record.get('line_no')} record_id={record.get('record_id')}"
|
|
885
|
+
f" model={record.get('model')} datetime={record.get('datetime')}",
|
|
886
|
+
style="dim",
|
|
887
|
+
)
|
|
888
|
+
)
|
|
889
|
+
stderr.print(
|
|
890
|
+
Text(f"response: {build_response_preview(record.get('response'))}", style="dim")
|
|
891
|
+
)
|
|
892
|
+
dsl: dict[str, Any] | None = None
|
|
893
|
+
if args.commit_id is not None:
|
|
894
|
+
ssh_host = resolve_dsl_ssh_host(args.env)
|
|
895
|
+
remote_base_dir = resolve_dsl_remote_base_dir(args.env)
|
|
896
|
+
dsl = fetch_dsl_at_commit(thread_id, args.commit_id, ssh_host, remote_base_dir)
|
|
897
|
+
stderr.print(
|
|
898
|
+
Text(
|
|
899
|
+
f"dsl: fetched {len(dsl)} top-level key(s) at commit {args.commit_id}",
|
|
900
|
+
style="dim",
|
|
901
|
+
)
|
|
902
|
+
)
|
|
903
|
+
case = build_case_dict(record, dsl=dsl, record_id=args.record_id)
|
|
904
|
+
print(dump_case_yaml(case), end="")
|
|
905
|
+
return 0
|
|
906
|
+
|
|
907
|
+
|
|
654
908
|
def main(argv: list[str] | None = None) -> int:
|
|
655
|
-
|
|
909
|
+
# .env is resolved from the working directory upward (like yama.toml);
|
|
910
|
+
# variables already present in the real environment take precedence.
|
|
911
|
+
load_dotenv(find_dotenv(usecwd=True))
|
|
912
|
+
if argv is None:
|
|
913
|
+
argv = sys.argv[1:]
|
|
656
914
|
try:
|
|
915
|
+
if argv[:1] == ["dashboard"]:
|
|
916
|
+
return _run_dashboard(_dashboard_parser().parse_args(argv[1:]))
|
|
917
|
+
if argv[:1] == ["from-thread"]:
|
|
918
|
+
return _run_thread_case(_thread_case_parser().parse_args(argv[1:]))
|
|
919
|
+
args = _parser().parse_args(argv)
|
|
657
920
|
return asyncio.run(_run(args))
|
|
658
921
|
except (ConfigurationError, CollectionError, ValueError) as exc:
|
|
659
922
|
Console(stderr=True).print(
|
|
@@ -668,5 +931,13 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
668
931
|
Text.assemble(("LLM error: ", "bold red"), (str(exc), "red"))
|
|
669
932
|
)
|
|
670
933
|
return 2
|
|
934
|
+
except ThreadCaseError as exc:
|
|
935
|
+
# Fetching/selecting the thread record failed -- separate label from
|
|
936
|
+
# "Collection error"/"LLM error" since neither Case collection nor an
|
|
937
|
+
# LLM call was involved.
|
|
938
|
+
Console(stderr=True).print(
|
|
939
|
+
Text.assemble(("Thread case error: ", "bold red"), (str(exc), "red"))
|
|
940
|
+
)
|
|
941
|
+
return 2
|
|
671
942
|
except KeyboardInterrupt:
|
|
672
943
|
return 130
|