Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Changed

- `witan task claim` prints the lease the server granted alongside the
assignee, e.g. `(assignee=alice, lease 120 minutes)`. A lease that is not
whole minutes is printed in seconds, as the `witan task run` prompt states
it. The claim confirmations from `witan task run` and from a consolidated
multi-task run print it the same way.
17 changes: 17 additions & 0 deletions mcp/servers/witan/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,23 @@ def test_task_claim_and_release_cli(server, monkeypatch):
assert "Released" in combined


@requires_omnigraph
def test_task_claim_cli_prints_the_lease_it_was_granted(server, monkeypatch):
"""The lease is the server's, so a person claiming from the CLI needs it printed."""
from witan import readiness
from witan import server as srv
from witan.cli._common import _fn
from witan.cli.tasks import task_claim_cmd

printed = _patch_server(monkeypatch, server)
monkeypatch.setattr(readiness, "claim_lease_seconds", lambda: 5400)
t = _fn(srv.task_create)(title="t", description="d")

task_claim_cmd(t["slug"], assignee="alice")

assert "lease 90 minutes" in "\n".join(printed)


@requires_omnigraph
def test_task_update_cli(server, monkeypatch):
"""task update changes mutable fields."""
Expand Down
16 changes: 16 additions & 0 deletions mcp/servers/witan/tests/test_launch_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,22 @@ def test_emit_spec_prints_the_spec_and_does_not_launch(folders, monkeypatch, cap
assert not launched


def test_task_run_prints_the_lease_it_claimed_with(folders, monkeypatch, capsys):
"""`witan task run` claims too, so its confirmation says when the claim lapses."""
from witan.cli import run_helpers, tasks

here, _ = folders
claim = {**_CLAIMED, "lease_seconds": 7200}
_cli(monkeypatch, _Fake(task=_task(), claim=claim), here)
monkeypatch.setattr(run_helpers, "_launch_agent", lambda *a, **kw: None)

tasks.task_run("tk-a")

assert (
"Claimed tk-a (assignee=pytest, lease 120 minutes)." in capsys.readouterr().out
)


def test_emit_spec_exits_non_zero_on_a_refusal(folders, monkeypatch, capsys):
from witan.cli import projects

Expand Down
43 changes: 36 additions & 7 deletions mcp/servers/witan/witan/cli/run_helpers.py
Comment thread
blarghmatey marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,34 @@ def _overlap_lines(overlaps: list[dict]) -> list[str]:
return lines


def _lease_length(lease_seconds: int) -> str:
"""A claim's lease length as a person or agent reads it.

Minutes only when the lease is whole minutes: the server accepts any
positive number of seconds, and flooring a 90s lease would say it lapses
after 1 minute.

:param lease_seconds: The lease ``task_claim`` reported.
:returns: e.g. ``"120 minutes"`` or ``"90 seconds"``.
:rtype: str
"""
if lease_seconds % 60 == 0:
return f"{lease_seconds // 60} minutes"
return f"{lease_seconds} seconds"


def _lease_note(claim: dict) -> str:
"""The lease a granted claim reported, for the line that confirms the claim.

:param claim: What ``task_claim`` returned for a granted claim.
:returns: e.g. ``", lease 120 minutes"``, or ``""`` from a deployment older
than lease reporting, which grants the claim without one.
:rtype: str
"""
lease = claim.get("lease_seconds")
return f", lease {_lease_length(lease)}" if lease is not None else ""


def _run_prompt(
t: dict,
*,
Expand Down Expand Up @@ -334,12 +362,11 @@ def _run_prompt(
# `task_claim` renews it, which the agent can only do if it is told to.
# The length comes from the claim, never a local constant: a deployment
# sets its own, and this process is only its client.
if lease_seconds is None:
lapses = "lapses after the lease task_claim reports as lease_seconds"
elif lease_seconds % 60 == 0:
lapses = f"lapses after {lease_seconds // 60} minutes"
else:
lapses = f"lapses after {lease_seconds} seconds"
lapses = (
"lapses after the lease task_claim reports as lease_seconds"
if lease_seconds is None
else f"lapses after {_lease_length(lease_seconds)}"
)
held = (
f"This task is claimed for you. The claim is a lease, not a lock: it "
f"{lapses} and nothing renews it for you, "
Expand Down Expand Up @@ -764,8 +791,10 @@ def _deliver(spec: LaunchSpec | LaunchRefusal, cfg, *, emit_spec: bool) -> None:
stderr_console.print(f" [yellow]{esc(spec['claim']['remedy'])}[/yellow]")
raise SystemExit(1)
if spec["claim"]:
claim = spec["claim"]
console.print(
f"[cyan]Claimed {spec['slug']} (assignee={spec['claim']['assignee']}).[/cyan]"
f"[cyan]Claimed {spec['slug']} "
f"(assignee={claim['assignee']}{_lease_note(claim)}).[/cyan]"
)
_launch_agent(
cfg,
Expand Down
7 changes: 5 additions & 2 deletions mcp/servers/witan/witan/cli/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from .output import dump_record, get_output_format
from .run_helpers import (
_launch_agent,
_lease_note,
_merge_prompts,
_overlap_lines,
_pick_items,
Expand Down Expand Up @@ -544,7 +545,7 @@ def task_claim_cmd(
if result.get("claimed"):
console.print(
f"[green]Claimed[/green] [bold]{slug}[/bold] "
f"(assignee={result.get('assignee')})"
f"(assignee={result.get('assignee')}{_lease_note(result)})"
)
for line in _overlap_lines(result.get("overlaps") or []):
console.print(line, markup=False, emoji=False, highlight=False)
Expand Down Expand Up @@ -881,7 +882,9 @@ def _render_task(t: dict) -> str:
with bare_session_env(), launched_client_instance(instance):
res = _fn(s.task_claim)(slug=t["slug"], force=force) or {}
if res.get("claimed"):
console.print(f"[cyan]Claimed {t['slug']}.[/cyan]")
console.print(
f"[cyan]Claimed {t['slug']}{_lease_note(res)}.[/cyan]"
)
claimable.append(t)
claims[t["slug"]] = res
else:
Expand Down
Loading