@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.
- package/build/app.zig +331 -24
- package/build.zig +179 -11
- package/native-sdk.d.ts +8 -0
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +70 -1
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
- package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
- package/packages/core/scripts/stage_external_services.mjs +1 -1
- package/packages/core/sdk/core.d.ts +75 -0
- package/packages/core/sdk/core.ts +167 -12
- package/packages/core/sdk/events.d.ts +53 -0
- package/packages/core/sdk/events.ts +78 -7
- package/packages/core/src/checker.ts +470 -2
- package/packages/core/src/cli.ts +13 -0
- package/packages/core/src/contract.ts +3 -1
- package/packages/core/src/devhost.ts +30 -1
- package/packages/core/src/devhost_journal.mjs +10 -8
- package/packages/core/src/diagnostics.ts +99 -8
- package/packages/core/src/frontend.ts +6 -0
- package/packages/core/src/infer.ts +24 -0
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/native-ui/SKILL.md +11 -5
- package/skill-data/ts-core/SKILL.md +53 -20
- package/skill-data/ts-services/SKILL.md +4 -4
- package/skill-data/ts-services/references/service-surface.md +2 -1
- package/skill-data/zig/SKILL.md +1 -1
- package/src/app_runner/root.zig +29 -0
- package/src/app_runner/ts_core_main.zig +5 -0
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +8 -6
- package/src/embed/app_exports.zig +1 -0
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +28 -0
- package/src/embed/ui_host.zig +68 -2
- package/src/platform/linux/cef_host.cpp +7 -1
- package/src/platform/linux/gtk_host.c +200 -5
- package/src/platform/linux/gtk_host.h +2 -1
- package/src/platform/linux/root.zig +69 -4
- package/src/platform/macos/appkit_host.h +11 -7
- package/src/platform/macos/appkit_host.m +210 -88
- package/src/platform/macos/cef_host.mm +210 -88
- package/src/platform/macos/root.zig +77 -30
- package/src/platform/null_platform.zig +234 -51
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +10 -0
- package/src/platform/types.zig +105 -16
- package/src/platform/windows/root.zig +20 -6
- package/src/platform/windows/webview2_host.cpp +41 -5
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +8 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -24
- package/src/runtime/bridge_permission_tests.zig +35 -1
- package/src/runtime/bridge_responses.zig +1 -1
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/core.zig +12 -6
- package/src/runtime/effects.zig +1323 -35
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/file_access.zig +400 -0
- package/src/runtime/file_effect_crash_helper.zig +28 -0
- package/src/runtime/file_effect_crash_tests.zig +37 -0
- package/src/runtime/flow.zig +21 -9
- package/src/runtime/native_command_event_tests.zig +44 -2
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/root.zig +5 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +56 -5
- package/src/runtime/session_record.zig +38 -0
- package/src/runtime/session_replay.zig +97 -7
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/state.zig +10 -0
- package/src/runtime/system_services.zig +129 -36
- package/src/runtime/ts_core_host.zig +281 -11
- package/src/runtime/ts_core_host_tests.zig +95 -1
- package/src/runtime/ts_ui_app.zig +461 -8
- package/src/runtime/ui_app.zig +321 -109
- package/src/runtime/ui_app_tests.zig +132 -6
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +20 -0
- package/src/tooling/templates.zig +28 -0
- package/src/tooling/ts_core.zig +83 -0
- package/tools/corewire/emit.zig +3 -3
- package/tools/corewire/emit_facade.zig +65 -5
- package/tools/corewire/emit_profile.zig +2 -2
- package/tools/corewire/emit_service.zig +2 -2
- package/tools/corewire/service_contract.zig +4 -4
- package/tools/corewire/sidecar.zig +4 -4
|
@@ -377,10 +377,11 @@ test "runtime gates built-in OS bridge commands through explicit policy" {
|
|
|
377
377
|
try std.testing.expect(std.mem.indexOf(u8, denied.null_platform.lastBridgeResponse(), "OS API is not permitted") != null);
|
|
378
378
|
try std.testing.expect(std.mem.indexOf(u8, denied.null_platform.lastBridgeResponse(), "\"permission_denied\"") != null);
|
|
379
379
|
|
|
380
|
-
const grants = [_][]const u8{ security.permission_network, security.permission_filesystem, security.permission_notifications };
|
|
380
|
+
const grants = [_][]const u8{ security.permission_network, security.permission_filesystem, security.permission_notifications, security.permission_command };
|
|
381
381
|
const network_permission = [_][]const u8{security.permission_network};
|
|
382
382
|
const filesystem_permission = [_][]const u8{security.permission_filesystem};
|
|
383
383
|
const notifications_permission = [_][]const u8{security.permission_notifications};
|
|
384
|
+
const command_permission = [_][]const u8{security.permission_command};
|
|
384
385
|
const origins = [_][]const u8{"zero://inline"};
|
|
385
386
|
const policies = [_]bridge.CommandPolicy{
|
|
386
387
|
.{ .name = "native-sdk.os.openUrl", .permissions = &network_permission, .origins = &origins },
|
|
@@ -389,6 +390,14 @@ test "runtime gates built-in OS bridge commands through explicit policy" {
|
|
|
389
390
|
.{ .name = "native-sdk.os.addRecentDocument", .permissions = &filesystem_permission, .origins = &origins },
|
|
390
391
|
.{ .name = "native-sdk.os.clearRecentDocuments", .permissions = &filesystem_permission, .origins = &origins },
|
|
391
392
|
};
|
|
393
|
+
const action_policies = [_]bridge.CommandPolicy{
|
|
394
|
+
.{ .name = "native-sdk.os.openUrl", .permissions = &network_permission, .origins = &origins },
|
|
395
|
+
.{ .name = "native-sdk.os.showNotification", .permissions = ¬ifications_permission, .origins = &origins },
|
|
396
|
+
.{ .name = "native-sdk.os.revealPath", .permissions = &filesystem_permission, .origins = &origins },
|
|
397
|
+
.{ .name = "native-sdk.os.addRecentDocument", .permissions = &filesystem_permission, .origins = &origins },
|
|
398
|
+
.{ .name = "native-sdk.os.clearRecentDocuments", .permissions = &filesystem_permission, .origins = &origins },
|
|
399
|
+
.{ .name = "native-sdk.command.invoke", .permissions = &command_permission, .origins = &origins },
|
|
400
|
+
};
|
|
392
401
|
const allowed_urls = [_][]const u8{"https://example.com/*"};
|
|
393
402
|
|
|
394
403
|
const allowed = try TestHarness().create(std.testing.allocator, .{});
|
|
@@ -408,6 +417,31 @@ test "runtime gates built-in OS bridge commands through explicit policy" {
|
|
|
408
417
|
try std.testing.expectEqual(@as(usize, 1), allowed.null_platform.notificationCount());
|
|
409
418
|
try std.testing.expectEqualStrings("Build finished", allowed.null_platform.lastNotificationTitle());
|
|
410
419
|
|
|
420
|
+
try allowed.runtime.dispatchPlatformEvent(app, .{ .bridge_message = .{
|
|
421
|
+
.bytes = "{\"id\":\"action-denied\",\"command\":\"native-sdk.os.showNotification\",\"payload\":{\"id\":\"build\",\"title\":\"Build finished\",\"actionLabel\":\"Open\",\"actionCommand\":\"build.open\"}}",
|
|
422
|
+
.origin = "zero://inline",
|
|
423
|
+
} });
|
|
424
|
+
try std.testing.expect(std.mem.indexOf(u8, allowed.null_platform.lastBridgeResponse(), "Notification actions require command invoke permission") != null);
|
|
425
|
+
try std.testing.expectEqual(@as(usize, 1), allowed.null_platform.notificationCount());
|
|
426
|
+
|
|
427
|
+
allowed.runtime.options.builtin_bridge = .{ .enabled = true, .commands = &action_policies };
|
|
428
|
+
try allowed.runtime.dispatchPlatformEvent(app, .{ .bridge_message = .{
|
|
429
|
+
.bytes = "{\"id\":\"action-allowed\",\"command\":\"native-sdk.os.showNotification\",\"payload\":{\"id\":\"build\",\"title\":\"Build finished\",\"actionLabel\":\"Open\",\"actionCommand\":\"build.open\"}}",
|
|
430
|
+
.origin = "zero://inline",
|
|
431
|
+
} });
|
|
432
|
+
try std.testing.expect(std.mem.indexOf(u8, allowed.null_platform.lastBridgeResponse(), "\"ok\":true") != null);
|
|
433
|
+
try std.testing.expectEqual(@as(usize, 2), allowed.null_platform.notificationCount());
|
|
434
|
+
try std.testing.expectEqualStrings("build", allowed.null_platform.lastNotificationId());
|
|
435
|
+
try std.testing.expectEqualStrings("Open", allowed.null_platform.lastNotificationActionLabel());
|
|
436
|
+
try std.testing.expectEqualStrings("build.open", allowed.null_platform.lastNotificationActionCommand());
|
|
437
|
+
|
|
438
|
+
try allowed.runtime.dispatchPlatformEvent(app, .{ .bridge_message = .{
|
|
439
|
+
.bytes = "{\"id\":\"invalid-notification\",\"command\":\"native-sdk.os.showNotification\",\"payload\":{\"id\":42,\"title\":\"Build finished\"}}",
|
|
440
|
+
.origin = "zero://inline",
|
|
441
|
+
} });
|
|
442
|
+
try std.testing.expect(std.mem.indexOf(u8, allowed.null_platform.lastBridgeResponse(), "\"invalid_request\"") != null);
|
|
443
|
+
try std.testing.expectEqual(@as(usize, 2), allowed.null_platform.notificationCount());
|
|
444
|
+
|
|
411
445
|
try allowed.runtime.dispatchPlatformEvent(app, .{ .bridge_message = .{
|
|
412
446
|
.bytes = "{\"id\":\"open\",\"command\":\"native-sdk.os.openUrl\",\"payload\":{\"url\":\"https://example.com/docs\"}}",
|
|
413
447
|
.origin = "zero://inline",
|
|
@@ -49,7 +49,7 @@ pub fn writeCommandEventJson(event_value: anytype, output: []u8) ![]const u8 {
|
|
|
49
49
|
try json.writeString(&writer, @tagName(event_value.source));
|
|
50
50
|
try writer.print(",\"windowId\":{d},\"viewLabel\":", .{event_value.window_id});
|
|
51
51
|
try json.writeString(&writer, event_value.view_label);
|
|
52
|
-
try writer.print(",\"trayItemId\":{d}", .{event_value.tray_item_id});
|
|
52
|
+
try writer.print(",\"statusItemId\":{d},\"trayItemId\":{d}", .{ event_value.status_item_id, event_value.tray_item_id });
|
|
53
53
|
try writer.writeByte('}');
|
|
54
54
|
return writer.buffered();
|
|
55
55
|
}
|
|
@@ -186,7 +186,17 @@ pub fn RuntimeBuiltinBridge(comptime Runtime: type) type {
|
|
|
186
186
|
return bridge.writeSuccessResponse(response_buffer, request.id, result);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
pub fn dispatchOsBridgeCommand(self: *Runtime, request: bridge.Request, result_buffer: []u8, response_buffer: []u8) []const u8 {
|
|
189
|
+
pub fn dispatchOsBridgeCommand(self: *Runtime, request: bridge.Request, origin: []const u8, result_buffer: []u8, response_buffer: []u8) []const u8 {
|
|
190
|
+
if (std.mem.eql(u8, request.command, "native-sdk.os.showNotification")) {
|
|
191
|
+
var action_scratch: [platform.max_notification_action_command_bytes]u8 = undefined;
|
|
192
|
+
var action_storage = json.StringStorage.init(&action_scratch);
|
|
193
|
+
const action_command = jsonStringField(request.payload, "actionCommand", &action_storage) orelse "";
|
|
194
|
+
if (action_command.len > 0 and
|
|
195
|
+
!Self.allowsBuiltinBridgeCommand(self, "native-sdk.command.invoke", origin, security.permission_command))
|
|
196
|
+
{
|
|
197
|
+
return bridge.writeErrorResponse(response_buffer, request.id, .permission_denied, "Notification actions require command invoke permission");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
190
200
|
const result = if (std.mem.eql(u8, request.command, "native-sdk.os.openUrl"))
|
|
191
201
|
SystemServiceMethods.openExternalUrlFromJson(self, request.payload, result_buffer) catch |err| return bridge.writeErrorResponse(response_buffer, request.id, builtinBridgeErrorCode(err), builtinBridgeErrorMessage(err))
|
|
192
202
|
else if (std.mem.eql(u8, request.command, "native-sdk.os.showNotification"))
|
package/src/runtime/core.zig
CHANGED
|
@@ -101,6 +101,7 @@ const RuntimeMainWebViewState = runtime_state.RuntimeMainWebViewState;
|
|
|
101
101
|
const RuntimeSourceStorage = runtime_state.RuntimeSourceStorage;
|
|
102
102
|
const RuntimeWebView = runtime_state.RuntimeWebView;
|
|
103
103
|
const RuntimeTrayItem = runtime_state.RuntimeTrayItem;
|
|
104
|
+
const RuntimeStatusItem = runtime_state.RuntimeStatusItem;
|
|
104
105
|
const ShellApplyMode = runtime_state.ShellApplyMode;
|
|
105
106
|
const WindowSourcePolicy = runtime_state.WindowSourcePolicy;
|
|
106
107
|
const FocusTraversalDirection = runtime_state.FocusTraversalDirection;
|
|
@@ -205,11 +206,8 @@ pub const Runtime = struct {
|
|
|
205
206
|
view_count: usize = 0,
|
|
206
207
|
webviews: [platform.max_webviews]RuntimeWebView = undefined,
|
|
207
208
|
webview_count: usize = 0,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
tray_created: bool = false,
|
|
211
|
-
tray_title: []const u8 = "",
|
|
212
|
-
tray_title_storage: [platform.max_tray_title_bytes]u8 = undefined,
|
|
209
|
+
status_items: [platform.max_status_items]RuntimeStatusItem = [_]RuntimeStatusItem{.{}} ** platform.max_status_items,
|
|
210
|
+
status_item_count: usize = 0,
|
|
213
211
|
/// Audio playback mirror for the automation snapshot, stamped by
|
|
214
212
|
/// the ui-app layer whenever a dispatch or effect drain may have
|
|
215
213
|
/// moved the effects channel's playback state. Like the tray, the
|
|
@@ -325,7 +323,8 @@ pub const Runtime = struct {
|
|
|
325
323
|
/// list its full per-view item budget — the snapshot never truncates
|
|
326
324
|
/// menus the runtime accepted.
|
|
327
325
|
automation_widget_menu_items: [canvas_limits.max_canvas_widget_context_menu_items_per_view * platform.max_views]automation.snapshot.WidgetContextMenuItem = undefined,
|
|
328
|
-
automation_tray_items: [platform.max_tray_items]automation.snapshot.TrayItem = undefined,
|
|
326
|
+
automation_tray_items: [platform.max_status_items * platform.max_tray_items]automation.snapshot.TrayItem = undefined,
|
|
327
|
+
automation_trays: [platform.max_status_items]automation.snapshot.Tray = undefined,
|
|
329
328
|
/// Handshake for the `provenance` verb: cleared before the query is
|
|
330
329
|
/// evented to the app, set by the app's response publish — so the
|
|
331
330
|
/// dispatcher can answer with a teaching error when no app-side
|
|
@@ -777,11 +776,18 @@ pub const Runtime = struct {
|
|
|
777
776
|
pub const deleteCredential = SystemServiceMethods.deleteCredential;
|
|
778
777
|
pub const formatLocalTime = SystemServiceMethods.formatLocalTime;
|
|
779
778
|
pub const createTray = SystemServiceMethods.createTray;
|
|
779
|
+
pub const createStatusItem = SystemServiceMethods.createStatusItem;
|
|
780
|
+
pub const updateStatusItemShell = SystemServiceMethods.updateStatusItemShell;
|
|
781
|
+
pub const updateStatusItemMenu = SystemServiceMethods.updateStatusItemMenu;
|
|
782
|
+
pub const updateStatusItemTitle = SystemServiceMethods.updateStatusItemTitle;
|
|
783
|
+
pub const updateStatusItemPresentation = SystemServiceMethods.updateStatusItemPresentation;
|
|
784
|
+
pub const removeStatusItem = SystemServiceMethods.removeStatusItem;
|
|
780
785
|
pub const updateTrayMenu = SystemServiceMethods.updateTrayMenu;
|
|
781
786
|
pub const updateTrayTitle = SystemServiceMethods.updateTrayTitle;
|
|
782
787
|
pub const updateTrayPresentation = SystemServiceMethods.updateTrayPresentation;
|
|
783
788
|
pub const removeTray = SystemServiceMethods.removeTray;
|
|
784
789
|
const trayCommandNameForItem = SystemServiceMethods.trayCommandNameForItem;
|
|
790
|
+
const statusItemCommandNameForItem = SystemServiceMethods.statusItemCommandNameForItem;
|
|
785
791
|
const supportsFeatureFromJson = SystemServiceMethods.supportsFeatureFromJson;
|
|
786
792
|
const readClipboardTextFromJson = SystemServiceMethods.readClipboardTextFromJson;
|
|
787
793
|
const writeClipboardTextFromJson = SystemServiceMethods.writeClipboardTextFromJson;
|