@native-sdk/cli 0.9.2 → 0.9.4
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 +273 -37
- package/build/ts_run.mjs +15 -18
- package/build.zig +141 -9
- package/package.json +13 -10
- package/packages/core/compile-surface/core.ts +1 -0
- package/packages/core/package-lock.json +16 -13
- package/packages/core/package.json +5 -2
- package/packages/core/scripts/compiler_command.mjs +71 -0
- package/packages/core/scripts/compiler_typecheck.mjs +4 -4
- package/packages/core/scripts/embed_markup_c.mjs +25 -0
- package/packages/core/scripts/npm_static_spike.mjs +3 -3
- package/packages/core/scripts/run_external_core_compiler.mjs +4 -3
- package/packages/core/scripts/run_external_service_compiler.mjs +2 -1
- package/packages/core/sdk/core.ts +1 -0
- package/packages/core/sdk/events.d.ts +10 -0
- package/packages/core/sdk/events.ts +30 -5
- package/packages/core/sdk/text.d.ts +4 -0
- package/packages/core/sdk/text.ts +51 -0
- package/packages/core/src/checker.ts +61 -3
- package/packages/core/src/contract.ts +5 -4
- package/packages/core/src/devhost_journal.mjs +2 -2
- package/packages/core/src/diagnostics.ts +2 -2
- package/packages/core/src/service_contract.ts +10 -0
- package/packages/core/src/typed_ast.ts +9 -7
- package/packages/core/src/types.ts +28 -8
- package/skill-data/automation/SKILL.md +4 -3
- package/skill-data/native-ui/SKILL.md +5 -2
- package/skill-data/ts-core/SKILL.md +10 -4
- package/skill-data/ts-services/references/service-surface.md +1 -1
- package/src/app_runner/root.zig +208 -6
- package/src/app_runner/ts_core_main.zig +14 -4
- package/src/app_runner/ts_core_mobile.zig +6 -2
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +119 -0
- package/src/platform/macos/appkit_host.m +79 -12
- package/src/platform/macos/root.zig +68 -5
- package/src/primitives/canvas/events.zig +79 -1
- package/src/primitives/canvas/root.zig +1 -0
- package/src/primitives/canvas/text_interaction.zig +23 -0
- package/src/primitives/canvas/text_tests.zig +45 -0
- package/src/primitives/canvas/ui.zig +11 -8
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +3 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
- package/src/primitives/canvas/ui_markup_view_tests.zig +18 -2
- package/src/primitives/canvas/ui_tests.zig +37 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +13 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/canvas_widget_control_tests.zig +2 -0
- package/src/runtime/canvas_widget_text_tests.zig +124 -0
- package/src/runtime/native_command_event_tests.zig +29 -0
- package/src/runtime/session_journal.zig +21 -2
- package/src/runtime/ts_ui_app.zig +184 -7
- package/src/runtime/ui_app.zig +98 -18
- package/src/runtime/ui_app_tests.zig +232 -13
- package/src/runtime/ui_app_window_tests.zig +23 -0
- package/src/runtime/view_widget_text.zig +1 -1
- package/src/tooling/templates.zig +6 -2
- package/src/tooling/ts_core.zig +1 -1
- package/src/tooling/verbs.zig +228 -0
- package/tools/corewire/emit.zig +31 -12
- package/tools/corewire/emit_facade.zig +57 -2
- package/tools/corewire/emit_profile.zig +20 -7
- package/tools/corewire/emit_service.zig +49 -24
- package/tools/corewire/main.zig +21 -2
- package/tools/corewire/shim_rt.zig +20 -0
|
@@ -29,29 +29,24 @@ fn fingerprintType(hasher: *std.crypto.hash.sha2.Sha256, ref: service.TypeRef) v
|
|
|
29
29
|
if (ref.name) |name| fingerprintField(hasher, name);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/// Identity of
|
|
33
|
-
///
|
|
34
|
-
///
|
|
32
|
+
/// Identity of the service ABI facts both carriers put on the wire. The same
|
|
33
|
+
/// digest is embedded in the service executable and the Zig registry so a
|
|
34
|
+
/// stale or hand-supplied sibling is refused before numeric indices are used.
|
|
35
|
+
///
|
|
36
|
+
/// Deliberately excluded: compiler/package identities, implementation module
|
|
37
|
+
/// paths and exports, and `source_hash`. Those facts rebuild the service
|
|
38
|
+
/// executable, but they do not change operation indices or encoded values and
|
|
39
|
+
/// therefore must not rewrite the app runner or recompile the app core.
|
|
35
40
|
fn contractFingerprint(contract: service.Contract) [fingerprint_len]u8 {
|
|
36
41
|
var hasher = std.crypto.hash.sha2.Sha256.init(.{});
|
|
37
|
-
hasher.update("native-sdk.services.
|
|
42
|
+
hasher.update("native-sdk.services.abi.v3\x00");
|
|
38
43
|
var scalar: [8]u8 = undefined;
|
|
39
44
|
std.mem.writeInt(i64, &scalar, contract.format, .little);
|
|
40
45
|
hasher.update(&scalar);
|
|
41
46
|
std.mem.writeInt(i64, &scalar, contract.protocol_version, .little);
|
|
42
47
|
hasher.update(&scalar);
|
|
43
|
-
hasher.update(&.{@intFromBool(contract.deterministic)});
|
|
44
|
-
fingerprintField(&hasher, contract.compiler_version);
|
|
45
|
-
std.mem.writeInt(u64, &scalar, @intCast(contract.packages.len), .little);
|
|
46
|
-
hasher.update(&scalar);
|
|
47
|
-
for (contract.packages) |package_entry| {
|
|
48
|
-
fingerprintField(&hasher, package_entry.name);
|
|
49
|
-
fingerprintField(&hasher, package_entry.version);
|
|
50
|
-
fingerprintField(&hasher, package_entry.content_hash);
|
|
51
|
-
}
|
|
52
48
|
for (contract.types.records) |record| {
|
|
53
49
|
fingerprintField(&hasher, record.name);
|
|
54
|
-
fingerprintField(&hasher, record.origin);
|
|
55
50
|
for (record.fields) |field| {
|
|
56
51
|
fingerprintField(&hasher, field.name);
|
|
57
52
|
fingerprintType(&hasher, field.type);
|
|
@@ -59,12 +54,10 @@ fn contractFingerprint(contract: service.Contract) [fingerprint_len]u8 {
|
|
|
59
54
|
}
|
|
60
55
|
for (contract.types.enums) |enum_type| {
|
|
61
56
|
fingerprintField(&hasher, enum_type.name);
|
|
62
|
-
fingerprintField(&hasher, enum_type.origin);
|
|
63
57
|
for (enum_type.members) |member| fingerprintField(&hasher, member);
|
|
64
58
|
}
|
|
65
59
|
for (contract.types.unions) |union_type| {
|
|
66
60
|
fingerprintField(&hasher, union_type.name);
|
|
67
|
-
fingerprintField(&hasher, union_type.origin);
|
|
68
61
|
for (union_type.arms) |arm| {
|
|
69
62
|
fingerprintField(&hasher, arm.name);
|
|
70
63
|
for (arm.fields) |field| {
|
|
@@ -77,9 +70,6 @@ fn contractFingerprint(contract: service.Contract) [fingerprint_len]u8 {
|
|
|
77
70
|
hasher.update(&scalar);
|
|
78
71
|
for (contract.operations) |op| {
|
|
79
72
|
fingerprintField(&hasher, op.name);
|
|
80
|
-
fingerprintField(&hasher, op.client);
|
|
81
|
-
fingerprintField(&hasher, op.module);
|
|
82
|
-
fingerprintField(&hasher, op.@"export");
|
|
83
73
|
fingerprintType(&hasher, op.request);
|
|
84
74
|
fingerprintType(&hasher, op.result);
|
|
85
75
|
std.mem.writeInt(i64, &scalar, op.deadline_ms orelse 0, .little);
|
|
@@ -91,7 +81,6 @@ fn contractFingerprint(contract: service.Contract) [fingerprint_len]u8 {
|
|
|
91
81
|
std.mem.writeInt(i64, &scalar, stream.in_flight, .little);
|
|
92
82
|
hasher.update(&scalar);
|
|
93
83
|
} else hasher.update(&.{0});
|
|
94
|
-
fingerprintField(&hasher, op.source_hash);
|
|
95
84
|
}
|
|
96
85
|
return hasher.finalResult();
|
|
97
86
|
}
|
|
@@ -601,15 +590,23 @@ pub fn emitInprocMain(arena: std.mem.Allocator, contract: service.Contract) ![]c
|
|
|
601
590
|
/// and linked by one build graph, and the facade's fingerprint export is
|
|
602
591
|
/// the pairing check. No determinism fences — services run with ambient
|
|
603
592
|
/// authority by contract.
|
|
604
|
-
pub fn emitInprocProfile(arena: std.mem.Allocator) ![]const u8 {
|
|
593
|
+
pub fn emitInprocProfile(arena: std.mem.Allocator, optimization: ?[]const u8) ![]const u8 {
|
|
605
594
|
var out = std.Io.Writer.Allocating.init(arena);
|
|
606
595
|
const w = &out.writer;
|
|
607
|
-
try w.
|
|
608
|
-
\\{
|
|
596
|
+
try w.writeAll(
|
|
597
|
+
\\{
|
|
609
598
|
\\ "profile_format": 1,
|
|
610
599
|
\\ "name": "native-sdk-services",
|
|
611
600
|
\\ "entry": "service_inproc_main.ts",
|
|
612
601
|
\\ "emission": "llvm",
|
|
602
|
+
);
|
|
603
|
+
if (optimization) |value| {
|
|
604
|
+
try w.print(
|
|
605
|
+
\\ "optimization": "{s}",
|
|
606
|
+
, .{value});
|
|
607
|
+
try w.writeByte('\n');
|
|
608
|
+
}
|
|
609
|
+
try w.print(
|
|
613
610
|
\\ "abi": {{
|
|
614
611
|
\\ "prefix": "{s}",
|
|
615
612
|
\\ "init_symbol": "{s}init",
|
|
@@ -887,12 +884,13 @@ test "service projection derives host dispatch and registry from one contract" {
|
|
|
887
884
|
try std.testing.expect(std.mem.indexOf(u8, inproc, "writeHello") == null);
|
|
888
885
|
try std.testing.expect(std.mem.indexOf(u8, inproc, "requestId") == null);
|
|
889
886
|
|
|
890
|
-
const profile = try emitInprocProfile(std.testing.allocator);
|
|
887
|
+
const profile = try emitInprocProfile(std.testing.allocator, "release");
|
|
891
888
|
defer std.testing.allocator.free(profile);
|
|
892
889
|
try std.testing.expect(std.mem.indexOf(u8, profile, "\"prefix\": \"nsc_svc_\"") != null);
|
|
893
890
|
try std.testing.expect(std.mem.indexOf(u8, profile, "\"localize_runtime\": true") != null);
|
|
894
891
|
try std.testing.expect(std.mem.indexOf(u8, profile, "\"instance_per_thread\": true") != null);
|
|
895
892
|
try std.testing.expect(std.mem.indexOf(u8, profile, "\"entry\": \"service_inproc_main.ts\"") != null);
|
|
893
|
+
try std.testing.expect(std.mem.indexOf(u8, profile, "\"optimization\": \"release\"") != null);
|
|
896
894
|
try std.testing.expect(std.mem.indexOf(u8, profile, "\"symbol\": \"nsc_svc_dispatch\"") != null);
|
|
897
895
|
|
|
898
896
|
const registry = try emitRegistry(std.testing.allocator, contract);
|
|
@@ -910,6 +908,33 @@ test "service projection derives host dispatch and registry from one contract" {
|
|
|
910
908
|
try std.testing.expect(std.mem.indexOf(u8, client, "ServiceRoute<Msg, readonly (Uint8Array | null)[]>") != null);
|
|
911
909
|
|
|
912
910
|
const original_fingerprint = contractFingerprint(contract);
|
|
911
|
+
// An implementation-only fingerprint input change must leave the ABI
|
|
912
|
+
// digest alone: source/package/compiler facts rebuild only the service.
|
|
913
|
+
const implementation_only_fingerprint = contractFingerprint(.{
|
|
914
|
+
.format = contract.format,
|
|
915
|
+
.protocol_version = contract.protocol_version,
|
|
916
|
+
.compiler_version = "9.9.9",
|
|
917
|
+
.deterministic = contract.deterministic,
|
|
918
|
+
.packages = &.{.{ .name = "different-package", .version = "4.5.6", .content_hash = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }},
|
|
919
|
+
.types = contract.types,
|
|
920
|
+
.operations = &.{
|
|
921
|
+
.{
|
|
922
|
+
.name = operations[0].name,
|
|
923
|
+
.client = "renamedInternalClient",
|
|
924
|
+
.module = "src/services/moved.ts",
|
|
925
|
+
.@"export" = "moved",
|
|
926
|
+
.request = operations[0].request,
|
|
927
|
+
.result = operations[0].result,
|
|
928
|
+
.deadline_ms = operations[0].deadline_ms,
|
|
929
|
+
.cancellable = operations[0].cancellable,
|
|
930
|
+
.stream = operations[0].stream,
|
|
931
|
+
.source_hash = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
|
|
932
|
+
},
|
|
933
|
+
operations[1],
|
|
934
|
+
operations[2],
|
|
935
|
+
},
|
|
936
|
+
});
|
|
937
|
+
try std.testing.expectEqualSlices(u8, &original_fingerprint, &implementation_only_fingerprint);
|
|
913
938
|
const reordered_operations = [_]service.Operation{ operations[1], operations[0] };
|
|
914
939
|
const reordered_fingerprint = contractFingerprint(.{
|
|
915
940
|
.format = contract.format,
|
package/tools/corewire/main.zig
CHANGED
|
@@ -59,6 +59,7 @@ pub fn main(init: std.process.Init) !void {
|
|
|
59
59
|
var profile_path: ?[]const u8 = null;
|
|
60
60
|
var effective_sidecar_path: ?[]const u8 = null;
|
|
61
61
|
var check_only = false;
|
|
62
|
+
var optimization: ?[]const u8 = null;
|
|
62
63
|
var f64_slots: std.ArrayListUnmanaged([]const u8) = .empty;
|
|
63
64
|
var index: usize = 1;
|
|
64
65
|
while (index < args.len) : (index += 1) {
|
|
@@ -83,6 +84,9 @@ pub fn main(init: std.process.Init) !void {
|
|
|
83
84
|
try f64_slots.append(arena, args[index]);
|
|
84
85
|
} else if (std.mem.eql(u8, arg, "--check")) {
|
|
85
86
|
check_only = true;
|
|
87
|
+
} else if (std.mem.eql(u8, arg, "--optimization") and index + 1 < args.len) {
|
|
88
|
+
index += 1;
|
|
89
|
+
optimization = args[index];
|
|
86
90
|
} else {
|
|
87
91
|
try stderr.print("corewire: unknown argument \"{s}\"\n\n{s}", .{ arg, usage });
|
|
88
92
|
try stderr.flush();
|
|
@@ -256,7 +260,12 @@ pub fn main(init: std.process.Init) !void {
|
|
|
256
260
|
try stderr.flush();
|
|
257
261
|
std.process.exit(2);
|
|
258
262
|
}
|
|
259
|
-
|
|
263
|
+
if (optimization != null and !std.mem.eql(u8, optimization.?, "dev") and !std.mem.eql(u8, optimization.?, "release")) {
|
|
264
|
+
try stderr.print("corewire: --optimization must be dev or release\n", .{});
|
|
265
|
+
try stderr.flush();
|
|
266
|
+
std.process.exit(2);
|
|
267
|
+
}
|
|
268
|
+
break :blk emit_profile_mod.emitProfile(arena, parsed, entry, optimization, &diags) catch |err| switch (err) {
|
|
260
269
|
error.Refused => {
|
|
261
270
|
try diags.write(input, stderr);
|
|
262
271
|
try stderr.flush();
|
|
@@ -373,6 +382,7 @@ fn serviceProjection(init: std.process.Init, args: []const []const u8, stderr: *
|
|
|
373
382
|
var inproc_main_out: ?[]const u8 = null;
|
|
374
383
|
var inproc_profile_out: ?[]const u8 = null;
|
|
375
384
|
var saw_service_flag = false;
|
|
385
|
+
var optimization: ?[]const u8 = null;
|
|
376
386
|
var index: usize = 1;
|
|
377
387
|
while (index < args.len) : (index += 1) {
|
|
378
388
|
const arg = args[index];
|
|
@@ -400,6 +410,10 @@ fn serviceProjection(init: std.process.Init, args: []const []const u8, stderr: *
|
|
|
400
410
|
saw_service_flag = true;
|
|
401
411
|
index += 1;
|
|
402
412
|
inproc_profile_out = args[index];
|
|
413
|
+
} else if (saw_service_flag and std.mem.eql(u8, arg, "--optimization") and index + 1 < args.len) {
|
|
414
|
+
saw_service_flag = true;
|
|
415
|
+
index += 1;
|
|
416
|
+
optimization = args[index];
|
|
403
417
|
} else if (saw_service_flag) {
|
|
404
418
|
try stderr.print("corewire: unknown service projection argument \"{s}\"\n", .{arg});
|
|
405
419
|
try stderr.flush();
|
|
@@ -407,6 +421,11 @@ fn serviceProjection(init: std.process.Init, args: []const []const u8, stderr: *
|
|
|
407
421
|
}
|
|
408
422
|
}
|
|
409
423
|
if (!saw_service_flag) return false;
|
|
424
|
+
if (optimization != null and !std.mem.eql(u8, optimization.?, "dev") and !std.mem.eql(u8, optimization.?, "release")) {
|
|
425
|
+
try stderr.print("corewire: --optimization must be dev or release\n", .{});
|
|
426
|
+
try stderr.flush();
|
|
427
|
+
std.process.exit(2);
|
|
428
|
+
}
|
|
410
429
|
const sidecar_path = input orelse {
|
|
411
430
|
try stderr.print("usage: corewire --services-sidecar <services.contract.json> [--service-host-main <service_host_main.ts>] [--service-registry <services.zig>] [--service-client <services.gen.ts>] [--service-inproc-main <service_inproc_main.ts>] [--service-inproc-profile <service_profile.json>]\n", .{});
|
|
412
431
|
try stderr.flush();
|
|
@@ -469,7 +488,7 @@ fn serviceProjection(init: std.process.Init, args: []const []const u8, stderr: *
|
|
|
469
488
|
};
|
|
470
489
|
}
|
|
471
490
|
if (inproc_profile_out) |path| {
|
|
472
|
-
const generated = try emit_service_mod.emitInprocProfile(arena);
|
|
491
|
+
const generated = try emit_service_mod.emitInprocProfile(arena, optimization);
|
|
473
492
|
std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = path, .data = generated }) catch |err| {
|
|
474
493
|
try stderr.print("corewire: cannot write {s}: {t}\n", .{ path, err });
|
|
475
494
|
try stderr.flush();
|
|
@@ -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];
|