@native-sdk/cli 0.9.2 → 0.9.3

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 (47) hide show
  1. package/build.zig +69 -1
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/events.d.ts +7 -0
  6. package/packages/core/sdk/events.ts +26 -5
  7. package/packages/core/sdk/text.d.ts +4 -0
  8. package/packages/core/sdk/text.ts +51 -0
  9. package/packages/core/src/checker.ts +58 -1
  10. package/packages/core/src/contract.ts +5 -4
  11. package/packages/core/src/devhost_journal.mjs +2 -2
  12. package/packages/core/src/diagnostics.ts +2 -2
  13. package/packages/core/src/service_contract.ts +10 -0
  14. package/packages/core/src/typed_ast.ts +9 -7
  15. package/packages/core/src/types.ts +28 -8
  16. package/skill-data/automation/SKILL.md +4 -3
  17. package/skill-data/native-ui/SKILL.md +3 -1
  18. package/skill-data/ts-core/SKILL.md +7 -4
  19. package/src/app_runner/root.zig +208 -6
  20. package/src/app_runner/ts_core_main.zig +2 -0
  21. package/src/automation/protocol.zig +5 -1
  22. package/src/automation/snapshot.zig +119 -0
  23. package/src/platform/macos/appkit_host.m +79 -12
  24. package/src/platform/macos/root.zig +68 -5
  25. package/src/primitives/canvas/events.zig +79 -1
  26. package/src/primitives/canvas/root.zig +1 -0
  27. package/src/primitives/canvas/text_interaction.zig +23 -0
  28. package/src/primitives/canvas/text_tests.zig +45 -0
  29. package/src/primitives/canvas/ui.zig +11 -8
  30. package/src/primitives/canvas/ui_markup_compiled_tests.zig +3 -0
  31. package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
  32. package/src/primitives/canvas/ui_markup_view_tests.zig +18 -2
  33. package/src/primitives/canvas/ui_tests.zig +37 -0
  34. package/src/primitives/canvas/widget_builtin_tests.zig +13 -0
  35. package/src/runtime/automation_snapshot.zig +4 -0
  36. package/src/runtime/canvas_widget_control_tests.zig +2 -0
  37. package/src/runtime/canvas_widget_text_tests.zig +124 -0
  38. package/src/runtime/native_command_event_tests.zig +29 -0
  39. package/src/runtime/session_journal.zig +21 -2
  40. package/src/runtime/ts_ui_app.zig +164 -1
  41. package/src/runtime/ui_app.zig +91 -18
  42. package/src/runtime/ui_app_tests.zig +232 -13
  43. package/src/runtime/view_widget_text.zig +1 -1
  44. package/src/tooling/verbs.zig +1 -0
  45. package/tools/corewire/emit.zig +31 -12
  46. package/tools/corewire/emit_facade.zig +57 -2
  47. package/tools/corewire/shim_rt.zig +20 -0
@@ -42,17 +42,31 @@ const Sidecar = sidecar_mod.Sidecar;
42
42
  const TypeRef = sidecar_mod.TypeRef;
43
43
  const Payload = sidecar_mod.Payload;
44
44
 
45
- /// The eleven text-input event tags the markup engines recognize
45
+ /// Comptime string scans pay for every arm and every byte in its name.
46
+ /// Keep the generated consistency fence independent of Zig's default
47
+ /// 1000-backwards-branch quota: the sidecar admits 256 arms, and long legal
48
+ /// TypeScript identifiers must remain legal here too. The fixed floor covers
49
+ /// the surrounding reflection; the linear terms leave generous headroom over
50
+ /// `std.mem.eql`'s scalar comptime path.
51
+ fn msgTagConsistencyQuota(arms: []const sidecar_mod.MsgArm) u32 {
52
+ var name_bytes: u64 = 0;
53
+ for (arms) |arm| name_bytes += arm.name.len;
54
+ const quota: u64 = 100_000 + @as(u64, arms.len) * 1_024 + name_bytes * 256;
55
+ return @intCast(@min(quota, std.math.maxInt(u32)));
56
+ }
57
+
58
+ /// The thirteen text-input event tags the markup engines recognize
46
59
  /// structurally; a union payload carrying exactly these dispatches
47
60
  /// through the ABI's text_input entry.
48
61
  const text_input_event_tags = [_][]const u8{
49
- "insert_text", "delete_backward", "delete_forward", "delete_word_backward",
50
- "delete_word_forward", "clear", "move_caret", "set_selection",
51
- "set_composition", "commit_composition", "cancel_composition",
62
+ "insert_text", "delete_backward", "delete_forward", "delete_word_backward",
63
+ "delete_word_forward", "delete_to_start", "delete_to_line_start", "clear",
64
+ "move_caret", "set_selection", "set_composition", "commit_composition",
65
+ "cancel_composition",
52
66
  };
53
67
 
54
68
  /// Whether a union payload declares the text-input event shape the markup
55
- /// engines route through the dedicated ABI entry: exactly the eleven tags,
69
+ /// engines route through the dedicated ABI entry: exactly the thirteen tags,
56
70
  /// with the same structural payload vocabulary. This is public because the
57
71
  /// generated facade must make the identical decision when selecting the one
58
72
  /// sentinel-saturating decoder; one contract cannot have two recognizers.
@@ -883,6 +897,7 @@ const Emitter = struct {
883
897
  }
884
898
 
885
899
  fn tagTable(self: *Emitter) Error!void {
900
+ const consistency_quota = msgTagConsistencyQuota(self.sidecar.msg.arms);
886
901
  try self.raw(
887
902
  \\
888
903
  \\/// Declaration-order wire tags: the arm's index in this table IS
@@ -898,16 +913,17 @@ const Emitter = struct {
898
913
  try self.print(
899
914
  \\
900
915
  \\comptime {{
916
+ \\ @setEvalBranchQuota({d});
901
917
  \\ // The union and the tag table are emitted from one arm list;
902
918
  \\ // hold them equal anyway so a hand edit cannot skew dispatch.
903
919
  \\ const fields = @typeInfo({f}).@"union".fields;
904
- \\ if (fields.len != msg_tags.len) @compileError("core_shim: msg_tags and the message union disagree — regenerate from the sidecar");
920
+ \\ if (fields.len != msg_tags.len) @compileError("core_shim: Msg arm count does not match msg_tags");
905
921
  \\ for (fields, msg_tags) |field, tag_name| {{
906
- \\ if (!std.mem.eql(u8, field.name, tag_name)) @compileError("core_shim: msg_tags and the message union disagree — regenerate from the sidecar");
922
+ \\ if (!std.mem.eql(u8, field.name, tag_name)) @compileError("core_shim: Msg arm names do not match msg_tags");
907
923
  \\ }}
908
924
  \\}}
909
925
  \\
910
- , .{ident(self.sidecar.msg.name)});
926
+ , .{ consistency_quota, ident(self.sidecar.msg.name) });
911
927
  }
912
928
 
913
929
  // --------------------------------------------------- entry points
@@ -1852,6 +1868,8 @@ test "u64 attestations on selection bounds are accepted (the host supplies unsig
1852
1868
  \\ {"name": "delete_forward", "payload": {"kind": "void"}},
1853
1869
  \\ {"name": "delete_word_backward", "payload": {"kind": "void"}},
1854
1870
  \\ {"name": "delete_word_forward", "payload": {"kind": "void"}},
1871
+ \\ {"name": "delete_to_start", "payload": {"kind": "void"}},
1872
+ \\ {"name": "delete_to_line_start", "payload": {"kind": "void"}},
1855
1873
  \\ {"name": "clear", "payload": {"kind": "void"}},
1856
1874
  \\ {"name": "move_caret", "payload": {"kind": "value", "name": "Move"}},
1857
1875
  \\ {"name": "set_selection", "payload": {"kind": "value", "name": "Sel"}},
@@ -2210,14 +2228,15 @@ test "a text-input-named union without the payload shapes rides the record entry
2210
2228
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
2211
2229
  defer arena_state.deinit();
2212
2230
  const arena = arena_state.allocator();
2213
- // Eleven right names, wrong insert_text payload (void): the markup
2231
+ // Thirteen right names, wrong insert_text payload (void): the markup
2214
2232
  // predicate would not bind this as text input, so dispatch must
2215
2233
  // not route it to the text_input entry either.
2216
2234
  var arms: std.ArrayListUnmanaged(u8) = .empty;
2217
2235
  const tags = [_][]const u8{
2218
- "insert_text", "delete_backward", "delete_forward", "delete_word_backward",
2219
- "delete_word_forward", "clear", "move_caret", "set_selection",
2220
- "set_composition", "commit_composition", "cancel_composition",
2236
+ "insert_text", "delete_backward", "delete_forward", "delete_word_backward",
2237
+ "delete_word_forward", "delete_to_start", "delete_to_line_start", "clear",
2238
+ "move_caret", "set_selection", "set_composition", "commit_composition",
2239
+ "cancel_composition",
2221
2240
  };
2222
2241
  for (tags, 0..) |tag, index| {
2223
2242
  if (index > 0) try arms.appendSlice(arena, ", ");
@@ -2101,14 +2101,24 @@ const FacadeEmitter = struct {
2101
2101
  },
2102
2102
  .bytes => {
2103
2103
  self.use(.w_bytes);
2104
- try self.print("{s}nscfWBytes(sink, {s});\n", .{ pad, expr });
2104
+ if (self.isThemeStateAccent(container, member)) {
2105
+ // ThemeState.accent is author-facing `string` (the
2106
+ // ergonomic "#rrggbb" API) but the core ABI's one text
2107
+ // representation is bytes. The contract intentionally
2108
+ // reflects strings as bytes; bridge this one exact
2109
+ // launcher record at the generated boundary.
2110
+ self.use(.utf8_text);
2111
+ try self.print("{s}nscfWBytes(sink, nscfUtf8TextBytes({s}));\n", .{ pad, expr });
2112
+ } else {
2113
+ try self.print("{s}nscfWBytes(sink, {s});\n", .{ pad, expr });
2114
+ }
2105
2115
  },
2106
2116
  .void => {},
2107
2117
  .optional => |inner| {
2108
2118
  self.use(.w_bool);
2109
2119
  const temp = try std.fmt.allocPrint(self.arena, "nscfOpt{d}", .{self.temp_counter});
2110
2120
  self.temp_counter += 1;
2111
- try self.print("{s}const {s} = {s};\n{s}if ({s} === null) {{\n{s} nscfWBool(sink, false);\n{s}}} else {{\n{s} nscfWBool(sink, true);\n", .{ pad, temp, expr, pad, temp, pad, pad, pad });
2121
+ try self.print("{s}const {s} = {s};\n{s}if ({s} === null || {s} === undefined) {{\n{s} nscfWBool(sink, false);\n{s}}} else {{\n{s} nscfWBool(sink, true);\n", .{ pad, temp, expr, pad, temp, temp, pad, pad, pad });
2112
2122
  try self.fieldWriteStatements(inner.*, temp, container, member, depth + 1);
2113
2123
  try self.print("{s}}}\n", .{pad});
2114
2124
  },
@@ -2145,6 +2155,18 @@ const FacadeEmitter = struct {
2145
2155
  }
2146
2156
  }
2147
2157
 
2158
+ fn isThemeStateAccent(self: *FacadeEmitter, container: []const u8, member: []const u8) bool {
2159
+ if (!std.mem.eql(u8, member, "accent")) return false;
2160
+ for (self.sidecar.model_helpers) |helper| {
2161
+ if (!std.mem.eql(u8, helper.name, "themeState")) continue;
2162
+ return switch (helper.returns) {
2163
+ .node, .value => |name| std.mem.eql(u8, name, container),
2164
+ else => false,
2165
+ };
2166
+ }
2167
+ return false;
2168
+ }
2169
+
2148
2170
  fn recordWriter(self: *FacadeEmitter, name: []const u8) Error!void {
2149
2171
  const entry = sidecar_mod.findStruct(self.sidecar.types, name).?;
2150
2172
  self.use(.sink);
@@ -4004,6 +4026,37 @@ test "helpers wrap in declaration order with classed-return proofs" {
4004
4026
  try testing.expect(std.mem.indexOf(u8, generated, "nscfWI64(sink, nscfValue);") != null);
4005
4027
  }
4006
4028
 
4029
+ test "themeState helper encodes omitted fields and UTF-8 string accent" {
4030
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
4031
+ defer arena_state.deinit();
4032
+ const arena = arena_state.allocator();
4033
+ var source = try std.mem.replaceOwned(
4034
+ u8,
4035
+ arena,
4036
+ sidecar_mod.minimal_valid_json,
4037
+ "\"structs\": [",
4038
+ "\"structs\": [\n {\"name\": \"ThemeState\", \"origin\": \"sdk/events.ts\", \"fields\": [{\"name\": \"pack\", \"type\": {\"kind\": \"optional\", \"inner\": {\"kind\": \"enum\", \"name\": \"ThemeStatePack\"}}}, {\"name\": \"colorScheme\", \"type\": {\"kind\": \"optional\", \"inner\": {\"kind\": \"enum\", \"name\": \"ThemeStateColorScheme\"}}}, {\"name\": \"accent\", \"type\": {\"kind\": \"optional\", \"inner\": {\"kind\": \"bytes\"}}}] },",
4039
+ );
4040
+ source = try std.mem.replaceOwned(
4041
+ u8,
4042
+ arena,
4043
+ source,
4044
+ "\"enums\": []",
4045
+ "\"enums\": [{\"name\": \"ThemeStatePack\", \"origin\": \"sdk/events.ts\", \"members\": [\"house\", \"geist\"]}, {\"name\": \"ThemeStateColorScheme\", \"origin\": \"sdk/events.ts\", \"members\": [\"light\", \"dark\", \"system\"]}]",
4046
+ );
4047
+ source = try std.mem.replaceOwned(
4048
+ u8,
4049
+ arena,
4050
+ source,
4051
+ "\"model_helpers\": []",
4052
+ "\"model_helpers\": [{\"name\": \"themeState\", \"params\": [], \"returns\": {\"kind\": \"value\", \"name\": \"ThemeState\"}, \"arena\": false}]",
4053
+ );
4054
+ const generated = try facadeFromJson(arena, source);
4055
+ try testing.expect(std.mem.indexOf(u8, generated, "=== null ||") != null);
4056
+ try testing.expect(std.mem.indexOf(u8, generated, "=== undefined") != null);
4057
+ try testing.expect(std.mem.indexOf(u8, generated, "nscfWBytes(sink, nscfUtf8TextBytes(") != null);
4058
+ }
4059
+
4007
4060
  test "nullable integer helper returns prove their present branch" {
4008
4061
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
4009
4062
  defer arena_state.deinit();
@@ -4424,6 +4477,8 @@ test "text-input selection saturates signed and unsigned select-all sentinels" {
4424
4477
  \\ {"name": "delete_forward", "payload": {"kind": "void"}},
4425
4478
  \\ {"name": "delete_word_backward", "payload": {"kind": "void"}},
4426
4479
  \\ {"name": "delete_word_forward", "payload": {"kind": "void"}},
4480
+ \\ {"name": "delete_to_start", "payload": {"kind": "void"}},
4481
+ \\ {"name": "delete_to_line_start", "payload": {"kind": "void"}},
4427
4482
  \\ {"name": "clear", "payload": {"kind": "void"}},
4428
4483
  \\ {"name": "move_caret", "member": "move", "payload": {"kind": "value", "name": "Move"}},
4429
4484
  \\ {"name": "set_selection", "member": "selection", "payload": {"kind": "value", "name": "Sel"}},
@@ -92,6 +92,24 @@ var model_arenas = [2]std.heap.ArenaAllocator{
92
92
  };
93
93
  var model_arena_index: u1 = 0;
94
94
 
95
+ /// Quota for one comptime reflection pass over a record/union/enum. Canonical
96
+ /// encoding specializes over sidecar-shaped types, whose legal 256-arm unions
97
+ /// and long authored names can outrun Zig's default quota while resolving an
98
+ /// arm index. Scale with both entries and identifier bytes so app code never
99
+ /// has to raise a quota for generated shim work.
100
+ fn typeScanQuota(comptime T: type) u32 {
101
+ const fields = switch (@typeInfo(T)) {
102
+ .@"struct" => |info| info.fields,
103
+ .@"union" => |info| info.fields,
104
+ .@"enum" => |info| info.fields,
105
+ else => return 2_000,
106
+ };
107
+ var name_bytes: u64 = 0;
108
+ for (fields) |field| name_bytes += field.name.len;
109
+ const quota: u64 = 100_000 + @as(u64, fields.len) * 1_024 + name_bytes * 256;
110
+ return @intCast(@min(quota, std.math.maxInt(u32)));
111
+ }
112
+
95
113
  /// Decode a committed-model snapshot into a fresh mirror root. The
96
114
  /// PREVIOUS decode's root stays valid until the decode after this one;
97
115
  /// anything older is gone (the host holds exactly one committed root at
@@ -116,6 +134,7 @@ pub fn encodeAlloc(comptime T: type, value: T, allocator: std.mem.Allocator) []c
116
134
  }
117
135
 
118
136
  fn encodeInto(comptime T: type, value: T, allocator: std.mem.Allocator, out: *std.ArrayListUnmanaged(u8)) error{OutOfMemory}!void {
137
+ @setEvalBranchQuota(comptime typeScanQuota(T));
119
138
  switch (@typeInfo(T)) {
120
139
  .bool => try out.append(allocator, @intFromBool(value)),
121
140
  .int => {
@@ -220,6 +239,7 @@ pub const Reader = struct {
220
239
  /// records and slices into `allocator` (the shim frame arena in the
221
240
  /// dispatch path).
222
241
  pub fn decode(comptime T: type, reader: *Reader, allocator: std.mem.Allocator) T {
242
+ @setEvalBranchQuota(comptime typeScanQuota(T));
223
243
  switch (@typeInfo(T)) {
224
244
  .bool => {
225
245
  const raw = reader.take(1)[0];