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 afdf83d3..352d4d7b 100644 --- a/skills/COMMANDS.md +++ b/skills/COMMANDS.md @@ -123,6 +123,18 @@ call, so the Brain is not bypassed): `origin/main`, committed with `prompt_sync_push`, then `lifecycle.py check`, 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` + 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`. When more than one of `/queue`, `/questions` + and `/cockpit` ran in one chat, a paste is asked about, never guessed. + - **`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..fe4a19cd --- /dev/null +++ b/skills/cockpit/SKILL.md @@ -0,0 +1,18 @@ +--- +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. +--- + +# 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), 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. +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..c1df0472 --- /dev/null +++ b/skills/cockpit/cockpit.md @@ -0,0 +1,182 @@ +# /cockpit — watch a shift and steer it from chat + +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 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 +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 `/queue` +or `/questions` also ran in this chat, ask which one the paste is for. To start +a task outside 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**: "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 `, 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 | + +- **``** 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). + `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. + +## 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. + +## 6. Questions + +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 + +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/questions/questions.md b/skills/questions/questions.md index 80775e92..7ec94c8f 100644 --- a/skills/questions/questions.md +++ b/skills/questions/questions.md @@ -20,6 +20,7 @@ It is never a start-dev, `/route`, intake, plan or build request, even when the human's answer names work to do. An answered task resumes in the **next** shift (a shift already running has counted it), or in a session if the human says "start it now" in words. +If `/queue` or `/cockpit` also ran in this chat, ask which one a paste is for. ## Verbs diff --git a/skills/queue/queue.md b/skills/queue/queue.md index d0780eef..c546c7d4 100644 --- a/skills/queue/queue.md +++ b/skills/queue/queue.md @@ -15,6 +15,7 @@ prompt path or GitHub link, a task title, or a dashboard 📋 line such as `/route`, intake, plan or build request. Do not read the prompt to plan it, and do not offer to start it. If the human clearly wants to leave queue mode ("start this one now"), confirm that in one line, then route normally. +If `/questions` or `/cockpit` also ran in this chat, ask which one a paste is for. ## Verbs (plain words map onto these) diff --git a/skills/route/route.md b/skills/route/route.md index 73003974..5653ab62 100644 --- a/skills/route/route.md +++ b/skills/route/route.md @@ -26,6 +26,16 @@ The same holds in a chat that ran `/questions`: a pasted `Use the questions skill. Q17` line or an answer that names work means "record it in `questions.md`": follow [`questions`](../questions/questions.md), never `/start_dev`. +## 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. + +If two or more of `/queue`, `/questions` and `/cockpit` ran in this chat, ask +which one a paste is for (the queue, the inbox or the shift). Never guess. + ## 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 9351ed95..9682fe57 100644 --- a/skills/start_dev/SKILL.md +++ b/skills/start_dev/SKILL.md @@ -1,16 +1,20 @@ --- 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, a task pasted into a /queue chat (that means add it to queue.md), or an answer or pasted question line in a /questions chat (that means record it in questions.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), an answer or pasted question line in a /questions chat (that means record it in questions.md), or a task pasted into a /cockpit chat (that means /add it to the shift). --- # Start Dev -**Not in a queue chat.** If `/queue` ran earlier in this chat, a pasted -`Use the start-dev skill. ` line (the dashboard's 📋 text), prompt, path -or title means "add it to `queue.md`": follow [`../queue/queue.md`](../queue/queue.md) -and stop here. Likewise in a `/questions` chat: an answer or a pasted -`Use the questions skill. Q` line is recorded through [`../questions/questions.md`](../questions/questions.md), -never started. +**Not in a queue, questions or cockpit chat.** If `/queue` ran earlier in this +chat, a pasted `Use the start-dev skill. ` line (the dashboard's 📋 text), +prompt, path or title means "add it to `queue.md`": follow +[`../queue/queue.md`](../queue/queue.md). In a `/questions` chat, an answer or a +pasted `Use the questions skill. Q` line is recorded through +[`../questions/questions.md`](../questions/questions.md), never started. In a +`/cockpit` chat, a paste means "`/add` it to the running shift": follow +[`../cockpit/cockpit.md`](../cockpit/cockpit.md). If two or more of `/queue`, +`/questions` and `/cockpit` ran in this chat, ask which one the paste is for. +Each way, 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 new file mode 100644 index 00000000..eacf16f3 --- /dev/null +++ b/tests/test_cockpit_skill.py @@ -0,0 +1,293 @@ +"""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 `segment-end`" in " ".join(proc.split()) + + +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 + # 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"]) +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 installed yet" in " ".join(proc.split()) + + +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() + + +# -- 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() + flat = lambda text: " ".join(text.split()) # noqa: E731 + rule = "two or more of `/queue`, `/questions` and `/cockpit` ran in this chat, ask" + assert rule in flat(route) and rule in flat(start) + assert "`/questions` also ran in this chat, ask" in flat(_procedure()) + assert "a paste is asked about, never guessed" in flat( + (BRAIN / "skills" / "COMMANDS.md").read_text())