Skip to content
Merged
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
4 changes: 2 additions & 2 deletions agents/conductors/batch/_codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ def command(model: str, effort: str, mode: str, cwd: Path, write_root: Path) ->
"-c", f"model_reasoning_effort={json.dumps(effort)}",
"-c", 'model_provider="openai"', "-c", 'forced_login_method="chatgpt"',
"-c", "features.multi_agent=false", "-c", "features.goals=false", # usage is for this worker only
"--sandbox", "workspace-write", "--cd", str(cwd),
"--cd", str(cwd),
"--add-dir", str(write_root), "--skip-git-repo-check"]
if mode == "auto":
argv.append("--approve-for-me")
else:
argv += ["-c", 'approval_policy="never"']
argv += ["--sandbox", "workspace-write", "-c", 'approval_policy="never"']
return argv + ["-"]


Expand Down
10 changes: 6 additions & 4 deletions bin/codex_orchestrator_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def check() -> dict:
'verify gh auth and Heart before a shift. This check starts no model.'}


def smoke(model: str) -> dict:
def smoke(model: str, mode: str = 'auto') -> dict:
# Disposable workspace: no repositories, shift grants or publication.
import shutil

Expand All @@ -52,7 +52,7 @@ def smoke(model: str) -> dict:
'Do not read other projects, call another model, use the network, '
'create a task, commit, push or launch any background work.')
lease = _codex.launch(prompt, home=home, cwd=root, write_root=root, model=model,
effort='medium', mode='dontAsk', env=dict(os.environ))
effort='medium', mode=mode, env=dict(os.environ))
sid = lease['agent_id']
try:
end = time.monotonic() + 300
Expand All @@ -62,7 +62,7 @@ def smoke(model: str) -> dict:
usage = _codex.usage(sid, home)
passed = state == 'done' and marker.exists() and marker.read_text().strip() == 'PYAUTO_CODEX_OK'
return {'ok': passed and usage is not None, 'state': state, 'usage': usage,
'marker': passed, 'scope': 'no-op only; no development/merge readiness claim'}
'marker': passed, 'worker_mode': mode, 'scope': 'no-op only; no development/merge readiness claim'}
time.sleep(.2)
return {'ok': False, 'error': 'smoke timed out after 300 seconds'}
finally:
Expand All @@ -83,12 +83,14 @@ def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--smoke', action='store_true', help='explicitly run one no-op model session')
parser.add_argument('--model', help='installed Codex model id; required with --smoke')
parser.add_argument('--worker-mode', choices=('auto', 'dontAsk'), default='auto',
help='worker approval mode exercised by --smoke (default: auto)')
args = parser.parse_args()
if args.smoke and not args.model:
parser.error('--smoke requires --model')
result = check()
if args.smoke and result['ok']:
result = smoke(args.model)
result = smoke(args.model, args.worker_mode)
print(json.dumps(result, indent=2))
return 0 if result['ok'] else 1

Expand Down
3 changes: 2 additions & 1 deletion docs/codex_orchestrator.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ After the read-only check passes, explicitly run one disposable no-op session:
python3 PyAutoBrain/bin/codex_orchestrator_check.py --smoke --model <your-installed-model-id>
```

This consumes a Codex session. It verifies launch, completion, a written marker
This uses the production auto-mode launcher and consumes one Codex session.
Pass `--worker-mode dontAsk` to exercise that mode instead. It verifies launch, completion, a written marker
and usage in a temporary workspace. It does not create an issue, PR or shift,
run a reviewer, or prove repository permissions. It times out after five minutes.

Expand Down
2 changes: 1 addition & 1 deletion skills/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ call, so the Brain is not bypassed):
as `/queue` writes the queue.

- **`/cockpit`** — watch a running shift from chat and steer it
(PyAutoBrain#646). One Monitor on the canonical `batch watch --stream`
(PyAutoBrain#646). Codex reads in the current turn; Claude uses one Monitor on the canonical `batch watch --stream`
command, inside the shift's window, re-armed only at `segment-end`; the one
watch a session may hold (Mind `policy/shift_cockpit_watch.md`, enforced by
the end-at-deliverable hook). Steering is one comment on the shift issue from
Expand Down
7 changes: 6 additions & 1 deletion skills/batch/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ without `issue:`, and an expired CLI login (the human runs `claude /login`).
45 min after `review-at:`. Never two open briefs at once. The watcher reads
the `origin/main` ref of the Mind checkout in its env file **without
fetching**, so push the brief from that checkout or `git fetch` it before
launch; otherwise the watcher idles with "no open brief".
launch; otherwise the watcher idles with "no open brief". After a push from a separate
worktree, also verify the configured Mind checkout contains the pushed brief:
compare the local file's `git hash-object` with `git rev-parse origin/main:batches/<slot>.md`.
When its `main` lags, use `git merge --ff-only origin/main` there and repeat
the comparison. If Git reports a conflict or the hashes differ, report that
pickup is blocked. Verify pickup with the first watcher tick or status comment.

## When the batch is complete

Expand Down
2 changes: 1 addition & 1 deletion skills/cockpit/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: cockpit
description: Watch a running shift from chat when the human asks for a watch (/cockpit, "watch the shift", "start the cockpit") — stream its events with Monitor and steer it by comments on the shift issue. A question about the shift gets a one-shot read, never a watch. In a /cockpit chat, a pasted prompt, path or dashboard copy line means /add it to the shift, never start dev.
description: Watch a running shift from chat when the human asks for a watch (/cockpit, "watch the shift", "start the cockpit") — stream its events in the current Codex turn or with Claude Monitor and steer it by comments on the shift issue. A question about the shift gets a one-shot read, never a watch. In a /cockpit chat, a pasted prompt, path or dashboard copy line means /add it to the shift, never start dev.
---

# Cockpit
Expand Down
27 changes: 13 additions & 14 deletions skills/cockpit/cockpit.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ Shared routing context: `PyAutoBrain/skills/COMMANDS.md`.

## Attach only when asked

Arm the watch only on an explicit request for one: `/cockpit`, "/cockpit
watch", "watch the shift", "start the cockpit" (policy condition 1: the human
asked for it in this session). A question ("what's the shift doing?", "is
anything stuck?") gets a one-shot answer from `batch watch --once` or the reads
in section 7, with no Monitor; offer the watch in one line if it would help.
Attach only when explicitly asked in this session, e.g. `/cockpit` or "watch the shift".
For a status question, answer once with `batch watch --once` or the reads in section 7, with no Monitor.

## The rule of this chat

Expand Down Expand Up @@ -53,7 +50,12 @@ the record's `- issue:` line.

## 3. Attach

Call `Monitor` with `timeout_ms: 1800000`, description `shift <slot> events`,
In Codex, run the command below in a foreground terminal during the **current chat turn**.
Read stdout from the same session handle with short, interruptible waits and relay each event as it arrives.
Resume only on exit 3 with the printed cursor. On cancellation or turn end, interrupt and reap the reader.
If streaming is unavailable, give the human the command for their terminal.

In Claude, call `Monitor` with `timeout_ms: 1800000`, description `shift <slot> events`,
and exactly this command, in this flag order, with nothing before, after or
around it:

Expand Down Expand Up @@ -141,9 +143,8 @@ within 3 ticks (about 3 min), or `steer-unread` arrives, say so once.

## Stop watching

On "stop watching" or "close the cockpit", stop the Monitor with `TaskStop`
and say "Stopped watching; the shift carries on." The shift is unaffected (to
stop it, that is `/stop`). Do not arm again unless asked.
On "stop watching" or "close the cockpit", interrupt and reap the Codex reader or use Claude's `TaskStop`.
Confirm that the shift carries on. Resume watching only on request.

## 6. Questions

Expand Down Expand Up @@ -174,9 +175,7 @@ second Monitor.
- Arming anything after the shift ends, or re-arming after any exit but
`segment-end`.

## Without Monitor (web, mobile, Codex)
## Without a streaming tool

Run `batch watch --once` in the foreground when asked, and steer by the same
comments. Nothing is armed. Without `gh`, post the steering comment and make
the reads through the GitHub MCP tools that
[`../GITHUB_ACCESS.md`](../GITHUB_ACCESS.md) maps each `gh` call to.
On web or mobile, use `batch watch --once` on request and steer through the shift issue.
When `gh` is unavailable, use the equivalents in [GitHub access](../GITHUB_ACCESS.md).
26 changes: 25 additions & 1 deletion tests/test_orchestrator_codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ def test_command_preserves_sandbox_and_model(mode, tmp_path):
argv = _codex.command("selected-model", "high", mode, tmp_path, tmp_path / "worktrees")
assert argv[:3] == ["codex", "exec", "--json"]
assert argv[argv.index("--model") + 1] == "selected-model"
assert argv[argv.index("--sandbox") + 1] == "workspace-write"
if mode == "auto":
assert "--sandbox" not in argv # --approve-for-me selects workspace-write itself
else:
assert argv[argv.index("--sandbox") + 1] == "workspace-write"
assert "features.multi_agent=false" in argv
assert ("--approve-for-me" in argv) == (mode == "auto")
assert "--trust" not in argv and "--dangerously-bypass-hook-trust" not in argv
Expand Down Expand Up @@ -332,3 +335,24 @@ def test_check_default_does_not_launch_a_worker(tmp_path, monkeypatch):
monkeypatch.setattr(check.subprocess, 'run', lambda *a, **kw: SimpleNamespace(
returncode=0, stdout='--json --sandbox --add-dir --approve-for-me'))
assert check.check()['ok']

@pytest.mark.parametrize(("options", "expected"), [([], "auto"), (["--worker-mode", "dontAsk"], "dontAsk")])
def test_smoke_invokes_production_launcher_with_selected_mode(tmp_path, monkeypatch, options, expected):
import importlib.util
path = Path(orch.__file__).resolve().parents[3] / "bin" / "codex_orchestrator_check.py"
spec = importlib.util.spec_from_file_location("codex_check_mode_test", path)
check = importlib.util.module_from_spec(spec)
spec.loader.exec_module(check)
monkeypatch.setattr(check, "check", lambda: {"ok": True})
monkeypatch.setattr(sys, "argv", ["check", "--smoke", "--model", "selected", *options])

def launch(prompt, *, cwd, mode, model, **kwargs):
assert mode == expected and model == "selected"
(cwd / "smoke-ok.txt").write_text("PYAUTO_CODEX_OK")
return {"agent_id": "disposable"}

monkeypatch.setattr(_codex, "launch", launch)
monkeypatch.setattr(_codex, "state", lambda *_: "done")
monkeypatch.setattr(_codex, "usage", lambda *_: {"total": 1})
monkeypatch.setattr(_codex, "stop", lambda *_: None)
assert check.main() == 0
Loading