memex-python 0.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. memex_python-0.13.0/.github/workflows/release.yml +105 -0
  2. memex_python-0.13.0/.github/workflows/test.yml +38 -0
  3. memex_python-0.13.0/.gitignore +16 -0
  4. memex_python-0.13.0/LICENSE +190 -0
  5. memex_python-0.13.0/PKG-INFO +150 -0
  6. memex_python-0.13.0/PLAN.md +189 -0
  7. memex_python-0.13.0/README.md +131 -0
  8. memex_python-0.13.0/pyproject.toml +41 -0
  9. memex_python-0.13.0/renovate.json +4 -0
  10. memex_python-0.13.0/src/memex/__init__.py +336 -0
  11. memex_python-0.13.0/src/memex/_time.py +26 -0
  12. memex_python-0.13.0/src/memex/_uuid.py +62 -0
  13. memex_python-0.13.0/src/memex/bulk.py +138 -0
  14. memex_python-0.13.0/src/memex/commands.py +75 -0
  15. memex_python-0.13.0/src/memex/envelope.py +69 -0
  16. memex_python-0.13.0/src/memex/errors.py +51 -0
  17. memex_python-0.13.0/src/memex/factories.py +97 -0
  18. memex_python-0.13.0/src/memex/graph.py +30 -0
  19. memex_python-0.13.0/src/memex/integrity.py +317 -0
  20. memex_python-0.13.0/src/memex/intent.py +318 -0
  21. memex_python-0.13.0/src/memex/models.py +271 -0
  22. memex_python-0.13.0/src/memex/query.py +435 -0
  23. memex_python-0.13.0/src/memex/reducer.py +151 -0
  24. memex_python-0.13.0/src/memex/replay.py +144 -0
  25. memex_python-0.13.0/src/memex/retrieval.py +266 -0
  26. memex_python-0.13.0/src/memex/schemas.py +67 -0
  27. memex_python-0.13.0/src/memex/serialization.py +47 -0
  28. memex_python-0.13.0/src/memex/stats.py +71 -0
  29. memex_python-0.13.0/src/memex/store.py +222 -0
  30. memex_python-0.13.0/src/memex/task.py +361 -0
  31. memex_python-0.13.0/src/memex/transplant.py +480 -0
  32. memex_python-0.13.0/tests/support.py +47 -0
  33. memex_python-0.13.0/tests/test_bugfix_and_coverage.py +517 -0
  34. memex_python-0.13.0/tests/test_bugfix_bulk_retract_cascade.py +85 -0
  35. memex_python-0.13.0/tests/test_bugfix_holes.py +385 -0
  36. memex_python-0.13.0/tests/test_bugfix_regressions.py +253 -0
  37. memex_python-0.13.0/tests/test_bugfix_reid_ordering.py +110 -0
  38. memex_python-0.13.0/tests/test_bugfix_surface_contradictions_dedup.py +83 -0
  39. memex_python-0.13.0/tests/test_bugfix_sweep.py +430 -0
  40. memex_python-0.13.0/tests/test_bulk.py +161 -0
  41. memex_python-0.13.0/tests/test_cross_graph_fields.py +157 -0
  42. memex_python-0.13.0/tests/test_edge_cases.py +336 -0
  43. memex_python-0.13.0/tests/test_edge_cases_v2.py +188 -0
  44. memex_python-0.13.0/tests/test_envelope.py +73 -0
  45. memex_python-0.13.0/tests/test_graph.py +34 -0
  46. memex_python-0.13.0/tests/test_helpers.py +174 -0
  47. memex_python-0.13.0/tests/test_integrity.py +265 -0
  48. memex_python-0.13.0/tests/test_intent.py +188 -0
  49. memex_python-0.13.0/tests/test_phase1_foundation.py +141 -0
  50. memex_python-0.13.0/tests/test_query.py +424 -0
  51. memex_python-0.13.0/tests/test_query_advanced.py +174 -0
  52. memex_python-0.13.0/tests/test_reducer.py +312 -0
  53. memex_python-0.13.0/tests/test_replay.py +89 -0
  54. memex_python-0.13.0/tests/test_retrieval.py +420 -0
  55. memex_python-0.13.0/tests/test_serialization.py +107 -0
  56. memex_python-0.13.0/tests/test_setup.py +7 -0
  57. memex_python-0.13.0/tests/test_stats.py +80 -0
  58. memex_python-0.13.0/tests/test_store.py +69 -0
  59. memex_python-0.13.0/tests/test_task.py +218 -0
  60. memex_python-0.13.0/tests/test_transplant.py +339 -0
  61. memex_python-0.13.0/tests/test_types.py +161 -0
  62. memex_python-0.13.0/uv.lock +771 -0
@@ -0,0 +1,105 @@
1
+ name: Release to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+ inputs:
8
+ version:
9
+ description: "Version to release (leave empty to use pyproject.toml version)"
10
+ required: false
11
+ type: string
12
+
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: true
18
+ matrix:
19
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
20
+
21
+ steps:
22
+ - uses: actions/checkout@v6
23
+
24
+ - name: Install uv
25
+ uses: astral-sh/setup-uv@v7
26
+ with:
27
+ enable-cache: true
28
+
29
+ - name: Set up Python ${{ matrix.python-version }}
30
+ run: uv python install ${{ matrix.python-version }}
31
+
32
+ - name: Install dependencies
33
+ run: uv sync --all-extras
34
+
35
+ - name: Lint
36
+ run: uv run ruff check .
37
+
38
+ - name: Type-check
39
+ run: uv run mypy
40
+
41
+ - name: Run tests
42
+ run: uv run pytest --tb=short
43
+
44
+ build:
45
+ needs: test
46
+ runs-on: ubuntu-latest
47
+
48
+ steps:
49
+ - uses: actions/checkout@v6
50
+
51
+ - name: Install uv
52
+ uses: astral-sh/setup-uv@v7
53
+ with:
54
+ enable-cache: true
55
+
56
+ - name: Set up Python
57
+ run: uv python install 3.13
58
+
59
+ - name: Update version from release tag
60
+ if: github.event_name == 'release'
61
+ run: |
62
+ # GITHUB_REF_NAME is the tag (e.g. "v0.13.0"); strip an optional 'v'.
63
+ VERSION="${GITHUB_REF_NAME#v}"
64
+ if [[ ! "$VERSION" =~ ^[0-9] ]]; then
65
+ echo "::error::Could not derive a version from tag '${GITHUB_REF_NAME}'. Tag the release like 'v0.13.0'."
66
+ exit 1
67
+ fi
68
+ sed -i -E "s|^version = \".*\"|version = \"${VERSION}\"|" pyproject.toml
69
+ echo "Building version: ${VERSION}"
70
+
71
+ - name: Update version from input
72
+ if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != ''
73
+ run: |
74
+ VERSION="${{ github.event.inputs.version }}"
75
+ if [[ ! "$VERSION" =~ ^[0-9] ]]; then
76
+ echo "::error::Invalid version input '${VERSION}'. Expected something like '0.13.0'."
77
+ exit 1
78
+ fi
79
+ sed -i -E "s|^version = \".*\"|version = \"${VERSION}\"|" pyproject.toml
80
+ echo "Building version: ${VERSION}"
81
+
82
+ - name: Build package
83
+ run: uv build
84
+
85
+ - name: Upload build artifacts
86
+ uses: actions/upload-artifact@v7
87
+ with:
88
+ name: dist
89
+ path: dist/
90
+
91
+ publish-pypi:
92
+ needs: build
93
+ runs-on: ubuntu-latest
94
+ permissions:
95
+ id-token: write
96
+
97
+ steps:
98
+ - name: Download build artifacts
99
+ uses: actions/download-artifact@v8
100
+ with:
101
+ name: dist
102
+ path: dist/
103
+
104
+ - name: Publish to PyPI
105
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,38 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [master, main]
6
+ pull_request:
7
+ branches: [master, main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v6
19
+
20
+ - name: Install uv
21
+ uses: astral-sh/setup-uv@v7
22
+ with:
23
+ enable-cache: true
24
+
25
+ - name: Set up Python ${{ matrix.python-version }}
26
+ run: uv python install ${{ matrix.python-version }}
27
+
28
+ - name: Install dependencies
29
+ run: uv sync --all-extras
30
+
31
+ - name: Lint
32
+ run: uv run ruff check .
33
+
34
+ - name: Type-check
35
+ run: uv run mypy
36
+
37
+ - name: Run tests
38
+ run: uv run pytest --tb=short
@@ -0,0 +1,16 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .venv/
9
+ venv/
10
+
11
+ # Tooling caches
12
+ .pytest_cache/
13
+ .mypy_cache/
14
+ .ruff_cache/
15
+ .coverage
16
+ htmlcov/
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 AI2070
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.4
2
+ Name: memex-python
3
+ Version: 0.13.0
4
+ Summary: MemEX memory layer (Pydantic port) — Multi-session continuity for AI systems
5
+ Author: ai2070
6
+ License: Apache-2.0
7
+ License-File: LICENSE
8
+ Keywords: agents,ai,knowledge-graph,memory,pydantic
9
+ Requires-Python: >=3.10
10
+ Requires-Dist: pydantic>=2.6
11
+ Provides-Extra: dev
12
+ Requires-Dist: mypy; extra == 'dev'
13
+ Requires-Dist: pytest-cov; extra == 'dev'
14
+ Requires-Dist: pytest>=8; extra == 'dev'
15
+ Requires-Dist: ruff; extra == 'dev'
16
+ Provides-Extra: fast-uuid
17
+ Requires-Dist: uuid-utils>=0.7; extra == 'fast-uuid'
18
+ Description-Content-Type: text/markdown
19
+
20
+ # memex-python
21
+
22
+ **Structured, provenance-tracked memory for AI agents — a faithful Pydantic port of [`@ai2070/memex`](https://www.npmjs.com/package/@ai2070/memex).**
23
+
24
+ MemEX stores beliefs, evidence, conflicts, and updates — not just retrieved text. It separates three graphs (what is *believed* / *wanted* / *done*) and makes retrieval, contradiction, decay, and identity first-class. This is the Python implementation: every typed structure is a Pydantic v2 model, and behavior matches the TypeScript original (the full upstream test suite is ported — **575 tests**).
25
+
26
+ - **Pure & immutable** — every mutation is `apply_command(state, cmd) -> (new_state, events)`.
27
+ - **Pydantic-native** — models validate on construction; the discriminated-union commands *are* the schema.
28
+ - **Wire-compatible** — command tags, enum values, and JSON keys are byte-identical to the TS library, so a Python service and a TS service can share one event log.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ pip install memex-python # import name: `memex`
34
+ ```
35
+
36
+ Only runtime dependency: `pydantic>=2.6`.
37
+
38
+ ## Quickstart (functional core)
39
+
40
+ ```python
41
+ from memex import create_graph_state, create_memory_item, apply_command, get_scored_items
42
+
43
+ state = create_graph_state()
44
+
45
+ obs = create_memory_item(
46
+ scope="user:laz/general",
47
+ kind="observation",
48
+ content={"key": "login_count", "value": 42},
49
+ author="agent:monitor",
50
+ source_kind="observed",
51
+ authority=0.9,
52
+ importance=0.7,
53
+ )
54
+ state, events = apply_command(state, {"type": "memory.create", "item": obs})
55
+
56
+ top = get_scored_items(state, {"authority": 1.0, "importance": 0.5})
57
+ ```
58
+
59
+ Filters, options, and weights accept plain dicts *or* the typed models:
60
+
61
+ ```python
62
+ from memex import get_items, smart_retrieve
63
+
64
+ recent = get_items(state, {"kind": "observation", "range": {"authority": {"min": 0.5}}})
65
+
66
+ packed = smart_retrieve(
67
+ state,
68
+ budget=2000,
69
+ cost_fn=lambda item: len(str(item.content)),
70
+ weights={"authority": 0.6, "importance": 0.4},
71
+ contradictions="surface", # or "filter"
72
+ diversity={"author_penalty": 0.2},
73
+ )
74
+ ```
75
+
76
+ ## Quickstart (`MemexStore` facade)
77
+
78
+ For a stateful, object-oriented surface that rebinds state for you:
79
+
80
+ ```python
81
+ from memex import MemexStore
82
+
83
+ store = MemexStore()
84
+ a = store.create(scope="user:laz", kind="observation", content={"v": 1},
85
+ author="agent:x", source_kind="observed", authority=0.9)
86
+ b = store.create(scope="user:laz", kind="assertion", content={"v": 2},
87
+ author="agent:y", source_kind="user_explicit", authority=0.4)
88
+
89
+ store.mark_contradiction(a.id, b.id, "system:detector")
90
+ store.resolve_contradiction(a.id, b.id, "system:resolver") # b's authority drops
91
+
92
+ intent = store.create_intent(label="find target", priority=0.9, owner="user:laz")
93
+ task = store.create_task(intent_id=intent.id, action="search", priority=0.8)
94
+
95
+ snapshot = store.dumps(pretty=True) # JSON; MemexStore.loads(...) restores
96
+ ```
97
+
98
+ ## The three graphs
99
+
100
+ | Graph | Reducer | Core type | Holds |
101
+ |--------|-------------------------|--------------|-----------------------------------------|
102
+ | Memory | `apply_command` | `MemoryItem` | beliefs, evidence, contradictions, edges|
103
+ | Intent | `apply_intent_command` | `Intent` | active goals with a status machine |
104
+ | Task | `apply_task_command` | `Task` | units of work tied to intents |
105
+
106
+ Each item carries three orthogonal `0..1` scores — **authority** (trust), **conviction** (author confidence), **importance** (current salience) — plus `kind`, `source_kind`, `parents` (provenance), and typed `edges` (`DERIVED_FROM`, `CONTRADICTS`, `SUPPORTS`, `ABOUT`, `SUPERSEDES`, `ALIAS`).
107
+
108
+ ## Validating external input
109
+
110
+ ```python
111
+ from memex.schemas import validate_command
112
+ from memex import apply_command
113
+
114
+ cmd = validate_command(raw) # raises pydantic.ValidationError on a bad shape
115
+ state = apply_command(state, cmd).state
116
+ ```
117
+
118
+ ## Intentional divergences from the TS library
119
+
120
+ 1. **Always-on validation** — constructing any model with an out-of-range score raises `pydantic.ValidationError` (TS only validated inside the factories). Use `Model.model_construct(...)` to bypass for deliberately-invalid fixtures.
121
+ 2. **Error types** — score-bound violations surface as `ValidationError`; `cost_fn` contract violations and unknown sort/decay enums as `ValueError` (the TS `RangeError`).
122
+ 3. **Frozen entities** — `MemoryItem` / `Edge` / `Intent` / `Task` are immutable; "edits" produce new instances (`model_copy(update=...)`).
123
+ 4. **`from_` field** — `from` is a Python keyword, so `Edge.from_` is the attribute; it serializes to `"from"` via its alias.
124
+
125
+ Everything else — command tags, JSON shape, scoring/decay math, contradiction determinism, replay tolerance, transplant re-id semantics — matches the TS library exactly.
126
+
127
+ ## Development
128
+
129
+ CI uses [uv](https://docs.astral.sh/uv/) (see `.github/workflows/`):
130
+
131
+ ```bash
132
+ uv sync --all-extras
133
+ uv run ruff check .
134
+ uv run mypy
135
+ uv run pytest # 582 tests
136
+ ```
137
+
138
+ Or with plain pip:
139
+
140
+ ```bash
141
+ pip install -e ".[dev]"
142
+ pytest
143
+ ```
144
+
145
+ Releases publish to PyPI via `release.yml` (trusted publishing) on a published
146
+ GitHub release, or manually via `workflow_dispatch`.
147
+
148
+ ## License
149
+
150
+ Apache-2.0 (matching upstream).