@native-sdk/cli 0.6.3 → 0.7.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.zig +65 -91
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/text.ts +25 -14
- package/packages/core/src/checker.ts +39 -0
- package/packages/core/src/emitter.ts +125 -1
- package/skill-data/native-ui/SKILL.md +23 -6
- package/src/platform/macos/appkit_host.m +25 -1
- package/src/platform/macos/cef_host.mm +24 -2
- package/src/platform/macos/root.zig +13 -0
- package/src/primitives/canvas/code.zig +1008 -0
- package/src/primitives/canvas/code_tests.zig +1912 -0
- package/src/primitives/canvas/events.zig +111 -1
- package/src/primitives/canvas/layout_audit.zig +3 -1
- package/src/primitives/canvas/markdown.zig +13 -11
- package/src/primitives/canvas/markdown_tests.zig +168 -6
- package/src/primitives/canvas/root.zig +8 -2
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text.zig +6 -0
- package/src/primitives/canvas/text_measure_cache.zig +4 -4
- package/src/primitives/canvas/text_span_tests.zig +254 -0
- package/src/primitives/canvas/text_spans.zig +556 -32
- package/src/primitives/canvas/themes/geist.zig +29 -0
- package/src/primitives/canvas/tokens.zig +72 -2
- package/src/primitives/canvas/ui.zig +400 -22
- package/src/primitives/canvas/ui_markup.zig +78 -7
- package/src/primitives/canvas/ui_markup_compiled.zig +89 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +45 -0
- package/src/primitives/canvas/ui_markup_contract.zig +41 -0
- package/src/primitives/canvas/ui_markup_view.zig +89 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +154 -3
- package/src/primitives/canvas/ui_schema.zig +30 -6
- package/src/primitives/canvas/ui_schema_tests.zig +13 -10
- package/src/primitives/canvas/ui_tests.zig +26 -0
- package/src/primitives/canvas/widget_invalidation.zig +4 -0
- package/src/primitives/canvas/widget_layout.zig +57 -8
- package/src/primitives/canvas/widget_layout_tests.zig +35 -0
- package/src/primitives/canvas/widget_metrics.zig +35 -1
- package/src/primitives/canvas/widget_render.zig +1077 -11
- package/src/primitives/canvas/widget_render_controls.zig +4 -4
- package/src/primitives/canvas/widget_runtime.zig +2 -0
- package/src/primitives/canvas/widget_text_input.zig +165 -8
- package/src/primitives/canvas/widget_text_select.zig +2 -2
- package/src/primitives/canvas/widget_tree.zig +6 -5
- package/src/primitives/canvas/widgets.zig +38 -0
- package/src/root.zig +1 -0
- package/src/runtime/canvas_budget_edge_tests.zig +3 -2
- package/src/runtime/canvas_limits.zig +13 -6
- package/src/runtime/canvas_widget_clipboard_tests.zig +137 -4
- package/src/runtime/canvas_widget_context_menu.zig +17 -2
- package/src/runtime/canvas_widget_event_tests.zig +18 -14
- package/src/runtime/canvas_widget_events.zig +58 -21
- package/src/runtime/canvas_widget_runtime.zig +112 -6
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +59 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +100 -0
- package/src/runtime/canvas_widget_state.zig +27 -0
- package/src/runtime/canvas_widget_text_tests.zig +383 -0
- package/src/runtime/core.zig +15 -5
- package/src/runtime/gpu_surface_events.zig +12 -12
- package/src/runtime/view.zig +61 -19
- package/src/runtime/view_widget_scroll.zig +48 -18
- package/src/runtime/view_widget_text.zig +248 -17
- package/src/runtime/window_view_runtime.zig +9 -0
package/build.zig
CHANGED
|
@@ -517,13 +517,15 @@ pub fn build(b: *std.Build) void {
|
|
|
517
517
|
test_step.dependOn(&battery_run.step);
|
|
518
518
|
}
|
|
519
519
|
// The corpus contract artifacts an external core toolchain
|
|
520
|
-
// consumes: per fixture, the extracted contract sidecar
|
|
521
|
-
//
|
|
522
|
-
|
|
520
|
+
// consumes: per fixture, the extracted contract sidecar, the
|
|
521
|
+
// generated entry module, and the compiler profile that builds
|
|
522
|
+
// it, under zig-out/core-contracts.
|
|
523
|
+
const contracts_step = b.step("stage-core-contracts", "Install each ts-core fixture's contract sidecar, generated entry module, and compiler profile under zig-out/core-contracts (requires node)");
|
|
523
524
|
for (ts_core_artifacts.core_contracts) |contract| {
|
|
524
525
|
const dir: std.Build.InstallDir = .{ .custom = b.fmt("core-contracts/{s}", .{contract.name}) };
|
|
525
526
|
contracts_step.dependOn(&b.addInstallFileWithDir(contract.sidecar, dir, "core.contract.json").step);
|
|
526
527
|
contracts_step.dependOn(&b.addInstallFileWithDir(contract.facade, dir, "core_facade.ts").step);
|
|
528
|
+
contracts_step.dependOn(&b.addInstallFileWithDir(contract.profile, dir, "core_profile.json").step);
|
|
527
529
|
}
|
|
528
530
|
ts_core_e2e_step.dependOn(&host_e2e_run.step);
|
|
529
531
|
ts_core_e2e_step.dependOn(&soundboard_e2e_run.step);
|
|
@@ -1384,6 +1386,7 @@ pub fn build(b: *std.Build) void {
|
|
|
1384
1386
|
addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard-ts", "Run soundboard-ts example tests", "examples/soundboard-ts", .managed),
|
|
1385
1387
|
addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-deck", "Run deck example tests", "examples/deck", .managed),
|
|
1386
1388
|
addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-markdown-viewer", "Run markdown viewer example tests", "examples/markdown-viewer", .managed),
|
|
1389
|
+
addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-code-editor", "Run code editor example tests", "examples/code-editor", .managed),
|
|
1387
1390
|
addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-calculator", "Run calculator example tests", "examples/calculator", .managed),
|
|
1388
1391
|
addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-notes", "Run notes example tests", "examples/notes", .managed),
|
|
1389
1392
|
addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-split-collapse", "Run split collapse example tests", "examples/split-collapse", .managed),
|
|
@@ -2009,7 +2012,13 @@ pub fn build(b: *std.Build) void {
|
|
|
2009
2012
|
\\ ready_uptime="$(printf '%s\n' "$ready" | sed -n 's/.*runtime_uptime_ns=\([0-9][0-9]*\).*/\1/p')"
|
|
2010
2013
|
\\ case "$ready_uptime" in ''|*[!0-9]*) echo "gpu-dashboard automation ready uptime was missing" >&2; exit 1 ;; esac
|
|
2011
2014
|
\\ if [ "$ready_uptime" -le 0 ] || [ "$ready_uptime" -gt "$ready_budget_ns" ]; then echo "gpu-dashboard automation ready exceeded $ready_budget_ms ms: $ready_uptime ns" >&2; exit 1; fi
|
|
2012
|
-
\\
|
|
2015
|
+
\\ attempts=0
|
|
2016
|
+
\\ while [ "$attempts" -lt 50 ]; do
|
|
2017
|
+
\\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
|
|
2018
|
+
\\ case "$snapshot" in *'window @w1 "Native SDK GPU Dashboard"'*'view @w1/dashboard-canvas kind=gpu_surface'*'accessibility_label="Native-rendered product dashboard canvas"'*) break ;; esac
|
|
2019
|
+
\\ attempts=$((attempts + 1))
|
|
2020
|
+
\\ sleep 0.1
|
|
2021
|
+
\\ done
|
|
2013
2022
|
\\ case "$snapshot" in *'window @w1 "Native SDK GPU Dashboard"'*) ;; *) echo "gpu-dashboard window was missing from snapshot" >&2; exit 1 ;; esac
|
|
2014
2023
|
\\ case "$snapshot" in *'view @w1/main kind=webview'*) echo "dashboard should not create an implicit main WebView" >&2; exit 1 ;; *) ;; esac
|
|
2015
2024
|
\\ case "$snapshot" in *'source kind=html bytes=0'*) echo "dashboard should not publish an empty default WebView source" >&2; exit 1 ;; *) ;; esac
|
|
@@ -2970,8 +2979,8 @@ const TsCoreE2eArtifacts = struct {
|
|
|
2970
2979
|
/// — every battery skipped — otherwise.
|
|
2971
2980
|
compiled_core_parity: []const CompiledCoreParity,
|
|
2972
2981
|
/// Per-fixture contract artifacts for an external core toolchain:
|
|
2973
|
-
/// the
|
|
2974
|
-
///
|
|
2982
|
+
/// the effective contract sidecar and its TypeScript facade/profile
|
|
2983
|
+
/// projections, installed by the stage-core-contracts step.
|
|
2975
2984
|
core_contracts: []const CoreContract,
|
|
2976
2985
|
};
|
|
2977
2986
|
|
|
@@ -2984,6 +2993,7 @@ const CoreContract = struct {
|
|
|
2984
2993
|
name: []const u8,
|
|
2985
2994
|
sidecar: std.Build.LazyPath,
|
|
2986
2995
|
facade: std.Build.LazyPath,
|
|
2996
|
+
profile: std.Build.LazyPath,
|
|
2987
2997
|
};
|
|
2988
2998
|
|
|
2989
2999
|
/// One fixture's compiled-core supply: the archive link input(s) and
|
|
@@ -3114,52 +3124,55 @@ fn tsCoreE2eArtifact(
|
|
|
3114
3124
|
|
|
3115
3125
|
const conformance_mod = module(b, target, optimize, "tests/sidecar/conformance_tests.zig");
|
|
3116
3126
|
conformance_mod.addImport("native_sdk", desktop_mod);
|
|
3117
|
-
// The canonical value encoder the
|
|
3127
|
+
// The canonical value encoder the envelope and snapshot axes compare
|
|
3118
3128
|
// against (the same module the generated shims stage).
|
|
3119
3129
|
conformance_mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
|
|
3120
3130
|
conformance_mod.addImport("ts_markup_core", markup_fixture_mod);
|
|
3121
3131
|
conformance_mod.addImport("shim_markup_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
|
|
3122
|
-
conformance_mod.addImport("facade_markup_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
|
|
3123
3132
|
// The integer-class fixture: a hand-written sidecar attesting mixed
|
|
3124
3133
|
// i64/u64 slot classes, so the suite drives boundary and full-range
|
|
3125
|
-
// integer values through a generated mirror's decode paths
|
|
3126
|
-
// holds the compiled facade's integer encoders to the same bytes.
|
|
3134
|
+
// integer values through a generated mirror's decode paths.
|
|
3127
3135
|
conformance_mod.addImport("shim_integer_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
|
|
3128
|
-
conformance_mod.addImport("facade_integer_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
|
|
3129
3136
|
const conformance_fixtures = [_]struct {
|
|
3130
3137
|
ts_import: []const u8,
|
|
3131
3138
|
shim_import: []const u8,
|
|
3132
|
-
facade_import: []const u8,
|
|
3133
3139
|
contract_name: []const u8,
|
|
3134
3140
|
core_mod: *std.Build.Module,
|
|
3135
3141
|
entry: []const u8,
|
|
3142
|
+
/// Attested integer slots the compiled projection carries as f64
|
|
3143
|
+
/// (values that reach the f64-exact boundary have no honest i64
|
|
3144
|
+
/// declaration on that side).
|
|
3145
|
+
f64_slots: []const []const u8 = &.{},
|
|
3136
3146
|
}{
|
|
3137
|
-
.{ .ts_import = "ts_host_core", .shim_import = "shim_host_core", .
|
|
3138
|
-
.{ .ts_import = "ts_soundboard_core", .shim_import = "shim_soundboard_core", .
|
|
3139
|
-
.{ .ts_import = "ts_monitor_core", .shim_import = "shim_monitor_core", .
|
|
3140
|
-
.{ .ts_import = "ts_ai_chat_core", .shim_import = "shim_ai_chat_core", .
|
|
3147
|
+
.{ .ts_import = "ts_host_core", .shim_import = "shim_host_core", .contract_name = "host-fixture", .core_mod = fixture_mod, .entry = "tests/ts-core/fixture.ts", .f64_slots = &.{"Model.pastBytes"} },
|
|
3148
|
+
.{ .ts_import = "ts_soundboard_core", .shim_import = "shim_soundboard_core", .contract_name = "soundboard", .core_mod = soundboard_core_mod, .entry = "examples/soundboard-ts/src/core.ts" },
|
|
3149
|
+
.{ .ts_import = "ts_monitor_core", .shim_import = "shim_monitor_core", .contract_name = "system-monitor", .core_mod = monitor_core_mod, .entry = "examples/system-monitor-ts/src/core.ts" },
|
|
3150
|
+
.{ .ts_import = "ts_ai_chat_core", .shim_import = "shim_ai_chat_core", .contract_name = "ai-chat", .core_mod = ai_chat_core_mod, .entry = "examples/ai-chat-ts/src/core.ts" },
|
|
3141
3151
|
};
|
|
3142
3152
|
// The corpus contract artifacts an external core toolchain consumes
|
|
3143
|
-
// (stage-core-contracts): the
|
|
3144
|
-
//
|
|
3153
|
+
// (stage-core-contracts): the effective sidecar plus its generated
|
|
3154
|
+
// entry module and compiler profile, per fixture.
|
|
3145
3155
|
var core_contracts: std.ArrayList(CoreContract) = .empty;
|
|
3146
3156
|
{
|
|
3147
3157
|
const markup_sidecar = sidecarExtractJson(b, target, optimize, extract_mod, markup_fixture_mod, "tests/ts-core/markup_fixture.ts");
|
|
3158
|
+
const projections = facadeProjections(b, corewire_exe, markup_sidecar, &.{});
|
|
3148
3159
|
core_contracts.append(b.allocator, .{
|
|
3149
3160
|
.name = "markup-fixture",
|
|
3150
|
-
.sidecar =
|
|
3151
|
-
.facade =
|
|
3161
|
+
.sidecar = projections.sidecar,
|
|
3162
|
+
.facade = projections.facade,
|
|
3163
|
+
.profile = projections.profile,
|
|
3152
3164
|
}) catch @panic("OOM");
|
|
3153
3165
|
}
|
|
3154
3166
|
for (conformance_fixtures) |fixture| {
|
|
3155
3167
|
const sidecar_json = sidecarExtractJson(b, target, optimize, extract_mod, fixture.core_mod, fixture.entry);
|
|
3156
3168
|
conformance_mod.addImport(fixture.ts_import, fixture.core_mod);
|
|
3157
3169
|
conformance_mod.addImport(fixture.shim_import, sidecarShimModule(b, target, optimize, corewire_exe, sidecar_json));
|
|
3158
|
-
|
|
3170
|
+
const projections = facadeProjections(b, corewire_exe, sidecar_json, fixture.f64_slots);
|
|
3159
3171
|
core_contracts.append(b.allocator, .{
|
|
3160
3172
|
.name = fixture.contract_name,
|
|
3161
|
-
.sidecar =
|
|
3162
|
-
.facade =
|
|
3173
|
+
.sidecar = projections.sidecar,
|
|
3174
|
+
.facade = projections.facade,
|
|
3175
|
+
.profile = projections.profile,
|
|
3163
3176
|
}) catch @panic("OOM");
|
|
3164
3177
|
}
|
|
3165
3178
|
|
|
@@ -3192,17 +3205,12 @@ fn tsCoreE2eArtifact(
|
|
|
3192
3205
|
while (inputs.next()) |input| {
|
|
3193
3206
|
parity_mod.addObjectFile(.{ .cwd_relative = b.dupe(input) });
|
|
3194
3207
|
}
|
|
3195
|
-
|
|
3196
|
-
//
|
|
3197
|
-
//
|
|
3198
|
-
//
|
|
3199
|
-
//
|
|
3200
|
-
|
|
3201
|
-
check_sidecar.addArg("--sidecar");
|
|
3202
|
-
check_sidecar.addFileArg(parity_sidecar);
|
|
3203
|
-
check_sidecar.addArg("--check");
|
|
3204
|
-
parity_tests.step.dependOn(&check_sidecar.step);
|
|
3205
|
-
break :blk parity_tests;
|
|
3208
|
+
// The generated mirror is the only projection this lane uses;
|
|
3209
|
+
// sidecarShimModule validates exactly that surface. Do not run
|
|
3210
|
+
// the all-projections checker here: an external compiler's
|
|
3211
|
+
// sidecar may legitimately predate facade-only metadata while
|
|
3212
|
+
// remaining a valid mirror contract for its linked archive.
|
|
3213
|
+
break :blk filteredTestArtifact(b, parity_mod, "external-core-parity-tests", &.{});
|
|
3206
3214
|
} else null;
|
|
3207
3215
|
|
|
3208
3216
|
// The full-corpus compiled-core batteries: each supplied fixture's
|
|
@@ -3247,14 +3255,6 @@ fn tsCoreE2eArtifact(
|
|
|
3247
3255
|
battery_mod.addImport(entry.core_import, paired_mod);
|
|
3248
3256
|
if (entry.second_import) |second| battery_mod.addImport(second, entry.second_mod.?);
|
|
3249
3257
|
const battery = filteredTestArtifact(b, battery_mod, b.fmt("compiled-core-{s}-tests", .{entry.name}), &.{});
|
|
3250
|
-
// Run the checker tier over the supplied sidecar explicitly —
|
|
3251
|
-
// the same surface an external compile is verified against in
|
|
3252
|
-
// the markup parity suite.
|
|
3253
|
-
const check_sidecar = b.addRunArtifact(corewire_exe);
|
|
3254
|
-
check_sidecar.addArg("--sidecar");
|
|
3255
|
-
check_sidecar.addFileArg(supply.sidecar);
|
|
3256
|
-
check_sidecar.addArg("--check");
|
|
3257
|
-
battery.step.dependOn(&check_sidecar.step);
|
|
3258
3258
|
compiled_core_parity.append(b.allocator, .{ .name = b.dupe(entry.name), .tests = battery }) catch @panic("OOM");
|
|
3259
3259
|
}
|
|
3260
3260
|
|
|
@@ -3331,18 +3331,36 @@ fn pairedCoreModule(
|
|
|
3331
3331
|
return mod;
|
|
3332
3332
|
}
|
|
3333
3333
|
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3334
|
+
const FacadeProjections = struct {
|
|
3335
|
+
sidecar: std.Build.LazyPath,
|
|
3336
|
+
facade: std.Build.LazyPath,
|
|
3337
|
+
profile: std.Build.LazyPath,
|
|
3338
|
+
};
|
|
3339
|
+
|
|
3340
|
+
/// A sidecar's compiled-core projections: the effective contract after
|
|
3341
|
+
/// caller-stated demotions, the generated entry module (core_facade.ts), and
|
|
3342
|
+
/// the compiler profile that builds it (core_profile.json), emitted by one
|
|
3343
|
+
/// corewire invocation so no staged sibling can describe a different layout.
|
|
3344
|
+
fn facadeProjections(
|
|
3337
3345
|
b: *std.Build,
|
|
3338
3346
|
corewire_exe: *std.Build.Step.Compile,
|
|
3339
3347
|
sidecar_json: std.Build.LazyPath,
|
|
3340
|
-
|
|
3348
|
+
f64_slots: []const []const u8,
|
|
3349
|
+
) FacadeProjections {
|
|
3341
3350
|
const generate = b.addRunArtifact(corewire_exe);
|
|
3342
3351
|
generate.addArg("--sidecar");
|
|
3343
3352
|
generate.addFileArg(sidecar_json);
|
|
3344
3353
|
generate.addArg("--facade");
|
|
3345
|
-
|
|
3354
|
+
const facade = generate.addOutputFileArg("core_facade.ts");
|
|
3355
|
+
generate.addArg("--profile");
|
|
3356
|
+
const profile = generate.addOutputFileArg("core_profile.json");
|
|
3357
|
+
generate.addArg("--effective-sidecar");
|
|
3358
|
+
const sidecar = generate.addOutputFileArg("core.contract.json");
|
|
3359
|
+
for (f64_slots) |slot| {
|
|
3360
|
+
generate.addArg("--f64-slot");
|
|
3361
|
+
generate.addArg(slot);
|
|
3362
|
+
}
|
|
3363
|
+
return .{ .sidecar = sidecar, .facade = facade, .profile = profile };
|
|
3346
3364
|
}
|
|
3347
3365
|
|
|
3348
3366
|
/// One fixture's generated-mirror module: run corewire over the
|
|
@@ -3372,50 +3390,6 @@ fn sidecarShimModule(
|
|
|
3372
3390
|
});
|
|
3373
3391
|
}
|
|
3374
3392
|
|
|
3375
|
-
/// One fixture's compiled-facade module: run corewire over the sidecar
|
|
3376
|
-
/// for its TypeScript projection (core_facade.ts), then compile that
|
|
3377
|
-
/// projection through the shipped transpiler — the checker/emitter tier
|
|
3378
|
-
/// is the compile, so this step IS the subset-acceptance proof — and
|
|
3379
|
-
/// stage the emitted Zig beside its rt kernel like any fixture core.
|
|
3380
|
-
fn facadeCoreModule(
|
|
3381
|
-
b: *std.Build,
|
|
3382
|
-
target: std.Build.ResolvedTarget,
|
|
3383
|
-
optimize: std.builtin.OptimizeMode,
|
|
3384
|
-
node: []const u8,
|
|
3385
|
-
corewire_exe: *std.Build.Step.Compile,
|
|
3386
|
-
sidecar_json: std.Build.LazyPath,
|
|
3387
|
-
) *std.Build.Module {
|
|
3388
|
-
const generate = b.addRunArtifact(corewire_exe);
|
|
3389
|
-
generate.addArg("--sidecar");
|
|
3390
|
-
generate.addFileArg(sidecar_json);
|
|
3391
|
-
generate.addArg("--facade");
|
|
3392
|
-
const facade_ts = generate.addOutputFileArg("core_facade.ts");
|
|
3393
|
-
const staged_ts = b.addWriteFiles();
|
|
3394
|
-
const facade_entry = staged_ts.addCopyFile(facade_ts, "core.ts");
|
|
3395
|
-
|
|
3396
|
-
const transpile = b.addSystemCommand(&.{node});
|
|
3397
|
-
transpile.addFileArg(b.path("packages/core/src/cli.ts"));
|
|
3398
|
-
transpile.addFileArg(facade_entry);
|
|
3399
|
-
transpile.addArg("-o");
|
|
3400
|
-
const emitted_core = transpile.addOutputFileArg("core.zig");
|
|
3401
|
-
tsCoreAddDirInputs(b, transpile, "packages/core/sdk");
|
|
3402
|
-
const transpiler_sources = [_][]const u8{
|
|
3403
|
-
"checker.ts", "cli.ts", "diagnostics.ts", "emitter.ts", "infer.ts", "modules.ts", "transpile.ts", "typed_ast.ts", "types.ts",
|
|
3404
|
-
};
|
|
3405
|
-
for (transpiler_sources) |source| {
|
|
3406
|
-
transpile.addFileInput(b.path(b.fmt("packages/core/src/{s}", .{source})));
|
|
3407
|
-
}
|
|
3408
|
-
|
|
3409
|
-
const staged = b.addWriteFiles();
|
|
3410
|
-
const core_root = staged.addCopyFile(emitted_core, "core.zig");
|
|
3411
|
-
_ = staged.addCopyFile(b.path("packages/core/rt/rt.zig"), "rt.zig");
|
|
3412
|
-
return b.createModule(.{
|
|
3413
|
-
.root_source_file = core_root,
|
|
3414
|
-
.target = target,
|
|
3415
|
-
.optimize = optimize,
|
|
3416
|
-
});
|
|
3417
|
-
}
|
|
3418
|
-
|
|
3419
3393
|
/// Extract a fixture's contract sidecar from its transpiled module
|
|
3420
3394
|
/// (tools/corewire/extract.zig) — a generated one-line main per
|
|
3421
3395
|
/// fixture, so corpus sidecars regenerate whenever the fixture or the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@native-sdk/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"@typescript/typescript6": "6.0.2"
|
|
33
33
|
},
|
|
34
34
|
"optionalDependencies": {
|
|
35
|
-
"@native-sdk/cli-darwin-arm64": "0.
|
|
36
|
-
"@native-sdk/cli-darwin-x64": "0.
|
|
37
|
-
"@native-sdk/cli-linux-arm64-gnu": "0.
|
|
38
|
-
"@native-sdk/cli-linux-arm64-musl": "0.
|
|
39
|
-
"@native-sdk/cli-linux-x64-gnu": "0.
|
|
40
|
-
"@native-sdk/cli-linux-x64-musl": "0.
|
|
41
|
-
"@native-sdk/cli-win32-arm64": "0.
|
|
42
|
-
"@native-sdk/cli-win32-x64": "0.
|
|
35
|
+
"@native-sdk/cli-darwin-arm64": "0.7.1",
|
|
36
|
+
"@native-sdk/cli-darwin-x64": "0.7.1",
|
|
37
|
+
"@native-sdk/cli-linux-arm64-gnu": "0.7.1",
|
|
38
|
+
"@native-sdk/cli-linux-arm64-musl": "0.7.1",
|
|
39
|
+
"@native-sdk/cli-linux-x64-gnu": "0.7.1",
|
|
40
|
+
"@native-sdk/cli-linux-x64-musl": "0.7.1",
|
|
41
|
+
"@native-sdk/cli-win32-arm64": "0.7.1",
|
|
42
|
+
"@native-sdk/cli-win32-x64": "0.7.1"
|
|
43
43
|
},
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@native-sdk/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@native-sdk/core",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.7.1",
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@typescript/old": "npm:typescript@6.0.3",
|
|
12
12
|
"@typescript/typescript6": "6.0.2"
|
|
@@ -216,11 +216,22 @@ function nextTextWordOffset(text: Uint8Array, offset: number): number {
|
|
|
216
216
|
return cursor;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
/// The selection constructor: offsets are whole byte offsets by
|
|
220
|
+
/// contract, proven in place — range-guarded (an ordered comparison
|
|
221
|
+
/// excludes NaN) and stated whole with Math.trunc. A value outside the
|
|
222
|
+
/// provable ±(2^53 − 1) window clamps to 0, the same floor every
|
|
223
|
+
/// caller's snap already applies.
|
|
224
|
+
function caretSelectionAt(anchor: number, focus: number): TextSelection {
|
|
225
|
+
const wholeAnchor = anchor >= 0 && anchor <= 9007199254740991 ? Math.trunc(anchor) : 0;
|
|
226
|
+
const wholeFocus = focus >= 0 && focus <= 9007199254740991 ? Math.trunc(focus) : 0;
|
|
227
|
+
return { anchor: wholeAnchor, focus: wholeFocus };
|
|
228
|
+
}
|
|
229
|
+
|
|
219
230
|
function snapTextCaretSelection(text: Uint8Array, selection: TextSelection): TextSelection {
|
|
220
|
-
return
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
231
|
+
return caretSelectionAt(
|
|
232
|
+
snapTextCaretOffset(text, selection.anchor),
|
|
233
|
+
snapTextCaretOffset(text, selection.focus),
|
|
234
|
+
);
|
|
224
235
|
}
|
|
225
236
|
|
|
226
237
|
function snapTextRange(text: Uint8Array, range: TextRange): TextRange {
|
|
@@ -290,7 +301,7 @@ function replaceTextEditRange(
|
|
|
290
301
|
);
|
|
291
302
|
return {
|
|
292
303
|
text: result.text,
|
|
293
|
-
selection:
|
|
304
|
+
selection: caretSelectionAt(cursor, cursor),
|
|
294
305
|
composition: composition,
|
|
295
306
|
};
|
|
296
307
|
}
|
|
@@ -308,7 +319,7 @@ function setTextComposition(
|
|
|
308
319
|
const absoluteCursor = snapTextCaretOffset(result.text, result.insertedStart + cursor);
|
|
309
320
|
return {
|
|
310
321
|
text: result.text,
|
|
311
|
-
selection:
|
|
322
|
+
selection: caretSelectionAt(absoluteCursor, absoluteCursor),
|
|
312
323
|
composition: { start: result.insertedStart, end: result.insertedEnd },
|
|
313
324
|
};
|
|
314
325
|
}
|
|
@@ -320,10 +331,10 @@ function cancelTextComposition(state: TextEditState, capacity: number): TextEdit
|
|
|
320
331
|
if (result === null) return null;
|
|
321
332
|
return {
|
|
322
333
|
text: result.text,
|
|
323
|
-
selection: snapTextCaretSelection(
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
334
|
+
selection: snapTextCaretSelection(
|
|
335
|
+
result.text,
|
|
336
|
+
caretSelectionAt(result.insertedStart, result.insertedStart),
|
|
337
|
+
),
|
|
327
338
|
composition: null,
|
|
328
339
|
};
|
|
329
340
|
}
|
|
@@ -355,7 +366,7 @@ function deleteForwardTextEdit(state: TextEditState, capacity: number): TextEdit
|
|
|
355
366
|
const caret = snapTextCaretOffset(state.text, state.selection.focus);
|
|
356
367
|
if (caret >= state.text.length) {
|
|
357
368
|
const len = state.text.length;
|
|
358
|
-
return { text: state.text, selection:
|
|
369
|
+
return { text: state.text, selection: caretSelectionAt(len, len), composition: null };
|
|
359
370
|
}
|
|
360
371
|
return replaceTextEditRange(
|
|
361
372
|
state,
|
|
@@ -394,7 +405,7 @@ function deleteWordForwardTextEdit(state: TextEditState, capacity: number): Text
|
|
|
394
405
|
const caret = snapTextCaretOffset(state.text, state.selection.focus);
|
|
395
406
|
if (caret >= state.text.length) {
|
|
396
407
|
const len = state.text.length;
|
|
397
|
-
return { text: state.text, selection:
|
|
408
|
+
return { text: state.text, selection: caretSelectionAt(len, len), composition: null };
|
|
398
409
|
}
|
|
399
410
|
return replaceTextEditRange(
|
|
400
411
|
state,
|
|
@@ -425,8 +436,8 @@ function moveTextCaret(state: TextEditState, move: TextCaretMove): TextEditState
|
|
|
425
436
|
target = state.text.length;
|
|
426
437
|
}
|
|
427
438
|
const selection: TextSelection = move.extend
|
|
428
|
-
?
|
|
429
|
-
:
|
|
439
|
+
? caretSelectionAt(state.selection.anchor, target)
|
|
440
|
+
: caretSelectionAt(target, target);
|
|
430
441
|
return {
|
|
431
442
|
text: state.text,
|
|
432
443
|
selection: snapTextCaretSelection(state.text, selection),
|
|
@@ -459,6 +459,7 @@ export class SubsetChecker {
|
|
|
459
459
|
for (const file of this.files) this.checkModuleShape(file);
|
|
460
460
|
this.checkEntryContract();
|
|
461
461
|
this.checkNameCollisions();
|
|
462
|
+
this.checkGeneratedMetadataNames();
|
|
462
463
|
this.checkModelHoldsData();
|
|
463
464
|
this.checkModelTextIsBytes();
|
|
464
465
|
this.checkCmdPurity();
|
|
@@ -1207,6 +1208,44 @@ export class SubsetChecker {
|
|
|
1207
1208
|
}
|
|
1208
1209
|
}
|
|
1209
1210
|
|
|
1211
|
+
/// NS1038 — fixed declarations consumed by the contract extractor share
|
|
1212
|
+
/// the emitted Zig namespace with authored declarations. Reserve the
|
|
1213
|
+
/// module-level type-origin table and each union's payload-member table so
|
|
1214
|
+
/// a valid TypeScript name fails with a teaching instead of duplicate Zig.
|
|
1215
|
+
private checkGeneratedMetadataNames(): void {
|
|
1216
|
+
const reportTypeOrigins = (name: ts.Identifier): void => {
|
|
1217
|
+
if (name.text === "type_origins") {
|
|
1218
|
+
this.report("NS1038", "`type_origins` collides with the generated contract type-origin metadata declaration.", name);
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
for (const file of this.files) {
|
|
1222
|
+
for (const stmt of file.statements) {
|
|
1223
|
+
if (
|
|
1224
|
+
ts.isInterfaceDeclaration(stmt) ||
|
|
1225
|
+
ts.isTypeAliasDeclaration(stmt) ||
|
|
1226
|
+
ts.isClassDeclaration(stmt) ||
|
|
1227
|
+
ts.isFunctionDeclaration(stmt)
|
|
1228
|
+
) {
|
|
1229
|
+
if (stmt.name) reportTypeOrigins(stmt.name);
|
|
1230
|
+
} else if (ts.isVariableStatement(stmt)) {
|
|
1231
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
1232
|
+
if (ts.isIdentifier(decl.name)) reportTypeOrigins(decl.name);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
for (const binding of exportListBindings(this.tast, file)) {
|
|
1237
|
+
if (binding.exportedName === "type_origins") {
|
|
1238
|
+
this.report("NS1038", "`type_origins` collides with the generated contract type-origin metadata declaration.", binding.spec.name);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
for (const union of this.table.unions.values()) {
|
|
1243
|
+
if (union.arms.some((arm) => arm.fields.length === 1) && union.arms.some((arm) => arm.tag === "payload_members")) {
|
|
1244
|
+
this.report("NS1038", `Union \`${union.name}\` has an arm named \`payload_members\`, which collides with its generated single-payload metadata declaration.`, union.decl.name);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1210
1249
|
/// NS1003: no function-typed fields anywhere in the model/message tree.
|
|
1211
1250
|
private checkModelHoldsData(): void {
|
|
1212
1251
|
const scanFields = (typeName: string, seen: Set<string>): void => {
|
|
@@ -269,7 +269,7 @@ const emittedFixtureNames = [
|
|
|
269
269
|
"jsPow", "tagEq", "tagIsNull",
|
|
270
270
|
"tagCast", "strEq", "strIsNull", "numEq", "numIsNull", "empty_bytes", "UpdateResult", "InitResult",
|
|
271
271
|
"CommitMode", "commitBytes", "commitScalars", "commitModelRoot",
|
|
272
|
-
"shouldCopy", "inOldHeap", "old_heap_base", "old_heap_len", "core_root",
|
|
272
|
+
"shouldCopy", "inOldHeap", "old_heap_base", "old_heap_len", "core_root", "type_origins",
|
|
273
273
|
] as const;
|
|
274
274
|
|
|
275
275
|
/// The `Cmd.audio*` control verbs and their zig enum literals (`resume` is a
|
|
@@ -375,6 +375,7 @@ export class Emitter {
|
|
|
375
375
|
this.fileSet = new Set(this.files);
|
|
376
376
|
this.sourceName = sourceName;
|
|
377
377
|
this.capacities = capacities;
|
|
378
|
+
this.validateGeneratedMetadataNames();
|
|
378
379
|
this.claimModuleNames();
|
|
379
380
|
this.computeExceptions();
|
|
380
381
|
}
|
|
@@ -520,6 +521,43 @@ export class Emitter {
|
|
|
520
521
|
return found;
|
|
521
522
|
}
|
|
522
523
|
|
|
524
|
+
/// Layer-3 re-derivation of the fixed names the contract extractor reads.
|
|
525
|
+
/// The checker gives the normal teaching; this fence prevents a direct
|
|
526
|
+
/// emitter caller from producing duplicate Zig declarations.
|
|
527
|
+
private validateGeneratedMetadataNames(): void {
|
|
528
|
+
const refuseTypeOrigins = (name: ts.Identifier): void => {
|
|
529
|
+
if (name.text === "type_origins") {
|
|
530
|
+
this.fail(name, "`type_origins` collides with the generated contract type-origin metadata declaration; rename the authored declaration.", "NS1038");
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
for (const file of this.files) {
|
|
534
|
+
for (const stmt of file.statements) {
|
|
535
|
+
if (
|
|
536
|
+
ts.isInterfaceDeclaration(stmt) ||
|
|
537
|
+
ts.isTypeAliasDeclaration(stmt) ||
|
|
538
|
+
ts.isClassDeclaration(stmt) ||
|
|
539
|
+
ts.isFunctionDeclaration(stmt)
|
|
540
|
+
) {
|
|
541
|
+
if (stmt.name) refuseTypeOrigins(stmt.name);
|
|
542
|
+
} else if (ts.isVariableStatement(stmt)) {
|
|
543
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
544
|
+
if (ts.isIdentifier(decl.name)) refuseTypeOrigins(decl.name);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
for (const binding of exportListBindings(this.tast, file)) {
|
|
549
|
+
if (binding.exportedName === "type_origins") {
|
|
550
|
+
this.fail(binding.spec.name, "`type_origins` collides with the generated contract type-origin metadata declaration; rename the export.", "NS1038");
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
for (const union of this.table.unions.values()) {
|
|
555
|
+
if (union.arms.some((arm) => arm.fields.length === 1) && union.arms.some((arm) => arm.tag === "payload_members")) {
|
|
556
|
+
this.fail(union.decl.name, `Union \`${union.name}\` has an arm named \`payload_members\`, which collides with its generated single-payload metadata declaration; rename the arm.`, "NS1038");
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
523
561
|
/// Claim every module-level name up front, across all files: fixture
|
|
524
562
|
/// names first, then types (never renamed), then exported values (never
|
|
525
563
|
/// renamed), then private values entry-first — a private collision takes
|
|
@@ -1014,10 +1052,68 @@ export class Emitter {
|
|
|
1014
1052
|
this.emitHoistedFunctions();
|
|
1015
1053
|
}
|
|
1016
1054
|
this.emitInstantiatedTypes();
|
|
1055
|
+
this.emitTypeOrigins();
|
|
1017
1056
|
this.emitCommitWalkers();
|
|
1018
1057
|
return this.out.join("\n") + "\n";
|
|
1019
1058
|
}
|
|
1020
1059
|
|
|
1060
|
+
/// The declaring module of every named type the contract tables can
|
|
1061
|
+
/// reach — a contract fact the sidecar extractor carries so a contract
|
|
1062
|
+
/// consumer can re-export each type from its own module. SDK library
|
|
1063
|
+
/// modules spell their shipped staging path (`sdk/<name>.ts`); the
|
|
1064
|
+
/// core's own modules spell their path relative to the entry module's
|
|
1065
|
+
/// directory, with POSIX separators because the sidecar/facade contract is
|
|
1066
|
+
/// platform-independent. Synthesized (anonymous) type names stay out:
|
|
1067
|
+
/// they are declared nowhere.
|
|
1068
|
+
private emitTypeOrigins(): void {
|
|
1069
|
+
const sdkDir = path.resolve(path.dirname(sdkCoreModulePath));
|
|
1070
|
+
const entryDir = path.dirname(path.resolve(this.file.fileName));
|
|
1071
|
+
const seen = new Set<string>();
|
|
1072
|
+
const entries: string[] = [];
|
|
1073
|
+
for (const file of this.files) {
|
|
1074
|
+
for (const stmt of file.statements) {
|
|
1075
|
+
if (!ts.isInterfaceDeclaration(stmt) && !ts.isTypeAliasDeclaration(stmt) && !ts.isClassDeclaration(stmt)) continue;
|
|
1076
|
+
if (!stmt.name) continue;
|
|
1077
|
+
const name = stmt.name.text;
|
|
1078
|
+
if (seen.has(name)) continue;
|
|
1079
|
+
if (!this.table.structs.has(name) && !this.table.enums.has(name) && !this.table.unions.has(name)) continue;
|
|
1080
|
+
if (this.table.genericStructTemplates.has(name) || this.table.genericAliasTemplates.has(name)) continue;
|
|
1081
|
+
seen.add(name);
|
|
1082
|
+
const fileName = path.resolve(file.fileName);
|
|
1083
|
+
const origin =
|
|
1084
|
+
path.dirname(fileName) === sdkDir
|
|
1085
|
+
? `sdk/${path.basename(fileName)}`
|
|
1086
|
+
: path.relative(entryDir, fileName).split(path.sep).join("/");
|
|
1087
|
+
const exported =
|
|
1088
|
+
hasExportModifier(stmt) ||
|
|
1089
|
+
file.statements.some(
|
|
1090
|
+
(candidate) =>
|
|
1091
|
+
ts.isExportDeclaration(candidate) &&
|
|
1092
|
+
candidate.moduleSpecifier === undefined &&
|
|
1093
|
+
candidate.exportClause !== undefined &&
|
|
1094
|
+
ts.isNamedExports(candidate.exportClause) &&
|
|
1095
|
+
candidate.exportClause.elements.some(
|
|
1096
|
+
(spec) => spec.name.text === name && this.tast.exportSpecifierTarget(spec) === stmt,
|
|
1097
|
+
),
|
|
1098
|
+
);
|
|
1099
|
+
// The third tuple field is additive and appears only for a private
|
|
1100
|
+
// declaration. Older extractors keep reading the two origin fields;
|
|
1101
|
+
// current ones use the marker to synthesize a structural facade type
|
|
1102
|
+
// instead of importing a name its module does not export.
|
|
1103
|
+
entries.push(` .{ ${zigString(name)}, ${zigString(origin)}${exported ? "" : ", false"} },`);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if (entries.length === 0) return;
|
|
1107
|
+
this.out.push(``);
|
|
1108
|
+
this.out.push(`// The declaring module of every named contract-table type (the sidecar`);
|
|
1109
|
+
this.out.push(`// extractor's origin facts; a third false field marks declarations the`);
|
|
1110
|
+
this.out.push(`// authored module does not export. Synthesized names are declared nowhere`);
|
|
1111
|
+
this.out.push(`// and stay out).`);
|
|
1112
|
+
this.out.push(`pub const type_origins = .{`);
|
|
1113
|
+
this.out.push(...entries);
|
|
1114
|
+
this.out.push(`};`);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1021
1117
|
/// R15e: emit every queued generic instantiation under its resolved
|
|
1022
1118
|
/// type-parameter scope.
|
|
1023
1119
|
private emitGenericInstantiations(): void {
|
|
@@ -1953,6 +2049,18 @@ export class Emitter {
|
|
|
1953
2049
|
this.out.push(` ${zigId(arm.tag)}: struct { ${fields.join(", ")} },`);
|
|
1954
2050
|
}
|
|
1955
2051
|
}
|
|
2052
|
+
const singles = un.arms.filter((a) => a.fields.length === 1);
|
|
2053
|
+
if (singles.length > 0) {
|
|
2054
|
+
// The authored member name of each single-payload arm: the arm's
|
|
2055
|
+
// emitted payload spells the bare type, erasing the author's
|
|
2056
|
+
// spelling, so the sidecar extractor reads it from this table (a
|
|
2057
|
+
// contract consumer constructing arm values needs the author's
|
|
2058
|
+
// property names).
|
|
2059
|
+
this.out.push(``);
|
|
2060
|
+
this.out.push(
|
|
2061
|
+
` pub const payload_members = .{ ${singles.map((a) => `.${zigId(a.tag)} = ${zigString(a.fields[0].tsName)}`).join(", ")} };`,
|
|
2062
|
+
);
|
|
2063
|
+
}
|
|
1956
2064
|
if (name === "Msg" && this.unbound.msg.length > 0) {
|
|
1957
2065
|
// The dead-state lint opt-out `native check` reads (viewUnbound).
|
|
1958
2066
|
this.out.push(``);
|
|
@@ -1985,6 +2093,7 @@ export class Emitter {
|
|
|
1985
2093
|
const names = new Set<string>(emittedFixtureNames);
|
|
1986
2094
|
names.add("Thrown");
|
|
1987
2095
|
names.add("thrown_payload");
|
|
2096
|
+
names.add("type_origins");
|
|
1988
2097
|
names.add(THROWN_UNION_NAME);
|
|
1989
2098
|
for (const file of this.files) {
|
|
1990
2099
|
for (const stmt of file.statements) {
|
|
@@ -11611,6 +11720,21 @@ function zigId(name: string): string {
|
|
|
11611
11720
|
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name) ? name : `@"${name}"`;
|
|
11612
11721
|
}
|
|
11613
11722
|
|
|
11723
|
+
/// A Zig double-quoted string literal for an authored spelling (name
|
|
11724
|
+
/// tables the sidecar extractor reads).
|
|
11725
|
+
function zigString(text: string): string {
|
|
11726
|
+
let out = '"';
|
|
11727
|
+
for (const ch of text) {
|
|
11728
|
+
if (ch === '"') out += '\\"';
|
|
11729
|
+
else if (ch === "\\") out += "\\\\";
|
|
11730
|
+
else if (ch === "\n") out += "\\n";
|
|
11731
|
+
else if (ch === "\r") out += "\\r";
|
|
11732
|
+
else if (ch === "\t") out += "\\t";
|
|
11733
|
+
else out += ch;
|
|
11734
|
+
}
|
|
11735
|
+
return out + '"';
|
|
11736
|
+
}
|
|
11737
|
+
|
|
11614
11738
|
/// Zig keywords that are legal JS label identifiers — a TS label with one of
|
|
11615
11739
|
/// these names takes a suffix so the emitted `label: while` stays parseable.
|
|
11616
11740
|
const zigOnlyKeywords = new Set([
|