@superhq/shuru 0.1.0 → 0.1.1

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 ADDED
@@ -0,0 +1,88 @@
1
+ # @superhq/shuru
2
+
3
+ TypeScript SDK for [shuru](https://github.com/superhq-ai/shuru) — programmatic access to ephemeral Linux microVMs on macOS.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add @superhq/shuru
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { Sandbox } from "@superhq/shuru";
15
+
16
+ const sb = await Sandbox.start();
17
+
18
+ const result = await sb.exec("echo hello");
19
+ console.log(result.stdout); // "hello\n"
20
+
21
+ await sb.writeFile("/tmp/app.ts", "console.log('hi')");
22
+ const content = await sb.readFile("/tmp/app.ts");
23
+
24
+ await sb.checkpoint("my-env"); // saves disk state and stops the VM
25
+ ```
26
+
27
+ ### Start from a checkpoint
28
+
29
+ ```ts
30
+ const sb = await Sandbox.start({ from: "my-env" });
31
+ ```
32
+
33
+ ### Options
34
+
35
+ ```ts
36
+ const sb = await Sandbox.start({
37
+ from: "my-env",
38
+ cpus: 4,
39
+ memory: 4096,
40
+ diskSize: 8192,
41
+ allowNet: true,
42
+ ports: ["8080:80"],
43
+ mounts: { "./src": "/workspace" },
44
+ });
45
+ ```
46
+
47
+ | Option | Type | Description |
48
+ |--------|------|-------------|
49
+ | `from` | `string` | Checkpoint name to start from |
50
+ | `cpus` | `number` | Number of vCPUs |
51
+ | `memory` | `number` | Memory in MB |
52
+ | `diskSize` | `number` | Disk size in MB |
53
+ | `allowNet` | `boolean` | Enable network access |
54
+ | `ports` | `string[]` | Port forwards (`"host:guest"`) |
55
+ | `mounts` | `Record<string, string>` | Directory mounts (`{ hostPath: guestPath }`) |
56
+ | `shuruBin` | `string` | Path to shuru binary (default: `"shuru"`) |
57
+
58
+ ## API
59
+
60
+ ### `Sandbox.start(opts?): Promise<Sandbox>`
61
+
62
+ Boot a new microVM. Returns when the VM is ready.
63
+
64
+ ### `sandbox.exec(command): Promise<ExecResult>`
65
+
66
+ Run a shell command in the VM. Returns `{ stdout, stderr, exitCode }`.
67
+
68
+ ### `sandbox.readFile(path): Promise<string>`
69
+
70
+ Read a file from the VM.
71
+
72
+ ### `sandbox.writeFile(path, content): Promise<void>`
73
+
74
+ Write a file to the VM.
75
+
76
+ ### `sandbox.checkpoint(name): Promise<void>`
77
+
78
+ Save the VM's disk state and stop the VM. To continue working, call `Sandbox.start({ from: name })`.
79
+
80
+ ### `sandbox.stop(): Promise<void>`
81
+
82
+ Stop the VM without saving. All changes are discarded.
83
+
84
+ ## Requirements
85
+
86
+ - macOS 14+ on Apple Silicon
87
+ - [shuru CLI](https://github.com/superhq-ai/shuru) installed
88
+ - Bun runtime
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhq/shuru",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
package/src/sandbox.ts CHANGED
@@ -3,6 +3,7 @@ import type { ExecResult, StartOptions } from "./types";
3
3
 
4
4
  export class Sandbox {
5
5
  private proc: ShuruProcess;
6
+ private stopped = false;
6
7
 
7
8
  private constructor(proc: ShuruProcess) {
8
9
  this.proc = proc;
@@ -70,9 +71,13 @@ export class Sandbox {
70
71
  if (resp.type !== "checkpoint") {
71
72
  throw new Error(`unexpected response type: ${resp.type}`);
72
73
  }
74
+ this.stopped = true;
75
+ await this.proc.stop();
73
76
  }
74
77
 
75
78
  async stop(): Promise<void> {
79
+ if (this.stopped) return;
80
+ this.stopped = true;
76
81
  await this.proc.stop();
77
82
  }
78
83
  }