|
1 | | -# social-alignment |
| 1 | +# CLAUDE.md — social-alignment |
2 | 2 |
|
3 | | -A deterministic pre-action **five-lens compass** for AI agents. The |
4 | | -alignment pillar of the NSE platform. Before an agent takes a significant |
5 | | -action, five lenses evaluate it and the enclave decides whether to proceed, |
6 | | -inform, ask, or halt. |
| 3 | +## What this is |
| 4 | +A deterministic five-lens pre-action compass for AI agents. Part of the open-source OpenClaw Nostr toolkit. MIT licensed. |
7 | 5 |
|
8 | | -**Import:** `pip install social-alignment` → `from social_alignment import AlignmentEnclave` |
9 | | - |
10 | | -Zero runtime dependencies. Does **not** depend on `nostrkey`. |
11 | | - |
12 | | -## Build & Test |
| 6 | +## Install |
| 7 | +``` |
| 8 | +pip install social-alignment |
| 9 | +``` |
13 | 10 |
|
14 | | -```bash |
| 11 | +## Develop |
| 12 | +``` |
| 13 | +python -m venv .venv && . .venv/bin/activate |
15 | 14 | pip install -e ".[dev]" |
16 | | -ruff check . |
17 | | -pytest -q |
| 15 | +python -m pytest -q # tests |
| 16 | +python -m build # sdist + wheel |
18 | 17 | ``` |
19 | 18 |
|
20 | | -## Structure |
21 | | - |
| 19 | +## Layout |
22 | 20 | - `src/social_alignment/` — package source |
23 | | - - `types.py` — enums (`ActionDomain`, `Lens`, `Severity`, `EscalationLevel`) and frozen |
24 | | - dataclasses (`ActionContext`, `LensResult`, `Projection`, `EscalationDecision`, |
25 | | - `CheckResult`, `Decision`, `AlignmentConfig`) |
26 | | - - `enclave.py` — the five pure lens functions, `_aggregate`, `_escalate`, `evaluate`, |
27 | | - and `AlignmentEnclave` (main entry point + in-memory decision log) |
28 | | -- `tests/` — pytest suite (known-answer + per-lens unit tests) |
29 | | -- `examples/basic_usage.py` — runnable example |
30 | | -- `clawhub/` — OpenClaw skill metadata |
31 | | - |
32 | | -## Publish |
33 | | - |
34 | | -```bash |
35 | | -# PyPI (needs API token + OTP) |
36 | | -python3 -m build |
37 | | -python3 -m twine upload dist/social_alignment-X.Y.Z* |
38 | | - |
39 | | -# ClawHub |
40 | | -npx clawhub publish ./clawhub --slug social-alignment --name "Social Alignment" \ |
41 | | - --version X.Y.Z --tags latest --changelog "..." |
42 | | -``` |
43 | | - |
44 | | -**Version must be bumped in 4 places:** `pyproject.toml`, `src/social_alignment/__init__.py` |
45 | | -(`__version__`), `clawhub/metadata.json`, and `clawhub/SKILL.md` (frontmatter `version:`). |
46 | | - |
47 | | -> Note: PyPI already carries `0.1.0` and `0.1.1`; ClawHub metadata had reserved `0.1.4`, |
48 | | -> and two divergent `0.1.5` builds were published/pushed. This build is `0.1.6` to stay |
49 | | -> ahead of all prior versions and requires a republish. |
| 21 | +- `tests/` — pytest suite |
| 22 | +- `clawhub/` — ClawHub skill metadata (SKILL.md, metadata.json) |
50 | 23 |
|
51 | 24 | ## Conventions |
52 | | - |
53 | | -- Python 3.10+, hatchling build, ruff linter (100 char line length) |
54 | | -- **Zero runtime dependencies.** Do not add any — this pillar must install standalone. |
55 | | -- Import matches package name: `pip install social-alignment` → `from social_alignment import ...` |
56 | | -- The five lenses are pure functions: same `ActionContext` + `AlignmentConfig` → same result. |
57 | | -- Severity ordering (`IntEnum`): `CLEAR=0 < CAUTION=1 < YIELD=2 < STOP=3`. Aggregate = max. |
58 | | -- `STOP` always defers to the human: `record_proceeded()` on a STOP without |
59 | | - `owner_overrode=True` raises `RuntimeError`. Enforced in code, no workaround. |
60 | | -- `AlignmentEnclave.create(owner_npub=..., owner_name=..., **overrides)` filters unknown |
61 | | - overrides against `AlignmentConfig` fields — the orchestrator passes a superset and must |
62 | | - never trigger a `TypeError`. `check(...)` filters unknown context kwargs the same way. |
63 | | -- Decision log is in-memory only (no persistence in this minimal build). |
64 | | -- Frozen dataclasses everywhere in `types.py`. |
65 | | - |
66 | | -## Orchestrator contract |
67 | | - |
68 | | -`nse-orchestrator`'s `entity.py` calls |
69 | | -`AlignmentEnclave.create(owner_npub=..., owner_name=...)` then |
70 | | -`.check(domain=..., description=..., **context)`. The orchestrator's `alignment` extra already |
71 | | -references `social-alignment`; no orchestrator code change is needed. |
| 25 | +- Python + pyproject (hatchling). Pure-Python crypto (`cryptography`), zero native build deps. |
| 26 | +- Public, MIT-licensed, open source. |
0 commit comments