@native-sdk/cli 0.9.0 → 0.9.1

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 (92) hide show
  1. package/build/app.zig +331 -24
  2. package/build.zig +179 -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 +167 -12
  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 +11 -5
  26. package/skill-data/ts-core/SKILL.md +53 -20
  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 +29 -0
  31. package/src/app_runner/ts_core_main.zig +5 -0
  32. package/src/app_runner/ts_core_mobile.zig +241 -0
  33. package/src/automation/protocol.zig +5 -1
  34. package/src/automation/snapshot.zig +8 -6
  35. package/src/embed/app_exports.zig +1 -0
  36. package/src/embed/root.zig +1 -0
  37. package/src/embed/tests.zig +28 -0
  38. package/src/embed/ui_host.zig +68 -2
  39. package/src/platform/linux/cef_host.cpp +7 -1
  40. package/src/platform/linux/gtk_host.c +200 -5
  41. package/src/platform/linux/gtk_host.h +2 -1
  42. package/src/platform/linux/root.zig +69 -4
  43. package/src/platform/macos/appkit_host.h +11 -7
  44. package/src/platform/macos/appkit_host.m +210 -88
  45. package/src/platform/macos/cef_host.mm +210 -88
  46. package/src/platform/macos/root.zig +77 -30
  47. package/src/platform/null_platform.zig +234 -51
  48. package/src/platform/null_platform_tests.zig +39 -0
  49. package/src/platform/root.zig +10 -0
  50. package/src/platform/types.zig +105 -16
  51. package/src/platform/windows/root.zig +20 -6
  52. package/src/platform/windows/webview2_host.cpp +41 -5
  53. package/src/root.zig +7 -0
  54. package/src/runtime/api.zig +8 -0
  55. package/src/runtime/automation_commands.zig +35 -2
  56. package/src/runtime/automation_snapshot.zig +32 -24
  57. package/src/runtime/bridge_permission_tests.zig +35 -1
  58. package/src/runtime/bridge_responses.zig +1 -1
  59. package/src/runtime/builtin_bridge.zig +11 -1
  60. package/src/runtime/core.zig +12 -6
  61. package/src/runtime/effects.zig +1323 -35
  62. package/src/runtime/effects_file_tests.zig +587 -0
  63. package/src/runtime/effects_notification_tests.zig +11 -0
  64. package/src/runtime/file_access.zig +400 -0
  65. package/src/runtime/file_effect_crash_helper.zig +28 -0
  66. package/src/runtime/file_effect_crash_tests.zig +37 -0
  67. package/src/runtime/flow.zig +21 -9
  68. package/src/runtime/native_command_event_tests.zig +44 -2
  69. package/src/runtime/pty.zig +5 -2
  70. package/src/runtime/root.zig +5 -0
  71. package/src/runtime/session_blobs.zig +4 -1
  72. package/src/runtime/session_journal.zig +56 -5
  73. package/src/runtime/session_record.zig +38 -0
  74. package/src/runtime/session_replay.zig +97 -7
  75. package/src/runtime/session_tests.zig +81 -0
  76. package/src/runtime/state.zig +10 -0
  77. package/src/runtime/system_services.zig +129 -36
  78. package/src/runtime/ts_core_host.zig +281 -11
  79. package/src/runtime/ts_core_host_tests.zig +95 -1
  80. package/src/runtime/ts_ui_app.zig +461 -8
  81. package/src/runtime/ui_app.zig +321 -109
  82. package/src/runtime/ui_app_tests.zig +132 -6
  83. package/src/runtime/ui_app_window_tests.zig +61 -7
  84. package/src/runtime/validation.zig +20 -0
  85. package/src/tooling/templates.zig +28 -0
  86. package/src/tooling/ts_core.zig +83 -0
  87. package/tools/corewire/emit.zig +3 -3
  88. package/tools/corewire/emit_facade.zig +65 -5
  89. package/tools/corewire/emit_profile.zig +2 -2
  90. package/tools/corewire/emit_service.zig +2 -2
  91. package/tools/corewire/service_contract.zig +4 -4
  92. package/tools/corewire/sidecar.zig +4 -4
@@ -26,8 +26,14 @@ const validateRevealPath = validation.validateRevealPath;
26
26
  const validateSaveDialogOptions = validation.validateSaveDialogOptions;
27
27
  const validateTrayMenuItems = validation.validateTrayMenuItems;
28
28
  const validateTrayOptions = validation.validateTrayOptions;
29
+ const validateTrayShell = validation.validateTrayShell;
29
30
  const validateTrayTitle = validation.validateTrayTitle;
30
31
 
32
+ fn optionalNotificationString(payload: []const u8, field: []const u8, storage: *json.StringStorage) ![]const u8 {
33
+ if (json.fieldValue(payload, field) == null) return "";
34
+ return jsonStringField(payload, field, storage) orelse error.InvalidNotificationOptions;
35
+ }
36
+
31
37
  pub fn RuntimeSystemServices(comptime Runtime: type) type {
32
38
  return struct {
33
39
  pub fn readClipboard(self: *Runtime, buffer: []u8) anyerror![]const u8 {
@@ -136,58 +142,113 @@ pub fn RuntimeSystemServices(comptime Runtime: type) type {
136
142
  return self.options.platform.services.formatLocalTime(timestamp_ms, style, buffer);
137
143
  }
138
144
 
139
- pub fn createTray(self: *Runtime, options: platform.TrayOptions) anyerror!void {
145
+ pub fn createStatusItem(self: *Runtime, status_item_id: platform.StatusItemId, options: platform.TrayOptions) anyerror!void {
146
+ try validation.validateStatusItemId(status_item_id);
140
147
  try validateTrayOptions(options);
141
- try self.options.platform.services.createTray(options);
142
- try storeTrayItems(self, options.items);
148
+ const status_item = try statusItemSlot(self, status_item_id);
149
+ const was_active = status_item.active;
150
+ try self.options.platform.services.createStatusItem(status_item_id, options);
151
+ try storeTrayItems(status_item, options.items);
143
152
  const title = if (options.presentation.title.len > 0) options.presentation.title else options.title;
144
- self.tray_title = try copyInto(&self.tray_title_storage, title);
145
- self.tray_created = true;
153
+ status_item.title = try copyInto(&status_item.title_storage, title);
154
+ status_item.id = status_item_id;
155
+ status_item.active = true;
156
+ status_item.visible = options.visible;
157
+ if (!was_active) self.status_item_count += 1;
146
158
  }
147
159
 
148
- pub fn updateTrayMenu(self: *Runtime, items: []const platform.TrayMenuItem) anyerror!void {
160
+ pub fn createTray(self: *Runtime, options: platform.TrayOptions) anyerror!void {
161
+ return self.createStatusItem(platform.primary_status_item_id, options);
162
+ }
163
+
164
+ pub fn updateStatusItemShell(self: *Runtime, status_item_id: platform.StatusItemId, shell: platform.TrayShell) anyerror!void {
165
+ try validation.validateStatusItemId(status_item_id);
166
+ try validateTrayShell(shell);
167
+ const status_item = findStatusItem(self, status_item_id) orelse return error.InvalidTrayOptions;
168
+ try self.options.platform.services.updateStatusItemShell(status_item_id, shell);
169
+ status_item.visible = shell.visible;
170
+ }
171
+
172
+ pub fn updateStatusItemMenu(self: *Runtime, status_item_id: platform.StatusItemId, items: []const platform.TrayMenuItem) anyerror!void {
173
+ try validation.validateStatusItemId(status_item_id);
149
174
  try validateTrayMenuItems(items);
150
- try self.options.platform.services.updateTrayMenu(items);
151
- try storeTrayItems(self, items);
175
+ const status_item = findStatusItem(self, status_item_id) orelse return error.InvalidTrayOptions;
176
+ try self.options.platform.services.updateStatusItemMenu(status_item_id, items);
177
+ try storeTrayItems(status_item, items);
178
+ }
179
+
180
+ pub fn updateTrayMenu(self: *Runtime, items: []const platform.TrayMenuItem) anyerror!void {
181
+ return self.updateStatusItemMenu(platform.primary_status_item_id, items);
152
182
  }
153
183
 
154
184
  /// Retitle the live status-bar button without re-creating the
155
185
  /// status item (a model-driven badge like "3 open" in the menu
156
186
  /// bar rides this seam). Platforms without the
157
187
  /// title seam report `UnsupportedService`; the menu keeps working.
158
- pub fn updateTrayTitle(self: *Runtime, title: []const u8) anyerror!void {
188
+ pub fn updateStatusItemTitle(self: *Runtime, status_item_id: platform.StatusItemId, title: []const u8) anyerror!void {
189
+ try validation.validateStatusItemId(status_item_id);
159
190
  try validateTrayTitle(title);
160
- try self.options.platform.services.updateTrayTitle(title);
161
- self.tray_title = try copyInto(&self.tray_title_storage, title);
191
+ const status_item = findStatusItem(self, status_item_id) orelse return error.InvalidTrayOptions;
192
+ try self.options.platform.services.updateStatusItemTitle(status_item_id, title);
193
+ status_item.title = try copyInto(&status_item.title_storage, title);
162
194
  }
163
195
 
164
- pub fn updateTrayPresentation(self: *Runtime, presentation: platform.TrayPresentation) anyerror!void {
196
+ pub fn updateTrayTitle(self: *Runtime, title: []const u8) anyerror!void {
197
+ return self.updateStatusItemTitle(platform.primary_status_item_id, title);
198
+ }
199
+
200
+ pub fn updateStatusItemPresentation(self: *Runtime, status_item_id: platform.StatusItemId, presentation: platform.TrayPresentation) anyerror!void {
201
+ try validation.validateStatusItemId(status_item_id);
165
202
  try validation.validateTrayPresentation(presentation);
166
- try self.options.platform.services.updateTrayPresentation(presentation);
167
- self.tray_title = try copyInto(&self.tray_title_storage, presentation.title);
203
+ const status_item = findStatusItem(self, status_item_id) orelse return error.InvalidTrayOptions;
204
+ try self.options.platform.services.updateStatusItemPresentation(status_item_id, presentation);
205
+ status_item.title = try copyInto(&status_item.title_storage, presentation.title);
206
+ }
207
+
208
+ pub fn updateTrayPresentation(self: *Runtime, presentation: platform.TrayPresentation) anyerror!void {
209
+ return self.updateStatusItemPresentation(platform.primary_status_item_id, presentation);
210
+ }
211
+
212
+ pub fn removeStatusItem(self: *Runtime, status_item_id: platform.StatusItemId) anyerror!void {
213
+ try validation.validateStatusItemId(status_item_id);
214
+ const status_item = findStatusItem(self, status_item_id) orelse return;
215
+ try self.options.platform.services.removeStatusItem(status_item_id);
216
+ status_item.* = .{};
217
+ self.status_item_count -= 1;
168
218
  }
169
219
 
170
220
  pub fn removeTray(self: *Runtime) anyerror!void {
171
- try self.options.platform.services.removeTray();
172
- self.tray_item_count = 0;
173
- self.tray_created = false;
174
- self.tray_title = "";
221
+ return self.removeStatusItem(platform.primary_status_item_id);
175
222
  }
176
223
 
177
- pub fn trayItemExists(self: *const Runtime, item_id: platform.TrayItemId) bool {
178
- for (self.tray_items[0..self.tray_item_count]) |item| {
224
+ pub fn statusItemExists(self: *const Runtime, status_item_id: platform.StatusItemId) bool {
225
+ return findStatusItemConst(self, status_item_id) != null;
226
+ }
227
+
228
+ pub fn statusItemMenuItemExists(self: *const Runtime, status_item_id: platform.StatusItemId, item_id: platform.TrayItemId) bool {
229
+ const status_item = findStatusItemConst(self, status_item_id) orelse return false;
230
+ for (status_item.items[0..status_item.item_count]) |item| {
179
231
  if (item.id == item_id) return true;
180
232
  }
181
233
  return false;
182
234
  }
183
235
 
184
- pub fn trayCommandNameForItem(self: *const Runtime, item_id: platform.TrayItemId) []const u8 {
185
- for (self.tray_items[0..self.tray_item_count]) |item| {
236
+ pub fn trayItemExists(self: *const Runtime, item_id: platform.TrayItemId) bool {
237
+ return self.statusItemMenuItemExists(platform.primary_status_item_id, item_id);
238
+ }
239
+
240
+ pub fn statusItemCommandNameForItem(self: *const Runtime, status_item_id: platform.StatusItemId, item_id: platform.TrayItemId) []const u8 {
241
+ const status_item = findStatusItemConst(self, status_item_id) orelse return "tray.action";
242
+ for (status_item.items[0..status_item.item_count]) |item| {
186
243
  if (item.id == item_id and item.command.len > 0) return item.command;
187
244
  }
188
245
  return "tray.action";
189
246
  }
190
247
 
248
+ pub fn trayCommandNameForItem(self: *const Runtime, item_id: platform.TrayItemId) []const u8 {
249
+ return self.statusItemCommandNameForItem(platform.primary_status_item_id, item_id);
250
+ }
251
+
191
252
  pub fn supportsFeatureFromJson(self: *Runtime, payload: []const u8, output: []u8) ![]const u8 {
192
253
  var scratch: [64]u8 = undefined;
193
254
  var storage = json.StringStorage.init(&scratch);
@@ -270,12 +331,21 @@ pub fn RuntimeSystemServices(comptime Runtime: type) type {
270
331
  pub fn showNotificationFromJson(self: *Runtime, payload: []const u8, output: []u8) ![]const u8 {
271
332
  var storage = json.StringStorage.init(output);
272
333
  const title = jsonStringField(payload, "title", &storage) orelse return error.InvalidNotificationOptions;
273
- const subtitle = jsonStringField(payload, "subtitle", &storage) orelse "";
274
- const body = jsonStringField(payload, "body", &storage) orelse jsonStringField(payload, "message", &storage) orelse "";
334
+ const subtitle = try optionalNotificationString(payload, "subtitle", &storage);
335
+ const body = if (json.fieldValue(payload, "body") != null)
336
+ try optionalNotificationString(payload, "body", &storage)
337
+ else
338
+ try optionalNotificationString(payload, "message", &storage);
339
+ const notification_id = try optionalNotificationString(payload, "id", &storage);
340
+ const action_label = try optionalNotificationString(payload, "actionLabel", &storage);
341
+ const action_command = try optionalNotificationString(payload, "actionCommand", &storage);
275
342
  try self.showNotification(.{
343
+ .id = notification_id,
276
344
  .title = title,
277
345
  .subtitle = subtitle,
278
346
  .body = body,
347
+ .action_label = action_label,
348
+ .action_command = action_command,
279
349
  });
280
350
  return writeTrueJson(output);
281
351
  }
@@ -398,20 +468,43 @@ pub fn RuntimeSystemServices(comptime Runtime: type) type {
398
468
  };
399
469
  }
400
470
 
401
- fn storeTrayItems(self: anytype, items: []const platform.TrayMenuItem) !void {
402
- self.tray_item_count = 0;
471
+ fn storeTrayItems(status_item: anytype, items: []const platform.TrayMenuItem) !void {
472
+ status_item.item_count = 0;
403
473
  for (items, 0..) |item, index| {
404
- self.tray_items[index].id = item.id;
405
- self.tray_items[index].command = try copyInto(&self.tray_items[index].command_storage, item.command);
406
- self.tray_items[index].label = try copyInto(&self.tray_items[index].label_storage, item.label);
407
- self.tray_items[index].detail = try copyInto(&self.tray_items[index].detail_storage, item.detail);
408
- self.tray_items[index].separator = item.separator;
409
- self.tray_items[index].enabled = item.enabled;
410
- self.tray_items[index].role = item.role;
411
- self.tray_items[index].key = try copyInto(&self.tray_items[index].key_storage, item.key);
412
- self.tray_items[index].modifiers = item.modifiers;
474
+ status_item.items[index].id = item.id;
475
+ status_item.items[index].command = try copyInto(&status_item.items[index].command_storage, item.command);
476
+ status_item.items[index].label = try copyInto(&status_item.items[index].label_storage, item.label);
477
+ status_item.items[index].detail = try copyInto(&status_item.items[index].detail_storage, item.detail);
478
+ status_item.items[index].separator = item.separator;
479
+ status_item.items[index].enabled = item.enabled;
480
+ status_item.items[index].role = item.role;
481
+ status_item.items[index].key = try copyInto(&status_item.items[index].key_storage, item.key);
482
+ status_item.items[index].modifiers = item.modifiers;
483
+ }
484
+ status_item.item_count = items.len;
485
+ }
486
+
487
+ fn findStatusItem(self: anytype, status_item_id: platform.StatusItemId) ?@TypeOf(&self.status_items[0]) {
488
+ for (&self.status_items) |*status_item| {
489
+ if (status_item.active and status_item.id == status_item_id) return status_item;
490
+ }
491
+ return null;
492
+ }
493
+
494
+ fn findStatusItemConst(self: anytype, status_item_id: platform.StatusItemId) ?@TypeOf(&self.status_items[0]) {
495
+ for (&self.status_items) |*status_item| {
496
+ if (status_item.active and status_item.id == status_item_id) return status_item;
497
+ }
498
+ return null;
499
+ }
500
+
501
+ fn statusItemSlot(self: anytype, status_item_id: platform.StatusItemId) !@TypeOf(&self.status_items[0]) {
502
+ if (findStatusItem(self, status_item_id)) |status_item| return status_item;
503
+ if (self.status_item_count >= self.status_items.len) return error.InvalidTrayOptions;
504
+ for (&self.status_items) |*status_item| {
505
+ if (!status_item.active) return status_item;
413
506
  }
414
- self.tray_item_count = items.len;
507
+ return error.InvalidTrayOptions;
415
508
  }
416
509
 
417
510
  fn validateExternalUrl(self: anytype, url: []const u8) !void {