moca-reader 0.6.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.
- moca_reader-0.6.0/.gitattributes +4 -0
- moca_reader-0.6.0/.github/dependabot.yml +11 -0
- moca_reader-0.6.0/.github/workflows/test.yml +169 -0
- moca_reader-0.6.0/.gitignore +8 -0
- moca_reader-0.6.0/CHANGELOG.md +228 -0
- moca_reader-0.6.0/CLAUDE.md +11 -0
- moca_reader-0.6.0/LICENSE +201 -0
- moca_reader-0.6.0/NOTICE +15 -0
- moca_reader-0.6.0/PKG-INFO +209 -0
- moca_reader-0.6.0/README.md +179 -0
- moca_reader-0.6.0/docs/adr/0000-template.md +26 -0
- moca_reader-0.6.0/docs/adr/0001-reader-library-with-no-host-dependencies.md +57 -0
- moca_reader-0.6.0/docs/adr/0002-framework-bindings-as-thin-adapters.md +51 -0
- moca_reader-0.6.0/docs/adr/README.md +16 -0
- moca_reader-0.6.0/docs/getting-started.md +136 -0
- moca_reader-0.6.0/packages/moca-reader-langchain/README.md +50 -0
- moca_reader-0.6.0/packages/moca-reader-langchain/pyproject.toml +25 -0
- moca_reader-0.6.0/packages/moca-reader-langchain/src/moca_reader_langchain/__init__.py +67 -0
- moca_reader-0.6.0/packages/moca-reader-langchain/src/moca_reader_langchain/py.typed +0 -0
- moca_reader-0.6.0/packages/moca-reader-langchain/tests/conftest.py +31 -0
- moca_reader-0.6.0/packages/moca-reader-langchain/tests/test_langchain_retriever.py +65 -0
- moca_reader-0.6.0/packages/moca-reader-llamaindex/README.md +51 -0
- moca_reader-0.6.0/packages/moca-reader-llamaindex/pyproject.toml +25 -0
- moca_reader-0.6.0/packages/moca-reader-llamaindex/src/moca_reader_llamaindex/__init__.py +77 -0
- moca_reader-0.6.0/packages/moca-reader-llamaindex/src/moca_reader_llamaindex/py.typed +0 -0
- moca_reader-0.6.0/packages/moca-reader-llamaindex/tests/conftest.py +31 -0
- moca_reader-0.6.0/packages/moca-reader-llamaindex/tests/test_llamaindex_retriever.py +57 -0
- moca_reader-0.6.0/pyproject.toml +80 -0
- moca_reader-0.6.0/src/moca_reader/__init__.py +84 -0
- moca_reader-0.6.0/src/moca_reader/_js.py +291 -0
- moca_reader-0.6.0/src/moca_reader/attestations.py +271 -0
- moca_reader-0.6.0/src/moca_reader/audience.py +49 -0
- moca_reader-0.6.0/src/moca_reader/backends/__init__.py +1 -0
- moca_reader-0.6.0/src/moca_reader/backends/bm25.py +118 -0
- moca_reader-0.6.0/src/moca_reader/backends/dense.py +146 -0
- moca_reader-0.6.0/src/moca_reader/backends/hybrid.py +73 -0
- moca_reader-0.6.0/src/moca_reader/backends/lexical.py +112 -0
- moca_reader-0.6.0/src/moca_reader/backends/memory_store.py +122 -0
- moca_reader-0.6.0/src/moca_reader/citation.py +213 -0
- moca_reader-0.6.0/src/moca_reader/codes.py +110 -0
- moca_reader-0.6.0/src/moca_reader/conformance.py +249 -0
- moca_reader-0.6.0/src/moca_reader/content.py +312 -0
- moca_reader-0.6.0/src/moca_reader/diagnostics.py +45 -0
- moca_reader-0.6.0/src/moca_reader/digest.py +92 -0
- moca_reader-0.6.0/src/moca_reader/dsse.py +97 -0
- moca_reader-0.6.0/src/moca_reader/ed25519.py +83 -0
- moca_reader-0.6.0/src/moca_reader/embedders.py +224 -0
- moca_reader-0.6.0/src/moca_reader/evidence_text.py +187 -0
- moca_reader-0.6.0/src/moca_reader/frontmatter.py +151 -0
- moca_reader-0.6.0/src/moca_reader/library.py +176 -0
- moca_reader-0.6.0/src/moca_reader/manifest.py +186 -0
- moca_reader-0.6.0/src/moca_reader/metadata.py +58 -0
- moca_reader-0.6.0/src/moca_reader/profiles.py +5 -0
- moca_reader-0.6.0/src/moca_reader/py.typed +0 -0
- moca_reader-0.6.0/src/moca_reader/reader.py +468 -0
- moca_reader-0.6.0/src/moca_reader/relations.py +46 -0
- moca_reader-0.6.0/src/moca_reader/resolver.py +33 -0
- moca_reader-0.6.0/src/moca_reader/reviews.py +18 -0
- moca_reader-0.6.0/src/moca_reader/schemas/ag-ui-citations.schema.json +36 -0
- moca_reader-0.6.0/src/moca_reader/schemas/citation-record.schema.json +326 -0
- moca_reader-0.6.0/src/moca_reader/schemas/manifest.schema.json +171 -0
- moca_reader-0.6.0/src/moca_reader/schemas/node.schema.json +372 -0
- moca_reader-0.6.0/src/moca_reader/schemas/review-predicate.schema.json +42 -0
- moca_reader-0.6.0/src/moca_reader/schemas/search-hit.schema.json +62 -0
- moca_reader-0.6.0/src/moca_reader/schemas/sidecar-index.schema.json +155 -0
- moca_reader-0.6.0/src/moca_reader/schemas/structure.schema.json +93 -0
- moca_reader-0.6.0/src/moca_reader/schemas/trust-root.schema.json +130 -0
- moca_reader-0.6.0/src/moca_reader/schemas.py +44 -0
- moca_reader-0.6.0/src/moca_reader/search.py +346 -0
- moca_reader-0.6.0/src/moca_reader/sidecar.py +228 -0
- moca_reader-0.6.0/src/moca_reader/source.py +285 -0
- moca_reader-0.6.0/src/moca_reader/state.py +119 -0
- moca_reader-0.6.0/src/moca_reader/strategies/__init__.py +1 -0
- moca_reader-0.6.0/src/moca_reader/strategies/diversify.py +28 -0
- moca_reader-0.6.0/src/moca_reader/strategies/ontology_guided.py +63 -0
- moca_reader-0.6.0/src/moca_reader/structure.py +385 -0
- moca_reader-0.6.0/src/moca_reader/structure_ops.py +160 -0
- moca_reader-0.6.0/src/moca_reader/unicode.py +33 -0
- moca_reader-0.6.0/tests/conftest.py +8 -0
- moca_reader-0.6.0/tests/fixtures/token-vectors.json +145 -0
- moca_reader-0.6.0/tests/parity/parity.mjs +134 -0
- moca_reader-0.6.0/tests/parity/run.py +122 -0
- moca_reader-0.6.0/tests/parity/scenarios.json +43 -0
- moca_reader-0.6.0/tests/spec_paths.py +13 -0
- moca_reader-0.6.0/tests/test_conformance.py +84 -0
- moca_reader-0.6.0/tests/test_dsse.py +83 -0
- moca_reader-0.6.0/tests/test_embedders.py +67 -0
- moca_reader-0.6.0/tests/test_members.py +51 -0
- moca_reader-0.6.0/tests/test_metadata.py +30 -0
- moca_reader-0.6.0/tests/test_sigstore.py +43 -0
- moca_reader-0.6.0/tests/test_spec_tables.py +47 -0
- moca_reader-0.6.0/uv.lock +4265 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
# The other MOCA repositories, at fixed refs: release tags, or commits while a Spec Change
|
|
17
|
+
# Proposal is in flight; never a branch (moca-spec CONTRIBUTING.md).
|
|
18
|
+
env:
|
|
19
|
+
MOCA_SPEC_REF: v0.6.0
|
|
20
|
+
MOCA_READER_TYPESCRIPT_REF: v0.6.0
|
|
21
|
+
MOCA_TOOLS_REF: v0.6.0
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
deps:
|
|
25
|
+
name: Public dependencies only
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
with:
|
|
30
|
+
path: moca-reader-python
|
|
31
|
+
# The check lives in moca-spec, the one copy every open repository runs.
|
|
32
|
+
- uses: actions/checkout@v4
|
|
33
|
+
with:
|
|
34
|
+
repository: ${{ github.repository_owner }}/moca-spec
|
|
35
|
+
ref: ${{ env.MOCA_SPEC_REF }}
|
|
36
|
+
path: moca-spec
|
|
37
|
+
# Read access to the other MOCA repos while they are private.
|
|
38
|
+
token: ${{ secrets.MOCA_REPOS_TOKEN || github.token }}
|
|
39
|
+
- uses: actions/setup-node@v4
|
|
40
|
+
with:
|
|
41
|
+
node-version: 22
|
|
42
|
+
- run: node moca-spec/scripts/check-deps.mjs moca-reader-python
|
|
43
|
+
|
|
44
|
+
test:
|
|
45
|
+
name: Test (${{ matrix.os }}, Python ${{ matrix.python }})
|
|
46
|
+
strategy:
|
|
47
|
+
fail-fast: false
|
|
48
|
+
matrix:
|
|
49
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
50
|
+
python: ['3.11', '3.14']
|
|
51
|
+
runs-on: ${{ matrix.os }}
|
|
52
|
+
steps:
|
|
53
|
+
- uses: actions/checkout@v4
|
|
54
|
+
with:
|
|
55
|
+
path: moca-reader-python
|
|
56
|
+
- uses: actions/checkout@v4
|
|
57
|
+
with:
|
|
58
|
+
repository: ${{ github.repository_owner }}/moca-spec
|
|
59
|
+
ref: ${{ env.MOCA_SPEC_REF }}
|
|
60
|
+
path: moca-spec
|
|
61
|
+
token: ${{ secrets.MOCA_REPOS_TOKEN || github.token }}
|
|
62
|
+
- uses: astral-sh/setup-uv@v6
|
|
63
|
+
with:
|
|
64
|
+
python-version: ${{ matrix.python }}
|
|
65
|
+
- run: uv sync --locked
|
|
66
|
+
working-directory: moca-reader-python
|
|
67
|
+
- run: uv run ruff check && uv run ruff format --check && uv run mypy
|
|
68
|
+
working-directory: moca-reader-python
|
|
69
|
+
- run: uv run pytest
|
|
70
|
+
working-directory: moca-reader-python
|
|
71
|
+
|
|
72
|
+
corpus:
|
|
73
|
+
name: Corpus and parity with the reference Reader
|
|
74
|
+
runs-on: ubuntu-latest
|
|
75
|
+
steps:
|
|
76
|
+
- uses: actions/checkout@v4
|
|
77
|
+
with:
|
|
78
|
+
path: moca-reader-python
|
|
79
|
+
- uses: actions/checkout@v4
|
|
80
|
+
with:
|
|
81
|
+
repository: ${{ github.repository_owner }}/moca-spec
|
|
82
|
+
ref: ${{ env.MOCA_SPEC_REF }}
|
|
83
|
+
path: moca-spec
|
|
84
|
+
token: ${{ secrets.MOCA_REPOS_TOKEN || github.token }}
|
|
85
|
+
- uses: actions/checkout@v4
|
|
86
|
+
with:
|
|
87
|
+
repository: ${{ github.repository_owner }}/moca-reader-typescript
|
|
88
|
+
ref: ${{ env.MOCA_READER_TYPESCRIPT_REF }}
|
|
89
|
+
path: moca-reader-typescript
|
|
90
|
+
token: ${{ secrets.MOCA_REPOS_TOKEN || github.token }}
|
|
91
|
+
- uses: actions/checkout@v4
|
|
92
|
+
with:
|
|
93
|
+
repository: ${{ github.repository_owner }}/moca-tools
|
|
94
|
+
ref: ${{ env.MOCA_TOOLS_REF }}
|
|
95
|
+
path: moca-tools
|
|
96
|
+
token: ${{ secrets.MOCA_REPOS_TOKEN || github.token }}
|
|
97
|
+
- uses: astral-sh/setup-uv@v6
|
|
98
|
+
with:
|
|
99
|
+
python-version: '3.14'
|
|
100
|
+
- uses: actions/setup-node@v4
|
|
101
|
+
with:
|
|
102
|
+
node-version: 22
|
|
103
|
+
- run: uv sync --locked
|
|
104
|
+
working-directory: moca-reader-python
|
|
105
|
+
- run: npm ci
|
|
106
|
+
working-directory: moca-reader-typescript
|
|
107
|
+
- run: npm ci
|
|
108
|
+
working-directory: moca-tools
|
|
109
|
+
- run: npm ci
|
|
110
|
+
working-directory: moca-spec
|
|
111
|
+
- run: node scripts/run-conformance.mjs --reader "../moca-reader-python/.venv/bin/python -m moca_reader.conformance"
|
|
112
|
+
working-directory: moca-spec
|
|
113
|
+
# The corpus never compares ranking; this checks we return what the reference Reader returns, in its order.
|
|
114
|
+
- run: node tests/parity/parity.mjs
|
|
115
|
+
working-directory: moca-reader-python
|
|
116
|
+
|
|
117
|
+
# Phase 1's gate: the getting-started guide works as written (docs/getting-started.md).
|
|
118
|
+
guide:
|
|
119
|
+
name: Getting-started guide
|
|
120
|
+
runs-on: ubuntu-latest
|
|
121
|
+
steps:
|
|
122
|
+
- uses: actions/checkout@v4
|
|
123
|
+
with:
|
|
124
|
+
path: moca-reader-python
|
|
125
|
+
- uses: actions/checkout@v4
|
|
126
|
+
with:
|
|
127
|
+
repository: ${{ github.repository_owner }}/moca-spec
|
|
128
|
+
ref: ${{ env.MOCA_SPEC_REF }}
|
|
129
|
+
path: moca-spec
|
|
130
|
+
token: ${{ secrets.MOCA_REPOS_TOKEN || github.token }}
|
|
131
|
+
# moca-spec's corpus runner links the reference Reader and moca-tools until they are on npm.
|
|
132
|
+
- uses: actions/checkout@v4
|
|
133
|
+
with:
|
|
134
|
+
repository: ${{ github.repository_owner }}/moca-reader-typescript
|
|
135
|
+
ref: ${{ env.MOCA_READER_TYPESCRIPT_REF }}
|
|
136
|
+
path: moca-reader-typescript
|
|
137
|
+
token: ${{ secrets.MOCA_REPOS_TOKEN || github.token }}
|
|
138
|
+
- uses: actions/checkout@v4
|
|
139
|
+
with:
|
|
140
|
+
repository: ${{ github.repository_owner }}/moca-tools
|
|
141
|
+
ref: ${{ env.MOCA_TOOLS_REF }}
|
|
142
|
+
path: moca-tools
|
|
143
|
+
token: ${{ secrets.MOCA_REPOS_TOKEN || github.token }}
|
|
144
|
+
- uses: actions/setup-python@v5
|
|
145
|
+
with:
|
|
146
|
+
python-version: '3.11'
|
|
147
|
+
- uses: astral-sh/setup-uv@v6
|
|
148
|
+
- uses: actions/setup-node@v4
|
|
149
|
+
with:
|
|
150
|
+
node-version: 22
|
|
151
|
+
- run: npm ci
|
|
152
|
+
working-directory: moca-reader-typescript
|
|
153
|
+
- run: npm ci
|
|
154
|
+
working-directory: moca-tools
|
|
155
|
+
- name: Example package from the moca-spec release
|
|
156
|
+
env:
|
|
157
|
+
GH_TOKEN: ${{ secrets.MOCA_REPOS_TOKEN || github.token }}
|
|
158
|
+
run: gh release download v0.6.0 -R ${{ github.repository_owner }}/moca-spec -p support-kb.moca -p example-trust-root.json -D "$RUNNER_TEMP/assets"
|
|
159
|
+
- run: uv build --out-dir "$RUNNER_TEMP/dist"
|
|
160
|
+
working-directory: moca-reader-python
|
|
161
|
+
# Until moca-reader is on PyPI and the repositories are public: install the wheel built from this
|
|
162
|
+
# commit, read the example from the private release, and use the moca-spec checkout. Drop each
|
|
163
|
+
# replacement when what it stands in for is public.
|
|
164
|
+
- run: >-
|
|
165
|
+
node ../moca-spec/scripts/run-guide.mjs docs/getting-started.md
|
|
166
|
+
--replace "pip install moca-reader=>pip install $RUNNER_TEMP/dist/moca_reader-*.whl"
|
|
167
|
+
--replace "https://github.com/openmoca/moca-spec/releases/download/v0.6.0/=>file://$RUNNER_TEMP/assets/"
|
|
168
|
+
--replace "git clone --depth 1 --branch v0.6.0 https://github.com/openmoca/moca-spec.git=>ln -s $GITHUB_WORKSPACE/moca-spec moca-spec"
|
|
169
|
+
working-directory: moca-reader-python
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `moca-reader`. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
4
|
+
|
|
5
|
+
## [0.6.0] - 2026-11-11
|
|
6
|
+
|
|
7
|
+
### Added (Sigstore, offline)
|
|
8
|
+
|
|
9
|
+
- With the `sigstore` extra, Sigstore bundles are verified offline against the
|
|
10
|
+
host's `sigstore.trustedRoot`, through sigstore-python 4.x. Without the extra
|
|
11
|
+
or a trusted root they stay A003; identities listed but none for the role is
|
|
12
|
+
A002, as in the reference Reader. There is no online mode. The corpus's
|
|
13
|
+
`sigstore-*` cases pass.
|
|
14
|
+
|
|
15
|
+
### Fixed (attestations §5)
|
|
16
|
+
|
|
17
|
+
- Strict Ed25519 checks before verifying: A and R are canonical points of
|
|
18
|
+
prime order, S < L. Before, a trusted small-order key verified a signature
|
|
19
|
+
of any message.
|
|
20
|
+
|
|
21
|
+
### Fixed (frontmatter line ends)
|
|
22
|
+
|
|
23
|
+
- Only LF or CRLF ends a line in the frontmatter block, in every Reader. The
|
|
24
|
+
reference Reader also ended lines at a lone CR, U+2028 and U+2029.
|
|
25
|
+
|
|
26
|
+
### Fixed (edge cases)
|
|
27
|
+
|
|
28
|
+
- Regular expressions and trimming follow package spec §2: ASCII digits,
|
|
29
|
+
ECMAScript white space, and an absolute end of string. Before, a date in
|
|
30
|
+
non-ASCII digits parsed, and a trailing newline passed several checks.
|
|
31
|
+
- An archive entry with a bad CRC-32 raised `BadZipFile`; it is now P002, as
|
|
32
|
+
is a stored entry whose size does not match its header.
|
|
33
|
+
- M007 knows every IANA formal URN namespace and informal ones.
|
|
34
|
+
- A leading byte order mark is not part of an evidence source.
|
|
35
|
+
|
|
36
|
+
### Changed (conformance adapter)
|
|
37
|
+
|
|
38
|
+
- The adapter passes the corpus option `strict`.
|
|
39
|
+
|
|
40
|
+
### Added (versioning, package spec §14)
|
|
41
|
+
|
|
42
|
+
- `M009_MOCA_VERSION_NEWER` (warning) for a package written for a newer
|
|
43
|
+
`mocaVersion` than `MOCA_VERSION` (`0.6`). Versions compare numerically, without
|
|
44
|
+
overflow. The `mocaVersion` check uses a full match, so a trailing newline no longer counts. The vendored schemas have portable patterns.
|
|
45
|
+
|
|
46
|
+
### Added (composition limits, package spec §7.1.1)
|
|
47
|
+
|
|
48
|
+
- Member resolution is bounded: `limits={"maxMemberDepth": …, "maxMembers": …}` (defaults 8 and 256, across every
|
|
49
|
+
depth of one read). A member past either limit is not resolved, and
|
|
50
|
+
`R001_MEMBER_UNRESOLVED` says why.
|
|
51
|
+
|
|
52
|
+
### Removed (structure.json, moca-spec ADR-0019)
|
|
53
|
+
|
|
54
|
+
- The Reader no longer reads or checks `structure.json`, and
|
|
55
|
+
`O004_STRUCTURE_VIEW_MISMATCH` is retired. A package that ships the file
|
|
56
|
+
stays valid and gets `structured` from `structure.ttl` alone. `structure_view` stays.
|
|
57
|
+
|
|
58
|
+
### Changed (sidecars and search)
|
|
59
|
+
|
|
60
|
+
- A sidecar item's `text` must equal the package's bytes at its span, which
|
|
61
|
+
must lie in the body (`S004`); lexical search reads the package's bytes, never
|
|
62
|
+
the sidecar's text, so a sidecar cannot stuff keywords into a node.
|
|
63
|
+
- A prefix declared by only the index or only the embedder is `S006`.
|
|
64
|
+
- The gate keeps one result per node representation and span: the English and
|
|
65
|
+
French pages of one node are no longer merged.
|
|
66
|
+
|
|
67
|
+
### Changed (determinism)
|
|
68
|
+
|
|
69
|
+
- `moca.json` and attestation statements that repeat a member name are `M001`
|
|
70
|
+
and `A001` (they were read with the last value).
|
|
71
|
+
- Locale fallback: exact, then the longest tag the request starts with, then the
|
|
72
|
+
lowest tag starting with the request, all case-insensitive.
|
|
73
|
+
- Evidence: Markdown and HTML quotes are normalised like their sources, and a
|
|
74
|
+
`TextPositionSelector` on its own is no longer checked (`matched` absent).
|
|
75
|
+
|
|
76
|
+
### Changed (limits and archives, review B9 and M6)
|
|
77
|
+
|
|
78
|
+
- Evidence work is bounded per package (`maxEvidenceChecksPerPackage`, 10,000;
|
|
79
|
+
`maxEvidenceBytesPerPackage`, 256 MiB scanned), each source is normalised once,
|
|
80
|
+
and a quote is matched in one pass. A package of 200 nodes with 256 quotes each
|
|
81
|
+
against an 8 MiB source now reads in well under a second.
|
|
82
|
+
- Directories have the entry and byte limits, and a file replaced by a link
|
|
83
|
+
after listing is unreadable.
|
|
84
|
+
- Archives: names must be UTF-8 (flag set) with no NUL, empty or `.` segments;
|
|
85
|
+
duplicate entries are `P003`; only stored and deflated entries are read
|
|
86
|
+
(others `P002`), and an unreadable entry stops the read.
|
|
87
|
+
|
|
88
|
+
### Changed (identity and tampering, review M2 and M3)
|
|
89
|
+
|
|
90
|
+
- A library refuses a second package with the same `id@version` and a different
|
|
91
|
+
digest, and reports `L001_IDENTITY_CONFLICT` (it was dropped silently).
|
|
92
|
+
- A package attestation naming this `id@version` with another digest is
|
|
93
|
+
`A008_PACKAGE_DIGEST_MISMATCH`, not `A002`.
|
|
94
|
+
- A resolved member whose `id` or `version` differs from its pin is `R002`.
|
|
95
|
+
- `read_package(target, require_signature=True)` makes a package without a valid package attestation invalid
|
|
96
|
+
(`A009_SIGNATURE_REQUIRED`).
|
|
97
|
+
|
|
98
|
+
### Changed (store search, review B2)
|
|
99
|
+
|
|
100
|
+
- A store search takes the loaded packages' states (`package_state(result)`; `StoreScope(states, clock)`) instead of bare
|
|
101
|
+
digests, and recomputes `superseded`, `contested`, `signed`, `signers`,
|
|
102
|
+
`attestedReviews` and `reviewStatus` at query time (contract §9.4). A package
|
|
103
|
+
superseded after ingest, or a key removed from the trust root, is reflected
|
|
104
|
+
at once.
|
|
105
|
+
|
|
106
|
+
### Changed (reviews, moca-spec ADR-0017)
|
|
107
|
+
|
|
108
|
+
- `reviewed` needs a signed package with every reviewed file approved.
|
|
109
|
+
Citation records gain `trust.reviewStatus` (`approved`, `disputed`,
|
|
110
|
+
`unverified`, `none`) and each review's `packageVerified`. The latest review
|
|
111
|
+
from each signer counts; a review dated after the clock is ignored
|
|
112
|
+
(`A007_REVIEW_DATE_FUTURE`); a trust-root entry's `reviewers` list limits whom
|
|
113
|
+
its key may sign as.
|
|
114
|
+
|
|
115
|
+
### Changed (audience, moca-spec ADR-0016)
|
|
116
|
+
|
|
117
|
+
- Under a host audience set, content with no audience label is left out unless
|
|
118
|
+
the host allows it (`Search(..., allow_unlabelled=True)`, off by default), and a malformed label never
|
|
119
|
+
matches; citation records mark it `audienceInvalid`. A translation with no
|
|
120
|
+
label has its default representation's. The gate, the backends and the store
|
|
121
|
+
backend apply the same rule.
|
|
122
|
+
|
|
123
|
+
### Changed (relations, moca-spec ADR-0015)
|
|
124
|
+
|
|
125
|
+
- `supersedes` and `conflictsWith` take effect only when the declaring package
|
|
126
|
+
has a valid package attestation from a key or Sigstore identity whose new
|
|
127
|
+
trust-root `ids` cover the target's id (package spec §7.2). Otherwise the
|
|
128
|
+
Reader reports `R004_RELATION_UNAUTHORISED` (info) and the relation has no
|
|
129
|
+
effect. `Library(allow_unsigned_relations=True)` (off by default) applies unsigned relations, for a library
|
|
130
|
+
of the host's own packages.
|
|
131
|
+
|
|
132
|
+
### Changed
|
|
133
|
+
|
|
134
|
+
Dates follow package spec §4.4:
|
|
135
|
+
|
|
136
|
+
- A full date means 00:00Z; a date-time needs an offset, and one without is
|
|
137
|
+
ignored (it already has a diagnostic) rather than read as UTC.
|
|
138
|
+
- A node's validity window is the intersection with its package's: a node can
|
|
139
|
+
no longer stay in force after the package's `validUntil`. An inverted window
|
|
140
|
+
is ignored.
|
|
141
|
+
- A trust-root key is not trusted from the instant of `expires`, checked
|
|
142
|
+
against the host clock, which `read_package` now takes (`clock`, a callable returning a `datetime`). A key whose `expires`
|
|
143
|
+
does not parse is not trusted.
|
|
144
|
+
|
|
145
|
+
Attestation verification follows the numbered algorithm now in attestations §7
|
|
146
|
+
(0.6.0):
|
|
147
|
+
|
|
148
|
+
- DSSE payloads and signatures are decoded strictly: base64 or base64url, with
|
|
149
|
+
or without padding. Anything else makes the payload malformed (`A001`) or the
|
|
150
|
+
signature not verify.
|
|
151
|
+
- A trust root is refused if it repeats a `keyid` or has a key or identity
|
|
152
|
+
without `roles`. An empty `roles` list trusts the entry for nothing.
|
|
153
|
+
|
|
154
|
+
### Fixed
|
|
155
|
+
|
|
156
|
+
Fixes from the 10 November 2026 specification review, each with a new case
|
|
157
|
+
in the moca-spec 0.6.0 conformance corpus:
|
|
158
|
+
|
|
159
|
+
- A malformed percent-encoding in a source `resource` or a link is reported as
|
|
160
|
+
`C008_UNSAFE_PATH` instead of being silently skipped.
|
|
161
|
+
- An absolute reference (a leading `/` or `\`, or a drive prefix such as `C:/`)
|
|
162
|
+
is `C008_UNSAFE_PATH`, as the Reader contract says. It was resolved under
|
|
163
|
+
`content/`.
|
|
164
|
+
- Structure traversal is iterative: a 30,000-concept `requires` chain no longer
|
|
165
|
+
risks the recursion limit.
|
|
166
|
+
- A validity bound or `stale_after` that does not parse as a date is treated as
|
|
167
|
+
absent; it no longer takes a node out of force.
|
|
168
|
+
- A `generated` or `verified` entry with no `by` is dropped; it was reported
|
|
169
|
+
with the actor `"undefined"`.
|
|
170
|
+
- `log.md` and `index.md` frontmatter gets the frontmatter size limit, and a
|
|
171
|
+
level-two heading (`##`) inside a fenced code block in `log.md` is no longer a C004 error.
|
|
172
|
+
- `moca.json` that is not valid UTF-8 is `M001`; it was read with replacement
|
|
173
|
+
characters.
|
|
174
|
+
- Only entries under `attestations/` are left out of the digest; a top-level
|
|
175
|
+
file named `attestations` is digested.
|
|
176
|
+
- Member cycles are detected by `id@version`, so a package can compose another
|
|
177
|
+
version of itself.
|
|
178
|
+
- A host source's byte limit is also enforced on the bytes it returns, and a
|
|
179
|
+
limit broken while reading is one `T003`, not a `P002` per file. An existing
|
|
180
|
+
file that is not a directory or a `.moca`/`.zip` archive is `T002`.
|
|
181
|
+
- Archive bytes are accepted as a target.
|
|
182
|
+
- A trust-root key or identity with an empty `roles` list is trusted for
|
|
183
|
+
nothing. It was trusted for both roles: a key a host disabled by emptying its
|
|
184
|
+
roles stayed live.
|
|
185
|
+
|
|
186
|
+
## [0.5.0] - Not published
|
|
187
|
+
|
|
188
|
+
The first release. It implements moca-spec 0.5 (0.5.0), passes all 93
|
|
189
|
+
cases of the 0.5.0 conformance corpus, both as pytest cases and
|
|
190
|
+
through the runner protocol, and returns the same ranked results as the
|
|
191
|
+
reference Reader in all 87 parity queries.
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
### Performance
|
|
195
|
+
|
|
196
|
+
- **Lexical search keeps each document's term counts** after its first search,
|
|
197
|
+
per package digest, and drops them when the package leaves the library.
|
|
198
|
+
Later searches only score: at 5,000 pages, about 21 ms a search after the
|
|
199
|
+
first. Scores and order are unchanged (the corpus and the parity check
|
|
200
|
+
against the reference Reader pass).
|
|
201
|
+
|
|
202
|
+
### Added
|
|
203
|
+
|
|
204
|
+
- `moca_reader.embedders`, with the `onnx` extra: MOCA's four standard embedding
|
|
205
|
+
models (`bge-small-en-v1.5`, `nomic-embed-text-v1.5`, `all-MiniLM-L6-v2`,
|
|
206
|
+
`multilingual-e5-small`) run locally, pinned by commit and SHA-256, checked
|
|
207
|
+
before loading. Vectors match `moca-index --model`, the .NET Reader's ONNX
|
|
208
|
+
binding and the MCP server exactly.
|
|
209
|
+
### Added
|
|
210
|
+
|
|
211
|
+
- `read_package`: directories, `.moca` archives and host sources; the
|
|
212
|
+
moca-digest-v2 digest; DSSE package and review attestations against a host
|
|
213
|
+
trust root, with Ed25519 keys only (attestations §5); members through a host resolver; content, evidence checks,
|
|
214
|
+
structure and capabilities. Sigstore bundles are reported as unverifiable
|
|
215
|
+
(`A003`).
|
|
216
|
+
- `Library`, `Search` and the gate; `LexicalBackend` (BM25 with the shared
|
|
217
|
+
tokeniser), `DenseBackend` over sidecar vectors (`S006`, `S007`,
|
|
218
|
+
`model.distance`, compared embedder prefixes), `MemoryStoreBackend`,
|
|
219
|
+
`HybridBackend` (Reciprocal Rank Fusion); `ontology_guided` and `diversify`
|
|
220
|
+
hooks; structure operations.
|
|
221
|
+
- `bind_sidecar` for `moca-jsonl-v1` sidecars, with float32 vectors.
|
|
222
|
+
- `python -m moca_reader.conformance`: the runner protocol adapter, shipped
|
|
223
|
+
with the package.
|
|
224
|
+
- `flat_metadata(record)` and `FLAT_FIELDS`: the consuming guide's flat
|
|
225
|
+
`moca_*` fields for a citation record.
|
|
226
|
+
- `moca-reader-langchain` and `moca-reader-llamaindex`: `MocaRetriever` for
|
|
227
|
+
each framework, over a host-built `Search`, carrying the whole citation
|
|
228
|
+
record and the flat fields in each result's metadata (ADR-0002).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# moca-reader-python
|
|
2
|
+
|
|
3
|
+
The Python MOCA Reader, `moca-reader` / `moca_reader` ([ADR-0001](docs/adr/0001-reader-library-with-no-host-dependencies.md)).
|
|
4
|
+
|
|
5
|
+
- **No host dependencies.** Only the runtime dependencies in `pyproject.toml`; no web framework, no network clients.
|
|
6
|
+
- **The spec is the contract.** Normative sources in `../moca-spec/spec/`. The reference Reader (TypeScript) is `../moca-reader-typescript/lib/`; this Reader's modules map one-to-one onto it. When they disagree, the spec wins; raise the difference as an issue in moca-spec.
|
|
7
|
+
- **Match the reference exactly where Python differs from JavaScript**: `_js.py` holds those behaviours (UTF-16 sort order, `Math.round`, `Date.parse`, lenient base64, `JSON.stringify`, truthiness). Use it rather than Python's defaults.
|
|
8
|
+
- **Never raise for a malformed package.** Report diagnostics. Raise only for programmer errors.
|
|
9
|
+
- **Never reach the network or the host filesystem outside the package** because a package names something.
|
|
10
|
+
- Name things as the spec does, in Python's style; comment each rule with its section (`# Contract §3.2`).
|
|
11
|
+
- Checks: `uv run pytest`, `uv run ruff check`, `uv run ruff format --check`, `uv run mypy` (strict), the corpus through the runner, and `node tests/parity/parity.mjs`.
|
|
@@ -0,0 +1,201 @@
|
|
|
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 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 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 those 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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Modular Ontology & Content Assembly (MOCA) Standard Contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
moca_reader-0.6.0/NOTICE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
MOCA — Modular Ontology, Content & Attestation
|
|
2
|
+
Copyright 2026 MOCA Standard Contributors
|
|
3
|
+
|
|
4
|
+
This product includes software developed by the MOCA Standard Contributors
|
|
5
|
+
(https://github.com/openmoca).
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0. You may obtain a copy of the
|
|
8
|
+
License in the LICENSE file in this repository, or at
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
The MOCA Reader for Python and its framework bindings (the files under src/,
|
|
14
|
+
packages/ and tests/). All of it is licensed under the Apache License,
|
|
15
|
+
Version 2.0.
|