iscc-lib 0.7.0 → 0.8.0

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.
data/Cargo.toml CHANGED
@@ -1,14 +1,25 @@
1
+ # Standalone manifest generated by scripts/build_ruby_source_gem.py
1
2
  [package]
2
3
  name = "iscc-rb"
3
- version.workspace = true
4
- edition.workspace = true
5
- rust-version.workspace = true
6
- publish = false # Published via RubyGems, not crates.io
4
+ version = "0.8.0"
5
+ edition = "2024"
6
+ rust-version = "1.85"
7
+ publish = false
7
8
 
8
9
  [lib]
9
10
  name = "iscc_rb"
10
11
  crate-type = ["cdylib"]
11
12
 
12
13
  [dependencies]
13
- iscc-lib = { path = "../iscc-lib" }
14
- magnus = { workspace = true }
14
+ iscc-lib = { path = "core" }
15
+ magnus = { version = "^0.8", features = ["rb-sys"] }
16
+
17
+ # Workspace release profile, copied from the root Cargo.toml
18
+ [profile.release]
19
+ lto = true
20
+ codegen-units = 1
21
+ strip = true
22
+ panic = "abort"
23
+
24
+ # Empty workspace: cargo must never walk up into an enclosing workspace
25
+ [workspace]
data/README.md CHANGED
@@ -28,8 +28,11 @@ Or add to your `Gemfile`:
28
28
  gem "iscc-lib"
29
29
  ```
30
30
 
31
- Precompiled gems are available for common platforms. If no precompiled gem matches your platform,
32
- the gem builds from source (requires a Rust toolchain and `libclang-dev`).
31
+ The gem requires Ruby `>= 3.3`. Precompiled platform gems are built for Ruby 3.3 to 3.4 on common
32
+ platforms. On a newer Ruby, or on a platform with no precompiled gem, `gem install iscc-lib`
33
+ installs the source gem and compiles the extension. That build needs a Rust toolchain (`rustup`),
34
+ `libclang-dev`, Ruby development headers, and network access: it installs the `rb_sys` gem and
35
+ downloads the Rust crates from crates.io. CI installs the source gem on Ruby 3.4.
33
36
 
34
37
  ## Quick Start
35
38
 
@@ -76,7 +79,7 @@ puts result.iscc
76
79
  - **Algorithm primitives:** `alg_simhash`, `alg_minhash_256`, `alg_cdc_chunks`, `sliding_window`
77
80
  - **Soft hashing:** `soft_hash_video_v0`
78
81
  - **Encoding:** `encode_base64`, `encode_component`
79
- - **Codec:** `iscc_decode`, `iscc_decompose`, `json_to_data_url`
82
+ - **Codec:** `iscc_decode`, `iscc_decompose`, `encode_seq`, `decode_seq`, `json_to_data_url`
80
83
  - **Streaming:** `DataHasher`, `InstanceHasher` for incremental processing
81
84
  - **Diagnostics:** `conformance_selftest`
82
85
 
data/core/CLAUDE.md ADDED
@@ -0,0 +1,177 @@
1
+ # CLAUDE.md — iscc-lib core crate
2
+
3
+ Pure Rust implementation of ISO 24138:2024 (ISCC) -- the hub of the hub-and-spoke workspace model.
4
+
5
+ ## Crate Role
6
+
7
+ - This is the **core crate** that all binding crates (`iscc-py`, `iscc-napi`, `iscc-wasm`,
8
+ `iscc-ffi`, `iscc-jni`, `iscc-rb`, `iscc-uniffi`) depend on
9
+ - Must remain **pure Rust** -- zero binding dependencies (no PyO3, napi, wasm-bindgen)
10
+ - Publishable to crates.io as `iscc-lib`
11
+ - All ISCC algorithm logic lives here; binding crates only translate the API
12
+
13
+ ## API Tier Rules
14
+
15
+ **Tier 1 -- public API, bound in all languages (crate-root symbols):**
16
+
17
+ <!-- tier1:begin -->
18
+
19
+ - Gen functions: `gen_meta_code_v0`, `gen_text_code_v0`, `gen_image_code_v0`, `gen_audio_code_v0`,
20
+ `gen_video_code_v0`, `gen_mixed_code_v0`, `gen_data_code_v0`, `gen_instance_code_v0`,
21
+ `gen_iscc_code_v0`, `gen_sum_code_v0`
22
+ - ISCC-IDv1 mint function (experimental): `gen_iscc_id_v1`
23
+ - Text utilities: `text_clean`, `text_remove_newlines`, `text_trim`, `text_collapse`
24
+ - Algorithm primitives: `sliding_window`, `alg_minhash_256`, `alg_cdc_chunks`, `alg_simhash`
25
+ - Soft hash: `soft_hash_video_v0`
26
+ - Encoding utilities: `encode_base64`, `json_to_data_url`
27
+ - Codec operations: `iscc_decompose`, `encode_component`, `iscc_decode`, `encode_seq`, `decode_seq`
28
+ - Algorithm constants: `META_TRIM_NAME`, `META_TRIM_DESCRIPTION`, `META_TRIM_META`, `IO_READ_SIZE`,
29
+ `TEXT_NGRAM_SIZE`
30
+ - Streaming types: `DataHasher`, `InstanceHasher`
31
+ - Diagnostic: `conformance_selftest`
32
+
33
+ <!-- tier1:end -->
34
+
35
+ Note: some Tier 1 symbols are feature-gated. `text_clean`, `text_collapse`, and `gen_text_code_v0`
36
+ require the `text-processing` feature. `gen_meta_code_v0`, `json_to_data_url`, `META_TRIM_NAME`,
37
+ `META_TRIM_DESCRIPTION`, and `META_TRIM_META` require the `meta-code` feature (which implies
38
+ `text-processing`). The `default` feature set includes `meta-code`.
39
+
40
+ **Tier 1 support types -- crate root, not counted as Tier 1 symbols:**
41
+
42
+ - `IsccError`, `IsccResult<T>`: the error every fallible Tier 1 call returns (excluded from the
43
+ symbol count in `EXCLUDED_ITEMS` of `scripts/check_tier1_docs.py`)
44
+ - The result structs of `types`, re-exported by `pub use types::*`; `types::X` and the crate-root
45
+ `X` are the same item. Likewise `streaming::DataHasher`/`streaming::InstanceHasher` and the
46
+ `codec` paths of `encode_base64`, `iscc_decompose`, `encode_seq` and `decode_seq` are the Tier 1
47
+ re-exports, not separate items. `codec::encode_component` IS a separate item: the enum-typed
48
+ Tier 2 variant of the crate-root function
49
+
50
+ **Tier 2 -- public Rust API outside the every-language contract (covered by SemVer):**
51
+
52
+ - `pub mod codec`, not exposed through bindings:
53
+ - `MainType`, `SubType`, `Version` enums
54
+ - `encode_header`, `decode_header`, `encode_base32`, `decode_base32`
55
+ - `encode_length`, `decode_length`, `encode_units`, `decode_units`
56
+ - `read_unit`, `SEQ_MAINTYPES`
57
+ - `streaming::SumHasher` (not re-exported at the crate root): Python and WASM wrap it as an extra;
58
+ the other bindings do not
59
+
60
+ **Internal -- `pub(crate)` or private, free to change:**
61
+
62
+ - `dct::alg_dct`, `wtahash::alg_wtahash`
63
+ - `xxh32::xxh32` -- the feature hash of Data-Code and Text-Code, implemented in this crate (no
64
+ xxHash dependency; decisions.md, 2026-11-22)
65
+ - Helper functions in `lib.rs` (`interleave_digests`, `meta_name_simhash`, `soft_hash_meta_v0`,
66
+ `soft_hash_meta_v0_with_bytes`, `soft_hash_text_v0`, `soft_hash_image_v0`, `soft_hash_audio_v0`,
67
+ `soft_hash_codes_v0`, etc.)
68
+ - `utils::multi_hash_blake3`
69
+
70
+ **Rules:**
71
+
72
+ - Adding to Tier 1 requires deliberate review
73
+ - Tier 1 is what `lib.rs` defines or re-exports at the crate root; algorithm and utility modules
74
+ stay `pub(crate)`
75
+ - Bindings translate the API; they must not define semantics
76
+ - Do not expose Rust enums directly in bindings (they break when variants are added)
77
+ - All result structs use `#[non_exhaustive]` so fields can be added in minor versions
78
+
79
+ ## Sync Core Design Pattern
80
+
81
+ All operations are CPU-bound. The core is synchronous -- no async, no tokio.
82
+
83
+ **One-shot functions:** `gen_*_v0(inputs, bits) -> IsccResult<*CodeResult>`
84
+
85
+ **Streaming types** (for Data-Code and Instance-Code on large files):
86
+
87
+ ```
88
+ new() -> update(&[u8]) -> ... -> update(&[u8]) -> finalize(bits) -> IsccResult<*CodeResult>
89
+ ```
90
+
91
+ - `DataHasher`: CDC + xxh32 + MinHash, tail buffering between `update()` calls
92
+ - `InstanceHasher`: BLAKE3 incremental hashing
93
+ - Both must produce output identical to their one-shot counterparts for the same byte stream
94
+
95
+ ## Key Types and Traits
96
+
97
+ - `IsccError` -- single error enum (`InvalidInput` variant), defined in `lib.rs`
98
+ - `IsccResult<T>` -- type alias for `Result<T, IsccError>`
99
+ - `*CodeResult` structs in `types.rs` -- each `gen_*_v0` returns a dedicated struct
100
+ - All carry an `iscc: String` field (the ISCC code with `"ISCC:"` prefix)
101
+ - Some carry additional fields: `name`, `description`, `meta`, `metahash`, `characters`,
102
+ `datahash`, `filesize`, `parts`, `units`
103
+ - `codec::MainType`, `codec::SubType`, `codec::Version` -- `#[repr(u8)]` enums with `TryFrom<u8>`
104
+
105
+ ## Conformance Rules
106
+
107
+ - Correctness baseline: vendored `tests/data.json` from `iscc-core`
108
+ - Vendored copies of `data.json` in per-language test trees are gated for byte-identity by
109
+ `tests/test_vendored_fixtures.py` (repo root) — every new tracked copy must be registered there
110
+ - Every `gen_*_v0` function except `gen_sum_code_v0` must match `iscc-core` output for every test
111
+ vector (`gen_sum_code_v0` has no conformance vectors — it composes Data-Code + Instance-Code
112
+ internally)
113
+ - `conformance_selftest()` runs all vectors at runtime (non-panicking, returns bool). The `SECTIONS`
114
+ table in `conformance.rs` is the only list of `data.json` sections, and a test fails when its
115
+ rows differ from the `data.json` keys: a new section needs a table row
116
+ - The meta, text, mixed and instance `#[test]` loops in `lib.rs` re-run their vectors to check the
117
+ extra output fields. They read the inputs through the `pub(crate)` parsers in `conformance.rs`,
118
+ the only file under `src` that parses `data.json`: a test adds its extra-field checks, never its
119
+ own input decoding
120
+ - The parsers share the Go runner's wrong-type rule (decisions.md, 2026-11-22): a wrong JSON type, a
121
+ fraction or an out-of-range number makes a case unparsable (`None`), never coerced or skipped
122
+ - Streaming types (`DataHasher`/`InstanceHasher`) are tested against one-shot functions at multiple
123
+ chunk sizes including byte-at-a-time
124
+ - No network access in tests -- all vectors are `include_str!` from `tests/data.json`
125
+ - `stream:` prefix in vector data means hex-encoded bytes; decode with `hex::decode`
126
+
127
+ ## Build and Test Commands
128
+
129
+ ```bash
130
+ cargo test -p iscc-lib # All tests (unit + conformance)
131
+ cargo test -p iscc-lib -- --test-threads=1 # Sequential (for debugging)
132
+ cargo clippy -p iscc-lib -- -D warnings # Lint
133
+ cargo fmt -p iscc-lib --check # Format check
134
+ cargo bench -p iscc-lib # Criterion benchmarks
135
+ ```
136
+
137
+ ## Dependencies
138
+
139
+ - `blake3` -- BLAKE3 hashing (Instance-Code, metahash)
140
+ - `data-encoding` -- base32/base64 encoding
141
+ - `hex` -- hex encode/decode for conformance vector parsing
142
+ - `unicode-normalization` -- NFKC/NFD normalization (optional, `text-processing` feature)
143
+ - `unicode-general-category` -- Unicode category classification for text filtering (optional,
144
+ `text-processing` feature)
145
+ - `thiserror` -- error derive macro
146
+ - `serde_json` -- JSON parsing for meta processing and conformance vectors
147
+ - `serde_json_canonicalizer` -- RFC 8785 (JCS) compliant JSON serialization for metadata
148
+ canonicalization (optional, `meta-code` feature)
149
+ - `serde`, `criterion`, `tempfile` -- dev-dependencies only
150
+
151
+ ## Common Pitfalls
152
+
153
+ - **Do not add async or tokio** -- the core is synchronous by design. Async adaptation happens in
154
+ binding crates.
155
+ - **Do not add PyO3, napi, or wasm-bindgen** -- this crate must stay pure Rust.
156
+ - **Do not make `pub(crate)` modules `pub`** without updating the tier documentation and getting
157
+ review.
158
+ - **`SubType::TEXT` is an alias for `SubType::None`** (both value 0) -- use `SubType::TEXT` in
159
+ Content-Code context for clarity.
160
+ - **`encode_component` rejects `MainType::Iscc`** -- ISCC-CODEs are composites assembled directly in
161
+ `gen_iscc_code_v0`.
162
+ - **`bits` parameter** is always in bits (64, 128, 256), not bytes. The codec encodes it as
163
+ `(bits / 32) - 1`.
164
+ - **Result structs are `#[non_exhaustive]`** -- do not construct them with struct literal syntax
165
+ outside this crate; use the `gen_*_v0` functions.
166
+ - **`DataHasher.update()` tail buffering** -- the last CDC chunk is retained as a tail until
167
+ `finalize()` or the next `update()`. This matches the Python `push()` / `prev_chunk` pattern.
168
+ - **Conformance vector format** -- `data.json` inputs use `"stream:<hex>"` for byte data, JSON
169
+ arrays for integer vectors, and plain strings for text. Read the test code for parsing patterns.
170
+ - **Text normalization order matters** -- `text_clean` applies NFKC, then control-char removal, then
171
+ line collapsing. `text_collapse` applies NFD, lowercase, filter C/M/P categories, then NFKC.
172
+ This mirrors the reference implementation step for step; do not reorder these steps. Unicode
173
+ data comes from the tables the dependencies ship (`unicode-normalization`,
174
+ `unicode-general-category`, and `str::to_lowercase()` from std), matching the reference's use of
175
+ whatever `unicodedata` its interpreter ships.
176
+ - **JSON canonicalization** -- the crate uses `serde_json_canonicalizer` for RFC 8785 (JCS)
177
+ compliant serialization of JSON metadata, matching iscc-core's `jcs.canonicalize()` behavior.