Skip to content

Latest commit

 

History

History
173 lines (135 loc) · 10.8 KB

AGENTS.md

File metadata and controls

173 lines (135 loc) · 10.8 KB

AGENTS.md

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.

What this repository is

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).

Setup

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.yml is gitignored and required before anything runs, including bundle exec rake - the Rakefile loads lib/configuration.rb, which reads it unconditionally.
  • Its defaults assume a sibling umbrella checkout (web_root: "../openaustralia") and reach into rblib/config.rb and twfy/conf/general there. 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_key values; real keys belong only in the gitignored configuration.yml, never in a commit.
  • A local MySQL database is needed for the load scripts; the exact CREATE DATABASE/CREATE USER statements are in the README.

Docker development environment

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.

Port clashes

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.

Commands

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.

CI

.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.

Structure

  • Top-level *.rb scripts are the entry points; the daily ones are parse-speeches.rb, parse-member-links.rb and sitemap.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 in docs/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/*.rnc are RELAX NG schemas for the XML the parser emits; spec/ uses RSpec with VCR cassettes.
  • docs/ holds docs/data-updates.md (the data-maintenance guide) and docs/agents/, the configuration the engineering skills read (see "Agent skills" below). There is no other prose documentation outside the README.

Gotchas

  • Hpricot is gone, Nokogiri is the HTML parser throughout (PR #253 converted it fully, not just parse-member-links.rb as earlier noted here). Titles/subtitles built by hand for raw XML insertion (eg lib/hansard_day.rb's title/subtitle/title_tag_value) go through numeric_entities before 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 on convert/hpricot-nokogiri; a separate, earlier attempt at GitHub Actions (PR #252) closed unmerged. .travis.yml is 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 moment main's CI story changes again.
  • APP_ENV is inferred from the working directory path (/production/ or /staging/ in Dir.pwd), defaulting to development; specs force test.
  • export-comments.rb / import-comments.rb require "mysql", which isn't in the Gemfile (mysql2 is), and refuse to run without the BE-DANGEROUS env var - treat them as broken until fixed.
  • wikipedia.rb is an empty file; nothing references it any more.
  • Data-file traps (full detail in docs/data-updates.md): members CSVs use d.m.yyyy dates but ministers CSVs use dd/mm/yyyy, always with 4-digit years; a new party abbreviation needs a mapping added to lib/people_csv_reader.rb; honorifics in ministers files must be The Hon (never bare Hon) with post-nominals whitelisted in lib/name.rb; after elections the merge order is people.csv, then representatives/senators.csv, then ministers/shadow-ministers.csv. Check any data edit with bundle exec ./parse-members.rb --no-load.
  • Scripts that load the database write to production-shaped tables; anything run with a real configuration.yml pointed 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__: under bundle exec ./script.rb __FILE__ is absolute while $PROGRAM_NAME stays 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 bridge DB_HOST to the docker-compose MySQL, and how to verify what loaded against production's public data at data.openaustralia.org.au.

Contributing

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.

Agent skills

Configuration the engineering skills read. These files describe how this repo works; edit them directly rather than re-running the setup skill.

Issue tracker

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.

Triage labels

The default five-label vocabulary: needs-triage, needs-info, ready-for-agent, ready-for-human, wontfix. See docs/agents/triage-labels.md.

Domain docs

Single-context: one GLOSSARY.md and one docs/adr/ at the root, both created lazily. See docs/agents/domain.md.