Skip to content

Commit 927efed

Browse files
committed
fix(app): a composer command cannot be a fresh run's task
A first prompt is a task, not a composer line, so `/task fix the parser` began a run whose task was that literal text. It is refused where a leg's steer already is: - in the lifecycle, which `agent6 run` and the ACP bridge share - before the detached spawn a hub makes, whose own refusal nobody reads
1 parent 67368de commit 927efed

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎src/agent6/app/run.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from agent6.app.reporter import STDIO_REPORTER, Reporter
5959
from agent6.budget import BudgetTracker
6060
from agent6.config import Config
61+
from agent6.directive import steer_problem
6162
from agent6.events import EventSink
6263
from agent6.git_ops import (
6364
GitError,
@@ -171,6 +172,11 @@ def run_task( # noqa: PLR0911, PLR0912, PLR0915
171172
"""
172173
role = session_kind(mode).role
173174
cwd = Path.cwd()
175+
# A first prompt is a task, not a composer line: without this the command
176+
# would become the literal task text the model works on.
177+
if (problem := steer_problem(task)) is not None:
178+
reporter.error(problem)
179+
return 2
174180
if session_id:
175181
try:
176182
validate_explicit_session_id(session_id)

‎src/agent6/ui/spawn.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def spawn_new_work( # noqa: PLR0911
8787
return None, f"unknown mode {mode!r}"
8888
if not task.strip():
8989
return None, "empty task"
90+
# The child refuses this too, but detached: nobody reads its stderr.
91+
if (problem := steer_problem(task)) is not None:
92+
return None, problem
9093
segments = None
9194
if mode == "run":
9295
try:

‎tests/unit/test_spawn_new_work.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,18 @@ def test_argv_carries_the_model_route(tmp_path: Path, monkeypatch: pytest.Monkey
370370
assert captured[-1][1:] == ["plan", "--preset", "quick", "--model", "o/m", "--", "t"]
371371
spawn.spawn_new_work(tmp_path, "run", "/parallel 2 t", model="o/m")
372372
assert captured[-1][1:] == ["run", "--model", "o/m", "--parallel", "2", "--", "t"]
373+
374+
375+
def test_a_composer_command_as_the_task_is_refused_before_any_spawn(
376+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
377+
) -> None:
378+
"""The new-work box takes a task, not a composer command: `/task` typed
379+
there is named before a run starts, since the child's own refusal would
380+
land on a detached process nobody reads."""
381+
captured = _capture_locate(monkeypatch)
382+
383+
session_dir, err = spawn.spawn_new_work(tmp_path, "run", "/task fix the parser")
384+
385+
assert session_dir is None
386+
assert "composer command" in err
387+
assert captured == []

‎tests/unit/test_task_directive_surfaces.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,29 @@ def test_an_ordinary_line_and_a_real_directive_say_nothing_extra(tmp_path: Path)
232232
assert submit_composer_line(d, "focus on the parser") == (True, "steering")
233233
# `/parallel` separates tasks by design, so a later one is meant.
234234
assert submit_composer_line(d, "/parallel a /parallel b")[1] == "steering"
235+
236+
237+
def test_a_composer_command_cannot_be_a_fresh_runs_task(
238+
capsys: pytest.CaptureFixture[str],
239+
) -> None:
240+
"""A run's first prompt is not a composer, so `/task` there would have
241+
become the literal task text the model works on. The lifecycle refuses it
242+
the way a leg's steer is refused, for `agent6 run` and the ACP bridge
243+
alike: both reach run_task."""
244+
import time
245+
from unittest.mock import MagicMock
246+
247+
from agent6.app.run import run_task
248+
from agent6.config.layer import load_effective
249+
250+
rc = run_task(
251+
load_effective(Path.cwd(), None).config,
252+
"/task fix the parser",
253+
started_at=time.time(),
254+
frontend=MagicMock(),
255+
session_id="run-REFUSED-AAAAAA",
256+
mode="run",
257+
)
258+
259+
assert rc == 2
260+
assert "composer command" in capsys.readouterr().err

0 commit comments

Comments
 (0)