Tasks: Fold lawmode into law-ai¶
Spec: spec.md · Plan: plan.md · Inventory: docs/lawmode-migration.md
Conventions¶
- Implementation is done by Claude Code from one handoff issue per phase (hub constitution §26/§28); the planning bot writes no migration code.
- Every implementation PR is a draft, from a branch, and carries
Governed by: PRD §5.8 / LAWAI-022 / spec 057. - The old
lawmode/tree is not modified, archived or deleted by T-001 … T-005. - Each task: Refs, Owner, Status, Files, Steps, Verify.
T-001 — P1: law_ai.lawmode app on the provider chain¶
- Refs: FR-1, FR-2, NFR-QUAL-1, NFR-DEP-1, AC-6
- Owner: Claude Code (handoff issue #237)
- Status:
[x] - Files:
backend/law_ai/lawmode/{__init__,apps,schemas,policy}.py,backend/law_ai/lawmode/services/{review,artifacts}.py,backend/law_ai/lawmode/disclaimer.md,backend/law_ai/settings/base.py,backend/tests/lawmode/ - Steps: port models/config/core from
lawmode/lawmode/; route the single-call path throughlaw_ai.core.llm; addLAWMODE_MODELSvalidation (Anthropic:claude-opus-5-5,claude-sonnet-5-5,claude-haiku-5-5only; no OpenAI). - Verify:
make lint && make typecheck && make test; AC-6 test. - Stories: US2 and US5 met for the backend code that exists; US3 in part (gated findings are
unreviewedand nothing passes or fails a change; the queue item is T-002); US1 foundation only (no command until T-004); US6 held (lawmode/unchanged). Per-story status and what P1 settled for later phases: docs/lawmode-migration.md § Progress.
T-002 — P2: code_legal_review graph, prompts, provenance, HITL¶
- Refs: FR-3, FR-4, FR-5, NFR-AUDIT-1, NFR-HITL-1, AC-2, AC-3
- Owner: Claude Code (handoff issue #238)
- Status:
[x] - Files:
backend/law_ai/agents_runtime/graphs/code_legal_review.py,backend/law_ai/agents_runtime/prompts/lawmode/*.v1.md,backend/law_ai/ingestionapp/quarantine_kinds.py,backend/tests/lawmode/ - Steps: port the eight chains onto
ChatProviderChain; move each inline f-string prompt to a versioned file; passprompt_id/prompt_version; add thelawmode_findingHITL node. - Verify: AC-2, AC-3 tests;
make test. - Stories: US2 met for every model call that exists (eight
llm_callevents per scan, each naminglawmode.<chain>/v1, plus alawmode_reviewevent per chain); US3 met in the backend (gated findings becomelawmode_findingqueue items and readawaiting_review; nothing passes or fails a change); US1 still needs P4's command; US6 held (lawmode/unchanged). Also in this phase:ChatProviderChaincarriesprompt_id/prompt_version,DECISION_ONLY_KINDSkeeps approved findings out of the commit sweep,ReviewResult.chains_not_runmakes a report with a failed chain incomplete, the per-review random marker (BL-20261112-14) with the detection answers checked before the review chains read them outside it, and noLawmodeScanmodel (spec §8 left it to this phase; the provenance events and queue rows already carry the scan id). What P2 settled for later phases: docs/lawmode-migration.md § Progress.
T-003 — P3: research tools on httpx + tenacity¶
- Refs: FR-6, NFR-SEC-1
- Owner: Claude Code (handoff issue)
- Status:
[ ] - Files:
backend/law_ai/agents_runtime/tools/{spdx,eurlex}.py(if kept, OQ-2),backend/tests/lawmode/test_tools.py - Steps: reuse
ingestionapp/sources/courtlistener.py; implement or drop SPDX/EUR-Lex on evidence; drop the Scholar stub; mocked transports only in tests. - Verify:
git grep -n "import requests" backend/law_ai/lawmode backend/law_ai/agents_runtime/toolsempty;make test.
T-004 — P4: lawmode_scan command, Make target, JSON v1, docs¶
- Refs: FR-7, NFR-SEC-2, AC-1
- Owner: Claude Code (handoff issue)
- Status:
[ ] - Files:
backend/law_ai/lawmode/management/commands/lawmode_scan.py,Makefile,backend/law_ai/lawmode/schema/report.v1.json,docs/lawmode.md,backend/tests/lawmode/fixtures/ - Steps: port
cli.pyoptions (--diff,--jurisdiction,--output,--json); add thescanentry the extension expects; document the ollama-only mode and the disclaimer. - Verify: AC-1;
make lint-specs;make test.
T-005 — P5: VS Code extension under law-ai CI¶
- Refs: FR-8, FR-9, NFR-SEC-1, AC-4, AC-5
- Owner: Claude Code (handoff issue)
- Status:
[ ] - Files:
extensions/vscode-lawmode/(OQ-3),Makefile(lint,typecheck,testgain the extension vianode:20-alpine),.github/workflows/ci.ymlpath filters,.gitignore(out/) - Steps: port
src/*.ts; replacechild_process.execwithexecFile+ argv; consume JSON v1; add lint/tsc/test scripts; no committed build output. - Verify: AC-4, AC-5; CI green on the PR; Actions spend stays $0 (public-repo standard runners only).
T-006 — P6: retire the old lawmode/ tree (PROPOSAL — needs Amr's OK)¶
- Refs: FR-10, AC-7
- Owner: Amr decides; Claude Code implements only after Amr approves in his own words
- Status:
[ ](blocked on approval) - Files:
lawmode/(whole tree),README.md,AGENTS.mdlayout rows; GitHub repositorybamr87/lawmode(archive is a settings change, so Amr does it or approves it explicitly) - Steps: after P1–P5 ship and
LAWAI-022isshipped, open a PR that removes or archiveslawmode/; nothing here happens on an agent's say-so. - Verify: Amr's approval comment linked in the PR;
make lint && make typecheck && make testgreen.
Done-When (Definition of Done)¶
- T-001 … T-005
[x]; T-006 done or explicitly deferred by Amr. - All
AC-*covered by passing tests. make lint && make typecheck && make testgreen.- LegalBench: no change (spec §12).
- Provenance logging verified on one recorded scan.
## Follow-ups Discoveredsection below populated.
Follow-ups Discovered¶
Append-only. Mirror each item into BACKLOG.md with a
BL-YYYYMMDD-NNid. CI (scripts/spec_validator.py) checks this section exists. CI (scripts/backlog_lint.py) checks the BACKLOG mirror.
- BL-20261112-09 — infra, med — Retire the old
lawmode/tree after the fold-in ships (remove or archivelawmode/, its inert nested workflow, the committed extension build output andlawmode/CLAUDE.md; archivebamr87/lawmode). Needs Amr's OK in his own words; spec 057 T-006. - BL-20261112-10 — feature, low — Per-repository
.lawmode/policy.yamloverrides forlawmode_scan; needs PyYAML as a direct dependency with a licence and security note (constitution §8). - BL-20261112-11 — feature, low — Optional PR-review workflow that runs
lawmode_scanon law-ai pull requests and posts findings after HITL approval; needs Amr's OK (pull-requests: write, hosted-provider secrets; public-repo standard runners only, $0). - BL-20261112-12 — feature, low — Package and publish the VS Code extension (Marketplace / Open VSX) once P5 ships; publishing is an external action that needs Amr's OK.
- BL-20261112-13 — feature, med —
LawmodeReviewer.review_code(backend/law_ai/lawmode/services/review.py) sends its whole input as one prompt, with no size cap and no chunking, so a large file, diff or directory will overrun the serving tier's context or time out and surface only asReviewUnavailableError. Spec 057 P4'slawmode_scanmust review per file (or chunk) and report anything it skipped or cut asnot_run— never truncate silently, and never count an unreviewed file as no findings. Surfaced by T-001 (P1). - BL-20261112-14 — tech-debt, med — The code under a lawmode review is untrusted input wrapped in
<source_code>tags (prompts/lawmode/review.v1.md). Code that contains the closing tag, or comments written as instructions, can steer the reply — most plausibly into returning no findings. Add a per-call random delimiter that the P2code_legal_reviewnodes share, and an adversarial fixture test that a planted instruction does not empty therisksarray. Surfaced by T-001 (P1). - BL-20261112-15 — doc-gap, low — Spec 057
plan.md§8 and handoff issues #237 / #241 sayLAWAI-022movesplanned → in-progress, butin-progressis not afeatures/v1status (shipped | partial | planned | deprecated | tbd) and fails the hub'sgovernance_lint.py check. P1 recordedpartialwith a comment infeatures/features.yml. Amend the plan's wording through a spec amendment, or ask the hub to add the status. Surfaced by T-001 (P1). - BL-20261112-16 — tech-debt, low —
LLM_PRICE_TABLE=set but blank — or any malformed JSON in it — stops settings import with a rawjson.JSONDecodeErrorfromenv.json(backend/law_ai/settings/base.py).LAWMODE_MODELSavoids this by staying a string thatlaw_ai.lawmode.policyparses into anImproperlyConfigurednaming the setting, and by treating blank as unset; giveLLM_PRICE_TABLEthe same treatment. Surfaced by T-001 (P1). - BL-20261116-08 — tech-debt, med — P1's single-call
LawmodeReviewer(backend/law_ai/lawmode/services/review.py) still wraps the code in fixed<source_code>tags (prompts/lawmode/review.v1.md), so the per-review random marker that BL-20261112-14 asked for protects only thecode_legal_reviewgraph. When P4 wireslawmode_scan, either retire the single-call path or move it onto the same marker in areview.v2.md, with the adversarial test. Surfaced by T-002 (P2). - BL-20261116-09 — tech-debt, low — The review surfaces still word every approval as a knowledge-graph commit. For a
lawmode_findingrow the service now returnsskipped: decision-onlywith nocommit_error(DECISION_ONLY_KINDS), but the Django admin's "Approve + commit" action counts it as failed,manage.py review_queue approveprints "approved but NOT committed", andPOST /api/ingestion/reviews/approvereturnscommitted: false. Have all three report "decision recorded" for decision-only kinds. Surfaced by T-002 (P2). - BL-20261116-10 — feature, low —
code_legal_reviewruns its six review chains one after another, in the old pipeline's order, so a scan on a hosted tier waits for eight sequential calls. Fan the six review chains out in parallel when the serving tier is hosted, and keep them sequential when the chain is pinned toollama(a local model serves one call at a time, so six concurrent calls would queue and time out behind each other); record scan latency before and after. Surfaced by T-002 (P2). - BL-20261116-11 — test-gap, low — The prompt-injection test for
code_legal_review(backend/tests/lawmode/test_code_legal_review.py::TestPromptInjection) runs a stubbed model that obeys any instruction it finds outside the data block: it proves code under review cannot end the per-review marker block, not that a real model ignores instructions written inside it. Add an opt-in@pytest.mark.integrationcheck (never inmake test) that runs the planted fixture against a local Ollama model and asserts the privacy finding survives. Surfaced by T-002 (P2). - BL-20261116-12 — tech-debt, med —
code_legal_reviewwrites the file path into every chain's turn outside the per-review marker block. P2 puts it on one line, drops control characters and keeps its last 240 characters (_prompt_path), so a file name cannot add lines or forge theENDline, but a short instruction in a file name still reaches the model outside the block. Before P4'slawmode_scanfills the path from the scanned repository's file names, move it inside the data envelope (or a second block under the same marker) and plant an instruction in a file name inTestPromptInjection. Surfaced by T-002 (P2).