From f724d532bea26d6c1889dabf98fc927a481f1829 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 16 Nov 2026 14:28:49 +0000 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20/cockpit=20skill=20=E2=80=94=20watc?= =?UTF-8?q?h=20a=20shift=20and=20steer=20it=20from=20chat=20(#646)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The second half of M3.4 build C. skills/cockpit (SKILL.md + cockpit.md): - Attach: one Monitor running exactly the canonical stream command the end-at-deliverable hook allows (`/bin/pyauto-brain batch watch --stream --record /batches/.md --from --for 28`, literal resolved checkouts, timeout 30 min), after a foreground `--check`; re-armed only on `segment-end`, never after any other exit. - Report: one plain line per event; PushNotification only for `NEEDS YOU:` lines. - Steering: plain words become exactly one comment on the shift issue from the human's login (/pause /resume /drop /stop /kill /cap /add, with an audit line); /stop and /kill confirmed first; /add after a premise check. - Questions: counted from Mind origin/main questions.md and handed to /questions, with a one-line fallback while that skill is not installed. - Routing: in a /cockpit chat a pasted prompt is an /add to the shift, never start dev (COMMANDS.md, route.md, start_dev's description and body). - Committed discovery for Claude and Codex. tests/test_cockpit_skill.py: the command matches the hook's own STREAM_RE and passes this repo's installed hook mid-window (fixture workspace with the real resolver), is refused at review-at + 46 min and with a `$VAR` left in; the steering table covers exactly the watcher's COMMANDS; routing and discovery. Co-Authored-By: Claude Opus 5.5 --- .claude/commands/cockpit.md | 1 + .claude/skills/cockpit | 1 + .codex/skills/cockpit | 1 + skills/COMMANDS.md | 11 ++ skills/cockpit/SKILL.md | 16 +++ skills/cockpit/cockpit.md | 169 +++++++++++++++++++++++++ skills/route/route.md | 7 ++ skills/start_dev/SKILL.md | 6 +- tests/test_cockpit_skill.py | 240 ++++++++++++++++++++++++++++++++++++ 9 files changed, 451 insertions(+), 1 deletion(-) create mode 120000 .claude/commands/cockpit.md create mode 120000 .claude/skills/cockpit create mode 120000 .codex/skills/cockpit create mode 100644 skills/cockpit/SKILL.md create mode 100644 skills/cockpit/cockpit.md create mode 100644 tests/test_cockpit_skill.py diff --git a/.claude/commands/cockpit.md b/.claude/commands/cockpit.md new file mode 120000 index 00000000..108678e6 --- /dev/null +++ b/.claude/commands/cockpit.md @@ -0,0 +1 @@ +../../skills/cockpit/cockpit.md \ No newline at end of file diff --git a/.claude/skills/cockpit b/.claude/skills/cockpit new file mode 120000 index 00000000..36a99b17 --- /dev/null +++ b/.claude/skills/cockpit @@ -0,0 +1 @@ +../../skills/cockpit \ No newline at end of file diff --git a/.codex/skills/cockpit b/.codex/skills/cockpit new file mode 120000 index 00000000..36a99b17 --- /dev/null +++ b/.codex/skills/cockpit @@ -0,0 +1 @@ +../../skills/cockpit \ No newline at end of file diff --git a/skills/COMMANDS.md b/skills/COMMANDS.md index 4d04f2b6..e46efb92 100644 --- a/skills/COMMANDS.md +++ b/skills/COMMANDS.md @@ -113,6 +113,17 @@ call, so the Brain is not bypassed): on `origin/main`, committed with `prompt_sync_push`, then `lifecycle.py check`. The dashboard only reads the queue (★ and rank on each queued task). +- **`/cockpit`** — watch a running shift from chat and steer it + (PyAutoBrain#646). 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 + the human's login: `/pause`, `/resume`, `/drop`, `/stop`, `/kill`, `/cap`, + `/add` (`/stop` and `/kill` confirmed first). In a chat that ran `/cockpit`, a + pasted prompt, prompt path, title or dashboard 📋 line means **`/add` it to + the shift — never start dev**, and `/route` must not send it to `start_dev`. + Questions go to `/questions`. + - **`update_issue`** — post a progress update (commits, summary, what is left) to the active task's GitHub issue, read from the PyAutoMind registry. The dev-lifecycle's progress leg; `start_dev_for_user` calls it at milestones. diff --git a/skills/cockpit/SKILL.md b/skills/cockpit/SKILL.md new file mode 100644 index 00000000..79064e9f --- /dev/null +++ b/skills/cockpit/SKILL.md @@ -0,0 +1,16 @@ +--- +name: cockpit +description: Watch a running shift from chat (/cockpit, "watch the shift", "what's the shift doing") — stream its events with Monitor and steer it by comments on the shift issue. In a /cockpit chat, a pasted prompt, path or dashboard copy line means /add it to the shift, never start dev. +--- + +# Cockpit + +Follow [`cockpit.md`](cockpit.md) exactly. This is the one skill allowed to hold +a watch past its turn, and only the shift's own event stream inside its window +(PyAutoMind `policy/shift_cockpit_watch.md`, enforced by the end-at-deliverable +hook). Once `/cockpit` has run in a chat, that chat is a **cockpit chat** until +the shift ends: anything pasted that names a task (a prompt, a `draft/` path, +a title, or the dashboard's 📋 line `Use the start-dev skill. `) means +**`/add` it to this shift**. It never means start dev, plan, intake or build. +Every steering act is exactly one comment on the shift issue, from the human's +own login; the chat steers the shift in no other way. diff --git a/skills/cockpit/cockpit.md b/skills/cockpit/cockpit.md new file mode 100644 index 00000000..1484421f --- /dev/null +++ b/skills/cockpit/cockpit.md @@ -0,0 +1,169 @@ +# /cockpit — watch a shift and steer it from chat + +The shift watcher (a timer, not a session) is the engine. It writes one line per +event to the shift's `events.jsonl`, and `pyauto-brain batch watch --stream` +prints them (PyAutoBrain#644). This chat only reads that stream and posts +steering comments on the shift issue, which the watcher reads on its next tick +(about 3 minutes). Closing the chat changes nothing about the shift. + +The watch is the one carve-out from "sessions end at their deliverable" +(PyAutoMind `policy/shift_cockpit_watch.md`). The end-at-deliverable hook +enforces it: it lets through only the canonical stream command below, inside +the shift's window. If the hook refuses a Monitor, relay its reason in one line +and stop. Never retry it in another form. + +Shared routing context: `PyAutoBrain/skills/COMMANDS.md`. + +## The rule of this chat + +After `/cockpit`, a pasted task is an **add to this shift**. That covers a whole +prompt, a prompt path or GitHub link, a task title, or a dashboard 📋 line such +as `Use the start-dev skill. draft/feature/x/y.md`. It is never a start-dev, +`/route`, intake, plan or build request (see "Steering", `/add`). If the human +clearly wants a task started outside the shift ("start this one now, not in +the shift"), confirm in one line, then route normally. + +## 1. Find the shift + +- **Record:** the `--record` the human named, else `PYAUTO_SHIFT_BRIEF` in + `~/.config/pyauto/orchestrator.env`, else the newest + `/batches/.md` whose window is open. +- **Checkouts:** `` and `` are the resolved PyAutoBrain and + PyAutoMind checkouts of this workspace (root: `PYAUTO_ROOT`, else the nearest + ancestor holding `.pyauto-root`): + `python3 /agents/_repo_paths.py path PyAutoMind --required --root `. + The hook pins the stream to exactly these two, so a copy elsewhere is refused. +- **Check, in the foreground:** + `/bin/pyauto-brain batch watch --stream --check --record /batches/.md`. + On a non-zero exit, say why in one line (its stderr) and stop, with nothing + armed. + +## 2. Check the steering identity once + +`gh api user --jq .login` must equal the watcher's mention login +(`PYAUTO_SHIFT_MENTION`, else `shift_watcher: mention_login:` in +`/config/policy.yaml`). If it differs, say once that the watcher ignores +steering from this login, and carry on watch-only. Read the shift issue URL from +the record's `- issue:` line. + +## 3. Attach + +Call `Monitor` with `timeout_ms: 1800000`, description `shift events`, +and exactly this command, in this flag order, with nothing before, after or +around it: + +``` +/bin/pyauto-brain batch watch --stream --record /batches/.md --from --for 28 +``` + +- Replace ``, ``, `` and `` with literal text: absolute + paths, digits. No `$VAR`, `~`, quotes, `cd`, pipe or `2>&1`. The hook refuses + any shell metacharacter, and paths only of `A-Z a-z 0-9 . _ / -`. +- First attach: leave out `--from ` (the last 5 events), or `--from 0` when + the human wants everything so far. +- Never add `--json` (one plain line per event is the report). Add + `--home ` after `--for 28` only when the human named one. + +Then say, in one line, the `attached : …` summary and the inbox count +(section 6). + +## 4. On each notification + +- **Print the lines as they came**, one plain line per event, with no + commentary unless asked. +- **A line starting `HH:MMZ NEEDS YOU:`** is also sent as a phone push + (`PushNotification`, where the client has it), with that line as the text. + Nothing else is pushed. +- **`segment-end next=--from N`** (exit 3): arm the same command again with + `--from N`. This is the only re-arm. +- **Anything else ends the watch:** `shift-end`, the `stopped` line, the + `STOP file present` line, the `Watch window over` line, exit 2 (refused), or + a Monitor expiry without `segment-end`. Do not arm again. Say: + "Shift over. Digest: . questions in your inbox. Go through them now + or later?" (the digest URL from the `digest` line, else the shift issue). The + session ends at that deliverable. + +## 5. Steering: plain words become one comment + +Post each act as one comment on the shift issue, first line the command (all +the watcher reads), second line an audit note: + +```bash +gh issue comment --body-file - <<'STEER' +/drop markdown_regeneration_sigma_min +(said in the cockpit: "drop the sigma one, it's not worth it") +STEER +``` + +Then say "posted; the watcher acknowledges on its next tick (about 3 min)". The +`steer` event arrives through the stream. If no `steer` event for it arrives +within 2 ticks (about 6 min), or `steer-unread` arrives, say so once. + +| The human says (examples) | Comment | Confirm first? | +|---|---|---| +| "pause", "hold off", "stop starting things" | `/pause` | no | +| "carry on", "resume" | `/resume` | no | +| "drop the PyAutoLens one", "forget X" | `/drop ` | no | +| "stop the shift", "kill everything" | `/stop` | **yes**: echo the comment, wait for "yes" (the watcher stops for good until `STOP` is removed by hand) | +| "kill that worker and retry", "restart X" | `/kill ` | **yes**, one line | +| "kill X and don't retry" | `/drop `, then `/kill ` (two comments, in that order) | **yes** | +| "also do ", a pasted task | `/add ` after the premise check below | no | +| "only one more merge", "no more merges" | `/cap merges ` | no | +| "fewer workers", "one worker only" | `/cap workers ` | no | +| "keep it under 400k" | `/cap tokens 400000` | no | +| "merge #347" | not a comment: the `/prm` procedure on that PR, in this chat. If a close-out is `running` on it, say so and ask the human to wait or `/drop` first | /prm's own | +| "put X on the queue", "move X up" | not a shift command: the `/queue` procedure | /queue's own | +| "go through my questions", "answer Q17" | not a shift command: `/questions` (section 6) | n/a | + +- **``** is the task id from the last snapshot + (`/bin/pyauto-brain batch watch --once --record `). "The + PyAutoLens one" is resolved from it. If two match, ask. +- **`/add`**: resolve the paste to a Mind-relative `draft/…/x.md` path. Then run + `/bin/pyauto-brain batch premise ` once in the foreground, and do + not post when it says `obsolete` (say why). The watcher's own gates (cutoff + 30 min before `review-at`, lanes, claims, organ rule) answer in the ack. +- **`/cap`** sets `merges`, `workers`, `sessions` or `tokens` for the rest of + the shift, never above the brief's own value (the watcher refuses that). +- Only the verbs above; the watcher ignores any other first line. + +## 6. Questions + +Parked workers' questions go to the Mind inbox `questions.md`, answered through +`/questions` (Build B), never in this chat's steering. Count the open ones at +attach and at shift end, from Mind `origin/main` (one foreground fetch, then a +local read): + +```bash +git -C fetch -q origin && git -C show origin/main:questions.md +``` + +Count the `### Q` entries under `## Open`. It is a reminder, never a demand. +When the human says "go through my questions" (or "now" at shift end), hand +over to the `/questions` skill. If `questions.md` is not on Mind `origin/main`, +or the `/questions` skill is not installed, say "the questions inbox is not +installed yet; parked questions are in the digest and on the shift issue" and +leave the count out. + +## 7. Answering questions about the shift + +Answer on request only, with reads made in this session: `batch watch --once` +(the snapshot), the status comment (`gh api` read), a PR (`gh pr view`, or +`gh pr checks` once) and `events.jsonl`. Never a polling loop, and never a +second Monitor. + +## Never in the cockpit + +- A Monitor or background command on anything but the stream. A Monitor or + background loop on GitHub (CI, a review, a merge) is refused by the hook: + read CI once and report. +- A merge the human did not command. +- A Mind write outside the `/queue` and `/questions` procedures. +- Arming anything after the shift ends, or re-arming after any exit but + `segment-end`. + +## Without Monitor (web, mobile, Codex) + +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. diff --git a/skills/route/route.md b/skills/route/route.md index 2a79ffbd..69fd88a0 100644 --- a/skills/route/route.md +++ b/skills/route/route.md @@ -23,6 +23,13 @@ title or dashboard 📋 line (`Use the start-dev skill. `) means "add it to `queue.md`": follow [`queue`](../queue/queue.md), never `/start_dev`. Only route a pasted task into development when the human says so in words. +## A cockpit chat is not a dev request + +If `/cockpit` ran earlier in this chat, a pasted prompt, prompt path, task +title or dashboard 📋 line means "`/add` it to the shift": follow +[`cockpit`](../cockpit/cockpit.md), never `/start_dev`. Only route a pasted +task into development when the human says so in words. + ## Classify → dispatch Infer the work-type from the request using the taxonomy in diff --git a/skills/start_dev/SKILL.md b/skills/start_dev/SKILL.md index c22864ec..667baa4c 100644 --- a/skills/start_dev/SKILL.md +++ b/skills/start_dev/SKILL.md @@ -1,6 +1,6 @@ --- name: start-dev -description: Plan and register PyAutoLabs development work, then route it to a library or workspace worktree. Not for questions, reviews, status, explicit workflow opt-outs, or a task pasted into a /queue chat (that means add it to queue.md). +description: Plan and register PyAutoLabs development work, then route it to a library or workspace worktree. Not for questions, reviews, status, explicit workflow opt-outs, a task pasted into a /queue chat (that means add it to queue.md), or one pasted into a /cockpit chat (that means /add it to the shift). --- # Start Dev @@ -10,6 +10,10 @@ description: Plan and register PyAutoLabs development work, then route it to a l or title means "add it to `queue.md`": follow [`../queue/queue.md`](../queue/queue.md) and stop here. +**Not in a cockpit chat.** If `/cockpit` ran earlier in this chat, the same +paste means "`/add` it to the running shift": follow +[`../cockpit/cockpit.md`](../cockpit/cockpit.md) and stop here. + Follow [`start_dev.md`](start_dev.md) in this directory exactly — the authoritative workflow body. `reference.md` holds the long-form templates and the branch survey; shared context and cross-harness notes are in diff --git a/tests/test_cockpit_skill.py b/tests/test_cockpit_skill.py new file mode 100644 index 00000000..93c92cd4 --- /dev/null +++ b/tests/test_cockpit_skill.py @@ -0,0 +1,240 @@ +"""The `/cockpit` skill (PyAutoBrain#646): watch a shift and steer it from chat. + +The witness: the Monitor command the skill tells a session to arm is the +canonical stream command the end-at-deliverable hook allows. It is checked +against the hook's own `STREAM_RE` and fed through the real hook script (this +repo's installed copy, byte-identical to PyAutoMind's canonical file and +drift-checked by `repos_sync.py --check`) with a fictional workspace and shift +record, mid-window. The steering verbs are the watcher's own, and the routers +send a cockpit-chat paste to `/add`, never to start_dev. +""" + +import ast +import json +import os +import re +import shutil +import subprocess +from datetime import datetime, timedelta, timezone +from pathlib import Path + +import pytest + +BRAIN = Path(__file__).resolve().parents[1] +SKILL = BRAIN / "skills" / "cockpit" +HOOK = BRAIN / ".claude" / "hooks" / "end-at-deliverable.sh" +SLOT = "2026-11-16-pm" + + +def _front(path: Path) -> dict: + block = path.read_text().split("---", 2)[1] + return dict(line.split(": ", 1) for line in block.strip().splitlines()) + + +def _procedure() -> str: + return (SKILL / "cockpit.md").read_text() + + +def _template() -> str: + """The one Monitor command line the procedure gives, placeholders and all.""" + lines = [line.strip() for line in _procedure().splitlines() + if "batch watch --stream --record" in line and "--for" in line] + assert len(lines) == 1, lines + return lines[0] + + +def _stream_re(): + """`STREAM_CHARS_RE` and `STREAM_RE`, taken from the hook's own source.""" + text = HOOK.read_text() + start = text.index("STREAM_CHARS_RE = ") + end = text.index("# Anything that reads the watcher's state") + namespace = {"re": re} + exec(text[start:end], namespace) # noqa: S102 — the hook's own regex definitions + return namespace["STREAM_CHARS_RE"], namespace["STREAM_RE"] + + +def _workspace(tmp_path, *, dispatched, review_at): + """A fictional workspace: real Brain resolver, a CLI file, one record.""" + ws = tmp_path / "ws" + for repo in ("PyAutoBrain", "PyAutoMind"): + (ws / repo / ".git").mkdir(parents=True) + (ws / "PyAutoBrain" / "agents").mkdir() + shutil.copy(BRAIN / "agents" / "_repo_paths.py", + ws / "PyAutoBrain" / "agents" / "_repo_paths.py") + (ws / "PyAutoBrain" / "bin").mkdir() + (ws / "PyAutoBrain" / "bin" / "pyauto-brain").write_text("#!/bin/sh\n") + (ws / "PyAutoMind" / "batches").mkdir() + stamp = "%Y-%m-%dT%H:%M:%SZ" + (ws / "PyAutoMind" / "batches" / f"{SLOT}.md").write_text( + f"# Batch {SLOT}\n- dispatched: {dispatched:{stamp}}\n" + f"- review-at: {review_at:{stamp}}\n- brief:\n") + return ws + + +def _command(ws, *, seq="42", first=False): + cmd = _template() + if first: + cmd = cmd.replace(" --from ", "") + return (cmd.replace("", str(ws / "PyAutoBrain")) + .replace("", str(ws / "PyAutoMind")) + .replace("", SLOT).replace("", seq)) + + +def _hook(ws, command): + payload = json.dumps({"tool_name": "Monitor", "tool_input": { + "command": command, "description": f"shift {SLOT} events", + "timeout_ms": 1800000}}) + env = {**os.environ, "PYAUTO_ROOT": str(ws)} + env.pop("PYAUTO_ALLOW_TIMERS", None) + return subprocess.run([str(HOOK)], input=payload, capture_output=True, + text=True, env=env) + + +# -- the contract with the hook ------------------------------------------------ + +def test_the_skill_gives_one_canonical_monitor_command(): + assert _template() == ( + "/bin/pyauto-brain batch watch --stream --record " + "/batches/.md --from --for 28") + proc = _procedure() + assert "timeout_ms: 1800000" in proc + assert "--for 28" in proc # one segment ends before Monitor's 30-minute cap + + +@pytest.mark.parametrize("first", [False, True]) +def test_the_command_matches_the_hooks_stream_re(tmp_path, first): + chars, stream = _stream_re() + now = datetime.now(timezone.utc) + ws = _workspace(tmp_path, dispatched=now - timedelta(hours=1), + review_at=now + timedelta(hours=1)) + cmd = _command(ws, first=first) + assert chars.fullmatch(cmd), cmd + assert stream.fullmatch(cmd), cmd + + +@pytest.mark.parametrize("first", [False, True]) +def test_the_real_hook_allows_the_command_mid_window(tmp_path, first): + now = datetime.now(timezone.utc) + ws = _workspace(tmp_path, dispatched=now - timedelta(hours=1), + review_at=now + timedelta(hours=1)) + result = _hook(ws, _command(ws, first=first)) + assert result.returncode == 0, result.stderr + assert result.stderr == "" + + +def test_the_real_hook_refuses_the_same_command_after_the_window(tmp_path): + """The other half of the carve-out: re-arming after the shift is refused.""" + now = datetime.now(timezone.utc) + review_at = now - timedelta(minutes=46) + ws = _workspace(tmp_path, dispatched=review_at - timedelta(hours=2), + review_at=review_at) + result = _hook(ws, _command(ws)) + assert result.returncode == 2 + assert "outside its window" in result.stderr + + +def test_a_command_with_a_variable_left_in_is_refused(tmp_path): + """The skill says literal text only: the hook refuses `$`.""" + now = datetime.now(timezone.utc) + ws = _workspace(tmp_path, dispatched=now - timedelta(hours=1), + review_at=now + timedelta(hours=1)) + cmd = _command(ws).replace(str(ws / "PyAutoBrain"), "$BRAIN") + assert _hook(ws, cmd).returncode == 2 + assert "No `$VAR`" in _procedure() + + +def test_the_hook_copy_is_the_one_the_harness_runs(): + settings = json.loads((BRAIN / ".claude" / "settings.json").read_text()) + matchers = [g.get("matcher", "") for g in settings["hooks"]["PreToolUse"]] + assert any(re.match(m, "Monitor") for m in matchers if m), matchers + + +# -- re-arm and report --------------------------------------------------------- + +def test_the_only_re_arm_is_at_segment_end(): + proc = _procedure() + assert "segment-end next=--from N" in proc + assert "This is the only re-arm." in proc + assert "Do not arm again." in proc + assert "re-arming after any exit but\n `segment-end`" in proc + + +def test_only_needs_you_lines_are_pushed(): + proc = _procedure() + assert "NEEDS YOU:" in proc and "PushNotification" in proc + assert "Nothing else is pushed." in proc + assert "one plain line per event" in proc + assert "Never add `--json`" in proc + + +# -- steering ------------------------------------------------------------------ + +def _watcher_verbs() -> tuple: + source = (BRAIN / "agents" / "conductors" / "batch" / "_orchestrator.py").read_text() + for node in ast.parse(source).body: + if isinstance(node, ast.Assign) and any( + isinstance(t, ast.Name) and t.id == "COMMANDS" for t in node.targets): + return ast.literal_eval(node.value) + raise AssertionError("no COMMANDS in _orchestrator.py") + + +def test_the_steering_table_covers_exactly_the_watchers_verbs(): + proc = _procedure() + cells = [line.split("|")[2].strip() for line in proc.splitlines() + if line.startswith("| \"")] + # A comment cell starts with the command; "not a comment: the `/prm` …" + # rows route elsewhere and post nothing. + comments = [cell for cell in cells if cell.startswith("`/")] + named = set(re.findall(r"`/([a-z]+)\b", " ".join(comments))) + assert named == set(_watcher_verbs()), named + assert all(cell.startswith("not ") for cell in cells if cell not in comments) + + +@pytest.mark.parametrize("verb", ["/stop", "/kill"]) +def test_stop_and_kill_are_confirmed_first(verb): + rows = [line for line in _procedure().splitlines() + if line.startswith("| \"") and f"`{verb}" in line.split("|")[2]] + assert rows and all("**yes**" in row for row in rows), rows + + +def test_steering_is_one_comment_from_the_humans_login(): + proc = _procedure() + assert "gh issue comment --body-file -" in proc + assert "(said in the cockpit:" in proc + assert "gh api user --jq .login" in proc + assert "batch premise " in proc and "obsolete" in proc + + +# -- questions and routing ------------------------------------------------------- + +def test_questions_go_to_the_questions_skill_and_degrade_without_it(): + proc = _procedure() + assert "`/questions`" in proc + assert "origin/main:questions.md" in proc + assert "the questions inbox is not\ninstalled yet" in proc + + +def test_the_skill_ships_and_says_a_paste_is_an_add(): + front = _front(SKILL / "SKILL.md") + assert front["name"] == "cockpit" + assert re.fullmatch(r"[a-z0-9-]+", front["name"]) + assert "never start dev" in front["description"] + assert "It never means start dev" in (SKILL / "SKILL.md").read_text() + + +def test_the_routers_send_a_cockpit_chat_paste_to_add_not_start_dev(): + commands = (BRAIN / "skills" / "COMMANDS.md").read_text() + assert "**`/cockpit`**" in commands and "never start dev" in commands + route = (BRAIN / "skills" / "route" / "route.md").read_text() + assert "A cockpit chat is not a dev request" in route + assert "../cockpit/cockpit.md" in route + start = BRAIN / "skills" / "start_dev" / "SKILL.md" + assert "/cockpit chat" in _front(start)["description"] + assert "../cockpit/cockpit.md" in start.read_text() + + +def test_the_skill_is_discoverable(): + """Committed discovery, as `install.sh --write-project-discovery` makes it.""" + assert (BRAIN / ".claude" / "skills" / "cockpit").resolve() == SKILL + assert (BRAIN / ".codex" / "skills" / "cockpit").resolve() == SKILL + assert (BRAIN / ".claude" / "commands" / "cockpit.md").read_text() == _procedure() From a0891b739d3bfdb392e4317f5145ceb1de569b7a Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 16 Nov 2026 14:34:45 +0000 Subject: [PATCH 2/2] =?UTF-8?q?fix(cockpit):=20review=20findings=20?= =?UTF-8?q?=E2=80=94=20attach=20only=20when=20asked,=20confirmed=20caps,?= =?UTF-8?q?=20honest=20/stop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review of f724d53 (#646): - A question about the shift ("what's the shift doing?") gets a one-shot `batch watch --once` read, never a Monitor; the watch is armed only on an explicit request (policy condition 1). Dropped from the triggers. - /cap: merge-cap counts the whole shift, so "one more merge" is merged + running + 1 read from the snapshot first; every /cap is confirmed with its number; "fewer workers" asks for one. Unclear wording means ask, never a guessed verb, task or number. - "kill everything" -> /stop is confirmed as "stops new work; running workers continue", then each running worker's /kill is offered as its own confirmed comment. - "Stop watching" stops the Monitor with TaskStop and leaves the shift be. - route and start_dev: when both /queue and /cockpit ran in a chat, a paste is asked about. The procedure is trimmed to stay within the 200-line budget. Co-Authored-By: Claude Opus 5.5 --- skills/cockpit/SKILL.md | 6 ++-- skills/cockpit/cockpit.md | 69 ++++++++++++++++++++++--------------- skills/route/route.md | 4 ++- skills/start_dev/SKILL.md | 4 ++- tests/test_cockpit_skill.py | 55 +++++++++++++++++++++++++++-- 5 files changed, 103 insertions(+), 35 deletions(-) diff --git a/skills/cockpit/SKILL.md b/skills/cockpit/SKILL.md index 79064e9f..fe4a19cd 100644 --- a/skills/cockpit/SKILL.md +++ b/skills/cockpit/SKILL.md @@ -1,6 +1,6 @@ --- name: cockpit -description: Watch a running shift from chat (/cockpit, "watch the shift", "what's the shift doing") — stream its events with Monitor and steer it by comments on the shift issue. 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 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. --- # Cockpit @@ -8,7 +8,9 @@ description: Watch a running shift from chat (/cockpit, "watch the shift", "what Follow [`cockpit.md`](cockpit.md) exactly. This is the one skill allowed to hold a watch past its turn, and only the shift's own event stream inside its window (PyAutoMind `policy/shift_cockpit_watch.md`, enforced by the end-at-deliverable -hook). Once `/cockpit` has run in a chat, that chat is a **cockpit chat** until +hook), and only when the human asks for a watch: a question such as "what's +the shift doing?" gets a one-shot `batch watch --once` answer, never a +Monitor. Once `/cockpit` has run in a chat, that chat is a **cockpit chat** until the shift ends: anything pasted that names a task (a prompt, a `draft/` path, a title, or the dashboard's 📋 line `Use the start-dev skill. `) means **`/add` it to this shift**. It never means start dev, plan, intake or build. diff --git a/skills/cockpit/cockpit.md b/skills/cockpit/cockpit.md index 1484421f..ae4c2156 100644 --- a/skills/cockpit/cockpit.md +++ b/skills/cockpit/cockpit.md @@ -1,19 +1,24 @@ # /cockpit — watch a shift and steer it from chat -The shift watcher (a timer, not a session) is the engine. It writes one line per -event to the shift's `events.jsonl`, and `pyauto-brain batch watch --stream` -prints them (PyAutoBrain#644). This chat only reads that stream and posts -steering comments on the shift issue, which the watcher reads on its next tick -(about 3 minutes). Closing the chat changes nothing about the shift. - +The shift watcher (a timer, not a session) writes each event to the shift's +`events.jsonl`; `pyauto-brain batch watch --stream` prints them (#644). This +chat reads that stream and steers only by comments on the shift issue, which +the watcher reads each tick (about 3 min); closing the chat changes nothing. The watch is the one carve-out from "sessions end at their deliverable" -(PyAutoMind `policy/shift_cockpit_watch.md`). The end-at-deliverable hook -enforces it: it lets through only the canonical stream command below, inside -the shift's window. If the hook refuses a Monitor, relay its reason in one line -and stop. Never retry it in another form. +(PyAutoMind `policy/shift_cockpit_watch.md`); the hook lets through only the +canonical command below, inside the window. If it refuses a Monitor, relay +its reason in one line and stop. Never retry it in another form. 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. + ## The rule of this chat After `/cockpit`, a pasted task is an **add to this shift**. That covers a whole @@ -104,13 +109,14 @@ within 2 ticks (about 6 min), or `steer-unread` arrives, say so once. | "pause", "hold off", "stop starting things" | `/pause` | no | | "carry on", "resume" | `/resume` | no | | "drop the PyAutoLens one", "forget X" | `/drop ` | no | -| "stop the shift", "kill everything" | `/stop` | **yes**: echo the comment, wait for "yes" (the watcher stops for good until `STOP` is removed by hand) | +| "stop the shift", "kill everything" | `/stop` | **yes**: "This stops new work; running workers continue — kill each with /kill ?" Post `/stop` on "yes" (the watcher stops for good until `STOP` is removed by hand). Then offer each running worker's `/kill ` as its own confirmed comment | | "kill that worker and retry", "restart X" | `/kill ` | **yes**, one line | | "kill X and don't retry" | `/drop `, then `/kill ` (two comments, in that order) | **yes** | | "also do ", a pasted task | `/add ` after the premise check below | no | -| "only one more merge", "no more merges" | `/cap merges ` | no | -| "fewer workers", "one worker only" | `/cap workers ` | no | -| "keep it under 400k" | `/cap tokens 400000` | no | +| "only one more merge", "no more merges" | `/cap merges `, n as below | **yes**, with n shown | +| "one worker only" (a number) | `/cap workers ` | **yes**, with n shown | +| "fewer workers" (no number) | nothing yet: ask "how many workers at most?" | ask | +| "keep it under 400k" | `/cap tokens 400000` | **yes**, with n shown | | "merge #347" | not a comment: the `/prm` procedure on that PR, in this chat. If a close-out is `running` on it, say so and ask the human to wait or `/drop` first | /prm's own | | "put X on the queue", "move X up" | not a shift command: the `/queue` procedure | /queue's own | | "go through my questions", "answer Q17" | not a shift command: `/questions` (section 6) | n/a | @@ -124,25 +130,32 @@ within 2 ticks (about 6 min), or `steer-unread` arrives, say so once. 30 min before `review-at`, lanes, claims, organ rule) answer in the ack. - **`/cap`** sets `merges`, `workers`, `sessions` or `tokens` for the rest of the shift, never above the brief's own value (the watcher refuses that). + `merges` counts the **whole shift**, not merges from now on: read merged + and running close-outs from `batch watch --once` first, then "one more + merge" is n = merged + running + 1, and "no more merges" is + n = merged + running. Confirm every `/cap` in one line with the number, + e.g. "Post `/cap merges 3` (2 merged, 0 running, so one more)?" +- **Unclear wording: ask.** Never guess a verb, a task or a number. One short + question, then post on the answer. - Only the verbs above; the watcher ignores any other first line. -## 6. Questions +## Stop watching -Parked workers' questions go to the Mind inbox `questions.md`, answered through -`/questions` (Build B), never in this chat's steering. Count the open ones at -attach and at shift end, from Mind `origin/main` (one foreground fetch, then a -local read): +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. -```bash -git -C fetch -q origin && git -C show origin/main:questions.md -``` +## 6. Questions -Count the `### Q` entries under `## Open`. It is a reminder, never a demand. -When the human says "go through my questions" (or "now" at shift end), hand -over to the `/questions` skill. If `questions.md` is not on Mind `origin/main`, -or the `/questions` skill is not installed, say "the questions inbox is not -installed yet; parked questions are in the digest and on the shift issue" and -leave the count out. +Parked workers' questions go to the Mind inbox `questions.md`, answered through +`/questions`, never by steering. At attach and at shift end, after one +foreground `git -C fetch -q origin`, count the `### Q` entries under +`## Open` in `git -C show origin/main:questions.md`: a reminder, never a +demand. "Go through my questions" (or "now" at shift end) hands over to +`/questions`. If `questions.md` is not on Mind `origin/main`, or the +`/questions` skill is not installed, say "the questions inbox is not installed +yet; parked questions are in the digest and on the shift issue" and leave the +count out. ## 7. Answering questions about the shift diff --git a/skills/route/route.md b/skills/route/route.md index 69fd88a0..0e7add3f 100644 --- a/skills/route/route.md +++ b/skills/route/route.md @@ -28,7 +28,9 @@ route a pasted task into development when the human says so in words. If `/cockpit` ran earlier in this chat, a pasted prompt, prompt path, task title or dashboard 📋 line means "`/add` it to the shift": follow [`cockpit`](../cockpit/cockpit.md), never `/start_dev`. Only route a pasted -task into development when the human says so in words. +task into development when the human says so in words. If both `/queue` and +`/cockpit` ran in this chat, ask which one the paste is for: the queue or this +shift. ## Classify → dispatch diff --git a/skills/start_dev/SKILL.md b/skills/start_dev/SKILL.md index 667baa4c..a0ca1c05 100644 --- a/skills/start_dev/SKILL.md +++ b/skills/start_dev/SKILL.md @@ -12,7 +12,9 @@ and stop here. **Not in a cockpit chat.** If `/cockpit` ran earlier in this chat, the same paste means "`/add` it to the running shift": follow -[`../cockpit/cockpit.md`](../cockpit/cockpit.md) and stop here. +[`../cockpit/cockpit.md`](../cockpit/cockpit.md) and stop here. If both +`/queue` and `/cockpit` ran in this chat, ask whether the paste is for the +queue or the shift, and stop here. Follow [`start_dev.md`](start_dev.md) in this directory exactly — the authoritative workflow body. `reference.md` holds the long-form templates and diff --git a/tests/test_cockpit_skill.py b/tests/test_cockpit_skill.py index 93c92cd4..5c2da419 100644 --- a/tests/test_cockpit_skill.py +++ b/tests/test_cockpit_skill.py @@ -156,7 +156,7 @@ def test_the_only_re_arm_is_at_segment_end(): assert "segment-end next=--from N" in proc assert "This is the only re-arm." in proc assert "Do not arm again." in proc - assert "re-arming after any exit but\n `segment-end`" in proc + assert "re-arming after any exit but `segment-end`" in " ".join(proc.split()) def test_only_needs_you_lines_are_pushed(): @@ -187,7 +187,9 @@ def test_the_steering_table_covers_exactly_the_watchers_verbs(): comments = [cell for cell in cells if cell.startswith("`/")] named = set(re.findall(r"`/([a-z]+)\b", " ".join(comments))) assert named == set(_watcher_verbs()), named - assert all(cell.startswith("not ") for cell in cells if cell not in comments) + # The rest route elsewhere ("not a comment: …") or ask first ("nothing yet: ask"). + assert all(cell.startswith(("not ", "nothing yet: ask")) for cell in cells + if cell not in comments) @pytest.mark.parametrize("verb", ["/stop", "/kill"]) @@ -211,7 +213,7 @@ def test_questions_go_to_the_questions_skill_and_degrade_without_it(): proc = _procedure() assert "`/questions`" in proc assert "origin/main:questions.md" in proc - assert "the questions inbox is not\ninstalled yet" in proc + assert "the questions inbox is not installed yet" in " ".join(proc.split()) def test_the_skill_ships_and_says_a_paste_is_an_add(): @@ -238,3 +240,50 @@ def test_the_skill_is_discoverable(): assert (BRAIN / ".claude" / "skills" / "cockpit").resolve() == SKILL assert (BRAIN / ".codex" / "skills" / "cockpit").resolve() == SKILL assert (BRAIN / ".claude" / "commands" / "cockpit.md").read_text() == _procedure() + + +# -- review findings (attach only when asked; /cap, /stop; stop watching) ----- + +def test_a_question_gets_a_one_shot_read_not_a_watch(): + front = _front(SKILL / "SKILL.md") + assert "what's the shift doing" not in front["description"] + assert "never a watch" in front["description"] + proc = _procedure() + assert "## Attach only when asked" in proc + assert proc.index("## Attach only when asked") < proc.index("## 3. Attach") + assert "with no Monitor" in proc + + +@pytest.mark.parametrize("verb", ["/cap merges", "/cap workers", "/cap tokens"]) +def test_every_cap_is_confirmed_with_its_number(verb): + rows = [line for line in _procedure().splitlines() + if line.startswith("| \"") and f"`{verb}" in line.split("|")[2]] + assert rows and all("**yes**, with n shown" in row for row in rows), rows + + +def test_the_merge_cap_counts_the_whole_shift(): + proc = _procedure() + assert "n = merged + running + 1" in proc + assert "counts the **whole shift**" in proc + assert "\"fewer workers\" (no number) | nothing yet: ask" in proc + assert "Never guess a verb, a task or a number." in proc + + +def test_stop_says_running_workers_continue_and_offers_kills(): + row = next(line for line in _procedure().splitlines() + if line.startswith("| \"stop the shift\"")) + assert "running workers continue" in row + assert "/kill " in row and "own confirmed comment" in row + + +def test_stop_watching_stops_the_monitor_only(): + proc = _procedure() + assert "## Stop watching" in proc and "`TaskStop`" in proc + assert "the shift carries on" in proc + + +def test_a_paste_in_a_queue_and_cockpit_chat_is_asked_about(): + route = (BRAIN / "skills" / "route" / "route.md").read_text() + start = (BRAIN / "skills" / "start_dev" / "SKILL.md").read_text() + assert "If both `/queue` and\n`/cockpit` ran in this chat, ask" in route + assert "If both\n`/queue` and `/cockpit` ran in this chat, ask" in start