Skip to content

feat: add Brainstorm community; generalize Discourse, MATLAB and page tools - #609

Merged
neuromechanist merged 12 commits into
developfrom
feature/brainstorm-community
Oct 11, 2026
Merged

neuromechanist merged 12 commits into
developfrom
feature/brainstorm-community

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Adds a Brainstorm assistant from the resources its admin (@tmedani) provided. While setting it up I found that several shared tools were not general enough, and some had bugs that also affect other communities. This PR fixes those too.

Brainstorm community (src/assistants/brainstorm/config.yaml)

  • Tutorials: 108 pages of the Brainstorm wiki, each fetched and checked: the 28 introduction tutorials, the advanced topics, e-phys, the sEEG suite, NIRSTORM, FEM/DUNEuro, plugins, and how to cite. Two are preloaded: the overview and Tutorial 1 (database structure).
  • Forum: https://neuroimage.usc.edu/forums, limited to the Discussions, Bugs, Requests, News and Uncategorized categories. Synced daily.
  • GitHub issues/PRs and MATLAB function help: brainstorm3, bst-users (scripts shared by users) and bst-duneuro.
  • Reference papers (DOIs checked against Crossref): Tadel 2011, Tadel 2019, Niso 2019, Medani 2023.
  • Embedding: the website and the forum share one host, neuroimage.usc.edu. It is allowed in cors_origins and in the worker. The maintainer is tmedani.

Fixes to shared tools, and who they reach

Fix Communities
Discourse jobs are scheduled at all MNE, BIDS, Brainstorm
Discourse tags honored; likes, categories and staff answers read BIDS (NeuroStars bids), MNE, Brainstorm
A Discourse sync that missed topics fails instead of passing MNE, BIDS, Brainstorm
Example tool calls in prompts corrected EEGLAB, FieldTrip, MetaBCI, MNE, Brainstorm
MATLAB help after the function line FieldTrip, Brainstorm, EEGLAB (a few files)
Stale docstrings pruned on sync every community with docstrings
HTML docs parsed with lxml, MoinMoin body recognized Brainstorm; MNE pages convert identically
Widget page reader returns the page's main content every community with the widget embedded

Discourse sync

  • No scheduled job existed. The scheduler had no Discourse job, so sync.discourse crons never ran. Production MNE was last synced by hand on 2026-02-25, and BIDS had 0 topics.
  • Schedules now run. MNE syncs weekly; BIDS and Brainstorm daily. A test fails when a community configures a forum without a schedule.
  • Manual trigger works. POST /sync/trigger now accepts discourse and runs in a worker thread. Note that all now includes Discourse, so it can run for hours.
  • tags is honored. The setting was read and never used; without this fix, a BIDS sync would have downloaded all of NeuroStars.
  • Likes and categories are read. Likes come from actions_summary, so the most-liked fallback works on any forum. Category names come from /site.json; before, they were always empty.
  • Fallback for forums without accepted answers. The answer is now the first substantive staff reply, after the most-liked reply by someone other than the asker. Brainstorm's forum is answered by its developers.
  • Incomplete syncs fail. A listing page that cannot be read (the forum down, or a configured tag or category that does not exist) used to end quietly, move the last-sync time past topics never seen, and count as a success. Now the sync stores what it read, keeps the last-sync time, and raises DiscourseSyncError. The scheduler tracks that as a failure, and the CLI exits 1.
  • Long syncs miss nothing. The last-sync time is when the sync started, so the next run picks up what changed during a long sync.
  • Other hardening. A database error stops the sync instead of failing every topic in turn. A non-JSON answer is logged and skipped. A listing may run to 1,000 pages; the old limit of 200 pages (6,000 topics) would soon have cut off MNE's.

Prompts

  • retrieve_*_docs takes only a url, and search_*_discussions has no status filter. The EEGLAB, FieldTrip, MetaBCI, MNE and Brainstorm prompts showed title=... and status="open", which teaches the model calls that fail.
  • These are corrected, and a test checks every example call in every community's prompt against the tool it names.

MATLAB docstrings

  • Help that follows the function line (MATLAB's own convention, used by FieldTrip and Brainstorm) is now indexed. Measured on full clones:

    Repository Files with main-function help, before After
    Brainstorm 46 of 1,464 1,399
    FieldTrip 325 of 5,331 4,011
  • License and copyright notices, %{ %} blocks and separator lines are not taken for help.

  • In EEGLAB, the only changes are 24 docstrings that were empty, a separator or a license, or that ended in a license that is now trimmed.

  • Pruning: the sync only ever inserted and updated, so removed functions, deleted files and old junk entries stayed searchable. It now prunes them. A file that could not be downloaded is never pruned, and deleted files are pruned only when GitHub's file listing is complete.

HTML documentation and the widget's page reader

  • Pages are parsed with lxml, and MoinMoin's div#content is recognized. html.parser lost about 75% of each Brainstorm tutorial.
  • fetch_current_page used to keep the text of <script> tags, so on a tutorial the model saw analytics code. It now reads the page's main content only, and reports a page with no readable text instead of returning it empty.

Changed

  • HED has no forum. NeuroStars (tag hed, 3 topics, never synced) is removed from HED, along with its search_hed_forum tool.

Review

Reviewed with the pr-review-toolkit agents, run on Sonnet: code-reviewer, pr-test-analyzer, comment-analyzer, silent-failure-hunter, then code-simplifier. type-design-analyzer was skipped because the PR adds no types.

  • code-reviewer: no finding at 80% confidence or higher.
  • Fixed:
    • All critical and important findings from the other three reviewers.
    • The wrong prompt examples (comment-analyzer).
    • Incomplete Discourse syncs passing as success (silent-failure-hunter).
    • Docstring pruning untested end to end, and its tests sitting in tests/test_integration, which the required check skips (pr-test-analyzer).
    • Inaccurate comments and changelog entries.
  • code-simplifier: made no changes.
  • Declined, with reasons:
    • Serializing manual and scheduled syncs. They could overlap before this PR too, so this is a separate change.
    • Storing which rule chose a forum answer. It needs a schema change, and the forum tool already tells the model that forum results are for discovery, not for answers.

Validation

  • uv run pytest -m "not network": 5,300 passed. The 5 live Discourse tests also pass, including a real Brainstorm forum sync. ruff check and ruff format --check are clean.
  • New offline tests:
    • Discourse sync end to end over respx: categories, last-sync time, failed listing, unknown tag, de-duplication, the topic cap.
    • Docstring pruning over respx: removed file, truncated listing, failed download.
    • The scheduler's Discourse job and its failure tracking.
  • End-to-end checks: a sync of 25 real forum topics (23 got an answer, all got a category); the assistant built with all 7 tools; the system prompt rendered with no unfilled placeholders.

After merge

  • MNE needs a one-time full forum resync to apply the new answer and category logic to the 5,913 topics already stored: osa sync discourse -c mne --full (about 1.7 hours). The scheduled incremental runs only refresh topics active since the last sync.
  • First Brainstorm forum sync takes about 2 hours. It runs at the next 05:15 UTC, or start it with osa sync discourse -c brainstorm.
  • Docstrings need no manual step: the weekly syncs re-parse every file and now prune. They could not be run against the GitHub API from my environment; the parser was validated on local clones.
  • Worker deploys automatically on merge (sync-worker-cors.yml). scripts/sync_worker_cors.py also allows *.usc.edu, because it always widens to a domain's last two parts, as it already does for *.github.io.
  • For the Brainstorm team:
    • Their tutorial pages already embed a Chatbase bot.
    • To embed the widget on the forum, a Discourse admin will likely need to allow the widget script in the forum's content security policy.
    • A logo is still to come from them.
  • Known limitations (not new):
    • The Discourse sync reads only the first ~20 posts of each topic.
    • FieldTrip's seven FAQ documents point at index pages whose source is a single {% include pagelist %} line, so they fetch almost nothing.

🤖 Generated with Claude Code

https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11

Parse documentation pages with lxml instead of html.parser, which nested
everything after an unclosed <p> and lost most of a MoinMoin wiki page.
Recognize MoinMoin's div#content as the page body. Every existing MNE page
converts identically.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
The parser read only the comments before a function line (EEGLAB style) and
missed the help after it, MATLAB's own convention used by FieldTrip and
Brainstorm. Help stops at a license or copyright notice, %{ %} license blocks
and separator lines are not taken for help, and a classdef file's header is
its help.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
- Honor the configured tags (alone or within categories); they were ignored,
  so a shared forum such as NeuroStars would have been synced whole.
- Read likes from actions_summary and category names from /site.json.
- On forums without accepted answers, fall back to the first substantive
  staff reply; the asker's own liked reply is the last resort.
- Run sync.discourse schedules and accept discourse in POST /sync/trigger,
  which now runs syncs off the event loop.
- Record the sync start as the last sync so long runs miss nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
Tutorials from the Brainstorm wiki (108 pages, two preloaded), the user
forum, issues and MATLAB help from brainstorm3, bst-users and bst-duneuro,
and the four reference papers. Maintained by tmedani.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
fetch_current_page kept the text of every script and read the whole page, so
on a Brainstorm tutorial the model saw analytics code instead of the
tutorial. Reuse the documentation fetcher's conversion.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
Both had NeuroStars tags configured but no schedule, so their forums were
never synced. A test now fails when a forum has no sync.discourse schedule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Worker Deployment Required

Worker changes detected. After merging to main or develop, the workflow will automatically deploy the worker.

Manual deployment (if needed):

cd workers/osa-worker
wrangler deploy --env dev  # for develop branch
wrangler deploy            # for main branch

HED does not use NeuroStars as a source. Its forum config and schedule are
removed, and with them the search_hed_forum tool.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
The docstring sync only inserted and updated, so removed or renamed
functions, deleted files, and text the parser no longer takes for help
stayed searchable. Prune each parsed file's stale symbols, and the files
missing from a complete repository listing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
A listing page that failed (forum down, or a configured tag or category that
does not exist) ended quietly, moved the last-sync time past topics never
seen, and counted as a successful job. Such a sync now stores what it read,
keeps the last-sync time, and raises DiscourseSyncError, which the scheduler
tracks as a failure and the CLI reports. Database errors stop the sync, a
non-JSON answer is logged and skipped, and a listing may run to 1,000 pages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
retrieve_x_docs takes only a url and search_x_discussions has no status
filter, so the EEGLAB, FieldTrip, MetaBCI, MNE and Brainstorm prompts taught
calls that fail. A test now checks every example call in every prompt
against the tool it names. Also clarifies Brainstorm config comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
Moves the pruning tests out of tests/test_integration, which the required
check skips, and tests sync_repo_docstrings against GitHub served over
respx: removed files, truncated listings and failed downloads. Logs the
deletions and corrects parser comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
The widget page reader now reports a page with no text in its HTML instead
of returning an empty success. The worker CORS list is regenerated with
scripts/sync_worker_cors.py. Changelog and registry notes updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019qLZ5bssRHp7tU3FuMtw11
@neuromechanist
neuromechanist merged commit 34f383f into develop Oct 11, 2026
10 checks passed
@neuromechanist
neuromechanist deleted the feature/brainstorm-community branch October 11, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants