kobako 0.12.2-x86_64-linux → 0.14.0-x86_64-linux
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.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +41 -0
- data/README.md +5 -3
- data/ROADMAP.md +26 -0
- data/crates/kobako-runtime/CHANGELOG.md +15 -0
- data/crates/kobako-runtime/README.md +1 -1
- data/crates/kobako-wasmtime/CHANGELOG.md +15 -0
- data/crates/kobako-wasmtime/README.md +1 -1
- data/data/kobako.wasm +0 -0
- data/lib/kobako/3.3/kobako.so +0 -0
- data/lib/kobako/3.4/kobako.so +0 -0
- data/lib/kobako/4.0/kobako.so +0 -0
- data/lib/kobako/catalog/handles.rb +2 -2
- data/lib/kobako/catalog/namespaces.rb +2 -2
- data/lib/kobako/catalog/snippets.rb +1 -1
- data/lib/kobako/codec/decoder.rb +7 -7
- data/lib/kobako/codec/encoder.rb +2 -2
- data/lib/kobako/codec/error.rb +3 -3
- data/lib/kobako/codec/factory.rb +10 -10
- data/lib/kobako/codec/handle_walk.rb +17 -21
- data/lib/kobako/codec/utils.rb +9 -9
- data/lib/kobako/codec.rb +4 -4
- data/lib/kobako/errors.rb +14 -39
- data/lib/kobako/handle.rb +5 -2
- data/lib/kobako/namespace.rb +3 -3
- data/lib/kobako/outcome.rb +1 -0
- data/lib/kobako/sandbox.rb +61 -33
- data/lib/kobako/sandbox_options.rb +51 -9
- data/lib/kobako/transport/dispatcher.rb +17 -14
- data/lib/kobako/transport/request.rb +2 -2
- data/lib/kobako/transport/response.rb +2 -2
- data/lib/kobako/transport/run.rb +1 -1
- data/lib/kobako/transport/yield.rb +3 -3
- data/lib/kobako/transport/yielder.rb +6 -6
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +0 -1
- data/release-please-config.json +66 -6
- data/sig/kobako/codec/handle_walk.rbs +2 -2
- data/sig/kobako/codec.rbs +11 -0
- data/sig/kobako/handle.rbs +0 -2
- data/sig/kobako/runtime.rbs +8 -3
- data/sig/kobako/sandbox.rbs +9 -5
- data/sig/kobako/sandbox_options.rbs +11 -2
- data/sig/kobako/transport/dispatcher.rbs +8 -8
- data/sig/kobako/transport/run.rbs +1 -1
- data/sig/kobako/transport/yielder.rbs +2 -2
- data/sig/kobako/transport.rbs +8 -0
- metadata +3 -4
- data/lib/kobako/snapshot.rb +0 -32
- data/sig/kobako/snapshot.rbs +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8fd7f2d9247b940469cb3b45486bec1c9a935e8ded2e84db54ac13604103f1b1
|
|
4
|
+
data.tar.gz: 29d14df5c7b29841036368eb5f4285b8d4d5e00e3eec7e145752836bae71fe6d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 198273370c7a5824f60acc112db2f1c2c57601ce0dc3b8573f07d7faacda7cf1bb7e017b84252c1fd43a09b726a66e7573e735d3a7e695fe6fa22c718f31cd7e
|
|
7
|
+
data.tar.gz: 243fc682f59f7852d88fae9d79aee94cf254312666f4bdb8688188ba6de415eac9f5fade45c5009e67aae2e8df186f87cd932edd71478591313170e6d202f785
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{".":"0.
|
|
1
|
+
{".":"0.14.0","wasm/kobako-core":"0.8.0","wasm/kobako-mruby":"0.8.0","wasm/kobako-io":"0.8.0","wasm/kobako-json":"0.8.0","wasm/kobako-regexp":"0.8.0","wasm/kobako-baker":"0.8.0","crates/kobako-codec":"0.8.0","crates/kobako-runtime":"0.8.0","crates/kobako-wasmtime":"0.8.0","crates/kobako":"0.8.0"}
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.14.0](https://github.com/elct9620/kobako/compare/v0.13.0...v0.14.0) (2026-07-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **codec:** add the Run invocation envelope to the wire tier ([dbdd760](https://github.com/elct9620/kobako/commit/dbdd760ddc258681669f7f620f63b75f36322687))
|
|
9
|
+
* **crates:** add the kobako host SDK skeleton ([8a99d09](https://github.com/elct9620/kobako/commit/8a99d09ef7068a6738d44f1a735d39516b24156b))
|
|
10
|
+
* **crates:** add the parity runner to the kobako SDK ([998f059](https://github.com/elct9620/kobako/commit/998f059abd308ef921c295658aaf8377febb44e2))
|
|
11
|
+
* **crates:** grow the SDK capability-Handle table ([f93fe8f](https://github.com/elct9620/kobako/commit/f93fe8f3dce2509cfa527229f8f593f4d816b940))
|
|
12
|
+
* **crates:** grow the SDK Member block-yield seam ([4404713](https://github.com/elct9620/kobako/commit/44047130f309a2c935198077fb4f7f86839355e7))
|
|
13
|
+
* **crates:** grow the SDK preload and run invocation seams ([d8d5fe2](https://github.com/elct9620/kobako/commit/d8d5fe268a56d45dad4f8b35a25e942a559dcd5f))
|
|
14
|
+
* **crates:** honor the respond_to_guest narrowing on the SDK Member seam ([0f5eff1](https://github.com/elct9620/kobako/commit/0f5eff16a1e9f2229ad9d9c9316bf94e92035301))
|
|
15
|
+
* **crates:** let a resolved Handle recover its concrete member type ([abd5502](https://github.com/elct9620/kobako/commit/abd55029a44a7631d323c3aec3b625d9692f9c5b))
|
|
16
|
+
* **crates:** mark the SDK Error taxonomy non_exhaustive ([001fc69](https://github.com/elct9620/kobako/commit/001fc69e637d2c046f55cb517f9d9cf931793715))
|
|
17
|
+
* **examples:** add the guest→host dispatch half to the Rust host ([5cdde68](https://github.com/elct9620/kobako/commit/5cdde68824352c5685aaa94ae464e909705a4648))
|
|
18
|
+
* **examples:** assemble a minimal Rust host on the published crates ([6b98680](https://github.com/elct9620/kobako/commit/6b98680bcb625f9790f44df839035427a576e266))
|
|
19
|
+
* **tasks:** add a rails-stats-style rake stats size report ([c02d530](https://github.com/elct9620/kobako/commit/c02d530d43a85594323b7801fdbe75aa95ae7f8c))
|
|
20
|
+
* **tasks:** gate parity coverage over the CORE anchor manifest ([d26972c](https://github.com/elct9620/kobako/commit/d26972c1ad51e05df951643e17d66a6c811ba862))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* **crates:** give SetupError a Display so Error::Setup reads cleanly ([bc8b128](https://github.com/elct9620/kobako/commit/bc8b128c9e296319c7fef47441b412d2ce345dff))
|
|
26
|
+
* **crates:** keep the no-timeout epoch deadline within range ([a3255df](https://github.com/elct9620/kobako/commit/a3255df98a77825bb39b571a60fe6ff83d269d19))
|
|
27
|
+
* **crates:** reject trailing bytes on Request and Run decode ([8e4929b](https://github.com/elct9620/kobako/commit/8e4929b64f3ea690f38211888070c2511da84754))
|
|
28
|
+
* **lib:** close the Data #with seam on Handle construction ([c0b50ae](https://github.com/elct9620/kobako/commit/c0b50aec659e32a72c905aaf94c939ac009ad621))
|
|
29
|
+
* **release:** resume the gem push loop past already-live versions ([170ee9b](https://github.com/elct9620/kobako/commit/170ee9bae6da3a65b4016040259e31e4721dfcfb))
|
|
30
|
+
* **release:** treat a yanked-only version as unpublished when publishing ([3111cc0](https://github.com/elct9620/kobako/commit/3111cc072a7c9d18b129fd2762f267d855b48d55))
|
|
31
|
+
* **transport:** fold fault messages to UTF-8 before they ride the wire ([0be8d40](https://github.com/elct9620/kobako/commit/0be8d4068dc5647f86746e80b356b0b9d52051f7))
|
|
32
|
+
|
|
33
|
+
## [0.13.0](https://github.com/elct9620/kobako/compare/v0.12.2...v0.13.0) (2026-07-03)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
* **crates:** build the requested isolation profile into the WASI context ([63c25d8](https://github.com/elct9620/kobako/commit/63c25d835d4d03010c1658217cee412318e6b5d8))
|
|
39
|
+
* enforce the isolation-profile floor at Sandbox construction ([73f0dfe](https://github.com/elct9620/kobako/commit/73f0dfe34a144045a559a28caec31468351de64a))
|
|
40
|
+
* forward the Sandbox profile request through the ext to the driver ([f47f906](https://github.com/elct9620/kobako/commit/f47f9063aa56462be023f5c76cbc73db6e4315ad))
|
|
41
|
+
* keep guest output readable after a trap ([464454c](https://github.com/elct9620/kobako/commit/464454cd774db96ad72b3787007f2ce015673587))
|
|
42
|
+
* **runtime:** runtimes declare their isolation profile ([f89717a](https://github.com/elct9620/kobako/commit/f89717a6bc9809f0de0df78f97da33a49a1474ac))
|
|
43
|
+
|
|
3
44
|
## [0.12.2](https://github.com/elct9620/kobako/compare/v0.12.1...v0.12.2) (2026-07-02)
|
|
4
45
|
|
|
5
46
|
|
data/README.md
CHANGED
|
@@ -154,6 +154,8 @@ sandbox = Kobako::Sandbox.new(
|
|
|
154
154
|
|
|
155
155
|
`memory_limit` covers the per-invocation `memory.grow` delta from the entry baseline, so a Sandbox reused across invocations does not silently accumulate against a global budget.
|
|
156
156
|
|
|
157
|
+
A fifth option, `profile:`, requests the Sandbox's isolation posture on the `:permissive` < `:hermetic` ladder (default `:hermetic`). `:hermetic` denies the guest ambient time and entropy; `:permissive` lets the guest's `wasi:clocks` / `wasi:random` read live host sources — an explicit trade of reproducibility, with filesystem, environment, and network still unreachable. The request is also a floor: construction fails with `Kobako::SetupError` on a runtime that declares a weaker posture than requested. See [`docs/security-model.md`](docs/security-model.md) § Isolation profiles.
|
|
158
|
+
|
|
157
159
|
### Invocation Lifecycle
|
|
158
160
|
|
|
159
161
|
One Sandbox serves many invocations. Service bindings and preloaded snippets persist across calls; capability state (Handles, stdout, stderr, memory delta) resets between them.
|
|
@@ -300,10 +302,10 @@ sandbox.run(:Greeter, name: "world") # => "hello, world"
|
|
|
300
302
|
|
|
301
303
|
| Form | Signature | Snippet name source | Validation timing |
|
|
302
304
|
|----------|--------------------------------------|---------------------------------------|----------------------------------------------------------------------------|
|
|
303
|
-
| Source | `preload(code: "...", name: :Const)` | The `name:` keyword |
|
|
304
|
-
| Bytecode | `preload(binary: bytes)` | Read from the bytecode's `debug_info` |
|
|
305
|
+
| Source | `preload(code: "...", name: :Const)` | The `name:` keyword | First invocation's replay; compile errors raise `Kobako::SandboxError` |
|
|
306
|
+
| Bytecode | `preload(binary: bytes)` | Read from the bytecode's `debug_info` | First invocation's replay; structural failure raises `Kobako::BytecodeError` |
|
|
305
307
|
|
|
306
|
-
Use the source form for snippets authored in your repo
|
|
308
|
+
Use the source form for snippets authored in your repo; use the bytecode form when snippets ship as build artifacts from a separate `mrbc` pipeline. Both replay through the same per-invocation path, so no snippet content failure surfaces at `#preload` — force the first replay with a no-op invocation (e.g. `sandbox.eval("nil")`) when you want validation before real traffic.
|
|
307
309
|
|
|
308
310
|
## Security
|
|
309
311
|
|
data/ROADMAP.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Roadmap
|
|
2
|
+
|
|
3
|
+
kobako is a Ruby gem providing an in-process Wasm sandbox for untrusted mruby
|
|
4
|
+
code: a wasmtime host runs a precompiled `kobako.wasm` guest, with host↔guest
|
|
5
|
+
Transport over a MessagePack wire. Features cover one-shot `#eval`, preload +
|
|
6
|
+
`#run` dispatch, Service injection through Namespaces / Members, opaque
|
|
7
|
+
Capability Handles, block yield re-entry, three-class error attribution,
|
|
8
|
+
output capture, and a warm Sandbox pool.
|
|
9
|
+
|
|
10
|
+
| Feature | Entry Points | Notes |
|
|
11
|
+
|---------|-------------|-------|
|
|
12
|
+
| ✅ [F-01 Sandbox instantiation](docs/behavior/lifecycle.md) | [lib/kobako/sandbox.rb](lib/kobako/sandbox.rb) | B-22 (per-Thread isolation) is exercised only indirectly through the pool contention tests; no test cites it |
|
|
13
|
+
| ✅ [F-02 Namespace declaration](docs/behavior/registration.md) | [lib/kobako/catalog/namespaces.rb](lib/kobako/catalog/namespaces.rb) | — |
|
|
14
|
+
| ✅ [F-03 Member binding](docs/behavior/registration.md) | [lib/kobako/namespace.rb](lib/kobako/namespace.rb) | — |
|
|
15
|
+
| ✅ [F-04 Synchronous mruby source execution (`#eval`)](docs/behavior/lifecycle.md) | [lib/kobako/sandbox.rb](lib/kobako/sandbox.rb) | — |
|
|
16
|
+
| ✅ [F-05 Guest-initiated Transport dispatch](docs/behavior/dispatch.md) | [lib/kobako/transport/dispatcher.rb](lib/kobako/transport/dispatcher.rb) | — |
|
|
17
|
+
| ✅ [F-06 Capability Handle encoding and referencing](docs/behavior/dispatch.md) | [lib/kobako/catalog/handles.rb](lib/kobako/catalog/handles.rb) | — |
|
|
18
|
+
| ✅ [F-07 Three-class error attribution and raising](docs/behavior/errors.md) | [lib/kobako/outcome.rb](lib/kobako/outcome.rb) | E-26 (guest-entry envelope decode failure) has no exercising test — not reachable through the public API |
|
|
19
|
+
| ✅ [F-08 Guest output capture](docs/behavior/lifecycle.md) | [lib/kobako/capture.rb](lib/kobako/capture.rb) | — |
|
|
20
|
+
| ✅ [F-09 Host–guest message codec](docs/wire-codec.md) | [lib/kobako/codec/](lib/kobako/codec/) | — |
|
|
21
|
+
| ✅ [F-10 Reproducible build pipeline](SPEC.md#code-organization) | [tasks/wasm/build.rake](tasks/wasm/build.rake) | Verified by build-time gates (`rake anchors`, double-bake byte-identity, gemspec whitelist), not `test/` |
|
|
22
|
+
| ✅ [F-11 Multi-layer test and benchmark suite](SPEC.md#testing-style) | [test/](test/) | Benchmarks live in [benchmark/](benchmark/) with the gate in `tasks/bench/`; the anchor baseline advances only by deliberate re-bless |
|
|
23
|
+
| ✅ [F-12 Guest block reception and yield re-entry](docs/behavior/yield.md) | [lib/kobako/transport/yielder.rb](lib/kobako/transport/yielder.rb) | — |
|
|
24
|
+
| ✅ [F-13 Snippet preloading (`#preload`)](docs/behavior/invocation.md) | [lib/kobako/catalog/snippets.rb](lib/kobako/catalog/snippets.rb) | — |
|
|
25
|
+
| ✅ [F-14 Synchronous entrypoint dispatch (`#run`)](docs/behavior/invocation.md) | [lib/kobako/sandbox.rb](lib/kobako/sandbox.rb) | — |
|
|
26
|
+
| ✅ [F-15 Warm Sandbox pool checkout (`Kobako::Pool`)](docs/behavior/runtime.md) | [lib/kobako/pool.rb](lib/kobako/pool.rb) | — |
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.8.0](https://github.com/elct9620/kobako/compare/kobako-runtime-v0.7.0...kobako-runtime-v0.8.0) (2026-07-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **crates:** give SetupError a Display so Error::Setup reads cleanly ([bc8b128](https://github.com/elct9620/kobako/commit/bc8b128c9e296319c7fef47441b412d2ce345dff))
|
|
9
|
+
|
|
10
|
+
## [0.7.0](https://github.com/elct9620/kobako/compare/kobako-runtime-v0.6.1...kobako-runtime-v0.7.0) (2026-07-03)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **crates:** build the requested isolation profile into the WASI context ([63c25d8](https://github.com/elct9620/kobako/commit/63c25d835d4d03010c1658217cee412318e6b5d8))
|
|
16
|
+
* **runtime:** runtimes declare their isolation profile ([f89717a](https://github.com/elct9620/kobako/commit/f89717a6bc9809f0de0df78f97da33a49a1474ac))
|
|
17
|
+
|
|
3
18
|
## [0.6.1](https://github.com/elct9620/kobako/compare/kobako-runtime-v0.6.0...kobako-runtime-v0.6.1) (2026-07-02)
|
|
4
19
|
|
|
5
20
|
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.8.0](https://github.com/elct9620/kobako/compare/kobako-wasmtime-v0.7.0...kobako-wasmtime-v0.8.0) (2026-07-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **crates:** keep the no-timeout epoch deadline within range ([a3255df](https://github.com/elct9620/kobako/commit/a3255df98a77825bb39b571a60fe6ff83d269d19))
|
|
9
|
+
|
|
10
|
+
## [0.7.0](https://github.com/elct9620/kobako/compare/kobako-wasmtime-v0.6.1...kobako-wasmtime-v0.7.0) (2026-07-03)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **crates:** build the requested isolation profile into the WASI context ([63c25d8](https://github.com/elct9620/kobako/commit/63c25d835d4d03010c1658217cee412318e6b5d8))
|
|
16
|
+
* **runtime:** runtimes declare their isolation profile ([f89717a](https://github.com/elct9620/kobako/commit/f89717a6bc9809f0de0df78f97da33a49a1474ac))
|
|
17
|
+
|
|
3
18
|
## [0.6.1](https://github.com/elct9620/kobako/compare/kobako-wasmtime-v0.6.0...kobako-wasmtime-v0.6.1) (2026-07-02)
|
|
4
19
|
|
|
5
20
|
|
data/data/kobako.wasm
CHANGED
|
Binary file
|
data/lib/kobako/3.3/kobako.so
CHANGED
|
Binary file
|
data/lib/kobako/3.4/kobako.so
CHANGED
|
Binary file
|
data/lib/kobako/4.0/kobako.so
CHANGED
|
Binary file
|
|
@@ -95,7 +95,7 @@ module Kobako
|
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
-
# Guard
|
|
98
|
+
# Guard #alloc against issuing an ID past the cap. Returns +nil+
|
|
99
99
|
# on success; raises +Kobako::HandleExhaustedError+ at exhaustion.
|
|
100
100
|
def ensure_capacity!
|
|
101
101
|
cap = Kobako::Handle::MAX_ID
|
|
@@ -107,7 +107,7 @@ module Kobako
|
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
# Single source of truth for the "unknown Handle id" raise used by
|
|
110
|
-
#
|
|
110
|
+
# #fetch. Returns +nil+ on success; raises +Kobako::SandboxError+
|
|
111
111
|
# when +id+ is not currently bound.
|
|
112
112
|
def require_bound!(id)
|
|
113
113
|
return if @entries.key?(id)
|
|
@@ -71,7 +71,7 @@ module Kobako
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
# Encode the preamble as msgpack bytes for stdin Frame 1 delivery.
|
|
74
|
-
# Routes through
|
|
74
|
+
# Routes through Kobako::Codec::Encoder like every other host-side
|
|
75
75
|
# wire encode so there is a single codec path; the preamble carries
|
|
76
76
|
# only Strings and Arrays, so none of the kobako ext types actually
|
|
77
77
|
# fire. Structure: +[["Namespace", ["MemberA", "MemberB"]], ...]+.
|
|
@@ -106,7 +106,7 @@ module Kobako
|
|
|
106
106
|
self
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
# Returns +true+ when
|
|
109
|
+
# Returns +true+ when #seal! has been called, +false+ otherwise.
|
|
110
110
|
def sealed?
|
|
111
111
|
@sealed
|
|
112
112
|
end
|
|
@@ -43,7 +43,7 @@ module Kobako
|
|
|
43
43
|
#
|
|
44
44
|
# The bytes are memoized — the table is replayed verbatim on every
|
|
45
45
|
# invocation after sealing, so Frame 3 never changes between
|
|
46
|
-
# encodes;
|
|
46
|
+
# encodes; #register drops the memo while the table is still open.
|
|
47
47
|
# Unlike +Catalog::Namespaces#encode+, which gates its memo on the
|
|
48
48
|
# seal, this one can fill eagerly and invalidate in +#register+
|
|
49
49
|
# because every mutation funnels through that single method — there is
|
data/lib/kobako/codec/decoder.rb
CHANGED
|
@@ -12,23 +12,23 @@ module Kobako
|
|
|
12
12
|
# ({docs/wire-codec.md}[link:../../../docs/wire-codec.md] § Type Mapping).
|
|
13
13
|
#
|
|
14
14
|
# Translates msgpack gem exceptions into the kobako error taxonomy
|
|
15
|
-
# (
|
|
15
|
+
# (Truncated, InvalidType, InvalidEncoding, UnsupportedType) so
|
|
16
16
|
# callers can pattern-match on the SPEC's wire-violation categories
|
|
17
17
|
# without leaking the gem's internal exception classes.
|
|
18
18
|
#
|
|
19
|
-
# Public API is a single function —
|
|
19
|
+
# Public API is a single function — +.decode+. The decoder is
|
|
20
20
|
# stateless; the +MessagePack::Unpacker+ instance is built per call
|
|
21
21
|
# because callers always decode exactly one wire value at a time.
|
|
22
22
|
module Decoder
|
|
23
23
|
# Decode +bytes+ into one Ruby value and validate transitively
|
|
24
|
-
# against the SPEC type mapping. Raises
|
|
25
|
-
# or
|
|
24
|
+
# against the SPEC type mapping. Raises Truncated, InvalidType,
|
|
25
|
+
# or InvalidEncoding on wire violations.
|
|
26
26
|
#
|
|
27
27
|
# When a block is given, the decoded value is yielded and the block's
|
|
28
28
|
# result is returned — wire Value Objects use this to build themselves
|
|
29
29
|
# from the decoded payload. The block runs inside this method's
|
|
30
30
|
# rescue, so a Value Object's +ArgumentError+ invariant failure
|
|
31
|
-
# surfaces as
|
|
31
|
+
# surfaces as InvalidType without a separate Utils.with_boundary
|
|
32
32
|
# wrapper at the call site.
|
|
33
33
|
def self.decode(bytes)
|
|
34
34
|
value = Factory.load(bytes.b)
|
|
@@ -37,7 +37,7 @@ module Kobako
|
|
|
37
37
|
# msgpack gem raises the format/type errors below; +ArgumentError+
|
|
38
38
|
# comes from our ext-type validators (Handle id range, Exception type
|
|
39
39
|
# whitelist) and from a yielded block's Value Object invariants — both
|
|
40
|
-
# are wire violations, so both map to
|
|
40
|
+
# are wire violations, so both map to InvalidType.
|
|
41
41
|
rescue ::MessagePack::UnknownExtTypeError, ::MessagePack::MalformedFormatError,
|
|
42
42
|
::MessagePack::StackError, ::ArgumentError => e
|
|
43
43
|
raise InvalidType, e.message
|
|
@@ -53,7 +53,7 @@ module Kobako
|
|
|
53
53
|
# Encoding Rules). The msgpack gem returns UTF-8-tagged Strings for
|
|
54
54
|
# str family but does not validate the bytes; +bin+ family decodes
|
|
55
55
|
# to ASCII-8BIT. Walk the tree once and reject invalid UTF-8 in any
|
|
56
|
-
# str-typed leaf via
|
|
56
|
+
# str-typed leaf via Utils.assert_utf8!. Kobako::Fault
|
|
57
57
|
# payloads are validated transitively: +Factory.unpack_fault+
|
|
58
58
|
# feeds the inner ext-0x02 bytes back through this Decoder, so their
|
|
59
59
|
# +str+ fields are already covered by the time control returns here.
|
data/lib/kobako/codec/encoder.rb
CHANGED
|
@@ -14,9 +14,9 @@ module Kobako
|
|
|
14
14
|
# strings, arrays, and maps go through the gem's narrowest-encoding
|
|
15
15
|
# logic; the three kobako-specific ext types (0x00 Symbol, 0x01
|
|
16
16
|
# Capability Handle, 0x02 Exception envelope) are registered on
|
|
17
|
-
# the cached
|
|
17
|
+
# the cached Kobako::Codec::Factory singleton.
|
|
18
18
|
#
|
|
19
|
-
# Public API is a single function —
|
|
19
|
+
# Public API is a single function — +.encode+. The codec is stateless;
|
|
20
20
|
# there is no buffer accumulator and no streaming write API. Callers
|
|
21
21
|
# that need to concatenate multiple encodings build the bytes
|
|
22
22
|
# themselves.
|
data/lib/kobako/codec/error.rb
CHANGED
|
@@ -7,11 +7,11 @@ module Kobako
|
|
|
7
7
|
# The wire codec implements the binary contract pinned in
|
|
8
8
|
# {docs/wire-codec.md}[link:../../../docs/wire-codec.md] § Type Mapping.
|
|
9
9
|
# Every wire violation surfaces as a
|
|
10
|
-
# subclass of
|
|
10
|
+
# subclass of Error so callers can pattern-match on the specific
|
|
11
11
|
# fault while still rescuing all codec faults via this base class.
|
|
12
12
|
#
|
|
13
13
|
# Higher layers (e.g. the Sandbox dispatch loop) translate these into
|
|
14
|
-
# the public
|
|
14
|
+
# the public Kobako::SandboxError / Kobako::TrapError taxonomy.
|
|
15
15
|
class Error < StandardError; end
|
|
16
16
|
|
|
17
17
|
# Input ended before the type prefix or payload was fully consumed.
|
|
@@ -21,7 +21,7 @@ module Kobako
|
|
|
21
21
|
# type mapping (e.g. an unknown ext code, or a reserved msgpack tag).
|
|
22
22
|
class InvalidType < Error; end
|
|
23
23
|
|
|
24
|
-
# A msgpack
|
|
24
|
+
# A msgpack +str+ payload was not valid UTF-8, or an ext 0x00 Symbol
|
|
25
25
|
# payload was not valid UTF-8 — both are wire violations per SPEC.
|
|
26
26
|
class InvalidEncoding < Error; end
|
|
27
27
|
|
data/lib/kobako/codec/factory.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Kobako
|
|
|
16
16
|
# § Ext Types).
|
|
17
17
|
#
|
|
18
18
|
# The factory is the single place in the host gem that touches the
|
|
19
|
-
# msgpack API — both
|
|
19
|
+
# msgpack API — both Encoder and Decoder delegate through it, so
|
|
20
20
|
# the three kobako ext codes (0x00 Symbol, 0x01 Capability Handle,
|
|
21
21
|
# 0x02 Exception envelope) are configured exactly once at first use.
|
|
22
22
|
#
|
|
@@ -93,11 +93,11 @@ module Kobako
|
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
# Validate the ext-0x00 payload as UTF-8 and intern. Raises
|
|
96
|
-
#
|
|
96
|
+
# InvalidEncoding on invalid bytes — SPEC forbids the
|
|
97
97
|
# binary-encoding fallback that msgpack-gem's default unpacker
|
|
98
98
|
# would otherwise apply. The re-tag step lives here because the
|
|
99
99
|
# msgpack ext-type unpacker hands us binary bytes; the assertion
|
|
100
|
-
# itself is shared with
|
|
100
|
+
# itself is shared with Decoder via Utils.assert_utf8!. The
|
|
101
101
|
# +"Symbol"+ label keeps the error message in Ruby vocabulary
|
|
102
102
|
# rather than wire-ext-code vocabulary.
|
|
103
103
|
def unpack_symbol(payload)
|
|
@@ -125,7 +125,7 @@ module Kobako
|
|
|
125
125
|
# Peel off the fixext-4 frame, hand the bytes to the
|
|
126
126
|
# Host-Gem-internal +Kobako::Handle.restore+ factory, and
|
|
127
127
|
# translate the +ArgumentError+ raised by Handle's invariants
|
|
128
|
-
# into a wire-layer +InvalidType+ via
|
|
128
|
+
# into a wire-layer +InvalidType+ via Codec::Utils.with_boundary.
|
|
129
129
|
# The Value Object owns the id-range contract; this method only
|
|
130
130
|
# owns the frame shape.
|
|
131
131
|
def unpack_handle(payload)
|
|
@@ -136,11 +136,11 @@ module Kobako
|
|
|
136
136
|
Codec::Utils.with_boundary { Kobako::Handle.restore(id) }
|
|
137
137
|
end
|
|
138
138
|
|
|
139
|
-
# Encode the inner ext-0x02 map via
|
|
139
|
+
# Encode the inner ext-0x02 map via Encoder (not +factory.dump+) so
|
|
140
140
|
# the embedded payload flows through the same boundary as a top-level
|
|
141
141
|
# encode — nested kobako values (Handle, nested Fault) reach the
|
|
142
142
|
# registered ext-type packers via the cached singleton. A +details+
|
|
143
|
-
# chain nested past
|
|
143
|
+
# chain nested past MAX_EXT_DEPTH has no wire representation and
|
|
144
144
|
# surfaces as +UnsupportedType+.
|
|
145
145
|
def pack_fault(fault)
|
|
146
146
|
within_ext_frame(UnsupportedType) do
|
|
@@ -149,12 +149,12 @@ module Kobako
|
|
|
149
149
|
end
|
|
150
150
|
|
|
151
151
|
# Peel the embedded msgpack map and hand it to +Kobako::Fault.new+
|
|
152
|
-
# inside
|
|
152
|
+
# inside Decoder.decode's block form, so the value-object's
|
|
153
153
|
# +ArgumentError+ invariants surface as +InvalidType+ through the
|
|
154
|
-
# decoder boundary. Inner decode goes through
|
|
154
|
+
# decoder boundary. Inner decode goes through Decoder (not
|
|
155
155
|
# +factory.load+) so the embedded +str+ payloads flow through the
|
|
156
156
|
# same UTF-8 validation as a top-level decode. A nested ext 0x02 in
|
|
157
|
-
# +details+ re-enters this method, so
|
|
157
|
+
# +details+ re-enters this method, so #within_ext_frame bounds the
|
|
158
158
|
# chain depth to keep it from exhausting the native stack.
|
|
159
159
|
def unpack_fault(payload)
|
|
160
160
|
within_ext_frame(InvalidType) do
|
|
@@ -167,7 +167,7 @@ module Kobako
|
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
# Track ext-envelope re-entry depth and refuse a chain past
|
|
170
|
-
#
|
|
170
|
+
# MAX_EXT_DEPTH, raising +over_limit+ so the failure lands in the
|
|
171
171
|
# caller's existing wire-error class. The counter is thread-scoped and
|
|
172
172
|
# balanced by the +ensure+, so a raise mid-chain still unwinds it to
|
|
173
173
|
# its entry value.
|
|
@@ -5,16 +5,16 @@ require_relative "../handle"
|
|
|
5
5
|
module Kobako
|
|
6
6
|
module Codec
|
|
7
7
|
# Substitutes Capability Handles into and out of a Ruby value tree at
|
|
8
|
-
# the host↔guest boundary.
|
|
8
|
+
# the host↔guest boundary. #deep_wrap allocates a +Kobako::Handle+ for
|
|
9
9
|
# each non-wire-representable leaf on the host→guest +#run+ argument
|
|
10
|
-
# path;
|
|
11
|
-
# host object on every guest→host value path.
|
|
12
|
-
# by-value codec-type predicate that decides which leaves
|
|
10
|
+
# path; #deep_restore resolves each wire-decoded Handle back to its
|
|
11
|
+
# host object on every guest→host value path. #representable? is the
|
|
12
|
+
# by-value codec-type predicate that decides which leaves #deep_wrap
|
|
13
13
|
# must wrap: the closed 12-entry wire type set
|
|
14
14
|
# ({docs/wire-codec.md}[link:../../../docs/wire-codec.md] § Type
|
|
15
15
|
# Mapping).
|
|
16
16
|
#
|
|
17
|
-
# All helpers are pure except
|
|
17
|
+
# All helpers are pure except #deep_wrap, whose only side effect is
|
|
18
18
|
# allocating new Handle ids into the supplied table.
|
|
19
19
|
module HandleWalk
|
|
20
20
|
module_function
|
|
@@ -24,7 +24,7 @@ module Kobako
|
|
|
24
24
|
# unsigned +uint 64+ maximum
|
|
25
25
|
# ({docs/wire-codec.md}[link:../../../docs/wire-codec.md] § Type
|
|
26
26
|
# Mapping #3, the +fixint+ / +int 8..64+ / +uint 8..64+ union).
|
|
27
|
-
# Anchored as a +Range+ so
|
|
27
|
+
# Anchored as a +Range+ so #primitive_type? stays a single
|
|
28
28
|
# dispatch line. This is the codec's encode domain — not to
|
|
29
29
|
# be confused with the Handle id range, which lives on
|
|
30
30
|
# +Kobako::Handle+ as +MIN_ID+ / +MAX_ID+ (1..2^31 − 1) and
|
|
@@ -41,13 +41,13 @@ module Kobako
|
|
|
41
41
|
# representable. Integers outside the codec's signed-64 /
|
|
42
42
|
# unsigned-64 union are rejected so the predicate agrees with the
|
|
43
43
|
# msgpack gem's encode-time +RangeError+ behaviour the codec
|
|
44
|
-
# already surfaces as
|
|
44
|
+
# already surfaces as UnsupportedType.
|
|
45
45
|
def representable?(value)
|
|
46
46
|
primitive_type?(value) || container_representable?(value)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# Deep-walk Array / Hash containers in +value+ and replace every
|
|
50
|
-
# leaf that fails
|
|
50
|
+
# leaf that fails #representable? with a +Kobako::Handle+
|
|
51
51
|
# allocated from +handler+. The
|
|
52
52
|
# walk only descends through representable container shapes
|
|
53
53
|
# (Array, Hash) one structural level at a time; a non-representable
|
|
@@ -61,13 +61,9 @@ module Kobako
|
|
|
61
61
|
# whose leaves are either representable or +Kobako::Handle+
|
|
62
62
|
# tokens.
|
|
63
63
|
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
# inside a block would resolve against the enclosing +self+
|
|
68
|
-
# (still +HandleWalk+ at definition time, but the qualified form
|
|
69
|
-
# keeps the dispatch readable when the recursive call sits inside a
|
|
70
|
-
# Proc captured from elsewhere).
|
|
64
|
+
# Recursive calls spell the +HandleWalk.+ receiver so the dispatch
|
|
65
|
+
# stays valid even when a block is captured and run under a
|
|
66
|
+
# different +self+ (+module_function+ privatizes the instance copies).
|
|
71
67
|
def deep_wrap(value, handler)
|
|
72
68
|
case value
|
|
73
69
|
when ::Array then value.map { |element| HandleWalk.deep_wrap(element, handler) }
|
|
@@ -79,7 +75,7 @@ module Kobako
|
|
|
79
75
|
|
|
80
76
|
# Deep-walk Array / Hash containers in +value+ and replace every
|
|
81
77
|
# +Kobako::Handle+ leaf with the host-side object +handler+ resolves
|
|
82
|
-
# it to. The symmetric inverse of
|
|
78
|
+
# it to. The symmetric inverse of #deep_wrap: that walk allocates objects
|
|
83
79
|
# into Handles on the host→guest argument path; this walk resolves
|
|
84
80
|
# Handles back to their objects wherever a guest→host payload carries
|
|
85
81
|
# one — an invocation result, a yield-block result, or a dispatch
|
|
@@ -107,9 +103,9 @@ module Kobako
|
|
|
107
103
|
end
|
|
108
104
|
end
|
|
109
105
|
|
|
110
|
-
# The non-container branch of
|
|
106
|
+
# The non-container branch of #representable?: returns +true+ for
|
|
111
107
|
# the scalar leaves and an existing Handle. Not part of the
|
|
112
|
-
# public surface; reach for
|
|
108
|
+
# public surface; reach for #representable? instead.
|
|
113
109
|
def primitive_type?(value)
|
|
114
110
|
case value
|
|
115
111
|
when ::NilClass, ::TrueClass, ::FalseClass, ::Float, ::String, ::Symbol, Kobako::Handle then true
|
|
@@ -118,10 +114,10 @@ module Kobako
|
|
|
118
114
|
end
|
|
119
115
|
end
|
|
120
116
|
|
|
121
|
-
# The container branch of
|
|
117
|
+
# The container branch of #representable?: recurses into Array
|
|
122
118
|
# elements and Hash key+value pairs through the public
|
|
123
|
-
#
|
|
124
|
-
#
|
|
119
|
+
# #representable?. Not part of the public surface; reach for
|
|
120
|
+
# #representable? instead.
|
|
125
121
|
def container_representable?(value)
|
|
126
122
|
case value
|
|
127
123
|
when ::Array then value.all? { |element| HandleWalk.representable?(element) }
|
data/lib/kobako/codec/utils.rb
CHANGED
|
@@ -10,18 +10,18 @@ module Kobako
|
|
|
10
10
|
# - UTF-8 assertion at the codec boundary
|
|
11
11
|
# ({docs/wire-codec.md}[link:../../../docs/wire-codec.md]
|
|
12
12
|
# § str/bin Encoding Rules and § Ext Types → ext 0x00). Used by
|
|
13
|
-
#
|
|
13
|
+
# Decoder when walking +str+ family payloads and by Factory
|
|
14
14
|
# when validating the +ext 0x00+ Symbol payload.
|
|
15
15
|
# - +ArgumentError+ translation at the codec boundary
|
|
16
|
-
# (
|
|
17
|
-
#
|
|
16
|
+
# (#with_boundary) so the public taxonomy stays
|
|
17
|
+
# Kobako::Codec::Error.
|
|
18
18
|
#
|
|
19
19
|
# Both helpers are pure — they only inspect inputs, never mutate them.
|
|
20
|
-
# The host↔guest Handle substitution walk lives in
|
|
20
|
+
# The host↔guest Handle substitution walk lives in HandleWalk.
|
|
21
21
|
module Utils
|
|
22
22
|
module_function
|
|
23
23
|
|
|
24
|
-
# Raise
|
|
24
|
+
# Raise InvalidEncoding unless +string+'s bytes are valid under
|
|
25
25
|
# its current encoding tag. +label+ is the caller-supplied prefix
|
|
26
26
|
# for the error message (e.g. +"str payload"+, +"Symbol payload"+).
|
|
27
27
|
def assert_utf8!(string, label)
|
|
@@ -32,13 +32,13 @@ module Kobako
|
|
|
32
32
|
|
|
33
33
|
# Run +block+ at the codec boundary: a value object raises
|
|
34
34
|
# +ArgumentError+ when an invariant is violated at construction, and
|
|
35
|
-
# this helper surfaces that as
|
|
36
|
-
# stays
|
|
35
|
+
# this helper surfaces that as InvalidType so the public taxonomy
|
|
36
|
+
# stays Kobako::Codec::Error and never leaks +ArgumentError+ from
|
|
37
37
|
# the Ruby standard library.
|
|
38
38
|
#
|
|
39
39
|
# Reach for this only where a value object is constructed outside a
|
|
40
|
-
#
|
|
41
|
-
# mapping (worked example:
|
|
40
|
+
# Decoder.decode block, whose rescue already performs the same
|
|
41
|
+
# mapping (worked example: Factory#unpack_handle building
|
|
42
42
|
# +Handle.restore+ from a raw fixext payload). Do not use it for
|
|
43
43
|
# general-purpose validation outside the codec boundary —
|
|
44
44
|
# host-layer +ArgumentError+ values should propagate unchanged.
|
data/lib/kobako/codec.rb
CHANGED
|
@@ -18,12 +18,12 @@ module Kobako
|
|
|
18
18
|
# the kobako root so the codec can register them without depending
|
|
19
19
|
# upward on Transport.
|
|
20
20
|
#
|
|
21
|
-
# Backed by the official +msgpack+ gem via
|
|
22
|
-
#
|
|
21
|
+
# Backed by the official +msgpack+ gem via Factory; Encoder and
|
|
22
|
+
# Decoder are thin wrappers that register the three kobako-specific
|
|
23
23
|
# ext types (0x00 Symbol, 0x01 Capability Handle, 0x02 Exception
|
|
24
24
|
# envelope) on a single +MessagePack::Factory+ instance. The Rust side
|
|
25
|
-
# mirrors this layer as the +codec+ module in the +kobako-
|
|
26
|
-
# the ext-code constants live as module-private values on
|
|
25
|
+
# mirrors this layer as the +codec+ module in the +kobako-codec+ crate;
|
|
26
|
+
# the ext-code constants live as module-private values on Factory
|
|
27
27
|
# alongside +codec::EXT_SYMBOL+ / +codec::EXT_HANDLE+ /
|
|
28
28
|
# +codec::EXT_ERRENV+ on that side.
|
|
29
29
|
module Codec
|