@capybara-hq/plugin-sdk 0.1.0-rc.75 → 0.1.0-rc.76

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.
@@ -315,7 +315,20 @@ export interface DeviceServiceStatus {
315
315
  * `node <codeDir ?? stateDir>/<entry>`, so a provider runs exactly that.
316
316
  */
317
317
  codeDir?: string;
318
+ /**
319
+ * The {@link deviceServiceFilesDigest} of the files the running process was started from, when
320
+ * the provider knows it (absent when stopped). The kernel compares it with the spec's files: a
321
+ * running service on other files (an upgraded extension) gets a reviewed start, which restarts
322
+ * it on the new files.
323
+ */
324
+ filesDigest?: string;
318
325
  }
326
+ /**
327
+ * The digest of a service's files: `sha256:` and the hex SHA-256 over each file in path order
328
+ * (path, NUL, byte length, NUL, bytes). Providers report it in {@link DeviceServiceStatus} and
329
+ * may send it to a machine instead of the files.
330
+ */
331
+ export declare function deviceServiceFilesDigest(files: Record<string, Uint8Array>): string;
319
332
  /**
320
333
  * A message stream to a device service ({@link DeviceProvider.openStream},
321
334
  * `DialInChannel.openStream`): whole messages both ways, flow-controlled by credit.
@@ -644,8 +657,9 @@ export interface DeviceProvider {
644
657
  * `<extension>.<name>`, {@link DEVICE_SERVICE_ID_RE}), never by the extension's bare name.
645
658
  * It writes `spec.files` into the service's code directory, then runs `spec.entry` with Node, the
646
659
  * service socket and state directory named in its environment (`DEVICE_SERVICE_SOCKET_ENV`,
647
- * `DEVICE_SERVICE_STATE_ENV`). A service already running under the name is kept as is. The
648
- * kernel has passed the launch through the command review before it calls this.
660
+ * `DEVICE_SERVICE_STATE_ENV`). A service already running under the name is kept as is, unless
661
+ * it runs other files than the spec's: then it is stopped and started on them. The kernel has
662
+ * passed the launch through the command review before it calls this.
649
663
  *
650
664
  * With `opts.ifRunning` it never starts anything and reads only `spec.name` (the kernel sends
651
665
  * `{ name, runtime: "node", entry: "", args: [], files: {} }`, which must not be refused): a
@@ -653,7 +667,8 @@ export interface DeviceProvider {
653
667
  * a restart for that runs the spec it was launched with and its stored code (the kernel calls
654
668
  * this after the device's allowlist changed, and before reviewing a launch); a stopped one
655
669
  * answers its `stopped` status (with `stateDir`, and `codeDir` where kept apart) and stays
656
- * stopped.
670
+ * stopped. A running one answers its `filesDigest` when known, so the kernel reviews a start on
671
+ * new files before calling this without `ifRunning`.
657
672
  */
658
673
  ensureService?(h: SandboxHandle, spec: DeviceServiceSpec, signal: AbortSignal, opts?: {
659
674
  ifRunning?: boolean;
@@ -8,6 +8,7 @@
8
8
  * (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
9
9
  * (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
10
10
  */
11
+ import { createHash } from "node:crypto";
11
12
  /** Device provider extension point ref. */
12
13
  export const DEVICE_PROVIDER_EXTENSION_POINT = "device-provider@1";
13
14
  /** The roots inside the sandbox the model may access. */
@@ -214,6 +215,20 @@ export function deviceServiceId(extension, name) {
214
215
  throw new TypeError(`Invalid device service ${JSON.stringify(name)} of extension ${JSON.stringify(extension)}`);
215
216
  return id;
216
217
  }
218
+ /**
219
+ * The digest of a service's files: `sha256:` and the hex SHA-256 over each file in path order
220
+ * (path, NUL, byte length, NUL, bytes). Providers report it in {@link DeviceServiceStatus} and
221
+ * may send it to a machine instead of the files.
222
+ */
223
+ export function deviceServiceFilesDigest(files) {
224
+ const h = createHash("sha256");
225
+ for (const path of Object.keys(files).sort()) {
226
+ const data = files[path];
227
+ h.update(`${path}\0${data.byteLength}\0`);
228
+ h.update(data);
229
+ }
230
+ return `sha256:${h.digest("hex")}`;
231
+ }
217
232
  // biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are exactly what must be blocked
218
233
  const CONTROL = /[\u0000-\u001f\u007f]/;
219
234
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.75";
1
+ export declare const SDK_VERSION = "0.1.0-rc.76";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.75";
1
+ export const SDK_VERSION = "0.1.0-rc.76";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.75",
3
+ "version": "0.1.0-rc.76",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {