kobako 0.20.0-aarch64-linux → 0.21.0-aarch64-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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +107 -0
  4. data/README.md +96 -44
  5. data/ROADMAP.md +1 -1
  6. data/crates/kobako-runtime/CHANGELOG.md +37 -0
  7. data/crates/kobako-runtime/README.md +1 -1
  8. data/crates/kobako-transport/CHANGELOG.md +31 -0
  9. data/crates/kobako-transport/README.md +43 -0
  10. data/crates/kobako-wasmtime/CHANGELOG.md +23 -0
  11. data/crates/kobako-wasmtime/README.md +1 -1
  12. data/data/kobako.wasm +0 -0
  13. data/lib/kobako/3.3/kobako.so +0 -0
  14. data/lib/kobako/3.4/kobako.so +0 -0
  15. data/lib/kobako/4.0/kobako.so +0 -0
  16. data/lib/kobako/catalog/services.rb +13 -21
  17. data/lib/kobako/catalog/snippets.rb +16 -34
  18. data/lib/kobako/codec/decoder.rb +10 -13
  19. data/lib/kobako/codec/encoder.rb +7 -7
  20. data/lib/kobako/codec/error.rb +6 -6
  21. data/lib/kobako/codec/ext_types.rb +12 -72
  22. data/lib/kobako/codec/handle_walk.rb +6 -6
  23. data/lib/kobako/codec/state.rb +4 -56
  24. data/lib/kobako/codec/utils.rb +4 -4
  25. data/lib/kobako/codec.rb +11 -21
  26. data/lib/kobako/context.rb +23 -17
  27. data/lib/kobako/errors.rb +32 -11
  28. data/lib/kobako/outcome.rb +71 -128
  29. data/lib/kobako/payload/arguments.rb +59 -0
  30. data/lib/kobako/payload.rb +19 -0
  31. data/lib/kobako/sandbox.rb +12 -13
  32. data/lib/kobako/sandbox_options.rb +1 -1
  33. data/lib/kobako/snippet/binary.rb +3 -4
  34. data/lib/kobako/snippet/source.rb +5 -6
  35. data/lib/kobako/snippet.rb +2 -2
  36. data/lib/kobako/transport/call.rb +21 -0
  37. data/lib/kobako/transport/dispatcher.rb +86 -135
  38. data/lib/kobako/transport/error.rb +21 -5
  39. data/lib/kobako/transport/reflection.rb +82 -0
  40. data/lib/kobako/transport/run.rb +25 -33
  41. data/lib/kobako/transport/yielder.rb +27 -36
  42. data/lib/kobako/transport.rb +11 -8
  43. data/lib/kobako/usage.rb +1 -1
  44. data/lib/kobako/version.rb +1 -1
  45. data/release-please-config.json +47 -2
  46. data/sig/kobako/catalog/services.rbs +1 -1
  47. data/sig/kobako/catalog/snippets.rbs +4 -4
  48. data/sig/kobako/codec/error.rbs +4 -4
  49. data/sig/kobako/codec/ext_types.rbs +0 -7
  50. data/sig/kobako/codec/state.rbs +0 -4
  51. data/sig/kobako/codec.rbs +4 -5
  52. data/sig/kobako/context.rbs +4 -4
  53. data/sig/kobako/errors.rbs +15 -3
  54. data/sig/kobako/outcome.rbs +12 -13
  55. data/sig/kobako/payload/arguments.rbs +26 -0
  56. data/sig/kobako/payload.rbs +4 -0
  57. data/sig/kobako/pool.rbs +0 -2
  58. data/sig/kobako/runtime.rbs +15 -13
  59. data/sig/kobako/snippet/binary.rbs +1 -1
  60. data/sig/kobako/snippet/source.rbs +1 -1
  61. data/sig/kobako/transport/call.rbs +21 -0
  62. data/sig/kobako/transport/dispatcher.rbs +8 -10
  63. data/sig/kobako/transport/error.rbs +11 -0
  64. data/sig/kobako/transport/reflection.rbs +15 -0
  65. data/sig/kobako/transport/run.rbs +1 -1
  66. data/sig/kobako/transport/yielder.rbs +2 -2
  67. data/sig/kobako/transport.rbs +8 -2
  68. metadata +12 -12
  69. data/lib/kobako/fault.rb +0 -38
  70. data/lib/kobako/outcome/panic.rb +0 -42
  71. data/lib/kobako/transport/request.rb +0 -76
  72. data/lib/kobako/transport/response.rb +0 -83
  73. data/lib/kobako/transport/yield.rb +0 -94
  74. data/sig/kobako/fault.rbs +0 -19
  75. data/sig/kobako/outcome/panic.rbs +0 -34
  76. data/sig/kobako/transport/request.rbs +0 -29
  77. data/sig/kobako/transport/response.rbs +0 -33
  78. data/sig/kobako/transport/yield.rbs +0 -34
@@ -6,38 +6,40 @@ module Kobako
6
6
  String path,
7
7
  (Float | Integer)? timeout_seconds,
8
8
  Integer? memory_limit,
9
- Integer? stdout_limit_bytes,
10
- Integer? stderr_limit_bytes,
9
+ Integer? stdout_limit,
10
+ Integer? stderr_limit,
11
11
  Symbol profile,
12
12
  Symbol gvl
13
13
  ) -> Runtime
14
14
 
15
15
  def eval: (
16
- ^(String, Kobako::Transport::_GuestYielder) -> String dispatch,
17
- String preamble,
16
+ Kobako::Transport::dispatch_proc dispatch,
17
+ Array[String] paths,
18
18
  String source,
19
- String snippets
19
+ Array[Kobako::Catalog::Snippets::tuple] snippets
20
20
  ) -> Kobako::Runtime::Snapshot
21
21
 
22
22
  def run: (
23
- ^(String, Kobako::Transport::_GuestYielder) -> String dispatch,
24
- String preamble,
25
- String snippets,
26
- String envelope
23
+ Kobako::Transport::dispatch_proc dispatch,
24
+ Array[String] paths,
25
+ Array[Kobako::Catalog::Snippets::tuple] snippets,
26
+ String entrypoint,
27
+ String payload
27
28
  ) -> Kobako::Runtime::Snapshot
28
29
 
29
30
  def profile: () -> Symbol
30
31
 
31
32
  # Frame-scoped guest re-entry handle the ext hands the dispatch Proc as
32
- # its second argument; stands in as the +String -> String+ callable the
33
- # host +Transport::Yielder+ invokes for a block yield.
33
+ # its last argument — the production conformer of
34
+ # +Kobako::Transport::_GuestYielder+, answering the Yield Reply already
35
+ # split off the core envelope.
34
36
  class GuestYielder
35
- def call: (String args_bytes) -> String
37
+ def call: (String args_bytes) -> [Symbol, String, String?]
36
38
  end
37
39
 
38
40
  # One invocation's result — the whole Snapshot the driver produced.
39
41
  class Snapshot
40
- def outcome: () -> String
42
+ def outcome: () -> [Symbol, String, Kobako::Outcome::panic_fields?]
41
43
 
42
44
  def trapped?: () -> bool
43
45
 
@@ -1,7 +1,7 @@
1
1
  module Kobako
2
2
  module Snippet
3
3
  class Binary < Data
4
- KIND: String
4
+ KIND: Symbol
5
5
 
6
6
  attr_reader body: String
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Kobako
2
2
  module Snippet
3
3
  class Source < Data
4
- KIND: String
4
+ KIND: Symbol
5
5
 
6
6
  attr_reader name: Symbol
7
7
  attr_reader body: String
@@ -0,0 +1,21 @@
1
+ module Kobako
2
+ module Transport
3
+ class Call < Data
4
+ attr_reader target: String | Integer
5
+ attr_reader method_name: String
6
+ attr_reader block_given: bool
7
+ attr_reader payload: String
8
+
9
+ def self.new: (target: String | Integer, method_name: String, block_given: bool, payload: String) -> Call
10
+ | (String | Integer, String, bool, String) -> Call
11
+
12
+ def initialize: (target: String | Integer, method_name: String, block_given: bool, payload: String) -> void
13
+
14
+ def with: (?target: String | Integer, ?method_name: String, ?block_given: bool, ?payload: String) -> Call
15
+
16
+ def ==: (untyped other) -> bool
17
+
18
+ def hash: () -> Integer
19
+ end
20
+ end
21
+ end
@@ -6,27 +6,25 @@ module Kobako
6
6
 
7
7
  BREAK_THROW: Symbol
8
8
 
9
- META_OWNERS: Array[Module]
10
9
 
11
- GADGET_OWNERS: Array[Module]
12
10
 
13
- CALLABLE_ALLOW: Array[Symbol]
14
11
 
15
- def self?.dispatch: (String request_bytes, Kobako::Transport::_ServiceRegistry resolver, Kobako::Codec::_HandleTable handler, Kobako::Transport::_GuestYielder yield_to_guest) -> String
12
+ def self?.dispatch: (Kobako::Transport::Call call, Kobako::Transport::_ServiceRegistry resolver, Kobako::Codec::_HandleTable handler, Kobako::Transport::_GuestYielder yield_to_guest) -> [bool, String, String?]
16
13
 
17
- def self?.resolve_call_args: (Kobako::Transport::Request request, Kobako::Codec::_HandleTable handler, bool carried_handle) -> [Array[untyped], Hash[Symbol, untyped]]
14
+ def self?.run: (Kobako::Transport::Call call, Kobako::Transport::_ServiceRegistry resolver, Kobako::Codec::_HandleTable handler, Kobako::Transport::Yielder? yielder) -> untyped
18
15
 
19
- def self?.encode_caught_error: (StandardError error) -> String
16
+ def self?.resolve_call_args: (Kobako::Payload::Arguments arguments, Kobako::Codec::_HandleTable handler, bool carried_handle) -> [Array[untyped], Hash[Symbol, untyped]]
17
+
18
+ def self?.caught_fault: (StandardError error) -> [String, String]
20
19
 
21
20
  def self?.invoke: (untyped target, String method, Array[untyped] args, Hash[Symbol, untyped] kwargs, ?Kobako::Transport::Yielder? yielder) -> untyped
22
21
 
23
- def self?.reject_meta_method!: (untyped target, Symbol name) -> void
22
+ def self?.reject_unreachable!: (untyped target, Symbol name) -> void
24
23
 
25
- def self?.reject_unexposed!: (untyped target, Symbol name) -> void
26
24
 
27
25
  def self?.resolve_arg: (untyped value, Kobako::Codec::_HandleTable handler) -> untyped
28
26
 
29
- def self?.resolve_target: (String | Kobako::Handle target, Kobako::Transport::_ServiceRegistry resolver, Kobako::Codec::_HandleTable handler) -> untyped
27
+ def self?.resolve_target: (String | Integer target, Kobako::Transport::_ServiceRegistry resolver, Kobako::Codec::_HandleTable handler) -> untyped
30
28
 
31
29
  def self?.resolve_path: (String path, Kobako::Transport::_ServiceRegistry resolver) -> untyped
32
30
 
@@ -36,7 +34,7 @@ module Kobako
36
34
 
37
35
  def self?.wrap_as_handle: (untyped value, Kobako::Codec::_HandleTable handler) -> Kobako::Handle
38
36
 
39
- def self?.encode_error: (String type, String message) -> String
37
+ def self?.fault: (String type, String message) -> [String, String]
40
38
  end
41
39
  end
42
40
  end
@@ -1,6 +1,17 @@
1
1
  module Kobako
2
2
  module Transport
3
3
  class Error < Kobako::SandboxError
4
+ @diagnostic: String?
5
+
6
+ def initialize: (
7
+ String message,
8
+ ?diagnostic: String?,
9
+ ?origin: String?,
10
+ ?klass: String?,
11
+ ?backtrace_lines: Array[String]?
12
+ ) -> void
13
+
14
+ def detailed_message: (?highlight: bool, **untyped) -> String
4
15
  end
5
16
  end
6
17
  end
@@ -0,0 +1,15 @@
1
+ module Kobako
2
+ module Transport
3
+ module Reflection
4
+ META_OWNERS: Array[Module]
5
+ GADGET_OWNERS: Array[Module]
6
+ CALLABLE_ALLOW: Array[Symbol]
7
+
8
+ def self?.refusal: (untyped target, Symbol name) -> String?
9
+
10
+ def self?.ambient_refusal: (untyped target, Symbol name) -> String?
11
+
12
+ def self?.narrowing_refusal: (untyped target, Symbol name) -> String?
13
+ end
14
+ end
15
+ end
@@ -11,7 +11,7 @@ module Kobako
11
11
 
12
12
  def initialize: (entrypoint: Symbol | String, ?args: Array[untyped], ?kwargs: Hash[untyped, untyped]) -> void
13
13
 
14
- def encode: (Kobako::Codec::_HandleTable handler) -> String
14
+ def payload: (Kobako::Codec::_HandleTable handler) -> String
15
15
 
16
16
  private
17
17
 
@@ -16,9 +16,9 @@ module Kobako
16
16
 
17
17
  private
18
18
 
19
- def restore: (untyped value, bool carried_handle) -> untyped
19
+ def decode_body: (String body) -> [untyped, bool]
20
20
 
21
- def yield_failure: (untyped payload, default: String) -> RuntimeError
21
+ def restore: (untyped value, bool carried_handle) -> untyped
22
22
  end
23
23
  end
24
24
  end
@@ -1,14 +1,20 @@
1
1
  module Kobako
2
2
  module Transport
3
3
  # The guest re-entry callable a dispatch hands to a Yielder: invoked
4
- # with the encoded yield args, it returns the encoded YieldResponse.
4
+ # with the encoded yield args, it returns the encoded Yield Reply.
5
5
  # The ext's Kobako::Runtime::GuestYielder is the production conformer;
6
6
  # modelled structurally so the Transport layer needs no upward
7
7
  # dependency on Runtime.
8
8
  interface _GuestYielder
9
- def call: (String) -> String
9
+ def call: (String) -> [Symbol, String, String?]
10
10
  end
11
11
 
12
+ # The per-invocation dispatch Proc, taking the routing fields the native
13
+ # side already decoded off the core envelope and answering the arm and
14
+ # body it puts on the Reply. Named here so the producer (Context) and the
15
+ # consumer (Runtime) cannot declare it differently.
16
+ type dispatch_proc = ^(String | Integer, String, bool, String, _GuestYielder) -> [bool, String, String?]
17
+
12
18
  # The Service registry a dispatch resolves constant-path targets
13
19
  # against. The Sandbox's Kobako::Catalog::Services is the
14
20
  # production conformer; modelled structurally so the Transport
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kobako
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Aotokitsuruya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-07-24 00:00:00.000000000 Z
11
+ date: 2026-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -41,6 +41,8 @@ files:
41
41
  - SECURITY.md
42
42
  - crates/kobako-runtime/CHANGELOG.md
43
43
  - crates/kobako-runtime/README.md
44
+ - crates/kobako-transport/CHANGELOG.md
45
+ - crates/kobako-transport/README.md
44
46
  - crates/kobako-wasmtime/CHANGELOG.md
45
47
  - crates/kobako-wasmtime/README.md
46
48
  - data/kobako.wasm
@@ -66,10 +68,10 @@ files:
66
68
  - lib/kobako/errors.rb
67
69
  - lib/kobako/execution.rb
68
70
  - lib/kobako/extension.rb
69
- - lib/kobako/fault.rb
70
71
  - lib/kobako/handle.rb
71
72
  - lib/kobako/outcome.rb
72
- - lib/kobako/outcome/panic.rb
73
+ - lib/kobako/payload.rb
74
+ - lib/kobako/payload/arguments.rb
73
75
  - lib/kobako/pool.rb
74
76
  - lib/kobako/runtime.rb
75
77
  - lib/kobako/sandbox.rb
@@ -78,12 +80,11 @@ files:
78
80
  - lib/kobako/snippet/binary.rb
79
81
  - lib/kobako/snippet/source.rb
80
82
  - lib/kobako/transport.rb
83
+ - lib/kobako/transport/call.rb
81
84
  - lib/kobako/transport/dispatcher.rb
82
85
  - lib/kobako/transport/error.rb
83
- - lib/kobako/transport/request.rb
84
- - lib/kobako/transport/response.rb
86
+ - lib/kobako/transport/reflection.rb
85
87
  - lib/kobako/transport/run.rb
86
- - lib/kobako/transport/yield.rb
87
88
  - lib/kobako/transport/yielder.rb
88
89
  - lib/kobako/unresolved.rb
89
90
  - lib/kobako/usage.rb
@@ -109,10 +110,10 @@ files:
109
110
  - sig/kobako/errors.rbs
110
111
  - sig/kobako/execution.rbs
111
112
  - sig/kobako/extension.rbs
112
- - sig/kobako/fault.rbs
113
113
  - sig/kobako/handle.rbs
114
114
  - sig/kobako/outcome.rbs
115
- - sig/kobako/outcome/panic.rbs
115
+ - sig/kobako/payload.rbs
116
+ - sig/kobako/payload/arguments.rbs
116
117
  - sig/kobako/pool.rbs
117
118
  - sig/kobako/runtime.rbs
118
119
  - sig/kobako/sandbox.rbs
@@ -121,12 +122,11 @@ files:
121
122
  - sig/kobako/snippet/binary.rbs
122
123
  - sig/kobako/snippet/source.rbs
123
124
  - sig/kobako/transport.rbs
125
+ - sig/kobako/transport/call.rbs
124
126
  - sig/kobako/transport/dispatcher.rbs
125
127
  - sig/kobako/transport/error.rbs
126
- - sig/kobako/transport/request.rbs
127
- - sig/kobako/transport/response.rbs
128
+ - sig/kobako/transport/reflection.rbs
128
129
  - sig/kobako/transport/run.rbs
129
- - sig/kobako/transport/yield.rbs
130
130
  - sig/kobako/transport/yielder.rbs
131
131
  - sig/kobako/unresolved.rbs
132
132
  - sig/kobako/usage.rbs
data/lib/kobako/fault.rb DELETED
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kobako
4
- # Wire-level value object for an ext-0x02 Exception envelope.
5
- #
6
- # Top-level shared wire primitive: like +Kobako::Handle+ (ext 0x01),
7
- # +Fault+ is a MessagePack ext-type leaf registered by
8
- # +Kobako::Codec::ExtTypes+ and rides nested inside other envelopes (a
9
- # +Kobako::Transport::Response+ error payload, or another Fault's
10
- # +details+). It lives at the kobako root rather than under +Transport+
11
- # because the Codec layer must register it, and Codec must not depend
12
- # upward on Transport.
13
- #
14
- # SPEC pins the payload
15
- # ({docs/wire-codec.md}[link:../../docs/wire-codec.md] § Ext Types
16
- # → ext 0x02) to a msgpack map with exactly three keys:
17
- # * "type" — one of "runtime", "argument", "undefined"
18
- # * "message" — human-readable string
19
- # * "details" — any wire-legal value, or nil when absent
20
- #
21
- # This object holds the *encoded* form. Reifying the corresponding Ruby
22
- # exception class (RuntimeError, ArgumentError, Kobako::ServiceError, ...)
23
- # is the responsibility of the dispatch layer, not the codec.
24
- #
25
- # Built on the +class X < Data.define(...)+ subclass form (the
26
- # Steep-friendly shape — see +lib/kobako/outcome/panic.rb+).
27
- class Fault < Data.define(:type, :message, :details)
28
- VALID_TYPES = %w[runtime argument undefined].freeze
29
-
30
- def initialize(type:, message:, details: nil)
31
- raise ArgumentError, "type must be String" unless type.is_a?(String)
32
- raise ArgumentError, "message must be String" unless message.is_a?(String)
33
- raise ArgumentError, "type=#{type.inspect} not one of #{VALID_TYPES.inspect}" unless VALID_TYPES.include?(type)
34
-
35
- super
36
- end
37
- end
38
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kobako
4
- module Outcome
5
- # Wire-contract Outcome Envelope → Panic envelope ({docs/wire-contract.md
6
- # Outcome Envelope}[link:../../../docs/wire-contract.md]). Wire-shaped failure record
7
- # carried in the OUTCOME_BUFFER when the guest run terminates with
8
- # an uncaught top-level exception.
9
- #
10
- # This is the **wire data**, not a raisable Ruby exception. The
11
- # mapping from Panic to a three-layer Ruby exception (TrapError /
12
- # SandboxError / ServiceError) happens at +Kobako::Outcome.decode+
13
- # via +build_panic_error+ — callers never raise +Panic+ directly.
14
- #
15
- # The five fields mirror SPEC: +origin+ ("sandbox" / "service"),
16
- # +klass+ (the guest-side exception class name as a String),
17
- # +message+, +backtrace+ (Array of String), +details+ (any
18
- # wire-legal value, nil when absent). Required-field validation is
19
- # enforced at construction; the +ORIGIN_SANDBOX+ / +ORIGIN_SERVICE+
20
- # constants pin the two SPEC-defined origin values.
21
- #
22
- # Built on the +class X < Data.define(...)+ subclass form so the
23
- # class body is fully Steep-visible; ruby/rbs upstream documents
24
- # this as the Steep-friendly shape and the +Style/DataInheritance+
25
- # cop is disabled on that basis (see +.rubocop.yml+).
26
- class Panic < Data.define(:origin, :klass, :message, :backtrace, :details)
27
- ORIGIN_SANDBOX = "sandbox"
28
- ORIGIN_SERVICE = "service"
29
-
30
- def initialize(origin:, klass:, message:, backtrace: [], details: nil)
31
- raise ArgumentError, "Panic origin must be String" unless origin.is_a?(String)
32
- raise ArgumentError, "Panic class must be String" unless klass.is_a?(String)
33
- raise ArgumentError, "Panic message must be String" unless message.is_a?(String)
34
- unless backtrace.is_a?(Array) && backtrace.all?(String)
35
- raise ArgumentError, "Panic backtrace must be Array of String"
36
- end
37
-
38
- super
39
- end
40
- end
41
- end
42
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../handle"
4
- require_relative "../codec"
5
-
6
- module Kobako
7
- # See lib/kobako/transport.rb for the umbrella module doc; this file
8
- # owns the Request value object and its +#encode+ / +.decode+ codec.
9
- module Transport
10
- # Value object for a single guest-initiated Transport Request
11
- # ({docs/wire-codec.md Envelope Encoding → Request}[link:../../../docs/wire-codec.md]).
12
- #
13
- # 5-element msgpack array:
14
- # +[target, method_name, args, kwargs, block_given]+. +target+ is
15
- # either a +String+ (+"MyService::KV"+, e.g. +"MyService::KV"+)
16
- # or a Handle. SPEC pins +kwargs+ map keys to ext 0x00 Symbol;
17
- # enforced at construction so the Value Object is the single source of
18
- # truth. +block_given+ is a Boolean signalling whether the guest call
19
- # site supplied a block; the block body itself never crosses the
20
- # wire.
21
- #
22
- # Built on the +class X < Data.define(...)+ subclass form so the
23
- # class body is fully Steep-visible; see +lib/kobako/outcome/panic.rb+
24
- # for the rationale.
25
- class Request < Data.define(:target, :method_name, :args, :kwargs, :block_given)
26
- def initialize(target:, method_name:, args: [], kwargs: {}, block_given: false)
27
- unless target.is_a?(String) || target.is_a?(Kobako::Handle)
28
- raise ArgumentError, "Request target must be String or Kobako::Handle, got #{target.class}"
29
- end
30
- raise ArgumentError, "Request method_name must be String" unless method_name.is_a?(String)
31
- raise ArgumentError, "Request args must be Array" unless args.is_a?(Array)
32
- unless block_given.is_a?(TrueClass) || block_given.is_a?(FalseClass)
33
- raise ArgumentError, "Request block_given must be Boolean, got #{block_given.class}"
34
- end
35
-
36
- validate_kwargs!(kwargs)
37
- super
38
- end
39
-
40
- # Encode this Request to msgpack bytes. The Value Object's own
41
- # invariants are the contract; this method does not re-check the shape.
42
- def encode
43
- Codec::Encoder.encode([target, method_name, args, kwargs, block_given])
44
- end
45
-
46
- # Decode +bytes+ into a Request. Raises +Codec::InvalidType+ when the
47
- # envelope is not the expected 5-element msgpack array, when any
48
- # position carries an ext 0x02 Fault envelope (a Request is a payload
49
- # position; the Response fault field is the envelope's only home), or
50
- # when the Value Object's construction invariants reject the decoded
51
- # fields.
52
- def self.decode(bytes)
53
- Codec.forbid_faults do
54
- Codec::Decoder.decode(bytes) do |arr|
55
- unless arr.is_a?(Array) && arr.length == 5
56
- raise Codec::InvalidType, "Request envelope is malformed (expected a 5-element array)"
57
- end
58
-
59
- target, method_name, args, kwargs, block_given = arr
60
- new(target: target, method_name: method_name, args: args, kwargs: kwargs, block_given: block_given)
61
- end
62
- end
63
- end
64
-
65
- private
66
-
67
- def validate_kwargs!(kwargs)
68
- raise ArgumentError, "Request kwargs must be Hash" unless kwargs.is_a?(Hash)
69
-
70
- kwargs.each_key do |k|
71
- raise ArgumentError, "Request kwargs keys must be Symbol, got #{k.class}" unless k.is_a?(Symbol)
72
- end
73
- end
74
- end
75
- end
76
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../codec"
4
- require_relative "../fault"
5
-
6
- module Kobako
7
- # See lib/kobako/transport.rb for the umbrella module doc; this file
8
- # owns the Response value object and its +#encode+ / +.decode+ codec,
9
- # plus the +STATUS_OK+ / +STATUS_ERROR+ status bytes.
10
- module Transport
11
- # ---------------- Response status bytes (docs/wire-contract.md § Response Shape) ---
12
-
13
- # Response variant marker for the success branch.
14
- STATUS_OK = 0
15
- # Response variant marker for the fault branch.
16
- STATUS_ERROR = 1
17
-
18
- # Value object for a single host-side Transport Response
19
- # ({docs/wire-codec.md Envelope Encoding → Response}[link:../../../docs/wire-codec.md]).
20
- #
21
- # 2-element msgpack array: +[status, value-or-fault]+. +status+ is 0
22
- # (success) or 1 (fault). For success the second element is the return
23
- # value; for fault it is a Fault (ext 0x02 envelope).
24
- #
25
- # Built on the +class X < Data.define(...)+ subclass form so the
26
- # class body is fully Steep-visible; see +lib/kobako/outcome/panic.rb+
27
- # for the rationale.
28
- class Response < Data.define(:status, :payload)
29
- def self.ok(value)
30
- new(status: STATUS_OK, payload: value)
31
- end
32
-
33
- def self.error(fault)
34
- unless fault.is_a?(Kobako::Fault)
35
- raise ArgumentError, "Response.error requires Kobako::Fault, got #{fault.class}"
36
- end
37
-
38
- new(status: STATUS_ERROR, payload: fault)
39
- end
40
-
41
- def initialize(status:, payload:)
42
- unless [STATUS_OK, STATUS_ERROR].include?(status)
43
- raise ArgumentError, "Response status must be 0 (ok) or 1 (error), got #{status.inspect}"
44
- end
45
- if status == STATUS_ERROR && !payload.is_a?(Kobako::Fault)
46
- raise ArgumentError, "Response with error status must carry a Kobako::Fault payload"
47
- end
48
-
49
- super
50
- end
51
-
52
- def ok? = status == STATUS_OK
53
- def error? = status == STATUS_ERROR
54
-
55
- # Encode this Response to msgpack bytes as the 2-element
56
- # +[status, payload]+ array. The ok variant's value is a payload
57
- # position, so a +Kobako::Fault+ inside it has no wire
58
- # representation and surfaces as +UnsupportedType+ — the
59
- # Dispatcher's auto-wrap rescue turns it into a Capability Handle.
60
- # The error variant carries the Fault envelope in its one legal
61
- # position and encodes it plainly.
62
- def encode
63
- return Codec::Encoder.encode([status, payload]) if error?
64
-
65
- Codec.forbid_faults { Codec::Encoder.encode([status, payload]) }
66
- end
67
-
68
- # Decode +bytes+ into a Response. Raises +Codec::InvalidType+ when the
69
- # envelope is not the expected 2-element msgpack array, or when the
70
- # Value Object's construction invariants reject the decoded fields.
71
- def self.decode(bytes)
72
- Codec::Decoder.decode(bytes) do |arr|
73
- unless arr.is_a?(Array) && arr.length == 2
74
- raise Codec::InvalidType, "Response envelope is malformed (expected a 2-element array)"
75
- end
76
-
77
- status, payload = arr
78
- new(status: status, payload: payload)
79
- end
80
- end
81
- end
82
- end
83
- end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../codec"
4
-
5
- module Kobako
6
- # See lib/kobako/transport.rb for the umbrella module doc; this file
7
- # owns the +Yield+ envelope value object plus its +#encode+ / +.decode+
8
- # codec for the +__kobako_yield_to_block+ wire form.
9
- module Transport
10
- # First byte of the YieldResponse for the success branch — body is
11
- # the block's return value encoded as a single msgpack value.
12
- TAG_OK = 0x01
13
- # First byte for +break val+ — body is the break value.
14
- TAG_BREAK = 0x02
15
- # Reserved for future +return val+ support; both sides reject this
16
- # tag as a wire violation (YieldResponse envelope contract).
17
- TAG_RESERVED = 0x03
18
- # First byte for an error / fault outcome — body is a
19
- # +{"class", "message", "backtrace"}+ Hash.
20
- TAG_ERROR = 0x04
21
-
22
- # Tags both sides currently accept on the wire.
23
- LIVE_TAGS = [TAG_OK, TAG_BREAK, TAG_ERROR].freeze
24
-
25
- # Value object for a single YieldResponse envelope
26
- # ({docs/wire-codec.md YieldResponse Envelope}[link:../../../docs/wire-codec.md]).
27
- #
28
- # The wire form is a one-byte tag followed by an msgpack payload.
29
- # The three live tags are +0x01+ (ok), +0x02+ (break), and +0x04+
30
- # (error); +0x03+ is reserved and rejected by both sides.
31
- #
32
- # +value+ carries whatever the wire payload decoded to — a plain
33
- # Ruby value for the +ok+ / +break+ tags, and a +{"class",
34
- # "message", "backtrace"}+ Hash for the +error+ tag. No further
35
- # shape constraint is enforced here; the host-side dispatcher
36
- # decides how to translate each variant into Ruby control flow.
37
- #
38
- # Lives alongside the other envelope value objects (+Request+,
39
- # +Response+) since it is the guest-to-host shape used
40
- # mid-dispatch-frame to answer a +__kobako_yield_to_block+ re-entry.
41
- class Yield < Data.define(:tag, :value)
42
- def initialize(tag:, value:)
43
- unless Kobako::Transport::LIVE_TAGS.include?(tag)
44
- raise ArgumentError,
45
- "Yield tag must be one of #{Kobako::Transport::LIVE_TAGS.inspect}, got #{tag.inspect}"
46
- end
47
-
48
- super
49
- end
50
-
51
- def ok? = tag == Kobako::Transport::TAG_OK
52
- def break? = tag == Kobako::Transport::TAG_BREAK
53
- def error? = tag == Kobako::Transport::TAG_ERROR
54
-
55
- # Encode this Yield to YieldResponse bytes: one tag byte followed
56
- # by an msgpack-encoded +value+.
57
- def encode
58
- [tag].pack("C") + Codec::Encoder.encode(value)
59
- end
60
-
61
- # Decode +bytes+ into a Yield. Rejects empty input, the reserved
62
- # tag 0x03, and any tag outside +LIVE_TAGS+ by raising
63
- # +Kobako::Codec::InvalidType+ — these are wire violations per the
64
- # SPEC's YieldResponse envelope contract.
65
- def self.decode(bytes)
66
- bytes = bytes.b
67
- raise Codec::InvalidType, "YieldResponse must carry at least one byte" if bytes.empty?
68
-
69
- tag = bytes.getbyte(0) # : Integer
70
- body = bytes.byteslice(1, bytes.bytesize - 1) # : String
71
-
72
- reject_dead_tag!(tag)
73
- # A YieldResponse is a payload position: an ext 0x02 Fault in its
74
- # value is a wire violation (the Response fault field is the
75
- # envelope's only home).
76
- new(tag: tag, value: Codec.forbid_faults { Codec::Decoder.decode(body) })
77
- end
78
-
79
- def self.reject_dead_tag!(tag)
80
- return if LIVE_TAGS.include?(tag)
81
-
82
- msg = if tag == TAG_RESERVED
83
- "YieldResponse tag 0x03 is reserved"
84
- else
85
- format(
86
- "YieldResponse tag 0x%02x is not recognised", tag
87
- )
88
- end
89
- raise Codec::InvalidType, msg
90
- end
91
- private_class_method :reject_dead_tag!
92
- end
93
- end
94
- end
data/sig/kobako/fault.rbs DELETED
@@ -1,19 +0,0 @@
1
- module Kobako
2
- class Fault < Data
3
- VALID_TYPES: Array[String]
4
-
5
- attr_reader type: String
6
- attr_reader message: String
7
- attr_reader details: untyped
8
-
9
- def self.new: (type: String, message: String, ?details: untyped) -> Fault
10
-
11
- def initialize: (type: String, message: String, ?details: untyped) -> void
12
-
13
- def with: (?type: String, ?message: String, ?details: untyped) -> Fault
14
-
15
- def ==: (untyped other) -> bool
16
-
17
- def hash: () -> Integer
18
- end
19
- end