reeval-python 0.18.0__py3-none-any.whl → 0.19.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.
reeval_python/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """Python eval authoring API for reeval (*.eval.py)."""
2
2
 
3
3
  from reeval_python.context import AttemptContext, SyncAttemptContext
4
- from reeval_python.declare import evaluate, evaluate_each, group, todo
4
+ from reeval_python.declare import evaluate, group, todo
5
5
  from reeval_python.environment import (
6
6
  DEFAULT_EGRESS_ALLOW,
7
7
  DockerSandbox,
@@ -10,15 +10,23 @@ from reeval_python.environment import (
10
10
  FakeJudge,
11
11
  Plugin,
12
12
  PluginBuild,
13
+ TartSandbox,
13
14
  define_environment,
14
15
  docker,
15
16
  fake_harness,
16
17
  fake_judge,
17
18
  plugin,
19
+ tart,
18
20
  )
19
21
  from reeval_python.errors import ReevalAssertionError, ReevalCallError
20
22
  from reeval_python.expect import Expectation, expect
21
- from reeval_python.options import BestOf, EvalOptions, JudgeDefaults, JudgeOptions
23
+ from reeval_python.options import (
24
+ BestOf,
25
+ CaseOptions,
26
+ EvalOptions,
27
+ JudgeDefaults,
28
+ JudgeOptions,
29
+ )
22
30
  from reeval_python.types import BackgroundHandle, Diff, ExecResult, FileChange, Turn, Verdict
23
31
 
24
32
  __all__ = [
@@ -29,6 +37,7 @@ __all__ = [
29
37
  "Diff",
30
38
  "DockerSandbox",
31
39
  "Environment",
40
+ "CaseOptions",
32
41
  "EvalOptions",
33
42
  "ExecResult",
34
43
  "Expectation",
@@ -42,16 +51,17 @@ __all__ = [
42
51
  "ReevalAssertionError",
43
52
  "ReevalCallError",
44
53
  "SyncAttemptContext",
54
+ "TartSandbox",
45
55
  "Turn",
46
56
  "Verdict",
47
57
  "define_environment",
48
58
  "docker",
49
59
  "evaluate",
50
- "evaluate_each",
51
60
  "expect",
52
61
  "fake_harness",
53
62
  "fake_judge",
54
63
  "group",
55
64
  "plugin",
65
+ "tart",
56
66
  "todo",
57
67
  ]
reeval_python/_wire.py CHANGED
@@ -405,6 +405,42 @@ class AttemptStart(TypedDict):
405
405
  type: Literal["start"]
406
406
 
407
407
 
408
+ # The host variable holding a Boat API key, made by `secret.fromEnv`.
409
+ BoatApiKey = TypedDict(
410
+ "BoatApiKey",
411
+ {
412
+ "from": "str",
413
+ "kind": "Literal[\"secret\"]",
414
+ },
415
+ )
416
+
417
+
418
+ # The host variable with the Boat API key, read on the host only.
419
+ BoatSandboxDescriptorApiKey = TypedDict(
420
+ "BoatSandboxDescriptorApiKey",
421
+ {
422
+ "from": "str",
423
+ "kind": "Literal[\"secret\"]",
424
+ },
425
+ )
426
+
427
+
428
+ # A boat.dev VM per attempt, made by `boat()` from `reeval/sandbox/boat`.
429
+ class BoatSandboxDescriptor(TypedDict):
430
+ # The host variable with the Boat API key, read on the host only.
431
+ apiKey: BoatSandboxDescriptorApiKey
432
+ # Cell id; defaults to `boat`, or `boat:<type>` with a `type`.
433
+ id: NotRequired[str]
434
+ kind: Literal["boat"]
435
+ # The most Boat sandboxes at once, across the run.
436
+ maxConcurrent: NotRequired[float]
437
+ # The start of every sandbox name reeval gives Boat, so a run's cleanup finds only its own:
438
+ # lowercase letters, digits and dashes.
439
+ prefix: str
440
+ # The machine size. Default `small`.
441
+ type: NotRequired[Literal["small", "default", "large", "xlarge"]]
442
+
443
+
408
444
  class CaptureConsoleItem(TypedDict):
409
445
  level: Literal["error", "warning", "info", "log", "debug"]
410
446
  source: str
@@ -508,9 +544,8 @@ class CaptureWindow(TypedDict):
508
544
 
509
545
 
510
546
  # A cell of an evaluation combines a harness, an environment (`-` when none is set), and that
511
- # environment's sandbox id. With `compare`, the control is `baseline` (or the cascaded
512
- # environment, or an empty `baseline`) and each variant is that environment on its own,
513
- # including its sandbox.
547
+ # environment's sandbox id. With `compare`, the control is `compare.control` and each variant is
548
+ # that environment on its own, including its sandbox.
514
549
  class Cell(TypedDict):
515
550
  # The environment's own name, also on a variant cell (`with-skill`, with no prefix).
516
551
  environment: str
@@ -519,6 +554,9 @@ class Cell(TypedDict):
519
554
  harness: str
520
555
  # The harness id, the environment name, and the sandbox id, joined with `/`.
521
556
  key: str
557
+ # `variant` on a compare's variant cell, else `control`: the compare's control, or any cell
558
+ # of an eval without `compare`, each environment of an `environments` grid included. A
559
+ # variant's lift is against the `control` cell on its harness and sandbox.
522
560
  role: CellRole
523
561
  # The sandbox id is `id` when set, or `fake` for the fake sandbox. A Docker sandbox starts
524
562
  # with the engine (`docker` by default). It adds `:` and the sanitized final component of
@@ -526,6 +564,8 @@ class Cell(TypedDict):
526
564
  # when that filename is `Dockerfile` and a parent is present). Non-empty `install` steps
527
565
  # append `+` and an eight-character hash.
528
566
  sandbox: str
567
+ # The environment's merged traits; unset when it has none. Not part of the key.
568
+ traits: NotRequired[dict[str, str | list[str]]]
529
569
  # The variant's name, for variant cells.
530
570
  variant: NotRequired[str]
531
571
 
@@ -629,10 +669,10 @@ class DeclarationTree(TypedDict):
629
669
  class DeclaredEval(TypedDict):
630
670
  # Names the eval's body to whoever runs it.
631
671
  body: str
632
- # Set on each case of a pooled `evaluate.each`: its template, index and the list's length.
672
+ # Set on each case of an eval with `cases`: its template, index and the list's length.
633
673
  family: NotRequired[DeclaredFamily]
634
674
  mode: DeclaredMode
635
- # The eval's name, as passed to `evaluate` (a case's, for `evaluate.each`).
675
+ # The eval's name, as passed to `evaluate` (a case's, for an eval with `cases`).
636
676
  name: str
637
677
  # The eval's own options, before the cascade.
638
678
  options: EvalOptionsData
@@ -640,13 +680,13 @@ class DeclaredEval(TypedDict):
640
680
  type: Literal["eval"]
641
681
 
642
682
 
643
- # Where a case of a pooled `evaluate.each` sits in its list.
683
+ # Where a case of an eval with `cases` sits in its list.
644
684
  class DeclaredFamily(TypedDict):
645
685
  # The case's index, from 0.
646
686
  case: int
647
687
  # How many cases the list has.
648
688
  cases: int
649
- # The name template passed to `evaluate.each`.
689
+ # The eval's own name, which each case's name extends.
650
690
  name: str
651
691
 
652
692
 
@@ -670,12 +710,12 @@ DeclaredNode: TypeAlias = "DeclaredEval | DeclaredGroup | DeclaredTodo"
670
710
 
671
711
 
672
712
  # An eval's own source as the SDK that declared it reads it: sha256 (hex) of its body's source
673
- # text, and an `evaluate.each` case's data as canonical JSON (object keys sorted, no whitespace,
674
- # non-ASCII characters as themselves). reeval hashes the case itself, with its secrets masked.
713
+ # text, and a case's data as canonical JSON (object keys sorted, no whitespace, non-ASCII
714
+ # characters as themselves). reeval hashes the case itself, with its secrets masked.
675
715
  class DeclaredSource(TypedDict):
676
716
  # sha256 of the body function's source text.
677
717
  body: str
678
- # The case's data as canonical JSON text; set on each case of an `evaluate.each`.
718
+ # The case's data as canonical JSON text; set on each case of an eval with `cases`.
679
719
  caseJson: NotRequired[str]
680
720
 
681
721
 
@@ -788,17 +828,25 @@ class EnvironmentSpec(TypedDict):
788
828
  setup: NotRequired[list[SetupStep]]
789
829
  # Skills placed for the agent.
790
830
  skills: NotRequired[list[SkillSource]]
831
+ # Filter facts for `where`, such as `{ stack: 'next' }`: a key to a string or a list of
832
+ # strings. A child's key replaces its parent's value whole; keys it doesn't set are
833
+ # inherited. Recorded on the cell, and never written to the sandbox, the prompt or the
834
+ # judge.
835
+ traits: NotRequired[dict[str, str | list[str]]]
791
836
  # The code the workspace starts as, before `files`, `rules` and `setup`; a child's replaces
792
837
  # its parent's.
793
838
  workspace: NotRequired[GitWorkspace]
794
839
 
795
840
 
796
- # Environments to run side by side against `environment`, the control.
841
+ # Environments to run side by side; `control` is what each variant is measured against.
797
842
  class EvalOptionsDataCompareCompare(TypedDict):
798
- # Which cells decide pass/fail: `variants` (default), `all`, or `none` (report only).
799
- gate: NotRequired[Literal["all", "none", "variants"]]
843
+ # The environment each variant is measured against. Not layered under the variants, and it
844
+ # replaces any `environments` the eval inherits.
845
+ control: EnvironmentData
846
+ # Which cells decide pass/fail: `variants` (default), `all`, or `observe` (none of them).
847
+ gate: NotRequired[Literal["all", "observe", "variants"]]
800
848
  # Harnesses (ids or descriptors) to compare on; the others run the control only.
801
- harness: NotRequired[list[AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | str]]
849
+ harnesses: NotRequired[list[AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | str]]
802
850
  # Lift in points from -1 to 1; a variant cell below it fails.
803
851
  minLift: NotRequired[float]
804
852
  # Other environments, each planned and run as itself.
@@ -813,11 +861,11 @@ class EvalOptionsDataCompareGatePassRate(TypedDict):
813
861
  passRate: float
814
862
 
815
863
 
816
- class EvalOptionsDataCompareHarnessAdd(TypedDict):
864
+ class EvalOptionsDataCompareHarnessesAdd(TypedDict):
817
865
  add: AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | list[HarnessDescriptor]
818
866
 
819
867
 
820
- class EvalOptionsDataCompareHarnessOnly(TypedDict):
868
+ class EvalOptionsDataCompareHarnessesOnly(TypedDict):
821
869
  only: list[str] | str
822
870
 
823
871
 
@@ -829,19 +877,17 @@ class EvalOptionsDataCompare(TypedDict):
829
877
  # Screenshot defaults for `c.capture()`. Shallow-merged; `viewport` and `model` replace the
830
878
  # value.
831
879
  capture: NotRequired[CaptureOptions]
832
- # Environments to run side by side against `environment`, the control.
880
+ # Environments to run side by side; `control` is what each variant is measured against.
833
881
  compare: EvalOptionsDataCompareCompare
834
882
  # Where the sandbox may connect. Replaces the inherited policy: config, profile defaults,
835
883
  # the environment, then groups and the eval.
836
884
  egress: NotRequired[Literal["allow-all", "deny-all", "proxy"] | EvalOptionsDataCompareEgressAllow]
837
885
  # Variables and secrets for the sandbox, merged by name down the cascade.
838
886
  env: NotRequired[EnvVars]
839
- # The control: the compare has no `baseline`.
840
- environment: NotRequired[EnvironmentData]
841
887
  # How each cell's attempts decide its outcome; default `'all'`.
842
- gate: NotRequired[Literal["all"] | EvalOptionsDataCompareGatePassRate]
888
+ gate: NotRequired[Literal["all", "observe"] | EvalOptionsDataCompareGatePassRate]
843
889
  # Which agents run the eval; each harness is its own cell.
844
- harness: NotRequired[AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | list[HarnessDescriptor] | EvalOptionsDataCompareHarnessAdd | EvalOptionsDataCompareHarnessOnly]
890
+ harnesses: NotRequired[AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | list[HarnessDescriptor] | EvalOptionsDataCompareHarnessesAdd | EvalOptionsDataCompareHarnessesOnly]
845
891
  # Defaults for `c.judge()`, merged field by field down the cascade.
846
892
  judge: NotRequired[ConfigJudgeOptions]
847
893
  # Keys a profile's `limit` may not narrow for this group or eval.
@@ -860,11 +906,11 @@ class EvalOptionsDataCompare(TypedDict):
860
906
  # Attempts per cell: a number, or `{ bestOf: n }` (odd, 3 or more), which stops each cell
861
907
  # once a majority of its `n` attempts agree and gates it on that majority; not on a compared
862
908
  # eval. Unset at every level, a compare with variants runs 4 a side, the fewest whose lift
863
- # can reach a verdict, and anything else runs once, a pooled `evaluate.each` case included.
909
+ # can reach a verdict, and anything else runs once, a case of an eval with `cases` included.
864
910
  runs: NotRequired[float | EvalOptionsDataCompareRunsBestOf]
865
911
  # The default machine when the resolved environment omits `sandbox`. Cascades like
866
- # `harness`. Not an environment: it does not invent skills, files or a name.
867
- sandbox: NotRequired[DockerSandboxDescriptor | FakeSandboxDescriptor]
912
+ # `harnesses`. Not an environment: it does not invent skills, files or a name.
913
+ sandbox: NotRequired[BoatSandboxDescriptor | DockerSandboxDescriptor | FakeSandboxDescriptor | TartSandboxDescriptor]
868
914
  # When each attempt's workspace is copied into its directory in `.reeval/runs`: `true` after
869
915
  # the checks, `'turns'` after each `c.send` too, `false` never. Default `true`.
870
916
  snapshot: NotRequired[SnapshotOptions | Literal["turns"] | bool]
@@ -874,124 +920,50 @@ class EvalOptionsDataCompare(TypedDict):
874
920
  timeout: NotRequired[float | str]
875
921
 
876
922
 
877
- # Environments to run side by side; `baseline` is the control.
878
- class EvalOptionsDataCompare2Compare(TypedDict):
879
- # The control. Not layered under the variants. Without it, the control is the environment
880
- # the eval would otherwise run in (the cascaded `environment`), else an empty one named
881
- # `baseline`.
882
- baseline: EnvironmentData
883
- # Which cells decide pass/fail: `variants` (default), `all`, or `none` (report only).
884
- gate: NotRequired[Literal["all", "none", "variants"]]
885
- # Harnesses (ids or descriptors) to compare on; the others run the control only.
886
- harness: NotRequired[list[AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | str]]
887
- # Lift in points from -1 to 1; a variant cell below it fails.
888
- minLift: NotRequired[float]
889
- # Other environments, each planned and run as itself.
890
- variants: list[EnvironmentData]
891
-
892
-
893
- class EvalOptionsDataCompare2EgressAllow(TypedDict):
923
+ class EvalOptionsData2EgressAllow(TypedDict):
894
924
  allow: list[str]
895
925
 
896
926
 
897
- class EvalOptionsDataCompare2GatePassRate(TypedDict):
898
- passRate: float
899
-
900
-
901
- class EvalOptionsDataCompare2HarnessAdd(TypedDict):
902
- add: AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | list[HarnessDescriptor]
927
+ class EvalOptionsData2EnvironmentsAdd(TypedDict):
928
+ add: EnvironmentData | list[EnvironmentData]
903
929
 
904
930
 
905
- class EvalOptionsDataCompare2HarnessOnly(TypedDict):
931
+ class EvalOptionsData2EnvironmentsOnly(TypedDict):
906
932
  only: list[str] | str
907
933
 
908
934
 
909
- class EvalOptionsDataCompare2RunsBestOf(TypedDict):
910
- bestOf: float
911
-
912
-
913
- class EvalOptionsDataCompare2(TypedDict):
914
- # Screenshot defaults for `c.capture()`. Shallow-merged; `viewport` and `model` replace the
915
- # value.
916
- capture: NotRequired[CaptureOptions]
917
- # Environments to run side by side; `baseline` is the control.
918
- compare: EvalOptionsDataCompare2Compare
919
- # Where the sandbox may connect. Replaces the inherited policy: config, profile defaults,
920
- # the environment, then groups and the eval.
921
- egress: NotRequired[Literal["allow-all", "deny-all", "proxy"] | EvalOptionsDataCompare2EgressAllow]
922
- # Variables and secrets for the sandbox, merged by name down the cascade.
923
- env: NotRequired[EnvVars]
924
- # How each cell's attempts decide its outcome; default `'all'`.
925
- gate: NotRequired[Literal["all"] | EvalOptionsDataCompare2GatePassRate]
926
- # Which agents run the eval; each harness is its own cell.
927
- harness: NotRequired[AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | list[HarnessDescriptor] | EvalOptionsDataCompare2HarnessAdd | EvalOptionsDataCompare2HarnessOnly]
928
- # Defaults for `c.judge()`, merged field by field down the cascade.
929
- judge: NotRequired[ConfigJudgeOptions]
930
- # Keys a profile's `limit` may not narrow for this group or eval.
931
- pin: NotRequired[list[PinnableKey]]
932
- # The model every question that names none of its own is answered by, down the cascade.
933
- question: NotRequired[QuestionOptions]
934
- # What a language model is asked about the attempts, always a list; they never change pass,
935
- # fail or the exit code. A question with `across` picks between pairs of attempts once they
936
- # all end; one without is asked of each attempt as it ends. Replaces the inherited list, so
937
- # `[]` asks none.
938
- questions: NotRequired[list[Question]]
939
- # The eval's version, part of its fingerprint: bump it when a change the eval file doesn't
940
- # show (a helper, a fixture, data it reads) changes what it measures. A group's applies to
941
- # the evals inside it that set none.
942
- revision: NotRequired[float | str]
943
- # Attempts per cell: a number, or `{ bestOf: n }` (odd, 3 or more), which stops each cell
944
- # once a majority of its `n` attempts agree and gates it on that majority; not on a compared
945
- # eval. Unset at every level, a compare with variants runs 4 a side, the fewest whose lift
946
- # can reach a verdict, and anything else runs once, a pooled `evaluate.each` case included.
947
- runs: NotRequired[float | EvalOptionsDataCompare2RunsBestOf]
948
- # The default machine when the resolved environment omits `sandbox`. Cascades like
949
- # `harness`. Not an environment: it does not invent skills, files or a name.
950
- sandbox: NotRequired[DockerSandboxDescriptor | FakeSandboxDescriptor]
951
- # When each attempt's workspace is copied into its directory in `.reeval/runs`: `true` after
952
- # the checks, `'turns'` after each `c.send` too, `false` never. Default `true`.
953
- snapshot: NotRequired[SnapshotOptions | Literal["turns"] | bool]
954
- # Labels for `--tag` and profiles to select by; a group's are added to its evals'.
955
- tags: NotRequired[list[str]]
956
- # Per attempt.
957
- timeout: NotRequired[float | str]
958
-
959
-
960
- class EvalOptionsData3EgressAllow(TypedDict):
961
- allow: list[str]
962
-
963
-
964
- class EvalOptionsData3GatePassRate(TypedDict):
935
+ class EvalOptionsData2GatePassRate(TypedDict):
965
936
  passRate: float
966
937
 
967
938
 
968
- class EvalOptionsData3HarnessAdd(TypedDict):
939
+ class EvalOptionsData2HarnessesAdd(TypedDict):
969
940
  add: AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | list[HarnessDescriptor]
970
941
 
971
942
 
972
- class EvalOptionsData3HarnessOnly(TypedDict):
943
+ class EvalOptionsData2HarnessesOnly(TypedDict):
973
944
  only: list[str] | str
974
945
 
975
946
 
976
- class EvalOptionsData3RunsBestOf(TypedDict):
947
+ class EvalOptionsData2RunsBestOf(TypedDict):
977
948
  bestOf: float
978
949
 
979
950
 
980
- class EvalOptionsData3(TypedDict):
951
+ class EvalOptionsData2(TypedDict):
981
952
  # Screenshot defaults for `c.capture()`. Shallow-merged; `viewport` and `model` replace the
982
953
  # value.
983
954
  capture: NotRequired[CaptureOptions]
984
955
  # Where the sandbox may connect. Replaces the inherited policy: config, profile defaults,
985
956
  # the environment, then groups and the eval.
986
- egress: NotRequired[Literal["allow-all", "deny-all", "proxy"] | EvalOptionsData3EgressAllow]
957
+ egress: NotRequired[Literal["allow-all", "deny-all", "proxy"] | EvalOptionsData2EgressAllow]
987
958
  # Variables and secrets for the sandbox, merged by name down the cascade.
988
959
  env: NotRequired[EnvVars]
989
- # What this group or eval runs in, and the control of a compare without a `baseline`.
990
- environment: NotRequired[EnvironmentData]
960
+ # What this group or eval runs in: one environment, or a list, each its own cell beside each
961
+ # harness. `{ add }` and `{ only }` edit the inherited list.
962
+ environments: NotRequired[EnvironmentData | list[EnvironmentData] | EvalOptionsData2EnvironmentsAdd | EvalOptionsData2EnvironmentsOnly]
991
963
  # How each cell's attempts decide its outcome; default `'all'`.
992
- gate: NotRequired[Literal["all"] | EvalOptionsData3GatePassRate]
964
+ gate: NotRequired[Literal["all", "observe"] | EvalOptionsData2GatePassRate]
993
965
  # Which agents run the eval; each harness is its own cell.
994
- harness: NotRequired[AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | list[HarnessDescriptor] | EvalOptionsData3HarnessAdd | EvalOptionsData3HarnessOnly]
966
+ harnesses: NotRequired[AntigravityHarnessDescriptor | ClaudeCodeHarnessDescriptor | CodexHarnessDescriptor | CursorHarnessDescriptor | FakeHarnessDescriptor | FxHarnessDescriptor | GooseHarnessDescriptor | GrokBuildHarnessDescriptor | OpenCodeHarnessDescriptor | PiHarnessDescriptor | list[HarnessDescriptor] | EvalOptionsData2HarnessesAdd | EvalOptionsData2HarnessesOnly]
995
967
  # Defaults for `c.judge()`, merged field by field down the cascade.
996
968
  judge: NotRequired[ConfigJudgeOptions]
997
969
  # Keys a profile's `limit` may not narrow for this group or eval.
@@ -1010,11 +982,11 @@ class EvalOptionsData3(TypedDict):
1010
982
  # Attempts per cell: a number, or `{ bestOf: n }` (odd, 3 or more), which stops each cell
1011
983
  # once a majority of its `n` attempts agree and gates it on that majority; not on a compared
1012
984
  # eval. Unset at every level, a compare with variants runs 4 a side, the fewest whose lift
1013
- # can reach a verdict, and anything else runs once, a pooled `evaluate.each` case included.
1014
- runs: NotRequired[float | EvalOptionsData3RunsBestOf]
985
+ # can reach a verdict, and anything else runs once, a case of an eval with `cases` included.
986
+ runs: NotRequired[float | EvalOptionsData2RunsBestOf]
1015
987
  # The default machine when the resolved environment omits `sandbox`. Cascades like
1016
- # `harness`. Not an environment: it does not invent skills, files or a name.
1017
- sandbox: NotRequired[DockerSandboxDescriptor | FakeSandboxDescriptor]
988
+ # `harnesses`. Not an environment: it does not invent skills, files or a name.
989
+ sandbox: NotRequired[BoatSandboxDescriptor | DockerSandboxDescriptor | FakeSandboxDescriptor | TartSandboxDescriptor]
1018
990
  # When each attempt's workspace is copied into its directory in `.reeval/runs`: `true` after
1019
991
  # the checks, `'turns'` after each `c.send` too, `false` never. Default `true`.
1020
992
  snapshot: NotRequired[SnapshotOptions | Literal["turns"] | bool]
@@ -1027,7 +999,7 @@ class EvalOptionsData3(TypedDict):
1027
999
  # `EvalOptions` in their data forms, as JSON carries them: the harness as data, the judge's
1028
1000
  # model by name or a fake judge, and environments without `extend`. The same `environment` /
1029
1001
  # compare object split as `EvalOptions`.
1030
- EvalOptionsData: TypeAlias = "EvalOptionsDataCompare | EvalOptionsDataCompare2 | EvalOptionsData3"
1002
+ EvalOptionsData: TypeAlias = "EvalOptionsDataCompare | EvalOptionsData2"
1031
1003
 
1032
1004
 
1033
1005
  class ExecResult(TypedDict):
@@ -1043,6 +1015,15 @@ class FakeHarnessDescriptorToolsItem(TypedDict):
1043
1015
  tool: str
1044
1016
 
1045
1017
 
1018
+ # Tokens the fake agent reports for every turn, as `turn.usage`; without it, null.
1019
+ class FakeHarnessDescriptorUsage(TypedDict):
1020
+ cacheRead: float
1021
+ cacheWrite: float
1022
+ input: float
1023
+ output: float
1024
+ reasoning: float | None
1025
+
1026
+
1046
1027
  # Files and message used instead when the environment gives the agent a skill.
1047
1028
  class FakeHarnessDescriptorWithSkill(TypedDict):
1048
1029
  files: NotRequired[dict[str, str]]
@@ -1105,6 +1086,11 @@ class FakeHarnessDescriptor(TypedDict):
1105
1086
  # Tool calls the fake agent reports on every turn, before writing files. `ok` defaults to
1106
1087
  # true; null reports a call whose result never came.
1107
1088
  tools: NotRequired[list[FakeHarnessDescriptorToolsItem]]
1089
+ # Each turn's recorded agent time, exactly, whatever the wall clock says: a test can compare
1090
+ # agent time without scheduling jitter, which four runs a side can tell apart.
1091
+ turnMs: NotRequired[float]
1092
+ # Tokens the fake agent reports for every turn, as `turn.usage`; without it, null.
1093
+ usage: NotRequired[FakeHarnessDescriptorUsage]
1108
1094
  # Files and message used instead when the environment gives the agent a skill.
1109
1095
  withSkill: NotRequired[FakeHarnessDescriptorWithSkill]
1110
1096
 
@@ -1536,7 +1522,7 @@ class PiHarnessDescriptor(TypedDict):
1536
1522
 
1537
1523
 
1538
1524
  # An option a profile's `limit` can narrow, and `pin` can protect.
1539
- PinnableKey: TypeAlias = "Literal[\"compare\", \"harness\", \"runs\"]"
1525
+ PinnableKey: TypeAlias = "Literal[\"compare\", \"harnesses\", \"runs\"]"
1540
1526
 
1541
1527
 
1542
1528
  class PluginMarketplace1(TypedDict):
@@ -1695,7 +1681,7 @@ class QuestionOptions(TypedDict):
1695
1681
  model: NotRequired[str]
1696
1682
 
1697
1683
 
1698
- SandboxDescriptor: TypeAlias = "FakeSandboxDescriptor | DockerSandboxDescriptor"
1684
+ SandboxDescriptor: TypeAlias = "FakeSandboxDescriptor | DockerSandboxDescriptor | TartSandboxDescriptor | BoatSandboxDescriptor"
1699
1685
 
1700
1686
 
1701
1687
  # A host environment variable, redacted everywhere reeval writes and recorded by name only. Made
@@ -1821,6 +1807,37 @@ class SnapshotOptions(TypedDict):
1821
1807
  SubstituteIn: TypeAlias = "Literal[\"header\", \"query\", \"body\"]"
1822
1808
 
1823
1809
 
1810
+ # Reach the VM over SSH when its Tart Guest Agent doesn't answer `tart exec`: as `user` (`admin`
1811
+ # when unset), with `key`, a private key the image trusts, absolute or relative to the file it's
1812
+ # written in.
1813
+ class TartSandboxDescriptorSsh(TypedDict):
1814
+ key: str
1815
+ user: NotRequired[str]
1816
+
1817
+
1818
+ # A macOS VM on this Mac, cloned from `image` for each attempt by Tart, made by `tart()`.
1819
+ class TartSandboxDescriptor(TypedDict):
1820
+ # CPUs each clone gets; the image's when unset.
1821
+ cpus: NotRequired[int]
1822
+ # Cell id; defaults to `tart:<image>`, the image's last path segment.
1823
+ id: NotRequired[str]
1824
+ # The VM each attempt clones: an OCI image such as
1825
+ # `ghcr.io/cirruslabs/macos-sequoia-base:latest`, or a local VM's name. Tart must have it
1826
+ # before the run: `reeval image build` (or `tart pull`) pulls it, and `reeval run` refuses
1827
+ # one `tart list` doesn't show.
1828
+ image: str
1829
+ kind: Literal["tart"]
1830
+ # The most Tart VMs at once, across the run: 1 or 2, and 2 when unset, since macOS runs at
1831
+ # most two macOS VMs at a time.
1832
+ maxConcurrent: NotRequired[float]
1833
+ # Memory each clone gets: `'8g'`, `'4096m'`, or bytes; the image's when unset.
1834
+ memory: NotRequired[str | int]
1835
+ # Reach the VM over SSH when its Tart Guest Agent doesn't answer `tart exec`: as `user`
1836
+ # (`admin` when unset), with `key`, a private key the image trusts, absolute or relative to
1837
+ # the file it's written in.
1838
+ ssh: NotRequired[TartSandboxDescriptorSsh]
1839
+
1840
+
1824
1841
  # The tokens one turn used, as its harness reported them. `input` excludes cache reads and
1825
1842
  # writes (so the prompt was `input + cacheRead + cacheWrite`); `reasoning` is part of `output`.
1826
1843
  class TokenUsage(TypedDict):
@@ -2016,6 +2033,7 @@ WebEventType: TypeAlias = "Literal[\"web-search\", \"web-fetch\"]"
2016
2033
  # reeval's camelCase keys: the SDK takes each in snake_case too.
2017
2034
  CAMEL_KEYS: frozenset[str] = frozenset(
2018
2035
  {
2036
+ "apiKey",
2019
2037
  "atMs",
2020
2038
  "bestOf",
2021
2039
  "cacheRead",
@@ -2044,6 +2062,7 @@ CAMEL_KEYS: frozenset[str] = frozenset(
2044
2062
  "startTimeout",
2045
2063
  "startedAt",
2046
2064
  "toolCallId",
2065
+ "turnMs",
2047
2066
  "withSkill",
2048
2067
  }
2049
2068
  )
@@ -2061,6 +2080,7 @@ RECORD_FIELDS: frozenset[str] = frozenset(
2061
2080
  "providerOptions",
2062
2081
  "regions",
2063
2082
  "score",
2083
+ "traits",
2064
2084
  "untested",
2065
2085
  "value",
2066
2086
  "write",
@@ -1,55 +1,55 @@
1
1
  {
2
- "version": "0.18.0",
2
+ "version": "0.19.0",
3
3
  "binaries": {
4
4
  "linux-x64": {
5
- "name": "reeval-0.18.0-linux-x64",
6
- "sha256": "58935d35f38ac6a35807a9e9fc75dfe21b3c41103de29d4b136de8f0fb7da315",
7
- "size": 88126944
5
+ "name": "reeval-0.19.0-linux-x64",
6
+ "sha256": "e846cb60a998ecdbdb0fe6ae6b753eb65ba1478b6919db26b88685ea28700463",
7
+ "size": 88290784
8
8
  },
9
9
  "linux-arm64": {
10
- "name": "reeval-0.18.0-linux-arm64",
11
- "sha256": "9273086a308ff6315091b8c13d201aceb2b86b08fae27393041b4c191fd8d7d4",
12
- "size": 88066344
10
+ "name": "reeval-0.19.0-linux-arm64",
11
+ "sha256": "56ed37c4a2869df2ef1fbbacea4b2727294beb5436434d2e593021de7fe07604",
12
+ "size": 88262952
13
13
  },
14
14
  "linux-x64-musl": {
15
- "name": "reeval-0.18.0-linux-x64-musl",
16
- "sha256": "d8a09bc64f9661cef911c510efadb3160e57c8d77aecbde05532ba6a4c8c8957",
17
- "size": 82097712
15
+ "name": "reeval-0.19.0-linux-x64-musl",
16
+ "sha256": "b9169da64f0610fe2d8c2d3d3c624753cb6efc17f796bd00f42496ed31afe690",
17
+ "size": 82261552
18
18
  },
19
19
  "linux-arm64-musl": {
20
- "name": "reeval-0.18.0-linux-arm64-musl",
21
- "sha256": "71e61a0244bdfdede8702cd70bcbb3f6e67deceec982b0bf5698b55d971ce742",
22
- "size": 81202384
20
+ "name": "reeval-0.19.0-linux-arm64-musl",
21
+ "sha256": "e8e6237a004da7f40e426aef248e367623f6e4ac1de6a5a8df4a2ba5ed2cb549",
22
+ "size": 81398992
23
23
  },
24
24
  "darwin-x64": {
25
- "name": "reeval-0.18.0-darwin-x64",
26
- "sha256": "37f405383d93ae6bdafb532bab609839dbf483d5411e2485edae161c001d94c7",
27
- "size": 76132624
25
+ "name": "reeval-0.19.0-darwin-x64",
26
+ "sha256": "a5351d0272495e3d48d1f5938f790b15c828231ac1dcb4574df5a169f030e7ba",
27
+ "size": 76296464
28
28
  },
29
29
  "darwin-arm64": {
30
- "name": "reeval-0.18.0-darwin-arm64",
31
- "sha256": "3702107fb5c338ba874cef7aac2fc5011e3b28ed2296e7eecbbfa3428860c1a7",
32
- "size": 69079410
30
+ "name": "reeval-0.19.0-darwin-arm64",
31
+ "sha256": "266efdc0631f8d45c34a46ffd64be103150d9404ae8668eae7e456768b5907d1",
32
+ "size": 69244530
33
33
  },
34
34
  "windows-x64": {
35
- "name": "reeval-0.18.0-windows-x64.exe",
36
- "sha256": "18ef75b27aa9303bf0f68e67c23a555b684ed373661fb6ad1b03e9f00750d6a0",
37
- "size": 92902400
35
+ "name": "reeval-0.19.0-windows-x64.exe",
36
+ "sha256": "7f7d6f48f01734ea1e3155c06d2ad5f32a501b2fb2cf7b7bbb754a3564228cca",
37
+ "size": 93066752
38
38
  },
39
39
  "linux-x64-baseline": {
40
- "name": "reeval-0.18.0-linux-x64-baseline",
41
- "sha256": "6104e41dde3f7af844b81a898fb31a934887e8931c648648533108b15fb8e2b0",
42
- "size": 88126944
40
+ "name": "reeval-0.19.0-linux-x64-baseline",
41
+ "sha256": "dc02245a06b18965165cfe2ab6cfc1b98e5055733ed94e04c8d90e367fb586a4",
42
+ "size": 88290784
43
43
  },
44
44
  "linux-x64-musl-baseline": {
45
- "name": "reeval-0.18.0-linux-x64-musl-baseline",
46
- "sha256": "17c41eafea3e13c8cdad79013706cfc4c7e11794302668cc1a2cc449412ceb3f",
47
- "size": 82097712
45
+ "name": "reeval-0.19.0-linux-x64-musl-baseline",
46
+ "sha256": "3e26eeb95cea7fbd4407033abf3c3f9e16054b7b3baa87e79691de8edca2a01c",
47
+ "size": 82261552
48
48
  },
49
49
  "windows-x64-baseline": {
50
- "name": "reeval-0.18.0-windows-x64-baseline.exe",
51
- "sha256": "b2fd67b24425ef8e42792926fbff985254e4947113927bf1f2fe231519425b28",
52
- "size": 92902400
50
+ "name": "reeval-0.19.0-windows-x64-baseline.exe",
51
+ "sha256": "b129c95c1ffa718e01b39e289d8c291aa22e9aa3509893aeb20a318c6d59e8d4",
52
+ "size": 93066752
53
53
  }
54
54
  }
55
55
  }
reeval_python/declare.py CHANGED
@@ -11,18 +11,20 @@ import inspect
11
11
  import itertools
12
12
  import json
13
13
  import linecache
14
+ import math
14
15
  import re
15
16
  import sys
16
17
  import textwrap
17
18
  from collections.abc import Callable, Coroutine, Sequence
18
19
  from dataclasses import dataclass, field
20
+ from decimal import Decimal
19
21
  from pathlib import Path
20
22
  from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast, overload
21
23
 
22
24
  from reeval_python import _wire as w
23
25
  from reeval_python.checks import ASSERT_HOOK, check, compile_eval
24
26
  from reeval_python.environment import Environment
25
- from reeval_python.options import EvalOptions
27
+ from reeval_python.options import CaseOptions, EvalOptions
26
28
  from reeval_python.wire import options_to_wire
27
29
 
28
30
  if TYPE_CHECKING:
@@ -115,7 +117,7 @@ _suites: list[_Suite] = []
115
117
  _bodies: dict[str, Callable[..., Any]] = {}
116
118
  # By id (the names joined with " › "): each eval's name path and whether it is a family's case.
117
119
  _names: dict[str, tuple[tuple[str, ...], bool]] = {}
118
- # Each pooled evaluate_each's name path, by its id.
120
+ # Each eval with cases: its name path, by its id.
119
121
  _families: dict[str, tuple[str, ...]] = {}
120
122
 
121
123
 
@@ -141,9 +143,9 @@ def _separator_hint(path: tuple[str, ...], earlier: tuple[str, ...]) -> str:
141
143
 
142
144
  def _named_like_family(path: tuple[str, ...], family: tuple[str, ...]) -> ValueError:
143
145
  return ValueError(
144
- f"evaluate({' › '.join(path)!r}) has the same id as the pooled "
145
- f"evaluate_each({' › '.join(family)!r}) in this file: a family's id is its name "
146
- f"template. Give the eval or the template another name.{_separator_hint(path, family)}"
146
+ f"evaluate({' › '.join(path)!r}) has the same id as "
147
+ f"evaluate({' › '.join(family)!r}) with cases in this file. Give one of them another "
148
+ f"name.{_separator_hint(path, family)}"
147
149
  )
148
150
 
149
151
 
@@ -212,6 +214,32 @@ AsyncBody = Callable[["AttemptContext"], Coroutine[Any, Any, None]]
212
214
  Body = TypeVar("Body", SyncBody, AsyncBody)
213
215
 
214
216
 
217
+ T = TypeVar("T")
218
+ SyncCaseBody = Callable[["SyncAttemptContext", T], None]
219
+ AsyncCaseBody = Callable[["AttemptContext", T], Coroutine[Any, Any, None]]
220
+
221
+
222
+ class _Cases(Generic[T]):
223
+ """`evaluate(name, {"cases": …})`'s decorator: a body taking the context and one case."""
224
+
225
+ def __init__(self, register: Callable[[Callable[..., Any]], None]) -> None:
226
+ self._register = register
227
+
228
+ @overload
229
+ def __call__(self, fn: SyncCaseBody[T], /) -> SyncCaseBody[T]: ...
230
+ @overload
231
+ def __call__(self, fn: AsyncCaseBody[T], /) -> AsyncCaseBody[T]: ...
232
+
233
+ def __call__(self, fn: Callable[..., Any], /) -> Any:
234
+ self._register(fn)
235
+ return fn
236
+
237
+
238
+ # Overlaps the next on purpose: options with `cases` are `EvalOptions` too, and take a case body.
239
+ @overload
240
+ def evaluate( # pyright: ignore[reportOverlappingOverload]
241
+ name: str, options: CaseOptions[T], /, *, mode: Mode = "run"
242
+ ) -> _Cases[T]: ...
215
243
  @overload
216
244
  def evaluate(
217
245
  name: str, options: EvalOptions | None = None, /, *, mode: Mode = "run"
@@ -224,20 +252,28 @@ def evaluate(name: str, options: EvalOptions, fn: Body, /, *, mode: Mode = "run"
224
252
 
225
253
  def evaluate(
226
254
  name: str,
227
- arg: Callable[..., Any] | EvalOptions | None = None,
255
+ arg: Callable[..., Any] | EvalOptions | CaseOptions[Any] | None = None,
228
256
  arg2: Callable[..., Any] | None = None,
229
257
  /,
230
258
  *,
231
259
  mode: Mode = "run",
232
260
  ) -> Any:
261
+ """An eval: its name, options and body. With `cases`, the body takes `(c, case)` and runs
262
+ once per case with every cell and run."""
233
263
  if callable(arg) and arg2 is None:
234
264
  _register_eval(name, mode, {}, arg, None, None)
235
265
  return arg
236
- if isinstance(arg, dict) and callable(arg2):
237
- _register_eval(name, mode, dict[str, Any](cast(dict[str, Any], arg)), arg2, None, None)
266
+ opts = dict[str, Any](cast(dict[str, Any], arg)) if isinstance(arg, dict) else {}
267
+ with_cases = "cases" in opts or "case_key" in opts
268
+ if callable(arg2):
269
+ if with_cases:
270
+ _register_cases(name, mode, opts, arg2)
271
+ else:
272
+ _register_eval(name, mode, opts, arg2, None, None)
238
273
  return arg2
239
274
 
240
- opts = dict[str, Any](cast(dict[str, Any], arg)) if isinstance(arg, dict) else {}
275
+ if with_cases:
276
+ return _Cases[Any](lambda fn: _register_cases(name, mode, opts, fn))
241
277
 
242
278
  def decorator(fn: Callable[..., Any]) -> Callable[..., Any]:
243
279
  _register_eval(name, mode, opts, fn, None, None)
@@ -246,24 +282,138 @@ def evaluate(
246
282
  return decorator
247
283
 
248
284
 
249
- _PLACEHOLDER = re.compile(r"%#|%s|\$([A-Za-z_]\w*)")
250
-
251
-
252
- def _case_name(template: str, case: Any, index: int) -> str:
253
- """A case's eval name: `%#` is its index, `%s` the case as `str()` writes it, and `$field`
254
- the field of a dict case (left as written when the case has no such field). One pass, so a
255
- value that contains a placeholder stays as it is."""
256
- fields = cast(dict[str, Any], case) if isinstance(case, dict) else {}
285
+ _BAD_KEY = re.compile(r"[#/›\x00-\x1f\x7f]")
286
+ CASE_KEY_MAX = 80
287
+
288
+
289
+ def _default_key(case: Any) -> str | None:
290
+ if isinstance(case, str):
291
+ return case
292
+ if isinstance(case, int | float) and not isinstance(case, bool) and math.isfinite(case):
293
+ return _js_number(case)
294
+ if isinstance(case, dict):
295
+ fields = cast(dict[str, Any], case)
296
+ for key in ("id", "name"):
297
+ if isinstance(fields.get(key), str):
298
+ return cast(str, fields[key])
299
+ for key in ("id", "name"):
300
+ value = getattr(cast(object, case), key, None)
301
+ if isinstance(value, str):
302
+ return value
303
+ return None
304
+
305
+
306
+ def _js_number(n: float) -> str:
307
+ """A number as JavaScript's `String(n)` writes it (`2.0` as `2`, `1e-07` as `1e-7`), so both
308
+ SDKs key it alike. `repr` has the same shortest round-trip digits; only the layout differs."""
309
+ x = float(n)
310
+ if x == 0:
311
+ return "0"
312
+ parts = Decimal(repr(abs(x))).normalize().as_tuple()
313
+ digits = "".join(map(str, parts.digits))
314
+ size = len(digits)
315
+ point = size + int(parts.exponent)
316
+ if size <= point <= 21:
317
+ body = digits + "0" * (point - size)
318
+ elif 0 < point <= 21:
319
+ body = f"{digits[:point]}.{digits[point:]}"
320
+ elif -6 < point <= 0:
321
+ body = f"0.{'0' * -point}{digits}"
322
+ else:
323
+ mantissa = digits[0] + (f".{digits[1:]}" if size > 1 else "")
324
+ body = f"{mantissa}e{'+' if point > 0 else '-'}{abs(point - 1)}"
325
+ return ("-" if x < 0 else "") + body
326
+
327
+
328
+ def case_keys(cases: Sequence[Any], case_key: Callable[[Any], Any] | None, where: str) -> list[str]:
329
+ """Each case's key, in list order: `case_key(case)` when given, else its default. Trimmed,
330
+ 1–80 characters, with no `#`, `/`, `›` or control characters, and unique within the eval."""
331
+ seen: dict[str, int] = {}
332
+ out: list[str] = []
333
+ for i, case in enumerate(cases):
334
+ raw = case_key(case) if case_key else _default_key(case)
335
+ if raw is None:
336
+ raise ValueError(
337
+ f"cases[{i}] in {where} has no key: a case is its own key when it's a string or "
338
+ "a number, or a dict's id or name. Give it an id, or pass "
339
+ '"case_key": lambda case: case["slug"].'
340
+ )
341
+ if not isinstance(raw, str):
342
+ raise TypeError(
343
+ f"case_key in {where} must return a string (got {raw!r} for cases[{i}])"
344
+ )
345
+ key = raw.strip()
346
+ if not key or len(key) > CASE_KEY_MAX or _BAD_KEY.search(key):
347
+ raise ValueError(
348
+ f"cases[{i}] in {where} has the key {raw!r}: a case key is 1–{CASE_KEY_MAX} "
349
+ "characters, with no #, /, › or control characters."
350
+ + ("" if case_key else " Pass case_key to give it another.")
351
+ )
352
+ if key in seen:
353
+ raise ValueError(
354
+ f"cases[{seen[key]}] and cases[{i}] in {where} have the same key {key!r}. Each "
355
+ "case needs its own key"
356
+ + ("." if case_key else ": give them distinct ids or names, or pass case_key.")
357
+ )
358
+ seen[key] = i
359
+ out.append(key)
360
+ return out
257
361
 
258
- def fill(m: re.Match[str]) -> str:
259
- if m.group(0) == "%#":
260
- return str(index)
261
- if m.group(0) == "%s":
262
- return str(cast(object, case))
263
- key = m.group(1)
264
- return str(fields[key]) if key in fields else m.group(0)
265
362
 
266
- return _PLACEHOLDER.sub(fill, template)
363
+ def _register_cases(name: str, mode: Mode, opts: dict[str, Any], fn: Callable[..., Any]) -> None:
364
+ """Each case plans as an entry of its own named for the eval, `<name> [<key>]`, which the
365
+ record folds back into the eval."""
366
+ where = f"evaluate({name!r})"
367
+ cases = opts.pop("cases", None)
368
+ case_key = opts.pop("case_key", None)
369
+ if not isinstance(cast(object, cases), list | tuple):
370
+ raise TypeError(
371
+ f"case_key in {where} names each case, but there are no cases. Add cases, or drop "
372
+ "case_key."
373
+ if cases is None
374
+ else f"cases in {where} must be a list (got {type(cases).__name__}), e.g. "
375
+ '"cases": ["users", "posts"]'
376
+ )
377
+ cases = cast(Sequence[Any], cases)
378
+ if not cases:
379
+ raise ValueError(f"cases in {where} is an empty list. Give at least one case.")
380
+ if case_key is not None and not callable(case_key):
381
+ raise TypeError(f"case_key in {where} must be a function from a case to its key")
382
+ if isinstance(opts.get("runs"), dict):
383
+ raise ValueError(
384
+ f"{where} has cases, so it can't take runs={{'best_of': …}}: best-of stops each cell "
385
+ "on its own, and the cases pool over the runs. Set a fixed count, e.g. runs=3."
386
+ )
387
+ _refuse_generator(fn, where)
388
+ try:
389
+ inspect.signature(fn).bind(None, None)
390
+ except TypeError:
391
+ raise TypeError(
392
+ f"{where}: with cases, the body takes the attempt and its case, e.g. def body(c, case)"
393
+ ) from None
394
+ except ValueError:
395
+ pass
396
+ keys = case_keys(cases, cast(Callable[[Any], Any] | None, case_key), where)
397
+ body = body_hash(fn, where)
398
+ path = (*(frame.name for frame in _group_stack), name)
399
+ key = " › ".join(path)
400
+ if key in _families:
401
+ raise ValueError(
402
+ f"{where} with cases is declared twice in this file. Each eval needs its own "
403
+ "name, or their cases are pooled into one. Give each its own name."
404
+ f"{_separator_hint(path, _families[key])}"
405
+ )
406
+ plain = _names.get(key)
407
+ if plain is not None and not plain[1]:
408
+ raise _named_like_family(plain[0], path)
409
+ _families[key] = path
410
+ for index, (case, case_name) in enumerate(zip(cases, keys, strict=True)):
411
+ family = DeclaredFamily(name=name, case=index, cases=len(cases))
412
+ source: w.DeclaredSource = {
413
+ "body": body,
414
+ "caseJson": case_json(case, f"{where} case {case_name!r}"),
415
+ }
416
+ _register_eval(f"{name} [{case_name}]", mode, opts, _with_case(fn, case), source, family)
267
417
 
268
418
 
269
419
  def body_hash(fn: Callable[..., Any], where: str) -> str:
@@ -438,94 +588,6 @@ def _with_case(fn: Callable[..., Any], case: Any) -> Callable[..., Any]:
438
588
  return body
439
589
 
440
590
 
441
- T = TypeVar("T")
442
- SyncCaseBody = Callable[["SyncAttemptContext", T], None]
443
- AsyncCaseBody = Callable[["AttemptContext", T], Coroutine[Any, Any, None]]
444
-
445
-
446
- class _Each(Generic[T]):
447
- """`evaluate_each(…)`'s decorator: a body taking the context and one case."""
448
-
449
- def __init__(self, register: Callable[[Callable[..., Any]], None]) -> None:
450
- self._register = register
451
-
452
- @overload
453
- def __call__(self, fn: SyncCaseBody[T], /) -> SyncCaseBody[T]: ...
454
- @overload
455
- def __call__(self, fn: AsyncCaseBody[T], /) -> AsyncCaseBody[T]: ...
456
-
457
- def __call__(self, fn: Callable[..., Any], /) -> Any:
458
- self._register(fn)
459
- return fn
460
-
461
-
462
- def evaluate_each(
463
- cases: Sequence[T],
464
- name_template: str,
465
- options: EvalOptions | None = None,
466
- *,
467
- pool: bool = True,
468
- ) -> _Each[T]:
469
- """One eval per case; the body gets `(c, case)`. Its cases pool into one family unless
470
- `pool=False` or there's only one.
471
-
472
- Each eval is named from `name_template`: `%#` is the case's index, `%s` the case as `str()`
473
- writes it, and `$field` a dict case's field (`"greets $name"`), left as written when the
474
- case has no such field.
475
- """
476
- if not isinstance(cast(object, cases), list | tuple):
477
- raise TypeError(
478
- f"evaluate_each takes a list of cases (got {type(cases).__name__}), e.g. "
479
- 'evaluate_each([{"n": 1}, {"n": 2}], "case $n")'
480
- )
481
- opts = dict[str, Any](options or {})
482
- hint = (
483
- f" For evaluate_each, put $key, %s or %# in the name ({name_template!r}) so each case's "
484
- "name differs."
485
- )
486
-
487
- def decorator(fn: Callable[..., Any]) -> None:
488
- _refuse_generator(fn, f"evaluate_each({name_template!r})")
489
- try:
490
- inspect.signature(fn).bind(None, None)
491
- except TypeError:
492
- raise TypeError(
493
- f"evaluate_each({name_template!r}): the body takes the attempt and its case, "
494
- "e.g. def body(c, case)"
495
- ) from None
496
- except ValueError:
497
- pass
498
- each = f"evaluate_each({name_template!r})"
499
- body = body_hash(fn, each)
500
- pooled = pool and len(cases) > 1
501
- if pooled:
502
- path = (*(frame.name for frame in _group_stack), name_template)
503
- key = " › ".join(path)
504
- if key in _families:
505
- raise ValueError(
506
- f"evaluate_each({key!r}) is declared twice in this file. Each pooled "
507
- "evaluate_each needs its own name, or their cases are pooled into one family. "
508
- "Give each its own name template, or pass pool=False to keep the cases apart."
509
- f"{_separator_hint(path, _families[key])}"
510
- )
511
- plain = _names.get(key)
512
- if plain is not None and not plain[1]:
513
- raise _named_like_family(plain[0], path)
514
- _families[key] = path
515
- for index, case in enumerate(cases):
516
- family = None
517
- if pooled:
518
- family = DeclaredFamily(name=name_template, case=index, cases=len(cases))
519
- name = _case_name(name_template, case, index)
520
- source: w.DeclaredSource = {
521
- "body": body,
522
- "caseJson": case_json(case, f"{each} case {index}"),
523
- }
524
- _register_eval(name, "run", opts, _with_case(fn, case), source, family, hint)
525
-
526
- return _Each(decorator)
527
-
528
-
529
591
  def todo(name: str) -> None:
530
592
  """An eval or group still to write: listed in the plan, never run."""
531
593
  _declare(DeclaredTodo(name=name))
@@ -65,6 +65,10 @@ class DockerSandbox(_Descriptor):
65
65
  """reeval's Docker sandbox, made by `docker(…)`."""
66
66
 
67
67
 
68
+ class TartSandbox(_Descriptor):
69
+ """A macOS VM run by Tart, made by `tart(…)`."""
70
+
71
+
68
72
  class FakeHarness(_Descriptor):
69
73
  """The fake agent, made by `fake_harness(…)`."""
70
74
 
@@ -177,6 +181,13 @@ def docker(*, from_: str | None = None, **options: Any) -> DockerSandbox:
177
181
  )
178
182
 
179
183
 
184
+ def tart(image: str, **options: Any) -> TartSandbox:
185
+ """A macOS VM cloned from `image` (an OCI image or a local VM) for each attempt, run by
186
+ Tart on this Apple Silicon Mac. It runs under `egress="allow-all"` only. `ssh={"key": …}`
187
+ is relative to the eval file."""
188
+ return TartSandbox({"kind": "tart", "image": image, **value_to_wire(options)})
189
+
190
+
180
191
  def fake_harness(**options: Any) -> FakeHarness:
181
192
  """The fake agent, for evals that run without a real one."""
182
193
  return FakeHarness({"kind": "fake", **value_to_wire(options)})
reeval_python/expect.py CHANGED
@@ -11,7 +11,7 @@ import itertools
11
11
  import os
12
12
  import re
13
13
  import sys
14
- from collections.abc import Callable, Coroutine, Sequence
14
+ from collections.abc import Callable, Coroutine, Mapping, Sequence
15
15
  from contextvars import ContextVar
16
16
  from datetime import timedelta
17
17
  from typing import TYPE_CHECKING, Any, Generic, Self, TypeVar
@@ -224,6 +224,28 @@ class _Matchers(Generic[R]):
224
224
  def to_have_changed(self, paths: Pattern | Sequence[Pattern] = _UNSET) -> R:
225
225
  return self._match("toHaveChanged", _given(paths))
226
226
 
227
+ def to_stay_within(
228
+ self,
229
+ *,
230
+ tokens: int | None = None,
231
+ tool_calls: int | Mapping[str, int] | None = None,
232
+ duration: int | str | None = None,
233
+ ) -> R:
234
+ """The turn, or every turn of `c`, stayed within each limit given: `tokens` (input and
235
+ output, subagents included), `tool_calls` (a count, or a count per tool) and `duration`
236
+ (`"5m"`, or milliseconds). A turn with no reported usage can't be checked against
237
+ `tokens`, which is an error, not a failure."""
238
+ limits: dict[str, Any] = {}
239
+ if tokens is not None:
240
+ limits["tokens"] = tokens
241
+ if tool_calls is not None:
242
+ limits["toolCalls"] = (
243
+ dict(tool_calls) if isinstance(tool_calls, Mapping) else tool_calls
244
+ )
245
+ if duration is not None:
246
+ limits["duration"] = duration
247
+ return self._match("toStayWithin", [limits])
248
+
227
249
  def to_pass(self) -> R:
228
250
  """The judge's verdict passed."""
229
251
  return self._match("toPass", [])
reeval_python/options.py CHANGED
@@ -6,13 +6,20 @@ data reeval documents for it, in snake_case too, and reeval checks them when it
6
6
 
7
7
  from __future__ import annotations
8
8
 
9
- from collections.abc import Mapping, Sequence
9
+ from collections.abc import Callable, Mapping, Sequence
10
10
  from datetime import timedelta
11
- from typing import Any, Literal, TypedDict
12
-
13
- from reeval_python.environment import DockerSandbox, Environment, FakeHarness, FakeJudge
11
+ from typing import Any, Generic, Literal, Required, TypedDict, TypeVar
12
+
13
+ from reeval_python.environment import (
14
+ DockerSandbox,
15
+ Environment,
16
+ FakeHarness,
17
+ FakeJudge,
18
+ TartSandbox,
19
+ )
14
20
 
15
21
  Harness = str | FakeHarness | Mapping[str, Any]
22
+ T = TypeVar("T")
16
23
 
17
24
 
18
25
  class JudgeDefaults(TypedDict, total=False):
@@ -72,19 +79,20 @@ class EvalOptions(TypedDict, total=False):
72
79
  compare: Mapping[str, Any]
73
80
  egress: Literal["allow-all", "deny-all", "proxy"] | Mapping[str, Sequence[str]]
74
81
  env: Mapping[str, Any]
75
- environment: Environment | Mapping[str, Any]
76
- gate: Literal["all"] | Mapping[str, float]
77
- harness: Harness | Sequence[Harness] | Mapping[str, Any]
82
+ environments: Environment | Sequence[Environment] | Mapping[str, Any]
83
+ """One environment, or a list, each its own cell beside each harness; `{"add": …}` and
84
+ `{"only": [names]}` edit the inherited list."""
85
+ gate: Literal["all", "observe"] | Mapping[str, float]
86
+ """`"all"` (every attempt passes), `{"pass_rate": 0.8}`, or `"observe"` (nothing gates: the
87
+ attempts run and are recorded, and only run and infra errors fail the eval)."""
88
+ harnesses: Harness | Sequence[Harness] | Mapping[str, Any]
78
89
  judge: JudgeDefaults
79
90
  pin: Sequence[str]
80
91
  question: Mapping[str, Any]
81
92
  questions: Sequence[Mapping[str, Any]]
82
93
  """Asked of each attempt, or between attempts with `across`; `[]` clears the group's. Each
83
94
  names what it's shown: `{"question": …, "diff": True}`, at least one input."""
84
- runs: int | BestOf
85
- """Attempts per cell, or `{"best_of": n}`, which gates each cell on its majority. Not on a
86
- compared eval."""
87
- sandbox: DockerSandbox | Mapping[str, Any]
95
+ sandbox: DockerSandbox | TartSandbox | Mapping[str, Any]
88
96
  snapshot: bool | Literal["turns"] | Mapping[str, Any]
89
97
  """When each attempt's workspace is copied into its directory in `.reeval/runs`: `True` after
90
98
  the checks, `"turns"` after each `send` too, `False` never, or `{"when": …, "compress": True}`
@@ -92,6 +100,21 @@ class EvalOptions(TypedDict, total=False):
92
100
  revision: int | str
93
101
  """The eval's version, in its fingerprint: bump it when a helper, a constant outside the body
94
102
  or a fixture changes what it measures. A group's applies to evals inside that set none."""
103
+ runs: int | BestOf
104
+ """Attempts per cell, or `{"best_of": n}`, which gates each cell on its majority. Not on a
105
+ compared eval."""
95
106
  tags: Sequence[str]
96
107
  timeout: timedelta | float
97
108
  """Per attempt, in seconds or as a timedelta."""
109
+
110
+
111
+ class CaseOptions(EvalOptions, Generic[T], total=False):
112
+ """An eval's options with `cases`: each case runs the body, `(c, case)`, with every cell and
113
+ run, and the cases pool into one pass rate (and, with `compare`, one lift paired by case).
114
+ Per eval only."""
115
+
116
+ cases: Required[Sequence[T]]
117
+ """The inputs, each JSON data."""
118
+ case_key: Callable[[T], str]
119
+ """Each case's key, which names it in the output and the record. Without it, a string or a
120
+ finite number is its own key, and a dict uses its `id`, else its `name`."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: reeval-python
3
- Version: 0.18.0
3
+ Version: 0.19.0
4
4
  Summary: Python authoring SDK for reeval (*.eval.py eval files)
5
5
  Project-URL: Homepage, https://reeval.ai
6
6
  Project-URL: Repository, https://github.com/invertase/reeval
@@ -195,15 +195,15 @@ expect.poll(lambda: c.read_file("ready.txt"), timeout=10).to_be("ready\n")
195
195
  expect.poll(c, "the server wrote its log").to_have_file("server.log")
196
196
  ```
197
197
 
198
- ### Names of `evaluate_each` cases
198
+ ### Cases
199
199
 
200
- `evaluate_each(cases, name)` names each eval from `name`: `%#` is the case's index, `%s` the case
201
- as `str()` writes it, and `$field` a dict case's field. Each placeholder is filled once, so a value
202
- that contains `$` or `%` stays as it is, and a `$field` the case doesn't have is left as written.
203
- Two evals with one name in a file are refused where they're declared.
200
+ `"cases"` runs one eval over a list, and the body takes the attempt and its case. Each case has a
201
+ key: a string or a number is its own, a dict or an object its `id` or `name`, and `"case_key"`
202
+ gives any other. A key is 1–80 characters with no `#`, `/`, `›` or control characters, and unique
203
+ within the eval; the run reports each case as `<eval> [<key>]`.
204
204
 
205
205
  ```python
206
- @evaluate_each([{"lang": "en"}, {"lang": "fr"}], "greets in $lang (#%#)")
206
+ @evaluate("greets", {"cases": [{"lang": "en"}, {"lang": "fr"}], "case_key": lambda c: c["lang"]})
207
207
  def greets(c: SyncAttemptContext, case: dict[str, str]) -> None: ...
208
208
  ```
209
209
 
@@ -0,0 +1,22 @@
1
+ reeval_python/__init__.py,sha256=R7ALlyTIdakTpdIis7uLcuM2oI21H7lnGUjYB0uRsNY,1435
2
+ reeval_python/__main__.py,sha256=opVNjZHR3dLJnP_p528E5oz8E-oow6606wwPZ0L0Mto,282
3
+ reeval_python/_wire.py,sha256=BYA9kIwx8DYgVW7oJb0WmsB_AWWh3OQJrEciITllkrE,86684
4
+ reeval_python/aio.py,sha256=yyi09fi_Bt7N704HRcRJLTGmNHcxyD3bFwevPcMa_Z4,421
5
+ reeval_python/binaries.json,sha256=LXDaNQudidIv2lu0DSB7iNSVsB_zFPFYSdsR3bE14CM,1902
6
+ reeval_python/checks.py,sha256=gYSpLMzMMvZ_neV5siB9cLpUfOwSbax6tj-N8N57NNE,11078
7
+ reeval_python/cli.py,sha256=qyXObxNbWoisgQCo0tEhqDh0oM141dQ77Jqung60Vv0,18953
8
+ reeval_python/context.py,sha256=tGlIlFfyRv9_g3WUzfxlnrrkcPuOk1bO0T21dWeaT8k,17993
9
+ reeval_python/declare.py,sha256=Lfwf_oTJH1M-Xfyh2kNxbm_IQStTy2vhImt9lFRxF24,23052
10
+ reeval_python/environment.py,sha256=2TA8z_NvvXwid9OIHIKknglasN5-tHunsDLHLM02eGg,6713
11
+ reeval_python/errors.py,sha256=wgwjeVoZImkIuKC2GiYK6ahar85glpOmDAWKRg6cowY,894
12
+ reeval_python/expect.py,sha256=SFH4vzFEN7UtjhtwofAGmXkVn4jMmLWFj6XCAa4hDP4,11874
13
+ reeval_python/options.py,sha256=tujPvUfYmLouJpl2Smn38joAeIrf_cfY29RDXMg45sk,4570
14
+ reeval_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ reeval_python/runner.py,sha256=bNwRfHQdeM0PC113G5d0RzFRtHcFMMLj8bE3cnoZKII,21070
16
+ reeval_python/types.py,sha256=Ycy9KwhmtSfYKTny-DFbshBRkvxDlSA-g_fRakZZN5Q,3342
17
+ reeval_python/wire.py,sha256=-l9FAC7-fo4G1U9rZw47Nw44z-spHcs4Kck5IFNQZFY,7275
18
+ reeval_python-0.19.0.dist-info/METADATA,sha256=dB5v9ORVVbFujc8wULbV-_YNbE6Te4qK7d8ZHmdsnHs,10014
19
+ reeval_python-0.19.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
20
+ reeval_python-0.19.0.dist-info/entry_points.txt,sha256=174mqsaUhMzSZlbOUgyM8P_YN-VXmrGcU8F3H-6Eu7g,50
21
+ reeval_python-0.19.0.dist-info/licenses/LICENSE,sha256=ksfhGdGZnBIw2o77d0o71LHzgK-bRGUx1qS6nzYMjK4,11348
22
+ reeval_python-0.19.0.dist-info/RECORD,,
@@ -1,22 +0,0 @@
1
- reeval_python/__init__.py,sha256=EjoZRdxQwnpazy5U49o2IWczzh7gzVUGJDssbXyY30Q,1356
2
- reeval_python/__main__.py,sha256=opVNjZHR3dLJnP_p528E5oz8E-oow6606wwPZ0L0Mto,282
3
- reeval_python/_wire.py,sha256=22jUXhLHHPq-7Lm8b3CEpNT1LKsjS2ekmuP_lSD3vvc,87210
4
- reeval_python/aio.py,sha256=yyi09fi_Bt7N704HRcRJLTGmNHcxyD3bFwevPcMa_Z4,421
5
- reeval_python/binaries.json,sha256=GslgTwSeQ-hMH-NZZl3QLiyOg4k5rwqmuJOuafXxJnE,1902
6
- reeval_python/checks.py,sha256=gYSpLMzMMvZ_neV5siB9cLpUfOwSbax6tj-N8N57NNE,11078
7
- reeval_python/cli.py,sha256=qyXObxNbWoisgQCo0tEhqDh0oM141dQ77Jqung60Vv0,18953
8
- reeval_python/context.py,sha256=tGlIlFfyRv9_g3WUzfxlnrrkcPuOk1bO0T21dWeaT8k,17993
9
- reeval_python/declare.py,sha256=5uy4SLMIBsZhHt9CBwL6Qm9G1IzGX-54cEBf7NFjQkM,20177
10
- reeval_python/environment.py,sha256=9GYE6j2M0xoITBpbg5oU1_9e87guOPo-YNNNVy_Stb0,6261
11
- reeval_python/errors.py,sha256=wgwjeVoZImkIuKC2GiYK6ahar85glpOmDAWKRg6cowY,894
12
- reeval_python/expect.py,sha256=M_0YWpWl-l-g2KFRrxzr9XtD8SV82JlHPFhlR9CVVoQ,10928
13
- reeval_python/options.py,sha256=netFwG2GtikJDOoBCf53dMnZktnxLJIKG1qPU4lEsY4,3547
14
- reeval_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- reeval_python/runner.py,sha256=bNwRfHQdeM0PC113G5d0RzFRtHcFMMLj8bE3cnoZKII,21070
16
- reeval_python/types.py,sha256=Ycy9KwhmtSfYKTny-DFbshBRkvxDlSA-g_fRakZZN5Q,3342
17
- reeval_python/wire.py,sha256=-l9FAC7-fo4G1U9rZw47Nw44z-spHcs4Kck5IFNQZFY,7275
18
- reeval_python-0.18.0.dist-info/METADATA,sha256=QqhZ-D_ZdxI6Ihgw_gy6AYrFpGOUjX_KgM-5d5NFsAA,10022
19
- reeval_python-0.18.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
20
- reeval_python-0.18.0.dist-info/entry_points.txt,sha256=174mqsaUhMzSZlbOUgyM8P_YN-VXmrGcU8F3H-6Eu7g,50
21
- reeval_python-0.18.0.dist-info/licenses/LICENSE,sha256=ksfhGdGZnBIw2o77d0o71LHzgK-bRGUx1qS6nzYMjK4,11348
22
- reeval_python-0.18.0.dist-info/RECORD,,