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
21 changes: 17 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ name: Brain Tests
# PRs on drift Brain cannot cause; organs not checked out (Heart, Hands) are
# skipped by the check itself, so this gates exactly Brain.
#
# TWO repos are checked out on purpose. PyAutoBrain alone cannot even COLLECT
# THREE repos are checked out on purpose. PyAutoBrain alone cannot even COLLECT
# the suite: `agents/faculties/sizing/_sizing.py` reads the body map
# (`BRAIN_HOME.parent / "PyAutoMind" / "repos.yaml"`) at import time and is
# deliberately strict, so `test_policy_seams.py` and `test_sizing_paths.py`
# error out before a single test runs. Checking PyAutoMind out as a sibling
# reproduces the workspace layout the code assumes — the same layout the
# firewall gate's `--root` needs. Both repos are public, so the default
# GITHUB_TOKEN suffices — no PAT. No other sibling repo is needed (verified by
# running the suite against exactly this two-repo layout).
# firewall gate's `--root` needs. PyAutoCortex is the third: the cortex
# conductor imports the Cortex's own `scripts/cortex.py` at runtime and its
# tests render the board against that repo's `tests/fixtures/skeleton`, the
# fixture that IS the schema's witness — a copied fixture here would drift
# from the schema it claims to test (the tests skip cleanly when the checkout
# is absent, so a local run without it still passes). All three repos are
# public, so the default GITHUB_TOKEN suffices — no PAT. No other sibling repo
# is needed (verified by running the suite against exactly this layout).

# One run per commit: PR events carry the CI; pushes only build main.
# Superseded runs are cancelled on PR refs only — a cancelled main run would
Expand Down Expand Up @@ -60,6 +65,14 @@ jobs:
with:
repository: PyAutoLabs/PyAutoMind
path: PyAutoMind
# The science organ the cortex conductor reasons over: its
# `scripts/cortex.py` is the schema API and its skeleton fixture is
# what `test_cortex_conductor.py` renders.
- name: Checkout PyAutoCortex (the Cortex schema + fixture)
uses: actions/checkout@v4
with:
repository: PyAutoLabs/PyAutoCortex
path: PyAutoCortex
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ the `/<verb>` slash commands.
| `workspace` | The voice — the organism's expressive function: plan/survey workspace + HowTo example authorship (workspace\|howto registers) — WorkspaceDecision (never writes) | `bin/pyauto-brain workspace` |
| `eyes` | The perceptive function — the organism's sense of its own appearance: survey/review a visualization workspace's figure surface, critiques route to intake/start_dev — EyesSurvey/EyesReviewSurface (never renders, never edits) | `bin/pyauto-brain eyes` |
| `profiling` | The proprioceptive function — the organism's sense of its own effort: campaign/ingest/triage plans over the autolens_profiling workspace — ProfilingDecision | `bin/pyauto-brain profiling` |
| `cortex` | The learning function — where the organism finds out what is true: reason over PyAutoCortex (phases, gates, rulings), render its board, grade the gates, admit ready phases into a slot — never submits a run, never writes a ruling | `bin/pyauto-brain cortex` |
| `hygiene` | The maintenance function — the organism's sense of its own upkeep: code-quality debt (dev-loop cost + tidiness), delegating fixes — HygieneDecision | `bin/pyauto-brain hygiene` |
| `clone` | The Mitosis Agent: partition the reference assistant, analyze the domain, emit the CloneDecision; --apply --mode lightweight-seed delegates the seed birth to Build; 'clone sync' patches the reference's generic-file diff onto the born siblings (dry run by default; rejected hunks are a human decision) | `bin/pyauto-brain clone` |
| `build` | Coordinate execution: consult the vitals faculty, then delegate to PyAutoHands | `bin/pyauto-brain build` |
Expand Down
5 changes: 5 additions & 0 deletions agents/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ _resolve_dir() {
# resolve_mind — locate the PyAutoMind checkout (the organism's intent store).
resolve_mind() { _resolve_dir PYAUTO_MIND PyAutoMind; }

# resolve_cortex — locate the PyAutoCortex checkout (the organism's science
# state: phases, gates, runs, rulings of record). Resolved independently of the
# Mind so a session holding one organ and not the other still works.
resolve_cortex() { _resolve_dir PYAUTO_CORTEX PyAutoCortex; }

# resolve_memory — locate the PyAutoMemory checkout (the organism's long-term
# scientific/architectural knowledge). Optional: the Feature Agent degrades
# gracefully when memory is absent rather than inventing context.
Expand Down
131 changes: 131 additions & 0 deletions agents/conductors/cortex/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Cortex agent

> **Tier: conductor** — a front-door agent you *drive*. The *learning
> function* — where the organism finds out what is true: it reasons over
> PyAutoCortex (the science body map, the pre-registered phases, the rulings
> of record), renders the Cortex board, grades the gates and admits ready
> phases into a laptop slot. It **never submits a run and never writes a
> ruling**: the run is the human's act, the verdict is the human's word, and
> the ruling file is the Cortex script's to write.

The same split the organism already uses twice — **Heart ↔ vitals**, **Gut ↔
hygiene**: the organ keeps the state, the conductor reasons over it. The
Cortex holds runs and rulings the way the Mind holds prompts and PRs; this is
the Cortex's intake-and-dashboard conductor.

## Verbs

| Verb | Question | Emits |
|------|----------|-------|
| `census` | What is the Cortex holding? | phase counts by state, the board's section counts, rulings, projects, batches, epics (`--json` for the lot) |
| `dashboard --check` | Are the committed pages current? | exit 0 current · **1 stale** · 2 no checkout · 3 unreadable tree |
| `dashboard --apply` | — | writes `dashboard.md` + `dashboard.html` |
| `gates [--grade] [--apply]` | What is each gated phase waiting on, and has it cleared? | the refs, a verdict per phase, and with `--apply` the `gated → ready` flips |
| `plan [--budget N]` | Which ready phases fit the slot? | `== CortexPlan ==` — members against the review-minute budget, plus the launch lines |
| `collect [--slot S] [--pull] [--refreshed ISO] [--apply] [--out F] [--phase REL]` | What did the pull bring back, and is it worth reviewing? | one packet member block per live member — six scored legs, the readout, a blank ruling line — and exit **1** when any member is not HEALTHY |

```
pyauto-brain cortex # census
pyauto-brain cortex dashboard --apply
pyauto-brain cortex gates --grade
pyauto-brain cortex plan --budget 30
pyauto-brain cortex collect --pull --apply # score the board, then move it on
pyauto-brain cortex <verb> --cortex <dir> # another checkout
```

## Where the Cortex is

`--cortex <dir>` → `$PYAUTO_CORTEX` → beside this PyAutoBrain checkout →
`$PYAUTO_ROOT/PyAutoCortex`. Its own resolver (`resolve_cortex` in
`agents/_common.sh`, mirrored in `_cortex.py`), never an extension of the
Mind's: a session holding one organ and not the other still works.

## What it reads, and what it refuses to read

- `<cortex_root>/scripts/cortex.py` is imported at runtime and is the schema
API: `load_phases`, `load_rulings`, `load_projects`, `gates_report`,
`batch_records`, `move_phase`. The conductor always reasons with the schema
the checkout it is pointed at implements.
- **Stdlib only, and Mind-free.** The renderer runs bare inside the Cortex's
own `dashboard_refresh.yml`, which installs nothing and checks out no
PyAutoMind — so `_cortex.py` imports neither `_sizing` nor `_intake` (both
hard-fail without a Mind checkout). The Mind's renderer helpers are copied,
not imported; that duplication is the price of a one-repo render.
- **No path is named in this code.** Science projects live outside the
workspace; the one place carrying such a path is the Cortex's own
`projects.yaml`, and every path the board prints is read from a row of it.

## The board

Sections, in the reading order of a slot: **Awaiting ruling** (pulled and
awaiting-ruling phases, ordered failures → a ruling is required → clean) →
**Running / submitted** (job ids, wall against the phase's budget, the last
`refreshed:` line) → **Ready** → **Gated** (the open refs) → **Recent
rulings** → **Epics** (each card links its Mind half) → **Projects** (the
where-to-look table straight from `projects.yaml`). A counts table near the
top is what `board/_board.py` reads for the Brain board's Cortex strip.

`--check` compares the pages with the generation comment **and** the visible
`Last updated` banner stripped, so a re-render on a new date is not drift —
the Mind's normaliser strips only the comment, which is why its refresh
workflow self-heals with an empty commit most nights.

## The admission rule (`plan`)

A phase is plannable when its `State:` is `ready`, its `Witness:` is
registered, its `Budget:` is set and its lane is the session's — detected the
way the batch conductor detects it (`gh` on PATH ⇒ `local-dev`). Cheapest
first against `--budget` (default 45 review-minutes). **No autonomy cap is
consulted**: science members are supervised by definition, and the ruling is
the human's. A cloud session reports the ready count and plans nothing — a
science run is launched from the machine that can reach the queue.

## Gate grading

`gates --grade [--apply]` is a thin wrapper over the Cortex script's own
`gates_report(root, grade=…, write=…)`. The grading rule (a PR clears when it
merged; an issue when it closed as `completed`; anything unreadable fails
closed) and the writes live there, so the Cortex's daily `gates_grade.yml`
runs them with no Brain checkout at all. `--apply` is this surface's spelling
of the script's `--write`, and it may only ever move `gated → ready` (and
demote a `ready` phase whose gate reopened).

## Scoring a pull (`collect`)

The board is rolling: a member joins the review on the pull that fills its
results in. `collect` scores every member whose phase is `submitted` or
`running` (or the phases named by `--phase`) against **six legs**, each
`PASS | FAIL | UNOBSERVABLE`:

| Leg | Read from |
|-----|-----------|
| `err` | every `error.<jobid>*.err` under the roots. Benign = every non-blank line is a `*Warning*` line or its indented continuation — **not** size 0; `Traceback`/`Error`/`Killed`/`OOM` ⇒ FAIL |
| `wall` | the `.out`'s first and last date stamps when it ends `Finished.`, else `Time To Run` in `search.summary` — **from the `<hash>.zip` when there is one**, because an extracted run dir can be a stale partial. Over `Budget:` ⇒ FAIL |
| `version` | a top-level `version` key in a JSON matching the project's `witness_file` |
| `checkpoint` | `<root>/.cortex/pull.json` only (`{"pulled_at": ISO, "runs": {"<jobid>": {"checkpoint_bytes": N, "checkpoint_mtime": ISO}}}`) — `search_internal/checkpoint.hdf5` is never pulled, so without that manifest the leg is UNOBSERVABLE, tagged `RAL only` |
| `resume` | `Fit Already Completed` / `Resuming … previous samples found` in the `.out` ⇒ FAIL: those are the previous fit's numbers |
| `witness` | a file matching `witness_file` newer than the phase's first submission |

HEALTH is **FAILED** if any leg failed, **SUSPECT** if any is unobservable,
**HEALTHY** otherwise; `delivered:` counts the HEALTHY ones. Two of the four
`delivered:` legs of `batches/AGENTS.md` are simply not visible on the laptop
today — inventing PASS for them would be inventing evidence and FAIL would
condemn every healthy run, so they are UNOBSERVABLE and the member goes to the
human as SUSPECT.

Everything is read from the laptop tree the human's own sync CLI filled; the
search roots are the project's `mirror` then `local_path`, from
`projects.yaml`. **The only thing that reaches the cluster is `--pull`**, which
runs that project's own `<sync_cli> pull` and prints the command first.
`--apply` (which needs a refresh stamp, from `--pull` or `--refreshed <ISO>`)
moves each member `running → pulled → awaiting-ruling`, appends one
`- refreshed:` line per member and rewrites the member's `<state>` — rehearsed
on a throwaway copy of the tree first and refused outright if
`cortex.py check` would not pass afterwards. A phase whose run line is still
live, or one still `submitted` (no such edge), is left where it is with a note.

## What it never does

Submits a job · writes or edits a ruling · reads `sacct` as health · touches
RAL · consults an autonomy cap · edits a phase except through the Cortex
script's own `move`.
Loading
Loading