@native-sdk/cli 0.9.0 → 0.9.2

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 (181) hide show
  1. package/build/app.zig +357 -33
  2. package/build.zig +234 -11
  3. package/native-sdk.d.ts +8 -0
  4. package/package.json +10 -10
  5. package/packages/core/compile-surface/core.ts +70 -1
  6. package/packages/core/package-lock.json +11 -11
  7. package/packages/core/package.json +2 -2
  8. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  9. package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
  10. package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
  11. package/packages/core/scripts/stage_external_services.mjs +1 -1
  12. package/packages/core/sdk/core.d.ts +75 -0
  13. package/packages/core/sdk/core.ts +170 -13
  14. package/packages/core/sdk/events.d.ts +53 -0
  15. package/packages/core/sdk/events.ts +78 -7
  16. package/packages/core/src/checker.ts +470 -2
  17. package/packages/core/src/cli.ts +13 -0
  18. package/packages/core/src/contract.ts +3 -1
  19. package/packages/core/src/devhost.ts +30 -1
  20. package/packages/core/src/devhost_journal.mjs +10 -8
  21. package/packages/core/src/diagnostics.ts +99 -8
  22. package/packages/core/src/frontend.ts +6 -0
  23. package/packages/core/src/infer.ts +24 -0
  24. package/skill-data/automation/SKILL.md +1 -1
  25. package/skill-data/native-ui/SKILL.md +18 -12
  26. package/skill-data/ts-core/SKILL.md +54 -21
  27. package/skill-data/ts-services/SKILL.md +4 -4
  28. package/skill-data/ts-services/references/service-surface.md +2 -1
  29. package/skill-data/zig/SKILL.md +1 -1
  30. package/src/app_runner/root.zig +122 -6
  31. package/src/app_runner/ts_core_main.zig +9 -4
  32. package/src/app_runner/ts_core_mobile.zig +241 -0
  33. package/src/app_runner/window_placement.zig +63 -0
  34. package/src/automation/protocol.zig +5 -1
  35. package/src/automation/snapshot.zig +8 -6
  36. package/src/embed/app_exports.zig +3 -1
  37. package/src/embed/conversions.zig +1 -0
  38. package/src/embed/host.zig +10 -3
  39. package/src/embed/root.zig +2 -0
  40. package/src/embed/tests.zig +41 -1
  41. package/src/embed/types.zig +2 -0
  42. package/src/embed/ui_host.zig +94 -4
  43. package/src/platform/android/NativeSdkActivity.java +49 -4
  44. package/src/platform/android/android_host.c +3 -3
  45. package/src/platform/android/native_sdk_app.h +1 -1
  46. package/src/platform/ios/apple_image_fit.h +38 -0
  47. package/src/platform/ios/files.zig +1 -0
  48. package/src/platform/ios/native_sdk_app.h +1 -1
  49. package/src/platform/ios/uikit_host.m +28 -5
  50. package/src/platform/linux/cef_host.cpp +17 -3
  51. package/src/platform/linux/gtk_host.c +243 -15
  52. package/src/platform/linux/gtk_host.h +5 -4
  53. package/src/platform/linux/root.zig +91 -11
  54. package/src/platform/macos/appkit_host.h +18 -11
  55. package/src/platform/macos/appkit_host.m +402 -128
  56. package/src/platform/macos/cef_host.mm +342 -122
  57. package/src/platform/macos/image_fit_test.m +44 -0
  58. package/src/platform/macos/root.zig +231 -39
  59. package/src/platform/null_platform.zig +251 -54
  60. package/src/platform/null_platform_tests.zig +97 -4
  61. package/src/platform/root.zig +12 -0
  62. package/src/platform/types.zig +174 -35
  63. package/src/platform/windows/root.zig +42 -13
  64. package/src/platform/windows/webview2_host.cpp +72 -11
  65. package/src/primitives/app_manifest/root.zig +3 -0
  66. package/src/primitives/app_manifest/tests.zig +24 -0
  67. package/src/primitives/app_manifest/types.zig +13 -0
  68. package/src/primitives/app_manifest/validation.zig +24 -0
  69. package/src/primitives/canvas/a11y_audit.zig +9 -7
  70. package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
  71. package/src/primitives/canvas/events.zig +50 -0
  72. package/src/primitives/canvas/layout_audit.zig +6 -6
  73. package/src/primitives/canvas/markdown.zig +4 -0
  74. package/src/primitives/canvas/markdown_tests.zig +1 -0
  75. package/src/primitives/canvas/png.zig +138 -0
  76. package/src/primitives/canvas/root.zig +13 -2
  77. package/src/primitives/canvas/text_span_tests.zig +5 -3
  78. package/src/primitives/canvas/text_spans.zig +2 -0
  79. package/src/primitives/canvas/text_tests.zig +20 -0
  80. package/src/primitives/canvas/ui.zig +55 -2
  81. package/src/primitives/canvas/ui_markup.zig +40 -13
  82. package/src/primitives/canvas/ui_markup_binary.zig +8 -6
  83. package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
  84. package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
  85. package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
  86. package/src/primitives/canvas/ui_markup_tests.zig +11 -2
  87. package/src/primitives/canvas/ui_markup_view.zig +8 -2
  88. package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
  89. package/src/primitives/canvas/ui_schema.zig +17 -13
  90. package/src/primitives/canvas/ui_tests.zig +47 -0
  91. package/src/primitives/canvas/widget_access.zig +3 -3
  92. package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
  93. package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
  94. package/src/primitives/canvas/widget_invalidation.zig +33 -6
  95. package/src/primitives/canvas/widget_layout.zig +333 -126
  96. package/src/primitives/canvas/widget_layout_tests.zig +169 -0
  97. package/src/primitives/canvas/widget_metrics.zig +7 -8
  98. package/src/primitives/canvas/widget_render.zig +76 -44
  99. package/src/primitives/canvas/widget_render_controls.zig +110 -32
  100. package/src/primitives/canvas/widget_render_style.zig +58 -18
  101. package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
  102. package/src/primitives/canvas/widget_routing.zig +40 -34
  103. package/src/primitives/canvas/widget_runtime.zig +11 -2
  104. package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
  105. package/src/primitives/canvas/widget_semantics.zig +8 -3
  106. package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
  107. package/src/primitives/canvas/widget_tree.zig +99 -5
  108. package/src/primitives/canvas/widgets.zig +20 -7
  109. package/src/root.zig +10 -0
  110. package/src/runtime/api.zig +14 -0
  111. package/src/runtime/automation_commands.zig +35 -2
  112. package/src/runtime/automation_snapshot.zig +32 -24
  113. package/src/runtime/automation_widget_dispatch.zig +48 -6
  114. package/src/runtime/bridge_permission_tests.zig +35 -1
  115. package/src/runtime/bridge_responses.zig +1 -1
  116. package/src/runtime/builtin_bridge.zig +16 -3
  117. package/src/runtime/canvas_frame_packet_tests.zig +22 -13
  118. package/src/runtime/canvas_image_tests.zig +146 -2
  119. package/src/runtime/canvas_images.zig +35 -16
  120. package/src/runtime/canvas_limits.zig +13 -3
  121. package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
  122. package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
  123. package/src/runtime/canvas_widget_control_tests.zig +31 -1
  124. package/src/runtime/canvas_widget_events.zig +151 -26
  125. package/src/runtime/canvas_widget_floating_tests.zig +48 -0
  126. package/src/runtime/canvas_widget_runtime.zig +322 -102
  127. package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
  128. package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
  129. package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
  130. package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
  131. package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
  132. package/src/runtime/canvas_widget_state.zig +33 -7
  133. package/src/runtime/core.zig +28 -6
  134. package/src/runtime/effects.zig +1337 -49
  135. package/src/runtime/effects_file_tests.zig +587 -0
  136. package/src/runtime/effects_image_tests.zig +91 -0
  137. package/src/runtime/effects_notification_tests.zig +11 -0
  138. package/src/runtime/file_access.zig +400 -0
  139. package/src/runtime/file_effect_crash_helper.zig +28 -0
  140. package/src/runtime/file_effect_crash_tests.zig +37 -0
  141. package/src/runtime/flow.zig +21 -9
  142. package/src/runtime/gpu_surface_events.zig +25 -2
  143. package/src/runtime/native_command_event_tests.zig +44 -2
  144. package/src/runtime/pty.zig +5 -2
  145. package/src/runtime/root.zig +7 -0
  146. package/src/runtime/session_blobs.zig +4 -1
  147. package/src/runtime/session_journal.zig +56 -5
  148. package/src/runtime/session_record.zig +38 -0
  149. package/src/runtime/session_replay.zig +110 -15
  150. package/src/runtime/session_tests.zig +192 -4
  151. package/src/runtime/shell_layout_tests.zig +12 -0
  152. package/src/runtime/state.zig +10 -0
  153. package/src/runtime/system_services.zig +129 -36
  154. package/src/runtime/ts_core_host.zig +281 -11
  155. package/src/runtime/ts_core_host_tests.zig +142 -1
  156. package/src/runtime/ts_ui_app.zig +461 -8
  157. package/src/runtime/ui_app.zig +330 -112
  158. package/src/runtime/ui_app_tests.zig +251 -25
  159. package/src/runtime/ui_app_window_tests.zig +74 -8
  160. package/src/runtime/validation.zig +20 -0
  161. package/src/runtime/view.zig +3 -0
  162. package/src/runtime/view_widget_control.zig +18 -0
  163. package/src/runtime/view_widget_scroll.zig +112 -18
  164. package/src/runtime/view_widget_tree.zig +110 -13
  165. package/src/runtime/widget_bridge.zig +2 -0
  166. package/src/runtime/window_command_bridge_tests.zig +86 -0
  167. package/src/runtime/window_storage.zig +16 -1
  168. package/src/runtime/window_views.zig +1 -0
  169. package/src/tooling/ios.zig +3 -0
  170. package/src/tooling/manifest.zig +90 -2
  171. package/src/tooling/package.zig +67 -2
  172. package/src/tooling/raw_manifest.zig +10 -0
  173. package/src/tooling/templates.zig +156 -18
  174. package/src/tooling/ts_core.zig +83 -0
  175. package/src/tooling/web_engine.zig +1 -1
  176. package/tools/corewire/emit.zig +3 -3
  177. package/tools/corewire/emit_facade.zig +65 -5
  178. package/tools/corewire/emit_profile.zig +2 -2
  179. package/tools/corewire/emit_service.zig +2 -2
  180. package/tools/corewire/service_contract.zig +4 -4
  181. package/tools/corewire/sidecar.zig +4 -4
@@ -9,6 +9,7 @@ const runtime_canvas_widget_context_menu = @import("canvas_widget_context_menu.z
9
9
  const runtime_canvas_widget_display = @import("canvas_widget_display.zig");
10
10
  const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
11
11
  const runtime_canvas_widget_scroll_drivers = @import("canvas_widget_scroll_drivers.zig");
12
+ const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
12
13
 
13
14
  const canvasWidgetInputBatchesDisplayListRefresh = canvas_frame_helpers.canvasWidgetInputBatchesDisplayListRefresh;
14
15
  const gpuSurfaceFrameEventFromGpuFrame = canvas_frame_helpers.gpuSurfaceFrameEventFromGpuFrame;
@@ -361,7 +362,7 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
361
362
  // activation (checkbox/toggle state), not only app Msgs and
362
363
  // commands. Geometry controls applied their live resize on
363
364
  // move; a terminal drag owes no release mutation.
364
- if (!widget_drag_terminal) try CanvasWidgetEventMethods().updateCanvasWidgetControlFromPointer(self, pointer_event.*);
365
+ if (!widget_drag_terminal) try CanvasWidgetEventMethods().updateCanvasWidgetControlFromPointer(self, pointer_event);
365
366
  try CanvasWidgetEventMethods().updateCanvasWidgetInteractionFromPointer(self, pointer_event.*);
366
367
  // The text pass may stamp a caret/selection or clear
367
368
  // edit onto the event for the app dispatch below.
@@ -448,6 +449,28 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
448
449
  // from "an arrow landed here in place".
449
450
  if (widget_keyboard_event) |*keyboard_event| {
450
451
  keyboard_event.keyboard.focus_moved = widget_focus_moved;
452
+ // Nearest-radio-group navigation owns its key even when
453
+ // Home/End names the current edge or a one-member group
454
+ // wraps in place. Selection is a separate stamp: a real
455
+ // focus move selects the landed radio, and an in-place
456
+ // move selects only an unchecked current radio. Bare
457
+ // radios preserve their legacy focus-only spatial
458
+ // behavior, and Tab entry never synthesizes a selection.
459
+ const view_index = runtimeFindViewIndex(self, input_event.window_id, input_event.label).?;
460
+ const layout = self.views[view_index].widgetLayoutTree();
461
+ const radio_group_navigation = navigation: {
462
+ const target = keyboard_event.target orelse break :navigation false;
463
+ if (target.kind != .radio) break :navigation false;
464
+ if (canvas_widget_runtime.canvasWidgetRadioGroupScopeIndex(layout, target.index) == null) break :navigation false;
465
+ break :navigation canvas_widget_runtime.canvasWidgetGroupFocusEdgeFromInput(input_event) != null or
466
+ canvas_widget_runtime.canvasWidgetSpatialFocusDirection(input_event) != null;
467
+ };
468
+ keyboard_event.keyboard.radio_group_navigation = radio_group_navigation;
469
+ if (radio_group_navigation) {
470
+ const target = keyboard_event.target.?;
471
+ keyboard_event.keyboard.radio_group_selection = widget_focus_moved or
472
+ !canvas_widget_runtime.canvasWidgetSelectableSelected(layout.nodes[target.index].widget);
473
+ }
451
474
  }
452
475
  // Clipboard shortcuts resolve against the raw input (copy has
453
476
  // no routed target when a static text selection is live) and
@@ -471,7 +494,7 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
471
494
  // armed/shown tooltip before the control mutation and
472
495
  // app dispatch observe the input.
473
496
  try CanvasWidgetEventMethods().updateCanvasTooltipIntentForKeyboardActivation(self, keyboard_event.*);
474
- try CanvasWidgetEventMethods().updateCanvasWidgetControlFromKeyboard(self, keyboard_event.*);
497
+ try CanvasWidgetEventMethods().updateCanvasWidgetControlFromKeyboard(self, keyboard_event);
475
498
  try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, keyboard_event);
476
499
  }
477
500
  // An IME sequence belongs to whoever it STARTED over: a
@@ -289,13 +289,13 @@ test "runtime dispatches tray item commands" {
289
289
  .{ .id = 8, .label = "Legacy" },
290
290
  } });
291
291
 
292
- try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .tray_action = 7 });
292
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .tray_action = .{ .item_id = 7 } });
293
293
  try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
294
294
  try std.testing.expectEqualStrings("app.refresh", app_state.last_name);
295
295
  try std.testing.expectEqual(CommandSource.tray, app_state.last_source);
296
296
  try std.testing.expectEqual(@as(platform.TrayItemId, 7), app_state.last_tray_item_id);
297
297
 
298
- try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .tray_action = 8 });
298
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .tray_action = .{ .item_id = 8 } });
299
299
  try std.testing.expectEqual(@as(u32, 2), app_state.command_count);
300
300
  try std.testing.expectEqualStrings("tray.action", app_state.last_name);
301
301
  try std.testing.expectEqual(@as(platform.TrayItemId, 8), app_state.last_tray_item_id);
@@ -349,6 +349,48 @@ test "runtime dispatches named tray lifecycle commands with tray source" {
349
349
  try std.testing.expectEqual(@as(platform.WindowId, 3), app_state.last_window_id);
350
350
  }
351
351
 
352
+ test "runtime dispatches notification actions through the normal command path" {
353
+ const TestApp = struct {
354
+ command_count: u32 = 0,
355
+ last_name: []const u8 = "",
356
+ last_source: CommandSource = .runtime,
357
+ last_window_id: platform.WindowId = 0,
358
+
359
+ fn app(self: *@This()) App {
360
+ return .{ .context = self, .name = "notification-command", .source = platform.WebViewSource.html("<p>Notification</p>"), .event_fn = event };
361
+ }
362
+
363
+ fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
364
+ _ = runtime;
365
+ const self: *@This() = @ptrCast(@alignCast(context));
366
+ switch (event_value) {
367
+ .command => |command| {
368
+ self.command_count += 1;
369
+ self.last_name = command.name;
370
+ self.last_source = command.source;
371
+ self.last_window_id = command.window_id;
372
+ },
373
+ else => {},
374
+ }
375
+ }
376
+ };
377
+
378
+ const harness = try TestHarness().create(std.testing.allocator, .{});
379
+ defer harness.destroy(std.testing.allocator);
380
+ var app_state: TestApp = .{};
381
+ try harness.start(app_state.app());
382
+
383
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .notification_command = .{
384
+ .name = "build.open",
385
+ .window_id = 4,
386
+ } });
387
+
388
+ try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
389
+ try std.testing.expectEqualStrings("build.open", app_state.last_name);
390
+ try std.testing.expectEqual(CommandSource.notification, app_state.last_source);
391
+ try std.testing.expectEqual(@as(platform.WindowId, 4), app_state.last_window_id);
392
+ }
393
+
352
394
  test "runtime dispatches file drop events to app and window bridge" {
353
395
  const TestApp = struct {
354
396
  drop_count: u32 = 0,
@@ -924,7 +924,9 @@ const f_dupfd_cloexec: c_int = switch (builtin.os.tag) {
924
924
  fn errnoValue() c_int {
925
925
  return switch (builtin.os.tag) {
926
926
  .macos => c.__error().*,
927
- .linux => c.__errno_location().*,
927
+ // Bionic spells the errno accessor `__errno`; glibc and musl agree
928
+ // on `__errno_location`.
929
+ .linux => if (comptime builtin.abi.isAndroid()) c.__errno().* else c.__errno_location().*,
928
930
  else => 0,
929
931
  };
930
932
  }
@@ -962,7 +964,8 @@ const c = struct {
962
964
  extern "c" fn fcntl(fd: c_int, cmd: c_int, ...) c_int;
963
965
  extern "c" fn poll(fds: [*]Pollfd, nfds: c_uint, timeout: c_int) c_int;
964
966
  extern "c" fn __error() *c_int; // Darwin errno
965
- extern "c" fn __errno_location() *c_int; // Linux errno
967
+ extern "c" fn __errno_location() *c_int; // Linux errno (glibc/musl)
968
+ extern "c" fn __errno() *c_int; // Bionic errno
966
969
  };
967
970
 
968
971
  /// A nudge pipe for the io thread: [read end, write end]. BOTH ends are
@@ -80,8 +80,12 @@ pub const max_effect_fetch_payload_bytes = runtime_effects.max_effect_fetch_payl
80
80
  pub const max_effect_body_bytes = runtime_effects.max_effect_body_bytes;
81
81
  pub const default_effect_fetch_timeout_ms = runtime_effects.default_effect_fetch_timeout_ms;
82
82
  pub const EffectFileOp = runtime_effects.EffectFileOp;
83
+ pub const EffectFileEvent = runtime_effects.EffectFileEvent;
83
84
  pub const EffectFileOutcome = runtime_effects.EffectFileOutcome;
84
85
  pub const EffectFileResult = runtime_effects.EffectFileResult;
86
+ pub const FileAccessBinding = runtime_effects.FileAccessBinding;
87
+ pub const effect_file_stream_chunk_bytes = runtime_effects.effect_file_stream_chunk_bytes;
88
+ pub const max_effect_file_streams = runtime_effects.max_effect_file_streams;
85
89
  pub const EffectCredentialsOperation = runtime_effects.EffectCredentialsOperation;
86
90
  pub const EffectCredentialsOutcome = runtime_effects.EffectCredentialsOutcome;
87
91
  pub const EffectCredentialsResult = runtime_effects.EffectCredentialsResult;
@@ -139,6 +143,7 @@ pub const EffectImageOutcome = runtime_effects.EffectImageOutcome;
139
143
  pub const imageCachePath = runtime_effects.imageCachePath;
140
144
  pub const max_effect_image_path_bytes = runtime_effects.max_effect_image_path_bytes;
141
145
  pub const max_effect_image_bytes = runtime_effects.max_effect_image_bytes;
146
+ pub const max_effect_image_source_bytes = runtime_effects.max_effect_image_source_bytes;
142
147
  pub const effect_image_blob_hash_len = runtime_effects.effect_image_blob_hash_len;
143
148
  pub const EffectChannelEvent = runtime_effects.EffectChannelEvent;
144
149
  pub const EffectChannelEventKind = runtime_effects.EffectChannelEventKind;
@@ -185,6 +190,7 @@ pub const ts_core_spawn_key_base = runtime_ts_core_host.spawn_key_base;
185
190
  pub const ts_core_audio_key_base = runtime_ts_core_host.audio_key_base;
186
191
  pub const ts_core_video_key_base = runtime_ts_core_host.video_key_base;
187
192
  pub const ts_core_db_key_base = runtime_ts_core_host.db_key_base;
193
+ pub const ts_core_file_stream_key_base = runtime_ts_core_host.file_stream_key_base;
188
194
 
189
195
  const runtime_ts_ui_app = @import("ts_ui_app.zig");
190
196
  pub const TsUiApp = runtime_ts_ui_app.TsUiApp;
@@ -241,6 +247,7 @@ const runtime_canvas_images = @import("canvas_images.zig");
241
247
  pub const RegisteredCanvasImage = runtime_canvas_images.RegisteredCanvasImage;
242
248
  pub const max_registered_canvas_images = runtime_canvas_images.max_registered_canvas_images;
243
249
  pub const max_registered_canvas_image_pixel_bytes = runtime_canvas_images.max_registered_canvas_image_pixel_bytes;
250
+ pub const max_registered_canvas_image_pixel_bytes_ceiling = runtime_canvas_images.max_registered_canvas_image_pixel_bytes_ceiling;
244
251
 
245
252
  // The media-surface producer channel (media_surface.zig): the handle
246
253
  // type `Runtime.acquireMediaSurfaceProducer` returns rides the public
@@ -39,7 +39,10 @@ pub const hash_len: usize = runtime_effects.effect_image_blob_hash_len;
39
39
 
40
40
  /// The largest payload one blob may hold — the largest journaled effect
41
41
  /// payload that goes out of line (an image load's encoded source).
42
- pub const max_blob_bytes: usize = @max(runtime_effects.max_effect_image_bytes, runtime_effects.max_effect_persist_snapshot_bytes);
42
+ pub const max_blob_bytes: usize = @max(
43
+ runtime_effects.effect_file_stream_chunk_bytes,
44
+ @max(runtime_effects.max_effect_image_bytes, runtime_effects.max_effect_persist_snapshot_bytes),
45
+ );
43
46
 
44
47
  pub const BlobHash = [hash_len]u8;
45
48
 
@@ -185,6 +185,7 @@ fn formatLayoutDescription(comptime epoch: u32) []const u8 {
185
185
  "native_command=" ++ layout_fingerprint.describe(platform.NativeCommandEvent) ++ "\n" ++
186
186
  "menu_command=" ++ layout_fingerprint.describe(platform.MenuCommandEvent) ++ "\n" ++
187
187
  "tray_command=" ++ layout_fingerprint.describe(platform.TrayCommandEvent) ++ "\n" ++
188
+ "notification_command=" ++ layout_fingerprint.describe(platform.NotificationCommandEvent) ++ "\n" ++
188
189
  "timer=" ++ layout_fingerprint.describe(platform.TimerEvent) ++ "\n" ++
189
190
  "audio=" ++ layout_fingerprint.describe(platform.AudioEvent) ++ "\n" ++
190
191
  "video=" ++ layout_fingerprint.describe(platform.VideoEvent) ++ "\n" ++
@@ -466,6 +467,7 @@ const EventTag = enum(u8) {
466
467
  video = 25,
467
468
  view_focused = 26,
468
469
  tray_command = 27,
470
+ notification_command = 28,
469
471
  };
470
472
 
471
473
  // The bit assignments below are hand-written wire layout: they are
@@ -585,9 +587,10 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
585
587
  try cursor.writeInt(u64, message.window_id);
586
588
  try cursor.writeStr(message.webview_label);
587
589
  },
588
- .tray_action => |item_id| {
590
+ .tray_action => |action| {
589
591
  try cursor.writeEnum(EventTag.tray_action);
590
- try cursor.writeInt(u32, item_id);
592
+ try cursor.writeInt(u32, action.status_item_id);
593
+ try cursor.writeInt(u32, action.item_id);
591
594
  },
592
595
  .shortcut => |shortcut| {
593
596
  try cursor.writeEnum(EventTag.shortcut);
@@ -611,6 +614,12 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
611
614
  try cursor.writeEnum(EventTag.tray_command);
612
615
  try cursor.writeStr(command.name);
613
616
  try cursor.writeInt(u64, command.window_id);
617
+ try cursor.writeInt(u32, command.status_item_id);
618
+ },
619
+ .notification_command => |command| {
620
+ try cursor.writeEnum(EventTag.notification_command);
621
+ try cursor.writeStr(command.name);
622
+ try cursor.writeInt(u64, command.window_id);
614
623
  },
615
624
  .timer => |timer| {
616
625
  try cursor.writeEnum(EventTag.timer);
@@ -809,7 +818,10 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
809
818
  .webview_label = webview_label,
810
819
  } };
811
820
  },
812
- .tray_action => .{ .tray_action = try cursor.readInt(u32) },
821
+ .tray_action => .{ .tray_action = .{
822
+ .status_item_id = try cursor.readInt(u32),
823
+ .item_id = try cursor.readInt(u32),
824
+ } },
813
825
  .shortcut => blk: {
814
826
  const id = try cursor.readStr();
815
827
  const key = try cursor.readStr();
@@ -842,6 +854,14 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
842
854
  break :blk .{ .tray_command = .{
843
855
  .name = name,
844
856
  .window_id = try cursor.readInt(u64),
857
+ .status_item_id = try cursor.readInt(u32),
858
+ } };
859
+ },
860
+ .notification_command => blk: {
861
+ const name = try cursor.readStr();
862
+ break :blk .{ .notification_command = .{
863
+ .name = name,
864
+ .window_id = try cursor.readInt(u64),
845
865
  } };
846
866
  },
847
867
  .timer => blk: {
@@ -1034,7 +1054,12 @@ pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]con
1034
1054
  try cursor.writeInt(u16, record.status);
1035
1055
  try cursor.writeEnum(record.fetch_outcome);
1036
1056
  try cursor.writeEnum(record.file_op);
1057
+ try cursor.writeEnum(record.file_event);
1037
1058
  try cursor.writeEnum(record.file_outcome);
1059
+ try cursor.writeInt(u64, record.file_total);
1060
+ try cursor.writeInt(i64, record.file_mtime_ms);
1061
+ try cursor.writeBool(record.file_exists);
1062
+ try cursor.writeBool(record.file_rejected_admission);
1038
1063
  try cursor.writeEnum(record.clipboard_op);
1039
1064
  try cursor.writeEnum(record.clipboard_outcome);
1040
1065
  try cursor.writeInt(u64, record.timer_timestamp_ns);
@@ -1045,6 +1070,8 @@ pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]con
1045
1070
  try cursor.writeInt(u64, record.audio_duration_ms);
1046
1071
  try cursor.writeBool(record.audio_playing);
1047
1072
  try cursor.writeBool(record.audio_buffering);
1073
+ try cursor.writeBytes(&record.file_blob_hash);
1074
+ try cursor.writeInt(u64, record.file_blob_len);
1048
1075
  try cursor.writeBytes(&record.audio_bands);
1049
1076
  // v7: image terminals — outcome, decoded dimensions, and the blob
1050
1077
  // store content address of the journaled source bytes.
@@ -1120,7 +1147,12 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
1120
1147
  .status = try cursor.readInt(u16),
1121
1148
  .fetch_outcome = try cursor.readEnum(runtime_effects.EffectFetchOutcome),
1122
1149
  .file_op = try cursor.readEnum(runtime_effects.EffectFileOp),
1150
+ .file_event = try cursor.readEnum(runtime_effects.EffectFileEvent),
1123
1151
  .file_outcome = try cursor.readEnum(runtime_effects.EffectFileOutcome),
1152
+ .file_total = try cursor.readInt(u64),
1153
+ .file_mtime_ms = try cursor.readInt(i64),
1154
+ .file_exists = try cursor.readBool(),
1155
+ .file_rejected_admission = try cursor.readBool(),
1124
1156
  .clipboard_op = try cursor.readEnum(runtime_effects.EffectClipboardOp),
1125
1157
  .clipboard_outcome = try cursor.readEnum(runtime_effects.EffectClipboardOutcome),
1126
1158
  .timer_timestamp_ns = try cursor.readInt(u64),
@@ -1132,6 +1164,8 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
1132
1164
  .audio_playing = try cursor.readBool(),
1133
1165
  .audio_buffering = try cursor.readBool(),
1134
1166
  };
1167
+ @memcpy(&record.file_blob_hash, try cursor.readBytes(record.file_blob_hash.len));
1168
+ record.file_blob_len = try cursor.readInt(u64);
1135
1169
  @memcpy(&record.audio_bands, try cursor.readBytes(record.audio_bands.len));
1136
1170
  // v7: image terminals.
1137
1171
  record.image_outcome = try cursor.readEnum(runtime_effects.EffectImageOutcome);
@@ -1636,8 +1670,14 @@ test "event codec round-trips every payload variant" {
1636
1670
  try testing.expectEqual(@as(platform.WindowId, 3), decoded.tray_command.window_id);
1637
1671
  }
1638
1672
  {
1639
- const decoded = try roundTripEvent(.{ .tray_action = 9 });
1640
- try testing.expectEqual(@as(platform.TrayItemId, 9), decoded.tray_action);
1673
+ const decoded = try roundTripEvent(.{ .notification_command = .{ .name = "build.open", .window_id = 2 } });
1674
+ try testing.expectEqualStrings("build.open", decoded.notification_command.name);
1675
+ try testing.expectEqual(@as(platform.WindowId, 2), decoded.notification_command.window_id);
1676
+ }
1677
+ {
1678
+ const decoded = try roundTripEvent(.{ .tray_action = .{ .status_item_id = 3, .item_id = 9 } });
1679
+ try testing.expectEqual(@as(platform.StatusItemId, 3), decoded.tray_action.status_item_id);
1680
+ try testing.expectEqual(@as(platform.TrayItemId, 9), decoded.tray_action.item_id);
1641
1681
  }
1642
1682
  {
1643
1683
  const decoded = try roundTripEvent(.{ .window_focused = 4 });
@@ -1676,6 +1716,17 @@ test "effect codec round-trips payloads and outcomes" {
1676
1716
  try testing.expect(decoded.truncated);
1677
1717
  try testing.expectEqual(@as(u16, 200), decoded.status);
1678
1718
 
1719
+ const delete_encoded = try encodeEffect(.{
1720
+ .kind = .file,
1721
+ .key = 78,
1722
+ .file_op = .delete,
1723
+ .file_outcome = .not_found,
1724
+ }, &buffer);
1725
+ const delete_decoded = try decodeEffect(delete_encoded);
1726
+ try testing.expectEqual(runtime_effects.EffectResultKind.file, delete_decoded.kind);
1727
+ try testing.expectEqual(runtime_effects.EffectFileOp.delete, delete_decoded.file_op);
1728
+ try testing.expectEqual(runtime_effects.EffectFileOutcome.not_found, delete_decoded.file_outcome);
1729
+
1679
1730
  const exit_encoded = try encodeEffect(.{
1680
1731
  .kind = .exit,
1681
1732
  .key = 5,
@@ -241,6 +241,16 @@ pub const SessionRecorder = struct {
241
241
  journaled.credentials_secret_len = record.payload.len;
242
242
  }
243
243
  }
244
+ if (record.kind == .file and record.file_event == .chunk and record.payload.len > 0) {
245
+ const blob_sink = self.blob_sink orelse {
246
+ return self.fail("a streamed file chunk needs the session blob store, and none is bound - wire SessionRecorder.blob_sink");
247
+ };
248
+ const hash = session_blobs.hashBytes(record.payload);
249
+ blob_sink.write_fn(blob_sink.context, hash, record.payload) catch |err| return self.fail(@errorName(err));
250
+ journaled.file_blob_hash = hash;
251
+ journaled.file_blob_len = record.payload.len;
252
+ journaled.payload = "";
253
+ }
244
254
  if (record.kind == .image and record.payload.len > 0) {
245
255
  const blob_sink = self.blob_sink orelse {
246
256
  return self.fail("an image effect result needs the session blob store, and none is bound - wire SessionRecorder.blob_sink (the app runner creates blobs/ beside the journal)");
@@ -458,6 +468,34 @@ test "recorder moves model restore snapshots into the session blob store" {
458
468
  try testing.expectEqualStrings("canonical model", restored);
459
469
  }
460
470
 
471
+ test "recorder moves streamed file chunks into the session blob store" {
472
+ var buffer_sink = BufferSink{};
473
+ var blobs = session_blobs.MemoryBlobStore.init(testing.allocator);
474
+ defer blobs.deinit();
475
+ const recorder = try testing.allocator.create(SessionRecorder);
476
+ defer testing.allocator.destroy(recorder);
477
+ recorder.* = SessionRecorder.init(buffer_sink.sink());
478
+ recorder.blob_sink = blobs.sink();
479
+ recorder.begin(.{ .platform_name = "test", .app_name = "file-stream" });
480
+ recorder.recordEffect(.{
481
+ .kind = .file,
482
+ .key = 91,
483
+ .payload = "streamed bytes",
484
+ .file_op = .read_stream,
485
+ .file_event = .chunk,
486
+ .file_outcome = .ok,
487
+ .file_total = 14,
488
+ });
489
+ recorder.finish();
490
+ var reader = try journal.Reader.init(buffer_sink.bytes());
491
+ _ = (try reader.next()).?;
492
+ const effect = (try reader.next()).?.effect;
493
+ try testing.expectEqual(@as(usize, 0), effect.payload.len);
494
+ try testing.expectEqual(@as(u64, 14), effect.file_blob_len);
495
+ var scratch: [32]u8 = undefined;
496
+ try testing.expectEqualStrings("streamed bytes", try blobs.read(effect.file_blob_hash, &scratch));
497
+ }
498
+
461
499
  test "recorder redacts credential bytes from journal and blob storage" {
462
500
  const secret = "storage-tier-four-live-token";
463
501
  const set_secret = "storage-tier-four-set-token";
@@ -28,10 +28,11 @@
28
28
 
29
29
  const std = @import("std");
30
30
  const canvas = @import("canvas");
31
- const canvas_limits = @import("canvas_limits.zig");
32
31
  const automation_protocol = @import("../automation/protocol.zig");
32
+ const canvas_limits = @import("canvas_limits.zig");
33
33
  const core = @import("core.zig");
34
34
  const journal = @import("session_journal.zig");
35
+ const platform = @import("../platform/root.zig");
35
36
  const runtime_effects = @import("effects.zig");
36
37
  const session_blobs = @import("session_blobs.zig");
37
38
 
@@ -58,8 +59,8 @@ pub const ReplayError = error{
58
59
  /// can never produce (an image record claiming `.loaded` with a
59
60
  /// zero-length blob: the recorder journals `.loaded` only after the
60
61
  /// bytes decoded and registered, and empty bytes cannot decode; or
61
- /// decoded dimensions the canvas registry would never have accepted
62
- /// — zero or over-budget on `.loaded`, nonzero on any other
62
+ /// decoded dimensions no conforming recording could have accepted
63
+ /// — zero or over the SDK hard ceiling on `.loaded`, nonzero on any other
63
64
  /// outcome) — the journal is damaged or hand-edited.
64
65
  /// `JournalCorrupt` is the structural sibling (payloads that fail
65
66
  /// to decode at all); this class is for records that decode fine
@@ -178,6 +179,13 @@ pub fn replaySession(
178
179
  },
179
180
  .effect => |effect_record| {
180
181
  var effect = effect_record;
182
+ if (effect.kind == .file and fileRecordDamaged(effect)) {
183
+ std.debug.print(
184
+ "replay refused after event {d}: file record for key {d} has an invalid stream/stat payload shape\n",
185
+ .{ report.events_replayed, effect.key },
186
+ );
187
+ return error.ReplayDamagedRecord;
188
+ }
181
189
  // A `.loaded` image record ALWAYS names source bytes:
182
190
  // the recorder journals `.loaded` only after those
183
191
  // exact bytes decoded and registered (a failed decode
@@ -199,9 +207,8 @@ pub fn replaySession(
199
207
  // Decoded dimensions obey the recorder the same way: a
200
208
  // live `.loaded` journals only after the canvas registry
201
209
  // accepted the pixels (nonzero width and height, and
202
- // width * height * 4 bytes within
203
- // `max_registered_canvas_image_pixel_bytes` — the same
204
- // bound `registerCanvasImage` enforces), and every other
210
+ // width * height * 4 bytes within that recording's
211
+ // runtime-frozen app image budget), and every other
205
212
  // outcome journals 0x0. Refuse out-of-bound dims HERE:
206
213
  // the fed values flow verbatim into the app's Msg — and,
207
214
  // on the TS core host, through `@intCast` into
@@ -244,7 +251,7 @@ pub fn replaySession(
244
251
  }
245
252
  if (effect.kind == .image and imageDimsDamaged(effect)) {
246
253
  std.debug.print(
247
- "replay refused after event {d}: image record for id {d} claims .{s} with dimensions {d}x{d} - a recorded .loaded always carries nonzero decoded dimensions within the registered-image pixel budget and every other outcome records 0x0, so the journal is damaged or hand-edited; re-record the session\n",
254
+ "replay refused after event {d}: image record for id {d} claims .{s} with dimensions {d}x{d} - a recorded .loaded always carries nonzero decoded dimensions within the SDK's registered-image ceiling and every other outcome records 0x0, so the journal is damaged or hand-edited; re-record the session\n",
248
255
  .{ report.events_replayed, effect.key, @tagName(effect.image_outcome), effect.image_width, effect.image_height },
249
256
  );
250
257
  return error.ReplayDamagedRecord;
@@ -362,6 +369,16 @@ pub fn replaySession(
362
369
  };
363
370
  effect.payload = bytes;
364
371
  }
372
+ if (effect.kind == .file and effect.file_blob_len > 0) {
373
+ const bytes = resolveBlob(effect.file_blob_hash, effect.file_blob_len, runtime_effects.effect_file_stream_chunk_bytes, options.blobs, &blob_scratch) catch |err| {
374
+ std.debug.print(
375
+ "replay refused after event {d}: file stream for key {d} references blob {s} ({d} bytes) that could not be resolved ({s})\n",
376
+ .{ report.events_replayed, effect.key, session_blobs.hexName(effect.file_blob_hash), effect.file_blob_len, @errorName(err) },
377
+ );
378
+ return error.ReplayMissingBlob;
379
+ };
380
+ effect.payload = bytes;
381
+ }
365
382
  if (effect.kind == .image and effect.image_blob_len > 0) {
366
383
  const bytes = resolveBlob(effect.image_blob_hash, effect.image_blob_len, runtime_effects.max_effect_image_bytes, options.blobs, &blob_scratch) catch |err| {
367
384
  std.debug.print(
@@ -592,6 +609,25 @@ fn dbRecordDamaged(record: journal.EffectResultRecord) bool {
592
609
  };
593
610
  }
594
611
 
612
+ fn fileRecordDamaged(record: journal.EffectResultRecord) bool {
613
+ if (record.file_rejected_admission) switch (record.file_outcome) {
614
+ .rejected => {},
615
+ .sink_missing, .out_of_order => if (record.file_op != .write_stream_chunk and record.file_op != .write_stream_close) return true,
616
+ else => return true,
617
+ };
618
+ if (record.file_blob_len > runtime_effects.effect_file_stream_chunk_bytes) return true;
619
+ if (record.file_event == .chunk) {
620
+ return record.file_op != .read_stream or record.file_outcome != .ok or
621
+ record.payload.len != 0 or record.file_blob_len == 0;
622
+ }
623
+ if (record.file_blob_len != 0) return true;
624
+ if (record.file_event == .done) {
625
+ return record.file_op != .read_stream or record.file_outcome != .ok or record.payload.len != 0;
626
+ }
627
+ if (record.file_op == .stat and record.file_outcome == .ok) return record.payload.len != 0;
628
+ return record.file_total != 0 or record.file_mtime_ms != 0 or record.file_exists;
629
+ }
630
+
595
631
  fn credentialsRecordDamaged(record: journal.EffectResultRecord) bool {
596
632
  if (record.payload.len != 0 or record.exit_reason != .exited) return true;
597
633
  const redacted_get = record.credentials_operation == .get and record.credentials_outcome == .ok;
@@ -717,9 +753,14 @@ fn imageDimsDamaged(record: journal.EffectResultRecord) bool {
717
753
  return record.image_width != 0 or record.image_height != 0;
718
754
  }
719
755
  if (record.image_width == 0 or record.image_height == 0) return true;
756
+ if (record.image_width > platform.max_decoded_image_dimension or record.image_height > platform.max_decoded_image_dimension) return true;
720
757
  const pixels = std.math.mul(u64, record.image_width, record.image_height) catch return true;
721
758
  const pixel_bytes = std.math.mul(u64, pixels, 4) catch return true;
722
- return pixel_bytes > canvas_limits.max_registered_canvas_image_pixel_bytes;
759
+ // The journal does not carry the recording's manifest budget. Validate
760
+ // against the SDK-wide ceiling: a result above the replay runtime's
761
+ // current (possibly lowered) budget is still valid recorder truth. Its
762
+ // Msg feeds verbatim; best-effort pixel re-registration may fit smaller.
763
+ return pixel_bytes > canvas_limits.max_registered_canvas_image_pixel_bytes_ceiling;
723
764
  }
724
765
 
725
766
  /// Journaled results that regenerate deterministically from the
@@ -731,15 +772,13 @@ fn effectRegeneratesUnderReplay(record: journal.EffectResultRecord) bool {
731
772
  return switch (record.kind) {
732
773
  .timer => true,
733
774
  .exit => record.exit_reason == .rejected,
734
- // Only DETERMINISTIC admission refusals regenerate — marked by
735
- // the provenance bit the recorder set (`truncated`, unused for
736
- // pty otherwise). Executor-truth terminals — start failures,
737
- // the platform-unsupported rejection, output, and real exits —
738
- // are external inputs and must be fed, even when their reason
739
- // is `.rejected`.
775
+ // Only DETERMINISTIC admission/protocol results regenerate — marked
776
+ // by each effect family's provenance bit. Executor-truth terminals —
777
+ // start failures, platform refusals, output, and real exits — are
778
+ // external inputs and must be fed, even when their reason is rejected.
740
779
  .pty => record.pty_kind == .exit and record.truncated,
741
780
  .response => record.fetch_outcome == .rejected,
742
- .file => record.file_outcome == .rejected,
781
+ .file => record.file_rejected_admission,
743
782
  .clipboard => record.clipboard_outcome == .rejected,
744
783
  // Audio rejections are loop-side validation (path bounds) that
745
784
  // refuses again; everything else — loaded acknowledgments,
@@ -791,6 +830,62 @@ fn effectRegeneratesUnderReplay(record: journal.EffectResultRecord) bool {
791
830
  };
792
831
  }
793
832
 
833
+ test "only admission-tagged file results regenerate" {
834
+ try std.testing.expect(effectRegeneratesUnderReplay(.{
835
+ .kind = .file,
836
+ .key = 1,
837
+ .file_outcome = .rejected,
838
+ .file_rejected_admission = true,
839
+ }));
840
+ try std.testing.expect(!fileRecordDamaged(.{
841
+ .kind = .file,
842
+ .key = 2,
843
+ .file_op = .write_stream_chunk,
844
+ .file_outcome = .sink_missing,
845
+ .file_rejected_admission = true,
846
+ }));
847
+ try std.testing.expect(fileRecordDamaged(.{
848
+ .kind = .file,
849
+ .key = 2,
850
+ .file_op = .write_stream_chunk,
851
+ .file_outcome = .ok,
852
+ .file_rejected_admission = true,
853
+ }));
854
+ try std.testing.expect(!effectRegeneratesUnderReplay(.{
855
+ .kind = .file,
856
+ .key = 1,
857
+ .file_op = .read_stream,
858
+ .file_outcome = .rejected,
859
+ }));
860
+ try std.testing.expect(effectRegeneratesUnderReplay(.{
861
+ .kind = .file,
862
+ .key = 2,
863
+ .file_op = .write_stream_chunk,
864
+ .file_outcome = .sink_missing,
865
+ .file_rejected_admission = true,
866
+ }));
867
+ try std.testing.expect(effectRegeneratesUnderReplay(.{
868
+ .kind = .file,
869
+ .key = 3,
870
+ .file_op = .write_stream_close,
871
+ .file_outcome = .out_of_order,
872
+ .file_rejected_admission = true,
873
+ }));
874
+ try std.testing.expect(!fileRecordDamaged(.{
875
+ .kind = .file,
876
+ .key = 4,
877
+ .file_op = .write_stream_chunk,
878
+ .file_outcome = .ok,
879
+ }));
880
+ try std.testing.expect(fileRecordDamaged(.{
881
+ .kind = .file,
882
+ .key = 4,
883
+ .file_op = .write_stream_chunk,
884
+ .file_outcome = .ok,
885
+ .file_total = 1,
886
+ }));
887
+ }
888
+
794
889
  /// Re-render a journaled screenshot mark through the same deterministic
795
890
  /// reference renderer the automation `screenshot` verb used at record
796
891
  /// time, and hash the PNG.