Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Legal Department

Contracts, IP protection, terms of service, GDPR compliance, licensing, privacy policies.

FieldValue
IDlegal
Icon§
Colorslate
Engine cratelegal-engine (~390 lines)
Wrapper cratedept-legal
StatusSkeleton

Overview

The Legal department manages the full contract lifecycle, compliance audits, and intellectual property tracking. It wraps legal-engine via the ADR-014 DepartmentApp pattern and is registered in the composition root alongside the other skeleton departments.

System Prompt

You are the Legal department of RUSVEL.

Focus: contracts, IP protection, terms of service, GDPR compliance, licensing, privacy policies.

Capabilities

CapabilityDescription
contractCreate, list, review, and sign contracts
complianceRecord and track compliance checks (GDPR, Privacy, Licensing, Tax)
ipFile and manage intellectual property assets (Patent, Trademark, Copyright, TradeSecret)

Quick Actions

LabelPrompt
Draft contract“Draft a contract. Ask me for type, parties, and terms.”
Compliance check“Run a compliance check for GDPR and privacy policy.”
IP review“Review intellectual property assets.”

Architecture

Three manager structs compose the engine, each backed by ObjectStore via StoragePort:

ManagerDomain TypeObject KindMethods
ContractManagerContractlegal_contractcreate_contract, list_contracts
ComplianceManagerComplianceChecklegal_complianceadd_check, list_checks
IpManagerIpAssetlegal_ipfile_asset, list_assets

Domain Types

ContractContractId (UUIDv7), ContractStatus enum (Draft, Sent, Signed, Expired, Cancelled), fields: title, counterparty, template, signed_at, expires_at, created_at, metadata.

ComplianceCheckComplianceCheckId (UUIDv7), ComplianceArea enum (GDPR, Privacy, Licensing, Tax), fields: description, passed, checked_at, notes, metadata.

IpAssetIpAssetId (UUIDv7), IpKind enum (Patent, Trademark, Copyright, TradeSecret), fields: name, description, filed_at, status, metadata.

  • LegalDepartment struct with OnceLock<Arc<LegalEngine>> for lazy initialization
  • register() creates the engine, stores it, and registers agent tools
  • shutdown() delegates to engine
  • 2 unit tests (department creation, manifest purity)

Registered Tools

Tool NameDescriptionParameters
legal.contracts.createCreate a new contract draftsession_id, title, counterparty, template
legal.contracts.listList contracts for a sessionsession_id
legal.compliance.checkRecord a compliance check outcomesession_id, area, description, passed, notes
legal.ip.registerFile an intellectual property assetsession_id, kind, name, description

Events

Event KindConstantDescription
legal.contract.createdCONTRACT_CREATEDA new contract draft was created
legal.compliance.checkedCOMPLIANCE_CHECKEDA compliance check was recorded
legal.ip.filedIP_FILEDAn IP asset was filed
legal.review.completedREVIEW_COMPLETEDA legal review was completed

Note: event constants are defined in legal_engine::events but emission is not yet wired into manager methods (skeleton status).

Required Ports

PortOptional
StoragePortNo
EventPortNo
AgentPortNo
JobPortNo

UI Contribution

Tabs: actions, agents, rules, events

No dashboard cards, settings panel, or custom components.

Chat Flow

sequenceDiagram
    participant User
    participant Frontend
    participant API as /api/dept/legal/chat
    participant Agent as AgentPort
    participant Engine as LegalEngine
    participant Store as ObjectStore

    User->>Frontend: "Draft an NDA for Acme Corp"
    Frontend->>API: POST (SSE)
    API->>Agent: run(system_prompt + user message)
    Agent->>Engine: legal.contracts.create(title, counterparty, template)
    Engine->>Store: objects().put("legal_contract", ...)
    Store-->>Engine: Ok
    Engine-->>Agent: { contract_id }
    Agent-->>API: SSE token stream
    API-->>Frontend: SSE events
    Frontend-->>User: "Created contract draft [id]"

CLI Usage

rusvel legal status          # Show department status
rusvel legal list             # List all legal items
rusvel legal list --kind contract  # List contracts only
rusvel legal events           # Show recent legal events

Testing

cargo test -p legal-engine    # Engine tests (contract CRUD, health check)
cargo test -p dept-legal      # Wrapper tests (manifest, department creation)

Current Status: Skeleton

The Legal department is fully registered and bootable within the RUSVEL department registry, but its business logic is minimal. Here is what exists and what remains to be built:

What exists:

  • Manager structures with basic CRUD operations (create + list for each domain)
  • Domain types with full serialization (Contract, ComplianceCheck, IpAsset)
  • 4 agent tools registered in the scoped tool registry
  • Event kind constants defined (but not yet emitted from manager methods)
  • Engine implements the Engine trait with health check
  • Unit tests for engine and wrapper

What needs to be built for production readiness:

  • Wire emit_event() calls into manager methods so domain events actually fire
  • Add review_contract, sign_contract operations to ContractManager
  • Add mark_passed operation to ComplianceManager
  • Add file_ip (full filing workflow with status transitions) to IpManager
  • Implement AI-assisted contract drafting via AgentPort (template expansion)
  • Add job kinds for async legal review workflows (e.g., JobKind::Custom("legal.review"))
  • Build compliance report generation (aggregate check results into a report)
  • Add engine-specific API routes (e.g., /api/dept/legal/contracts, /api/dept/legal/compliance)
  • Add engine-specific CLI commands (e.g., rusvel legal draft, rusvel legal audit)
  • Add personas for legal agent specialization
  • Add skills and rules for legal workflows

Source Files

FileLinesPurpose
crates/legal-engine/src/lib.rs390Engine struct, capabilities, tests
crates/legal-engine/src/contract.rs112Contract domain type + ContractManager
crates/legal-engine/src/compliance.rs108ComplianceCheck domain type + ComplianceManager
crates/legal-engine/src/ip.rs107IpAsset domain type + IpManager
crates/dept-legal/src/lib.rs89DepartmentApp implementation
crates/dept-legal/src/manifest.rs96Static manifest definition
crates/dept-legal/src/tools.rs184Agent tool registration