Metadata-Version: 2.5
Name: pluvy
Version: 0.0.2
Summary: Read-only, parser-backed engineering policy gate for Python, Go, Java, JavaScript and TypeScript
Project-URL: Homepage, https://sectrend-cn.github.io/pluvy/
Project-URL: Repository, https://github.com/sectrend-cn/pluvy
Project-URL: Documentation, https://sectrend-cn.github.io/pluvy/docs/getting-started/
Project-URL: Issues, https://github.com/sectrend-cn/pluvy/issues
Author: Sectrend Information Technology Co., Ltd.
License-Expression: MIT
License-File: LICENSE
Keywords: ai-agents,architecture,ci,code-quality,code-review,engineering-standards,linter,policy,static-analysis,tree-sitter
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Go
Classifier: Programming Language :: Java
Classifier: Programming Language :: JavaScript
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.12
Requires-Dist: agent-client-protocol<0.13,>=0.12.1
Requires-Dist: mcp<2,>=1.26
Requires-Dist: pydantic<3,>=2.10
Requires-Dist: tree-sitter-go<0.26,>=0.25
Requires-Dist: tree-sitter-java<0.24,>=0.23
Requires-Dist: tree-sitter-javascript<0.26,>=0.25
Requires-Dist: tree-sitter-python<0.26,>=0.25
Requires-Dist: tree-sitter-typescript<0.24,>=0.23
Requires-Dist: tree-sitter<0.26,>=0.25
Description-Content-Type: text/markdown

# Pluvy

[![PyPI](https://img.shields.io/pypi/v/pluvy)](https://pypi.org/project/pluvy/)
[![Python](https://img.shields.io/pypi/pyversions/pluvy)](https://pypi.org/project/pluvy/)
[![License](https://img.shields.io/pypi/l/pluvy)](LICENSE)

**An engineering policy gate for code written by people and coding agents.**
Pluvy parses Python, Go, Java, JavaScript/JSX and TypeScript/TSX with
tree-sitter and fails the build when a change erases type contracts, swallows
errors, weakens or deletes tests, or crosses the architecture boundaries your
repository declares.

Website: [sectrend-cn.github.io/pluvy](https://sectrend-cn.github.io/pluvy/)

```text
$ pluvy --all
src/orders.py:4:25: type.broad: Do not erase contracts with typing.Any
tests/test_orders.py:5:5: test.tautology: Assertion in test_load cannot fail because it restates the same expression or a literal true. Assert an independently produced value or outcome instead.
tests/test_orders.py:6:5: warning: unused.return: Return value from 'load' is discarded
Diagnostic scope: full_files.
Usage reference scope: 2 files.
Architecture all: 2 files; 3 findings.
```

## Why Pluvy

- **One policy, five languages.** A single committed `.pluvy/pluvy.json`
  drives the same checkers across every supported language.
- **Architecture as data.** Declare owners, placements and forbidden import
  directions; the gate enforces them on every change.
- **Built for agent-written code.** It catches shortcuts that keep CI green
  without doing the work: tautological or assertion-free tests, deleted tests
  and eroded assertions, swallowed exceptions, literal fallback chains, casts
  and `Any`.
- **Change-aware.** `--base` and `--staged` report only the definitions and
  statements a change touches, so existing debt does not block new work.
- **Read-only.** No mode modifies, stages, stashes, restores or deletes source
  files, and none changes Git configuration. It is safe to run in CI, in hooks
  and inside agent sessions.

## What it checks

22 checkers, all enabled by default:

| Area | Checkers |
| --- | --- |
| Type contracts | `type.broad`, `type.annotation`, `type.signature`, `type.boundary`, `type.assertion`, `type.contract` |
| Test integrity | `test.integrity` (tautological and vacuous tests), `test.deletion` (removed tests, assertion erosion, changed snapshots) |
| Error handling | `flow.handling` (swallowed handlers, long `??` literal fallbacks) |
| Architecture | `architecture.owner`, `architecture.structure`, `architecture.import`, `architecture.dispatch`, `architecture.object_model` |
| Dead code | `unused.parameter`, `unused.function`, `unused.field`, `unused.return` |
| Structure and size | `function_size`, `structure.guarded_projection`, `imports.wildcard` |
| Suppression hygiene | `type.suppression` (foreign and malformed suppression directives) |

Options, defaults, per-language coverage and known limits are listed in
[Checker configuration](docs/checker-configuration.md).

## Quick start

Python 3.12 or newer is required. Install the published command line from
[PyPI](https://pypi.org/project/pluvy/):

```sh
uv tool install pluvy
```

Without uv, use `python -m pip install pluvy`. To try it once without
installing, run `uvx pluvy --all`.

Add a policy to the repository you want to check and commit it:

```sh
mkdir -p .pluvy
echo '{"version": 2, "include": ["src/*", "tests/*"], "checkers": {}}' > .pluvy/pluvy.json
```

Then run one of the three modes:

```sh
pluvy --all                 # audit every selected file, including existing debt
pluvy --base origin/main    # audit only what changed since a commit
pluvy --staged              # audit the Git index before committing
```

Add `--root /path/to/project` to run from another directory and
`--format json` for machine-readable output.

| Exit code | Meaning |
| --- | --- |
| `0` | No error findings; warnings may be present |
| `1` | At least one error finding |
| `2` | Configuration, encoding, filesystem or Git failure |

[Getting started](docs/getting-started.md) covers installation options, building
up a policy, triaging the first audit of an existing repository and per-task
gating. A [Chinese translation](docs/zh/getting-started.md) is available.

## Adopting on an existing repository

The first `--all` on an existing codebase usually exits `1`. That is the
baseline reading, not a failure of the tool. A practical path:

1. Gate pull requests with `--base` so new changes are held to the policy.
2. Work through the `--all` findings over time: fix the code first.
3. Treat threshold, exclusion and owner changes as architecture decisions, each
   with its own full audit and review. A staged policy change is refused until
   that audit passes.

Exceptions use an approved next-line suppression that names one rule and a
reason; see [comment suppressions](docs/comment-suppressions.md).

## Policy

Each target repository owns `.pluvy/pluvy.json`; paths inside it are relative to
the repository root. Start from [the example policy](examples/.pluvy/pluvy.json),
which declares owners, an import boundary and size limits:

```json
{
  "version": 2,
  "include": ["src/*", "tests/*"],
  "exclude": [],
  "checkers": {
    "function_size": {"lines": 50, "complexity": 10},
    "architecture.import": {
      "boundaries": [
        {
          "name": "domain does not depend on adapters",
          "sources": ["src/domain/*"],
          "forbidden_imports": ["adapters", "adapters.*"]
        }
      ]
    }
  }
}
```

Specify `"enabled": false` only to turn a checker off; omitted checkers and
options keep their defaults.

## Integration

### Coding agents

The bundled skill in `.agents/skills/pluvy/` tells an agent when the gate
applies, which mode to run after a task and how to report the result. The PyPI
package contains the tool only, so copy the skill from this repository into the
consuming project's skills directory, or point to it from `AGENTS.md`. See
[Agent integration](docs/getting-started.md#agent-integration).

### CI

Any CI system that can install a Python package can run the same commands.
This repository gates itself in
[GitHub Actions](.github/workflows/engineering.yml).

### Pre-commit

Once the policy is committed, a pre-commit hook can run `pluvy --staged`.
Install hooks yourself; Pluvy never changes Git configuration.

## Extending

Language plugins own suffixes and grammar interpretation; rules implement
`RuleBundle` over a shared `TreeContext`. See
[Plugin architecture](docs/plugin-architecture.md).

Agent review rules are a programmatic extension point: they are registered in
Python, not enabled from the JSON policy, and invoke an ACP agent that submits
findings through MCP tools. See [Agent review](docs/agent-review.md).

## Development

Set up a development environment from this checkout:

```sh
python -m pip install --no-cache-dir uv==0.8.22
uv sync --locked --group dev
. .venv/bin/activate
```

The required checks are listed in `AGENTS.md` and run in
[the engineering workflow](.github/workflows/engineering.yml). Shared code
policy lives in [Engineering standards](docs/engineering-standards.md).

## License

[MIT](LICENSE)
