Skip to content

[Agents] Replace autoreview skill and fix quality findings - #177

Merged
arnodelorme merged 10 commits into
developfrom
autoreview-loop-skill
Jun 12, 2026
Merged

arnodelorme merged 10 commits into
developfrom
autoreview-loop-skill

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

Replace the broken autoreview skill with the strict thermo-nuclear code-quality review workflow, and fix the quality issues found while applying it. Centralizes GUI/console session updates, fixes MNE conversion invariants and temp-file cleanup, and adds focused regression tests.

Fixes #178
Fixes #179
Fixes #180
Fixes #181
Fixes #182
Fixes #183

@claude

claude Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 3m 30s —— View job


Code review

This PR's own commits (on top of the stacked #174/#176) touch only the oc-autoreview-adapted skill tooling — 7 files, ~1.4k lines: SKILL.md, agents/openai.yaml, the autoreview script, new-review-campaign.py, and the test-review-harness (.py + new .ps1). No src/eegprep runtime code changes, so there's no EEGLAB parity, EEG data-structure, or GUI/console-sync surface to regress here.

Blocking

None.

Important

None.

Nits

  • run_droid leaks the temp prompt-file handle — scripts/autoreview:751
    prompt_path = Path(tempfile.NamedTemporaryFile("w", suffix=".txt", delete=False).name)
    prompt_path.write_text(prompt)
    The NamedTemporaryFile object is discarded with its handle still open (same pre-existing pattern as run_codex:691). On POSIX this is harmless; since this PR newly adds a PowerShell harness implying Windows use, the lingering open handle could intermittently interfere with the immediate write_text. Low confidence it actually breaks, but cheap to make robust:
    with tempfile.NamedTemporaryFile("w", suffix=".txt", delete=False) as handle:
        handle.write(prompt)
    prompt_path = Path(handle.name)
    Fix this →

Test gaps

None. The behavioral surface here is the test-review-harness itself (buggy/benign fixtures + --require-finding channel --expect-findings), which exercises the helper end-to-end; no additional eegprep test coverage is warranted for tooling-only changes.

EEGLAB parity notes

None applicable — no runtime/package code changed. The review prompt embedded in build_prompt correctly encodes EEGPrep parity priorities (EEG dict fields, channel-major shape, 1-based indexing, pop_*/return_com/(EEG, com) contracts, runtime independence from src/eegprep/eeglab), and CODEBASE_EXCLUDED_PREFIXES properly excludes vendored EEGLAB and sample_data/ from codebase audits.

Things checked and verified correct

  • choose_target / main target dispatch: changed_paths is always assigned across local/branch/codebase/commit paths before use.
  • path_matches_scope handles directory prefixes, exact paths, and globs (fnmatch); SKILL.md correctly tells users to quote glob --path values so the shell doesn't expand them.
  • validate_report out-of-scope filtering: drops findings outside changed_paths and downgrades patch is incorrect→correct only when no in-scope findings remain — sound.
  • run_with_heartbeat non-stream loop re-calls communicate(input=None, timeout=...) after TimeoutExpired without killing the child — the documented pattern; self._input offset is preserved so stdin is not re-sent or truncated.
  • new-review-campaign.py uses shlex.quote on packet paths and write_new guards against clobbering existing campaign files; the .gitignore .workflow/ addition matches the default --root.
  • SKILL.md command examples (--mode uncommitted alias, --model codex=gpt-5.1, --thinking codex=xhigh, --path/--scope-file) all match the implemented argparse surface.
    • autoreview-loop-skill

@suraj-ranganath

suraj-ranganath commented Jun 9, 2026 •

Copy link
Copy Markdown
Member Author

Problem

The oc-autoreview-adapted skill and campaign loop did not work well enough for EEGPrep. In practice, the subagent autoreview loop ran for too long and produced no usable findings, fixes, commits, or packet PRs. At the same time, EEGPrep still needs a high-bar maintainability review skill that helps agents catch structural regressions, wrong ownership layers, and code that technically works but makes the project harder to ship.

Approach

Remove the full .agents/skills/oc-autoreview-adapted skill directory, including helper scripts, harnesses, metadata, and campaign scaffolding. Add .agents/skills/thermo-nuclear-code-quality-review as a lightweight review playbook adapted from Cursor's MIT-licensed thermo-nuclear code quality review concept. The new skill is EEGPrep-specific: it emphasizes AGENTS.md, EEGLAB parity, GUI/console session contracts, EEG dict invariants, canonical package ownership, and concrete structural failure modes. No EEGPrep runtime code is changed.

Key code

The new skill defines the review contract, review bar, EEGPrep architecture boundaries, aggressive-but-actionable findings, preferred remedies, and output order. It intentionally has no long-running automation script or subagent loop.

Tests

Ran ./pre-commit.py --changed-from origin/feature/eegprep-agent-cli, which passed. Ran git diff --check and a direct skill-shape check for frontmatter, trailing newlines, and tab-free files. Since this PR changes only agent skill files and .gitignore cleanup, no pytest suite was needed.

Stacking

This PR targets develop but is stacked on #174 and #176. Reviewers should not merge this before the earlier stacked PRs land.

@suraj-ranganath suraj-ranganath changed the title [Agents] Improve autoreview loop skill [Agents] Remove broken autoreview skill Jun 10, 2026
@suraj-ranganath suraj-ranganath changed the title [Agents] Remove broken autoreview skill [Agents] Replace broken autoreview skill Jun 10, 2026
@suraj-ranganath suraj-ranganath changed the title [Agents] Replace broken autoreview skill [Agents] Replace autoreview skill and fix quality findings Jun 11, 2026
@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Claude PR comparison update:

Reviewed #184-#188 against this PR. #184 and #186 were strict subsets of the current branch. #185 used MNE get_components() as an ICA mixing shortcut, but this PR keeps the stronger EEGPrep invariant: icaact is produced from the stored icaweights @ icasphere unmixing transform. From #187, I folded in the useful cleanup that pure-MNE converter tests should not be marked as MATLAB tests. From #188, I folded in the pop_runscript regression where CURRENTSET = 0 must clear the selected EEG instead of leaving stale data selected. Closed #184-#188 as redundant.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

@claude review this

@claude

claude Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 4m 29s —— View job


Code review

Reviewed the 45 files changed by this PR's own commits (9dc4af4..HEAD) on top of the stacked #174/#176 base. Scope: removal of the oc-autoreview-adapted skill, addition of thermo-nuclear-code-quality-review, plus the runtime/test fixes the new skill surfaced (session sync centralization, MNE conversion invariants, temp-file cleanup, logging contracts, dispatch table refactor, dipfit/runscript regressions, dead test_*/__main__ purge).

Blocking

None.

Important

  1. Multiple notify_changed() per single console flush — src/eegprep/functions/adminfunc/console.py:355-389
    after_execute can call apply_workspace_state up to three times in one assignment turn (dataset block, then _store_eeg, then STUDY block), and each call ends with self.notify_changed(). Previously the workspace coalesced into a single notify_changed() at the end. This is mostly cosmetic — listeners are idempotent — but GUI listeners that re-render on every notify (main window dataset list, status bar) will now redraw 2–3× per %run/multi-target assignment. Worth confirming there's no visible flicker or extra cost on large ALLEEG. If a regression appears, a with session.batched_changes(): context (or a notify=False flag on apply_workspace_state, matching add_history's existing convention) is the natural fix.

Nits

  1. Tuple-pack with conditional on RHS — src/eegprep/functions/guifunc/menu_actions.py:1452
    eeg_out, command = out[0], out[1] if len(out) > 1 else ""
    Parses correctly (command = out[1] if … else ""), but is a known precedence trap. Splitting into two lines avoids the next reader having to verify it.
    Fix this →
  2. apply_workspace_state(currentset=…) index range check is one-sided — src/eegprep/functions/guifunc/session.py:253
    Validates max(resolved_currentset) > len(resolved_alleeg) but not min(resolved_currentset) < 1. normalize_dataset_indices already enforces positivity for non-empty lists, so this is defensive only. A short comment pointing at that contract would prevent a future reader from "fixing" it.

Test gaps

None blocking. New coverage is well-targeted at the exact regressions the PR claims to fix:

  • test_processing_logging_contract.py pins the print→logging contract for pop_select, eeg_lat2point, and _combine_regions (asserts capsys.readouterr().out == "").
  • test_eeg_eeg2mne_cleans_temporary_bridge_files and test_eeg_mne2eeg_cleans_temporary_bridge_files patch tempfile.TemporaryDirectory to a controlled parent and assert the dir is empty after — directly verifies the no-leak claim.
  • test_eeglab_clean_artifacts_roundtrip_uses_private_tempdir asserts no ./tmp.set/./tmp2.set are left in cwd.
  • test_eeg_mne2eeg_epochs_ica_fields verifies the icaweights @ icasphere @ data ≈ icaact and pinv(icaweights @ icasphere) ≈ icawinv invariants — exactly what the new _mne_ica_to_eeglab_fields exists to enforce.
  • test_dipfit_mutating_menu_action_updates_session_and_history guards the silent-dropped-result bug in _run_dipfit_function.
  • test_file_menu_runscript_clear_currentset_resets_eeg covers the CURRENTSET = 0 clear case folded in from Apply runscript namespace changes through session helpers #188.
  • test_eegprep_visual_capture_registry_covers_manifest_cases guards the new dispatch table against missing entries.

EEGLAB parity notes

  • MNE→EEGLAB ICA conversion (eeg_mne2eeg_epochs.py) is the most consequential parity fix in this PR. The previous code stored the MNE mixing matrix from ica.get_components() into icasphere and an identity into icaweights (literally swapped), so icaweights @ icasphere @ data did not reproduce icaact and pinv(icaweights @ icasphere) ≠ icawinv. The new _mne_ica_to_eeglab_fields composes unmixing_matrix_ @ pca_components_[:n_components] @ pre_whitener_ into a true unmixing, stores it in icaweights with an identity icasphere, derives icawinv = pinv(unmixing), and recomputes icaact from that unmixing — restoring the canonical EEGLAB invariant. This also matches the PR description's reason for not taking [EEG] Fix mne2eeg_epochs data orientation and ICA fields #185's ica.get_components() shortcut.
  • Data is now correctly placed in channel-major shape (nbchan, pnts, trials) via np.transpose(mne_data, (1, 2, 0)), matching AGENTS.md's channel-major contract; previous code stored MNE's (n_epochs, n_channels, n_times) layout, which would have broken every downstream sigprocfunc.
  • The Fortran-order reshape (reshape(n_ica_channels, -1, order="F")) preserves EEGLAB's sample-then-trial flattening — important because EEGLAB's runica/icaact reshape contract is column-major.
  • pop_select, eeg_lat2point, eeg_eegrej print→logging conversion preserves MATLAB's informational/warning content (preserved strings and side-effect semantics), just routes through the standard Python logger. Externally observable behavior matches.
  • New apply_workspace_state centralizes the EEG/ALLEEG/CURRENTSET/STUDY/ALLCOM/LASTCOM/CURRENTSTUDY transaction the way EEGLAB's eeg_store + workspace assignment expects: dataset selection, then history append, then notify. Index normalization remains 1-based EEGLAB-facing.
  • Runtime independence from src/eegprep/eeglab/ is preserved across all touched modules; removal of demo __main__ blocks with hardcoded /Users/arno/Python/... paths actually strengthens this.

Things checked and verified correct

  • _mne_ica_to_eeglab_fields math: unmixing = unmixing_matrix_ @ pca_components_[:n_components] @ pre_whitener_ is the documented MNE pipeline (whiten → PCA-project → ICA-unmix). _prewhitener_matrix correctly handles both the scalar (values.size == 1 → eye / scalar) and per-channel-vector (size == n_channels → diag(1/v)) cases, and falls through to the full matrix when noise_cov is not None.
  • _resolve_workspace_eeg only uses currentset-based fallback when caller omits eeg (eeg is _UNSET); explicit None/dict/list pass-through is unaffected. All existing callers either omit eeg or pass real EEG dicts.
  • _mirror_current_eeg_into_alleeg keeps ALLEEG[CURRENTSET-1] in sync after apply_workspace_state — required so the next pull_from_session() doesn't show a stale dataset list.
  • apply_workspace_state(append_dataset_history=False) is the right choice from accept_pop_result and from the console assignment path: history is already appended by the surrounding flow, so passing True here would duplicate.
  • eeg_eeg2mne / eeg_mne2eeg / clean_artifacts all swap the previous NamedTemporaryFile(delete=False) + manual os.remove pattern for tempfile.TemporaryDirectory(prefix="…") context managers. The directories are auto-cleaned on context exit, including on exception paths — strictly safer than the previous os.remove('./tmp.set') (which silently leaked on error and polluted cwd).
  • Visual-capture dispatch table replaces ~200 lines of elif args.case == "…": chain with a single _capture_case_handlers() dict. The new test_eegprep_visual_capture_registry_covers_manifest_cases cross-checks the manifest against the registry, so missing entries fail loudly.
  • pop_runscript namespace now also carries ALLCOM, LASTCOM, CURRENTSTUDY, and the test enforces that all three flow back into the session. The CURRENTSET = 0 path correctly resets EEG to eeg_emptyset() (folded from Apply runscript namespace changes through session helpers #188).
  • Dipfit menu actions: previously pop_dipfit_headmodel/gridsearch/nonlinear/multifit/leadfield/loreta returned (eeg_out, command) tuples that were discarded — dataset/dipfit mutations didn't make it back into the session, and history lost the command. New code routes through _store_current_from_gui and there's a regression test.
  • Logging contract tests (test_processing_logging_contract.py) use capsys + caplog correctly: they assert both that stdout/stderr are empty and that the expected message is in caplog.text — so a future "fix" that prints again would fail loudly.
    • autoreview-loop-skill

@arnodelorme
arnodelorme merged commit 56bc097 into develop Jun 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants