Metadata-Version: 2.5
Name: docketry
Version: 0.17.1
Summary: Reads one intake mailbox over IMAP, checks each message against rules you declare, and holds anything that fails until a named person approves it. Runs locally; no server.
License: 
                                         Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
License-File: LICENSE
License-File: NOTICE
Keywords: email,guardrails,law,legal,pipeline
Classifier: Intended Audience :: Legal Industry
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.11
Provides-Extra: cite
Requires-Dist: eyecite>=2; extra == 'cite'
Requires-Dist: httpx>=0.27; extra == 'cite'
Provides-Extra: docx
Requires-Dist: python-docx>=1; extra == 'docx'
Provides-Extra: export
Requires-Dist: openpyxl>=3; extra == 'export'
Requires-Dist: python-docx>=1; extra == 'export'
Provides-Extra: ocr
Requires-Dist: pillow>=10; extra == 'ocr'
Requires-Dist: pytesseract>=0.3; extra == 'ocr'
Provides-Extra: pdf
Requires-Dist: pypdf>=4; extra == 'pdf'
Description-Content-Type: text/markdown

# Docketry

Docketry drains a dedicated intake mailbox over IMAP, normalizes each message,
runs a declared set of checks against it, and stops anything that fails one
until a named person approves it in an audit log. It runs on one machine, in
one directory, with no server component and no outbound network traffic.

A Python 3.11+ CLI plus a local-only web queue. Core is stdlib-only.

```console
$ pip install docketry
$ docketry demo          # sample traffic + dashboard, no mailbox needed
```

---

## Contents

[What it does](#what-it-does) ·
[Install](#install) ·
[Quickstart](#quickstart) ·
[How a message moves](#how-a-message-moves) ·
[Gates that ship](#gates-that-ship) ·
[Configuration](#configuration) ·
[Commands](#commands) ·
[Writing a gate](#writing-a-gate) ·
[Audit log](#audit-log) ·
[Local model](#local-model-optional) ·
[What it does not do](#what-it-does-not-do)

## What it does

A firm points forwarding rules at a mailbox nobody works out of —
`intake@yourfirm.com`. Docketry reads that mailbox and no other. For each
message it:

1. Parses it into a normalized envelope: addresses, subject, text body,
   attachments with SHA-256 digests, and threading headers.
2. Stores it in SQLite on local disk, attachment bytes in a content-addressed
   directory. Deduplicated on the SHA-256 of the raw message.
3. Runs the gates bound to the pipeline's first stage.
4. Sets the message's status from the results: `ok`, `pending_review` or
   `blocked`.
5. Holds anything not `ok` until `docketry approve` records a name and a role.
   The gates then run again; the message advances only if they pass.

Two of the shipped gates do work a firm would otherwise do by hand.

**`name-screen`** matches a list of party or matter names against subject, body
and attachment filenames, case-insensitively on word boundaries. Bound with
`on_fail = "block"`, a message naming a screened party stops, and releasing it
writes a row containing the approver's name, role, gate and timestamp.

**`notice-parser`** extracts case numbers, document titles and dates from court
e-service mail. Five adapters ship — `fl-eportal-service`, `pacer-nef`,
`jacs-hearing`, `jaws-hearing`, `efile-receipt` — producing one of three notice
types: `service_notice`, `filing_receipt`, `hearing_notice`. Mail the adapters
cannot read is held rather than half-parsed, and `docketry stats` counts
template drift separately so a portal changing its format is visible.

## Install

```console
$ pip install docketry                                # core, stdlib-only
$ pip install "docketry[pdf,ocr,docx,cite,export]"    # optional features
```

| Extra | Pulls in | Enables |
|---|---|---|
| `pdf` | `pypdf` | PDF text extraction, redaction |
| `ocr` | `pytesseract`, `Pillow` | scanned PDFs; also needs the `tesseract` binary |
| `docx` | `python-docx` | Word extraction, Word timeline export |
| `cite` | `eyecite`, `httpx` | citation extraction, CourtListener verification |
| `export` | `openpyxl`, `python-docx` | Excel and Word exports |

Single-file executables for Windows, macOS and Linux are attached to every
[release](https://github.com/harkins-solutions/docketry/releases); run one with
no arguments and it opens the demo. `docketry doctor` reports which extras are
installed and what is unavailable without them.

## Quickstart

```console
$ docketry init
Intake mailbox address (e.g. intake@yourfirm.com): intake@smallfirm.com
IMAP host for that mailbox [imap.smallfirm.com]:
Folder to read [INBOX]:
Store the mailbox password in config.toml? (no = read it from DOCKETRY_IMAP_PASSWORD) [y/N]: n
Your firm's own email domains [smallfirm.com]:
Who reviews intake day to day [paralegal]: legal assistant
Who can release anything, including a conflict hold [attorney]:
Screened names or matters (comma separated): Acme Insurance, Roberta Vance
Addresses or domains court e-service arrives from [@myflcourtaccess.com, @uscourts.gov]:
Hold attachments larger than (MB) [25]:

Written to docketry-home:
  config.toml
  guardrails.toml
  roles.toml
```

Nine questions, three files. The IMAP host is guessed from the address domain.
The manifest and the role registry are built and validated in memory first, so
answers that would not load fail before anything is written. `docketry init
--host H --user U` skips the questions for scripted installs.

```console
$ export DOCKETRY_IMAP_PASSWORD='app-password-here'
$ docketry poll                      # one read-only sweep
$ docketry queue                     # what is held, and by which gate
$ docketry approve 3 --gate name-screen --by "A. Vance" --role attorney
$ docketry ui                        # same queue at http://127.0.0.1:8642
```

Polling never marks, moves or deletes anything in the mailbox, and Docketry
never sends mail. Position is tracked by the mailbox's UIDVALIDITY and
last-seen UID; if the server resets UIDVALIDITY, the cursor resets rather than
skipping messages.

## How a message moves

Stages are declared in `guardrails.toml`; the default is `["ingest", "review"]`.

```
poll → parse → store → gates(stage 1) → status
                                          ├── ok             → advance
                                          ├── pending_review → queue
                                          └── blocked        → held
                                                   ↓
                                          approve (name + role, recorded)
                                                   ↓
                                          gates run again → advance → next stage → done
```

`advance()` is the only code path that moves a message forward. An approval
does not set a status; it inserts an audit row, after which that stage's gates
run again against the stored message. A hold clears when the gates clear it.

Statuses: `ok`, `pending_review`, `blocked`, `done`.

Gates return findings with a severity. Only `fail` can hold a message. What a
`fail` does is the binding's `on_fail`:

| `on_fail` | Effect of a `fail` finding |
|---|---|
| `warn` | recorded; message continues |
| `bounce` | status `pending_review`; appears in `docketry queue` |
| `block` | status `blocked` |

Both held states clear the same way: an approval by a role the registry says
may release that gate.

## Gates that ship

| id | Checks | Options | Stages |
|---|---|---|---|
| `name-screen` | subject, body, attachment filenames against a term list; case-insensitive, word-boundary | `terms` (list, required), `note` (str) | any |
| `notice-parser` | that court e-service mail parses to a known notice type | `adapters_file` (path) | `ingest` |
| `sender-scope` | sender against allow/deny lists of addresses or `@domain` suffixes | `allow` (list), `deny` (list) | `ingest` |
| `attachment-policy` | attachment extension and size | `deny_extensions` (list), `max_size_mb` (number) | `ingest` |
| `doc-classifier` | proposes a document type per attachment; never applies one | — | any |
| `provenance-stamp` | records source and hashes; informational, never holds | — | any |

`allowed_stages` is checked when the manifest loads: binding `notice-parser` to
a stage other than `ingest` is a load error, not a runtime surprise.

A binding:

```toml
[pipeline]
stages = ["ingest", "review"]

[[gate]]
id = "name-screen"
binds_to = ["ingest"]
on_fail = "block"
authority = "attorney"

[gate.options]
terms = ["Acme Insurance", "Roberta Vance"]
note = "ethical wall"
```

Three worked manifests are in [`examples/`](examples/) — default, solo-strict,
litigation-team. A test loads all three on every build.

## Configuration

A Docketry home is one directory; nothing is stored outside it.

| Path | Contains |
|---|---|
| `config.toml` | mailbox connection, firm domains, optional model. Created mode 0600 |
| `guardrails.toml` | stages and gate bindings |
| `roles.toml` | role names and what each may release (optional) |
| `adapters.toml` | firm-specific e-service parsers (optional) |
| `contacts.toml` | who an address belongs to (optional) |
| `gates/*.py` | the firm's own gates (optional) |
| `store/docketry.db` | SQLite: messages, findings, approvals, notices, matters |
| `store/attachments/` | attachment bytes, content-addressed by SHA-256 |
| `anchors.log` | audit-chain heads written by `docketry anchor` |

```toml
# config.toml
[mailbox]
host = "imap.gmail.com"
user = "intake@yourfirm.com"
folder = "INBOX"
port = 993                 # default
# password = "..."         # or set DOCKETRY_IMAP_PASSWORD, which wins

[firm]
domains = ["yourfirm.com"]

[llm]                      # optional; see Local model
base_url = "http://127.0.0.1:11434"
model = "qwen2.5"
timeout = 120
```

`roles.toml` names the jobs the firm actually has and what each may release.
`may_release` takes gate ids or `"*"`:

```toml
[[role]]
name = "paralegal"
may_release = ["sender-scope", "attachment-policy", "notice-parser"]

[[role]]
name = "attorney"
may_release = ["*"]

[[person]]                 # optional
name = "Dana Reyes"
roles = ["paralegal"]
```

Without `roles.toml`, an approval's role must equal the gate's `authority`
exactly. With it, a role whose `may_release` covers the gate can release it, so
an attorney can clear a hold marked for a paralegal. Where `[[person]]` entries
exist, a listed person cannot approve under a role they do not hold.

There is no login. A role is a name typed at approval time and checked against
the registry: it catches mistakes, not lies.

## Commands

`docketry --home PATH <command>`; `--home` defaults to `./docketry-home`.

**Intake and review**

| Command | Does |
|---|---|
| `init` | ask nine questions, write the home. `--host/--user` to skip; `--store-password` to store it |
| `poll` | one read-only IMAP sweep: ingest, run gates, parse notices |
| `watch --every N` | `poll` on a loop, N seconds apart |
| `queue` | messages held, and the gates holding them |
| `approve ID --gate G --by NAME --role R [--note N]` | record an approval, re-run the gates |
| `advance ID` | re-run gates and move one stage forward |
| `status` · `stats [--days N] [--json]` | counts by status; volume, holds by gate, time-to-release |
| `digest` | one-screen summary to paste into mail |
| `ui [--port N]` | review queue on 127.0.0.1; refuses any other bind address |
| `doctor` | config, gates, manifest, roles, extras, model reachability, audit chain |
| `demo [--port N]` | disposable home with sample traffic |

**Gates**

| Command | Does |
|---|---|
| `gates [--quiet]` | every bindable gate, its source, its allowed stages |
| `new-gate ID [--title T] [--force]` | write a working gate into `<home>/gates/` |
| `try-gate ID [--subject S] [--from A] [--body B] [--attach F] [--eml FILE] [--option K=V]` | run one gate against one message |

**Notices, matters, documents**

| Command | Does |
|---|---|
| `notices [--type T]` | parsed notices and their extracted fields |
| `matters` · `matter-open` · `matter-status` · `matter-advance` | matters through firm-defined workflow stages |
| `classify FILE` · `class-queue` · `class-apply ID --by --role` | document-type proposals and their approval |
| `timeline CASE` · `timeline-export CASE OUT` · `docket-reconcile CASE DOCKET` | case chronology, Word/Excel export, diff against a pulled docket |
| `redact-scan` · `redact-apply` · `redact-verify FILE` | find terms, burn boxes into a PDF, confirm they are gone |
| `verify-draft FILE [--offline]` · `lint FILE [--rules F]` | citation checking, draft rules |
| `report [--days N]` · `contacts` · `roles` · `workflow-check FILE` | pipeline health, config inspection |
| `anchor` | verify the approval chain, print its head |

`doctor` exits non-zero if anything is misconfigured. Commands exit with a
one-line message rather than a traceback when the cause is config or input.

## Writing a gate

A gate is a class with an `id` and a `check()` returning findings.

```console
$ docketry new-gate zip-screen
wrote docketry-home/gates/zip_screen.py

$ docketry try-gate zip-screen --attach "discovery.zip"
gate:    zip-screen (file:gates/zip_screen.py)
message: 'Test message' from someone@example.com, 1 attachment(s)
result:  [fail] discovery.zip is a zip archive
```

Add four lines to `guardrails.toml` and it runs on every message, held and
released like any shipped gate. Gates load from `<home>/gates/*.py` or from an
installed package declaring a `docketry.gates` entry point.

**[GATES.md](GATES.md)** — walkthrough and reference.
**[ARCHITECTURE.md](ARCHITECTURE.md)** — diagrams, data model, module map.

## Audit log

Every finding and every approval is a row in `store/docketry.db`. Approvals are
hash-chained: each row stores a SHA-256 over its own fields plus the previous
row's digest, so an edited, deleted, reordered or inserted approval stops
verifying. `doctor` checks the chain; `anchor` verifies it and prints the head:

```console
$ docketry anchor
docketry-anchor 2026-08-30T02:27:55+00:00 approvals=118 head=9f2c...e41
```

An intact chain means no row changed in place. It does not mean the log is
authentic: the database is on the firm's disk with no key, so anyone who can
edit a row can recompute every digest after it.
[`tests/test_chain.py`](tests/test_chain.py) does exactly that and asserts the
rewritten chain verifies. Detecting a rewrite requires a copy of the head kept
where it cannot be edited — mail it, print it, or let `docketry digest` carry
it into a daily summary.

Approvals written before v0.16 carry no digest. They are counted and reported
as unchained rather than back-filled.

## Local model (optional)

Docketry works fully without a model and calls one only if `[llm]` is set. The
hostname is resolved and every returned address checked before a request is
built; unless all of them are loopback, private-range or link-local, the
request is refused. The vetted address is the one dialled, and a 3xx response
is refused rather than followed.

Any OpenAI-compatible server works: Ollama, llama.cpp, vLLM, LM Studio.
Reasoning models' `<think>` narration is separated from the answer rather than
returned as it.

A model proposes. It never releases a hold, applies a classification, chooses
what to redact, or advances a stage. `tests/test_llm.py` asserts that no gate,
the pipeline runner, and the redaction path import the model client.

## What it does not do

- **Not hosted.** No server, no telemetry, no account. Nothing leaves the machine.
- **Not case management.** No billing, trust accounting, client portal or calendar sync.
- **Not access control.** No login; roles are attestations.
- **Not a security product.** No malware or phishing claims. `attachment-policy`
  is pipeline policy, not antivirus.
- **Not encrypted at rest.** Messages and attachments are plaintext on disk,
  protected by file permissions. Use full-disk encryption.
- **No currency guarantee.** Docketry never claims a rule, deadline or citation
  is current. It checks inputs against sources you point it at, and fails
  loudly when it cannot.

## Skills

`skills/` holds nine agent skills for Claude Code or any Agent
Skills-compatible harness: `intake-triage`, `classify-document`,
`review-draft`, `redact-document`, `build-timeline`, `reconcile-docket`,
`manage-matter`, `pipeline-health`, `assign-contacts`. Install with
`cp -r skills/* .claude/skills/`.

Each drives the same CLI the pipeline uses and carries explicit limits: no
citation verified from model knowledge, no classification applied without a
named approver, no hold released by the agent. Each ships an eval suite in
`claude plugin eval` format, and a test fails the build if one does not.

## Development

```console
$ python -m unittest discover -s tests          # 437 tests
```

`tests/test_boundaries.py` asserts `docketry/core/` imports nothing from
`tools/`, the CLI or the UI, and caps the port at 12 files and 2,500 lines.
`tests/test_first_gate.py` executes GATES.md step by step. `tests/test_examples.py`
loads every shipped example and checks the skills' eval suites.

## License

Apache-2.0. [SECURITY.md](SECURITY.md) covers what is in scope for a report and
how to send one without pasting client data into a public tracker.
