diff --git a/.agent-eval/tasks/use-repo-scan/check.py b/.agent-eval/tasks/use-repo-scan/check.py index 4487d3824f..d9cdbfb32f 100644 --- a/.agent-eval/tasks/use-repo-scan/check.py +++ b/.agent-eval/tasks/use-repo-scan/check.py @@ -8,7 +8,7 @@ manifest_ok: examples/toy-repo/repo-eval.yaml exists, dokimi's manifest loader accepts it (repo_manifest.v1 schema and rules), and `cli.py repo scan ../examples/toy-repo --manifest -repo-eval.yaml --json` exits 0 with AGENTS.md among the scanned files. `repo validate` is not +repo-eval.yaml --json` exits 0 with AGENTS.md among the scanned files. `eval check --schema-only` is not required: it also wants eval_dir and the tasks directory to exist, which a scan-only manifest (like the framework's own benchmarks/self-scan.repo-eval.yaml) does not have. answer_names_claim_1/2: the final answer calls each broken claim (the missing path, the dead diff --git a/.agent-eval/tasks/use-repo-scan/oracle.patch b/.agent-eval/tasks/use-repo-scan/oracle.patch index 6d791751b3..38692c93a9 100644 --- a/.agent-eval/tasks/use-repo-scan/oracle.patch +++ b/.agent-eval/tasks/use-repo-scan/oracle.patch @@ -7,7 +7,7 @@ index 0000000..19f7355 +# dokimi manifest for an L0 scan of this repository's agent guidance: +# python cli.py repo scan --manifest repo-eval.yaml +# eval_dir, entry_points and tasks are required by repo_manifest.v1 and unused by a scan -+# (`repo validate` would refuse this file: the repository has no evaluation tasks). ++# (`eval check --schema-only` would refuse this file: the repository has no evaluation tasks). +schema: repo_manifest.v1 +id: tinycalc +eval_dir: .agent-eval diff --git a/dokimi/benchmarks/self-scan.repo-eval.yaml b/dokimi/benchmarks/self-scan.repo-eval.yaml index 5092771be2..1baf75fa01 100644 --- a/dokimi/benchmarks/self-scan.repo-eval.yaml +++ b/dokimi/benchmarks/self-scan.repo-eval.yaml @@ -1,9 +1,8 @@ # Copyright (C) 2026 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -# The framework's own agent guidance, scanned by L0 in CI (`repo scan .. --manifest-file`). -# eval_dir and tasks are required by repo_manifest.v1 and unused by a scan; this file is for -# `repo scan` only (`repo validate` would refuse it: the framework has no repository tasks). +# The framework's agent guidance, scanned by L0 in CI: `repo scan` only (`eval check --schema-only` would refuse it). +# eval_dir and tasks are required by repo_manifest.v1 and unused by a scan (the framework has no repository tasks). schema: repo_manifest.v1 id: dokimi eval_dir: dokimi/tests diff --git a/dokimi/changelog.d/20261124_120000_napetrov_cli-f1b-net.md b/dokimi/changelog.d/20261124_120000_napetrov_cli-f1b-net.md new file mode 100644 index 0000000000..f61c44933a --- /dev/null +++ b/dokimi/changelog.d/20261124_120000_napetrov_cli-f1b-net.md @@ -0,0 +1,14 @@ + + +### Changed + +- **Network, timeout and cache flags have one spelling each (part of #94, F1b).** The phase timeouts are one + `--timeout [PHASE=]SEC`: `repo run` and `eval check` `--build-timeout` is `--timeout build=SEC`, `--grade-timeout` + is `--timeout verify=SEC`, and a bare SEC is the agent run's (`repo run` only). `tasks run --network` takes + `[PHASE=]MODE[:hosts]`. Bare `none` or `public` sets every phase. An allowlist must specify `solve`, + `verify` or both, for example `--network solve,verify=allowlist:pypi.org`. `--cache NAME=DIR` is the one cache spelling in the + help text. The old timeout spellings exit 2 and print the new command. `--agent-network`, `--build-network` and + `--cache-root` keep their names: their values mean something other than the network policy or `--cache`. diff --git a/dokimi/docs/coding-harnesses.md b/dokimi/docs/coding-harnesses.md index 03ad8e4a12..a8213d8101 100644 --- a/dokimi/docs/coding-harnesses.md +++ b/dokimi/docs/coding-harnesses.md @@ -688,11 +688,14 @@ decisions land in `metrics.network.verify_egress`). Later sources win: deprecated `allow_internet`), then `[agent]` and `[verifier]` overrides, and `environment.egress` for an agent's solve. An unknown mode refuses the cell, and its `network.json` holds the reason. -3. The operator: `dokimi tasks run --network PHASE=MODE[:host,...]`, - repeatable, with `all` for every phase. For example - `--network verify=none` grades a public task offline, and - `--network solve=allowlist:pypi.org,files.pythonhosted.org` lets every - arm install packages. +3. The operator: `dokimi tasks run --network [PHASE=]MODE[:host,...]`, + repeatable. Bare `none` or `public`, or `all=none` or `all=public`, + applies to every phase. Bare `none` also disables build networking, so + image builds fail if their `RUN` steps need network access. Use + `--network verify=none` to grade offline while keeping the build policy. + An allowlist requires `solve`, `verify` or both. For example, + `--network solve,verify=allowlist:pypi.org,files.pythonhosted.org` lets + both phases reach those package hosts. Under `allowlist`, HTTPS goes through the sidecar's CONNECT proxy. A bare allowlist entry is `host:443`, so a plain-HTTP request to that host (port 80) is diff --git a/dokimi/docs/quickstart.md b/dokimi/docs/quickstart.md index e9a54f9bf5..7a807ffc0c 100644 --- a/dokimi/docs/quickstart.md +++ b/dokimi/docs/quickstart.md @@ -266,7 +266,7 @@ failed check. A command that validates its input and then runs exits 2 for the first and 1 for the second. Not every command follows this yet: `repo run` and -`eval check` exit 2 for a source that does not parse, a pinned local path inside a repository, a `--cache-dir` (or `$DOKIMI_REPO_CACHE`) that is not a usable directory or a `--cache-root` or `--cache NAME=PATH` that is not one, +`eval check` exit 2 for a source that does not parse, a pinned local path inside a repository, a `--cache-dir` (or `$DOKIMI_REPO_CACHE`) that is not a usable directory or a `--cache-root` or `--cache NAME=DIR` that is not one, but still exit 1 for other input refusals (a missing or malformed manifest, a bad arm; the `✗` lines; a `.mcp.json` the CLI rejects under `--tools all` is exit 2 before any cell; a `--manifest` path that leaves the source tree as typed is exit 2, pinned or not, as a source refusal; a link in the tree that leads out of it is exit 1), and diff --git a/dokimi/docs/reference/cli-interface.json b/dokimi/docs/reference/cli-interface.json index c8e6f6d01c..027db2cad7 100644 --- a/dokimi/docs/reference/cli-interface.json +++ b/dokimi/docs/reference/cli-interface.json @@ -650,14 +650,12 @@ {"key": "--allow-unsupported", "action": "_StoreTrueAction", "choices": null, "const": true, "default": false, "group_key": null, "group_required": null, "hidden": false, "is_flag": true, "kind": "option", "nargs": 0, "position": null, "required": false, "type": null}, {"key": "--arm", "action": "_AppendAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--build-network", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, - {"key": "--build-timeout", "action": "_StoreAction", "choices": null, "const": null, "default": 10800, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": "dokimi.cli.build_parser..positive_int#faf57db5ff9f"}, {"key": "--cache", "action": "_AppendAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--cache-dir", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--cache-root", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--concurrency/-j", "action": "_StoreAction", "choices": null, "const": null, "default": 1, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": "dokimi.cli.build_parser..positive_int#faf57db5ff9f"}, {"key": "--docker", "action": "_StoreAction", "choices": null, "const": null, "default": "docker", "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--fail-on", "action": "_StoreAction", "choices": ["'fail'", "'warn'"], "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, - {"key": "--grade-timeout", "action": "_StoreAction", "choices": null, "const": null, "default": 3600, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": "dokimi.cli.build_parser..positive_int#faf57db5ff9f"}, {"key": "--help/-h", "action": "_HelpAction", "choices": null, "const": null, "default": "==SUPPRESS==", "group_key": null, "group_required": null, "hidden": false, "is_flag": true, "kind": "option", "nargs": 0, "position": null, "required": false, "type": null}, {"key": "--image", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--json", "action": "_StoreTrueAction", "choices": null, "const": true, "default": false, "group_key": null, "group_required": null, "hidden": false, "is_flag": true, "kind": "option", "nargs": 0, "position": null, "required": false, "type": null}, @@ -669,6 +667,7 @@ {"key": "--source-dir", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--suite", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--task", "action": "_AppendAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, + {"key": "--timeout", "action": "_PhaseSeconds", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": "dokimi.commands.repo_run._timeout_flag..phase_seconds#5d93375793d0"}, {"key": "--warm", "action": "_StoreTrueAction", "choices": null, "const": true, "default": false, "group_key": null, "group_required": null, "hidden": false, "is_flag": true, "kind": "option", "nargs": 0, "position": null, "required": false, "type": null} ], "path": "dokimi eval check", @@ -1458,7 +1457,6 @@ {"key": "--arm", "action": "_AppendAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": true, "type": null}, {"key": "--bin", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--build-network", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, - {"key": "--build-timeout", "action": "_StoreAction", "choices": null, "const": null, "default": 10800, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": "dokimi.cli.build_parser..positive_int#faf57db5ff9f"}, {"key": "--cache", "action": "_AppendAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--cache-dir", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--cache-root", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, @@ -1467,7 +1465,6 @@ {"key": "--delegation", "action": "_StoreAction", "choices": ["'native'", "'none'"], "const": null, "default": "native", "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--docker", "action": "_StoreAction", "choices": null, "const": null, "default": "docker", "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--force", "action": "_StoreTrueAction", "choices": null, "const": true, "default": false, "group_key": null, "group_required": null, "hidden": false, "is_flag": true, "kind": "option", "nargs": 0, "position": null, "required": false, "type": null}, - {"key": "--grade-timeout", "action": "_StoreAction", "choices": null, "const": null, "default": 3600, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": "dokimi.cli.build_parser..positive_int#faf57db5ff9f"}, {"key": "--harness", "action": "_StoreAction", "choices": null, "const": null, "default": "claude-code", "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--help/-h", "action": "_HelpAction", "choices": null, "const": null, "default": "==SUPPRESS==", "group_key": null, "group_required": null, "hidden": false, "is_flag": true, "kind": "option", "nargs": 0, "position": null, "required": false, "type": null}, {"key": "--image", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, @@ -1486,7 +1483,7 @@ {"key": "--source-dir", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--suite", "action": "_StoreAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, {"key": "--task", "action": "_AppendAction", "choices": null, "const": null, "default": null, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null}, - {"key": "--timeout", "action": "_StoreAction", "choices": null, "const": null, "default": 2700, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": "dokimi.cli.build_parser..positive_int#faf57db5ff9f"}, + {"key": "--timeout", "action": "_PhaseSeconds", "choices": null, "const": null, "default": 2700, "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": "dokimi.commands.repo_run._timeout_flag..phase_seconds#e985ebe24af9"}, {"key": "--tools", "action": "_StoreAction", "choices": null, "const": null, "default": "all", "group_key": null, "group_required": null, "hidden": false, "is_flag": false, "kind": "option", "nargs": null, "position": null, "required": false, "type": null} ], "path": "dokimi repo run", diff --git a/dokimi/docs/repo-evaluation-contract.md b/dokimi/docs/repo-evaluation-contract.md index 43eb13a94f..0b9a4bfece 100644 --- a/dokimi/docs/repo-evaluation-contract.md +++ b/dokimi/docs/repo-evaluation-contract.md @@ -175,7 +175,7 @@ outside every workspace and passes its absolute path to entry points as anywhere in that context, for example a build wrapper under ``, and must work for every task base: a version pinned in the task tree (such as `.bazelversion`) is read at run time, not baked in. A build that runs - past `--build-timeout` seconds (3 hours by default) fails as a container + past `--timeout build=SEC` seconds (3 hours by default) fails as a container error rather than hanging the batch. - `eval check` (§4.3) fails a task whose agent container can read any file under `tasks` or `{source_dir}`. @@ -838,7 +838,7 @@ A missing cell counts on its host’s row when one exists. Otherwise it counts o its task, arm and model, or only in the batch total when there are zero or multiple such rows. Both commands exit 2, before any build, on a source that does not parse (a local path that is not a -directory, an unpinned remote), on a pinned local path inside a repository that is not its root, on a `--cache-dir` (or, without the flag, a `$DOKIMI_REPO_CACHE`) that is not a usable directory and on a `--cache-root` or `--cache NAME=PATH` that is not one; a +directory, an unpinned remote), on a pinned local path inside a repository that is not its root, on a `--cache-dir` (or, without the flag, a `$DOKIMI_REPO_CACHE`) that is not a usable directory and on a `--cache-root` or `--cache NAME=DIR` that is not one; a source that parses but cannot be opened (clone, fetch, revision) exits 1 with a `✗` line. A manifest that is missing or malformed exits 1 too; a `--manifest` path that leaves the source tree is refused as a source and exits 2, for an unpinned local directory and for a pinned source (`@`) alike; a link in the tree that leads out of it, the default @@ -2489,7 +2489,7 @@ eval tree to `/_eval/content`, and build the image from the eval tree without its tasks directory (tag `dokimi/:`) unless `--image` names one. Cache directories default to `~/.cache/dokimi/caches//`; `--cache-root` moves them all and -`--cache NAME=PATH` points one elsewhere. A `--cache-root` or `--cache NAME=PATH` that is a regular file or +`--cache NAME=DIR` points one elsewhere. A `--cache-root` or `--cache NAME=DIR` that is a regular file or below one (checked before a remote source is cloned), or a `--cache-root` that holds a regular file named after a cache, is refused before the image build with exit 2, naming the flag and the path; so is one that cannot be resolved (a symbolic link loop), and a `--cache-root` that is a regular file is refused also when every cache has its own `--cache` and when the diff --git a/dokimi/dokimi/cli_flags.py b/dokimi/dokimi/cli_flags.py index 0e0a688f21..4a2ddd2109 100644 --- a/dokimi/dokimi/cli_flags.py +++ b/dokimi/dokimi/cli_flags.py @@ -258,7 +258,8 @@ class Concept: Concept( name="timeout", help="time limits, per phase", - # F1b adds the phase prefix (#94 §2.4). Current repo leaves parse whole seconds. + # F1b adds the phase prefix (#94 §2.4): the phases are the network's (build, solve, verify). + # A bare SEC is the agent run (solve). The value is seconds with an optional phase prefix. canonical=(Flag("--timeout", "[PHASE=]SEC", "int"),), banned=("--grade-timeout", "--build-timeout"), ), @@ -422,12 +423,14 @@ class FlagMove: """An old spelling that moved: argv that uses it is tombstoned (exit 2, prints the new argv). ``leaves`` limits the move to those leaves (their argv paths), for a spelling that keeps - another meaning on other leaves. The empty tuple means every leaf. + another meaning on other leaves. The empty tuple means every leaf. ``prefix`` is put in front + of the old value: ``--build-timeout 5`` is ``--timeout build=5``. """ old: str new: str leaves: tuple[tuple[str, ...], ...] = () + prefix: str = "" FLAG_MOVES: tuple[FlagMove, ...] = ( @@ -487,6 +490,9 @@ class FlagMove: FlagMove("--estimate-only", "--dry-run", leaves=( ("catalog", "routing"), ("skill", "routing"), ("skill", "novelty", "analyze"), )), + # Timeout concept (F1b): the phase is a prefix of the value. A bare SEC on `repo run` stays the agent run. + FlagMove("--build-timeout", "--timeout", leaves=(("repo", "run"), ("eval", "check")), prefix="build="), + FlagMove("--grade-timeout", "--timeout", leaves=(("repo", "run"), ("eval", "check")), prefix="verify="), # Arm concept (F1b): a subject arm list is repeatable --arm; the old comma list is the same value. FlagMove("--arms", "--arm", leaves=(("arms", "run"), ("arms", "matrix-run"), ("explore", "run"))), # Harness concept (F1b): the list of harnesses a tasks run uses, repeatable or comma-separated. diff --git a/dokimi/dokimi/cli_routes.py b/dokimi/dokimi/cli_routes.py index c5b22c3008..bd630cbcc4 100644 --- a/dokimi/dokimi/cli_routes.py +++ b/dokimi/dokimi/cli_routes.py @@ -21,7 +21,7 @@ from collections.abc import Callable, Sequence from dataclasses import dataclass, field -from dokimi.cli_flags import FLAG_MOVES +from dokimi.cli_flags import FLAG_MOVES, FlagMove SECTIONS: tuple[str, ...] = ("The loop", "Subjects", "Evals", "Analysis and data") @@ -549,6 +549,21 @@ def moved_argv( return None +def _rewrite_moved_token(rewritten: list[str], index: int, move: FlagMove, equals: str, value: str) -> None: + """Rewrite the token at ``index`` to ``move.new``; a ``prefix`` goes in front of the value (F1b).""" + if not move.prefix: + # a new spelling that carries its value (--fail-on=warn) takes no stray value from the old one + rewritten[index] = move.new if "=" in move.new else f"{move.new}{equals}{value}" + elif equals: + rewritten[index] = f"{move.new}={move.prefix}{value}" + else: # the value is the next token: --build-timeout 5 is --timeout build=5 + rewritten[index] = move.new + if index + 1 < len(rewritten) and not rewritten[index + 1].startswith("-"): + rewritten[index + 1] = move.prefix + rewritten[index + 1] + else: + rewritten.insert(index + 1, move.prefix) + + def moved_flags_argv(argv: Sequence[str]) -> list[str] | None: """``argv`` with each moved spelling rewritten to its new one, or None when none moved.""" canon = _canonical(tuple(argv)) @@ -562,8 +577,7 @@ def moved_flags_argv(argv: Sequence[str]) -> list[str] | None: name, equals, value = token.partition("=") for move in FLAG_MOVES: if name == move.old and (not move.leaves or leaf in move.leaves): - # a new spelling that carries its value (--fail-on=warn) takes no stray value from the old one - rewritten[index] = move.new if "=" in move.new else f"{move.new}{equals}{value}" + _rewrite_moved_token(rewritten, index, move, equals, value) changed = True break return rewritten if changed else None diff --git a/dokimi/dokimi/commands/repo_run.py b/dokimi/dokimi/commands/repo_run.py index 2d7b77369d..dd7ba924cf 100644 --- a/dokimi/dokimi/commands/repo_run.py +++ b/dokimi/dokimi/commands/repo_run.py @@ -204,15 +204,15 @@ def _pin_batch(batch_dir: Path, pin: dict[str, str]) -> None: def _pair(text: str) -> tuple[str, str]: name, sep, path = text.partition("=") if not sep or not name or not path: - raise ValueError(f"--cache takes NAME=PATH, got {text!r}") + raise ValueError(f"--cache takes NAME=DIR, got {text!r}") return name, path def _check_cache_flags(args: argparse.Namespace) -> None: - """Refuse a ``--cache-root`` or a ``--cache NAME=PATH`` path no cache directory can be made in (exit 2) (#826). + """Refuse a ``--cache-root`` or a ``--cache NAME=DIR`` path no cache directory can be made in (exit 2) (#826). They need no manifest, so they are checked before the source is opened (a remote one is cloned or fetched). - A ``--cache`` that is not ``NAME=PATH`` is left to ``_context``. + A ``--cache`` that is not ``NAME=DIR`` is left to ``_context``. """ from dokimi.commands.cache_dir import CACHE_USE, resolved_cache_dir @@ -588,7 +588,47 @@ def _usd(text: str) -> float: return value -def _common(p: argparse.ArgumentParser, source_help: str, cache_help: str, positive_int) -> None: +# The phase of a `--timeout [PHASE=]SEC` value and the argparse dest it sets (#94 F1b; the network's phases). +_TIMEOUT_DEST = {"solve": "timeout", "build": "build_timeout", "verify": "grade_timeout"} + + +class _PhaseSeconds(argparse.Action): + """Store the (phase, seconds) that `_phase_seconds` parsed in the dest of its phase.""" + + def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace, values: Any, + option_string: str | None = None) -> None: + phase, seconds = values + setattr(namespace, _TIMEOUT_DEST[phase], seconds) + namespace.timeout_set = True + + +def _timeout_flag(p: argparse.ArgumentParser, phases: tuple[str, ...], positive_int) -> None: + """``--timeout [PHASE=]SEC``: a bare SEC or ``solve=`` is the agent run, ``build=`` the image build and + ``verify=`` each grade or oracle run. A command takes only the phases it runs (`eval check` has no agent).""" + + def phase_seconds(text: str) -> tuple[str, int]: + phase, sep, value = text.rpartition("=") + if not sep and "solve" not in phases: + forms = " or ".join(f"{phase}=SEC" for phase in phases) + raise argparse.ArgumentTypeError(f"use {forms}; got {text!r}") + phase = phase if sep else "solve" + if phase not in phases: + raise argparse.ArgumentTypeError(f"{phase!r} is not a phase of this command " + f"(take {', '.join(phases)}); got {text!r}") + return phase, positive_int(value) + + texts = { + "solve": "a bare SEC is the agent run (solve, default 2700, unless task.json sets timeout_s)", + "build": "build=SEC the image build (default 10800, 3 hours)", + "verify": "verify=SEC each grade or oracle run (default 3600)", + } + cli_flags.add(p, "timeout", "--timeout", type=phase_seconds, action=_PhaseSeconds, default=2700 if "solve" in phases else None, + metavar="[PHASE=]SEC", help="Seconds per phase: " + "; ".join(texts[ph] for ph in phases)) + p.set_defaults(build_timeout=docker_cmd.BUILD_TIMEOUT_S, grade_timeout=3600) + + +def _common(p: argparse.ArgumentParser, source_help: str, cache_help: str, positive_int, + timeout_phases: tuple[str, ...]) -> None: p.add_argument("source", help=source_help) p.add_argument("--manifest", default=".agent-eval/repo-eval.yaml", help="Manifest path relative to the repository root") @@ -606,17 +646,14 @@ def _common(p: argparse.ArgumentParser, source_help: str, cache_help: str, posit help="Build the image even if the tag exists") p.add_argument("--build-network", default=None, dest="build_network", help="docker build --network (for example host, behind a local proxy)") - p.add_argument("--build-timeout", type=positive_int, default=docker_cmd.BUILD_TIMEOUT_S, dest="build_timeout", - help="Seconds the image build may run before it fails (default 10800, 3 hours)") - p.add_argument("--cache", action="append", default=None, metavar="NAME=PATH", + _timeout_flag(p, timeout_phases, positive_int) + p.add_argument("--cache", action="append", default=None, metavar="NAME=DIR", help="Host directory for the manifest cache NAME; repeatable") p.add_argument("--cache-root", default=None, dest="cache_root", help="Parent of cache directories without --cache " "(default: ~/.cache/dokimi/caches/)") p.add_argument("--source-dir", default=None, dest="source_dir", help="Full-history clone mounted as {source_dir} (default: the source's own git dir)") - p.add_argument("--grade-timeout", type=positive_int, default=3600, dest="grade_timeout", - help="Seconds per grade/oracle run (default 3600)") cli_flags.add(p, "concurrency", "--concurrency", "-j", type=positive_int, default=1, dest="jobs", metavar="N", help="Parallel tasks or cells (default 1)") p.add_argument("--docker", default="docker", help="docker CLI (default: docker)") @@ -640,7 +677,7 @@ def register(repo_sub, eval_sub, positive_int, source_help: str, cache_help: str "pass it (score-only: reach score.max), and the agent's container must not see tasks or source; " "--schema-only: the manifest and task.json checks of `repo validate`", description=CHECK_EXIT) - _common(check_p, source_help, cache_help, positive_int) + _common(check_p, source_help, cache_help, positive_int, timeout_phases=("build", "verify")) check_p.add_argument("--schema-only", action="store_true", dest="schema_only", help="Check the manifest and every task.json against one snapshot, with no self-check run " "(what `repo validate` did); --json and --fail-on apply to it") @@ -665,13 +702,15 @@ def register(repo_sub, eval_sub, positive_int, source_help: str, cache_help: str schema_refused = tuple((a.option_strings[0], a.dest, a.default) for a in check_p._actions if a.option_strings and a.dest not in schema_kept and not isinstance(a, argparse._HelpAction)) + # Refuse explicit `--timeout` values even when they equal the phase defaults. + schema_refused += (("--timeout", "timeout_set", False),) check_p.set_defaults(func=cmd_eval_check, emits_cli_output=True, cli_kind="eval check", schema_refused=schema_refused) run_p = repo_sub.add_parser( "run", help="Run an agent per (task, arm, model, rep) in the image and grade each run; one " "result.json per cell, already finished cells skipped", description=RUN_EXIT) - _common(run_p, source_help, cache_help, positive_int) + _common(run_p, source_help, cache_help, positive_int, timeout_phases=("solve", "build", "verify")) run_p.add_argument("--arm", action="append", default=None, required=True, help="guidance:none | guidance:raw | guidance:bridge | guidance:as-skill | " "guidance:overlay (the base with the AGENTS..md of the harness only) | " @@ -699,8 +738,6 @@ def register(repo_sub, eval_sub, positive_int, source_help: str, cache_help: str run_p.add_argument("--delegation", choices=DELEGATION_MODES, default="native", help="native: the agent may start subagents (default); none: the profile's tool " "arguments without the subagent tools, for a single-agent baseline") - run_p.add_argument("--timeout", type=positive_int, default=2700, - help="Seconds per agent run unless task.json sets timeout_s (default 2700)") run_p.add_argument("--max-turns", type=positive_int, default=200, dest="max_turns", help="Unless task.json sets max_turns (default 200)") run_p.add_argument("--probes", default=None, metavar="FILE", diff --git a/dokimi/dokimi/commands/tasks.py b/dokimi/dokimi/commands/tasks.py index 9349c52c19..4e43f3f3ce 100644 --- a/dokimi/dokimi/commands/tasks.py +++ b/dokimi/dokimi/commands/tasks.py @@ -397,10 +397,11 @@ def register(sub, positive_int, eval_sub) -> None: ), ) run_p.add_argument( - "--network", action="append", default=[], metavar="PHASE=MODE", + "--network", action="append", default=[], metavar="[PHASE=]MODE[:hosts]", help=( - "Network for a docker-* phase (build, solve, verify, or all): none, public, or " - "allowlist:host[:port],... Repeatable; overrides the task's own network_mode. " + "Network for a docker-* phase (build, solve, verify, or all). Bare none or public applies to " + "every phase. For an allowlist, specify solve or verify, e.g. solve,verify=allowlist:pypi.org. " + "Repeatable; overrides the task's own network_mode. " "Default build=public solve=none verify=none" ), ) diff --git a/dokimi/dokimi/harnesses/docker_solver.py b/dokimi/dokimi/harnesses/docker_solver.py index 46ae8331a9..2b8f27661a 100644 --- a/dokimi/dokimi/harnesses/docker_solver.py +++ b/dokimi/dokimi/harnesses/docker_solver.py @@ -126,7 +126,7 @@ class DockerSolverHarness: kind: str = "docker" env: dict[str, str] = field(default_factory=dict) agent_location: str = "container" - network: tuple[str, ...] = () # --network PHASE=MODE overrides (see :mod:`.network_policy`) + network: tuple[str, ...] = () # --network [PHASE=]MODE overrides (see :mod:`.network_policy`) runner: process.Runner = field(default=process.run, compare=False, repr=False) skill_notice: bool = True diff --git a/dokimi/dokimi/harnesses/network_policy.py b/dokimi/dokimi/harnesses/network_policy.py index 37b4ab19b0..1a8b9a7155 100644 --- a/dokimi/dokimi/harnesses/network_policy.py +++ b/dokimi/dokimi/harnesses/network_policy.py @@ -29,7 +29,9 @@ ``public`` is not extended to an agent: Harbor defaults to public and catalogs copy it, so honouring it would hand every agent the internet. An agent gets the internet only from an explicit ``[agent]`` policy or the operator. -3. The operator: ``dokimi tasks run --network PHASE=MODE[:host,...]``. +3. The operator: ``dokimi tasks run --network [PHASE=]MODE[:host,...]``. + Bare ``none`` and ``public`` apply to every phase, including ``build``. + Use ``solve`` or ``verify`` (or both) for ``allowlist``. The effective plan, with each phase's source, is recorded in every run's ``metrics.network``, so two runs can be checked for the same network before @@ -100,10 +102,12 @@ def policy(mode: Any, hosts: Iterable[Any] = (), source: str = "default") -> Pha def parse_override(spec: str) -> dict[str, PhasePolicy]: - """``PHASE[,PHASE]=MODE[:host,...]`` (``all`` for every phase) -> one policy per phase.""" + """``[PHASE[,PHASE]=]MODE[:host,...]``: no PHASE, or ``all``, is every phase -> one policy per phase.""" phases_raw, sep, value = spec.partition("=") - if not sep or not value: - raise ValueError(f"--network {spec!r}: expected PHASE=MODE, e.g. verify=none or " + if not sep: # a bare MODE[:hosts] is every phase (the --network registry spelling, #94 §2.4) + phases_raw, value = "all", spec + if not value or (not sep and value.strip().lower() in (*PHASES, *_PHASE_ALIASES)): + raise ValueError(f"--network {spec!r}: expected [PHASE=]MODE, e.g. verify=none or " "solve=allowlist:pypi.org,files.pythonhosted.org") mode, _, hosts = value.partition(":") phases = [p.strip() for raw in phases_raw.split(",") @@ -114,10 +118,10 @@ def parse_override(spec: str) -> dict[str, PhasePolicy]: f"expected {', '.join(PHASES)} or all") pol = policy(mode, [h for h in hosts.split(",") if h.strip()], "cli") if pol.mode == "allowlist" and not pol.hosts: - raise ValueError(f"--network {spec!r}: allowlist needs hosts, e.g. allowlist:pypi.org") + raise ValueError(f"--network {spec!r}: allowlist needs hosts, e.g. solve=allowlist:pypi.org") if pol.mode == "allowlist" and "build" in phases: raise ValueError(f"--network {spec!r}: the image build takes none or public (docker build " - "cannot route through the egress sidecar)") + f"cannot route through the egress sidecar). Use --network solve,verify={value}") return {p: pol for p in phases} diff --git a/dokimi/dokimi/harnesses/runner.py b/dokimi/dokimi/harnesses/runner.py index 546571b202..9b84944245 100644 --- a/dokimi/dokimi/harnesses/runner.py +++ b/dokimi/dokimi/harnesses/runner.py @@ -43,7 +43,7 @@ class TaskSuiteRunner: command_template: str | None = None dry_run: bool = False repeats: int = 1 - network: tuple[str, ...] = () # --network PHASE=MODE overrides, docker-* harnesses only + network: tuple[str, ...] = () # --network [PHASE=]MODE overrides, docker-* harnesses only # Starts the processes of every harness except the `docker-*` ones (docker_solver spawns its own). runner: process.Runner = field(default=process.run, repr=False) diff --git a/dokimi/dokimi/repos/container.py b/dokimi/dokimi/repos/container.py index d3f1f1711e..6359cb3736 100644 --- a/dokimi/dokimi/repos/container.py +++ b/dokimi/dokimi/repos/container.py @@ -282,7 +282,7 @@ def build(self, context: Path, dockerfile: Path, tag: str, network: str | None = except OSError as exc: raise DockerError(f"docker build {tag}: cannot run {self.docker!r}: {exc}") from exc if proc.timed_out: - raise ContainerError(f"docker build {tag} timed out after {timeout_s:g}s (--build-timeout):\n" + raise ContainerError(f"docker build {tag} timed out after {timeout_s:g}s (--timeout build=SEC):\n" f"{(proc.stderr or proc.stdout)[-3000:]}") if proc.returncode: kind = DockerError if _daemon_unreachable(proc.stderr) else ContainerError diff --git a/dokimi/tests/data/cli_flags_allowlist.txt b/dokimi/tests/data/cli_flags_allowlist.txt index 51f688eaea..61284a1955 100644 --- a/dokimi/tests/data/cli_flags_allowlist.txt +++ b/dokimi/tests/data/cli_flags_allowlist.txt @@ -12,7 +12,7 @@ # that a new row has a reason. # # Rows with no reason are the spellings already on main when this file was written (b69b15f8). ---agent-network +--agent-network # repo run: the agent container's docker network (host or bridge), not the policy modes of --network; no registry concept yet --all --all-atoms --allow-self-judge @@ -25,9 +25,8 @@ --baseline-harness --bases --both ---build-network ---build-timeout ---cache-root +--build-network # repo run: docker build --network NAME for the image build, a docker network name, not the policy modes of --network +--cache-root # repo run: the parent directory of the per-name manifest caches, resolved at run time; not --cache NAME=DIR --calls --candidate --candidates # repo run's candidate file (repos/choices.py): no registry concept yet; a F1b migration names it @@ -62,7 +61,6 @@ --from-eval --github-token --golden-runs ---grade-timeout --grader --grounded --grounded-from-topics diff --git a/dokimi/tests/test_cli_f1b_net.py b/dokimi/tests/test_cli_f1b_net.py new file mode 100644 index 0000000000..d4979769f6 --- /dev/null +++ b/dokimi/tests/test_cli_f1b_net.py @@ -0,0 +1,109 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +"""The network, timeout and cache concepts' moves (issue #94 §2.4, F1b): old spellings tombstone, new ones parse the same.""" + +from __future__ import annotations + +import pytest + +from dokimi import cli, cli_routes +from dokimi.cli import build_parser +from dokimi.commands.repo_run import _pair +from dokimi.harnesses import network_policy + + +def _tombstone(argv: list[str], capsys) -> str: + """The text of the tombstone that ``argv`` prints; it must exit 2 without running anything.""" + with pytest.raises(SystemExit) as exc: + cli.parse_args(argv) + assert exc.value.code == 2 + return capsys.readouterr().err + + +@pytest.mark.parametrize(("old", "new"), [ + # timeout: the phase is a prefix of the value + (["repo", "run", "src", "--build-timeout", "5"], ["repo", "run", "src", "--timeout", "build=5"]), + (["repo", "run", "src", "--grade-timeout=600"], ["repo", "run", "src", "--timeout=verify=600"]), + (["eval", "check", "src", "--build-timeout", "36000"], ["eval", "check", "src", "--timeout", "build=36000"]), + (["eval", "check", "src", "--grade-timeout", "600"], ["eval", "check", "src", "--timeout", "verify=600"]), +]) +def test_an_old_timeout_spelling_tombstones_with_the_new_argv(old, new, capsys): + text = _tombstone(old, capsys) + assert text.startswith("moved: dokimi ") + assert " ".join(new) in text + + +@pytest.mark.parametrize("argv", [ + ["repo", "run", "src", "--timeout", "900"], # a bare SEC is the agent run's + ["repo", "run", "src", "--timeout", "build=5", "--timeout", "verify=60"], + ["eval", "check", "src", "--timeout", "build=5"], + ["tasks", "run", "--all", "--harness", "h", "--network", "none"], +]) +def test_a_canonical_timeout_or_network_spelling_is_not_moved(argv): + assert cli_routes.moved_flags_argv(argv) is None + + +REPO_RUN = ["repo", "run", "src", "--arm", "guidance:none", "--model", "m", "--name", "b"] + + +@pytest.mark.parametrize(("argv", "dest", "value"), [ + ([*REPO_RUN, "--timeout", "900"], "timeout", 900), + ([*REPO_RUN, "--timeout", "build=5"], "build_timeout", 5), + ([*REPO_RUN, "--timeout", "verify=60"], "grade_timeout", 60), + (["eval", "check", "src", "--timeout", "build=36000"], "build_timeout", 36000), + (["eval", "check", "src", "--timeout", "verify=600"], "grade_timeout", 600), +]) +def test_a_timeout_phase_sets_the_dest_the_phase_always_set(argv, dest, value): + assert getattr(build_parser().parse_args(argv), dest) == value + + +def test_a_bare_seconds_value_is_refused_on_eval_check(capsys): + """eval check has no solve phase: a bare SEC (the agent run) is refused, not read as some other phase.""" + with pytest.raises(SystemExit) as exc: + build_parser().parse_args(["eval", "check", "src", "--timeout", "900"]) + assert exc.value.code == 2 + assert "use build=SEC or verify=SEC" in capsys.readouterr().err + + +def test_an_unknown_timeout_phase_is_refused(capsys): + with pytest.raises(SystemExit) as exc: + build_parser().parse_args([*REPO_RUN, "--timeout", "bogus=5"]) + assert exc.value.code == 2 + assert "'bogus' is not a phase of this command" in capsys.readouterr().err + + +def test_a_moved_timeout_value_after_a_flag_is_still_prefixed(): + """The value is the next token even when the token before the old flag is a flag.""" + argv = ["eval", "check", "--schema-only", "--build-timeout", "5", "src"] + assert cli_routes.moved_flags_argv(argv) == ["eval", "check", "--schema-only", "--timeout", "build=5", "src"] + + +def test_the_timeout_defaults_are_the_documented_seconds(): + args = build_parser().parse_args(REPO_RUN) + assert (args.timeout, args.build_timeout, args.grade_timeout) == (2700, 10800, 3600) + check = build_parser().parse_args(["eval", "check", "src"]) + assert (check.timeout, check.build_timeout, check.grade_timeout) == (None, 10800, 3600) + + +def test_a_moved_timeout_flag_with_no_value_does_not_index_past_the_end(): + """The value-aware rewrite reads the next token only when there is one.""" + assert cli_routes.moved_flags_argv(["eval", "check", "src", "--build-timeout"]) == ["eval", "check", "src", "--timeout", "build="] + + +def test_a_moved_timeout_flag_without_a_value_leaves_the_next_flag_intact(): + argv = ["repo", "run", "src", "--build-timeout", "--arm", "guidance:none"] + assert cli_routes.moved_flags_argv(argv) == ["repo", "run", "src", "--timeout", "build=", "--arm", "guidance:none"] + + +def test_a_cache_override_refusal_matches_the_cli_metavar(): + with pytest.raises(ValueError, match="--cache takes NAME=DIR"): + _pair("cache") + + +def test_a_bare_network_mode_means_every_phase(): + """`tasks run --network none` (no PHASE=) sets every phase, as the registry's spelling promises.""" + args = build_parser().parse_args(["tasks", "run", "--all", "--harness", "h", "--network", "none"]) + overrides = network_policy.parse_override(args.network[0]) + assert set(overrides) == set(network_policy.PHASES) + assert {p.mode for p in overrides.values()} == {"none"} diff --git a/dokimi/tests/test_cli_flags.py b/dokimi/tests/test_cli_flags.py index cee08497f5..4c4e32570d 100644 --- a/dokimi/tests/test_cli_flags.py +++ b/dokimi/tests/test_cli_flags.py @@ -153,7 +153,7 @@ def _tree_violations() -> list[str]: # Types a parser may use for each registry kind. A kind not listed takes any type. _TYPES_BY_KIND: Mapping[str, frozenset[str]] = { - "int": frozenset({"int", "non_negative_int", "positive_int"}), + "int": frozenset({"int", "non_negative_int", "phase_seconds", "positive_int"}), "float": frozenset({"float", "positive_fraction", "unit_interval"}), "usd": frozenset({"positive_usd", "_usd"}), } @@ -210,13 +210,6 @@ def _tree_violations() -> list[str]: ("dokimi explore run", "--arm", "metavar"): ("ARM", "an explore arm is oracle, empty or command: