kobako 0.5.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 (79) hide show
  1. checksums.yaml +7 -0
  2. data/.release-please-manifest.json +1 -0
  3. data/CHANGELOG.md +29 -0
  4. data/LICENSE +201 -0
  5. data/README.md +408 -0
  6. data/data/kobako.wasm +0 -0
  7. data/lib/kobako/3.3/kobako.so +0 -0
  8. data/lib/kobako/3.4/kobako.so +0 -0
  9. data/lib/kobako/4.0/kobako.so +0 -0
  10. data/lib/kobako/capture.rb +43 -0
  11. data/lib/kobako/catalog/handles.rb +107 -0
  12. data/lib/kobako/catalog/namespaces.rb +99 -0
  13. data/lib/kobako/catalog/snippets.rb +149 -0
  14. data/lib/kobako/catalog.rb +18 -0
  15. data/lib/kobako/codec/decoder.rb +73 -0
  16. data/lib/kobako/codec/encoder.rb +37 -0
  17. data/lib/kobako/codec/error.rb +34 -0
  18. data/lib/kobako/codec/factory.rb +162 -0
  19. data/lib/kobako/codec/utils.rb +145 -0
  20. data/lib/kobako/codec.rb +31 -0
  21. data/lib/kobako/errors.rb +140 -0
  22. data/lib/kobako/fault.rb +40 -0
  23. data/lib/kobako/handle.rb +60 -0
  24. data/lib/kobako/namespace.rb +67 -0
  25. data/lib/kobako/outcome/panic.rb +42 -0
  26. data/lib/kobako/outcome.rb +166 -0
  27. data/lib/kobako/runtime.rb +30 -0
  28. data/lib/kobako/sandbox.rb +314 -0
  29. data/lib/kobako/sandbox_options.rb +70 -0
  30. data/lib/kobako/snapshot.rb +40 -0
  31. data/lib/kobako/snippet/binary.rb +29 -0
  32. data/lib/kobako/snippet/source.rb +28 -0
  33. data/lib/kobako/snippet.rb +18 -0
  34. data/lib/kobako/transport/dispatcher.rb +195 -0
  35. data/lib/kobako/transport/error.rb +24 -0
  36. data/lib/kobako/transport/request.rb +78 -0
  37. data/lib/kobako/transport/response.rb +69 -0
  38. data/lib/kobako/transport/run.rb +141 -0
  39. data/lib/kobako/transport/yield.rb +91 -0
  40. data/lib/kobako/transport/yielder.rb +89 -0
  41. data/lib/kobako/transport.rb +24 -0
  42. data/lib/kobako/usage.rb +41 -0
  43. data/lib/kobako/version.rb +5 -0
  44. data/lib/kobako.rb +10 -0
  45. data/release-please-config.json +24 -0
  46. data/sig/kobako/capture.rbs +11 -0
  47. data/sig/kobako/catalog/handles.rbs +19 -0
  48. data/sig/kobako/catalog/namespaces.rbs +17 -0
  49. data/sig/kobako/catalog/snippets.rbs +27 -0
  50. data/sig/kobako/catalog.rbs +4 -0
  51. data/sig/kobako/codec/decoder.rbs +12 -0
  52. data/sig/kobako/codec/encoder.rbs +7 -0
  53. data/sig/kobako/codec/error.rbs +18 -0
  54. data/sig/kobako/codec/factory.rbs +31 -0
  55. data/sig/kobako/codec/utils.rbs +19 -0
  56. data/sig/kobako/errors.rbs +55 -0
  57. data/sig/kobako/fault.rbs +19 -0
  58. data/sig/kobako/handle.rbs +18 -0
  59. data/sig/kobako/namespace.rbs +19 -0
  60. data/sig/kobako/outcome/panic.rbs +34 -0
  61. data/sig/kobako/outcome.rbs +24 -0
  62. data/sig/kobako/runtime.rbs +23 -0
  63. data/sig/kobako/sandbox.rbs +55 -0
  64. data/sig/kobako/sandbox_options.rbs +32 -0
  65. data/sig/kobako/snapshot.rbs +15 -0
  66. data/sig/kobako/snippet/binary.rbs +12 -0
  67. data/sig/kobako/snippet/source.rbs +13 -0
  68. data/sig/kobako/snippet.rbs +4 -0
  69. data/sig/kobako/transport/dispatcher.rbs +34 -0
  70. data/sig/kobako/transport/error.rbs +6 -0
  71. data/sig/kobako/transport/request.rbs +32 -0
  72. data/sig/kobako/transport/response.rbs +30 -0
  73. data/sig/kobako/transport/run.rbs +27 -0
  74. data/sig/kobako/transport/yield.rbs +34 -0
  75. data/sig/kobako/transport/yielder.rbs +21 -0
  76. data/sig/kobako/transport.rbs +4 -0
  77. data/sig/kobako/usage.rbs +11 -0
  78. data/sig/kobako.rbs +3 -0
  79. metadata +145 -0
@@ -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
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kobako
4
+ VERSION = "0.5.0"
5
+ end
data/lib/kobako.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "kobako/version"
4
+ require "kobako/kobako"
5
+ require_relative "kobako/errors"
6
+ require_relative "kobako/transport"
7
+ require_relative "kobako/catalog"
8
+ require_relative "kobako/runtime"
9
+ require_relative "kobako/snapshot"
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
+ }
@@ -0,0 +1,11 @@
1
+ module Kobako
2
+ class Capture
3
+ EMPTY: Capture
4
+
5
+ attr_reader bytes: String
6
+
7
+ def initialize: (bytes: String, truncated: bool) -> void
8
+
9
+ def truncated?: () -> bool
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Kobako
2
+ module Catalog
3
+ class Handles
4
+ def initialize: (?next_id: Integer) -> void
5
+
6
+ def alloc: (untyped object) -> Kobako::Handle
7
+
8
+ def fetch: (Integer id) -> untyped
9
+
10
+ def reset!: () -> self
11
+
12
+ def size: () -> Integer
13
+
14
+ private
15
+
16
+ def require_bound!: (Integer id) -> void
17
+ end
18
+ end
19
+ end
@@ -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
@@ -0,0 +1,27 @@
1
+ module Kobako
2
+ module Catalog
3
+ class Snippets
4
+ NAME_PATTERN: Regexp
5
+
6
+ type entry = Kobako::Snippet::Source | Kobako::Snippet::Binary
7
+
8
+ def initialize: () -> void
9
+
10
+ def register: (?code: String?, ?name: (Symbol | String)?, ?binary: String?) -> (Symbol | nil)
11
+
12
+ def encode: () -> String
13
+
14
+ private
15
+
16
+ def register_source!: (String? code, (Symbol | String)? name) -> Symbol
17
+
18
+ def ensure_source_args!: (String? code, (Symbol | String)? name) -> [String, Symbol | String]
19
+
20
+ def register_binary!: (String bytes) -> nil
21
+
22
+ def entry_payload: (entry) -> Hash[String, untyped]
23
+
24
+ def normalize_name: (Symbol | String name) -> Symbol
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ module Kobako
2
+ module Catalog
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ module Kobako
2
+ module Codec
3
+ module Decoder
4
+ def self.decode: [T] (String bytes) { (untyped value) -> T } -> T
5
+ | (String bytes) -> untyped
6
+
7
+ private
8
+
9
+ def self.validate_utf8!: (untyped value) -> void
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module Kobako
2
+ module Codec
3
+ module Encoder
4
+ def self.encode: (untyped value) -> String
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module Kobako
2
+ module Codec
3
+ class Error < StandardError
4
+ end
5
+
6
+ class Truncated < Error
7
+ end
8
+
9
+ class InvalidType < Error
10
+ end
11
+
12
+ class InvalidEncoding < Error
13
+ end
14
+
15
+ class UnsupportedType < Error
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ module Kobako
2
+ module Codec
3
+ class Factory
4
+ include Singleton
5
+ extend Forwardable
6
+ extend SingleForwardable
7
+
8
+ EXT_SYMBOL: Integer
9
+ EXT_HANDLE: Integer
10
+ EXT_ERRENV: Integer
11
+
12
+ def dump: (untyped value) -> String
13
+ def load: (String bytes) -> untyped
14
+
15
+ def self.dump: (untyped value) -> String
16
+ def self.load: (String bytes) -> untyped
17
+
18
+ private
19
+
20
+ def initialize: () -> void
21
+ def register_symbol: () -> void
22
+ def pack_symbol: (Symbol symbol) -> String
23
+ def unpack_symbol: (String payload) -> Symbol
24
+ def register_handle: () -> void
25
+ def register_fault: () -> void
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
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module Kobako
2
+ module Codec
3
+ module Utils
4
+ MSGPACK_INT_RANGE: Range[Integer]
5
+
6
+ def self?.assert_utf8!: (String string, String label) -> void
7
+
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
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ module Kobako
2
+ class Error < StandardError
3
+ end
4
+
5
+ class TrapError < Error
6
+ end
7
+
8
+ class TimeoutError < TrapError
9
+ end
10
+
11
+ class MemoryLimitError < TrapError
12
+ end
13
+
14
+ class SetupError < Error
15
+ end
16
+
17
+ class ModuleNotBuiltError < SetupError
18
+ end
19
+
20
+ class SandboxError < Error
21
+ attr_reader origin: String?
22
+ attr_reader klass: String?
23
+ attr_reader backtrace_lines: Array[String]?
24
+ attr_reader details: untyped
25
+
26
+ def initialize: (
27
+ String message,
28
+ ?origin: String?,
29
+ ?klass: String?,
30
+ ?backtrace_lines: Array[String]?,
31
+ ?details: untyped
32
+ ) -> void
33
+ end
34
+
35
+ class ServiceError < Error
36
+ attr_reader origin: String?
37
+ attr_reader klass: String?
38
+ attr_reader backtrace_lines: Array[String]?
39
+ attr_reader details: untyped
40
+
41
+ def initialize: (
42
+ String message,
43
+ ?origin: String?,
44
+ ?klass: String?,
45
+ ?backtrace_lines: Array[String]?,
46
+ ?details: untyped
47
+ ) -> void
48
+ end
49
+
50
+ class HandlerExhaustedError < SandboxError
51
+ end
52
+
53
+ class BytecodeError < SandboxError
54
+ end
55
+ end
@@ -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
@@ -0,0 +1,34 @@
1
+ module Kobako
2
+ module Outcome
3
+ class Panic
4
+ ORIGIN_SANDBOX: String
5
+ ORIGIN_SERVICE: String
6
+
7
+ attr_reader origin: String
8
+ attr_reader klass: String
9
+ attr_reader message: String
10
+ attr_reader backtrace: Array[String]
11
+ attr_reader details: untyped
12
+
13
+ def initialize: (
14
+ origin: String,
15
+ klass: String,
16
+ message: String,
17
+ ?backtrace: Array[String],
18
+ ?details: untyped
19
+ ) -> void
20
+
21
+ def with: (
22
+ ?origin: String,
23
+ ?klass: String,
24
+ ?message: String,
25
+ ?backtrace: Array[String],
26
+ ?details: untyped
27
+ ) -> Panic
28
+
29
+ def ==: (untyped other) -> bool
30
+
31
+ def hash: () -> Integer
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ module Kobako
2
+ module Outcome
3
+ TYPE_VALUE: Integer
4
+ TYPE_PANIC: Integer
5
+
6
+ def self?.decode: (String bytes) -> untyped
7
+
8
+ def self?.build_trap_error: (Integer? tag) -> TrapError
9
+
10
+ def self?.split_tag: (String bytes) -> [Integer?, String]
11
+
12
+ def self?.decode_value: (String body) -> untyped
13
+
14
+ def self?.decode_panic: (String body) -> void
15
+
16
+ def self?.build_panic_record: (String body) -> Panic
17
+
18
+ def self?.build_panic_error: (Panic panic) -> (SandboxError | ServiceError)
19
+
20
+ def self?.panic_target_class: (Panic panic) -> (singleton(SandboxError) | singleton(ServiceError))
21
+
22
+ def self?.build_transport_error: (String message, ?detail: String?) -> Transport::Error
23
+ end
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
@@ -0,0 +1,55 @@
1
+ module Kobako
2
+ class Sandbox
3
+ extend Forwardable
4
+
5
+ attr_reader wasm_path: String
6
+ attr_reader options: Kobako::SandboxOptions
7
+
8
+ # Forwarded to @options via Forwardable#def_delegators.
9
+ def timeout: () -> Float?
10
+ def memory_limit: () -> Integer?
11
+ def stdout_limit: () -> Integer
12
+ def stderr_limit: () -> Integer
13
+
14
+ def initialize: (
15
+ ?wasm_path: String?,
16
+ ?stdout_limit: Integer?,
17
+ ?stderr_limit: Integer?,
18
+ ?timeout: (Float | Integer)?,
19
+ ?memory_limit: Integer?
20
+ ) -> void
21
+
22
+ def stdout: () -> String
23
+
24
+ def stderr: () -> String
25
+
26
+ def stdout_truncated?: () -> bool
27
+
28
+ def stderr_truncated?: () -> bool
29
+
30
+ attr_reader usage: Kobako::Usage
31
+
32
+ def define: (Symbol | String name) -> Kobako::Namespace
33
+
34
+ def preload: (code: String, name: Symbol | String) -> Kobako::Sandbox
35
+ | (binary: String) -> Kobako::Sandbox
36
+
37
+ def run: (Symbol | String target, *untyped args, **untyped kwargs) -> untyped
38
+
39
+ def eval: (String code) -> untyped
40
+
41
+ private
42
+
43
+ def install_dispatch_proc!: () -> void
44
+
45
+ def reset_invocation_state!: () -> void
46
+
47
+ def begin_invocation!: () -> void
48
+
49
+ def read_usage!: () -> void
50
+
51
+ def trap_class_for: (Kobako::TrapError err) -> singleton(Kobako::TrapError)
52
+
53
+ def invoke!: (Symbol verb) { () -> Kobako::Snapshot } -> untyped
54
+ end
55
+ end
@@ -0,0 +1,32 @@
1
+ module Kobako
2
+ class SandboxOptions < Data
3
+ DEFAULT_TIMEOUT_SECONDS: Float
4
+ DEFAULT_MEMORY_LIMIT: Integer
5
+ DEFAULT_OUTPUT_LIMIT: Integer
6
+
7
+ attr_reader timeout: Float?
8
+ attr_reader memory_limit: Integer?
9
+ attr_reader stdout_limit: Integer
10
+ attr_reader stderr_limit: Integer
11
+
12
+ def self.new: (
13
+ ?timeout: (Float | Integer)?,
14
+ ?memory_limit: Integer?,
15
+ ?stdout_limit: Integer?,
16
+ ?stderr_limit: Integer?
17
+ ) -> SandboxOptions
18
+
19
+ def initialize: (
20
+ ?timeout: (Float | Integer)?,
21
+ ?memory_limit: Integer?,
22
+ ?stdout_limit: Integer?,
23
+ ?stderr_limit: Integer?
24
+ ) -> void
25
+
26
+ private
27
+
28
+ def normalize_timeout: ((Float | Integer)? timeout) -> Float?
29
+
30
+ def normalize_memory_limit: (Integer? memory_limit) -> Integer?
31
+ end
32
+ end