kobako 0.29.0 → 0.31.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.
Files changed (291) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +552 -10
  4. data/Cargo.lock +595 -139
  5. data/README.md +126 -564
  6. data/ROADMAP.md +3 -2
  7. data/crates/kobako-runtime/CHANGELOG.md +488 -1
  8. data/crates/kobako-runtime/Cargo.toml +73 -15
  9. data/crates/kobako-runtime/README.md +11 -4
  10. data/crates/kobako-runtime/src/cred.rs +124 -0
  11. data/crates/kobako-runtime/src/dispatch.rs +5 -6
  12. data/crates/kobako-runtime/src/endpoint/buffer.rs +301 -0
  13. data/crates/kobako-runtime/src/endpoint/dispatch.rs +292 -0
  14. data/crates/kobako-runtime/src/endpoint/invoke.rs +181 -0
  15. data/crates/kobako-runtime/src/endpoint.rs +267 -0
  16. data/crates/kobako-runtime/src/errno.rs +391 -0
  17. data/crates/kobako-runtime/src/error.rs +31 -10
  18. data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
  19. data/crates/kobako-runtime/src/filesystem/bind/fid.rs +82 -0
  20. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +274 -0
  21. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +248 -0
  22. data/crates/kobako-runtime/src/filesystem/bind.rs +2857 -0
  23. data/crates/kobako-runtime/src/filesystem/overlay/file.rs +89 -0
  24. data/crates/kobako-runtime/src/filesystem/overlay/inode.rs +106 -0
  25. data/crates/kobako-runtime/src/filesystem/overlay/path.rs +263 -0
  26. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +128 -0
  27. data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +238 -0
  28. data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +135 -0
  29. data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +54 -0
  30. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +316 -739
  31. data/crates/kobako-runtime/src/filesystem/overlay.rs +2627 -1154
  32. data/crates/kobako-runtime/src/filesystem/pipe.rs +224 -0
  33. data/crates/kobako-runtime/src/filesystem/rdir.rs +84 -0
  34. data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
  35. data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +32 -0
  36. data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +107 -0
  37. data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +22 -0
  38. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +1997 -0
  39. data/crates/kobako-runtime/src/filesystem/wrap.rs +208 -0
  40. data/crates/kobako-runtime/src/filesystem.rs +25 -388
  41. data/crates/kobako-runtime/src/fork.rs +96 -0
  42. data/crates/kobako-runtime/src/grant.rs +3 -0
  43. data/crates/kobako-runtime/src/hashtable.rs +46 -0
  44. data/crates/kobako-runtime/src/lib.rs +27 -11
  45. data/crates/kobako-runtime/src/limits.rs +195 -0
  46. data/crates/kobako-runtime/src/locking/seqlock.rs +66 -0
  47. data/crates/kobako-runtime/src/locking.rs +228 -0
  48. data/crates/kobako-runtime/src/memcg.rs +383 -0
  49. data/crates/kobako-runtime/src/mount.rs +86 -101
  50. data/crates/kobako-runtime/src/net/backends.rs +43 -0
  51. data/crates/kobako-runtime/src/net/connections.rs +179 -0
  52. data/crates/kobako-runtime/src/net/credential.rs +125 -0
  53. data/crates/kobako-runtime/src/net/egress.rs +160 -0
  54. data/crates/kobako-runtime/src/net/family.rs +181 -0
  55. data/crates/kobako-runtime/src/net/http.rs +2733 -0
  56. data/crates/kobako-runtime/src/net/lookup.rs +285 -0
  57. data/crates/kobako-runtime/src/net/mock.rs +251 -0
  58. data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
  59. data/crates/kobako-runtime/src/net/reactor.rs +531 -0
  60. data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
  61. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
  62. data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
  63. data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
  64. data/crates/kobako-runtime/src/net/resolv.rs +227 -0
  65. data/crates/kobako-runtime/src/net/socket.rs +870 -0
  66. data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
  67. data/crates/kobako-runtime/src/net/tls.rs +58 -0
  68. data/crates/kobako-runtime/src/net/transport.rs +279 -0
  69. data/crates/kobako-runtime/src/net/udp.rs +1003 -0
  70. data/crates/kobako-runtime/src/net.rs +42 -0
  71. data/crates/kobako-runtime/src/network/builder.rs +177 -0
  72. data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
  73. data/crates/kobako-runtime/src/network.rs +551 -0
  74. data/crates/kobako-runtime/src/policy.rs +16 -0
  75. data/crates/kobako-runtime/src/profile.rs +37 -16
  76. data/crates/kobako-runtime/src/runtime.rs +3 -5
  77. data/crates/kobako-runtime/src/sched.rs +311 -0
  78. data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
  79. data/crates/kobako-runtime/src/security/hooks.rs +242 -0
  80. data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
  81. data/crates/kobako-runtime/src/security.rs +601 -0
  82. data/crates/kobako-runtime/src/snapshot.rs +121 -2
  83. data/crates/kobako-runtime/src/vfs/attr.rs +162 -0
  84. data/crates/kobako-runtime/src/vfs/dentry.rs +1466 -0
  85. data/crates/kobako-runtime/src/vfs/file.rs +1911 -0
  86. data/crates/kobako-runtime/src/vfs/inode.rs +425 -0
  87. data/crates/kobako-runtime/src/vfs/kern_path.rs +213 -0
  88. data/crates/kobako-runtime/src/vfs/mount.rs +60 -0
  89. data/crates/kobako-runtime/src/vfs/namei.rs +5837 -0
  90. data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
  91. data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
  92. data/crates/kobako-runtime/src/vfs/openat2.rs +116 -0
  93. data/crates/kobako-runtime/src/vfs/path.rs +64 -0
  94. data/crates/kobako-runtime/src/vfs/readdir.rs +163 -0
  95. data/crates/kobako-runtime/src/vfs/stat.rs +293 -0
  96. data/crates/kobako-runtime/src/vfs/super_block.rs +126 -0
  97. data/crates/kobako-runtime/src/vfs/utimes.rs +299 -0
  98. data/crates/kobako-runtime/src/vfs.rs +63 -0
  99. data/crates/kobako-runtime/src/wait.rs +356 -0
  100. data/crates/kobako-transport/CHANGELOG.md +39 -2
  101. data/crates/kobako-transport/Cargo.toml +3 -3
  102. data/crates/kobako-transport/README.md +8 -8
  103. data/crates/kobako-transport/src/abi.rs +78 -72
  104. data/crates/kobako-transport/src/envelope/bytes.rs +49 -30
  105. data/crates/kobako-transport/src/envelope/call.rs +37 -9
  106. data/crates/kobako-transport/src/envelope/compile_reply.rs +2 -2
  107. data/crates/kobako-transport/src/envelope/error_record.rs +24 -3
  108. data/crates/kobako-transport/src/envelope/fault.rs +2 -2
  109. data/crates/kobako-transport/src/envelope/name.rs +99 -0
  110. data/crates/kobako-transport/src/envelope/outcome.rs +11 -11
  111. data/crates/kobako-transport/src/envelope/preamble.rs +34 -31
  112. data/crates/kobako-transport/src/envelope/reply.rs +29 -29
  113. data/crates/kobako-transport/src/envelope/request.rs +2 -2
  114. data/crates/kobako-transport/src/envelope/run.rs +1 -1
  115. data/crates/kobako-transport/src/envelope/unsupported.rs +12 -12
  116. data/crates/kobako-transport/src/envelope.rs +15 -10
  117. data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
  118. data/crates/kobako-wasmtime/Cargo.toml +35 -15
  119. data/crates/kobako-wasmtime/README.md +11 -6
  120. data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
  121. data/crates/kobako-wasmtime/build.rs +16 -0
  122. data/crates/kobako-wasmtime/src/abi.rs +19 -47
  123. data/crates/kobako-wasmtime/src/ambient.rs +33 -19
  124. data/crates/kobako-wasmtime/src/cache.rs +28 -20
  125. data/crates/kobako-wasmtime/src/config.rs +59 -60
  126. data/crates/kobako-wasmtime/src/driver.rs +63 -145
  127. data/crates/kobako-wasmtime/src/exports.rs +147 -32
  128. data/crates/kobako-wasmtime/src/guest.rs +44 -0
  129. data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
  130. data/crates/kobako-wasmtime/src/imports.rs +48 -18
  131. data/crates/kobako-wasmtime/src/instance_pre.rs +7 -7
  132. data/crates/kobako-wasmtime/src/invocation.rs +93 -51
  133. data/crates/kobako-wasmtime/src/lib.rs +6 -7
  134. data/crates/kobako-wasmtime/src/limiter.rs +52 -211
  135. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
  136. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +70 -57
  137. data/crates/kobako-wasmtime/src/preview1/differential.rs +137 -27
  138. data/crates/kobako-wasmtime/src/preview1/errno.rs +90 -233
  139. data/crates/kobako-wasmtime/src/preview1/fd.rs +1301 -522
  140. data/crates/kobako-wasmtime/src/preview1/memory.rs +126 -150
  141. data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +192 -0
  142. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +1989 -708
  143. data/crates/kobako-wasmtime/src/preview1/path.rs +181 -365
  144. data/crates/kobako-wasmtime/src/preview1/poll.rs +345 -173
  145. data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -25
  146. data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
  147. data/crates/kobako-wasmtime/src/preview1/testsuite.rs +147 -0
  148. data/crates/kobako-wasmtime/src/preview1.rs +471 -416
  149. data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
  150. data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
  151. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
  152. data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
  153. data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
  154. data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
  155. data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
  156. data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
  157. data/crates/kobako-wasmtime/src/preview2.rs +57 -0
  158. data/crates/kobako-wasmtime/src/trap.rs +31 -16
  159. data/crates/kobako-wasmtime/src/wasi.rs +238 -93
  160. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  161. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  162. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  163. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  164. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  165. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  166. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  167. data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
  168. data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
  169. data/data/kobako.wasm +0 -0
  170. data/ext/kobako/Cargo.toml +1 -1
  171. data/ext/kobako/src/{runtime/errors.rs → errors.rs} +35 -27
  172. data/ext/kobako/src/escape.rs +98 -0
  173. data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +36 -16
  174. data/ext/kobako/src/filesystem/ruby.rs +689 -0
  175. data/ext/kobako/src/filesystem.rs +217 -0
  176. data/ext/kobako/src/gvl.rs +306 -0
  177. data/ext/kobako/src/lib.rs +64 -3
  178. data/ext/kobako/src/network/mock.rs +187 -0
  179. data/ext/kobako/src/network.rs +591 -0
  180. data/ext/kobako/src/runtime/bridge.rs +31 -30
  181. data/ext/kobako/src/runtime/snapshot.rs +5 -5
  182. data/ext/kobako/src/runtime.rs +221 -138
  183. data/ext/kobako/src/wire.rs +42 -0
  184. data/lib/kobako/catalog/extensions.rb +19 -7
  185. data/lib/kobako/catalog/flags.rb +4 -6
  186. data/lib/kobako/catalog/grants.rb +5 -4
  187. data/lib/kobako/catalog/handles.rb +9 -31
  188. data/lib/kobako/catalog/mount.rb +12 -12
  189. data/lib/kobako/catalog/network.rb +35 -0
  190. data/lib/kobako/catalog/replacements.rb +28 -0
  191. data/lib/kobako/catalog/services.rb +7 -21
  192. data/lib/kobako/catalog/snippets.rb +10 -25
  193. data/lib/kobako/catalog.rb +4 -1
  194. data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
  195. data/lib/kobako/codec/decoder.rb +12 -12
  196. data/lib/kobako/codec/ext_types.rb +5 -7
  197. data/lib/kobako/codec/handle_walk.rb +5 -47
  198. data/lib/kobako/codec/nesting.rb +7 -7
  199. data/lib/kobako/codec/value_budget.rb +134 -42
  200. data/lib/kobako/codec.rb +1 -1
  201. data/lib/kobako/context.rb +28 -15
  202. data/lib/kobako/errors.rb +15 -12
  203. data/lib/kobako/extension.rb +3 -2
  204. data/lib/kobako/filesystem.rb +53 -15
  205. data/lib/kobako/handle.rb +2 -2
  206. data/lib/kobako/names.rb +28 -0
  207. data/lib/kobako/network.rb +210 -0
  208. data/lib/kobako/outcome.rb +7 -7
  209. data/lib/kobako/payload/arguments.rb +2 -2
  210. data/lib/kobako/pool.rb +47 -25
  211. data/lib/kobako/runtime.rb +3 -2
  212. data/lib/kobako/sandbox.rb +113 -56
  213. data/lib/kobako/sandbox_options.rb +41 -107
  214. data/lib/kobako/snippet/bytecode.rb +1 -1
  215. data/lib/kobako/snippet/source.rb +1 -1
  216. data/lib/kobako/transport/argument_wrap.rb +64 -0
  217. data/lib/kobako/transport/block_failure.rb +1 -1
  218. data/lib/kobako/transport/dispatcher.rb +10 -10
  219. data/lib/kobako/transport/exposure.rb +28 -17
  220. data/lib/kobako/transport/reflection.rb +28 -11
  221. data/lib/kobako/transport/run.rb +13 -28
  222. data/lib/kobako/transport/yielder.rb +3 -10
  223. data/lib/kobako/transport.rb +1 -0
  224. data/lib/kobako/version.rb +1 -1
  225. data/lib/kobako.rb +38 -0
  226. data/release-please-config.json +16 -0
  227. data/sig/core/thread.rbs +6 -0
  228. data/sig/kobako/catalog/extensions.rbs +5 -3
  229. data/sig/kobako/catalog/grants.rbs +7 -4
  230. data/sig/kobako/catalog/handles.rbs +2 -4
  231. data/sig/kobako/catalog/mount.rbs +3 -5
  232. data/sig/kobako/catalog/network.rbs +20 -0
  233. data/sig/kobako/catalog/replacements.rbs +14 -0
  234. data/sig/kobako/catalog/services.rbs +1 -5
  235. data/sig/kobako/catalog/snippets.rbs +3 -5
  236. data/sig/kobako/catalog.rbs +1 -1
  237. data/sig/kobako/codec/boundary.rbs +9 -0
  238. data/sig/kobako/codec/decoder.rbs +1 -1
  239. data/sig/kobako/codec/handle_walk.rbs +0 -6
  240. data/sig/kobako/codec/nesting.rbs +2 -2
  241. data/sig/kobako/codec/value_budget.rbs +48 -5
  242. data/sig/kobako/codec.rbs +1 -2
  243. data/sig/kobako/context.rbs +4 -2
  244. data/sig/kobako/errors.rbs +4 -4
  245. data/sig/kobako/filesystem.rbs +38 -15
  246. data/sig/kobako/guest_yielder.rbs +1 -1
  247. data/sig/kobako/network.rbs +115 -0
  248. data/sig/kobako/outcome.rbs +1 -1
  249. data/sig/kobako/payload/arguments.rbs +1 -1
  250. data/sig/kobako/pool.rbs +8 -4
  251. data/sig/kobako/runtime.rbs +32 -3
  252. data/sig/kobako/sandbox.rbs +22 -7
  253. data/sig/kobako/sandbox_options.rbs +29 -38
  254. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  255. data/sig/kobako/transport/dispatcher.rbs +2 -2
  256. data/sig/kobako/transport/error.rbs +1 -1
  257. data/sig/kobako/transport/exposure.rbs +3 -5
  258. data/sig/kobako/transport/reflection.rbs +12 -2
  259. data/sig/kobako/transport/run.rbs +3 -5
  260. data/sig/kobako/transport/yielder.rbs +0 -3
  261. data/sig/kobako/transport.rbs +2 -2
  262. data/sig/kobako.rbs +13 -0
  263. metadata +131 -34
  264. data/crates/kobako-runtime/src/filesystem/directory/spelling.rs +0 -194
  265. data/crates/kobako-runtime/src/filesystem/directory.rs +0 -1082
  266. data/crates/kobako-runtime/src/filesystem/memory.rs +0 -1100
  267. data/crates/kobako-runtime/src/filesystem/overlay/exclusive.rs +0 -88
  268. data/crates/kobako-runtime/src/filesystem/path.rs +0 -60
  269. data/crates/kobako-runtime/src/filesystem/temporary.rs +0 -167
  270. data/crates/kobako-wasmtime/src/capture.rs +0 -96
  271. data/crates/kobako-wasmtime/src/descriptors.rs +0 -167
  272. data/crates/kobako-wasmtime/src/dispatch.rs +0 -125
  273. data/crates/kobako-wasmtime/src/guest_mem.rs +0 -271
  274. data/crates/kobako-wasmtime/src/io.rs +0 -89
  275. data/crates/kobako-wasmtime/src/preview1/args.rs +0 -60
  276. data/crates/kobako-wasmtime/src/preview1/beneath.rs +0 -188
  277. data/crates/kobako-wasmtime/tests/compile_posture.rs +0 -43
  278. data/crates/kobako-wasmtime/tests/guest_file.rs +0 -1054
  279. data/crates/kobako-wasmtime/tests/preamble_flags.rs +0 -70
  280. data/crates/kobako-wasmtime/tests/snippet_compile.rs +0 -95
  281. data/crates/kobako-wasmtime/tests/support/mod.rs +0 -30
  282. data/crates/kobako-wasmtime/tests/unanswered_call.rs +0 -86
  283. data/crates/kobako-wasmtime/tests/unsupported_call.rs +0 -51
  284. data/ext/kobako/src/runtime/escape.rs +0 -53
  285. data/ext/kobako/src/runtime/filesystem/ruby.rs +0 -400
  286. data/ext/kobako/src/runtime/filesystem.rs +0 -236
  287. data/ext/kobako/src/runtime/gvl.rs +0 -112
  288. data/lib/kobako/constant_name.rb +0 -8
  289. data/sig/kobako/codec/utils.rbs +0 -9
  290. data/sig/kobako/constant_name.rbs +0 -3
  291. /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
@@ -14,15 +14,6 @@ module Kobako
14
14
  PREDICATE = :respond_to_guest?
15
15
  private_constant :PREDICATE
16
16
 
17
- # Kernel's own reflection, bound onto each object so a forwarder or a
18
- # BasicObject answers from its own method table rather than through
19
- # +method_missing+ / +respond_to_missing?+.
20
- CLASS_OF = Kernel.instance_method(:class)
21
- SINGLETON_CLASS_OF = Kernel.instance_method(:singleton_class)
22
- SINGLETON_METHODS = Kernel.instance_method(:singleton_methods)
23
- PRIVATE_METHODS = Kernel.instance_method(:private_methods)
24
- private_constant :CLASS_OF, :SINGLETON_CLASS_OF, :SINGLETON_METHODS, :PRIVATE_METHODS
25
-
26
17
  CALLABLE = Set.new(Reflection::CALLABLE_ALLOW).freeze
27
18
  NOTHING = Set.new.freeze
28
19
  private_constant :CALLABLE, :NOTHING
@@ -31,18 +22,38 @@ module Kobako
31
22
  # each class's own surface for a caller that makes many references at
32
23
  # once (a Handle table), so two objects of one class enumerate it once.
33
24
  def self.of(object, surfaces = {})
34
- klass = CLASS_OF.bind_call(object)
35
- names = narrows_itself?(object, klass) ? nil : default_names(object, klass, surfaces)
25
+ klass = Reflection::CLASS_OF.bind_call(object)
26
+ names = narrows_itself?(object, klass) ? nil : resolve_default_names(object, klass, surfaces)
36
27
  new(object: object, names: names)
37
28
  end
38
29
 
30
+ # The class of +object+ when no reference may stand for it, as its
31
+ # reachable surface is not Service behaviour; +nil+ otherwise. A
32
+ # +Binding+ / +Method+ / +UnboundMethod+ hands the guest a callable
33
+ # proxy onto host reflection (a returned +Binding+ reaches
34
+ # +Binding#eval+); a +Class+ or +Module+ hands over its class-level API
35
+ # (+File.popen+ / +read+, +Kernel.system+), which the owner-based
36
+ # dispatch floor cannot see because a singleton-class owner matches no
37
+ # core-module list; a +Delegator+ (+SimpleDelegator+, +DelegateClass+,
38
+ # +WeakRef+, +Tempfile+) is a transparent forwarder whose public
39
+ # +method_missing+ binds and calls the private method the guest names
40
+ # (+Kernel#system+), a surface the floor reads as ordinary Service
41
+ # behaviour.
42
+ def self.refused_class_of(object)
43
+ case object
44
+ when Binding, Method, UnboundMethod, Module, Delegator
45
+ # Delegator < BasicObject exposes no static +#class+.
46
+ Reflection::CLASS_OF.bind_call(object)
47
+ end
48
+ end
49
+
39
50
  # Whether the guest may call +name+ through this reference. The
40
51
  # object's own predicate is consulted with the private surface
41
52
  # included, so the guest's +public_send+ can never reach it.
42
53
  def exposes?(name)
43
54
  return names.include?(name) if names
44
55
 
45
- object.__send__(PREDICATE, name) ? true : false
56
+ Reflection::SEND.bind_call(object, PREDICATE, name) ? true : false
46
57
  end
47
58
 
48
59
  class << self
@@ -53,13 +64,13 @@ module Kobako
53
64
  # +respond_to_missing?+ cannot answer for it.
54
65
  def narrows_itself?(object, klass)
55
66
  klass.method_defined?(PREDICATE) || klass.private_method_defined?(PREDICATE) ||
56
- PRIVATE_METHODS.bind_call(object, false).include?(PREDICATE) ||
57
- SINGLETON_METHODS.bind_call(object, false).include?(PREDICATE)
67
+ Reflection::PRIVATE_METHODS.bind_call(object, false).include?(PREDICATE) ||
68
+ Reflection::SINGLETON_METHODS.bind_call(object, false).include?(PREDICATE)
58
69
  end
59
70
 
60
71
  # A callable keeps its callable names; a class-level surface or a
61
72
  # forwarder has no surface of its own to expose.
62
- def default_names(object, klass, surfaces)
73
+ def resolve_default_names(object, klass, surfaces)
63
74
  case object
64
75
  when Proc, Method then CALLABLE
65
76
  when Module, Delegator then NOTHING
@@ -76,9 +87,9 @@ module Kobako
76
87
  end
77
88
 
78
89
  def with_singleton(object, names)
79
- return names if SINGLETON_METHODS.bind_call(object, false).empty?
90
+ return names if Reflection::SINGLETON_METHODS.bind_call(object, false).empty?
80
91
 
81
- names.union(authored_names(SINGLETON_CLASS_OF.bind_call(object))).freeze
92
+ names.union(authored_names(Reflection::SINGLETON_CLASS_OF.bind_call(object))).freeze
82
93
  end
83
94
 
84
95
  # The public methods +owner+ itself defines in Ruby source.
@@ -17,6 +17,19 @@ module Kobako
17
17
  # callable exposes by default, so the floor and the Exposure agree.
18
18
  CALLABLE_ALLOW = %i[call [] yield arity lambda?].freeze
19
19
 
20
+ # Kernel's own reflection and dispatch, bound onto each object so a
21
+ # forwarder or a BasicObject answers from its own method table rather
22
+ # than through +method_missing+ / +respond_to_missing?+, for the floor,
23
+ # the Exposure, and the call alike.
24
+ CLASS_OF = Kernel.instance_method(:class)
25
+ IS_A = Kernel.instance_method(:is_a?)
26
+ SINGLETON_CLASS_OF = Kernel.instance_method(:singleton_class)
27
+ SINGLETON_METHODS = Kernel.instance_method(:singleton_methods)
28
+ PRIVATE_METHODS = Kernel.instance_method(:private_methods)
29
+ RESPOND_TO = Kernel.instance_method(:respond_to?)
30
+ PUBLIC_SEND = Kernel.instance_method(:public_send)
31
+ SEND = BasicObject.instance_method(:__send__)
32
+
20
33
  # The reason +name+ is unreachable through +exposure+, or +nil+ when
21
34
  # the dispatch may proceed. Composes the ambient-surface floor with the
22
35
  # reference's Exposure, in that order: the Exposure only narrows and
@@ -77,20 +90,20 @@ module Kobako
77
90
  # A name with no method never reaches +instance_method+, which would
78
91
  # keep a guest-chosen name as a Symbol for the life of the process.
79
92
  def ambient_refusal(target, name)
80
- return refused(name) if name == :method_missing
93
+ return service_refusal(name) if name == :method_missing
81
94
 
82
95
  klass = lookup_class(target)
83
- return defined_refusal(target, name, klass) if klass.public_method_defined?(name)
84
- return "no public method #{name.inspect} on target" unless target.respond_to?(name)
85
- return refused(name) if klass.method_defined?(name) || klass.private_method_defined?(name)
96
+ return public_method_refusal(target, name, klass) if klass.public_method_defined?(name)
97
+ return "no public method #{name.inspect} on target" unless RESPOND_TO.bind_call(target, name)
98
+ return service_refusal(name) if klass.method_defined?(name) || klass.private_method_defined?(name)
86
99
 
87
100
  owner_refusal(target, name, klass)
88
101
  end
89
102
 
90
- def defined_refusal(target, name, klass)
103
+ def public_method_refusal(target, name, klass)
91
104
  method = klass.instance_method(name)
92
105
  owner_refusal(target, name, method.owner) ||
93
- (authored_for?(target, name, method, klass) ? nil : refused(name))
106
+ (authored_for?(target, name, method, klass) ? nil : service_refusal(name))
94
107
  end
95
108
 
96
109
  # A bound callable keeps its callable names and a record its member
@@ -102,7 +115,7 @@ module Kobako
102
115
  (klass <= Struct || klass <= Data) && target.members.include?(name)
103
116
  end
104
117
 
105
- def refused(name)
118
+ def service_refusal(name)
106
119
  "method #{name.inspect} is not a Service method"
107
120
  end
108
121
 
@@ -110,16 +123,20 @@ module Kobako
110
123
  return nil unless ambient_owner?(owner, target)
111
124
  return nil if GADGET_OWNERS.include?(owner) && CALLABLE_ALLOW.include?(name)
112
125
 
113
- refused(name)
126
+ service_refusal(name)
114
127
  end
115
128
 
116
129
  # The class a method lookup on +target+ starts at. A plain object's
117
130
  # singleton class is taken only when it already holds a public
118
131
  # method, since asking for it otherwise would create one.
119
132
  def lookup_class(target)
120
- return target.singleton_class if target.is_a?(Module) || target.singleton_methods.any?
133
+ return SINGLETON_CLASS_OF.bind_call(target) if module?(target) || SINGLETON_METHODS.bind_call(target).any?
134
+
135
+ CLASS_OF.bind_call(target)
136
+ end
121
137
 
122
- target.class
138
+ def module?(target)
139
+ IS_A.bind_call(target, Module)
123
140
  end
124
141
 
125
142
  # Whatever +Class+ inherits is surface every object shares rather
@@ -132,7 +149,7 @@ module Kobako
132
149
  def ambient_owner?(owner, target)
133
150
  owner >= Class ||
134
151
  GADGET_OWNERS.include?(owner) ||
135
- (target.is_a?(Module) && owner.singleton_class?)
152
+ (module?(target) && owner.singleton_class?)
136
153
  end
137
154
  end
138
155
  end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../constant_name"
4
3
  require_relative "../handle"
4
+ require_relative "../names"
5
5
  require_relative "../codec"
6
6
  require_relative "../payload"
7
+ require_relative "argument_wrap"
7
8
 
8
9
  module Kobako
9
10
  module Transport
@@ -11,9 +12,9 @@ module Kobako
11
12
  # legitimately holds one.
12
13
  class Run < Data.define(:entrypoint, :args, :kwargs) # :nodoc:
13
14
  def initialize(entrypoint:, args: [], kwargs: {})
14
- entrypoint = normalize_entrypoint(entrypoint)
15
- validate_args!(args)
16
- validate_kwargs!(kwargs)
15
+ entrypoint = Kobako.to_constant_name(entrypoint, "entrypoint")
16
+ validate_args(args)
17
+ validate_kwargs(kwargs)
17
18
  super
18
19
  end
19
20
 
@@ -21,44 +22,28 @@ module Kobako
21
22
  # invocation's table. The walk starts one level down, since +args+ and
22
23
  # +kwargs+ ride inside the payload document the wire's nesting bound
23
24
  # is counted from.
24
- def payload(handles)
25
+ def encode_payload(handles)
25
26
  Payload::Arguments.new(
26
- args: Codec::HandleWalk.deep_wrap(args, handles, 1),
27
- kwargs: Codec::HandleWalk.deep_wrap(kwargs, handles, 1)
27
+ args: ArgumentWrap.wrap(args, handles, 1),
28
+ kwargs: ArgumentWrap.wrap(kwargs, handles, 1)
28
29
  ).encode
29
30
  end
30
31
 
31
32
  private
32
33
 
33
- # A target of the wrong type raises TypeError, a Host App programming
34
- # error caught before the run reaches the guest.
35
- def normalize_entrypoint(target)
36
- unless target.is_a?(Symbol) || target.is_a?(String)
37
- raise TypeError, "entrypoint must be a Symbol or String, got #{target.class}"
38
- end
39
-
40
- target_str = target.to_s
41
- unless CONSTANT_NAME.match?(target_str)
42
- raise ArgumentError,
43
- "entrypoint must match #{CONSTANT_NAME.inspect} (got #{target.inspect})"
44
- end
45
-
46
- target_str.to_sym
47
- end
48
-
49
- def validate_args!(args)
50
- raise ArgumentError, "arguments must be an Array" unless args.is_a?(Array)
34
+ def validate_args(args)
35
+ raise TypeError, "arguments must be an Array" unless args.is_a?(Array)
51
36
  raise ArgumentError, forged_handle_message("arguments") if args.any?(Kobako::Handle)
52
37
  end
53
38
 
54
39
  # Checked here so the Host App sees the host-side message before any
55
40
  # encode boundary.
56
- def validate_kwargs!(kwargs)
57
- raise ArgumentError, "keyword arguments must be a Hash" unless kwargs.is_a?(Hash)
41
+ def validate_kwargs(kwargs)
42
+ raise TypeError, "keyword arguments must be a Hash" unless kwargs.is_a?(Hash)
58
43
 
59
44
  bad_keys = kwargs.each_key.grep_v(Symbol)
60
45
  unless bad_keys.empty?
61
- raise ArgumentError,
46
+ raise TypeError,
62
47
  "keyword argument keys must be Symbols (got #{bad_keys.inspect})"
63
48
  end
64
49
  raise ArgumentError, forged_handle_message("keyword argument values") if kwargs.each_value.any?(Kobako::Handle)
@@ -11,18 +11,15 @@ module Kobako
11
11
  @break_tag = break_tag
12
12
  @handles = handles
13
13
  @failure = failure
14
- @active = true
15
14
  end
16
15
 
17
16
  # The ok value is consumed by the host Service, so a Capability Handle
18
17
  # in it is restored. A block exit stays in the guest, so the Service
19
18
  # is only unwound.
20
19
  def yield(*args)
21
- raise LocalJumpError, "guest block invoked after host dispatch frame returned" unless @active
22
-
23
- arm, body, klass = @guest_yielder.call(encode_args(args))
20
+ arm, body, class_name = @guest_yielder.call(encode_args(args))
24
21
  raise UnsupportedError, "the Sandbox runtime does not support yielding to a block" if arm == :unsupported
25
- raise @failure.remember(BlockError.new(body, klass: klass)) if arm == :error
22
+ raise @failure.remember(BlockError.new(body, class_name: class_name)) if arm == :error
26
23
 
27
24
  throw @break_tag if arm == :break
28
25
 
@@ -33,16 +30,12 @@ module Kobako
33
30
  method(:yield).to_proc
34
31
  end
35
32
 
36
- def invalidate
37
- @active = false
38
- end
39
-
40
33
  private
41
34
 
42
35
  # Restated so the Service reads a refusal of its own argument rather
43
36
  # than a codec class it never named.
44
37
  def encode_args(args)
45
- Kobako::Codec::Nesting.assert_within_bound!(args)
38
+ Kobako::Codec::Nesting.assert_within_bound(args)
46
39
  Kobako::Codec::Encoder.encode(args)
47
40
  rescue Kobako::Codec::Error => e
48
41
  raise YieldValueError, "Service yielded a value the block cannot receive: #{e.message}"
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "transport/call"
4
+ require_relative "transport/argument_wrap"
4
5
  require_relative "transport/run"
5
6
  require_relative "transport/block_failure"
6
7
  require_relative "transport/yielder"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kobako
4
- VERSION = "0.29.0"
4
+ VERSION = "0.31.0"
5
5
  end
data/lib/kobako.rb CHANGED
@@ -1,5 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Inside +lib/+, the code sits in tiers: a tier may use the tiers below it
4
+ # and never one above.
5
+ #
6
+ # Orchestration Sandbox, Pool, Runtime (+ ext), Context
7
+ # |
8
+ # Catalog setup-time registries + the per-invocation Handle table
9
+ # |
10
+ # Transport --+ call value objects + dispatch
11
+ # Outcome ----+ guest-result attribution
12
+ # | |
13
+ # Payload <---+ the [args, kwargs] shape a Call or Run carries
14
+ # | |
15
+ # Codec <-----+ byte-level payload wire
16
+ # |
17
+ # Root dependency-free value objects and error classes
18
+ #
19
+ # The Envelope has no tier here, because the native side frames and
20
+ # decodes it.
21
+ #
22
+ # These rules keep the tiers acyclic:
23
+ #
24
+ # [A type sits at the lowest tier that needs it]
25
+ # Kobako::Handle sits at the root, for Codec.
26
+ # [A native piece sits at the tier of the constant it registers on]
27
+ # Kobako::Filesystem and Kobako::Network sit at the root, for the
28
+ # Catalog, and so do the name rules on Kobako itself, for the Catalog and
29
+ # Transport; Kobako::Runtime sits with the Sandbox that drives it.
30
+ # [Outcome may require <tt>transport/error.rb</tt>]
31
+ # The gem contract fixes the class name.
32
+ # [<tt>Codec.track_handles</tt> wraps only the decode call]
33
+ # Wrapping more leaks its flag into re-entry.
34
+ #
35
+ # Namespace follows dependency direction, not which tier reads a type most.
36
+ # Kobako::Transport::Error stays in Transport despite the lateral edge from
37
+ # Outcome, because its file depends only on the root <tt>errors.rb</tt>.
38
+
3
39
  require_relative "kobako/version"
4
40
 
5
41
  begin
@@ -10,7 +46,9 @@ rescue LoadError
10
46
  end
11
47
 
12
48
  require_relative "kobako/filesystem"
49
+ require_relative "kobako/network"
13
50
  require_relative "kobako/errors"
51
+ require_relative "kobako/names"
14
52
  require_relative "kobako/unresolved"
15
53
  require_relative "kobako/extension"
16
54
  require_relative "kobako/transport"
@@ -2,6 +2,7 @@
2
2
  "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3
3
  "release-type": "ruby",
4
4
  "bump-minor-pre-major": true,
5
+ "commit-search-depth": 1000,
5
6
  "last-release-sha": "98509af508988f708bf0d7a76a718bb0428a177e",
6
7
  "packages": {
7
8
  ".": {
@@ -114,6 +115,11 @@
114
115
  "path": "/wasm/kobako-baker/Cargo.lock",
115
116
  "jsonpath": "$.package[?(@.name=='kobako-baker')].version"
116
117
  },
118
+ {
119
+ "type": "toml",
120
+ "path": "/wasm/kobako-baker/Cargo.toml",
121
+ "jsonpath": "$.dependencies['kobako-transport'].version"
122
+ },
117
123
  {
118
124
  "type": "generic",
119
125
  "path": "/wasm/kobako-baker/README.md"
@@ -139,6 +145,11 @@
139
145
  "path": "/wasm/Cargo.lock",
140
146
  "jsonpath": "$.package[?(@.name=='kobako-transport')].version"
141
147
  },
148
+ {
149
+ "type": "toml",
150
+ "path": "/wasm/kobako-baker/Cargo.lock",
151
+ "jsonpath": "$.package[?(@.name=='kobako-transport')].version"
152
+ },
142
153
  {
143
154
  "type": "generic",
144
155
  "path": "/crates/kobako-transport/README.md"
@@ -159,6 +170,11 @@
159
170
  "path": "/wasm/Cargo.lock",
160
171
  "jsonpath": "$.package[?(@.name=='kobako-codec')].version"
161
172
  },
173
+ {
174
+ "type": "toml",
175
+ "path": "/crates/kobako-codec/Cargo.toml",
176
+ "jsonpath": "$.dependencies['kobako-transport'].version"
177
+ },
162
178
  {
163
179
  "type": "generic",
164
180
  "path": "/crates/kobako-codec/README.md"
@@ -0,0 +1,6 @@
1
+ # The block form rbs 4.2.0 leaves out. ruby/rbs types it after that release
2
+ # (7c396890); this goes once a release carrying it is the floor.
3
+ class Thread
4
+ def self.handle_interrupt: [T] (Hash[Class, :immediate | :on_blocking | :never] hash) { (nil) -> T } -> T
5
+ | ...
6
+ end
@@ -5,17 +5,19 @@ module Kobako
5
5
 
6
6
  def install: (untyped extension, snippets: Kobako::Catalog::Snippets, services: Kobako::Catalog::Services) -> self
7
7
 
8
- def assert_dependencies!: () -> self
8
+ def assert_dependencies: () -> self
9
9
 
10
10
  def resolve: () -> Hash[String, untyped]
11
11
 
12
12
  private
13
13
 
14
- def install_object: (untyped backend) -> untyped
14
+ def object_of: (untyped backend) -> untyped
15
15
 
16
16
  def resolve_backend: (untyped extension, Hash[String, untyped] resolved, Hash[untyped, untyped] by_provider) -> void
17
17
 
18
- def validate!: (untyped extension) -> void
18
+ def validate: (untyped extension) -> void
19
+
20
+ def validate_dependencies: (untyped dependencies) -> void
19
21
 
20
22
  def unmet_dependency: () -> [untyped, untyped]?
21
23
 
@@ -1,13 +1,16 @@
1
1
  module Kobako
2
2
  module Catalog
3
3
  class Grants
4
- def initialize: () -> void
4
+ type key = [Symbol, String]
5
+
6
+ type grant = Mount | Network
5
7
 
6
- def register: (Mount grant) -> nil
8
+ def initialize: () -> void
7
9
 
8
- def include?: (Mount grant) -> bool
10
+ def register: (grant grant) -> nil
9
11
 
10
- def entries: (?Hash[String, Mount] overrides) -> Array[Mount::tuple]
12
+ def include?: (grant grant) -> bool
13
+ def entries: (?Hash[key, grant] overrides) -> [Array[Mount::tuple], Array[Network::tuple]]
11
14
  end
12
15
  end
13
16
  end
@@ -13,11 +13,9 @@ module Kobako
13
13
 
14
14
  private
15
15
 
16
- def reject_unwrappable!: (untyped object) -> void
16
+ def ensure_capacity: () -> void
17
17
 
18
- def ensure_capacity!: () -> void
19
-
20
- def require_bound!: (Integer id) -> void
18
+ def require_bound: (Integer id) -> void
21
19
  end
22
20
  end
23
21
  end
@@ -14,15 +14,13 @@ module Kobako
14
14
 
15
15
  def self.new: (at: untyped, access: untyped, filesystem: untyped, policy: policy?) -> Mount
16
16
 
17
- def key: () -> String
17
+ def initialize: (at: untyped, access: untyped, filesystem: untyped, policy: policy?) -> void
18
+
19
+ def key: () -> Grants::key
18
20
 
19
21
  def conflict: (Mount other) -> String?
20
22
 
21
23
  def to_native: () -> tuple
22
-
23
- private
24
-
25
- def nested?: (String other) -> bool
26
24
  end
27
25
  end
28
26
  end
@@ -0,0 +1,20 @@
1
+ module Kobako
2
+ module Catalog
3
+ class Network < Data
4
+ type tuple = [String, untyped]
5
+
6
+ attr_reader name: String
7
+ attr_reader entry: untyped
8
+
9
+ def self.new: (name: untyped, entry: untyped) ?{ (Kobako::Network::Builder) -> void } -> Network
10
+
11
+ def initialize: (name: untyped, entry: untyped) ?{ (Kobako::Network::Builder) -> void } -> void
12
+
13
+ def key: () -> Grants::key
14
+
15
+ def conflict: (Mount | Network other) -> String?
16
+
17
+ def to_native: () -> tuple
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ module Kobako
2
+ module Catalog
3
+ class Replacements
4
+ @grants: Grants
5
+ @replaced: Hash[Grants::key, Grants::grant]
6
+
7
+ def initialize: (Grants grants) -> void
8
+
9
+ def replace: (Grants::grant grant, String refusal) -> nil
10
+
11
+ def entries: () -> [Array[Mount::tuple], Array[Network::tuple]]
12
+ end
13
+ end
14
+ end
@@ -1,8 +1,6 @@
1
1
  module Kobako
2
2
  module Catalog
3
3
  class Services
4
- RESERVED_NAMESPACE: String
5
-
6
4
  def initialize: () -> void
7
5
 
8
6
  def bind: (Symbol | String path, untyped object) -> self
@@ -15,9 +13,7 @@ module Kobako
15
13
 
16
14
  private
17
15
 
18
- def validate_path!: (Symbol | String path) -> String
19
-
20
- def reserved?: (String path) -> bool
16
+ def validate_path: (Symbol | String path) -> String
21
17
 
22
18
  def collision?: (String path) -> bool
23
19
  end
@@ -15,15 +15,13 @@ module Kobako
15
15
 
16
16
  private
17
17
 
18
- def register_source!: (String? code, (Symbol | String)? name) -> nil
18
+ def register_source: (String? code, (Symbol | String)? name) -> nil
19
19
 
20
- def ensure_source_args!: (String? code, (Symbol | String)? name) -> [String, Symbol | String]
20
+ def ensure_source_args: (String? code, (Symbol | String)? name) -> [String, Symbol | String]
21
21
 
22
- def register_binary!: (String bytes) -> nil
22
+ def register_binary: (String bytes) -> nil
23
23
 
24
24
  def entry_tuple: (entry) -> tuple
25
-
26
- def normalize_name: (Symbol | String name) -> Symbol
27
25
  end
28
26
  end
29
27
  end
@@ -1,5 +1,5 @@
1
1
  module Kobako
2
2
  module Catalog
3
- def self.to_utf8!: (String text, String what) -> String
3
+ def self.to_utf8: (String text, String what) -> String
4
4
  end
5
5
  end
@@ -0,0 +1,9 @@
1
+ module Kobako
2
+ module Codec
3
+ module Boundary
4
+ def self.assert_utf8: (String string, String label) -> void
5
+
6
+ def self.within: [T] () { () -> T } -> T
7
+ end
8
+ end
9
+ end
@@ -6,7 +6,7 @@ module Kobako
6
6
 
7
7
  private
8
8
 
9
- def self.validate_utf8!: (untyped value) -> void
9
+ def self.validate_utf8: (untyped value) -> void
10
10
  end
11
11
  end
12
12
  end
@@ -5,16 +5,10 @@ module Kobako
5
5
 
6
6
  def self.representable?: (untyped value, ?Integer depth) -> bool
7
7
 
8
- def self.deep_wrap: (untyped value, Kobako::Codec::_HandleTable handles, ?Integer depth) -> untyped
9
-
10
8
  def self.deep_restore: (untyped value, Kobako::Codec::_HandleTable handles) -> untyped
11
9
 
12
10
  private
13
11
 
14
- def self.guard_nesting!: (Integer depth) -> void
15
-
16
- def self.deep_wrap_hash: (Hash[untyped, untyped] hash, Kobako::Codec::_HandleTable handles, Integer depth) -> Hash[untyped, untyped]
17
-
18
12
  def self.primitive_type?: (untyped value) -> bool
19
13
 
20
14
  def self.container_representable?: (untyped value, Integer depth) -> bool
@@ -1,9 +1,9 @@
1
1
  module Kobako
2
2
  module Codec
3
3
  module Nesting
4
- def self.assert_within_bound!: (untyped value, ?Integer depth) -> void
4
+ def self.assert_within_bound: (untyped value, ?Integer depth) -> void
5
5
 
6
- def self.assert_members_within_bound!: (Array[untyped] members, Integer depth) -> void
6
+ def self.assert_members_within_bound: (Array[untyped] members, Integer depth) -> void
7
7
  end
8
8
  end
9
9
  end