@hotcell/daemon 0.1.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 (142) hide show
  1. package/dist/agent-check.d.ts +1 -0
  2. package/dist/agent-check.js +105 -0
  3. package/dist/agent-check.js.map +1 -0
  4. package/dist/api/server.d.ts +64 -0
  5. package/dist/api/server.js +1368 -0
  6. package/dist/api/server.js.map +1 -0
  7. package/dist/api/ws.d.ts +14 -0
  8. package/dist/api/ws.js +214 -0
  9. package/dist/api/ws.js.map +1 -0
  10. package/dist/applevz-check.d.ts +1 -0
  11. package/dist/applevz-check.js +280 -0
  12. package/dist/applevz-check.js.map +1 -0
  13. package/dist/backups.d.ts +29 -0
  14. package/dist/backups.js +76 -0
  15. package/dist/backups.js.map +1 -0
  16. package/dist/capacity.d.ts +63 -0
  17. package/dist/capacity.js +95 -0
  18. package/dist/capacity.js.map +1 -0
  19. package/dist/config.d.ts +241 -0
  20. package/dist/config.js +152 -0
  21. package/dist/config.js.map +1 -0
  22. package/dist/cost.d.ts +9 -0
  23. package/dist/cost.js +19 -0
  24. package/dist/cost.js.map +1 -0
  25. package/dist/density-bench.d.ts +1 -0
  26. package/dist/density-bench.js +97 -0
  27. package/dist/density-bench.js.map +1 -0
  28. package/dist/driver/agent-driver.d.ts +67 -0
  29. package/dist/driver/agent-driver.js +197 -0
  30. package/dist/driver/agent-driver.js.map +1 -0
  31. package/dist/driver/agent.d.ts +94 -0
  32. package/dist/driver/agent.js +319 -0
  33. package/dist/driver/agent.js.map +1 -0
  34. package/dist/driver/applevz.d.ts +95 -0
  35. package/dist/driver/applevz.js +527 -0
  36. package/dist/driver/applevz.js.map +1 -0
  37. package/dist/driver/container.d.ts +99 -0
  38. package/dist/driver/container.js +733 -0
  39. package/dist/driver/container.js.map +1 -0
  40. package/dist/driver/fc-api.d.ts +85 -0
  41. package/dist/driver/fc-api.js +173 -0
  42. package/dist/driver/fc-api.js.map +1 -0
  43. package/dist/driver/firecracker.d.ts +126 -0
  44. package/dist/driver/firecracker.js +560 -0
  45. package/dist/driver/firecracker.js.map +1 -0
  46. package/dist/driver/index.d.ts +17 -0
  47. package/dist/driver/index.js +61 -0
  48. package/dist/driver/index.js.map +1 -0
  49. package/dist/driver/router.d.ts +82 -0
  50. package/dist/driver/router.js +159 -0
  51. package/dist/driver/router.js.map +1 -0
  52. package/dist/driver/types.d.ts +234 -0
  53. package/dist/driver/types.js +2 -0
  54. package/dist/driver/types.js.map +1 -0
  55. package/dist/driver/unsupported.d.ts +50 -0
  56. package/dist/driver/unsupported.js +81 -0
  57. package/dist/driver/unsupported.js.map +1 -0
  58. package/dist/driver/vz-image.d.ts +35 -0
  59. package/dist/driver/vz-image.js +75 -0
  60. package/dist/driver/vz-image.js.map +1 -0
  61. package/dist/e2e-harness.d.ts +1 -0
  62. package/dist/e2e-harness.js +99 -0
  63. package/dist/e2e-harness.js.map +1 -0
  64. package/dist/egress-check.d.ts +8 -0
  65. package/dist/egress-check.js +317 -0
  66. package/dist/egress-check.js.map +1 -0
  67. package/dist/fc-check.d.ts +1 -0
  68. package/dist/fc-check.js +113 -0
  69. package/dist/fc-check.js.map +1 -0
  70. package/dist/index.d.ts +2 -0
  71. package/dist/index.js +114 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/kernels.d.ts +22 -0
  74. package/dist/kernels.js +134 -0
  75. package/dist/kernels.js.map +1 -0
  76. package/dist/lifecycle.d.ts +49 -0
  77. package/dist/lifecycle.js +111 -0
  78. package/dist/lifecycle.js.map +1 -0
  79. package/dist/logger.d.ts +16 -0
  80. package/dist/logger.js +67 -0
  81. package/dist/logger.js.map +1 -0
  82. package/dist/metrics.d.ts +46 -0
  83. package/dist/metrics.js +92 -0
  84. package/dist/metrics.js.map +1 -0
  85. package/dist/net/firewall.d.ts +4 -0
  86. package/dist/net/firewall.js +80 -0
  87. package/dist/net/firewall.js.map +1 -0
  88. package/dist/pricing.d.ts +36 -0
  89. package/dist/pricing.js +81 -0
  90. package/dist/pricing.js.map +1 -0
  91. package/dist/proxy/allowlist-default.d.ts +23 -0
  92. package/dist/proxy/allowlist-default.js +53 -0
  93. package/dist/proxy/allowlist-default.js.map +1 -0
  94. package/dist/proxy/allowlist.d.ts +43 -0
  95. package/dist/proxy/allowlist.js +87 -0
  96. package/dist/proxy/allowlist.js.map +1 -0
  97. package/dist/proxy/egress.d.ts +49 -0
  98. package/dist/proxy/egress.js +599 -0
  99. package/dist/proxy/egress.js.map +1 -0
  100. package/dist/proxy/ratelimit.d.ts +49 -0
  101. package/dist/proxy/ratelimit.js +74 -0
  102. package/dist/proxy/ratelimit.js.map +1 -0
  103. package/dist/proxy/server.d.ts +26 -0
  104. package/dist/proxy/server.js +202 -0
  105. package/dist/proxy/server.js.map +1 -0
  106. package/dist/router-check.d.ts +1 -0
  107. package/dist/router-check.js +97 -0
  108. package/dist/router-check.js.map +1 -0
  109. package/dist/smoke-fc.d.ts +1 -0
  110. package/dist/smoke-fc.js +183 -0
  111. package/dist/smoke-fc.js.map +1 -0
  112. package/dist/smoke-microvm.d.ts +1 -0
  113. package/dist/smoke-microvm.js +187 -0
  114. package/dist/smoke-microvm.js.map +1 -0
  115. package/dist/smoke-remote.d.ts +20 -0
  116. package/dist/smoke-remote.js +155 -0
  117. package/dist/smoke-remote.js.map +1 -0
  118. package/dist/smoke-vz.d.ts +1 -0
  119. package/dist/smoke-vz.js +161 -0
  120. package/dist/smoke-vz.js.map +1 -0
  121. package/dist/smoke.d.ts +7 -0
  122. package/dist/smoke.js +962 -0
  123. package/dist/smoke.js.map +1 -0
  124. package/dist/store.d.ts +124 -0
  125. package/dist/store.js +578 -0
  126. package/dist/store.js.map +1 -0
  127. package/dist/tracing.d.ts +45 -0
  128. package/dist/tracing.js +144 -0
  129. package/dist/tracing.js.map +1 -0
  130. package/dist/types.d.ts +274 -0
  131. package/dist/types.js +3 -0
  132. package/dist/types.js.map +1 -0
  133. package/dist/util.d.ts +27 -0
  134. package/dist/util.js +63 -0
  135. package/dist/util.js.map +1 -0
  136. package/dist/warmpool-check.d.ts +1 -0
  137. package/dist/warmpool-check.js +83 -0
  138. package/dist/warmpool-check.js.map +1 -0
  139. package/dist/web/dashboard.d.ts +1 -0
  140. package/dist/web/dashboard.js +456 -0
  141. package/dist/web/dashboard.js.map +1 -0
  142. package/package.json +53 -0
@@ -0,0 +1,99 @@
1
+ import Docker from "dockerode";
2
+ import type { ExecEvent, ExecOptions, FileChangeEvent, FileInfo, ListFilesOptions, MkdirOptions, ReadFileOptions, StartProcessOptions, WaitForPortOptions, WatchOptions, WriteFileOptions } from "../types.js";
3
+ import type { CreateOptions, Driver, ProcessLiveness, HostInfo, SandboxStats, StartProcessResult, TcpBridge, TerminalOptions, TerminalSession } from "./types.js";
4
+ /**
5
+ * Container driver — backs each sandbox with a long-lived OCI container via the
6
+ * Docker Engine API. Maximum density and works identically on Linux and macOS
7
+ * (Docker Desktop / colima / Apple `container`'s Docker-compatible endpoint).
8
+ *
9
+ * The container is named deterministically from the sandbox id and kept alive
10
+ * (`sleep infinity` / image default) so the daemon can `exec` into it on demand
11
+ * — the same model Docker exec gives us for free in Phase 0, standing in for the
12
+ * dedicated in-sandbox agent that the microVM drivers will need.
13
+ */
14
+ /** Egress-enforcement network settings, passed in from config by the driver factory. */
15
+ export interface EgressNetConfig {
16
+ enforce: boolean;
17
+ network: string;
18
+ subnet: string;
19
+ /** Pinned DNS resolver IP, or "" for Docker's embedded resolver. */
20
+ dns: string;
21
+ }
22
+ export declare class ContainerDriver implements Driver {
23
+ readonly name = "container";
24
+ private docker;
25
+ private ensured;
26
+ private egress?;
27
+ private egressNetReady;
28
+ constructor(docker?: Docker, egress?: EgressNetConfig);
29
+ private containerName;
30
+ /** Deterministic name for the sandbox's persistent workspace volume. */
31
+ private volumeName;
32
+ ping(): Promise<void>;
33
+ hostInfo(): Promise<HostInfo>;
34
+ /**
35
+ * Create the egress-enforcement bridge network if missing (idempotent). Uses the
36
+ * configured subnet so the host firewall's `-s <subnet>` rules match, with the
37
+ * gateway pinned to `.1`. Safe to call repeatedly; a 409 (already exists) is fine.
38
+ */
39
+ private ensureEgressNetwork;
40
+ /** Create the workspace volume if it does not already exist (idempotent). */
41
+ private ensureVolume;
42
+ /** Pull the image if it is not already present locally. */
43
+ private ensureImage;
44
+ create(opts: CreateOptions): Promise<void>;
45
+ /**
46
+ * Clone a git repo into `/workspace` at create time so an agent comes up with
47
+ * the code in place. Installs git first if the image lacks it (the default
48
+ * slim image), then shallow-clones into a subdir named after the repo. A
49
+ * failure throws — unlike best-effort `setup`, the agent needs the code.
50
+ */
51
+ private cloneRepo;
52
+ /**
53
+ * Run declarative setup commands in order, once, after the container starts.
54
+ * Best-effort: a non-zero exit is logged but does not fail create. Kept out of
55
+ * `launchContainer` on purpose so it does not re-fire on `start()`/resume.
56
+ */
57
+ private runSetup;
58
+ start(opts: CreateOptions): Promise<void>;
59
+ stop(id: string): Promise<void>;
60
+ /** Shared create/start path: ensure image (+volume), then run the container. */
61
+ private launchContainer;
62
+ exec(id: string, command: string, opts: ExecOptions, onEvent: (e: ExecEvent) => void): Promise<number>;
63
+ /**
64
+ * Run a non-interactive command and capture its streams + exit code. Never
65
+ * throws on a non-zero exit — callers decide what a failure means.
66
+ */
67
+ private execCapture;
68
+ /**
69
+ * Run a non-interactive command and return its stdout as a UTF-8 string.
70
+ * Throws if the command exits non-zero.
71
+ */
72
+ private runAndCapture;
73
+ writeFile(id: string, opts: WriteFileOptions): Promise<void>;
74
+ readFile(id: string, opts: ReadFileOptions): Promise<string>;
75
+ mkdir(id: string, opts: MkdirOptions): Promise<void>;
76
+ listFiles(id: string, opts: ListFilesOptions): Promise<FileInfo[]>;
77
+ watchFiles(id: string, path: string, opts: WatchOptions & {
78
+ signal: AbortSignal;
79
+ }, onEvent: (e: FileChangeEvent) => void): Promise<void>;
80
+ startProcess(id: string, procId: string, command: string, opts: StartProcessOptions): Promise<StartProcessResult>;
81
+ listProcesses(id: string, procs: Array<{
82
+ procId: string;
83
+ pid: number;
84
+ }>): Promise<ProcessLiveness[]>;
85
+ killProcess(id: string, pid: number, signal?: string): Promise<void>;
86
+ streamProcessLogs(id: string, logPath: string, opts: {
87
+ follow: boolean;
88
+ signal: AbortSignal;
89
+ }, onData: (chunk: string) => void): Promise<void>;
90
+ waitForPort(id: string, port: number, opts: WaitForPortOptions): Promise<boolean>;
91
+ openTcpBridge(id: string, port: number, host: string): Promise<TcpBridge>;
92
+ openTerminal(id: string, opts: TerminalOptions): Promise<TerminalSession>;
93
+ createBackup(id: string, tarPath: string): Promise<{
94
+ bytes: number;
95
+ }>;
96
+ restoreBackup(id: string, tarPath: string): Promise<void>;
97
+ stats(id: string): Promise<SandboxStats>;
98
+ destroy(id: string): Promise<void>;
99
+ }