This file provides guidance to AI coding agents (Claude Code, GitHub Copilot, and others) when working with code in
this repository. CLAUDE.md and .github/copilot-instructions.md point here so the guidance lives in one place.
The OpenAustralia Hansard parser: Ruby scripts that parse Hansard from the Australian Parliament and load it into
the OpenAustralia.org.au database. It is consumed as a git submodule of
openaustralia/openaustralia (the umbrella repository), and in
production is driven by the twfy app's cron scripts (dailyupdate runs parse-member-links.rb nightly;
morningupdate runs parse-speeches.rb previous-working-day then sitemap.rb on weekdays).
Ruby 3.4.9 (.ruby-version). To work on the host, make setup installs Ruby with mise (or rbenv), the gems,
configuration.yml and ../rblib, and starts MySQL. It's safe to rerun. To work in Docker instead, see below.
configuration.ymlis gitignored and required before anything runs, includingbundle exec rake- the Rakefile loadslib/configuration.rb, which reads it unconditionally.- Its defaults assume a sibling umbrella checkout (
web_root: "../openaustralia") and reach intorblib/config.rbandtwfy/conf/generalthere. For standalone development, uncomment the "Standalone development override" keys in the example so you don't need twfy or PHP at all (see README). - The example file has placeholder
morph_api_key/theyvoteforyou_api_keyvalues; real keys belong only in the gitignoredconfiguration.yml, never in a commit. - A local MySQL database is needed for the load scripts; the exact
CREATE DATABASE/CREATE USERstatements are in the README.
One stack, defined in .devcontainer/compose.yaml, serves every way of working: make, plain docker compose
(through the root compose.yaml), and the dev container in VS Code, RubyMine, Codespaces or
devcontainer up --workspace-folder .. They all share the same containers and data.
make up # MySQL plus a Ruby container with the gems installed, once it's ready
make services-up # MySQL only, for running specs on the host
make status # each container's health and host ports
make logs # follow the logs (SERVICE=<name> for one container)
make shell # a shell in the app container, or a fresh one if it has stopped
make test # the specs, as CI runs them (ARGS=spec/lib/name_spec.rb:42 to narrow)
make lint # RuboCop (ARGS=<paths> to narrow)
make console # IRB with lib/ loaded
make down # stop and remove the containers, keeping the data
make clean # also remove built images and dependencies, so the next start rebuilds; keeps the data
make clobber # also remove the data, and prune unused Docker images and cache machine-wide
make up and make services-up return once every service passes its healthcheck. Run make for the full list.
A start that takes longer than START_LIMIT (in .devcontainer/compose.yaml) counts as failed, and stops loudly on purpose;
see "If the app won't start" in the README.
There's no web app here: the app container is Ruby with the gems installed and ../rblib cloned, for running the
specs (make test, or make shell then bundle exec rspec). make test, make lint and make console start the
stack first if it isn't running. It shares MySQL's network, so configuration.yml's test
settings work unchanged inside it. To run specs on the host instead, make services-up starts MySQL alone.
| Variable | Default | Publishes |
|---|---|---|
DB_PORT |
3306 | MySQL. The specs and sitemap read it too; postcodes.rb and the db: rake tasks still use 3306 (#1006) |
Put overrides in .env at the repo root, which is gitignored, with different values in each worktree. Compose reads
it however you start the stack. Containers and data are named openaustralia-parser (name: in compose.yaml), so a second checkout of
this repo, such as a worktree, shares them unless its .env also sets its own COMPOSE_PROJECT_NAME. For
host-side commands to see the same values, put dotenv in a gitignored .envrc if you use direnv, or
run set -a; . ./.env; set +a.
To see what holds a port, use ss -ltnp | grep 3306 (Linux) or lsof -iTCP:3306 -sTCP:LISTEN (macOS); a database
server installed on the host is the usual culprit.
make test and make lint run the first three in the app container. On the host, set EXCLUDE_NEWS=1 for the specs
as CI does, or the sitemap specs fail for want of PHP.
bundle exec rake # default task: the RSpec suite
bundle exec rspec spec/lib/name_spec.rb
bundle exec rubocop
bundle exec ruby-audit / bundle exec bundle-audit
bundle exec ./parse-members.rb --no-load # data-file sanity checks, no DB writes
bundle exec ./postcodes.rb --no-load
bundle exec rake db:stats / db:backup / db:validate_encoding
script/console # loads lib/**/*.rb into IRB
bin/run <script> is the production wrapper (picks the Ruby manager, dispatches .rb/.pl/.php); you don't need it
locally.
.github/workflows/ruby.yaml runs on every push/PR on this branch (convert/hpricot-nokogiri) - not yet on
main, see the Gotchas entry below for why that matters. Two jobs: test (bundle exec rspec against a real
MySQL service container) and scripts (parse-members.rb --no-load, postcodes.rb --no-load). A third, lint
(RuboCop), exists in the file but is commented out - run make lint yourself, CI won't catch it.
- Top-level
*.rbscripts are the entry points; the daily ones areparse-speeches.rb,parse-member-links.rbandsitemap.rb.lib/holds the parser proper (hansard_parser.rb,hansard_rewriter.rb,people.rb, ...). data/*.csv(people, representatives, senators, ministers, shadow-ministers) are maintained by hand for by-elections, party changes and reshuffles - a routine workflow here, not an anomaly. The full workflows and file formats are indocs/data-updates.md. The most common parser failure is an unrecognised person in a division; the fix is usually a data file edit.xml_schemas/*.rncare RELAX NG schemas for the XML the parser emits;spec/uses RSpec with VCR cassettes.docs/holdsdocs/data-updates.md(the data-maintenance guide) anddocs/agents/, the configuration the engineering skills read (see "Agent skills" below). There is no other prose documentation outside the README.
- Hpricot is gone, Nokogiri is the HTML parser throughout (PR #253 converted it fully, not just
parse-member-links.rbas earlier noted here). Titles/subtitles built by hand for raw XML insertion (eglib/hansard_day.rb'stitle/subtitle/title_tag_value) go throughnumeric_entitiesbefore use - Nokogiri's entity output is inconsistent (numeric ref, named HTML entity, or literal UTF-8 char depending on the surrounding markup), and raw-appended text has to be deterministically XML-safe regardless. - CI (see above) is branch-specific, not yet on
main. It was added directly onconvert/hpricot-nokogiri; a separate, earlier attempt at GitHub Actions (PR #252) closed unmerged..travis.ymlis gone entirely now too (removed, not just dead). Once this branch merges, check.github/workflows/directly rather than trusting this note - it'll be stale the momentmain's CI story changes again. APP_ENVis inferred from the working directory path (/production/or/staging/inDir.pwd), defaulting to development; specs forcetest.export-comments.rb/import-comments.rbrequire "mysql", which isn't in the Gemfile (mysql2is), and refuse to run without theBE-DANGEROUSenv var - treat them as broken until fixed.wikipedia.rbis an empty file; nothing references it any more.- Data-file traps (full detail in
docs/data-updates.md): members CSVs used.m.yyyydates but ministers CSVs usedd/mm/yyyy, always with 4-digit years; a new party abbreviation needs a mapping added tolib/people_csv_reader.rb; honorifics in ministers files must beThe Hon(never bareHon) with post-nominals whitelisted inlib/name.rb; after elections the merge order is people.csv, then representatives/senators.csv, then ministers/shadow-ministers.csv. Check any data edit withbundle exec ./parse-members.rb --no-load. - Scripts that load the database write to production-shaped tables; anything run with a real
configuration.ymlpointed at production paths is a live action needing an explicit go-ahead. - Entry scripts guard their main code with
File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__), not a bare$PROGRAM_NAME == __FILE__: underbundle exec ./script.rb__FILE__is absolute while$PROGRAM_NAMEstays relative, so the bare form silently skips the script. Keep the expanded form in new scripts. - For running scripts against a real local database, see the README's "Backfilling a real local dev database"
section: the local-dev-against-
twfy-docker workflow, how to bridgeDB_HOSTto the docker-compose MySQL, and how to verify what loaded against production's public data at data.openaustralia.org.au.
This repository has no CONTRIBUTING.md or templates of its own; the org-wide ones in
openaustralia/.github apply. Fetch the current versions rather than
relying on a copy:
curl -fsSL https://raw.githubusercontent.com/openaustralia/.github/main/.github/CONTRIBUTING.md
curl -fsSL https://raw.githubusercontent.com/openaustralia/.github/main/AGENTS.md
Any equivalent fetch of those URLs works (web fetch, or gh api if the GitHub CLI
is installed); don't assume a particular tool is present.
After merging a change here, the umbrella repository's submodule pointer needs bumping before production picks it up.
Configuration the engineering skills read. These files describe how this repo works; edit them directly rather than re-running the setup skill.
Issues live as GitHub issues in the umbrella repo, openaustralia/openaustralia — issues are disabled on this
repo. Driven by the gh CLI with -R openaustralia/openaustralia. See docs/agents/issue-tracker.md.
The default five-label vocabulary: needs-triage, needs-info, ready-for-agent, ready-for-human, wontfix.
See docs/agents/triage-labels.md.
Single-context: one GLOSSARY.md and one docs/adr/ at the root, both created lazily. See docs/agents/domain.md.