rulins commited on
Commit
52bd961
·
verified ·
1 Parent(s): 608ecfa

Card: paper link and citation; tasks: updated grader and stream copies

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. README.md +30 -5
  2. harbor/kv-store-R1000-seed42/tests/_cb/contextbench/graders/log.py +7 -3
  3. harbor/kv-store-R1000-seed42/tests/_cb/contextbench/runner.py +14 -0
  4. harbor/kv-store-R1000-seed42/tests/_cb/contextbench/stream.py +60 -10
  5. harbor/kv-store-R1000-seed43/tests/_cb/contextbench/graders/log.py +7 -3
  6. harbor/kv-store-R1000-seed43/tests/_cb/contextbench/runner.py +14 -0
  7. harbor/kv-store-R1000-seed43/tests/_cb/contextbench/stream.py +60 -10
  8. harbor/kv-store-R1000-seed44/tests/_cb/contextbench/graders/log.py +7 -3
  9. harbor/kv-store-R1000-seed44/tests/_cb/contextbench/runner.py +14 -0
  10. harbor/kv-store-R1000-seed44/tests/_cb/contextbench/stream.py +60 -10
  11. harbor/kv-store-R1000-seed45/tests/_cb/contextbench/graders/log.py +7 -3
  12. harbor/kv-store-R1000-seed45/tests/_cb/contextbench/runner.py +14 -0
  13. harbor/kv-store-R1000-seed45/tests/_cb/contextbench/stream.py +60 -10
  14. harbor/kv-store-R1000-seed46/tests/_cb/contextbench/graders/log.py +7 -3
  15. harbor/kv-store-R1000-seed46/tests/_cb/contextbench/runner.py +14 -0
  16. harbor/kv-store-R1000-seed46/tests/_cb/contextbench/stream.py +60 -10
  17. harbor/kv-store-R1000-seed47/tests/_cb/contextbench/graders/log.py +7 -3
  18. harbor/kv-store-R1000-seed47/tests/_cb/contextbench/runner.py +14 -0
  19. harbor/kv-store-R1000-seed47/tests/_cb/contextbench/stream.py +60 -10
  20. harbor/kv-store-R1000-seed48/tests/_cb/contextbench/graders/log.py +7 -3
  21. harbor/kv-store-R1000-seed48/tests/_cb/contextbench/runner.py +14 -0
  22. harbor/kv-store-R1000-seed48/tests/_cb/contextbench/stream.py +60 -10
  23. harbor/kv-store-R1000-seed49/tests/_cb/contextbench/graders/log.py +7 -3
  24. harbor/kv-store-R1000-seed49/tests/_cb/contextbench/runner.py +14 -0
  25. harbor/kv-store-R1000-seed49/tests/_cb/contextbench/stream.py +60 -10
  26. harbor/kv-store-R130-seed42/tests/_cb/contextbench/graders/log.py +7 -3
  27. harbor/kv-store-R130-seed42/tests/_cb/contextbench/runner.py +14 -0
  28. harbor/kv-store-R130-seed42/tests/_cb/contextbench/stream.py +60 -10
  29. harbor/kv-store-R130-seed43/tests/_cb/contextbench/graders/log.py +7 -3
  30. harbor/kv-store-R130-seed43/tests/_cb/contextbench/runner.py +14 -0
  31. harbor/kv-store-R130-seed43/tests/_cb/contextbench/stream.py +60 -10
  32. harbor/kv-store-R130-seed44/tests/_cb/contextbench/graders/log.py +7 -3
  33. harbor/kv-store-R130-seed44/tests/_cb/contextbench/runner.py +14 -0
  34. harbor/kv-store-R130-seed44/tests/_cb/contextbench/stream.py +60 -10
  35. harbor/kv-store-R130-seed45/tests/_cb/contextbench/graders/log.py +7 -3
  36. harbor/kv-store-R130-seed45/tests/_cb/contextbench/runner.py +14 -0
  37. harbor/kv-store-R130-seed45/tests/_cb/contextbench/stream.py +60 -10
  38. harbor/kv-store-R130-seed46/tests/_cb/contextbench/graders/log.py +7 -3
  39. harbor/kv-store-R130-seed46/tests/_cb/contextbench/runner.py +14 -0
  40. harbor/kv-store-R130-seed46/tests/_cb/contextbench/stream.py +60 -10
  41. harbor/kv-store-R130-seed47/tests/_cb/contextbench/graders/log.py +7 -3
  42. harbor/kv-store-R130-seed47/tests/_cb/contextbench/runner.py +14 -0
  43. harbor/kv-store-R130-seed47/tests/_cb/contextbench/stream.py +60 -10
  44. harbor/kv-store-R130-seed48/tests/_cb/contextbench/graders/log.py +7 -3
  45. harbor/kv-store-R130-seed48/tests/_cb/contextbench/runner.py +14 -0
  46. harbor/kv-store-R130-seed48/tests/_cb/contextbench/stream.py +60 -10
  47. harbor/kv-store-R130-seed49/tests/_cb/contextbench/graders/log.py +7 -3
  48. harbor/kv-store-R130-seed49/tests/_cb/contextbench/runner.py +14 -0
  49. harbor/kv-store-R130-seed49/tests/_cb/contextbench/stream.py +60 -10
  50. harbor/kv-store-R16000-seed42/tests/_cb/contextbench/graders/log.py +7 -3
README.md CHANGED
@@ -41,7 +41,7 @@ not fit in its context window. Each task streams a sequence of operations as ord
41
  user turns, more than the context budget holds, and the reward is read from the
42
  agent's own messages: what survived in its context, not what it wrote to disk.
43
 
44
- Paper: [https://huggingface.co/papers/2609.37725](https://huggingface.co/papers/2609.37725)
45
 
46
  ## Families
47
 
@@ -73,6 +73,9 @@ and a reserve of 2048.
73
  | `gold` | string (JSON) | the answers the graders score against |
74
  | `meta` | string (JSON) | generator settings and instance statistics |
75
 
 
 
 
76
  Each operation is shown to the agent as
77
  `=== {header} ({remaining} op(s) remaining after this) ===` followed by its body.
78
 
@@ -112,8 +115,15 @@ result = run(my_agent, inst, budget=row["budget"], reserve=row["reserve"],
112
 
113
  The `harbor/` directory holds one Harbor task per instance, and `registry.json`
114
  lists the datasets `contextbench` (every task) and `contextbench-<family>`
115
- (for example `contextbench-kv-store`). Download the repository, then run Harbor
116
- from inside it:
 
 
 
 
 
 
 
117
 
118
  ```bash
119
  hf download context-language-model/ContextBench --repo-type dataset --local-dir contextbench-hf
@@ -123,10 +133,25 @@ harbor jobs start --registry-path registry.json -d contextbench \
123
  ```
124
 
125
  Use `-d contextbench-sudoku-sketchpad` for one family, `-i <task_id>` for one task,
126
- `-p harbor/` to run the directory without the registry, or `-a oracle` to check a
127
- task with its reference solution. Agents that deliver operations into a running
128
  conversation ship with the `contextbench` package (`contextbench.harbor.agents`).
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  ## License
131
 
132
  Apache-2.0.
 
41
  user turns, more than the context budget holds, and the reward is read from the
42
  agent's own messages: what survived in its context, not what it wrote to disk.
43
 
44
+ Paper: [Context Language Models](https://arxiv.org/abs/2609.37725) ([paper page](https://huggingface.co/papers/2609.37725))
45
 
46
  ## Families
47
 
 
73
  | `gold` | string (JSON) | the answers the graders score against |
74
  | `meta` | string (JSON) | generator settings and instance statistics |
75
 
76
+ The budget is counted in `o200k_base` tokens for every agent. An agent may enforce a
77
+ stricter budget of its own; that is part of the agent, not of the benchmark.
78
+
79
  Each operation is shown to the agent as
80
  `=== {header} ({remaining} op(s) remaining after this) ===` followed by its body.
81
 
 
115
 
116
  The `harbor/` directory holds one Harbor task per instance, and `registry.json`
117
  lists the datasets `contextbench` (every task) and `contextbench-<family>`
118
+ (for example `contextbench-kv-store`). The same tasks are on GitHub, so Harbor runs
119
+ them in one line:
120
+
121
+ ```bash
122
+ harbor jobs start --repo RulinShao/ContextBench -d contextbench \
123
+ -a contextbench.harbor.agents:Terminus2Stream -m <model>
124
+ ```
125
+
126
+ Or download this repository and run Harbor from inside it:
127
 
128
  ```bash
129
  hf download context-language-model/ContextBench --repo-type dataset --local-dir contextbench-hf
 
133
  ```
134
 
135
  Use `-d contextbench-sudoku-sketchpad` for one family, `-i <task_id>` for one task,
136
+ `-p harbor/` to run the downloaded directory without the registry, or `-a oracle` to
137
+ check a task with its reference solution. Agents that deliver operations into a running
138
  conversation ship with the `contextbench` package (`contextbench.harbor.agents`).
139
 
140
+ ## Citation
141
+
142
+ ContextBench was introduced in the Context Language Models paper. If you use it, please cite:
143
+
144
+ ```bibtex
145
+ @article{shao2026context,
146
+ title = {Context Language Models},
147
+ author = {Shao, Rulin and Shen, Shannon Zejiang and Yin, Junjie Oscar and Li, Yuetai and
148
+ Wang, Minheng and Ivison, Hamish and Poovendran, Radha and Lambert, Nathan and
149
+ Xiao, Teng and Lewis, Mike and Yih, Wen-tau and Zettlemoyer, Luke and Koh, Pang Wei},
150
+ journal = {arXiv preprint arXiv:2609.37725},
151
+ year = {2026}
152
+ }
153
+ ```
154
+
155
  ## License
156
 
157
  Apache-2.0.
harbor/kv-store-R1000-seed42/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R1000-seed42/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R1000-seed42/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R1000-seed43/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R1000-seed43/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R1000-seed43/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R1000-seed44/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R1000-seed44/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R1000-seed44/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R1000-seed45/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R1000-seed45/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R1000-seed45/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R1000-seed46/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R1000-seed46/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R1000-seed46/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R1000-seed47/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R1000-seed47/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R1000-seed47/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R1000-seed48/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R1000-seed48/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R1000-seed48/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R1000-seed49/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R1000-seed49/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R1000-seed49/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R130-seed42/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R130-seed42/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R130-seed42/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R130-seed43/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R130-seed43/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R130-seed43/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R130-seed44/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R130-seed44/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R130-seed44/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R130-seed45/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R130-seed45/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R130-seed45/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R130-seed46/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R130-seed46/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R130-seed46/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R130-seed47/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R130-seed47/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R130-seed47/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R130-seed48/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R130-seed48/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R130-seed48/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R130-seed49/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool:
harbor/kv-store-R130-seed49/tests/_cb/contextbench/runner.py CHANGED
@@ -105,6 +105,7 @@ def run(
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
 
108
  ) -> dict:
109
  """Run one instance end to end and return the result dict.
110
 
@@ -115,9 +116,22 @@ def run(
115
 
116
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
117
  and ``result.json`` into ``out_dir``, and returns the same result dict.
 
 
 
 
118
  """
119
  instance = load_instance(instance_dir)
120
  out = Path(out_dir)
 
 
 
 
 
 
 
 
 
121
  out.mkdir(parents=True, exist_ok=True)
122
  usable = budget - reserve
123
 
 
105
  max_turns: int | None = None,
106
  system_prompt: str | None = None,
107
  delivery: str = "reply",
108
+ overwrite: bool = False,
109
  ) -> dict:
110
  """Run one instance end to end and return the result dict.
111
 
 
116
 
117
  Writes ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``
118
  and ``result.json`` into ``out_dir``, and returns the same result dict.
119
+
120
+ ``out_dir`` must be empty or absent: the graders read every snapshot in it, so
121
+ files from an earlier run would be credited to this one. ``overwrite=True``
122
+ deletes an existing ``out_dir`` first.
123
  """
124
  instance = load_instance(instance_dir)
125
  out = Path(out_dir)
126
+ if out.exists() and any(out.iterdir()):
127
+ if not overwrite:
128
+ raise FileExistsError(
129
+ f"{out} is not empty; the graders would read its old snapshots as part "
130
+ "of this run. Use a fresh directory or pass overwrite=True."
131
+ )
132
+ import shutil
133
+
134
+ shutil.rmtree(out)
135
  out.mkdir(parents=True, exist_ok=True)
136
  usable = budget - reserve
137
 
harbor/kv-store-R130-seed49/tests/_cb/contextbench/stream.py CHANGED
@@ -79,14 +79,11 @@ _READY_SEGMENT_RE = _standalone_command_re(ADVANCE_MARKER)
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
- #: Shell statement separators. A bundled command such as
 
83
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
84
- #: last segment is a clean echo.
85
- _SEPARATORS = re.compile(r";|\n|&&|\|\|")
86
-
87
-
88
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
89
- _MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")
90
 
91
 
92
  def _strip_heredoc_bodies(command: str) -> str:
@@ -112,12 +109,65 @@ def _strip_heredoc_bodies(command: str) -> str:
112
  return "\n".join(out)
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def _statements(command: str) -> list[str]:
116
  """Split a shell command into statements, ignoring here-document bodies and
117
- quoted strings that span lines (both are data, not statements)."""
118
- text = _strip_heredoc_bodies(command)
119
- text = _MULTILINE_QUOTED.sub("''", text)
120
- return _SEPARATORS.split(text)
121
 
122
 
123
  @dataclass(frozen=True)
 
79
  _SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)
80
  _SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)
81
 
82
+ #: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see
83
+ #: :func:`_split_unquoted`). A bundled command such as
84
  #: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its
85
+ #: last statement is a clean echo.
 
 
 
86
  _HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
 
87
 
88
 
89
  def _strip_heredoc_bodies(command: str) -> str:
 
109
  return "\n".join(out)
110
 
111
 
112
+ def _split_unquoted(text: str) -> list[str]:
113
+ """Split on ``;``, newline, ``&&`` and ``||`` outside quotes.
114
+
115
+ Single quotes are literal to the closing quote; double quotes honour backslash
116
+ escapes; a backslash outside quotes escapes the next character. A separator inside
117
+ quotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).
118
+ An unterminated quote keeps the rest of the text in the current statement.
119
+ """
120
+ segments: list[str] = []
121
+ buf: list[str] = []
122
+ quote: str | None = None
123
+ i, n = 0, len(text)
124
+ while i < n:
125
+ c = text[i]
126
+ if quote == "'":
127
+ buf.append(c)
128
+ if c == "'":
129
+ quote = None
130
+ i += 1
131
+ continue
132
+ if quote == '"':
133
+ buf.append(c)
134
+ if c == "\\" and i + 1 < n:
135
+ buf.append(text[i + 1])
136
+ i += 2
137
+ continue
138
+ if c == '"':
139
+ quote = None
140
+ i += 1
141
+ continue
142
+ if c == "\\" and i + 1 < n:
143
+ buf.append(text[i:i + 2])
144
+ i += 2
145
+ continue
146
+ if c in "'\"":
147
+ quote = c
148
+ buf.append(c)
149
+ i += 1
150
+ continue
151
+ if c in ";\n":
152
+ segments.append("".join(buf))
153
+ buf = []
154
+ i += 1
155
+ continue
156
+ if text.startswith("&&", i) or text.startswith("||", i):
157
+ segments.append("".join(buf))
158
+ buf = []
159
+ i += 2
160
+ continue
161
+ buf.append(c)
162
+ i += 1
163
+ segments.append("".join(buf))
164
+ return segments
165
+
166
+
167
  def _statements(command: str) -> list[str]:
168
  """Split a shell command into statements, ignoring here-document bodies and
169
+ separators inside quoted strings (both are data, not statements)."""
170
+ return _split_unquoted(_strip_heredoc_bodies(command))
 
 
171
 
172
 
173
  @dataclass(frozen=True)
harbor/kv-store-R16000-seed42/tests/_cb/contextbench/graders/log.py CHANGED
@@ -41,10 +41,14 @@ ANSWER_RE = re.compile(
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
 
 
 
 
44
  def _count_correct(want: str, answers: set[str]) -> bool:
45
- """A count is correct when the integer appears as a standalone token."""
46
- pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")
47
- return any(pat.search(a) for a in answers)
48
 
49
 
50
  def _lookup_correct(want: str, answers: set[str]) -> bool:
 
41
  _TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")
42
 
43
 
44
+ #: A complete number: optional sign, digits, optional decimal part.
45
+ _NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")
46
+
47
+
48
  def _count_correct(want: str, answers: set[str]) -> bool:
49
+ """A count is correct when an answer states exactly one number and it equals the
50
+ gold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""
51
+ return any(_NUMBER_RE.findall(a) == [want] for a in answers)
52
 
53
 
54
  def _lookup_correct(want: str, answers: set[str]) -> bool: