matchlock-sdk 0.1.29 → 0.2.4

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.
package/README.md CHANGED
@@ -77,8 +77,9 @@ const sandbox = new Sandbox("alpine:latest").withNetworkInterception({
77
77
  - Fluent sandbox builder (`Sandbox`) with network, secrets, mounts, env, VFS hooks, image config
78
78
  - Typed network interception rules and local callback hooks via `withNetworkInterception(...)`
79
79
  - Supports fully offline mode via `.withNoNetwork()` (no guest NIC / no egress)
80
- - JSON-RPC `create`, `exec`, `exec_stream`, `exec_pipe`, `exec_tty`, `write_file`, `read_file`, `list_files`, `port_forward`, `cancel`, `close`
80
+ - JSON-RPC `create`, `exec`, `exec_stream`, `exec_pipe`, `exec_tty`, `log`, `log_stream`, `write_file`, `read_file`, `list_files`, `port_forward`, `cancel`, `close`
81
81
  - Streaming stdout/stderr via `execStream` and bidirectional stdin/stdout/stderr via `execPipe`
82
+ - VM log access via `log()` and `logStream()`
82
83
  - Interactive PTY shell/commands via `execInteractive` (stdin/stdout + resize events)
83
84
  - Local VFS callbacks (`hook`, `dangerousHook`, `mutateHook`, `actionHook`)
84
85
  - Port forwarding API parity (`portForward`, `portForwardWithAddresses`)
@@ -13,6 +13,7 @@ const REQUEST_NOTIFICATION_METHODS = new Set([
13
13
  "exec_pipe.stderr",
14
14
  "exec_tty.ready",
15
15
  "exec_tty.stdout",
16
+ "log_stream.data",
16
17
  ]);
17
18
  class RPCTransport {
18
19
  config;
@@ -29,7 +30,9 @@ class RPCTransport {
29
30
  this.onClosed = onClosed;
30
31
  }
31
32
  async start() {
32
- if (this.process && this.process.exitCode === null && !this.process.killed) {
33
+ if (this.process &&
34
+ this.process.exitCode === null &&
35
+ !this.process.killed) {
33
36
  return;
34
37
  }
35
38
  const command = this.config.useSudo ? "sudo" : this.config.binaryPath;
@@ -55,7 +58,7 @@ class RPCTransport {
55
58
  this.process = child;
56
59
  }
57
60
  isRunning() {
58
- return !!this.process && this.process.exitCode === null && !this.process.killed;
61
+ return (!!this.process && this.process.exitCode === null && !this.process.killed);
59
62
  }
60
63
  async close(timeoutSeconds = 0) {
61
64
  if (!this.isRunning()) {
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Sandbox } from "./builder";
2
- import { type BinaryLike, type Config, type CreateOptions, type ExecInteractiveOptions, type ExecInteractiveResult, type ExecOptions, type ExecPipeOptions, type ExecPipeResult, type ExecResult, type ExecStreamOptions, type ExecStreamResult, type FileInfo, type PortForwardBinding, type RequestOptions, type StreamReader, type StreamWriter, type VolumeInfo } from "./types";
2
+ import { type BinaryLike, type Config, type CreateOptions, type ExecInteractiveOptions, type ExecInteractiveResult, type ExecOptions, type ExecPipeOptions, type ExecPipeResult, type ExecResult, type ExecStreamOptions, type ExecStreamResult, type FileInfo, type LogStreamOptions, type PortForwardBinding, type RequestOptions, type StreamReader, type StreamWriter, type VolumeInfo } from "./types";
3
3
  export { defaultConfig } from "./client/utils";
4
4
  export declare class Client {
5
5
  private readonly config;
@@ -28,6 +28,8 @@ export declare class Client {
28
28
  execPipe(command: string, options?: ExecPipeOptions): Promise<ExecPipeResult>;
29
29
  execPipeWithDir(command: string, workingDir?: string, stdin?: StreamReader, stdout?: StreamWriter, stderr?: StreamWriter, options?: RequestOptions): Promise<ExecPipeResult>;
30
30
  execInteractive(command: string, options?: ExecInteractiveOptions): Promise<ExecInteractiveResult>;
31
+ log(options?: RequestOptions): Promise<string>;
32
+ logStream(options?: LogStreamOptions): Promise<void>;
31
33
  writeFile(path: string, content: BinaryLike, options?: RequestOptions): Promise<void>;
32
34
  writeFileMode(path: string, content: BinaryLike, mode: number, options?: RequestOptions): Promise<void>;
33
35
  readFile(path: string, options?: RequestOptions): Promise<Buffer>;
@@ -37,4 +39,5 @@ export declare class Client {
37
39
  private portForwardMappings;
38
40
  private sendRequest;
39
41
  private handleNotification;
42
+ private writeStreamChunk;
40
43
  }
package/dist/client.js CHANGED
@@ -152,6 +152,30 @@ class Client {
152
152
  async execInteractive(command, options = {}) {
153
153
  return this.execAPI.execInteractive(command, options);
154
154
  }
155
+ async log(options = {}) {
156
+ const result = (0, utils_1.asObject)(await this.sendRequest("log", undefined, options));
157
+ return Buffer.from((0, utils_1.asString)(result.content), "base64").toString("utf8");
158
+ }
159
+ async logStream(options = {}) {
160
+ const onNotification = (method, params) => {
161
+ if (method !== "log_stream.data") {
162
+ return;
163
+ }
164
+ const data = (0, utils_1.asString)(params.data);
165
+ if (!data) {
166
+ return;
167
+ }
168
+ let decoded;
169
+ try {
170
+ decoded = Buffer.from(data, "base64");
171
+ }
172
+ catch {
173
+ return;
174
+ }
175
+ this.writeStreamChunk(options.stdout, decoded);
176
+ };
177
+ await this.sendRequest("log_stream", undefined, options, onNotification);
178
+ }
155
179
  async writeFile(path, content, options = {}) {
156
180
  await this.writeFileMode(path, content, 0o644, options);
157
181
  }
@@ -224,5 +248,15 @@ class Client {
224
248
  this.vfsHooks.handleFileEventNotification(params, this);
225
249
  }
226
250
  }
251
+ writeStreamChunk(writer, chunk) {
252
+ if (!writer) {
253
+ return;
254
+ }
255
+ if (typeof writer === "function") {
256
+ void writer(chunk);
257
+ return;
258
+ }
259
+ writer.write(chunk);
260
+ }
227
261
  }
228
262
  exports.Client = Client;
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { Client, defaultConfig } from "./client";
2
2
  export { Sandbox, createSandbox } from "./builder";
3
3
  export { MatchlockError, RPCError } from "./errors";
4
4
  export { NETWORK_HOOK_ACTION_ALLOW, NETWORK_HOOK_ACTION_BLOCK, NETWORK_HOOK_ACTION_MUTATE, NETWORK_HOOK_PHASE_AFTER, NETWORK_HOOK_PHASE_BEFORE, VFS_HOOK_ACTION_ALLOW, VFS_HOOK_ACTION_BLOCK, VFS_HOOK_OP_STAT, VFS_HOOK_OP_READDIR, VFS_HOOK_OP_OPEN, VFS_HOOK_OP_CREATE, VFS_HOOK_OP_MKDIR, VFS_HOOK_OP_CHMOD, VFS_HOOK_OP_REMOVE, VFS_HOOK_OP_REMOVE_ALL, VFS_HOOK_OP_RENAME, VFS_HOOK_OP_SYMLINK, VFS_HOOK_OP_READLINK, VFS_HOOK_OP_READ, VFS_HOOK_OP_WRITE, VFS_HOOK_OP_CLOSE, VFS_HOOK_OP_SYNC, VFS_HOOK_OP_TRUNCATE, VFS_HOOK_PHASE_BEFORE, VFS_HOOK_PHASE_AFTER, } from "./types";
5
- export type { BinaryLike, Config, CreateOptions, ExecInteractiveOptions, ExecInteractiveResult, ExecOptions, ExecPipeOptions, ExecPipeResult, ExecResult, ExecStreamOptions, ExecStreamResult, FileInfo, VolumeInfo, HostIPMapping, ImageConfig, MountConfig, NetworkBodyTransform, NetworkHookFunc, NetworkHookRequest, NetworkHookRequestMutation, NetworkHookResponseMutation, NetworkHookResult, NetworkHookAction, NetworkHookPhase, NetworkHookRule, NetworkInterceptionConfig, PortForward, PortForwardBinding, RequestOptions, Secret, TTYSize, StreamWriter, StreamReader, VFSActionHookFunc, VFSActionRequest, VFSDangerousHookFunc, VFSHookAction, VFSHookEvent, VFSHookFunc, VFSHookOp, VFSHookPhase, VFSHookRule, VFSInterceptionConfig, VFSMutateHookFunc, VFSMutateRequest, } from "./types";
5
+ export type { BinaryLike, Config, CreateOptions, ExecInteractiveOptions, ExecInteractiveResult, ExecOptions, ExecPipeOptions, ExecPipeResult, ExecResult, ExecStreamOptions, ExecStreamResult, FileInfo, VolumeInfo, HostIPMapping, ImageConfig, LogStreamOptions, MountConfig, NetworkBodyTransform, NetworkHookFunc, NetworkHookRequest, NetworkHookRequestMutation, NetworkHookResponseMutation, NetworkHookResult, NetworkHookAction, NetworkHookPhase, NetworkHookRule, NetworkInterceptionConfig, PortForward, PortForwardBinding, RequestOptions, Secret, TTYSize, StreamWriter, StreamReader, VFSActionHookFunc, VFSActionRequest, VFSDangerousHookFunc, VFSHookAction, VFSHookEvent, VFSHookFunc, VFSHookOp, VFSHookPhase, VFSHookRule, VFSInterceptionConfig, VFSMutateHookFunc, VFSMutateRequest, } from "./types";
package/dist/types.d.ts CHANGED
@@ -241,3 +241,6 @@ export interface ExecInteractiveOptions extends ExecOptions {
241
241
  cols?: number;
242
242
  resize?: AsyncIterable<TTYSize> | Iterable<TTYSize>;
243
243
  }
244
+ export interface LogStreamOptions extends RequestOptions {
245
+ stdout?: StreamWriter;
246
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matchlock-sdk",
3
- "version": "0.1.29",
3
+ "version": "0.2.4",
4
4
  "description": "TypeScript SDK for Matchlock sandboxes",
5
5
  "license": "MIT",
6
6
  "repository": {