Commit Graph

10 Commits

Author SHA1 Message Date
7ee90dce31 feat: external precedent library with auto halacha extraction
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 1m27s
Adds a third corpus of legal authority distinct from style_corpus
(Daphna's prior decisions for voice) and case_precedents (chair-attached
quotes per case). The new corpus holds chair-uploaded court rulings and
other appeals committee decisions, with binding rules (הלכות) extracted
automatically and queued for chair approval.

Pipeline (web/app.py + services/precedent_library.py):
file → extract → chunk → Voyage embed → halacha_extractor → store +
publish progress over the existing Redis SSE channel.

Schema V7 (services/db.py): extends case_law with source_kind +
extraction status fields under a CHECK constraint pinning practice_area
to the three appeals committee domains (rishuy_uvniya, betterment_levy,
compensation_197). New precedent_chunks (vector(1024)) and halachot
tables (vector(1024) over rule_statement, IVFFlat indexes, gin on
practice_areas/subject_tags). Halachot start as pending_review; only
approved/published rows are visible to search_precedent_library.

Agents: legal-writer, legal-researcher, legal-analyst, legal-ceo,
legal-qa get search_precedent_library. legal-writer prompt explains
the three-corpus distinction and CREAC use; legal-qa now verifies that
every cited halacha resolves to an approved row in the corpus.

UI: /precedents page with four tabs — library / semantic search /
pending review (J/K nav, A/R/E shortcuts, badge count) / stats.
Reuses the existing upload-sheet progress + SSE pattern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 08:38:18 +00:00
7600810639 researcher: persist precedents to DB + save report to disk
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 14s
Two structural gaps in legal-researcher's "שלב 5: דיווח" surfaced while
auditing the case 8174-24 run:

  1. **No DB linkage.** The skill told the researcher to post a comment
     summarizing precedents but never to call mcp__legal-ai__precedent_attach.
     The MCP tool itself wasn't even in the tools frontmatter — so even
     a researcher that wanted to write to case_precedents physically
     couldn't. Result: 0 rows in case_precedents after a successful
     research run, even with 8 precedents identified and verified in
     the comment text. The writer then has to grep free-text instead
     of querying a structured table.

  2. **No persisted file.** Research output existed only as a Paperclip
     comment. The writer/QA can't `Read` it from disk; they have to go
     through Paperclip API to fetch comment bodies. Compare to the
     analyst, which is required to write `analysis-and-research.md`.

Fix:
  • Added precedent_attach, precedent_list, precedent_search_library
    to the tools frontmatter.
  • Rewrote step 5 with explicit ordering: save to disk → attach
    verified precedents to DB → update status → email → post comment.
  • Documented the precedent_attach call signature inline (case_number,
    citation, quote, section_id) so the agent doesn't have to reverse-
    engineer it. Includes guidance on which precedents to attach
    (verified with quote) vs which to leave for external verification.

Effect: future research runs will populate case_precedents and
data/cases/{N}/documents/research/precedent-research.md, both of which
the writer needs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 17:51:31 +00:00
47127f1e85 agents: close-own-issue PATCH for every agent (kill the retry loop)
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 9s
The retry loop bug we fixed in legal-analyst yesterday existed in every
single sub-agent skill. They all post a comment + wake the CEO + exit,
leaving their own issue in `in_progress`. Paperclip's "in_progress with
no live execution" watchdog then re-wakes them, repeating until something
external transitions the issue. Watched it happen on CMPA-17 (researcher)
today — 4 iterations + manual SIGTERM + manual PATCH.

Same fix applied to all 5 remaining agents:
  • legal-researcher.md
  • legal-writer.md
  • legal-qa.md
  • legal-exporter.md
  • legal-proofreader.md (file was incomplete — also added the missing
    שלב 5: דיווח and wake-CEO sections to bring it to parity with the
    other agents)

Each gets a "סגור את ה-issue של עצמך — חובה!" section with two PATCH
templates: one for `done` after a successful run, one for `blocked` if
checks fail or output is incomplete. The section sits before the
wake-CEO block, with an explicit reference to the CMPA-17 incident so
the rule has a concrete anchor.

Result: every agent now has the same close-issue contract. No more
zombie in_progress issues, no more 4× wakeup loops.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 17:35:44 +00:00
6b5d6586dc Agents: voice docs awareness for qa/researcher/analyst/ceo
Until now only legal-writer referenced the voice corpus. Without these
references the qa agent can't validate writer output, the researcher
chooses precedents outside Daphna's canon, and the analyst's claims
classification doesn't match block-zayin rules.

- legal-qa: adds 8th check "voice_compliance" — block ז structure,
  block י voice (אכן/אולם, "אנחנו" verbs, no numbered lists), correct
  precedent from canon, acceptance template match.
- legal-researcher: must check daphna-precedent-network.md before
  proposing any precedent; cross-reference with Daphna's own past
  decisions via search_decisions.
- legal-analyst: reads block-zayin-claims.md — its output is the
  writer's input for block ז.
- legal-ceo: lists all 6 voice docs and which agent reads each.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 17:14:44 +00:00
28daff58be Pre-existing agent updates + analysis DOCX export
Updates accumulated from prior sessions:
- HEARTBEAT: company-based filtering (CMP/CMPA) rules
- legal-qa, legal-researcher: routine updates
- analysis_docx_exporter: new service for analysis DOCX export
- compose page: "הורד כ-DOCX" button for analysis
- decision_template.docx: template for exporter

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 18:49:10 +00:00
45d52a74d2 Fix agent wakeup: /wake → /wakeup, remove broken DB fallback
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 7s
The agents used /api/agents/{id}/wake (404) with a fallback of INSERT
INTO agent_wakeup_requests. The DB insert creates only the wakeup
record without a heartbeat_run, so the Paperclip dispatcher never
processes it — agents get stuck in queued forever.

Fix:
- All agents: /wake → /wakeup (correct Paperclip API endpoint)
- Remove all DB INSERT fallbacks, replace with warning
- Document the rule in CLAUDE.md: always API, never DB insert
- Save to memory for future conversations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 14:18:57 +00:00
e698419faf Fix git not found error crashing document uploads in container
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 3m13s
Install git in Docker image and wrap all subprocess git calls in
try/except so a missing or failing git binary never kills an upload
that already succeeded.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 12:38:40 +00:00
3f6a130cf9 Make all agent instructions self-contained — no reliance on hope
Every agent now has explicit instructions in its own definition file,
not just in HEARTBEAT.md. An agent following only its own step-by-step
instructions will do the right thing on any new case.

All 6 non-CEO agents: explicit wakeup CEO block in completion step
  (curl API + psql fallback, with agent name customized)

legal-ceo.md: issue template for analyst with 5 mandatory items
  (document mapping table, no-extract list, split large docs,
   wakeup CEO, blocked if failed)

legal-writer.md: explicit Read of decision-methodology.md as step 1
  (before case_get, not just "read before starting")

legal-qa.md: methodology_compliance severity → critical
  (was warning — decisions without syllogisms/steel-man now blocked)

legal-proofreader.md: added case_update tool + status='proofread'
  (was missing entirely — CEO couldn't know proofreading was done)

legal-researcher.md: added case_update + mail notification
  (was missing — CEO couldn't know research was done)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 13:17:44 +00:00
444fb73681 Align all Paperclip agents with decision-methodology.md
All agents audited line-by-line against the new methodology.

legal-analyst (18 changes):
- Reads methodology before starting
- Issues formulated as syllogisms (rule + facts + question)
- SWOT replaced with analytical structure (rule/facts/open questions)
- Factual findings separated from legal conclusions
- Issue ordering: threshold → dispositive → secondary
- Claim handling section (bundle/skip recommendations)
- Standard of review field added
- CREAC preparation per issue
- Steel-man field per issue
- "הגוף המחליט" replaces "צד מיוצג"

legal-ceo (14 changes):
- Knows methodology exists, reads it before orchestrating
- Step B: asks claim handling (bundle/skip table) + appeal classification
- Step B: key questions as condensed syllogisms
- Step C: directions structured as syllogisms (rule + facts + conclusion)
- Step D: verifies chair_directions completeness before sending to writer
- Status map expanded with intermediate states
- Fallback conditions for every step
- Methodology consistency rule added

legal-researcher (4 changes):
- Reads methodology before starting
- Case law summaries include hierarchy level and CREAC role
- Plan mapping requires exact quotation + ambiguity detection
- Reporting structured by source type (text/precedent/policy)

legal-exporter (1 change):
- Verifies QA passed before export

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 23:43:42 +00:00
4574987a69 Add 3 new agents: legal-researcher, legal-writer, legal-qa
Complete agent pipeline for decision writing:
1. legal-analyst (existing) — extract claims/responses/replies
2. legal-researcher (new) — analyze precedents, plans, protocols
3. legal-writer (new) — write decision blocks in Dafna's style
4. legal-qa (new) — validate before export (6 checks)

All agents use claude_local adapter (Claude Code session, zero API cost).
Each has YAML frontmatter with specific tools and detailed Hebrew instructions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 16:47:28 +00:00