kobako 0.3.0 → 0.5.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.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -0
- data/CHANGELOG.md +29 -0
- data/Cargo.lock +1 -1
- data/README.md +85 -6
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/lib.rs +4 -2
- data/ext/kobako/src/{wasm → runtime}/cache.rs +22 -18
- data/ext/kobako/src/runtime/capture.rs +91 -0
- data/ext/kobako/src/runtime/config.rs +26 -0
- data/ext/kobako/src/runtime/dispatch.rs +211 -0
- data/ext/kobako/src/runtime/exports.rs +51 -0
- data/ext/kobako/src/runtime/guest_mem.rs +228 -0
- data/ext/kobako/src/{wasm/host_state.rs → runtime/invocation.rs} +195 -81
- data/ext/kobako/src/runtime/trap.rs +134 -0
- data/ext/kobako/src/runtime.rs +782 -0
- data/ext/kobako/src/snapshot.rs +110 -0
- data/lib/kobako/capture.rb +11 -16
- data/lib/kobako/catalog/handles.rb +107 -0
- data/lib/kobako/catalog/namespaces.rb +99 -0
- data/lib/kobako/{snippet/table.rb → catalog/snippets.rb} +37 -62
- data/lib/kobako/catalog.rb +18 -0
- data/lib/kobako/codec/decoder.rb +13 -7
- data/lib/kobako/codec/factory.rb +21 -18
- data/lib/kobako/codec/utils.rb +118 -29
- data/lib/kobako/codec.rb +6 -3
- data/lib/kobako/errors.rb +45 -28
- data/lib/kobako/fault.rb +40 -0
- data/lib/kobako/handle.rb +60 -0
- data/lib/kobako/namespace.rb +67 -0
- data/lib/kobako/outcome.rb +55 -29
- data/lib/kobako/runtime.rb +30 -0
- data/lib/kobako/sandbox.rb +131 -67
- data/lib/kobako/sandbox_options.rb +6 -9
- data/lib/kobako/snapshot.rb +40 -0
- data/lib/kobako/snippet/binary.rb +6 -7
- data/lib/kobako/snippet/source.rb +8 -8
- data/lib/kobako/snippet.rb +7 -9
- data/lib/kobako/transport/dispatcher.rb +195 -0
- data/lib/kobako/transport/error.rb +24 -0
- data/lib/kobako/transport/request.rb +78 -0
- data/lib/kobako/transport/response.rb +69 -0
- data/lib/kobako/transport/run.rb +141 -0
- data/lib/kobako/transport/yield.rb +91 -0
- data/lib/kobako/transport/yielder.rb +89 -0
- data/lib/kobako/transport.rb +24 -0
- data/lib/kobako/usage.rb +41 -0
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +4 -3
- data/release-please-config.json +24 -0
- data/sig/kobako/capture.rbs +0 -2
- data/sig/kobako/{rpc/handle_table.rbs → catalog/handles.rbs} +3 -9
- data/sig/kobako/catalog/namespaces.rbs +17 -0
- data/sig/kobako/{snippet/table.rbs → catalog/snippets.rbs} +2 -11
- data/sig/kobako/{rpc.rbs → catalog.rbs} +1 -1
- data/sig/kobako/codec/decoder.rbs +2 -1
- data/sig/kobako/codec/factory.rbs +3 -3
- data/sig/kobako/codec/utils.rbs +11 -1
- data/sig/kobako/errors.rbs +7 -7
- data/sig/kobako/fault.rbs +19 -0
- data/sig/kobako/handle.rbs +18 -0
- data/sig/kobako/namespace.rbs +19 -0
- data/sig/kobako/outcome.rbs +2 -2
- data/sig/kobako/runtime.rbs +23 -0
- data/sig/kobako/sandbox.rbs +10 -7
- data/sig/kobako/snapshot.rbs +15 -0
- data/sig/kobako/transport/dispatcher.rbs +34 -0
- data/sig/kobako/transport/error.rbs +6 -0
- data/sig/kobako/transport/request.rbs +32 -0
- data/sig/kobako/transport/response.rbs +30 -0
- data/sig/kobako/transport/run.rbs +27 -0
- data/sig/kobako/transport/yield.rbs +34 -0
- data/sig/kobako/transport/yielder.rbs +21 -0
- data/sig/kobako/transport.rbs +4 -0
- data/sig/kobako/usage.rbs +11 -0
- metadata +52 -30
- data/ext/kobako/src/wasm/dispatch.rs +0 -161
- data/ext/kobako/src/wasm/instance.rs +0 -771
- data/ext/kobako/src/wasm.rs +0 -125
- data/lib/kobako/invocation.rb +0 -112
- data/lib/kobako/rpc/dispatcher.rb +0 -169
- data/lib/kobako/rpc/envelope.rb +0 -118
- data/lib/kobako/rpc/fault.rb +0 -41
- data/lib/kobako/rpc/handle.rb +0 -39
- data/lib/kobako/rpc/handle_table.rb +0 -107
- data/lib/kobako/rpc/namespace.rb +0 -74
- data/lib/kobako/rpc/server.rb +0 -158
- data/lib/kobako/rpc.rb +0 -11
- data/lib/kobako/wasm.rb +0 -25
- data/sig/kobako/invocation.rbs +0 -23
- data/sig/kobako/rpc/dispatcher.rbs +0 -33
- data/sig/kobako/rpc/envelope.rbs +0 -51
- data/sig/kobako/rpc/fault.rbs +0 -20
- data/sig/kobako/rpc/handle.rbs +0 -19
- data/sig/kobako/rpc/namespace.rbs +0 -24
- data/sig/kobako/rpc/server.rbs +0 -37
- data/sig/kobako/wasm.rbs +0 -39
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../codec"
|
|
4
|
+
require_relative "yield"
|
|
5
|
+
|
|
6
|
+
module Kobako
|
|
7
|
+
# See lib/kobako/transport.rb for the umbrella module doc; this file
|
|
8
|
+
# owns the host-side object that materialises a guest-supplied block as
|
|
9
|
+
# a Ruby callable the Service method can yield into.
|
|
10
|
+
module Transport
|
|
11
|
+
# Host-side stand-in for a guest-supplied block (B-23).
|
|
12
|
+
#
|
|
13
|
+
# Each guest call that carries +block_given: true+ gets a Yielder
|
|
14
|
+
# that the Dispatcher hands to the Service method as +&block+. The
|
|
15
|
+
# Service method observes it as an ordinary Ruby Proc through
|
|
16
|
+
# {#to_proc}; +yield val+ / +block.call(val)+ invokes {#yield}, which
|
|
17
|
+
# serialises the positional args, re-enters the guest via the injected
|
|
18
|
+
# +yield_to_guest+ lambda
|
|
19
|
+
# ({docs/behavior.md B-24}[link:../../../docs/behavior.md]), and
|
|
20
|
+
# reifies the +YieldResponse+ into Ruby control flow:
|
|
21
|
+
#
|
|
22
|
+
# * +tag 0x01+ ok — return the decoded value to +yield+'s caller
|
|
23
|
+
# * +tag 0x02+ break — +throw break_tag, value+ so the Dispatcher's
|
|
24
|
+
# +catch+ frame unwinds the Service method
|
|
25
|
+
# ({docs/behavior.md B-25}[link:../../../docs/behavior.md])
|
|
26
|
+
# * +tag 0x04+ error — raise the +{class, message}+ payload at the
|
|
27
|
+
# Service's yield site
|
|
28
|
+
#
|
|
29
|
+
# The Dispatcher calls {#invalidate!} from its +ensure+ block once
|
|
30
|
+
# dispatch completes; any later call to a stashed Yielder then raises
|
|
31
|
+
# +LocalJumpError+ — the observable shape of
|
|
32
|
+
# {docs/behavior.md E-23}[link:../../../docs/behavior.md] (escaped
|
|
33
|
+
# Yielder).
|
|
34
|
+
class Yielder
|
|
35
|
+
# +yield_to_guest+ is a +String → String+ callable (typically
|
|
36
|
+
# +Runtime#yield_to_active_invocation+ bound through a lambda) that
|
|
37
|
+
# {#yield} invokes to re-enter the guest; +break_tag+ is the +catch+
|
|
38
|
+
# throw tag the Dispatcher matches against to unwind the Service on
|
|
39
|
+
# +tag 0x02+.
|
|
40
|
+
def initialize(yield_to_guest, break_tag)
|
|
41
|
+
@yield_to_guest = yield_to_guest
|
|
42
|
+
@break_tag = break_tag
|
|
43
|
+
@active = true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Re-enter the guest with +args+ and reify the YieldResponse into
|
|
47
|
+
# Ruby control flow. Raises +LocalJumpError+ if called after
|
|
48
|
+
# {#invalidate!} (E-23).
|
|
49
|
+
def yield(*args)
|
|
50
|
+
raise LocalJumpError, "guest block invoked after host dispatch frame returned" unless @active
|
|
51
|
+
|
|
52
|
+
response = Kobako::Transport::Yield.decode(@yield_to_guest.call(Kobako::Codec::Encoder.encode(args)))
|
|
53
|
+
return response.value if response.ok?
|
|
54
|
+
|
|
55
|
+
throw @break_tag, response.value if response.break?
|
|
56
|
+
|
|
57
|
+
raise yield_failure(response.value, default: "yield error")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# The Proc the Dispatcher passes as +&block+, binding {#yield} so a
|
|
61
|
+
# Service method's +yield+ / +block.call+ drives the round-trip.
|
|
62
|
+
def to_proc
|
|
63
|
+
method(:yield).to_proc
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Mark this Yielder dead. Called by the Dispatcher's +ensure+ block
|
|
67
|
+
# when the originating dispatch frame returns; any later {#yield}
|
|
68
|
+
# call then raises +LocalJumpError+ (E-23).
|
|
69
|
+
def invalidate!
|
|
70
|
+
@active = false
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
# Reify a +YieldResponse+ tag 0x04 payload into a +RuntimeError+ the
|
|
76
|
+
# Service method observes at its +yield+ site. The +{class, message,
|
|
77
|
+
# backtrace}+ shape mirrors the +Kobako::Transport::Yield+ tag 0x04
|
|
78
|
+
# payload; +default+ provides a fallback when the payload is not a
|
|
79
|
+
# Hash.
|
|
80
|
+
def yield_failure(payload, default:)
|
|
81
|
+
return RuntimeError.new(default) unless payload.is_a?(Hash)
|
|
82
|
+
|
|
83
|
+
klass = payload["class"] || "RuntimeError"
|
|
84
|
+
message = payload["message"] || default
|
|
85
|
+
RuntimeError.new("#{klass}: #{message}")
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "transport/request"
|
|
4
|
+
require_relative "transport/response"
|
|
5
|
+
require_relative "transport/run"
|
|
6
|
+
require_relative "transport/yield"
|
|
7
|
+
require_relative "transport/yielder"
|
|
8
|
+
require_relative "transport/error"
|
|
9
|
+
require_relative "transport/dispatcher"
|
|
10
|
+
|
|
11
|
+
module Kobako
|
|
12
|
+
# Kobako::Transport — host↔guest message transport namespace.
|
|
13
|
+
# Houses the envelope value objects (Request / Response / Run / Yield),
|
|
14
|
+
# the guest→host +Dispatcher+, and the host→guest +Yielder+.
|
|
15
|
+
# +Sandbox#initialize+ composes them onto the
|
|
16
|
+
# +Runtime+ as a dispatch +Proc+ + +yield_to_guest+ lambda pair
|
|
17
|
+
# ({docs/behavior.md B-12}[link:../../docs/behavior.md]). "RPC" was
|
|
18
|
+
# deliberately not chosen — it implies a cross-process boundary that
|
|
19
|
+
# kobako does not have, since host and guest share one OS thread and
|
|
20
|
+
# one wasm linear memory. See
|
|
21
|
+
# {SPEC.md Refinement → Internal Concepts}[link:../../SPEC.md].
|
|
22
|
+
module Transport
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/kobako/usage.rb
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Kobako
|
|
4
|
+
# Per-last-invocation resource accounting for a +Kobako::Sandbox+
|
|
5
|
+
# ({docs/behavior.md B-35}[link:../../docs/behavior.md]). Carries two
|
|
6
|
+
# readers populated by every +#eval+ / +#run+ invocation:
|
|
7
|
+
#
|
|
8
|
+
# * +wall_time+ — the Float number of seconds the guest export call
|
|
9
|
+
# spent inside wasmtime during the most recent invocation. The
|
|
10
|
+
# measurement bracket aligns with the +timeout+ deadline
|
|
11
|
+
# ({docs/behavior.md B-01}[link:../../docs/behavior.md]); time spent
|
|
12
|
+
# in host Service callbacks is included, but everything that runs
|
|
13
|
+
# after the guest export returns — the post-export
|
|
14
|
+
# +OUTCOME_BUFFER+ fetch and decode, plus stdout / stderr capture
|
|
15
|
+
# readout — is excluded.
|
|
16
|
+
# * +memory_peak+ — the Integer high-water mark, in bytes, of the
|
|
17
|
+
# per-invocation +memory.grow+ delta past the linear-memory size
|
|
18
|
+
# captured at invocation entry. Same baseline accounting as
|
|
19
|
+
# +memory_limit+ ({docs/behavior.md E-20}[link:../../docs/behavior.md]):
|
|
20
|
+
# the mruby image's initial allocation and any prior-invocation
|
|
21
|
+
# watermark sit outside the measurement. On +MemoryLimitError+
|
|
22
|
+
# +memory_peak+ never exceeds the configured cap because the
|
|
23
|
+
# rejected +desired+ value is not promoted into the high-water.
|
|
24
|
+
#
|
|
25
|
+
# Both readers are populated on every outcome, including +TrapError+
|
|
26
|
+
# branches, so the Host App can read +Sandbox#usage+ after rescuing a
|
|
27
|
+
# trap to diagnose how much of the budget the failing invocation
|
|
28
|
+
# consumed. Before the first invocation +Sandbox#usage+ returns the
|
|
29
|
+
# pre-invocation sentinel +Kobako::Usage::EMPTY+.
|
|
30
|
+
#
|
|
31
|
+
# Built on the +class X < Data.define(...)+ subclass form so the
|
|
32
|
+
# class body is fully Steep-visible; ruby/rbs upstream documents this
|
|
33
|
+
# as the Steep-friendly shape and the +Style/DataInheritance+ cop is
|
|
34
|
+
# disabled on that basis (see +.rubocop.yml+).
|
|
35
|
+
class Usage < Data.define(:wall_time, :memory_peak)
|
|
36
|
+
# Pre-invocation sentinel ({docs/behavior.md B-35}[link:../../docs/behavior.md]).
|
|
37
|
+
# Reused by +Sandbox+ before any invocation has run so callers do not
|
|
38
|
+
# need to handle a +nil+ +#usage+.
|
|
39
|
+
EMPTY = new(wall_time: 0.0, memory_peak: 0)
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/kobako/version.rb
CHANGED
data/lib/kobako.rb
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
require_relative "kobako/version"
|
|
4
4
|
require "kobako/kobako"
|
|
5
5
|
require_relative "kobako/errors"
|
|
6
|
-
require_relative "kobako/
|
|
7
|
-
require_relative "kobako/
|
|
8
|
-
require_relative "kobako/
|
|
6
|
+
require_relative "kobako/transport"
|
|
7
|
+
require_relative "kobako/catalog"
|
|
8
|
+
require_relative "kobako/runtime"
|
|
9
|
+
require_relative "kobako/snapshot"
|
|
9
10
|
require_relative "kobako/sandbox"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
|
|
3
|
+
"release-type": "ruby",
|
|
4
|
+
"last-release-sha": "5694da60b08931ea260e13025689b8d8c47d767a",
|
|
5
|
+
"packages": {
|
|
6
|
+
".": {
|
|
7
|
+
"component": "kobako",
|
|
8
|
+
"include-component-in-tag": false,
|
|
9
|
+
"release-type": "ruby"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"extra-files": [
|
|
13
|
+
{
|
|
14
|
+
"type": "toml",
|
|
15
|
+
"path": "ext/kobako/Cargo.toml",
|
|
16
|
+
"jsonpath": "$.package.version"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"type": "toml",
|
|
20
|
+
"path": "Cargo.lock",
|
|
21
|
+
"jsonpath": "$.package[?(@.name=='kobako')].version"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
data/sig/kobako/capture.rbs
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
module Kobako
|
|
2
|
-
module
|
|
3
|
-
class
|
|
2
|
+
module Catalog
|
|
3
|
+
class Handles
|
|
4
4
|
def initialize: (?next_id: Integer) -> void
|
|
5
5
|
|
|
6
|
-
def alloc: (untyped object) ->
|
|
6
|
+
def alloc: (untyped object) -> Kobako::Handle
|
|
7
7
|
|
|
8
8
|
def fetch: (Integer id) -> untyped
|
|
9
9
|
|
|
10
|
-
def release: (Integer id) -> untyped
|
|
11
|
-
|
|
12
10
|
def reset!: () -> self
|
|
13
11
|
|
|
14
|
-
def mark_disconnected: (Integer id) -> self
|
|
15
|
-
|
|
16
12
|
def size: () -> Integer
|
|
17
13
|
|
|
18
|
-
def include?: (Integer id) -> bool
|
|
19
|
-
|
|
20
14
|
private
|
|
21
15
|
|
|
22
16
|
def require_bound!: (Integer id) -> void
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Kobako
|
|
2
|
+
module Catalog
|
|
3
|
+
class Namespaces
|
|
4
|
+
def initialize: (?handler: Kobako::Catalog::Handles) -> void
|
|
5
|
+
|
|
6
|
+
def define: (Symbol | String name) -> Kobako::Namespace
|
|
7
|
+
|
|
8
|
+
def lookup: (String target) -> untyped
|
|
9
|
+
|
|
10
|
+
def encode: () -> String
|
|
11
|
+
|
|
12
|
+
def seal!: () -> self
|
|
13
|
+
|
|
14
|
+
def sealed?: () -> bool
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Kobako
|
|
2
|
-
module
|
|
3
|
-
class
|
|
2
|
+
module Catalog
|
|
3
|
+
class Snippets
|
|
4
4
|
NAME_PATTERN: Regexp
|
|
5
5
|
|
|
6
6
|
type entry = Kobako::Snippet::Source | Kobako::Snippet::Binary
|
|
@@ -11,15 +11,6 @@ module Kobako
|
|
|
11
11
|
|
|
12
12
|
def encode: () -> String
|
|
13
13
|
|
|
14
|
-
def each: () { (entry) -> void } -> Array[entry]
|
|
15
|
-
| () -> Enumerator[entry, Array[entry]]
|
|
16
|
-
|
|
17
|
-
def names: () -> Array[Symbol]
|
|
18
|
-
|
|
19
|
-
def size: () -> Integer
|
|
20
|
-
|
|
21
|
-
def empty?: () -> bool
|
|
22
|
-
|
|
23
14
|
private
|
|
24
15
|
|
|
25
16
|
def register_source!: (String? code, (Symbol | String)? name) -> Symbol
|
|
@@ -23,9 +23,9 @@ module Kobako
|
|
|
23
23
|
def unpack_symbol: (String payload) -> Symbol
|
|
24
24
|
def register_handle: () -> void
|
|
25
25
|
def register_fault: () -> void
|
|
26
|
-
def unpack_handle: (String payload) -> Kobako::
|
|
27
|
-
def pack_fault: (Kobako::
|
|
28
|
-
def unpack_fault: (String payload) -> Kobako::
|
|
26
|
+
def unpack_handle: (String payload) -> Kobako::Handle
|
|
27
|
+
def pack_fault: (Kobako::Fault fault) -> String
|
|
28
|
+
def unpack_fault: (String payload) -> Kobako::Fault
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|
data/sig/kobako/codec/utils.rbs
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
module Kobako
|
|
2
2
|
module Codec
|
|
3
3
|
module Utils
|
|
4
|
+
MSGPACK_INT_RANGE: Range[Integer]
|
|
5
|
+
|
|
4
6
|
def self?.assert_utf8!: (String string, String label) -> void
|
|
5
7
|
|
|
6
|
-
def self?.
|
|
8
|
+
def self?.with_boundary: [T] () { () -> T } -> T
|
|
9
|
+
|
|
10
|
+
def self?.representable?: (untyped value) -> bool
|
|
11
|
+
|
|
12
|
+
def self?.deep_wrap: (untyped value, Kobako::Catalog::Handles handler) -> untyped
|
|
13
|
+
|
|
14
|
+
def self?.primitive_type?: (untyped value) -> bool
|
|
15
|
+
|
|
16
|
+
def self?.container_representable?: (untyped value) -> bool
|
|
7
17
|
end
|
|
8
18
|
end
|
|
9
19
|
end
|
data/sig/kobako/errors.rbs
CHANGED
|
@@ -11,6 +11,12 @@ module Kobako
|
|
|
11
11
|
class MemoryLimitError < TrapError
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
class SetupError < Error
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class ModuleNotBuiltError < SetupError
|
|
18
|
+
end
|
|
19
|
+
|
|
14
20
|
class SandboxError < Error
|
|
15
21
|
attr_reader origin: String?
|
|
16
22
|
attr_reader klass: String?
|
|
@@ -39,15 +45,9 @@ module Kobako
|
|
|
39
45
|
?backtrace_lines: Array[String]?,
|
|
40
46
|
?details: untyped
|
|
41
47
|
) -> void
|
|
42
|
-
|
|
43
|
-
class Disconnected < ServiceError
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
class HandleTableError < SandboxError
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
class
|
|
50
|
+
class HandlerExhaustedError < SandboxError
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
class BytecodeError < SandboxError
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Kobako
|
|
2
|
+
class Handle
|
|
3
|
+
MIN_ID: Integer
|
|
4
|
+
MAX_ID: Integer
|
|
5
|
+
|
|
6
|
+
attr_reader id: Integer
|
|
7
|
+
|
|
8
|
+
def initialize: (id: Integer) -> void
|
|
9
|
+
|
|
10
|
+
def self.restore: (Integer id) -> Handle
|
|
11
|
+
|
|
12
|
+
def with: (?id: Integer) -> Handle
|
|
13
|
+
|
|
14
|
+
def ==: (untyped other) -> bool
|
|
15
|
+
|
|
16
|
+
def hash: () -> Integer
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Kobako
|
|
2
|
+
class Namespace
|
|
3
|
+
NAME_PATTERN: Regexp
|
|
4
|
+
|
|
5
|
+
attr_reader name: String
|
|
6
|
+
|
|
7
|
+
def initialize: (String name) -> void
|
|
8
|
+
|
|
9
|
+
def bind: (Symbol | String member, untyped object) -> self
|
|
10
|
+
|
|
11
|
+
def fetch: (Symbol | String member) -> untyped
|
|
12
|
+
|
|
13
|
+
def to_preamble: () -> [String, Array[String]]
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def validate_member_name!: (Symbol | String member) -> String
|
|
18
|
+
end
|
|
19
|
+
end
|
data/sig/kobako/outcome.rbs
CHANGED
|
@@ -13,12 +13,12 @@ module Kobako
|
|
|
13
13
|
|
|
14
14
|
def self?.decode_panic: (String body) -> void
|
|
15
15
|
|
|
16
|
-
def self?.
|
|
16
|
+
def self?.build_panic_record: (String body) -> Panic
|
|
17
17
|
|
|
18
18
|
def self?.build_panic_error: (Panic panic) -> (SandboxError | ServiceError)
|
|
19
19
|
|
|
20
20
|
def self?.panic_target_class: (Panic panic) -> (singleton(SandboxError) | singleton(ServiceError))
|
|
21
21
|
|
|
22
|
-
def self?.
|
|
22
|
+
def self?.build_transport_error: (String message, ?detail: String?) -> Transport::Error
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Kobako
|
|
2
|
+
class Runtime
|
|
3
|
+
def self.default_path: () -> String
|
|
4
|
+
|
|
5
|
+
def self.from_path: (
|
|
6
|
+
String path,
|
|
7
|
+
(Float | Integer)? timeout_seconds,
|
|
8
|
+
Integer? memory_limit,
|
|
9
|
+
Integer? stdout_limit_bytes,
|
|
10
|
+
Integer? stderr_limit_bytes
|
|
11
|
+
) -> Runtime
|
|
12
|
+
|
|
13
|
+
def on_dispatch=: (^(String) -> String dispatch_proc) -> void
|
|
14
|
+
|
|
15
|
+
def yield_to_active_invocation: (String args_bytes) -> String
|
|
16
|
+
|
|
17
|
+
def eval: (String preamble, String source, String snippets) -> Kobako::Snapshot
|
|
18
|
+
|
|
19
|
+
def run: (String preamble, String snippets, String envelope) -> Kobako::Snapshot
|
|
20
|
+
|
|
21
|
+
def usage: () -> [Float, Integer]
|
|
22
|
+
end
|
|
23
|
+
end
|
data/sig/kobako/sandbox.rbs
CHANGED
|
@@ -3,10 +3,7 @@ module Kobako
|
|
|
3
3
|
extend Forwardable
|
|
4
4
|
|
|
5
5
|
attr_reader wasm_path: String
|
|
6
|
-
attr_reader instance: Kobako::Wasm::Instance
|
|
7
6
|
attr_reader options: Kobako::SandboxOptions
|
|
8
|
-
attr_reader services: Kobako::RPC::Server
|
|
9
|
-
attr_reader snippets: Kobako::Snippet::Table
|
|
10
7
|
|
|
11
8
|
# Forwarded to @options via Forwardable#def_delegators.
|
|
12
9
|
def timeout: () -> Float?
|
|
@@ -30,7 +27,9 @@ module Kobako
|
|
|
30
27
|
|
|
31
28
|
def stderr_truncated?: () -> bool
|
|
32
29
|
|
|
33
|
-
|
|
30
|
+
attr_reader usage: Kobako::Usage
|
|
31
|
+
|
|
32
|
+
def define: (Symbol | String name) -> Kobako::Namespace
|
|
34
33
|
|
|
35
34
|
def preload: (code: String, name: Symbol | String) -> Kobako::Sandbox
|
|
36
35
|
| (binary: String) -> Kobako::Sandbox
|
|
@@ -41,12 +40,16 @@ module Kobako
|
|
|
41
40
|
|
|
42
41
|
private
|
|
43
42
|
|
|
44
|
-
def
|
|
43
|
+
def install_dispatch_proc!: () -> void
|
|
44
|
+
|
|
45
|
+
def reset_invocation_state!: () -> void
|
|
45
46
|
|
|
46
47
|
def begin_invocation!: () -> void
|
|
47
48
|
|
|
48
|
-
def
|
|
49
|
+
def read_usage!: () -> void
|
|
50
|
+
|
|
51
|
+
def trap_class_for: (Kobako::TrapError err) -> singleton(Kobako::TrapError)
|
|
49
52
|
|
|
50
|
-
def invoke!: (Symbol verb) { () ->
|
|
53
|
+
def invoke!: (Symbol verb) { () -> Kobako::Snapshot } -> untyped
|
|
51
54
|
end
|
|
52
55
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Kobako
|
|
2
|
+
class Snapshot
|
|
3
|
+
def return_bytes: () -> String
|
|
4
|
+
def stdout_bytes: () -> String
|
|
5
|
+
def stdout_truncated: () -> bool
|
|
6
|
+
def stderr_bytes: () -> String
|
|
7
|
+
def stderr_truncated: () -> bool
|
|
8
|
+
def wall_time: () -> Float
|
|
9
|
+
def memory_peak: () -> Integer
|
|
10
|
+
|
|
11
|
+
def stdout: () -> Kobako::Capture
|
|
12
|
+
def stderr: () -> Kobako::Capture
|
|
13
|
+
def usage: () -> Kobako::Usage
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Kobako
|
|
2
|
+
module Transport
|
|
3
|
+
module Dispatcher
|
|
4
|
+
class UndefinedTargetError < StandardError
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
BREAK_THROW: Symbol
|
|
8
|
+
|
|
9
|
+
def self?.dispatch: (String request_bytes, Kobako::Catalog::Namespaces namespaces, Kobako::Catalog::Handles handler, ^(String) -> String yield_to_guest) -> String
|
|
10
|
+
|
|
11
|
+
def self?.resolve_call_args: (Kobako::Transport::Request request, Kobako::Catalog::Handles handler) -> [Array[untyped], Hash[Symbol, untyped]]
|
|
12
|
+
|
|
13
|
+
def self?.encode_caught_error: (StandardError error) -> String
|
|
14
|
+
|
|
15
|
+
def self?.invoke: (untyped target, String method, Array[untyped] args, Hash[Symbol, untyped] kwargs, ?Kobako::Transport::Yielder? yielder) -> untyped
|
|
16
|
+
|
|
17
|
+
def self?.resolve_arg: (untyped value, Kobako::Catalog::Handles handler) -> untyped
|
|
18
|
+
|
|
19
|
+
def self?.resolve_target: (String | Kobako::Handle target, Kobako::Catalog::Namespaces namespaces, Kobako::Catalog::Handles handler) -> untyped
|
|
20
|
+
|
|
21
|
+
def self?.resolve_path: (String path, Kobako::Catalog::Namespaces namespaces) -> untyped
|
|
22
|
+
|
|
23
|
+
def self?.resolve_handle: (Kobako::Handle handle, Kobako::Catalog::Handles handler) -> untyped
|
|
24
|
+
|
|
25
|
+
def self?.require_live_object!: (Integer id, Kobako::Catalog::Handles handler) -> untyped
|
|
26
|
+
|
|
27
|
+
def self?.encode_ok: (untyped value, Kobako::Catalog::Handles handler) -> String
|
|
28
|
+
|
|
29
|
+
def self?.wrap_as_handle: (untyped value, Kobako::Catalog::Handles handler) -> Kobako::Handle
|
|
30
|
+
|
|
31
|
+
def self?.encode_error: (String type, String message) -> String
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Kobako
|
|
2
|
+
module Transport
|
|
3
|
+
STATUS_OK: Integer
|
|
4
|
+
STATUS_ERROR: Integer
|
|
5
|
+
|
|
6
|
+
class Request < Data
|
|
7
|
+
attr_reader target: String | Kobako::Handle
|
|
8
|
+
attr_reader method_name: String
|
|
9
|
+
attr_reader args: Array[untyped]
|
|
10
|
+
attr_reader kwargs: Hash[Symbol, untyped]
|
|
11
|
+
attr_reader block_given: bool
|
|
12
|
+
|
|
13
|
+
def self.new: (target: String | Kobako::Handle, method_name: String, ?args: Array[untyped], ?kwargs: Hash[Symbol, untyped], ?block_given: bool) -> Request
|
|
14
|
+
|
|
15
|
+
def self.decode: (String bytes) -> Request
|
|
16
|
+
|
|
17
|
+
def initialize: (target: String | Kobako::Handle, method_name: String, ?args: Array[untyped], ?kwargs: Hash[Symbol, untyped], ?block_given: bool) -> void
|
|
18
|
+
|
|
19
|
+
def encode: () -> String
|
|
20
|
+
|
|
21
|
+
def with: (?target: String | Kobako::Handle, ?method_name: String, ?args: Array[untyped], ?kwargs: Hash[Symbol, untyped], ?block_given: bool) -> Request
|
|
22
|
+
|
|
23
|
+
def ==: (untyped other) -> bool
|
|
24
|
+
|
|
25
|
+
def hash: () -> Integer
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def validate_kwargs!: (Hash[untyped, untyped] kwargs) -> void
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Kobako
|
|
2
|
+
module Transport
|
|
3
|
+
class Response < Data
|
|
4
|
+
attr_reader status: Integer
|
|
5
|
+
attr_reader payload: untyped
|
|
6
|
+
|
|
7
|
+
def self.ok: (untyped value) -> Response
|
|
8
|
+
|
|
9
|
+
def self.error: (Kobako::Fault fault) -> Response
|
|
10
|
+
|
|
11
|
+
def self.decode: (String bytes) -> Response
|
|
12
|
+
|
|
13
|
+
def self.new: (status: Integer, payload: untyped) -> Response
|
|
14
|
+
|
|
15
|
+
def initialize: (status: Integer, payload: untyped) -> void
|
|
16
|
+
|
|
17
|
+
def with: (?status: Integer, ?payload: untyped) -> Response
|
|
18
|
+
|
|
19
|
+
def ok?: () -> bool
|
|
20
|
+
|
|
21
|
+
def error?: () -> bool
|
|
22
|
+
|
|
23
|
+
def encode: () -> String
|
|
24
|
+
|
|
25
|
+
def ==: (untyped other) -> bool
|
|
26
|
+
|
|
27
|
+
def hash: () -> Integer
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Kobako
|
|
2
|
+
module Transport
|
|
3
|
+
class Run < Data
|
|
4
|
+
NAME_PATTERN: Regexp
|
|
5
|
+
|
|
6
|
+
attr_reader entrypoint: Symbol
|
|
7
|
+
attr_reader args: Array[untyped]
|
|
8
|
+
attr_reader kwargs: Hash[Symbol, untyped]
|
|
9
|
+
|
|
10
|
+
def self.new: (entrypoint: Symbol | String, ?args: Array[untyped], ?kwargs: Hash[untyped, untyped]) -> Run
|
|
11
|
+
|
|
12
|
+
def initialize: (entrypoint: Symbol | String, ?args: Array[untyped], ?kwargs: Hash[untyped, untyped]) -> void
|
|
13
|
+
|
|
14
|
+
def encode: (Kobako::Catalog::Handles handler) -> String
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def normalize_entrypoint: (Symbol | String target) -> Symbol
|
|
19
|
+
|
|
20
|
+
def validate_args!: (Array[untyped] args) -> Array[untyped]
|
|
21
|
+
|
|
22
|
+
def validate_kwargs!: (Hash[untyped, untyped] kwargs) -> Hash[Symbol, untyped]
|
|
23
|
+
|
|
24
|
+
def forged_handle_message: (String slot) -> String
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|