Skip to content

Replace Python agent with claude -p CLI#119

Merged
xrendan merged 4 commits intomainfrom
replace-python-agent-with-claude-cli
Mar 27, 2026
Merged

Replace Python agent with claude -p CLI#119
xrendan merged 4 commits intomainfrom
replace-python-agent-with-claude-cli

Conversation

@xrendan
Copy link
Copy Markdown
Member

@xrendan xrendan commented Mar 27, 2026

Summary

  • Eliminates the Python agent entirely — removes agent/src/, pyproject.toml, claude-agent-sdk, psycopg2, and the in-process MCP server
  • Rails jobs now spawn claude -p directly; Claude reads data via curl to new Rails GET endpoints and writes via existing endpoints
  • WebFetch restricted to *.canada.ca, *.gc.ca, www.parl.ca

What changed

New Rails API (read endpoints):

  • GET /api/agent/commitments/:id — full commitment with criteria, matches, events, bills, departments, status_changes
  • GET /api/agent/commitments — list with filters (status, policy_area, stale_days, limit)
  • GET /api/agent/commitments/:id/sources
  • GET /api/agent/bills/:id + GET /api/agent/bills
  • GET /api/agent/entries/:id + GET /api/agent/entries?unprocessed=true

New tracking endpoints (called by Stop hooks):

  • PATCH /api/agent/commitments/:id/touch_assessed — updates last_assessed_at; skips if a recent evaluation_run already exists
  • PATCH /api/agent/entries/:id/mark_processed — sets agent_processed_at; idempotent

Stop hooks (agent/.claude/hooks/):

  • on_stop_commitment.sh — fires after every commitment evaluation run
  • on_stop_entry.sh — fires after every entry processing run
  • Hooks are injected per-job via --settings JSON, so each job type only loads its own script

Jobs:

  • Stream claude -p output to stderr in real time via popen2e
  • Pass CLAUDE_CODE_OAUTH_TOKEN for auth; explicitly unset RAILS_MASTER_KEY and SECRET_KEY_BASE
  • Per-job hook config passed inline via --settings

Other:

  • Migration: add_column :entries, :agent_processed_at, :datetime
  • CORS: allow all localhost:* origins in development
  • Dockerfiles: install claude CLI binary

Test plan

  • Tested against commitment #2881 — agent evaluated successfully, criteria assessed, evaluation run recorded
  • Run bundle exec rails db:migrate
  • Verify GET /api/agent/commitments/1 returns expected shape
  • Queue an AgentEvaluateCommitmentJob and confirm last_assessed_at updates
  • Queue an AgentProcessEntryJob and confirm agent_processed_at is set

🤖 Generated with Claude Code

xrendan and others added 4 commits March 27, 2026 11:21
Eliminates the Python agent entirely (claude-agent-sdk, psycopg2, MCP
server) in favour of spawning `claude -p` directly from Rails jobs.
Claude uses curl via Bash to call Rails API read/write endpoints, and
WebFetch (restricted to canada.ca / gc.ca / parl.ca) for government
pages.

Key changes:
- Delete agent/src/ and pyproject.toml
- Add GET read endpoints: /api/agent/commitments, /api/agent/bills,
  /api/agent/entries (with full detail and list/filter support)
- Add PATCH /api/agent/commitments/:id/touch_assessed and
  /api/agent/entries/:id/mark_processed for Stop hooks
- Migration: add agent_processed_at to entries
- AgentEvaluateCommitmentJob + AgentProcessEntryJob rewritten to spawn
  claude -p with streamed output, per-job Stop hooks, and explicit
  RAILS_MASTER_KEY unset
- agent/.claude/hooks/on_stop_commitment.sh and on_stop_entry.sh
  guarantee last_assessed_at + agent_processed_at are updated even if
  the agent skips record_evaluation_run
- agent/CLAUDE.md rewritten as curl-based API reference
- CORS: allow all localhost origins for development
- Dockerfiles: install claude CLI binary

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Auto-correct 226 offenses: trailing commas in hash literals and spacing inside array literal brackets.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The bin/brakeman script uses --ensure-latest which fails CI when the installed version is behind the latest release.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@xrendan xrendan merged commit 559e407 into main Mar 27, 2026
1 of 3 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

Development

Successfully merging this pull request may close these issues.

1 participant