Skip to content

Replay your coding agent sessions as a map and a timeline

fix: private store ignores symlink modes; search sums distinct paths; cron escapes %

aiswaryasankartestc07fbed31ed8
diff --git a/python/src/agentplay/cli.py b/python/src/agentplay/cli.py
index 7892618..751a147 100644
--- a/python/src/agentplay/cli.py
+++ b/python/src/agentplay/cli.py
@@ -436,7 +436,9 @@ def cmd_autotune(args: argparse.Namespace) -> int:
# cron's PATH rarely holds pipx, uv or venv bin dirs, so name the command by absolute path.
found = shutil.which("agentplay")
exe = shlex.quote(os.path.abspath(found)) if found else f"{shlex.quote(sys.executable)} -m agentplay"
- print(f" {int(mm)} {int(hh)} * * * {autotune.HOOK_COMMAND.replace('agentplay', exe, 1)}")
+ # cron ends the command at an unescaped %, before the shell sees it.
+ cmd = autotune.HOOK_COMMAND.replace("agentplay", exe, 1).replace("%", "\\%")
+ print(f" {int(mm)} {int(hh)} * * * {cmd}")
else:
path = autotune.install_hook()
cfg["when"] = "session-start"
diff --git a/python/src/agentplay/search.py b/python/src/agentplay/search.py
index 4571fc4..cf1d4fa 100644
--- a/python/src/agentplay/search.py
+++ b/python/src/agentplay/search.py
@@ -185,14 +185,22 @@ def query(terms_by_session: dict[str, dict[str, list[list[Any]]]], q: str) -> di
if not hits:
continue
groups: dict[tuple[str, str], list[int | None]] = {}
- totals: dict[tuple[str, str], int] = {}
+ # Per group: totals by full-path term (distinct files add up), and the
+ # basename alias's total, used only when no full-path term matched.
+ full: dict[tuple[str, str], dict[str, int]] = {}
+ alias: dict[tuple[str, str], int] = {}
for t, (seq, touch, *total) in hits:
# The basename and the full-path term of one file are the same match.
key = (_label(t), touch)
if seq not in groups.setdefault(key, []):
groups[key].append(seq)
if total:
- totals[key] = max(totals.get(key, 0), total[0])
+ if t.startswith("file:") and t.count(":") >= 2:
+ by_term = full.setdefault(key, {})
+ by_term[t] = max(by_term.get(t, 0), total[0])
+ else:
+ alias[key] = max(alias.get(key, 0), total[0])
+ totals = {k: sum(full[k].values()) if full.get(k) else alias.get(k, 0) for k in groups}
# Stored postings are capped per touch kind, so cap per kind here too or a
# busy file's reads would crowd its edits out of the stepper.
by_touch: dict[str, set[int]] = {}
diff --git a/python/src/agentplay/store.py b/python/src/agentplay/store.py
index 6fec434..de501ba 100644
--- a/python/src/agentplay/store.py
+++ b/python/src/agentplay/store.py
@@ -42,7 +42,10 @@ def _atomic_write(path: Path, data: bytes, *, private: bool = True) -> None:
path = Path(os.path.realpath(path))
path.parent.mkdir(parents=True, exist_ok=True)
try:
- mode: int | None = stat.S_IMODE(path.stat().st_mode)
+ # lstat for the store: a link planted there must not lend its target's mode
+ # (a 0644 target would make the replacement readable by other users).
+ st = os.lstat(path) if private else path.stat()
+ mode: int | None = stat.S_IMODE(st.st_mode) if stat.S_ISREG(st.st_mode) else None
except FileNotFoundError:
mode = None
tmp = path.parent / f"{path.name}{uuid.uuid4().hex[:8]}.tmp"
diff --git a/python/tests/test_autotune_lifecycle.py b/python/tests/test_autotune_lifecycle.py
index d7d3798..69735e7 100644
--- a/python/tests/test_autotune_lifecycle.py
+++ b/python/tests/test_autotune_lifecycle.py
@@ -76,14 +76,16 @@ def test_an_unreadable_config_is_reported_and_never_overwritten(tuned):
assert exc.value.code == "bad_json" and path.read_text() == "{not json"
-def test_a_revoked_or_broken_repo_does_not_abort_the_run(tuned):
+def test_a_revoked_or_broken_repo_does_not_abort_the_run(tuned, monkeypatch):
st, root, found, due = tuned
found.append(_fix("md0001", MD))
autotune.run(st, force=True)
due.append(True)
fixes.revoke(st.base, "acme/api")
+ # A clock of its own, so the assertion proves this run moved the daily marker.
+ monkeypatch.setattr(autotune, "_now", lambda: "2099-01-01T00:00:00Z")
res = autotune.run(st, force=True, today="2099-01-01")
- assert res["retired"] == [] and autotune.config(st.base)["lastRun"]
+ assert res["retired"] == [] and autotune.config(st.base)["lastRun"] == "2099-01-01T00:00:00Z"
assert not [x for x in autotune.config(st.base)["log"] if x["kind"] == "error"]
# Granted again but the checkout lost .git: logged once, not on every daily run.
fixes.grant(st.base, "acme/api")
@@ -194,3 +196,17 @@ def test_approving_a_change_after_its_repo_is_revoked_writes_nothing(tuned):
with pytest.raises(fixes.FixError) as exc:
autotune.approve(st, "hook01")
assert exc.value.code == "not_granted" and not (root / ".claude" / "settings.json").exists()
+
+
+def test_cron_line_escapes_percent_signs(tmp_path, monkeypatch, capsys):
+ monkeypatch.setattr(cli, "Store", lambda: Store(tmp_path))
+ monkeypatch.setattr(fixes, "status", lambda _b: {"repos": []})
+ monkeypatch.setattr(autotune, "uninstall_hook", lambda: None)
+ monkeypatch.setattr(shutil, "which", lambda _n: "/opt/100%/agentplay")
+
+ class A:
+ action, at, repo = "on", "09:30", []
+
+ assert cli.cmd_autotune(A()) == 0
+ line = capsys.readouterr().out.splitlines()[-1]
+ assert "100\\%" in line and "100%/" not in line
diff --git a/python/tests/test_search_health_fixes.py b/python/tests/test_search_health_fixes.py
index a483339..0690388 100644
--- a/python/tests/test_search_health_fixes.py
+++ b/python/tests/test_search_health_fixes.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import http.client
import json
+import os
import subprocess
import threading
from pathlib import Path
@@ -421,3 +422,28 @@ def test_bad_cron_time_leaves_the_hook_alone(monkeypatch, capsys):
action, at, repo = "on", "9am", []
assert cli.cmd_autotune(A()) == 1 and not called
+
+
[email protected](not hasattr(os, "symlink") or os.name == "nt", reason="POSIX permissions")
+def test_a_private_store_write_never_takes_a_symlink_targets_mode(tmp_path):
+ from agentplay.store import _atomic_write
+
+ target = tmp_path / "elsewhere.json"
+ target.write_text("theirs")
+ target.chmod(0o644)
+ link = tmp_path / "store" / "index.json"
+ link.parent.mkdir()
+ link.symlink_to(target)
+ _atomic_write(link, b"ours")
+ assert not link.is_symlink() and (link.stat().st_mode & 0o777) == 0o600
+ assert target.read_text() == "theirs" and (target.stat().st_mode & 0o777) == 0o644
+
+
+def test_file_chips_add_up_distinct_paths_that_share_a_basename():
+ terms = {"s1": {
+ "file:acme/api:src/one/a.ts": [[1, "read", 50]],
+ "file:acme/api:src/two/a.ts": [[2, "read", 50]],
+ "file:a.ts": [[1, "read", 50], [2, "read", 50]],
+ }}
+ chip = search.query(terms, "file:src")["s1"]["chips"][0]
+ assert chip["n"] == 100