Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dokimi/changelog.d/20261125_150000_dotdot-link-readers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- **Reach, uptake, skill usage, the `edit-outside-workspace` scan and `first_useful` follow a `..` after a link in a traced path, as `guidance_read` does (#1173)** — five readers of a `read` or `edit` event path took the `..` by name, so a path through a link matched the wrong file: `cat alias/../AGENTS.md` with `alias -> docs/nested` counted as a read of `AGENTS.md` in `repo reach`'s `read_by_tool` and in the `reads` of `uptake`, though the system opens `docs/AGENTS.md`; the same read of `.claude/skills/x/alias/../SKILL.md` credited a skill in `skills_used`; an edit of `sub/alias/../x` with `sub/alias -> /outside/nested` was no `edit-outside-workspace` finding though it writes `/outside/x`, and an edit of `sub/alias/../x` hit a `first_useful` glob `sub/x`. `repo run` and `repo reach` now give them the links the workspace had as the agent started, and `repo scan` the links of a cell's kept `workspace/`: only a path with a `..` is followed, the directories before its last name as the system resolves them and the last name as written. A reader with no links (a cell with no `workspace/`, a caller that passes none) takes the `..` by name as before, and `repo scan` reports an edit as outside the workspace when either reading of its path leaves it. A link the agent made to `/eval/run/workspace/...`, the workspace as the container names it, leads into the workspace in all of them (and in `guidance_read`), so `alias/../x` with `alias -> /eval/run/workspace/docs/nested` is the in-workspace `docs/x`, not an `edit-outside-workspace` finding.
1 change: 1 addition & 0 deletions dokimi/docs/behavioural-security.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Per finished cell directory (`{task}__{arm}__{model}__r{rep}` with a `result.jso
| `exec.log` | `strace -f -s 4096 -e trace=execve` of the agent, when the image records one: commands a script the agent wrote ran, which the trace does not show |
| `egress.jsonl` | an egress sidecar's allow/deny decisions. `repo run` starts none yet (per-host egress is not implemented there), so `egress-denied` and an egress canary leak are unmeasured in its cells |
| `answer.txt` | the final answer (a canary there is a leak) |
| `workspace/` | the links of the agent's final tree, when the cell kept it: an edit path with a `..` after a link (`sub/link/../x`) is followed as the system does, and is `edit-outside-workspace` when that, or the path read by name, leaves the workspace. Without a `workspace/` directory the path is read by name alone |

strace cuts a string longer than its `-s` limit (32 by default, so pass `-s`): the rules do
not judge a cut argument, only canaries are matched in its kept text, and `coverage.exec_cut`
Expand Down
10 changes: 6 additions & 4 deletions dokimi/docs/repo-evaluation-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ hits the task's `useful` key (§3). The definition depends on the grader:
| Grader | Declare | Hit |
|---|---|---|
| test: the grade runs the target tests | `{"command": "<regex>"}` | the first `command` event whose text matches the regex (`regex.search`) and whose `rc` is `0`. `rc` 0 says that command passed, not that every target test did, so the regex should name the target tests |
| edit or diff: the grade reads a target file | `{"edit": "<glob>"}` or a list | the first `edit` event whose path matches a glob (`match_glob`, as the guidance globs) |
| edit or diff: the grade reads a target file | `{"edit": "<glob>"}` or a list | the first `edit` event whose path matches a glob (`match_glob`, as the guidance globs; a `..` after a link in the path is followed as in `guidance_read`, so `sub/alias/../x` with `sub/alias -> ../docs/nested` is `docs/x`) |
| review (`dokimi:review_*`) | none | none, so `not_declared`: the answer is the product, so no event is the useful result. A declared key is measured all the same |
| any other repository grader | either form, or none | none declared, `not_declared` |

Expand Down Expand Up @@ -701,7 +701,7 @@ row shows which.
A cell of an arm that installs skills also has a `skills` object in
`result.json`: `measured`, `skills_installed` (the installed skill names),
`skills_used` (the installed skills the agent called with the `Skill` tool or
whose `SKILL.md` it read, the call or read neither denied nor failed, in order of first use), `expected_skill` (the task's,
whose `SKILL.md` it read, the call or read neither denied nor failed, a `..` after a link in the read path followed as in `guidance_read`, in order of first use), `expected_skill` (the task's,
or `null`), `skill_invoked` (the expected skill was used; any installed skill
when the task names none) and `skill_selected_correct` (the expected skill was
the first one used; `null` when the task names none). When the trace could not
Expand All @@ -719,7 +719,7 @@ command events that name an added file as a workspace path (`tools/fmt`,
`./tools/fmt`, `/eval/run/workspace/tools/fmt`, not `cd tools && ./fmt`; a file
with no `/` only as `./name`, under the workspace path or after an interpreter (a bare `name` resolves through `PATH`), so
`npm run lint` does not name a `lint` file), `reads` the read events of one that did not fail (a
read of an added script counts as use), `mcp_calls` the calls of the servers' tools
read of an added script counts as use; a `..` after a link in the path is followed as in `guidance_read`, so `alias/../tools/fmt` with `alias -> docs/nested` reads `docs/tools/fmt`), `mcp_calls` the calls of the servers' tools
(`mcp__<server>__<tool>`), none of them a call the harness denied; `used`
is whether any is non-zero, and `measured` is
`false` when the agent left no trace to count from. `repo report` shows the
Expand Down Expand Up @@ -1775,7 +1775,9 @@ per scenario).
- `loaded`: both tokens reported;
- `truncated`: one token reported;
- `fetched`: reported only after the agent read the file with a tool (a
read that was denied or failed is none). For the
read that was denied or failed is none; a `..` after a link in the read
path is followed as in `guidance_read`, by the links of the probe
workspace, a `CLAUDE.md` link among them). For the
Claude Code (its Bash tool), Codex and Copilot profiles a shell read counts
only as a bare `cat`, `head`, `tail`, `nl` or `sed -n`, after the `time`
keyword too (`time -p cat AGENTS.md`, `time -- cat AGENTS.md`; the
Expand Down
11 changes: 6 additions & 5 deletions dokimi/dokimi/repos/arms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

import hashlib
import os
import posixpath
import re
from collections.abc import Mapping
from collections.abc import Callable, Mapping
from dataclasses import dataclass
from pathlib import Path, PurePosixPath
from typing import Any
Expand All @@ -31,6 +30,7 @@

from dokimi.skills.formats import SPEC_NAME_MAX
from dokimi.digest_entries import listed_entries
from dokimi.repos.event_format import followed_path

from dokimi import process

Expand Down Expand Up @@ -314,9 +314,10 @@ def skill_unmeasured(installed: list[str], expected: str | None) -> dict[str, An
"skill_invoked": None, "skill_selected_correct": None}


def skill_usage(events: list[dict[str, Any]], installed: list[str], expected: str | None) -> dict[str, Any]:
def skill_usage(events: list[dict[str, Any]], installed: list[str], expected: str | None,
resolve: Callable[[str], str | None] | None = None) -> dict[str, Any]:
"""Which installed skills the agent used: a ``Skill`` tool call naming it, or a read of its ``SKILL.md``; neither
refused nor failed.
refused nor failed. ``resolve`` follows the workspace's links for a read path with a ``..`` in it.

``skill_invoked``: the expected skill was used (any installed one when the task names none);
``skill_selected_correct``: the expected skill was the first one used, ``None`` without one.
Expand All @@ -329,7 +330,7 @@ def skill_usage(events: list[dict[str, Any]], installed: list[str], expected: st
if e.get("kind") == "tool" and e.get("name") == "Skill":
name = str(e.get("skill") or "").split(":")[-1] # a plugin skill is plugin:name
elif e.get("kind") == "read":
parts = PurePosixPath(posixpath.normpath(str(e.get("path") or ""))).parts
parts = PurePosixPath(followed_path(str(e.get("path") or ""), resolve)).parts
if len(parts) == 4 and "/".join(parts[:2]) == SKILLS_DIR and parts[3] == "SKILL.md":
name = parts[2]
if name in installed and name not in used:
Expand Down
16 changes: 16 additions & 0 deletions dokimi/dokimi/repos/event_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from __future__ import annotations

import posixpath
from collections.abc import Callable
from typing import Any, Mapping

EVENT_VERSION = 2 # the major version this code writes; a version change adds repo_event.vN.json
Expand All @@ -30,6 +32,20 @@ def plain_path(path: str) -> str:
return lead + "/".join(p for p in path.split("/") if p not in ("", ".")) or "."


def followed_path(path: str, resolve: Callable[[str], str | None] | None = None) -> str:
"""``path`` normalized; a relative one with a ``..`` has the directories before its last name followed by ``resolve``
(the workspace's links, :meth:`~dokimi.repos.held_guidance.HeldGuidance.resolved`) and keeps that name as written.
A result that starts with ``..`` leaves the workspace, and so does one that ``resolve`` cannot follow (None). With no
``resolve``, or for a path with no ``..`` or an absolute one, the result is :func:`posixpath.normpath`'s."""
plain = plain_path(path)
if not resolve or plain.startswith("/") or ".." not in plain.split("/"):
return posixpath.normpath(path)
head, _, name = plain.rpartition("/")
if name == "..":
return resolve(plain) or ".."
return plain_path(f"{resolve(head) or '..'}/{name}")


def event_version(event: Mapping[str, Any]) -> int:
"""The format version of one event; an event with no ``v`` is the unversioned format, read as 1."""
v = event.get("v")
Expand Down
6 changes: 5 additions & 1 deletion dokimi/dokimi/repos/held_guidance.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from collections.abc import Iterable
from pathlib import Path

from .container import WORKSPACE
from .manifest import RepoManifest, match_glob
from .overlay_paths import _link_target, _supplies_a_file
from .workspace import SNAPSHOT_AUTHOR, _git_env, _workspace_files
Expand All @@ -27,7 +28,8 @@ class HeldGuidance:
"""The guidance files a workspace held as the agent started, as the files they resolve to. ``path in held`` is
true for a path that leads to one of them through the links the workspace had at the start: a link into the
workspace (``alias/AGENTS.md`` through a directory link, ``sub/AGENTS.md`` to ``../AGENTS.md``) counts, also
after the agent removed or retargeted the link; a file or a link the agent made does not."""
after the agent removed or retargeted the link; a file or a link the agent made does not. An absolute link target
under ``/eval/run/workspace`` (the workspace as the container names it) leads into the workspace."""

def __init__(self, ws: Path, files: Iterable[str]) -> None:
self.root = os.path.realpath(ws)
Expand Down Expand Up @@ -73,6 +75,8 @@ def resolved(self, path: str) -> str | None:
if hops == 40:
return None
hops, target = hops + 1, self.links[key]
if target == WORKSPACE or target.startswith(WORKSPACE + "/"): # the agent's name for this workspace
target = self.root + target[len(WORKSPACE):]
if os.path.isabs(target) or target[:1] in (os.sep, os.altsep): # ``\x`` is rooted on the drive of the link
here, names = _anchored(target, here)
else:
Expand Down
14 changes: 3 additions & 11 deletions dokimi/dokimi/repos/process_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@

from __future__ import annotations

import posixpath
import re
from collections.abc import Callable, Iterable, Mapping
from dataclasses import dataclass
from pathlib import PurePosixPath
from typing import Any

from dokimi.repos.event_format import TOOL_KINDS, plain_path
from dokimi.repos.event_format import TOOL_KINDS, followed_path, plain_path

COUNTER_FIELDS = ("text", "output", "any")

Expand Down Expand Up @@ -84,16 +83,9 @@ def _workspace_path(path: str, resolve: Callable[[str], str | None] | None = Non
is collapsed by name, as when the workspace is not known. A path that climbs out of the workspace is None either way."""
if path.startswith("~"):
return None
p = PurePosixPath(plain_path(path))
if p.is_absolute():
if PurePosixPath(plain_path(path)).is_absolute():
return None
if ".." in p.parts:
if not resolve:
p = PurePosixPath(posixpath.normpath(p))
elif p.name != "..":
p = PurePosixPath(resolve(str(p.parent)) or "..") / p.name
else:
p = PurePosixPath(resolve(str(p)) or "..")
p = PurePosixPath(followed_path(path, resolve))
return None if ".." in p.parts else str(p)


Expand Down
18 changes: 11 additions & 7 deletions dokimi/dokimi/repos/reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import shlex
import shutil
import tempfile
from collections.abc import Iterator
from collections.abc import Callable, Iterator
from contextlib import contextmanager
from dataclasses import dataclass
from datetime import datetime, timezone
Expand All @@ -61,6 +61,7 @@
from .events import convert
from .transcript import Transcript
from .harness_profile import HarnessProfile
from .held_guidance import HeldGuidance
from .manifest import RepoManifest, check_repo
from .overlays import overlay_of
from .reach_overlays import native_in_probe, overlay_report
Expand Down Expand Up @@ -408,12 +409,14 @@ def prose_words(answer: str) -> int:
return len(_prose(answer))


def classify(seeded: SeededFile, transcript: Transcript | None) -> dict[str, Any]:
def classify(seeded: SeededFile, transcript: Transcript | None,
resolve: Callable[[str], str | None] | None = None) -> dict[str, Any]:
"""The head, the tail and the class of one seeded file; ``resolve`` follows the workspace's links in a read path."""
if transcript is None:
return {"head": False, "tail": False, "read_by_tool": False, "class": "error"}
reported = set(TOKEN_RE.findall(transcript.answer))
head, tail = seeded.head in reported, seeded.tail in reported
reads = transcript.reads()
reads = transcript.reads(resolve)
read_by_tool = any(p in reads for p in (seeded.path, *seeded.aliases))
if not (head or tail):
cls = "not_loaded"
Expand Down Expand Up @@ -487,7 +490,7 @@ def _write_shadow(workspace: Path, item: SeededFile, dirs: list[Path], written:


def _score_row(row: dict[str, Any], transcript: Transcript | None, known: set[str],
shadow: SeededFile | None) -> None:
shadow: SeededFile | None, resolve: Callable[[str], str | None] | None = None) -> None:
"""The row's reported, unknown and prose from the answer, and the result of its shadow file, which is kept on
the row: it is not a tree file, so it gets no records and no matrix row."""
if transcript is not None:
Expand All @@ -496,7 +499,7 @@ def _score_row(row: dict[str, Any], transcript: Transcript | None, known: set[st
row.update(reported=reported, unknown=[t for t in reported if t not in known | own],
prose=prose_words(transcript.answer))
if shadow is not None:
row["shadow"] = {"path": shadow.path, "tokens": [shadow.head, shadow.tail], **classify(shadow, transcript)}
row["shadow"] = {"path": shadow.path, "tokens": [shadow.head, shadow.tail], **classify(shadow, transcript, resolve)}


def run_reach(
Expand Down Expand Up @@ -544,6 +547,7 @@ def run_reach(
if re.match(r"^\d{2,}-.*\.(stdout|events\.jsonl)$", old.name) and old.is_file():
old.unlink()
known = {s.head for s in seeded} | {s.tail for s in seeded}
resolve = HeldGuidance(workspace, []).resolved # the aliases are links the workspace has now
scenario_rows, records = [], []
for n, scenario in enumerate(plan):
shadow = _shadow_seed(scenario, salt)
Expand All @@ -555,11 +559,11 @@ def run_reach(
if transcript is not None:
(trace_dir / f"{slug}.events.jsonl").write_text(transcript.events_jsonl(), encoding="utf-8")
version = transcript.harness_version or version
_score_row(row, transcript, known, shadow)
_score_row(row, transcript, known, shadow, resolve)
scenario_rows.append(row)
for item in seeded:
records.append({"file": item.path, "scenario": scenario.id, "harness": profile.name,
"harness_version": version, "model": model, **classify(item, transcript)})
"harness_version": version, "model": model, **classify(item, transcript, resolve)})
finally:
if dry_run or not keep: # a dry run names no workspace, so it keeps none
shutil.rmtree(base, onerror=retry_writable)
Expand Down
Loading
Loading