Skip to content
Python

run: connectors are available, and the record uses the new names

Rohit C Prasadbab5b07c9b7b
diff --git a/coworker/headless/runner.py b/coworker/headless/runner.py
index 7a920b15..f36bf163 100644
--- a/coworker/headless/runner.py
+++ b/coworker/headless/runner.py
@@ -5,8 +5,8 @@
--model anthropic/claude-sonnet-5 --approval-mode bypass-approvals --out ./run-record
Each run is its own process with its own engine. It reads this computer's settings (the
-default model, stored keys, the sandbox and its allowed sites) and changes none of them;
-`--isolated` reads nothing at all, for benchmark runs. The model id is accepted in
+default model, stored keys, connectors, the sandbox and its allowed sites) and changes none
+of them, beyond renewing a sign-in; `--isolated` reads nothing at all, for benchmark runs. The model id is accepted in
OpenWorker's `provider:model` form or the `provider/model` form other tools use.
Approvals and questions are separate. An approval follows `--approval-mode`: asked in the terminal
@@ -842,10 +842,10 @@ def _run(args: argparse.Namespace) -> int:
question_asker=terminal.ask if terminal is not None and not auto_answer else None,
directory_requester=terminal.directory if terminal is not None and not auto_answer else None,
tool_requester=terminal.tool if terminal is not None and not auto_answer else None,
- # A run reads this computer's settings and changes none of them. A connector
- # refreshes its stored sign-in as it works, so connectors stay out of a run for
- # now. (An isolated run has none to begin with.)
- connector_filter=None if args.isolated else set(),
+ # Connectors: whatever is connected on this computer and the coworker may use,
+ # as in the app. Their sign-ins are renewed under the store's lock
+ # (secrets.SecretStore.exclusive), so a run and the app do not collide. An
+ # isolated run has none: its state folder is empty.
)
# Questions: answered by rule when nobody will (coworker/unattended.py). Approvals:
# with a terminal they reach the person whatever --auto-answer says.
@@ -1293,9 +1293,10 @@ def _write_records(
"args": {
"model": model,
"model_as_given": args.model,
- "persona": args.coworker,
- "mode": args.mode,
- "attendance": args.attendance,
+ "coworker": args.coworker,
+ "approval_mode": args.approval_mode,
+ # Questions were answered by rule (--auto-answer, or no terminal to ask on).
+ "auto_answer": args.attendance == "auto",
"isolated": bool(args.isolated),
"max_iterations": args.max_iterations,
"max_output_tokens": args.max_output_tokens,
@@ -1352,9 +1353,10 @@ def _write_records(
outcome=outcome,
reasoning_effort=effort["label"],
agent_extra={
- "persona": args.coworker,
- "mode": args.mode,
- "attendance": args.attendance,
+ "coworker": args.coworker,
+ "approval_mode": args.approval_mode,
+ # Questions were answered by rule (--auto-answer, or no terminal to ask on).
+ "auto_answer": args.attendance == "auto",
"reasoning_effort": effort["label"],
"reasoning_effort_detail": effort["detail"],
},
diff --git a/docs/headless.md b/docs/headless.md
index d5ddeb7d..2fafe980 100644
--- a/docs/headless.md
+++ b/docs/headless.md
@@ -71,12 +71,18 @@ closing summary line go to standard error.
### What a run reads from this computer
A run uses this computer's OpenWorker settings: the default model, the stored provider
-keys, the sandbox and its allowed sites. It reads them and changes none of them.
-Connectors are not available in a run yet.
+keys, the connectors you have connected, the sandbox and its allowed sites. It reads them
+and changes none of them. The one thing it may write is a renewed sign-in, as the app does
+when a sign-in expires.
+
+A connector's actions go through the approval mode like any other tool call.
Each run is its own process. Two runs started from two terminals do not share anything
but those settings, and each is saved as its own session.
+The app and any number of runs can work at the same time. When a sign-in needs renewing,
+one of them renews it and the others use the result.
+
### Approvals and questions
These are separate, and each has its own switch.
diff --git a/tests/test_headless_run.py b/tests/test_headless_run.py
index debc4b20..6b75e91f 100644
--- a/tests/test_headless_run.py
+++ b/tests/test_headless_run.py
@@ -107,7 +107,7 @@ def test_bypass_writes_the_file_and_leaves_a_full_record(tmp_path: Path) -> None
summary = _summary(out)
assert summary["outcome"] == "completed"
assert summary["args"]["model"] == "anthropic:claude-sonnet-5" # provider/model converted
- assert summary["args"]["attendance"] == "auto"
+ assert summary["args"]["auto_answer"] is True
assert summary["tool_calls"] == 2 and summary["tool_calls_denied"] == 0
assert summary["answers"] == {
"cards_refused": 0,
@@ -126,7 +126,7 @@ def test_bypass_writes_the_file_and_leaves_a_full_record(tmp_path: Path) -> None
traj = json.loads((tmp_path / "logs" / "trajectory.json").read_text(encoding="utf-8"))
assert traj["schema_version"] == "ATIF-v1.7"
assert traj["agent"]["name"] == "openworker" and traj["agent"]["version"].startswith("openworker")
- assert traj["agent"]["extra"]["attendance"] == "auto"
+ assert traj["agent"]["extra"]["auto_answer"] is True
assert [s["step_id"] for s in traj["steps"]] == list(range(1, len(traj["steps"]) + 1))
agent_steps = [s for s in traj["steps"] if s["source"] == "agent"]
assert agent_steps[0]["tool_calls"][0]["function_name"] == "write_file"
@@ -167,7 +167,7 @@ def test_dangerous_mode_warns_and_clears_the_downloaded_file_floor(tmp_path: Pat
assert "Dangerously bypass approvals is on" in proc.stderr
messages = _messages(out)
assert any(m.get("role") == "notice" and m.get("kind") == "dangerous_mode" for m in messages)
- assert _summary(out)["args"]["mode"] == "dangerously-bypass-approvals"
+ assert _summary(out)["args"]["approval_mode"] == "dangerously-bypass-approvals"
def test_a_question_is_answered_by_the_engine_and_counted(tmp_path: Path) -> None:
@@ -291,7 +291,7 @@ def test_code_persona_runs_headless_and_is_recorded(tmp_path: Path) -> None:
proc, ws, out = _run(tmp_path, "bypass-approvals", extra=["--coworker", "code"])
assert proc.returncode == 0, proc.stdout + proc.stderr
summary = _summary(out)
- assert summary["outcome"] == "completed" and summary["args"]["persona"] == "code"
+ assert summary["outcome"] == "completed" and summary["args"]["coworker"] == "code"
assert (ws / "hello.txt").read_text(encoding="utf-8") == "hello"
system = next(m for m in _messages(out) if m["role"] == "system")["content"]
assert "coding agent" in system
@@ -441,7 +441,7 @@ def test_an_empty_standard_input_stops_the_run(tmp_path: Path) -> None:
assert not (out / "summary.json").exists()
-def test_ask_is_recorded_under_the_engines_name_for_it(tmp_path: Path) -> None:
+def test_ask_is_the_default_and_the_engine_gets_its_own_name_for_it(tmp_path: Path) -> None:
from coworker.headless.runner import parse_args
base = ["--prompt", "x", "--model", "anthropic/claude-sonnet-5", "--out", str(tmp_path)]
diff --git a/tests/test_run_cli.py b/tests/test_run_cli.py
index 467d1778..4cf2291e 100644
--- a/tests/test_run_cli.py
+++ b/tests/test_run_cli.py
@@ -103,6 +103,24 @@ def test_this_computers_settings_are_read_and_not_changed(tmp_path: Path) -> Non
assert sorted(p.name for p in machine.iterdir() if p.is_dir()) == ["sessions"]
+def test_a_run_has_the_connectors_this_computer_has_connected(tmp_path: Path) -> None:
+ """The write is refused here (mode ask, nobody to ask), which is the proof the
+ connector's tool was there to be called; nothing leaves the computer."""
+ machine = tmp_path / "machine"
+ machine.mkdir()
+ (machine / "secrets.json").write_text(json.dumps({"github:default": {"token": "ghp_test", "enabled": True}}), encoding="utf-8")
+ script = [
+ {"text": "", "tool_calls": [{"name": "github_create_issue", "arguments": {"owner": "acme", "repo": "app", "title": "A title", "body": "A body"}}]},
+ {"text": "It was refused."},
+ ]
+ proc, ws, _ = _run(tmp_path, script, "--model", "anthropic/claude-sonnet-5", machine=machine)
+ assert proc.returncode == 0, proc.stderr
+ (folder,) = _session_folders(machine, ws)
+ answers = json.loads((folder / "answers.json").read_text(encoding="utf-8"))
+ assert [row["tool"] for row in answers["rows"]] == ["github_create_issue"]
+ assert json.loads((machine / "secrets.json").read_text(encoding="utf-8")) == {"github:default": {"token": "ghp_test", "enabled": True}}
+
+
def test_two_runs_in_one_workspace_are_two_sessions(tmp_path: Path) -> None:
for _ in range(2):
proc, ws, machine = _run(tmp_path, WRITE_THEN_DONE, "--model", "anthropic/claude-sonnet-5", "--approval-mode", "bypass-approvals")
@@ -120,7 +138,7 @@ def test_the_default_mode_asks_and_with_no_terminal_the_card_is_refused(tmp_path
assert "no terminal is attached" in proc.stderr and "--approval-mode auto-approve" in proc.stderr
(folder,) = _session_folders(machine, ws)
summary = json.loads((folder / "summary.json").read_text(encoding="utf-8"))
- assert summary["args"]["mode"] == "interactive" and summary["args"]["attendance"] == "auto"
+ assert summary["args"]["approval_mode"] == "ask" and summary["args"]["auto_answer"] is True
assert summary["answers"]["cards_refused"] == 1
@@ -437,7 +455,7 @@ def test_at_a_terminal_a_question_is_asked_there(tmp_path: Path) -> None:
(folder,) = _session_folders(machine, ws)
messages = json.loads((folder / "messages.json").read_text(encoding="utf-8"))
assert any(m.get("role") == "tool" and "blue" in str(m.get("content")) for m in messages)
- assert json.loads((folder / "summary.json").read_text(encoding="utf-8"))["args"]["attendance"] == "attended"
+ assert json.loads((folder / "summary.json").read_text(encoding="utf-8"))["args"]["auto_answer"] is False
@pytest.mark.skipif(sys.platform == "win32", reason="needs a pseudo-terminal")