Python
run: --coworker chooses the coworker, and the workspace defaults to the current folder
Rohit C Prasad8064af1ed1ea
diff --git a/coworker/headless/runner.py b/coworker/headless/runner.pyindex 33aaa7dc..46b97912 100644--- a/coworker/headless/runner.py+++ b/coworker/headless/runner.py@@ -60,7 +60,9 @@ def parse_args(argv: Optional[list[str]] = None) -> argparse.Namespace:src = p.add_mutually_exclusive_group(required=True)src.add_argument("--prompt", "--prompt-text", dest="prompt_text", help="the task text")src.add_argument("--prompt-file", help="file containing the task text (UTF-8)")- p.add_argument("--workspace", required=True, help="folder the agent works in")+ p.add_argument(+ "--workspace", default=".", help="folder the agent works in (default: the current folder)"+ )p.add_argument("--add-dir",dest="add_dir",@@ -76,7 +78,12 @@ def parse_args(argv: Optional[list[str]] = None) -> argparse.Namespace:p.add_argument("--model", required=True, help="provider:model (OpenWorker) or provider/model")- p.add_argument("--persona", default="cowork", help="OpenWorker persona id (default: cowork)")+ p.add_argument(+ "--coworker", dest="persona", default="cowork", metavar="ID",+ help="the coworker that does the task, by its id (default: cowork)",+ )+ # The flag's first name; kept so an existing harness command still works.+ p.add_argument("--persona", dest="persona", default=argparse.SUPPRESS, help=argparse.SUPPRESS)p.add_argument("--mode", default="bypass-approvals", choices=MODES)p.add_argument("--attendance",@@ -628,6 +635,17 @@ def run(args: argparse.Namespace) -> int:from ..secrets import SecretStore, state_dirfrom ..unattended import DANGEROUS_MODE_WARNING+ # An unknown id would otherwise run the default coworker without saying so.+ from ..personas.registry import get_registry++ known = get_registry().ids()+ if args.persona not in known:+ print(+ f"openworker run: no coworker has the id {args.persona!r}. Known ids: {', '.join(sorted(known))}",+ file=sys.stderr,+ )+ return 2+workspace = Path(args.workspace).resolve()workspace.mkdir(parents=True, exist_ok=True)# `--add-dir DIR`: extra writable folders. An explicit list replaces the engine'sdiff --git a/docs/headless.md b/docs/headless.mdindex d96f2856..c9af329a 100644--- a/docs/headless.md+++ b/docs/headless.md@@ -70,12 +70,12 @@ Options:| Flag | Meaning ||---|---|| `--prompt TEXT` / `--prompt-file PATH` | the task |-| `--workspace DIR` | the folder the agent works in |+| `--workspace DIR` | the folder the agent works in; the current folder when left out || `--add-dir DIR` | an extra folder the agent may read and write, beside the workspace (repeatable), for a harness whose output contract lives outside the workspace — e.g. `--add-dir /output`. The file tools only write inside the session's folders, in every mode; the shell is not scoped, so without this a delivery would depend on which tool the model happened to pick. Recorded under `args.extra_dirs` in `summary.json`. || `--model ID` | `provider:model` or `provider/model` (first slash splits) || `--mode` | see above; default `bypass-approvals` || `--attendance` | `auto` (the only value here) |-| `--persona` | `cowork` (default) or `code` |+| `--coworker ID` | the coworker that does the task, by its id: `cowork` (default) or `code`. An unknown id stops the run with exit code 2 || `--reasoning-effort` | `low` … `max`, sent to the provider; unset = provider default, recorded || `--max-output-tokens`, `--max-iterations`, `--timeout-seconds` | ceilings; `--timeout-seconds 0` when an outer runner enforces its own || `--tool-result-max-bytes` | bound each tool result (default 10,000; 0 = off); full text spilled under `out/tool-output/` |diff --git a/tests/test_headless_run.py b/tests/test_headless_run.pyindex 4492ef74..87819a0e 100644--- a/tests/test_headless_run.py+++ b/tests/test_headless_run.py@@ -279,7 +279,7 @@ def test_empty_reply_is_nudged_and_a_permanent_error_is_not_retried(tmp_path: Padef test_code_persona_runs_headless_and_is_recorded(tmp_path: Path) -> None:- proc, ws, out = _run(tmp_path, "bypass-approvals", extra=["--persona", "code"])+ proc, ws, out = _run(tmp_path, "bypass-approvals", extra=["--coworker", "code"])assert proc.returncode == 0, proc.stdout + proc.stderrsummary = _summary(out)assert summary["outcome"] == "completed" and summary["args"]["persona"] == "code"@@ -357,3 +357,32 @@ def test_run_help_and_the_top_level_help_mention_the_command() -> None:[sys.executable, "-m", "coworker.cli"], env=_env(), capture_output=True, text=True, timeout=120)assert "run <task>" in top.stdout+++def test_the_old_persona_flag_still_chooses_the_coworker(tmp_path: Path) -> None:+ proc, ws, out = _run(tmp_path, "bypass-approvals", extra=["--persona", "code"])+ assert proc.returncode == 0, proc.stderr+ assert _summary(out)["args"]["persona"] == "code"+++def test_an_unknown_coworker_id_stops_the_run(tmp_path: Path) -> None:+ proc, ws, out = _run(tmp_path, "bypass-approvals", extra=["--coworker", "no-such-coworker"])+ assert proc.returncode == 2+ assert "no-such-coworker" in proc.stderr and "cowork" in proc.stderr+ assert not (out / "summary.json").exists()+++def test_the_workspace_defaults_to_the_current_folder(tmp_path: Path) -> None:+ here = tmp_path / "here"+ here.mkdir()+ script = tmp_path / "script.json"+ script.write_text(json.dumps(SCRIPT), encoding="utf-8")+ out = tmp_path / "out"+ cmd = [+ sys.executable, "-m", "coworker.cli", "run", "--prompt", TASK,+ "--model", "anthropic/claude-sonnet-5", "--mode", "bypass-approvals",+ "--out", str(out), "--scripted", str(script), "--timeout-seconds", "120",+ ]+ proc = subprocess.run(cmd, env=_env(None), cwd=here, capture_output=True, text=True, timeout=300)+ assert proc.returncode == 0, proc.stderr+ assert _summary(out)["args"]["workspace"] == str(here.resolve())