@native-sdk/cli 0.4.4 → 0.5.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 (94) hide show
  1. package/build/app.zig +371 -5
  2. package/build/ts_run.mjs +102 -0
  3. package/build.zig +255 -1
  4. package/build.zig.zon +1 -0
  5. package/package.json +19 -10
  6. package/packages/core/package-lock.json +44 -0
  7. package/packages/core/package.json +38 -0
  8. package/packages/core/rt/rt.zig +1579 -0
  9. package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
  10. package/packages/core/sdk/core.ts +694 -0
  11. package/packages/core/sdk/events.ts +137 -0
  12. package/packages/core/sdk/text.ts +519 -0
  13. package/packages/core/src/checker.ts +1869 -0
  14. package/packages/core/src/cli.ts +68 -0
  15. package/packages/core/src/devhost.ts +291 -0
  16. package/packages/core/src/devhost_resolver.mjs +22 -0
  17. package/packages/core/src/diagnostics.ts +417 -0
  18. package/packages/core/src/emitter.ts +8815 -0
  19. package/packages/core/src/infer.ts +1515 -0
  20. package/packages/core/src/modules.ts +173 -0
  21. package/packages/core/src/ownership.ts +740 -0
  22. package/packages/core/src/text_polyfill.ts +337 -0
  23. package/packages/core/src/text_tables.ts +408 -0
  24. package/packages/core/src/transpile.ts +146 -0
  25. package/packages/core/src/typed_ast.ts +546 -0
  26. package/packages/core/src/types.ts +815 -0
  27. package/skill-data/native-ui/SKILL.md +14 -0
  28. package/skill-data/ts-core/SKILL.md +493 -0
  29. package/skill-data/zig/SKILL.md +10 -0
  30. package/src/app_runner/root.zig +24 -0
  31. package/src/app_runner/ts_core_main.zig +231 -0
  32. package/src/platform/windows/webview2_host.cpp +24 -0
  33. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  34. package/src/primitives/app_manifest/root.zig +5 -0
  35. package/src/primitives/canvas/commands.zig +14 -7
  36. package/src/primitives/canvas/layout_audit.zig +5 -5
  37. package/src/primitives/canvas/lazy_tls.zig +73 -0
  38. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  39. package/src/primitives/canvas/root.zig +11 -0
  40. package/src/primitives/canvas/tests.zig +1 -0
  41. package/src/primitives/canvas/text_atlas.zig +40 -32
  42. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  43. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  44. package/src/primitives/canvas/text_spans.zig +39 -26
  45. package/src/primitives/canvas/tokens.zig +69 -0
  46. package/src/primitives/canvas/ui.zig +125 -0
  47. package/src/primitives/canvas/ui_markup.zig +22 -3
  48. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  49. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  50. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  51. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  52. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  53. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  54. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  55. package/src/primitives/canvas/ui_schema.zig +8 -0
  56. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  57. package/src/primitives/canvas/widget_builtin_tests.zig +309 -5
  58. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  59. package/src/primitives/canvas/widget_layout.zig +138 -2
  60. package/src/primitives/canvas/widget_metrics.zig +16 -8
  61. package/src/primitives/canvas/widget_render.zig +25 -15
  62. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  63. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  64. package/src/root.zig +7 -0
  65. package/src/runtime/canvas_frame.zig +57 -36
  66. package/src/runtime/canvas_images.zig +9 -3
  67. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  68. package/src/runtime/canvas_widget_runtime.zig +7 -4
  69. package/src/runtime/core.zig +16 -0
  70. package/src/runtime/effects.zig +1525 -133
  71. package/src/runtime/effects_fetch_tests.zig +42 -0
  72. package/src/runtime/effects_file_tests.zig +220 -0
  73. package/src/runtime/effects_host_tests.zig +594 -0
  74. package/src/runtime/effects_tests.zig +287 -0
  75. package/src/runtime/root.zig +18 -0
  76. package/src/runtime/session_replay.zig +7 -1
  77. package/src/runtime/tests.zig +2 -0
  78. package/src/runtime/ts_core_host.zig +1505 -0
  79. package/src/runtime/ts_core_host_tests.zig +1408 -0
  80. package/src/runtime/ts_ui_app.zig +469 -0
  81. package/src/runtime/ui_app.zig +189 -38
  82. package/src/runtime/ui_app_tests.zig +221 -0
  83. package/src/runtime/ui_app_window_tests.zig +182 -0
  84. package/src/runtime/view_canvas.zig +24 -17
  85. package/src/runtime/view_widget_tree.zig +2 -2
  86. package/src/tooling/codesign.zig +212 -105
  87. package/src/tooling/doctor.zig +78 -0
  88. package/src/tooling/manifest.zig +47 -0
  89. package/src/tooling/package.zig +435 -20
  90. package/src/tooling/raw_manifest.zig +15 -0
  91. package/src/tooling/root.zig +1 -0
  92. package/src/tooling/templates.zig +777 -34
  93. package/src/tooling/ts_core.zig +1099 -0
  94. package/src/tooling/verbs.zig +105 -2
@@ -402,6 +402,188 @@ test "each window's tokens carry its own surface density, not the main canvas's"
402
402
  try std.testing.expectEqual(@as(f32, 1), main_after.pixel_snap.scale);
403
403
  }
404
404
 
405
+ // ------------------- window-control clearance in secondary windows
406
+
407
+ const CaptionWinModel = struct {
408
+ settings_open: bool = true,
409
+ /// The padded variant appends the contract spacer (the soundboard
410
+ /// pattern) so its header already clears the caption cluster.
411
+ padded: bool = false,
412
+ };
413
+
414
+ const CaptionWinMsg = union(enum) {
415
+ settings_closed,
416
+ };
417
+
418
+ const CaptionWinApp = ui_app_model.UiApp(CaptionWinModel, CaptionWinMsg);
419
+
420
+ fn captionWinUpdate(model: *CaptionWinModel, msg: CaptionWinMsg) void {
421
+ switch (msg) {
422
+ .settings_closed => model.settings_open = false,
423
+ }
424
+ }
425
+
426
+ fn captionWinView(ui: *CaptionWinApp.Ui, model: *const CaptionWinModel) CaptionWinApp.Ui.Node {
427
+ _ = model;
428
+ return ui.column(.{ .gap = 8, .padding = 12 }, .{
429
+ ui.text(.{}, "main body"),
430
+ });
431
+ }
432
+
433
+ fn captionWinWindows(model: *const CaptionWinModel, scratch: *CaptionWinApp.WindowsScratch) []const CaptionWinApp.WindowDescriptor {
434
+ var count: usize = 0;
435
+ if (model.settings_open) {
436
+ scratch.windows[count] = .{
437
+ .label = settings_window_label,
438
+ .canvas_label = settings_canvas_label,
439
+ .title = "Tools",
440
+ .width = 320,
441
+ .height = 240,
442
+ .on_close = .settings_closed,
443
+ };
444
+ count += 1;
445
+ }
446
+ return scratch.windows[0..count];
447
+ }
448
+
449
+ /// A hidden-inset SECONDARY window's titlebar: a drag row with a
450
+ /// leading title and a right-aligned status text — the same
451
+ /// system-monitor shape the main-canvas caption tests use, but built
452
+ /// through `window_view` and `rebuildWindowSlot`.
453
+ fn captionWinWindowView(ui: *CaptionWinApp.Ui, model: *const CaptionWinModel, window_label: []const u8) CaptionWinApp.Ui.Node {
454
+ std.debug.assert(std.mem.eql(u8, window_label, settings_window_label));
455
+ if (model.padded) {
456
+ return ui.column(.{}, .{
457
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
458
+ ui.text(.{}, "Tools"),
459
+ ui.el(.stack, .{ .grow = 1 }, .{}),
460
+ ui.text(.{}, "recording"),
461
+ ui.el(.stack, .{ .width = 138 }, .{}),
462
+ }),
463
+ ui.text(.{}, "body"),
464
+ });
465
+ }
466
+ return ui.column(.{}, .{
467
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
468
+ ui.text(.{}, "Tools"),
469
+ ui.el(.stack, .{ .grow = 1 }, .{}),
470
+ ui.text(.{}, "recording"),
471
+ }),
472
+ ui.text(.{}, "body"),
473
+ });
474
+ }
475
+
476
+ const CaptionWinFixture = struct {
477
+ harness: *core.TestHarness(),
478
+ app_state: *CaptionWinApp,
479
+ app: core.App,
480
+ settings_id: support.platform.WindowId,
481
+
482
+ /// Start the app with Windows-shaped hidden-titlebar chrome (the
483
+ /// DWM caption cluster overlays the trailing 138pt of the 320pt
484
+ /// secondary window's top band) and install both canvases.
485
+ fn create(padded: bool) !CaptionWinFixture {
486
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
487
+ errdefer harness.destroy(std.testing.allocator);
488
+ harness.null_platform.gpu_surfaces = true;
489
+ harness.null_platform.window_chrome = .{
490
+ .insets = .{ .top = 32, .right = 138 },
491
+ .buttons = geometry.RectF.init(182, 0, 138, 32),
492
+ };
493
+ const app_state = try CaptionWinApp.create(std.heap.page_allocator, .{
494
+ .name = "ui-app-caption-window",
495
+ .scene = panel_scene,
496
+ .canvas_label = canvas_label,
497
+ .update = captionWinUpdate,
498
+ .view = captionWinView,
499
+ .windows_fn = captionWinWindows,
500
+ .window_view = captionWinWindowView,
501
+ });
502
+ errdefer app_state.destroy();
503
+ app_state.model.padded = padded;
504
+ const app = app_state.app();
505
+ try harness.start(app);
506
+ // The model declares the settings window from the start, so the
507
+ // main canvas's installing rebuild creates it.
508
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
509
+ .label = canvas_label,
510
+ .size = geometry.SizeF.init(400, 300),
511
+ .scale_factor = 1,
512
+ .frame_index = 1,
513
+ .timestamp_ns = 1_000_000,
514
+ .nonblank = true,
515
+ } });
516
+ var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
517
+ var settings_id: support.platform.WindowId = 0;
518
+ for (harness.runtime.listWindows(&buffer)) |info| {
519
+ if (std.mem.eql(u8, info.label, settings_window_label)) settings_id = info.id;
520
+ }
521
+ if (settings_id == 0) return error.TestUnexpectedResult;
522
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
523
+ .window_id = settings_id,
524
+ .label = settings_canvas_label,
525
+ .size = geometry.SizeF.init(320, 240),
526
+ .scale_factor = 1,
527
+ .frame_index = 1,
528
+ .timestamp_ns = 2_000_000,
529
+ .nonblank = true,
530
+ } });
531
+ return .{ .harness = harness, .app_state = app_state, .app = app, .settings_id = settings_id };
532
+ }
533
+
534
+ fn destroy(self: CaptionWinFixture) void {
535
+ self.app_state.destroy();
536
+ self.harness.destroy(std.testing.allocator);
537
+ }
538
+
539
+ fn textFrame(self: CaptionWinFixture, window_id: support.platform.WindowId, label: []const u8, text: []const u8) !geometry.RectF {
540
+ const layout = try self.harness.runtime.canvasWidgetLayout(window_id, label);
541
+ for (layout.nodes) |node| {
542
+ if (node.widget.kind == .text and std.mem.eql(u8, node.widget.text, text)) return node.frame;
543
+ }
544
+ return error.TestUnexpectedResult;
545
+ }
546
+ };
547
+
548
+ test "a secondary window's drag header content stays clear of the Windows caption cluster" {
549
+ // The naive shape: the window view never consumed the chrome
550
+ // channel, so its right-aligned status would lay out flush to the
551
+ // window edge — UNDER the min/max/close buttons. `rebuildWindowSlot`
552
+ // must run the same collision scan + one-retry clearance the main
553
+ // rebuild runs, with the cluster stamped into the SLOT's tokens.
554
+ const fixture = try CaptionWinFixture.create(false);
555
+ defer fixture.destroy();
556
+
557
+ // The trailing status text ends at (or before) the cluster's
558
+ // leading edge (182 = 320 - 138); without the reservation it ended
559
+ // at the window's right edge, inside the cluster.
560
+ const status = try fixture.textFrame(fixture.settings_id, settings_canvas_label, "recording");
561
+ try std.testing.expect(status.maxX() <= 182 + 0.01);
562
+ // The leading title and the body below the band are untouched.
563
+ const title = try fixture.textFrame(fixture.settings_id, settings_canvas_label, "Tools");
564
+ try std.testing.expectEqual(@as(f32, 0), title.x);
565
+
566
+ // The stamp lived in a LOCAL copy of the slot's tokens: the main
567
+ // canvas (no drag header, no collision) keeps an unstamped stored
568
+ // set and its own layout.
569
+ const main_stored = try fixture.harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
570
+ try std.testing.expect(main_stored.window_controls == null);
571
+ const main_body = try fixture.textFrame(1, canvas_label, "main body");
572
+ try std.testing.expectEqual(@as(f32, 12), main_body.x);
573
+ }
574
+
575
+ test "a padded secondary drag header keeps its layout (no double reservation)" {
576
+ // The contract shape: the header's own trailing spacer already
577
+ // clears the cluster, so nothing collides and the slot retry must
578
+ // NOT fire — a double reservation would shove the status text a
579
+ // full cluster-width further left (near 182 - 138 = 44).
580
+ const fixture = try CaptionWinFixture.create(true);
581
+ defer fixture.destroy();
582
+
583
+ const status = try fixture.textFrame(fixture.settings_id, settings_canvas_label, "recording");
584
+ try std.testing.expect(@abs(status.maxX() - 182) < 0.5);
585
+ }
586
+
405
587
  // ------------------------------------------------- window-action effects
406
588
 
407
589
  const VerbModel = struct {
@@ -209,8 +209,14 @@ fn addCanvasCount(value: *usize, amount: usize, max_value: usize, comptime failu
209
209
  /// the half-full bound; small lists keep the linear scans.
210
210
  const summary_id_index_slots = 4096;
211
211
  const SummaryIdIndex = canvas.plan_key_index.HashSlots(summary_id_index_slots);
212
- threadlocal var summary_current_id_index: SummaryIdIndex = .{};
213
- threadlocal var summary_presented_id_index: SummaryIdIndex = .{};
212
+ // Lazily heap-allocated per thread (32 KiB of probe tables): reset per
213
+ // diff, so first-use init on the diffing thread is the only contract —
214
+ // threads that never diff summaries never allocate it.
215
+ const SummaryIdScratch = struct {
216
+ current: SummaryIdIndex = .{},
217
+ presented: SummaryIdIndex = .{},
218
+ };
219
+ const summary_id_scratch = canvas.lazy_tls.LazyTls(SummaryIdScratch);
214
220
 
215
221
  pub const PresentedCanvasCommand = struct {
216
222
  id: ?canvas.ObjectId = null,
@@ -647,28 +653,29 @@ pub fn RuntimeViewCanvasFrame(comptime RuntimeView: type) type {
647
653
  presented.len >= canvas.plan_key_index.min_entries_for_index) and
648
654
  canvas.plan_key_index.fitsHashSlots(summary_id_index_slots, current_commands.len) and
649
655
  canvas.plan_key_index.fitsHashSlots(summary_id_index_slots, presented.len);
650
- if (use_index) {
651
- summary_current_id_index.reset();
656
+ const id_scratch: ?*SummaryIdScratch = if (use_index) summary_id_scratch.get() else null;
657
+ if (id_scratch) |scratch| {
658
+ scratch.current.reset();
652
659
  for (current_commands, 0..) |command, index| {
653
660
  const id = command.objectId() orelse continue;
654
661
  var p = SummaryIdIndex.probe(canvas.plan_key_index.mixHash(id));
655
- while (summary_current_id_index.next(&p)) |_| {}
656
- summary_current_id_index.insert(p, @intCast(index));
662
+ while (scratch.current.next(&p)) |_| {}
663
+ scratch.current.insert(p, @intCast(index));
657
664
  }
658
- summary_presented_id_index.reset();
665
+ scratch.presented.reset();
659
666
  for (presented, 0..) |command, index| {
660
667
  const id = command.id orelse continue;
661
668
  var p = SummaryIdIndex.probe(canvas.plan_key_index.mixHash(id));
662
- while (summary_presented_id_index.next(&p)) |_| {}
663
- summary_presented_id_index.insert(p, @intCast(index));
669
+ while (scratch.presented.next(&p)) |_| {}
670
+ scratch.presented.insert(p, @intCast(index));
664
671
  }
665
672
  }
666
673
 
667
674
  var len: usize = 0;
668
675
  for (presented) |previous| {
669
676
  const id = previous.id orelse continue;
670
- const current_ref = if (use_index)
671
- currentCanvasCommandByIdIndexed(current_commands, id)
677
+ const current_ref = if (id_scratch) |scratch|
678
+ currentCanvasCommandByIdIndexed(&scratch.current, current_commands, id)
672
679
  else
673
680
  self.currentCanvasCommandById(id);
674
681
  if (current_ref == null) {
@@ -683,8 +690,8 @@ pub fn RuntimeViewCanvasFrame(comptime RuntimeView: type) type {
683
690
  for (current_commands, 0..) |command, index| {
684
691
  const id = command.objectId() orelse continue;
685
692
  const bounds = command.bounds();
686
- const previous_ref = if (use_index)
687
- presentedCanvasCommandByIdIndexed(presented, id)
693
+ const previous_ref = if (id_scratch) |scratch|
694
+ presentedCanvasCommandByIdIndexed(&scratch.presented, presented, id)
688
695
  else
689
696
  self.presentedCanvasCommandById(id);
690
697
  if (previous_ref) |previous| {
@@ -708,17 +715,17 @@ pub fn RuntimeViewCanvasFrame(comptime RuntimeView: type) type {
708
715
  return output[0..len];
709
716
  }
710
717
 
711
- fn currentCanvasCommandByIdIndexed(commands: []const canvas.CanvasCommand, id: canvas.ObjectId) ?canvas.CommandRef {
718
+ fn currentCanvasCommandByIdIndexed(current_index: *const SummaryIdIndex, commands: []const canvas.CanvasCommand, id: canvas.ObjectId) ?canvas.CommandRef {
712
719
  var p = SummaryIdIndex.probe(canvas.plan_key_index.mixHash(id));
713
- while (summary_current_id_index.next(&p)) |candidate| {
720
+ while (current_index.next(&p)) |candidate| {
714
721
  if (commands[candidate].objectId() == id) return .{ .index = candidate, .command = commands[candidate] };
715
722
  }
716
723
  return null;
717
724
  }
718
725
 
719
- fn presentedCanvasCommandByIdIndexed(presented: []const PresentedCanvasCommand, id: canvas.ObjectId) ?PresentedCanvasCommandRef {
726
+ fn presentedCanvasCommandByIdIndexed(presented_index: *const SummaryIdIndex, presented: []const PresentedCanvasCommand, id: canvas.ObjectId) ?PresentedCanvasCommandRef {
720
727
  var p = SummaryIdIndex.probe(canvas.plan_key_index.mixHash(id));
721
- while (summary_presented_id_index.next(&p)) |candidate| {
728
+ while (presented_index.next(&p)) |candidate| {
722
729
  if (presented[candidate].id == id) return .{ .index = candidate, .command = presented[candidate] };
723
730
  }
724
731
  return null;
@@ -226,10 +226,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
226
226
  );
227
227
 
228
228
  // Per-pass probe-table indices over the collected entry lists
229
- // (shared threadlocal scratch; see the reconcile-id-index note
229
+ // (shared per-thread scratch; see the reconcile-id-index note
230
230
  // in canvas_widget_runtime.zig). Lookups return exactly what
231
231
  // the linear scans returned; only the search cost changes.
232
- const index_scratch = &canvas_widget_runtime.canvas_widget_reconcile_index_scratch;
232
+ const index_scratch = canvas_widget_runtime.canvas_widget_reconcile_index_scratch.get();
233
233
  index_scratch.controls.build(previous_control_states);
234
234
  index_scratch.source_controls.build(self.widgetSourceControlEntries());
235
235
  index_scratch.texts.build(previous_text_states);