Metadata-Version: 2.4
Name: intentsity
Version: 1.0.0
Summary: IntensityIntent v1 wire contract: encoder, decoder, capability handshake, conformance vectors
Author: TechnoPerVRt
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Dynamic: license-file

# intentsity

The **IntensityIntent v1** wire contract: one encoder, one decoder, one
capability handshake, one set of conformance vectors.

Every source that drives a toy through a hub speaks this format. Before this
package existed there were five independent encoders of it, and they did not
agree — which is how a source ended up emitting datagrams the hub could not
attribute, making session-mode allowlists and exclusivity decorative rather
than enforced.

This package depends on nothing: not on an application, not on a third party,
not on an address. That is the whole point — it is small enough to pin.

## Install

```bash
pip install "intentsity==1.0.0"
```

Pin an exact version, not a range. Then check at import or connect, whichever
comes first:

```python
from intentsity import require_attribution
require_attribution()
```

## Use

```python
from intentsity import IntensityIntent, encode_bytes, decode_bytes

sock.sendto(
    encode_bytes(IntensityIntent(intensity=0.42, device="toy-a",
                                 role="kick", source="cadence")),
    (host, port),
)

intent = decode_bytes(datagram)      # None if it is not a well-typed v1 intent
if intent is not None and not intent.stop:
    mix[intent.mix_role()] = intent.intensity
```

| Symbol | What it is for |
|---|---|
| `IntensityIntent` | The frozen dataclass. `mix_role()` collapses the role vocabulary to `base`/`kick`/`rail`/`hit`. |
| `parse_intent(dict)` | Decode an already-parsed JSON object. Returns `None`, never raises. |
| `decode_bytes(bytes \| str)` | Decode a datagram or text frame. Returns `None`, never raises. |
| `intent_to_dict(intent)` | Build the wire object. Raises `ContractError` rather than emit something unattributable. |
| `encode_bytes(intent)` | The exact bytes that go on the wire. |
| `require_attribution()` | The handshake. Raises `CapabilityError` on a drifted pin. |
| `load_vectors()` / `vectors_path()` | The conformance vectors, for your own test suite. |

## Capabilities, not version numbers

`require_attribution()` exists because a drifted git pin once silently
broadcast one person's intensity to every connected toy, with nothing anywhere
reporting it. A version number would not have caught that; a capability the
consumer can interrogate does. A capability name is a promise about behaviour;
capabilities are added when behaviour appears and never removed.

There are two ways a stale pin fails, and both are loud:

- recent enough to have the symbol, too old to have the behaviour →
  `CapabilityError` naming the missing capability and the fix;
- older than the symbol itself → `ImportError` on the import line. Absence of
  the marker is **not** a pass; the installs the check exists to catch are
  exactly the ones that lack it.

This build provides `intent-v1`, `attribution-v1`, `reject-nonfinite-v1`.

## Conformance vectors

`src/intentsity/vectors/intent-v1.json` is the canonical spec. It is plain,
strict JSON — no comments, no `NaN`, no language-specific constructs — because
the second implementation of this contract is C# and will not get a Python
port. **A non-Python reader consumes that file unchanged.** Two conventions
make that possible:

- `decode[].input` is raw wire **text**, not a JSON value, so truncated bytes,
  non-JSON junk and the bare `NaN` literal stay representable while the vector
  file itself stays parseable.
- `encode[].intensity_special` (`nan` / `inf` / `-inf`) carries the encode
  inputs JSON cannot hold.

Expectations are objects compared as unordered maps; numbers compare
numerically; errors are stable codes (`source_required`,
`unsupported_version`, `intensity_not_finite`), never message text. The file's
own `notes` array repeats all of this for a reader who arrives with no other
context.

## Strict out, typed in

**Emission is strict.** `intent_to_dict` refuses to build a datagram with no
`source` (the receiver could not attribute it), or one claiming a version this
package does not implement, or one carrying a non-finite intensity.

**Decoding stays liberal about what is missing** — the lossy subset with no
`v` and no `source` still parses, because v1 is valid forever on a deployed
profile — **and strict about types.** The following were previously coerced and
are now rejected:

| Input | Was | Now | Why |
|---|---|---|---|
| `{"intensity": NaN}` | **1.0 — full intensity** | rejected | `max(0, min(1, nan))` returns `1.0` |
| `{"intensity": Infinity}` | 1.0 | rejected | same class of input |
| `{"stop": "no"}` | **a stop** | rejected | truthiness is not a boolean |
| `{"intensity": true}` | 1.0 | rejected | in Python a bool is an int |
| `{"intensity": "0.5"}` | 0.5 | rejected | a numeric string is a type error, and coercing it makes implementations disagree across languages |
| `{"v": "abc"}` | **`ValueError` out of the parser** | rejected | the old parser raised; the hub's receive loop does not guard the call |
| `{"v": 2}` | parsed as v1 | rejected | half-obeying an envelope you do not understand is worse than dropping it |
| `{"v": 0}` | parsed as v1 | rejected | no version zero was ever issued |
| `{"role": 5}` | `"5"` | rejected | type error |

Rejection is always the safe direction: a receiver that drops a message falls
through to its dead-man and zeroes. No rejection in this package can raise the
intensity of anything.

## Scope

v1 only. `seq`, `ts`, `session`, `kind` and scoped-stop semantics belong to the
v2 envelope and are deliberately absent — a v2 message is rejected here rather
than partially executed.
