@field/cascade 0.3.1 → 0.4.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 (74) hide show
  1. package/AGENTS.md +14 -9
  2. package/ARCHITECTURE.md +22 -6
  3. package/CHANGELOG.md +51 -1
  4. package/CONTRIBUTING.md +71 -0
  5. package/DESIGN.md +19 -13
  6. package/README.md +42 -11
  7. package/dist/assets/{CodeEditor-D22fVi-4.js → CodeEditor-BNOJIDzL.js} +4 -4
  8. package/dist/assets/{CodePanel-DPNEYfcR.js → CodePanel-2wp2G0Fj.js} +2 -2
  9. package/dist/assets/{CustomNodeDialog-DeHCAvgb.js → CustomNodeDialog-DNqaVBqA.js} +1 -1
  10. package/dist/assets/{ProjectSettings-DWpVtWEx.js → ProjectSettings-DcdYF2E1.js} +1 -1
  11. package/dist/assets/{SettingsDialog-za00IS3L.js → SettingsDialog-D2xVvyiR.js} +1 -1
  12. package/dist/assets/{VersionHistoryDialog-DTMGhI0_.js → VersionHistoryDialog-DW288ykF.js} +1 -1
  13. package/dist/assets/{core-JsyKMO1k.js → core-B1y38i95.js} +1 -1
  14. package/dist/assets/{cssMode-emdRheFK.js → cssMode-BLucnaln.js} +1 -1
  15. package/dist/assets/{editor.api-xHX-fMSo.js → editor.api-B3Et3Pph.js} +1 -1
  16. package/dist/assets/{freemarker2-C3M8_Gs3.js → freemarker2-DVlPoano.js} +1 -1
  17. package/dist/assets/geo-DhyFdBXX.js +1 -0
  18. package/dist/assets/{handlebars-CBMurtFk.js → handlebars-B5FZBAMR.js} +1 -1
  19. package/dist/assets/{html-xbLQwknw.js → html-FodD8KbR.js} +1 -1
  20. package/dist/assets/{htmlMode-2wKdDTon.js → htmlMode-CsG57VCD.js} +1 -1
  21. package/dist/assets/{image-i1j6nWKe.js → image-B3F-nq25.js} +1 -1
  22. package/dist/assets/index-CC6YQw2n.js +212 -0
  23. package/dist/assets/index-Y2ock1cw.css +1 -0
  24. package/dist/assets/{javascript-DJaOo_2I.js → javascript-B3gonF_H.js} +1 -1
  25. package/dist/assets/{jsonMode-Bheas8_0.js → jsonMode-Y3w1ahZg.js} +1 -1
  26. package/dist/assets/{liquid-BCj_BGbM.js → liquid-CTpWXIYO.js} +1 -1
  27. package/dist/assets/{lspLanguageFeatures-BfIsx_xz.js → lspLanguageFeatures-CODBdKEZ.js} +1 -1
  28. package/dist/assets/{mdx-DwiQDiVO.js → mdx-CDAQJZIz.js} +1 -1
  29. package/dist/assets/{python-BjrB5nqj.js → python-LOIlxJU-.js} +1 -1
  30. package/dist/assets/{razor-CfoBmGDs.js → razor-CllPQSHo.js} +1 -1
  31. package/dist/assets/{tsMode-BcEoMSxp.js → tsMode-CO28ut8t.js} +1 -1
  32. package/dist/assets/{typescript-DIg7TEmQ.js → typescript-ruU9wKQ_.js} +1 -1
  33. package/dist/assets/{workers-vXYuwtPw.js → workers-Bc1Ywp4-.js} +1 -1
  34. package/dist/assets/{xml-DexLQIQy.js → xml-DoXP2Dh1.js} +1 -1
  35. package/dist/assets/{yaml-DUnD_1dE.js → yaml-D9YPyGiJ.js} +1 -1
  36. package/dist/cli/index.js +999 -185
  37. package/dist/cli/runtime/gpu.ts +71 -0
  38. package/dist/contracts/camera.d.ts +70 -0
  39. package/dist/contracts/camera.js +27 -0
  40. package/dist/contracts/capabilities.d.ts +6 -6
  41. package/dist/contracts/definition.d.ts +41 -2
  42. package/dist/contracts/index.d.ts +2 -0
  43. package/dist/contracts/index.js +2 -0
  44. package/dist/contracts/schema.js +25 -2
  45. package/dist/contracts/series.d.ts +75 -0
  46. package/dist/contracts/series.js +2 -0
  47. package/dist/contracts/validate.js +19 -3
  48. package/dist/contracts/values.d.ts +3 -2
  49. package/dist/contracts/values.js +1 -0
  50. package/dist/gpu.d.ts +17 -0
  51. package/dist/gpu.js +61 -1
  52. package/dist/index.html +2 -2
  53. package/dist/runtime/builtins/core/camera.d.ts +252 -0
  54. package/dist/runtime/builtins/core/camera.js +149 -0
  55. package/dist/runtime/builtins/core/index.d.ts +2 -1
  56. package/dist/runtime/builtins/core/index.js +3 -1
  57. package/dist/runtime/camera/index.d.ts +60 -0
  58. package/dist/runtime/camera/index.js +234 -0
  59. package/dist/runtime/definition/architecture.js +36 -1
  60. package/dist/runtime/gpu.d.ts +33 -0
  61. package/dist/runtime/gpu.js +218 -0
  62. package/dist/runtime/index.d.ts +3 -0
  63. package/dist/runtime/index.js +3 -0
  64. package/dist/runtime/runtime.js +63 -6
  65. package/dist/runtime/series/index.d.ts +41 -0
  66. package/dist/runtime/series/index.js +167 -0
  67. package/dist/runtime/types.d.ts +1 -1
  68. package/doc/HEADLESS_GPU.md +160 -0
  69. package/doc/NODE_REFERENCE.md +36 -0
  70. package/doc/PROJECT_AUTHORING.md +106 -20
  71. package/package.json +10 -2
  72. package/dist/assets/geo-BAR6lQp5.js +0 -1
  73. package/dist/assets/index-BDV5xGBZ.css +0 -1
  74. package/dist/assets/index-CMcH8AgP.js +0 -212
@@ -74,3 +74,74 @@ export const ColorWrite = {
74
74
  ALPHA: 0x8,
75
75
  ALL: 0xf,
76
76
  } as const;
77
+
78
+ /** Read one single-sample rgba8unorm 2D texture into owned, tightly packed
79
+ * top-left RGBA bytes. No colour conversion, PNG encoding or graph transport.
80
+ * The caller owns the source texture and must give it COPY_SRC usage.
81
+ */
82
+ export async function readTexture(
83
+ device: GPUDevice,
84
+ texture: GPUTexture,
85
+ options: { signal?: {
86
+ readonly aborted: boolean;
87
+ addEventListener(type: 'abort', listener: () => void, options?: { once?: boolean }): void;
88
+ removeEventListener(type: 'abort', listener: () => void): void;
89
+ } } = {},
90
+ ): Promise<{ data: Uint8Array<ArrayBuffer>; width: number; height: number }> {
91
+ const { signal } = options;
92
+ if (signal?.aborted) throw new Error('GPU readback aborted');
93
+ if (texture.format !== 'rgba8unorm' || texture.dimension !== '2d'
94
+ || texture.depthOrArrayLayers !== 1 || texture.sampleCount !== 1
95
+ || !(texture.usage & TextureUsage.COPY_SRC)) {
96
+ throw new Error('GPU readback requires a single-sample rgba8unorm 2D texture with COPY_SRC usage');
97
+ }
98
+ const { width, height } = texture;
99
+ const rowBytes = width * 4;
100
+ const bytesPerRow = Math.ceil(rowBytes / 256) * 256;
101
+ let buffer: GPUBuffer | undefined;
102
+ let mapped = false;
103
+ let abort: (() => void) | undefined;
104
+ let errorScopeOpen = false;
105
+ try {
106
+ device.pushErrorScope('validation');
107
+ errorScopeOpen = true;
108
+ buffer = device.createBuffer({
109
+ label: 'Cascade RGBA readback', size: bytesPerRow * height,
110
+ usage: BufferUsage.COPY_DST | BufferUsage.MAP_READ,
111
+ });
112
+ const encoder = device.createCommandEncoder();
113
+ encoder.copyTextureToBuffer({ texture }, { buffer, bytesPerRow }, [width, height]);
114
+ device.queue.submit([encoder.finish()]);
115
+ const validation = device.popErrorScope();
116
+ errorScopeOpen = false;
117
+ const completion = Promise.allSettled([buffer.mapAsync(MapMode.READ), validation]);
118
+ let completed: Awaited<typeof completion>;
119
+ if (signal) {
120
+ completed = await Promise.race([completion, new Promise<never>((_, reject) => {
121
+ abort = () => reject(new Error('GPU readback aborted'));
122
+ signal.addEventListener('abort', abort, { once: true });
123
+ if (signal.aborted) abort();
124
+ })]);
125
+ } else completed = await completion;
126
+ const mappingResult = completed[0];
127
+ const validationResult = completed[1];
128
+ if (validationResult.status === 'rejected') throw validationResult.reason;
129
+ const validationError = validationResult.value;
130
+ if (validationError) throw new Error(`GPU readback validation failed: ${validationError.message}`);
131
+ if (mappingResult.status === 'rejected') throw mappingResult.reason;
132
+ mapped = true;
133
+ if (signal?.aborted) throw new Error('GPU readback aborted');
134
+ const source = new Uint8Array(buffer.getMappedRange());
135
+ const data = new Uint8Array(rowBytes * height);
136
+ for (let y = 0; y < height; y++) data.set(source.subarray(y * bytesPerRow, y * bytesPerRow + rowBytes), y * rowBytes);
137
+ return { data, width, height };
138
+ } finally {
139
+ if (abort) signal?.removeEventListener('abort', abort);
140
+ if (errorScopeOpen) {
141
+ try { await device.popErrorScope(); }
142
+ catch { /* Preserve the operation's original failure. */ }
143
+ }
144
+ if (mapped) buffer?.unmap();
145
+ buffer?.destroy();
146
+ }
147
+ }
@@ -0,0 +1,70 @@
1
+ import type { Vec2i, Vec3 } from "./values.js";
2
+ /**
3
+ * A camera, following Houdini's `/obj/cam`.
4
+ *
5
+ * `AGENTS.md` already required following Houdini's parameter names where
6
+ * Houdini has an equivalent node, and Marcus restated it for this type
7
+ * specifically on 2026-09-08. It is worth writing down what that costs, because
8
+ * the obvious design is not the Houdini one and it was proposed first here:
9
+ *
10
+ * **There is no field of view.** Houdini has `focal` (a focal length in
11
+ * millimetres) and `aperture` (the horizontal aperture, also in millimetres),
12
+ * and the angle is derived from the two. The defaults — 50 mm on a 41.4214 mm
13
+ * aperture — are a 45° horizontal field of view, which is where that odd
14
+ * aperture number comes from. Carrying an `fov` instead would be one number
15
+ * rather than two, and it would also make every lens value a photographer knows
16
+ * untypeable.
17
+ *
18
+ * **The orientation is `translate` and `rotate`, not eye-and-target.** A
19
+ * Houdini camera is an object with an ordinary transform, looking down its own
20
+ * **-Z** with **+Y** up, and look-at is a second mechanism layered on top
21
+ * (`lookatpath` and `upvector`) rather than the primitive. So `lookat` and `up`
22
+ * are here as the optional override they are in Houdini, and `rotate` is what
23
+ * the type actually carries.
24
+ *
25
+ * **Rotation is degrees, XYZ order** — Houdini's convention, and already the
26
+ * one `cascade.geo.Transform` uses for its own `rotate`. Note that this is
27
+ * deliberately unlike expressions, where bare trigonometry is radians; that
28
+ * divergence is recorded in `AGENTS.md` and is not new here.
29
+ *
30
+ * The one place this departs from Houdini's names is **`resolution` in place of
31
+ * `resx` and `resy`**, because the vault's more specific rule wins: anything
32
+ * with an x and a y is one `vec2`, and resolutions are named in that rule
33
+ * explicitly. Two floats that are really one vector cost two Inspector rows and
34
+ * two keyframes and let a graph carry a width without its height.
35
+ *
36
+ * Resolution belongs to the camera rather than to the render target for a
37
+ * Houdini reason that is easy to miss: the **vertical** aperture is not stored,
38
+ * it is derived from the horizontal one and the resolution ratio. So the frame
39
+ * shape participates in the projection, and a camera that did not know it could
40
+ * not produce a vertical angle at all.
41
+ */
42
+ export interface Camera {
43
+ /** World position. Houdini `t`. */
44
+ readonly translate: Vec3;
45
+ /** Degrees, XYZ order. Houdini `r`. The camera looks down its own -Z. */
46
+ readonly rotate: Vec3;
47
+ /** Focal length in millimetres. Houdini `focal`, default 50. */
48
+ readonly focal: number;
49
+ /** Horizontal aperture in millimetres. Houdini `aperture`, default 41.4214. */
50
+ readonly aperture: number;
51
+ /** Near clipping plane. Houdini `near`, default 0.001. */
52
+ readonly near: number;
53
+ /** Far clipping plane. Houdini `far`, default 10000. */
54
+ readonly far: number;
55
+ /** Frame size in pixels. Houdini `resx`/`resy` as one `vec2i`. */
56
+ readonly resolution: Vec2i;
57
+ /** PIXEL aspect ratio, not the frame's. Houdini `aspect`, default 1. */
58
+ readonly aspect: number;
59
+ /** Houdini `projection`. */
60
+ readonly projection: "perspective" | "orthographic";
61
+ /** Width of the orthographic frame in world units. Houdini `orthowidth`. */
62
+ readonly orthowidth: number;
63
+ }
64
+ /** Houdini's own defaults, so a camera with nothing set matches a fresh
65
+ * `/obj/cam` rather than something invented here. */
66
+ export declare const CAMERA_DEFAULTS: Camera;
67
+ /** True for any object carrying the fields this type is identified by. Used at
68
+ * the document boundary, where a value arrives as parsed JSON. */
69
+ export declare function isCamera(value: unknown): value is Camera;
70
+ //# sourceMappingURL=camera.d.ts.map
@@ -0,0 +1,27 @@
1
+ /** Houdini's own defaults, so a camera with nothing set matches a fresh
2
+ * `/obj/cam` rather than something invented here. */
3
+ export const CAMERA_DEFAULTS = Object.freeze({
4
+ translate: [0, 0, 0],
5
+ rotate: [0, 0, 0],
6
+ focal: 50,
7
+ aperture: 41.4214,
8
+ near: 0.001,
9
+ far: 10000,
10
+ resolution: [1280, 720],
11
+ aspect: 1,
12
+ projection: "perspective",
13
+ orthowidth: 2,
14
+ });
15
+ /** True for any object carrying the fields this type is identified by. Used at
16
+ * the document boundary, where a value arrives as parsed JSON. */
17
+ export function isCamera(value) {
18
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
19
+ return false;
20
+ }
21
+ const candidate = value;
22
+ return (Array.isArray(candidate.translate) &&
23
+ Array.isArray(candidate.rotate) &&
24
+ typeof candidate.focal === "number" &&
25
+ typeof candidate.aperture === "number");
26
+ }
27
+ //# sourceMappingURL=camera.js.map
@@ -77,13 +77,13 @@ export interface PythonCapability {
77
77
  * anything a graph author would recognise. So a shared device is not a
78
78
  * preference, it is the precondition for a chain of GPU nodes at all.
79
79
  *
80
- * **Stage 0 deliberately carries three members and no textures.** Ports still
81
- * pass `image`, so every picture is byte-identical to before; what this buys is
80
+ * **The capability carries a device/cache contract, not graph textures.** Ports
81
+ * still pass `image`; what this buys is
82
82
  * one device instead of one per node module, an owner for `device.lost`, and
83
83
  * somewhere legitimate to keep a pipeline — which is what lets the
84
84
  * `architecture/ambient-state` rule stay strict. The texture store, the
85
- * generation-stamped handles and the readback are Stage 1, and the shape of
86
- * this interface is meant to be lived with for a few days first.
85
+ * generation-stamped handles remain future work. Explicit RGBA8 readback is a
86
+ * helper in `cascade/gpu`, shared by browser and native hosts without encoding.
87
87
  *
88
88
  * The `GPUDevice` type comes from `@webgpu/types`, added to this package's
89
89
  * `tsconfig.json` as its only `types` entry. Contracts compiles with
@@ -102,7 +102,7 @@ export interface PythonCapability {
102
102
  */
103
103
  export interface GpuCapability {
104
104
  /**
105
- * The one device for this page. Shared by every node declaring `gpu`, which
105
+ * The one device for this host. Shared by every node declaring `gpu`, which
106
106
  * is the whole point — see the note above on why two would be useless.
107
107
  */
108
108
  readonly device: GPUDevice;
@@ -128,7 +128,7 @@ export interface GpuCapability {
128
128
  * right answer again.
129
129
  *
130
130
  * `create` runs once per key. `destroy` is called when the entry is dropped:
131
- * when the device is lost, or when the graph disposes. This is the member
131
+ * when the device is lost, or when the owning host disposes. This is the member
132
132
  * that makes `architecture/module-state` keepable — it was previously
133
133
  * forbidding the only available way to hold a pipeline.
134
134
  */
@@ -1,7 +1,7 @@
1
1
  import type { CapabilityMap, CascadeAbortSignal, NodeCapabilityName, ProgressReporter } from "./capabilities.js";
2
2
  import type { CascadeType, CoreType, JsonValue, NamespacedType, SerializableValueForType, ValueForType } from "./values.js";
3
3
  export type RuntimeEnvironment = "portable" | "browser" | "server";
4
- export type CapabilityForEnvironment<E extends RuntimeEnvironment> = E extends "portable" ? "assets" | "media" : E extends "browser" ? "assets" | "media" | "gpu" : "files" | "assets" | "media" | "python" | "shell";
4
+ export type CapabilityForEnvironment<E extends RuntimeEnvironment> = E extends "portable" ? "assets" | "media" | "gpu" : E extends "browser" ? "assets" | "media" | "gpu" : "files" | "assets" | "media" | "python" | "shell" | "gpu";
5
5
  export type DataTypeForEnvironment<E extends RuntimeEnvironment> = E extends "browser" ? CascadeType : Exclude<CascadeType, "texture">;
6
6
  type ControlFor<T extends CascadeType> = T extends "float" ? "number" | "slider" | "range" : T extends "int" ? "int" | "slider" | "range" : T extends "bool" ? "boolean" : T extends "string" ? "text" | "textarea" | "select" : T extends "vec2" | "vec3" | "vec4" | "vec2i" | "vec3i" | "vec4i" ? "vector" : T extends "mat2" | "mat3" | "mat4" ? "matrix" : T extends "color" ? "color" : T extends "image" ? "image" : T extends "asset" ? "asset" | "select" : T extends "texture" ? never : "select";
7
7
  /**
@@ -41,12 +41,34 @@ type AcceptMetadata<T extends CascadeType> = T extends "image" | "asset" ? {
41
41
  } : {
42
42
  readonly accept?: never;
43
43
  };
44
+ /**
45
+ * One choice on a select control: the bare value, or the value with the words
46
+ * a person reads.
47
+ *
48
+ * The labelled form exists because losing it cost something real. Converting
49
+ * `image-superres` turned *"Off (pass through) / Local — Real-ESRGAN /
50
+ * Magnific — costs money"* into `off` / `local` / `magnific`, and that third
51
+ * label carried **the only warning that one of the three engines spends money
52
+ * per call**. A lost display name is a papercut; a lost cost warning is a
53
+ * bill. Six props across the sketches had lost their labels by the time this
54
+ * landed, and that one is why it was not deferred any longer.
55
+ *
56
+ * A bare value stays legal, and reads as "the value is the label" — which is
57
+ * true of most enums and is what every existing definition means.
58
+ */
59
+ export type SelectOption<T extends CascadeType> = SerializableValueForType<T> | Readonly<{
60
+ value: SerializableValueForType<T>;
61
+ label: string;
62
+ /** Greyed out but visible: an option that exists and cannot be picked
63
+ * here, which is more informative than one that is simply absent. */
64
+ disabled?: boolean;
65
+ }>;
44
66
  type SelectMetadata<T extends CascadeType> = {
45
67
  readonly control?: Exclude<ControlFor<T>, "select">;
46
68
  readonly options?: never;
47
69
  } | {
48
70
  readonly control: Extract<ControlFor<T>, "select">;
49
- readonly options?: readonly SerializableValueForType<T>[];
71
+ readonly options?: readonly SelectOption<T>[];
50
72
  };
51
73
  export interface TriggerInputDefinition {
52
74
  readonly kind: "trigger";
@@ -100,6 +122,23 @@ export type PropDefinition<T extends PropDataType> = {
100
122
  * number came from.
101
123
  */
102
124
  readonly expression?: string;
125
+ /**
126
+ * Render this prop as a button that fires a named action, rather than as an
127
+ * editable field.
128
+ *
129
+ * It exists because converting a node removed a button. `observatory-moment`
130
+ * declared `action: 'panel:observatory-moments'` as a dynamic node, which the
131
+ * Inspector renders from `parameter.options.action`; the v1 adapter built its
132
+ * options from `label`, `min`, `max`, `step` and `options` only, so the
133
+ * Moment picker quietly became a two-step job through the panel menu instead
134
+ * of one click on the node. Nothing broke — the panel falls back to the
135
+ * selected node and reads the same prop — which is exactly why nobody would
136
+ * have noticed from a test.
137
+ *
138
+ * The value is the action name the host dispatches. Cascade does not
139
+ * interpret it; a `panel:` prefix is a Studio convention, not a contract.
140
+ */
141
+ readonly action?: string;
103
142
  } & NumericMetadata<T> & AcceptMetadata<T> & SelectMetadata<T>;
104
143
  export type AnyPropDefinition = {
105
144
  [T in PropDataType]: PropDefinition<T>;
@@ -1,9 +1,11 @@
1
1
  export * from "./animation.js";
2
+ export * from "./camera.js";
2
3
  export * from "./capabilities.js";
3
4
  export * from "./color.js";
4
5
  export * from "./definition.js";
5
6
  export * from "./document.js";
6
7
  export * from "./geometry.js";
8
+ export * from "./series.js";
7
9
  export * from "./validate.js";
8
10
  export * from "./values.js";
9
11
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,11 @@
1
1
  export * from "./animation.js";
2
+ export * from "./camera.js";
2
3
  export * from "./capabilities.js";
3
4
  export * from "./color.js";
4
5
  export * from "./definition.js";
5
6
  export * from "./document.js";
6
7
  export * from "./geometry.js";
8
+ export * from "./series.js";
7
9
  export * from "./validate.js";
8
10
  export * from "./values.js";
9
11
  //# sourceMappingURL=index.js.map
@@ -36,7 +36,27 @@ const dataProperties = {
36
36
  step: { type: "number", exclusiveMinimum: 0 },
37
37
  accept: { type: "array", items: { type: "string", minLength: 1 } },
38
38
  control,
39
- options: { type: "array" },
39
+ // A bare value, or `{ value, label, disabled? }`. Both forms, because a
40
+ // bare value means "the value is its own label" and is what every
41
+ // definition written before the labelled form meant.
42
+ options: {
43
+ type: "array",
44
+ items: {
45
+ anyOf: [
46
+ { not: { type: "object" } },
47
+ {
48
+ type: "object",
49
+ properties: {
50
+ value: {},
51
+ label: { type: "string", minLength: 1 },
52
+ disabled: { type: "boolean" },
53
+ },
54
+ required: ["value", "label"],
55
+ additionalProperties: false,
56
+ },
57
+ ],
58
+ },
59
+ },
40
60
  };
41
61
  const data = object(dataProperties, ["kind", "type"]);
42
62
  const output = object({ kind: dataProperties.kind, type: dataProperties.type, description }, ["kind", "type"]);
@@ -47,6 +67,8 @@ const prop = object({
47
67
  // Props only, not inputs: an input's value comes from whatever is wired to
48
68
  // it, so a default expression there would be describing the wrong thing.
49
69
  expression: { type: "string", minLength: 1 },
70
+ // A button that fires a named host action instead of an editable field.
71
+ action: { type: "string", minLength: 1 },
50
72
  }, ["type", "default"]);
51
73
  function environmentCapabilities(runsOn, capabilities) {
52
74
  return {
@@ -74,7 +96,7 @@ export const nodeDefinitionSchema = {
74
96
  props: record(prop),
75
97
  }, ["apiVersion", "runsOn"]),
76
98
  allOf: [
77
- environmentCapabilities("portable", ["assets", "media"]),
99
+ environmentCapabilities("portable", ["assets", "media", "gpu"]),
78
100
  environmentCapabilities("browser", ["assets", "media", "gpu"]),
79
101
  environmentCapabilities("server", [
80
102
  "files",
@@ -82,6 +104,7 @@ export const nodeDefinitionSchema = {
82
104
  "media",
83
105
  "python",
84
106
  "shell",
107
+ "gpu",
85
108
  ]),
86
109
  ],
87
110
  };
@@ -0,0 +1,75 @@
1
+ import type { CascadePreset } from "./document.js";
2
+ /**
3
+ * A series: one system, many instances.
4
+ *
5
+ * **A series is a graph plus an ordered list of parameter sets, and nothing
6
+ * else.** Plan: `Work/Projects/Cascade/plans/PLAN series.md`. The definition is
7
+ * deliberately this thin, because the alternative is the trap the plan names —
8
+ * *the series must not become a second document format.* If it grows its own
9
+ * copy of node state it forks from the graph and the two disagree.
10
+ *
11
+ * So there is no boundary in it. Houdini marks a region because the varying
12
+ * thing flows through the region as geometry; here the varying thing is a
13
+ * sparse map of parameter overrides keyed by node id, so the affected subgraph
14
+ * is **derived** from those overrides by the dependency graph that already
15
+ * exists. Nothing is marked, so nothing can be marked wrongly. That is also
16
+ * why `Block Begin`/`Block End` are not copied: they exist to serve feedback,
17
+ * a series has none, and the form without the feedback is all cost.
18
+ */
19
+ export interface CascadeSeries {
20
+ readonly version: 1;
21
+ /**
22
+ * Ordered, and ordered on purpose.
23
+ *
24
+ * Independent instances do not need an order, which makes a bag tempting.
25
+ * But feedback — instance N reading N-1 — needs a sequence, and retrofitting
26
+ * order onto something built unordered is the expensive kind of change.
27
+ * Ordered costs nothing today. Marcus, 2026-09-08: *"feedback will at some
28
+ * point be useful but maybe not this series."*
29
+ */
30
+ readonly instances: readonly CascadeSeriesInstance[];
31
+ /** Which output the series collects, one value per instance. */
32
+ readonly collect: SeriesCollection;
33
+ }
34
+ export interface CascadeSeriesInstance {
35
+ /**
36
+ * **The record's own id, never its index in the array.**
37
+ *
38
+ * The decision the plan says to make before anything is built. A set reorders
39
+ * the moment a filter changes or data arrives, so a judgement pinned to a
40
+ * position — a favourite, an override, a note — silently becomes a different
41
+ * picture. For the Observatory this is the moment's id; for a wedge, the
42
+ * parameter tuple; for a hand-written list, whatever the author typed.
43
+ */
44
+ readonly id: string;
45
+ /** This instance's overrides. `CascadePreset` already is a parameter set. */
46
+ readonly parameters: CascadePreset;
47
+ /** For display. Never an address — see `id`. */
48
+ readonly label?: string;
49
+ }
50
+ /**
51
+ * Either a graph output by name, or any node's output port.
52
+ *
53
+ * Both, for the same reason subnets stay an ordinary tool rather than the
54
+ * mechanism: requiring a `cascade.core.Output` node would mean restructuring an
55
+ * existing graph before it could be a series, and `cloud-volumes` is exactly
56
+ * that case.
57
+ */
58
+ export type SeriesCollection = {
59
+ readonly graphOutput: string;
60
+ } | {
61
+ readonly nodeId: string;
62
+ readonly output: string;
63
+ };
64
+ /** One instance's result. `status` is the run's, so a failed instance is
65
+ * reported rather than dropped — a series that silently renders 9,998 of
66
+ * 10,000 is worse than one that says which two failed. */
67
+ export interface SeriesInstanceResult {
68
+ readonly id: string;
69
+ readonly index: number;
70
+ readonly status: "completed" | "cancelled" | "failed";
71
+ readonly value: unknown;
72
+ readonly diagnostics: readonly unknown[];
73
+ readonly durationMs: number;
74
+ }
75
+ //# sourceMappingURL=series.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=series.js.map
@@ -13,16 +13,16 @@ const CONTROLS = new Set(["number", "slider", "range", "int", "boolean", "text",
13
13
  * capability belongs to.
14
14
  */
15
15
  export const CAPABILITIES_BY_ENVIRONMENT = {
16
- portable: ["assets", "media"],
16
+ portable: ["assets", "media", "gpu"],
17
17
  browser: ["assets", "media", "gpu"],
18
- server: ["files", "assets", "media", "python", "shell"],
18
+ server: ["files", "assets", "media", "python", "shell", "gpu"],
19
19
  };
20
20
  const ALLOWED = CAPABILITIES_BY_ENVIRONMENT;
21
21
  const fields = (names) => new Set(names.split(" "));
22
22
  const TOP_FIELDS = fields("apiVersion runsOn container capabilities label description icon inputs outputs props");
23
23
  const DATA_FIELDS = fields("kind type default description variadic min max step accept control options");
24
24
  const OUTPUT_FIELDS = fields("kind type description");
25
- const PROP_FIELDS = fields("type default label description min max step accept control options expression");
25
+ const PROP_FIELDS = fields("type default label description min max step accept control options expression action");
26
26
  function diagnostic(code, message, path) {
27
27
  return { phase: "definition", code: `definition/${code}`, message, path };
28
28
  }
@@ -170,6 +170,22 @@ export function validateNodeDefinition(value) {
170
170
  add("invalid-control", `${String(raw.control)} is not a Cascade control`, `${path}.control`);
171
171
  if ("options" in raw && raw.control !== "select")
172
172
  add("options-without-select", "options require the select control", `${path}.options`);
173
+ // A labelled option is `{ value, label }`. Checked because the failure
174
+ // is cosmetic and silent: a malformed entry reaches the control and
175
+ // renders as "[object Object]" rather than erroring, and the labelled
176
+ // form exists precisely because a lost label lost a cost warning.
177
+ if (Array.isArray(raw.options))
178
+ for (const [index, option] of raw.options.entries()) {
179
+ if (option === null || typeof option !== "object")
180
+ continue;
181
+ const entry = option;
182
+ if (!("value" in entry))
183
+ add("invalid-option", "a labelled option needs a value", `${path}.options[${index}]`);
184
+ if (typeof entry.label !== "string" || !entry.label)
185
+ add("invalid-option", "a labelled option needs a non-empty label", `${path}.options[${index}].label`);
186
+ if ("disabled" in entry && typeof entry.disabled !== "boolean")
187
+ add("invalid-option", "disabled must be a boolean", `${path}.options[${index}].disabled`);
188
+ }
173
189
  const type = raw.type;
174
190
  if (!validType(type)) {
175
191
  add("invalid-type", `${String(type)} is not a Cascade type`, `${path}.type`);
@@ -1,6 +1,7 @@
1
+ import type { Camera } from "./camera.js";
1
2
  import type { Color } from "./color.js";
2
3
  import type { Geometry, GeometryFileRef, GeometryJson, GeometrySerialized } from "./geometry.js";
3
- export declare const CORE_TYPES: readonly ["float", "int", "bool", "string", "vec2", "vec3", "vec4", "vec2i", "vec3i", "vec4i", "mat2", "mat3", "mat4", "image", "texture", "geometry", "points", "lines", "polyline", "mesh", "rects", "color", "asset", "array", "object", "any"];
4
+ export declare const CORE_TYPES: readonly ["float", "int", "bool", "string", "vec2", "vec3", "vec4", "vec2i", "vec3i", "vec4i", "mat2", "mat3", "mat4", "image", "texture", "geometry", "points", "lines", "polyline", "mesh", "rects", "color", "camera", "asset", "array", "object", "any"];
4
5
  export type CoreType = (typeof CORE_TYPES)[number];
5
6
  export type NamespacedType = `${string}.${string}`;
6
7
  export type CascadeType = CoreType | NamespacedType;
@@ -94,7 +95,7 @@ export interface AssetRef {
94
95
  readonly mediaType?: string;
95
96
  }
96
97
  export type SerializableValue = JsonValue | AssetRef | ImageRef | GeometryJson | GeometryFileRef;
97
- export type ValueForType<T extends CascadeType> = T extends "float" | "int" ? number : T extends "bool" ? boolean : T extends "string" ? string : T extends "vec2" ? Vec2 : T extends "vec3" ? Vec3 : T extends "vec4" ? Vec4 : T extends "vec2i" ? Vec2i : T extends "vec3i" ? Vec3i : T extends "vec4i" ? Vec4i : T extends "mat2" ? Mat2 : T extends "mat3" ? Mat3 : T extends "mat4" ? Mat4 : T extends "color" ? Color : T extends "image" ? ImageRef : T extends "texture" ? TextureHandle : T extends "geometry" ? Geometry : T extends "points" ? PointSet : T extends "lines" ? LineSegments : T extends "polyline" ? Polyline : T extends "mesh" ? Mesh : T extends "rects" ? Rects : T extends "asset" ? AssetRef : T extends "array" ? readonly unknown[] : T extends "object" ? Readonly<Record<string, unknown>> : unknown;
98
+ export type ValueForType<T extends CascadeType> = T extends "float" | "int" ? number : T extends "bool" ? boolean : T extends "string" ? string : T extends "vec2" ? Vec2 : T extends "vec3" ? Vec3 : T extends "vec4" ? Vec4 : T extends "vec2i" ? Vec2i : T extends "vec3i" ? Vec3i : T extends "vec4i" ? Vec4i : T extends "mat2" ? Mat2 : T extends "mat3" ? Mat3 : T extends "mat4" ? Mat4 : T extends "color" ? Color : T extends "camera" ? Camera : T extends "image" ? ImageRef : T extends "texture" ? TextureHandle : T extends "geometry" ? Geometry : T extends "points" ? PointSet : T extends "lines" ? LineSegments : T extends "polyline" ? Polyline : T extends "mesh" ? Mesh : T extends "rects" ? Rects : T extends "asset" ? AssetRef : T extends "array" ? readonly unknown[] : T extends "object" ? Readonly<Record<string, unknown>> : unknown;
98
99
  export type SerializableValueForType<T extends CascadeType> = T extends "texture" ? never : T extends "geometry" ? GeometrySerialized : T extends "array" ? readonly JsonValue[] : T extends "object" ? Readonly<Record<string, JsonValue>> : T extends "any" | NamespacedType ? JsonValue : ValueForType<T>;
99
100
  export {};
100
101
  //# sourceMappingURL=values.d.ts.map
@@ -21,6 +21,7 @@ export const CORE_TYPES = [
21
21
  "mesh",
22
22
  "rects",
23
23
  "color",
24
+ "camera",
24
25
  "asset",
25
26
  "array",
26
27
  "object",
package/dist/gpu.d.ts CHANGED
@@ -69,3 +69,20 @@ export declare const ColorWrite: {
69
69
  readonly ALPHA: 8;
70
70
  readonly ALL: 15;
71
71
  };
72
+ /** Read one single-sample rgba8unorm 2D texture into owned, tightly packed
73
+ * top-left RGBA bytes. No colour conversion, PNG encoding or graph transport.
74
+ * The caller owns the source texture and must give it COPY_SRC usage.
75
+ */
76
+ export declare function readTexture(device: GPUDevice, texture: GPUTexture, options?: {
77
+ signal?: {
78
+ readonly aborted: boolean;
79
+ addEventListener(type: 'abort', listener: () => void, options?: {
80
+ once?: boolean;
81
+ }): void;
82
+ removeEventListener(type: 'abort', listener: () => void): void;
83
+ };
84
+ }): Promise<{
85
+ data: Uint8Array<ArrayBuffer>;
86
+ width: number;
87
+ height: number;
88
+ }>;
package/dist/gpu.js CHANGED
@@ -43,11 +43,71 @@ var ColorWrite = {
43
43
  ALPHA: 8,
44
44
  ALL: 15
45
45
  };
46
+ async function readTexture(device, texture, options = {}) {
47
+ const { signal } = options;
48
+ if (signal?.aborted) throw new Error("GPU readback aborted");
49
+ if (texture.format !== "rgba8unorm" || texture.dimension !== "2d" || texture.depthOrArrayLayers !== 1 || texture.sampleCount !== 1 || !(texture.usage & TextureUsage.COPY_SRC)) {
50
+ throw new Error("GPU readback requires a single-sample rgba8unorm 2D texture with COPY_SRC usage");
51
+ }
52
+ const { width, height } = texture;
53
+ const rowBytes = width * 4;
54
+ const bytesPerRow = Math.ceil(rowBytes / 256) * 256;
55
+ let buffer;
56
+ let mapped = false;
57
+ let abort;
58
+ let errorScopeOpen = false;
59
+ try {
60
+ device.pushErrorScope("validation");
61
+ errorScopeOpen = true;
62
+ buffer = device.createBuffer({
63
+ label: "Cascade RGBA readback",
64
+ size: bytesPerRow * height,
65
+ usage: BufferUsage.COPY_DST | BufferUsage.MAP_READ
66
+ });
67
+ const encoder = device.createCommandEncoder();
68
+ encoder.copyTextureToBuffer({ texture }, { buffer, bytesPerRow }, [width, height]);
69
+ device.queue.submit([encoder.finish()]);
70
+ const validation = device.popErrorScope();
71
+ errorScopeOpen = false;
72
+ const completion = Promise.allSettled([buffer.mapAsync(MapMode.READ), validation]);
73
+ let completed;
74
+ if (signal) {
75
+ completed = await Promise.race([completion, new Promise((_, reject) => {
76
+ abort = () => reject(new Error("GPU readback aborted"));
77
+ signal.addEventListener("abort", abort, { once: true });
78
+ if (signal.aborted) abort();
79
+ })]);
80
+ } else completed = await completion;
81
+ const mappingResult = completed[0];
82
+ const validationResult = completed[1];
83
+ if (validationResult.status === "rejected") throw validationResult.reason;
84
+ const validationError = validationResult.value;
85
+ if (validationError) throw new Error(`GPU readback validation failed: ${validationError.message}`);
86
+ if (mappingResult.status === "rejected") throw mappingResult.reason;
87
+ mapped = true;
88
+ if (signal?.aborted) throw new Error("GPU readback aborted");
89
+ const source = new Uint8Array(buffer.getMappedRange());
90
+ const data = new Uint8Array(rowBytes * height);
91
+ for (let y = 0; y < height; y++) data.set(source.subarray(y * bytesPerRow, y * bytesPerRow + rowBytes), y * rowBytes);
92
+ return { data, width, height };
93
+ } finally {
94
+ if (abort) signal?.removeEventListener("abort", abort);
95
+ if (errorScopeOpen) {
96
+ try {
97
+ await device.popErrorScope();
98
+ } catch {
99
+ }
100
+ }
101
+ if (mapped) buffer?.unmap();
102
+ buffer?.destroy();
103
+ }
104
+ }
46
105
  export {
47
106
  BufferUsage,
48
107
  ColorWrite,
49
108
  MapMode,
50
109
  ShaderStage,
51
- TextureUsage
110
+ TextureUsage,
111
+ readTexture
52
112
  };
53
113
  //# sourceMappingURL=gpu.js.map
package/dist/index.html CHANGED
@@ -4,11 +4,11 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Cascade</title>
7
- <script type="module" crossorigin src="/assets/index-CMcH8AgP.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-CC6YQw2n.js"></script>
8
8
  <link rel="modulepreload" crossorigin href="/assets/legacy-CAj2_7QE.js">
9
9
  <link rel="modulepreload" crossorigin href="/assets/index-client-BoJgsN9M.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/nodeTypeUtils-BBA1JqHx.js">
11
- <link rel="stylesheet" crossorigin href="/assets/index-BDV5xGBZ.css">
11
+ <link rel="stylesheet" crossorigin href="/assets/index-Y2ock1cw.css">
12
12
  </head>
13
13
  <body>
14
14
  <div id="app"></div>