Skip to content

Commit 48042e9

Browse files
committed
fix(ui/cli): a btw beside a run with no commit yet says so instead of quoting git's unknown-revision error
1 parent 22dc675 commit 48042e9

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

‎src/agent6/ui/cli/_ask.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from agent6.sessions import layout as sessions_layout
1919
from agent6.sessions import manifest as sessions_manifest
2020
from agent6.ui.cli import _common, _steer
21-
from agent6.viewmodel import newest_session_dir
21+
from agent6.viewmodel import listing, newest_session_dir
2222

2323

2424
def summarize_session_log(logs_path: pathlib.Path) -> str:
@@ -198,7 +198,14 @@ def build_session_seed(cwd: pathlib.Path, session_id: str, *, latest: bool) -> S
198198
fallback = _diff_via_merge_stamp(cwd, manifest, base_sha, run_branch)
199199
if fallback is not None:
200200
diff_label, rc, diff, err = fallback
201-
if rc != 0:
201+
if (
202+
rc != 0
203+
and not git_ops.branch_exists(cwd, run_branch)
204+
and not listing.scan_session_log(layout.logs_path).finished
205+
):
206+
# The branch is cut by the first commit; before it there is nothing to diff.
207+
diff_body = "(no diff: the run has made no commit yet)"
208+
elif rc != 0:
202209
# Loud: an empty diff block reads as "no changes".
203210
diff_body = f"(diff unavailable: git diff exited {rc}: {err.strip()[:300]})"
204211
else:

‎tests/unit/test_ask_context.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,26 @@ def test_ask_run_digest_reports_unavailable_diff(
431431
assert "diff unavailable" in digest
432432

433433

434+
def test_ask_run_digest_of_a_run_with_no_commit_says_so(
435+
tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch
436+
) -> None:
437+
"""A `/btw` beside a run that had not committed yet got git's unknown-revision error."""
438+
rid = _make_run(tmp_path)
439+
session_dir = paths.state_dir(tmp_path) / "sessions" / "runs" / rid
440+
m = json.loads((session_dir / "manifest.json").read_text(encoding="utf-8"))
441+
_git(tmp_path, "checkout", "-q", m["base_sha"])
442+
_git(tmp_path, "branch", "-D", "agent6/run")
443+
(session_dir / "logs.jsonl").write_text(
444+
json.dumps({"type": "session.start", "user_task": "make x equal 2"}) + "\n",
445+
encoding="utf-8",
446+
)
447+
monkeypatch.chdir(tmp_path)
448+
digest = _build_ask_session_digest(tmp_path, rid, latest=False)
449+
assert digest is not None
450+
assert "(no diff: the run has made no commit yet)" in digest
451+
assert "unknown revision" not in digest
452+
453+
434454
def _session(
435455
tmp_path: pathlib.Path, bucket: str, sid: str, mode: str, *, run_branch: str | None
436456
) -> None:

0 commit comments

Comments
 (0)