Metadata-Version: 2.4
Name: licwatch
Version: 0.2.2
Summary: Dependency license-change detector — CI gate that diffs published license metadata per dependency per version and fails the build when a license changes, goes unknown, or adds obligations
Author-email: "Calas Automations Inc." <office@calasautomations.com>
License: MIT
Project-URL: Homepage, https://calasautomations.com
Project-URL: Repository, https://github.com/calasdan-sketch/licwatch
Project-URL: Issues, https://github.com/calasdan-sketch/licwatch/issues
Project-URL: Changelog, https://github.com/calasdan-sketch/licwatch/blob/main/CHANGELOG.md
Keywords: license,compliance,supply-chain,npm,pypi,spdx,ci
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

<!-- Image URLs are absolute on purpose: GitHub resolves relative paths, PyPI does not. -->
![licwatch: catch a dependency's license change before you ship it.](https://raw.githubusercontent.com/calasdan-sketch/licwatch/main/docs/brand/licwatch-banner.png)

**A CI check that fails your build when a dependency changes license, goes unknown, or adds obligations.**

```sh
pip install git+https://github.com/calasdan-sketch/licwatch.git
```

Needs Python 3.11 or newer (check with `python --version`). Not on PyPI yet; once it is, `pip install licwatch` will work.

```text
$ licwatch baseline
baseline written: licwatch-baseline.json (1 dependencies)
$ licwatch check
PASS: no license changes
  note: read package.json (1 entries)
```

*Real output from a throwaway folder whose `package.json` pins `left-pad` 1.3.0. For what a failing check looks like, see [Example output](#example-output).*

- **Diffs published licenses, not your code.** For every pinned dependency it compares the license the registry publishes (and the LICENSE file inside the tarball) against a baseline you commit.
- **Says what changed and what it obligates you to.** Relicense, unknown license, new copyleft or source-available terms, new dependency: each flag names the exact change.
- **Runs anywhere, asks for nothing.** Standard library only, no keys, no accounts, no telemetry; reads public npm and PyPI.

![License](https://img.shields.io/badge/license-MIT-blue)
![Python](https://img.shields.io/badge/python-%3E%3D3.11-blue)

## Quickstart

```sh
licwatch scan        # what licenses are in this project right now?
licwatch baseline    # record them; commit licwatch-baseline.json
licwatch check       # CI gate: exit 1 on any license flag, 0 when clean
```

`licwatch --help` lists every command with examples. Add `licwatch check` to CI (see [CI example](#ci-example)).

## Limits up front

- **Team tier features** (policy packs, legal review queue) — planned
  paid tier, deliberately out of the free core.
- **Private registries** — public npm and PyPI only.
- **yarn.lock / pnpm-lock** — custom formats without a stdlib
  parser; npm's package-lock covers the default toolchain.
- **SBOM export, dashboards, auto-fix, compatibility matrices** —
  refused, not deferred. licwatch is the gate: it reports what
  changed and what it obligates, it never inventories for its own
  sake, never changes your build, and never adjudicates whether
  two licenses combine. See REVIEW.md for the panel's reasoning.
- **Legal advice** — licwatch reports what changed and what the
  license obligates in general terms. It is not a lawyer; a flagged
  relicense means "a human reviews this before shipping", not a
  verdict on your specific use.

## Why this exists

A dependency changes license in a minor bump and your legal exposure
changes overnight with no code change at all. Elasticsearch (2021),
Terraform (2023), and Redis (2024) each moved to source-available
licenses (as of 2025, Elasticsearch and Redis have since added AGPL-3.0
as an option). Few teams watch licenses; most watch CVEs.

licwatch is the CI gate for that gap. It diffs published license
metadata per dependency per version against a baseline lockfile and
fails the build with the exact change:

- license changed (MIT → SSPL/BSL-style)
- license went unknown
- new obligations introduced (copyleft, source-available restrictions,
  new attribution requirements)
- new dependency added (new legal exposure)
- **license text changed inside the published tarball even though the
  registry metadata stayed the same** (the metadata blind spot —
  see below)

The whole report is one shape: **what changed, what it obligates you
to.**

## The tarball LICENSE-text layer

Registry metadata can lie by omission: a maintainer who changes the
LICENSE file without updating the metadata field is invisible to
metadata-only diffing. So licwatch also fingerprints the LICENSE file inside the
published tarball (whitespace-collapsed sha256 with copyright lines stripped, read in-memory —
never extracted to disk). At check time, only deps whose version
bumped AND whose metadata license is unchanged get a fingerprint
comparison — the only case where the layer adds signal, so the cost
stays bounded. A difference fails the gate as `LICENSE_TEXT_CHANGED`.

The same layer identifies licenses from LICENSE text when metadata
is UNKNOWN or says "SEE LICENSE IN LICENSE" (most such packages are
MIT/Apache with text in the file, not proprietary). Identification
uses distinctive grant phrases in the head of the file only, so
third-party notice sections can't false-positive a proprietary file
into an open license. A fetch failure degrades to a
"license-text unverified" note, never a gate failure — the metadata
gate stays primary. `--no-text` skips the layer entirely.

## Install (local)

```sh
pip install .
# or, for development:
pip install -e .
```

Requires Python 3.11+ (stdlib `tomllib`). No third-party dependencies, no keys, no
accounts, no telemetry, no phone-home. Registry reads are public,
unauthenticated GETs to registry.npmjs.org and pypi.org.

## Usage

```sh
# What licenses are in this project right now?
licwatch scan

# Record the baseline (commit licwatch-baseline.json)
licwatch baseline

# The CI gate: exit 1 on any license flag, 0 when clean
licwatch check

# Human-readable summary (never fails the build)
licwatch report

# Accept ONE flagged dependency into the baseline (the rest stay flagged)
licwatch accept redis

# What changes if I bump this package? (a query, never a gate)
licwatch whatif redis@5.0.0
```

Options: `--path <dir>` (default: current directory),
`--ecosystem npm|pypi|all` (default: all),
`--include-dev` (include devDependencies / dev lock entries),
`--json` (machine-readable output),
`--baseline <file>` (check/report),
`--allow-added` (check: treat new dependencies as notes, not failures),
`--allow-unpinned` (check: do not fail on unpinned dependencies),
`--no-text` (baseline/check/report: skip the tarball LICENSE-text layer),
`--jobs <n>` (parallel registry fetch workers, default 8),
`--output <file>` (baseline).

Exit codes: `0` pass/clean, `1` gate failed, `2` usage or resolution
error (missing baseline, malformed manifest, registry failure, or
unverified dependencies — see below).

A green gate means every dependency licwatch could read was checked
against the baseline. It does not cover what licwatch cannot see:
git/URL/editable installs are listed as notes only, and every
pinned version is compared (if a lockfile holds several versions of one
package, each is its own baseline entry, keyed `npm:name@version`). `check`
exits 2 when any dependency is unpinned (it cannot be checked — pin it
or commit a lockfile, or pass `--allow-unpinned` to knowingly proceed)
and when any registry fetch fails (the failing dep is reported as an
error, never misreported as removed, and findings for resolved deps
are still printed).

Manifests read: `package.json`, `package-lock.json` (locked versions
win over ranges), `requirements.txt` (with `-r` includes followed,
and `-c`/`--constraint` files followed the same way: a name left
unpinned in requirements but pinned with `==` in a constraints file
is checked at that pin; names only in constraints are not added),
`pyproject.toml` (PEP 621 dependencies), `Pipfile.lock`,
`poetry.lock`, `uv.lock` (registry packages only; git/path/editable
sources are noted, and the project itself is excluded; uv.lock does
not mark dev packages individually, so all locked packages are
checked, as with poetry.lock). Lockfiles win over plain manifests — they describe
the resolved tree including transitive deps. Only pinned versions
are checked — an unpinned range has no single published license, so
it is reported as skipped, never silently resolved to "latest".
URL/editable installs are noted, not vanished.

## Accepting a change (the workflow)

```sh
licwatch check        # FAIL: redis 4.0.0 -> 5.0.0: BSD-3-Clause -> BUSL-1.1
# ... human reviews the change ...
licwatch accept redis # updates ONLY redis in the baseline
licwatch check        # every other flag still fails; redis is clean
```

`licwatch accept redis --reason "legal OK'd BUSL for internal use,
ticket LEG-42"` stores the reason on that baseline entry, with a UTC
timestamp and the from/to licenses. `--reason` is optional; without
it the entry records `reason: null`. `licwatch report` prints each
accepted change with its recorded reason (or "no reason recorded").
It is a record of what someone wrote, not an approval: licwatch does
not check who accepted or whether the reason is sound.

Re-running `baseline` to accept one change would silently bless
every other drift since the last baseline. `accept` exists so that
never happens: one reviewed change, one updated entry.

## CI

When `GITHUB_ACTIONS=true` is set, `check` additionally prints
`::error` annotations for failing dependencies, so flags appear
inline on the PR. No flags, no setup — it auto-detects.

Registry hiccups: HTTP 429, 5xx, timeouts and network errors are
retried up to twice (waiting 1 s, then 3 s, or the server's
`Retry-After` capped at 10 s). A 404 is never retried. If all 3
attempts fail, the dependency is reported as a registry error
("... after 3 attempts"), never as a pass.

## Example output

Clean check:

```
PASS: no license changes
```

Gate failing on a relicense (illustrative data, not a real npm release; BSD-3-Clause → BUSL-1.1):

```
FAIL: 2 license flag(s)
  [CHANGED] redis [npm] 4.0.0 -> 5.0.0: BSD-3-Clause -> BUSL-1.1
      obligates you to: preserve copyright and license notices (attribution)
      obligates you to: source-available license — commercial use or redistribution restricted; review terms before shipping
  [RESTRICTIVE_INTRODUCED] redis [npm] 4.0.0 -> 5.0.0: BSD-3-Clause -> BUSL-1.1
      obligates you to: preserve copyright and license notices (attribution)
      obligates you to: source-available license — commercial use or redistribution restricted; review terms before shipping
```

Gate failing on a newly added dependency:

```
FAIL: 1 license flag(s)
  [ADDED] redis [npm] added at 4.0.0: license MIT
      obligates you to: preserve copyright and license notices (attribution)
```

SPDX expressions are handled: `AND` takes the most restrictive term,
`OR` takes the least restrictive (the licensee may choose), and
`WITH` exceptions keep the base license's category. An identifier
licwatch cannot classify is reported as unknown — never silently
treated as permissive.

## CI example

```yaml
- run: pip install .
- run: licwatch check
```

Commit `licwatch-baseline.json` and review it like a lockfile: every
entry is a legal fact about your build. The baseline records when it
was generated and which manifests were read.

## License

MIT — see [LICENSE](https://github.com/calasdan-sketch/licwatch/blob/main/LICENSE). Changes: [CHANGELOG.md](https://github.com/calasdan-sketch/licwatch/blob/main/CHANGELOG.md). Panel review notes: [REVIEW.md](https://github.com/calasdan-sketch/licwatch/blob/main/REVIEW.md).

---

Made by Calas Automations (CAL-us). Need help? Call Cara 431-244-9026.
