Card: paper link and citation; tasks: updated grader and stream copies
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- README.md+30-5
- harbor/kv-store-R1000-seed42/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R1000-seed42/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R1000-seed42/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R1000-seed43/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R1000-seed43/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R1000-seed43/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R1000-seed44/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R1000-seed44/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R1000-seed44/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R1000-seed45/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R1000-seed45/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R1000-seed45/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R1000-seed46/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R1000-seed46/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R1000-seed46/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R1000-seed47/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R1000-seed47/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R1000-seed47/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R1000-seed48/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R1000-seed48/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R1000-seed48/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R1000-seed49/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R1000-seed49/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R1000-seed49/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R130-seed42/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R130-seed42/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R130-seed42/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R130-seed43/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R130-seed43/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R130-seed43/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R130-seed44/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R130-seed44/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R130-seed44/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R130-seed45/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R130-seed45/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R130-seed45/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R130-seed46/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R130-seed46/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R130-seed46/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R130-seed47/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R130-seed47/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R130-seed47/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R130-seed48/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R130-seed48/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R130-seed48/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R130-seed49/tests/_cb/contextbench/graders/log.py+7-3
- harbor/kv-store-R130-seed49/tests/_cb/contextbench/runner.py+14
- harbor/kv-store-R130-seed49/tests/_cb/contextbench/stream.py+60-10
- harbor/kv-store-R16000-seed42/tests/_cb/contextbench/graders/log.py+7-3
40 unmodified lines4142434445464725 unmodified lines73747576777833 unmodified lines1121131141151161171181193 unmodified lines12312412512612712812913013113240 unmodified linesuser turns, more than the context budget holds, and the reward is read from theagent's own messages: what survived in its context, not what it wrote to disk.Paper: [https://huggingface.co/papers/2609.37725](https://huggingface.co/papers/2609.37725)## Families25 unmodified lines| `gold` | string (JSON) | the answers the graders score against || `meta` | string (JSON) | generator settings and instance statistics |Each operation is shown to the agent as`=== {header} ({remaining} op(s) remaining after this) ===` followed by its body.33 unmodified linesThe `harbor/` directory holds one Harbor task per instance, and `registry.json`lists the datasets `contextbench` (every task) and `contextbench-<family>`(for example `contextbench-kv-store`). Download the repository, then run Harborfrom inside it:```bashhf download context-language-model/ContextBench --repo-type dataset --local-dir contextbench-hf3 unmodified lines```Use `-d contextbench-sudoku-sketchpad` for one family, `-i <task_id>` for one task,`-p harbor/` to run the directory without the registry, or `-a oracle` to check atask with its reference solution. Agents that deliver operations into a runningconversation ship with the `contextbench` package (`contextbench.harbor.agents`).## LicenseApache-2.0.40 unmodified lines4142434445464725 unmodified lines73747576777879808133 unmodified lines1151161171181191201211221231241251261271281293 unmodified lines13313413513613713813914014114214314414514614714814915015115215315415515615740 unmodified linesuser turns, more than the context budget holds, and the reward is read from theagent's own messages: what survived in its context, not what it wrote to disk.Paper: [Context Language Models](https://arxiv.org/abs/2609.37725) ([paper page](https://huggingface.co/papers/2609.37725))## Families25 unmodified lines| `gold` | string (JSON) | the answers the graders score against || `meta` | string (JSON) | generator settings and instance statistics |The budget is counted in `o200k_base` tokens for every agent. An agent may enforce astricter budget of its own; that is part of the agent, not of the benchmark.Each operation is shown to the agent as`=== {header} ({remaining} op(s) remaining after this) ===` followed by its body.33 unmodified linesThe `harbor/` directory holds one Harbor task per instance, and `registry.json`lists the datasets `contextbench` (every task) and `contextbench-<family>`(for example `contextbench-kv-store`). The same tasks are on GitHub, so Harbor runsthem in one line:```bashharbor jobs start --repo RulinShao/ContextBench -d contextbench \-a contextbench.harbor.agents:Terminus2Stream -m <model>```Or download this repository and run Harbor from inside it:```bashhf download context-language-model/ContextBench --repo-type dataset --local-dir contextbench-hf3 unmodified lines```Use `-d contextbench-sudoku-sketchpad` for one family, `-i <task_id>` for one task,`-p harbor/` to run the downloaded directory without the registry, or `-a oracle` tocheck a task with its reference solution. Agents that deliver operations into a runningconversation ship with the `contextbench` package (`contextbench.harbor.agents`).## CitationContextBench was introduced in the Context Language Models paper. If you use it, please cite:```bibtex@article{shao2026context,title = {Context Language Models},author = {Shao, Rulin and Shen, Shannon Zejiang and Yin, Junjie Oscar and Li, Yuetai andWang, Minheng and Ivison, Hamish and Poovendran, Radha and Lambert, Nathan andXiao, Teng and Lewis, Mike and Yih, Wen-tau and Zettlemoyer, Luke and Koh, Pang Wei},journal = {arXiv preprint arXiv:2609.37725},year = {2026}}```## LicenseApache-2.0.
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
104 unmodified lines1051061071081091104 unmodified lines115116117118119120121122123104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict."""instance = load_instance(instance_dir)out = Path(out_dir)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve104 unmodified lines1051061071081091101114 unmodified lines116117118119120121122123124125126127128129130131132133134135136137104 unmodified linesmax_turns: int | None = None,system_prompt: str | None = None,delivery: str = "reply",overwrite: bool = False,) -> dict:"""Run one instance end to end and return the result dict.4 unmodified linesWrites ``context_snapshots/turn-NNNN.json`` per turn, ``interactive_stream.json``and ``result.json`` into ``out_dir``, and returns the same result dict.``out_dir`` must be empty or absent: the graders read every snapshot in it, sofiles from an earlier run would be credited to this one. ``overwrite=True``deletes an existing ``out_dir`` first."""instance = load_instance(instance_dir)out = Path(out_dir)if out.exists() and any(out.iterdir()):if not overwrite:raise FileExistsError(f"{out} is not empty; the graders would read its old snapshots as part ""of this run. Use a fresh directory or pass overwrite=True.")import shutilshutil.rmtree(out)out.mkdir(parents=True, exist_ok=True)usable = budget - reserve
78 unmodified lines798081828384858687888990919219 unmodified lines11211311411511611711811912012112212378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Shell statement separators. A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last segment is a clean echo._SEPARATORS = re.compile(r";|\n|&&|\|\|")_HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")_MULTILINE_QUOTED = re.compile(r"'[^']*\n[^']*'|\"(?:[^\"\\]|\\.)*\n(?:[^\"\\]|\\.)*\"")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andquoted strings that span lines (both are data, not statements)."""text = _strip_heredoc_bodies(command)text = _MULTILINE_QUOTED.sub("''", text)return _SEPARATORS.split(text)@dataclass(frozen=True)78 unmodified lines798081828384858687888919 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217378 unmodified lines_SUBMIT_LINE_RE = _standalone_line_re(SUBMIT_MARKER)_SUBMIT_SEGMENT_RE = _standalone_command_re(SUBMIT_MARKER)#: Statements are split on ``;``, newline, ``&&`` and ``||`` outside quotes (see#: :func:`_split_unquoted`). A bundled command such as#: ``printf '<<<ANSWER ...>>>'; echo READY_FOR_NEXT_OP`` advances, because its#: last statement is a clean echo._HEREDOC_OPEN = re.compile(r"<<(-?)\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")def _strip_heredoc_bodies(command: str) -> str:19 unmodified linesreturn "\n".join(out)def _split_unquoted(text: str) -> list[str]:"""Split on ``;``, newline, ``&&`` and ``||`` outside quotes.Single quotes are literal to the closing quote; double quotes honour backslashescapes; a backslash outside quotes escapes the next character. A separator insidequotes is data (``printf '%s' 'a;echo READY_FOR_NEXT_OP;b'`` is one statement).An unterminated quote keeps the rest of the text in the current statement."""segments: list[str] = []buf: list[str] = []quote: str | None = Nonei, n = 0, len(text)while i < n:c = text[i]if quote == "'":buf.append(c)if c == "'":quote = Nonei += 1continueif quote == '"':buf.append(c)if c == "\\" and i + 1 < n:buf.append(text[i + 1])i += 2continueif c == '"':quote = Nonei += 1continueif c == "\\" and i + 1 < n:buf.append(text[i:i + 2])i += 2continueif c in "'\"":quote = cbuf.append(c)i += 1continueif c in ";\n":segments.append("".join(buf))buf = []i += 1continueif text.startswith("&&", i) or text.startswith("||", i):segments.append("".join(buf))buf = []i += 2continuebuf.append(c)i += 1segments.append("".join(buf))return segmentsdef _statements(command: str) -> list[str]:"""Split a shell command into statements, ignoring here-document bodies andseparators inside quoted strings (both are data, not statements)."""return _split_unquoted(_strip_heredoc_bodies(command))@dataclass(frozen=True)
40 unmodified lines4142434445464748495040 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when the integer appears as a standalone token."""pat = re.compile(rf"(?<!\d){re.escape(want)}(?!\d)")return any(pat.search(a) for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:40 unmodified lines414243444546474849505152535440 unmodified lines_TAG_RE = re.compile(r"\s*#[0-9a-f]+\s*$")#: A complete number: optional sign, digits, optional decimal part._NUMBER_RE = re.compile(r"[-+]?\d+(?:\.\d+)?")def _count_correct(want: str, answers: set[str]) -> bool:"""A count is correct when an answer states exactly one number and it equals thegold integer. ``-5``, ``5.9`` or a hedge such as ``5 or 6`` is not ``5``."""return any(_NUMBER_RE.findall(a) == [want] for a in answers)def _lookup_correct(want: str, answers: set[str]) -> bool:
README.md+30-5
harbor/kv-store-R1000-seed42/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R1000-seed42/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R1000-seed42/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R1000-seed43/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R1000-seed43/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R1000-seed43/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R1000-seed44/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R1000-seed44/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R1000-seed44/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R1000-seed45/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R1000-seed45/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R1000-seed45/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R1000-seed46/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R1000-seed46/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R1000-seed46/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R1000-seed47/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R1000-seed47/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R1000-seed47/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R1000-seed48/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R1000-seed48/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R1000-seed48/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R1000-seed49/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R1000-seed49/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R1000-seed49/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R130-seed42/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R130-seed42/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R130-seed42/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R130-seed43/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R130-seed43/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R130-seed43/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R130-seed44/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R130-seed44/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R130-seed44/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R130-seed45/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R130-seed45/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R130-seed45/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R130-seed46/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R130-seed46/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R130-seed46/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R130-seed47/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R130-seed47/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R130-seed47/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R130-seed48/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R130-seed48/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R130-seed48/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R130-seed49/tests/_cb/contextbench/graders/log.py+7-3
harbor/kv-store-R130-seed49/tests/_cb/contextbench/runner.py+14
harbor/kv-store-R130-seed49/tests/_cb/contextbench/stream.py+60-10
harbor/kv-store-R16000-seed42/tests/_cb/contextbench/graders/log.py+7-3