@opencode/codemode 2.2.6 → 2.2.7

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.
@@ -19,8 +19,12 @@ export type Snapshot = {
19
19
  export type Header = {
20
20
  /** The build that wrote it: the package version, and a hash of the opcodes, the prelude's bytecode, codecs, and built-ins. */
21
21
  readonly build: string;
22
- /** A hash of the host's globals (extensions, a test harness), which the restoring runtime must have too. */
22
+ /**
23
+ * A hash of the host's globals (extensions, a test harness), and of each extension's name and whether it has
24
+ * `snapshot` hooks, which the restoring runtime must have too.
25
+ */
23
26
  readonly hosts: string;
27
+ readonly runId: string;
24
28
  /** The program texts, re-parsed and recompiled on restore, and checked against their hashes and bytecode hashes. */
25
29
  readonly sources: ReadonlyArray<{
26
30
  readonly id: string;
@@ -2,7 +2,10 @@ import { fromBytes, SnapshotError, toBytes } from "../../suspend-error.js";
2
2
  export { fromBytes, SnapshotError, toBytes };
3
3
  /** The snapshot format this build writes and reads: the bytecode VM's (see `src/vm/snapshot.ts`). */
4
4
  export const FORMAT = 2;
5
- export const hostsId = (ctx) => hash(ctx.intrinsics.hosts().join("\n"));
5
+ export const hostsId = (ctx) => hash([
6
+ ...ctx.intrinsics.hosts(),
7
+ ...(ctx.hosts?.extensions ?? []).map((extension) => `${extension.name} ${extension.hooked ? "hooks" : "no hooks"}`),
8
+ ].join("\n"));
6
9
  // --- Validation ---
7
10
  const fail = (message) => {
8
11
  throw new SnapshotError(`Invalid snapshot: ${message}`);
@@ -27,6 +30,7 @@ export const validate = (saved) => {
27
30
  const checked = {
28
31
  build: string(header.build, "the build"),
29
32
  hosts: string(header.hosts, "the host globals"),
33
+ runId: string(header.runId, "the run id"),
30
34
  sources: array(header.sources, "the sources").map((item) => {
31
35
  const source = object(item, "a source");
32
36
  return {
@@ -34,7 +34,7 @@ const vmSpecs = () => (specs ??= [
34
34
  name: "HostCalls",
35
35
  ctor: HostCalls,
36
36
  anchor: "hosts",
37
- fields: ["queued", "running", "inbox", "nextID", "blocked", "input"],
37
+ fields: ["runId", "queued", "running", "inbox", "nextID", "blocked", "input"],
38
38
  skip: ["ctx", "promises", "extension", "extensionResume"],
39
39
  },
40
40
  {
@@ -111,6 +111,7 @@ export const captureVm = (vm, options) => {
111
111
  },
112
112
  lost,
113
113
  strict: options.strict,
114
+ hosts: ctx.hosts,
114
115
  specs: vmSpecs(),
115
116
  external: (value) => {
116
117
  if (value === HOLE)
@@ -128,6 +129,7 @@ export const captureVm = (vm, options) => {
128
129
  header: {
129
130
  build: buildId(),
130
131
  hosts: hostsId(ctx),
132
+ runId: vm.hosts.runId,
131
133
  sources: programs.map((source) => ({
132
134
  id: source.id,
133
135
  code: source.code,
@@ -179,6 +181,7 @@ export const restoreVm = (vm, saved, options) => {
179
181
  anchor: (name) => anchors.get(name),
180
182
  node: (source, index) => sources.get(source)?.nodes[index],
181
183
  interruption: options.interruption,
184
+ hosts: ctx.hosts,
182
185
  specs: vmSpecs(),
183
186
  external: (data) => {
184
187
  if (data === "hole")
package/dist/vm/vm.d.ts CHANGED
@@ -119,6 +119,7 @@ export declare class Vm {
119
119
  * program value or its concurrent call is running: it holds live host values.
120
120
  */
121
121
  get activeExtension(): {
122
+ readonly key: string;
122
123
  readonly path: string;
123
124
  } | undefined;
124
125
  /** Saves the run's state as it is now. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/codemode",
4
- "version": "2.2.6",
4
+ "version": "2.2.7",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -18,8 +18,8 @@
18
18
  ],
19
19
  "exports": {
20
20
  ".": {
21
- "import": "./dist/index.js",
22
- "types": "./dist/index.d.ts"
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
23
  }
24
24
  },
25
25
  "scripts": {