@native-sdk/cli 0.9.0 → 0.9.2

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 (181) hide show
  1. package/build/app.zig +357 -33
  2. package/build.zig +234 -11
  3. package/native-sdk.d.ts +8 -0
  4. package/package.json +10 -10
  5. package/packages/core/compile-surface/core.ts +70 -1
  6. package/packages/core/package-lock.json +11 -11
  7. package/packages/core/package.json +2 -2
  8. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  9. package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
  10. package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
  11. package/packages/core/scripts/stage_external_services.mjs +1 -1
  12. package/packages/core/sdk/core.d.ts +75 -0
  13. package/packages/core/sdk/core.ts +170 -13
  14. package/packages/core/sdk/events.d.ts +53 -0
  15. package/packages/core/sdk/events.ts +78 -7
  16. package/packages/core/src/checker.ts +470 -2
  17. package/packages/core/src/cli.ts +13 -0
  18. package/packages/core/src/contract.ts +3 -1
  19. package/packages/core/src/devhost.ts +30 -1
  20. package/packages/core/src/devhost_journal.mjs +10 -8
  21. package/packages/core/src/diagnostics.ts +99 -8
  22. package/packages/core/src/frontend.ts +6 -0
  23. package/packages/core/src/infer.ts +24 -0
  24. package/skill-data/automation/SKILL.md +1 -1
  25. package/skill-data/native-ui/SKILL.md +18 -12
  26. package/skill-data/ts-core/SKILL.md +54 -21
  27. package/skill-data/ts-services/SKILL.md +4 -4
  28. package/skill-data/ts-services/references/service-surface.md +2 -1
  29. package/skill-data/zig/SKILL.md +1 -1
  30. package/src/app_runner/root.zig +122 -6
  31. package/src/app_runner/ts_core_main.zig +9 -4
  32. package/src/app_runner/ts_core_mobile.zig +241 -0
  33. package/src/app_runner/window_placement.zig +63 -0
  34. package/src/automation/protocol.zig +5 -1
  35. package/src/automation/snapshot.zig +8 -6
  36. package/src/embed/app_exports.zig +3 -1
  37. package/src/embed/conversions.zig +1 -0
  38. package/src/embed/host.zig +10 -3
  39. package/src/embed/root.zig +2 -0
  40. package/src/embed/tests.zig +41 -1
  41. package/src/embed/types.zig +2 -0
  42. package/src/embed/ui_host.zig +94 -4
  43. package/src/platform/android/NativeSdkActivity.java +49 -4
  44. package/src/platform/android/android_host.c +3 -3
  45. package/src/platform/android/native_sdk_app.h +1 -1
  46. package/src/platform/ios/apple_image_fit.h +38 -0
  47. package/src/platform/ios/files.zig +1 -0
  48. package/src/platform/ios/native_sdk_app.h +1 -1
  49. package/src/platform/ios/uikit_host.m +28 -5
  50. package/src/platform/linux/cef_host.cpp +17 -3
  51. package/src/platform/linux/gtk_host.c +243 -15
  52. package/src/platform/linux/gtk_host.h +5 -4
  53. package/src/platform/linux/root.zig +91 -11
  54. package/src/platform/macos/appkit_host.h +18 -11
  55. package/src/platform/macos/appkit_host.m +402 -128
  56. package/src/platform/macos/cef_host.mm +342 -122
  57. package/src/platform/macos/image_fit_test.m +44 -0
  58. package/src/platform/macos/root.zig +231 -39
  59. package/src/platform/null_platform.zig +251 -54
  60. package/src/platform/null_platform_tests.zig +97 -4
  61. package/src/platform/root.zig +12 -0
  62. package/src/platform/types.zig +174 -35
  63. package/src/platform/windows/root.zig +42 -13
  64. package/src/platform/windows/webview2_host.cpp +72 -11
  65. package/src/primitives/app_manifest/root.zig +3 -0
  66. package/src/primitives/app_manifest/tests.zig +24 -0
  67. package/src/primitives/app_manifest/types.zig +13 -0
  68. package/src/primitives/app_manifest/validation.zig +24 -0
  69. package/src/primitives/canvas/a11y_audit.zig +9 -7
  70. package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
  71. package/src/primitives/canvas/events.zig +50 -0
  72. package/src/primitives/canvas/layout_audit.zig +6 -6
  73. package/src/primitives/canvas/markdown.zig +4 -0
  74. package/src/primitives/canvas/markdown_tests.zig +1 -0
  75. package/src/primitives/canvas/png.zig +138 -0
  76. package/src/primitives/canvas/root.zig +13 -2
  77. package/src/primitives/canvas/text_span_tests.zig +5 -3
  78. package/src/primitives/canvas/text_spans.zig +2 -0
  79. package/src/primitives/canvas/text_tests.zig +20 -0
  80. package/src/primitives/canvas/ui.zig +55 -2
  81. package/src/primitives/canvas/ui_markup.zig +40 -13
  82. package/src/primitives/canvas/ui_markup_binary.zig +8 -6
  83. package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
  84. package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
  85. package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
  86. package/src/primitives/canvas/ui_markup_tests.zig +11 -2
  87. package/src/primitives/canvas/ui_markup_view.zig +8 -2
  88. package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
  89. package/src/primitives/canvas/ui_schema.zig +17 -13
  90. package/src/primitives/canvas/ui_tests.zig +47 -0
  91. package/src/primitives/canvas/widget_access.zig +3 -3
  92. package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
  93. package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
  94. package/src/primitives/canvas/widget_invalidation.zig +33 -6
  95. package/src/primitives/canvas/widget_layout.zig +333 -126
  96. package/src/primitives/canvas/widget_layout_tests.zig +169 -0
  97. package/src/primitives/canvas/widget_metrics.zig +7 -8
  98. package/src/primitives/canvas/widget_render.zig +76 -44
  99. package/src/primitives/canvas/widget_render_controls.zig +110 -32
  100. package/src/primitives/canvas/widget_render_style.zig +58 -18
  101. package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
  102. package/src/primitives/canvas/widget_routing.zig +40 -34
  103. package/src/primitives/canvas/widget_runtime.zig +11 -2
  104. package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
  105. package/src/primitives/canvas/widget_semantics.zig +8 -3
  106. package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
  107. package/src/primitives/canvas/widget_tree.zig +99 -5
  108. package/src/primitives/canvas/widgets.zig +20 -7
  109. package/src/root.zig +10 -0
  110. package/src/runtime/api.zig +14 -0
  111. package/src/runtime/automation_commands.zig +35 -2
  112. package/src/runtime/automation_snapshot.zig +32 -24
  113. package/src/runtime/automation_widget_dispatch.zig +48 -6
  114. package/src/runtime/bridge_permission_tests.zig +35 -1
  115. package/src/runtime/bridge_responses.zig +1 -1
  116. package/src/runtime/builtin_bridge.zig +16 -3
  117. package/src/runtime/canvas_frame_packet_tests.zig +22 -13
  118. package/src/runtime/canvas_image_tests.zig +146 -2
  119. package/src/runtime/canvas_images.zig +35 -16
  120. package/src/runtime/canvas_limits.zig +13 -3
  121. package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
  122. package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
  123. package/src/runtime/canvas_widget_control_tests.zig +31 -1
  124. package/src/runtime/canvas_widget_events.zig +151 -26
  125. package/src/runtime/canvas_widget_floating_tests.zig +48 -0
  126. package/src/runtime/canvas_widget_runtime.zig +322 -102
  127. package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
  128. package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
  129. package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
  130. package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
  131. package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
  132. package/src/runtime/canvas_widget_state.zig +33 -7
  133. package/src/runtime/core.zig +28 -6
  134. package/src/runtime/effects.zig +1337 -49
  135. package/src/runtime/effects_file_tests.zig +587 -0
  136. package/src/runtime/effects_image_tests.zig +91 -0
  137. package/src/runtime/effects_notification_tests.zig +11 -0
  138. package/src/runtime/file_access.zig +400 -0
  139. package/src/runtime/file_effect_crash_helper.zig +28 -0
  140. package/src/runtime/file_effect_crash_tests.zig +37 -0
  141. package/src/runtime/flow.zig +21 -9
  142. package/src/runtime/gpu_surface_events.zig +25 -2
  143. package/src/runtime/native_command_event_tests.zig +44 -2
  144. package/src/runtime/pty.zig +5 -2
  145. package/src/runtime/root.zig +7 -0
  146. package/src/runtime/session_blobs.zig +4 -1
  147. package/src/runtime/session_journal.zig +56 -5
  148. package/src/runtime/session_record.zig +38 -0
  149. package/src/runtime/session_replay.zig +110 -15
  150. package/src/runtime/session_tests.zig +192 -4
  151. package/src/runtime/shell_layout_tests.zig +12 -0
  152. package/src/runtime/state.zig +10 -0
  153. package/src/runtime/system_services.zig +129 -36
  154. package/src/runtime/ts_core_host.zig +281 -11
  155. package/src/runtime/ts_core_host_tests.zig +142 -1
  156. package/src/runtime/ts_ui_app.zig +461 -8
  157. package/src/runtime/ui_app.zig +330 -112
  158. package/src/runtime/ui_app_tests.zig +251 -25
  159. package/src/runtime/ui_app_window_tests.zig +74 -8
  160. package/src/runtime/validation.zig +20 -0
  161. package/src/runtime/view.zig +3 -0
  162. package/src/runtime/view_widget_control.zig +18 -0
  163. package/src/runtime/view_widget_scroll.zig +112 -18
  164. package/src/runtime/view_widget_tree.zig +110 -13
  165. package/src/runtime/widget_bridge.zig +2 -0
  166. package/src/runtime/window_command_bridge_tests.zig +86 -0
  167. package/src/runtime/window_storage.zig +16 -1
  168. package/src/runtime/window_views.zig +1 -0
  169. package/src/tooling/ios.zig +3 -0
  170. package/src/tooling/manifest.zig +90 -2
  171. package/src/tooling/package.zig +67 -2
  172. package/src/tooling/raw_manifest.zig +10 -0
  173. package/src/tooling/templates.zig +156 -18
  174. package/src/tooling/ts_core.zig +83 -0
  175. package/src/tooling/web_engine.zig +1 -1
  176. package/tools/corewire/emit.zig +3 -3
  177. package/tools/corewire/emit_facade.zig +65 -5
  178. package/tools/corewire/emit_profile.zig +2 -2
  179. package/tools/corewire/emit_service.zig +2 -2
  180. package/tools/corewire/service_contract.zig +4 -4
  181. package/tools/corewire/sidecar.zig +4 -4
@@ -462,6 +462,7 @@ export class SubsetChecker {
462
462
  private readonly permissions: Set<string>;
463
463
  private readonly persistRoutes: PersistRoutes | undefined;
464
464
  private readonly sdkCorePath: string;
465
+ private readonly windowViews: ReadonlySet<string> | undefined;
465
466
  private usesPersist = false;
466
467
  private usesStore = false;
467
468
  private usesSqlite = false;
@@ -476,6 +477,7 @@ export class SubsetChecker {
476
477
  permissions: readonly string[] = [],
477
478
  persistRoutes?: PersistRoutes,
478
479
  sdkCorePath: string = sdkCoreModulePath,
480
+ windowViews?: readonly string[],
479
481
  ) {
480
482
  this.tast = tast;
481
483
  this.table = table;
@@ -487,6 +489,7 @@ export class SubsetChecker {
487
489
  this.permissions = new Set(permissions);
488
490
  this.persistRoutes = persistRoutes;
489
491
  this.sdkCorePath = sdkCorePath;
492
+ this.windowViews = windowViews === undefined ? undefined : new Set(windowViews);
490
493
  }
491
494
 
492
495
  check(): CheckResult {
@@ -505,6 +508,8 @@ export class SubsetChecker {
505
508
  this.checkMigrationHook();
506
509
  this.checkThemePackHelper();
507
510
  this.checkStatusItemHelper();
511
+ this.checkStatusItemsHelper();
512
+ this.checkWindowsHelper();
508
513
  this.checkViewUnbound();
509
514
  this.checkReservedContractConsts();
510
515
  this.checkValueRecordAliases();
@@ -988,12 +993,453 @@ export class SubsetChecker {
988
993
  if (!valid) {
989
994
  this.report(
990
995
  "NS1033",
991
- "`statusItem` must return the exact canonical `StatusItemState` record (presentation, install-time shell fields, and rich menu rows); import it from `@native-sdk/core/events`.",
996
+ "`statusItem` must return the exact canonical `StatusItemState` record (live presentation, shell fields, and rich menu rows); import it from `@native-sdk/core/events`.",
992
997
  decl.type,
993
998
  );
994
999
  }
995
1000
  }
996
1001
 
1002
+ /// One entry-module function exported under its own wiring name. The
1003
+ /// entry-contract pass separately teaches re-exports and renames; this
1004
+ /// query lets related channels prove that the generated launcher will
1005
+ /// actually have the named callback available.
1006
+ private entryExportedFunction(name: string): ts.FunctionDeclaration | null {
1007
+ for (const stmt of this.entry.statements) {
1008
+ if (ts.isFunctionDeclaration(stmt) && stmt.name?.text === name && hasExportModifier(stmt)) return stmt;
1009
+ }
1010
+ for (const binding of exportListBindings(this.tast, this.entry)) {
1011
+ if (
1012
+ binding.exportedName === name &&
1013
+ !binding.renamed &&
1014
+ binding.target !== null &&
1015
+ binding.target !== undefined &&
1016
+ ts.isFunctionDeclaration(binding.target) &&
1017
+ binding.target.getSourceFile() === this.entry
1018
+ ) {
1019
+ return binding.target;
1020
+ }
1021
+ }
1022
+ return null;
1023
+ }
1024
+
1025
+ /// The generated launcher owns a closed, comptime-compiled registry keyed
1026
+ /// by direct `src/windows/<label>.native` stems. Require every possible
1027
+ /// descriptor to declare that identity as a literal at its canonical
1028
+ /// constructor call, then prove the root exists before compilation. This
1029
+ /// turns a would-be first-render panic into a source diagnostic in both
1030
+ /// `native check` and every build.
1031
+ private checkWindowViewRegistry(windowsDecl: ts.FunctionDeclaration): void {
1032
+ if (this.windowViews === undefined) return;
1033
+
1034
+ type ProducedKind = "collection" | "descriptor";
1035
+ let sawConstructor = false;
1036
+ let productionErrors = 0;
1037
+ const validatingCollections = new Set<ts.FunctionDeclaration>();
1038
+ const validatingDescriptors = new Set<ts.FunctionDeclaration>();
1039
+ const validatedCollections = new Set<ts.FunctionDeclaration>();
1040
+ const validatedDescriptors = new Set<ts.FunctionDeclaration>();
1041
+
1042
+ const unwrap = (expression: ts.Expression): ts.Expression => {
1043
+ let current = expression;
1044
+ while (
1045
+ ts.isParenthesizedExpression(current) ||
1046
+ ts.isAsExpression(current) ||
1047
+ ts.isSatisfiesExpression(current) ||
1048
+ ts.isNonNullExpression(current)
1049
+ ) {
1050
+ current = current.expression;
1051
+ }
1052
+ return current;
1053
+ };
1054
+
1055
+ const reportProduction = (node: ts.Node, kind: ProducedKind): void => {
1056
+ productionErrors += 1;
1057
+ this.report(
1058
+ "NS1033",
1059
+ kind === "collection"
1060
+ ? "Every value returned by `windows` must be an array literal of direct `windowDescriptor(...)` results (factored constructor helpers are fine); copied, spread, or mutable descriptor collections can replace the statically registered label."
1061
+ : "Every window returned by `windows` must flow directly from `windowDescriptor({...})` (or a helper whose own returns do); copying, spreading, or rebuilding a descriptor can replace its statically registered label.",
1062
+ node,
1063
+ );
1064
+ };
1065
+
1066
+ const appFunctionTarget = (call: ts.CallExpression): ts.FunctionDeclaration | null => {
1067
+ if (!ts.isIdentifier(call.expression) && !ts.isPropertyAccessExpression(call.expression)) return null;
1068
+ const target = this.tast.declarationOf(
1069
+ ts.isIdentifier(call.expression) ? call.expression : call.expression.name,
1070
+ );
1071
+ return target && ts.isFunctionDeclaration(target) && this.fileSet.has(target.getSourceFile()) ? target : null;
1072
+ };
1073
+
1074
+ const returnExpressions = (fn: ts.FunctionDeclaration): ts.Expression[] => {
1075
+ const returns: ts.Expression[] = [];
1076
+ const visit = (node: ts.Node): void => {
1077
+ if (node !== fn && (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node))) return;
1078
+ if (ts.isReturnStatement(node)) {
1079
+ if (node.expression) returns.push(node.expression);
1080
+ return;
1081
+ }
1082
+ ts.forEachChild(node, visit);
1083
+ };
1084
+ if (fn.body) visit(fn.body);
1085
+ return returns;
1086
+ };
1087
+
1088
+ const validateConstructor = (call: ts.CallExpression): void => {
1089
+ sawConstructor = true;
1090
+ const spec = call.arguments[0];
1091
+ if (!spec || !ts.isObjectLiteralExpression(unwrap(spec))) {
1092
+ productionErrors += 1;
1093
+ this.report(
1094
+ "NS1033",
1095
+ "A model-declared window must pass an inline object to `windowDescriptor`, with a static `label: asciiBytes(\"<label>\")` property selecting its compiled view.",
1096
+ spec ?? call,
1097
+ );
1098
+ return;
1099
+ }
1100
+ const object = unwrap(spec) as ts.ObjectLiteralExpression;
1101
+ const labelProp = object.properties.find((prop): prop is ts.PropertyAssignment =>
1102
+ ts.isPropertyAssignment(prop) &&
1103
+ ((ts.isIdentifier(prop.name) && prop.name.text === "label") ||
1104
+ (ts.isStringLiteral(prop.name) && prop.name.text === "label")),
1105
+ );
1106
+ const labelIndex = labelProp === undefined ? -1 : object.properties.indexOf(labelProp);
1107
+ if (object.properties.some((property, index) => ts.isSpreadAssignment(property) && index > labelIndex)) {
1108
+ productionErrors += 1;
1109
+ this.report(
1110
+ "NS1033",
1111
+ "A `windowDescriptor` spec cannot spread fields after its literal label: that spread can replace the identity after the registry check. Move the literal label after every spread.",
1112
+ object,
1113
+ );
1114
+ return;
1115
+ }
1116
+ const labelExpr = labelProp?.initializer;
1117
+ const labelArg = labelExpr && ts.isCallExpression(labelExpr) &&
1118
+ this.sdkRootFunctionName(labelExpr.expression) === "asciiBytes"
1119
+ ? labelExpr.arguments[0]
1120
+ : undefined;
1121
+ if (!labelArg || !ts.isStringLiteral(labelArg)) {
1122
+ productionErrors += 1;
1123
+ this.report(
1124
+ "NS1033",
1125
+ "A model-declared window label must be a static `asciiBytes(\"<label>\")` property inside `windowDescriptor({...})`; that literal selects `src/windows/<label>.native` at build time.",
1126
+ labelProp ?? object,
1127
+ );
1128
+ return;
1129
+ }
1130
+ const label = labelArg.text;
1131
+ if (
1132
+ label.length === 0 ||
1133
+ label.length > 64 ||
1134
+ label === "." ||
1135
+ label === ".." ||
1136
+ label.includes("\0") ||
1137
+ label.includes("/") ||
1138
+ label.includes("\\")
1139
+ ) {
1140
+ productionErrors += 1;
1141
+ this.report(
1142
+ "NS1033",
1143
+ "A model-declared window label must be a non-empty filename stem of at most 64 ASCII bytes, without path separators or NUL bytes.",
1144
+ labelArg,
1145
+ );
1146
+ return;
1147
+ }
1148
+ if (!this.windowViews.has(labelArg.text)) {
1149
+ productionErrors += 1;
1150
+ this.report(
1151
+ "NS1033",
1152
+ `Window label \`${labelArg.text}\` has no compiled view; add \`src/windows/${labelArg.text}.native\` or change the descriptor label to an existing root.`,
1153
+ labelArg,
1154
+ );
1155
+ }
1156
+
1157
+ const propertyNamed = (name: string): ts.PropertyAssignment | undefined =>
1158
+ object.properties.find((prop): prop is ts.PropertyAssignment =>
1159
+ ts.isPropertyAssignment(prop) &&
1160
+ ((ts.isIdentifier(prop.name) && prop.name.text === name) ||
1161
+ (ts.isStringLiteral(prop.name) && prop.name.text === name)),
1162
+ );
1163
+ const closePolicy = propertyNamed("closePolicy")?.initializer;
1164
+ const alwaysHides = closePolicy !== undefined && ts.isStringLiteral(unwrap(closePolicy)) && unwrap(closePolicy).text === "hide";
1165
+ const closeCommand = propertyNamed("onCloseCommand")?.initializer;
1166
+ const closeCommandArg = closeCommand !== undefined && ts.isCallExpression(unwrap(closeCommand)) &&
1167
+ this.sdkRootFunctionName((unwrap(closeCommand) as ts.CallExpression).expression) === "asciiBytes"
1168
+ ? (unwrap(closeCommand) as ts.CallExpression).arguments[0]
1169
+ : undefined;
1170
+ const definitelyEmptyCloseCommand = closeCommandArg !== undefined && ts.isStringLiteral(closeCommandArg) && closeCommandArg.text.length === 0;
1171
+ if (
1172
+ closeCommand !== undefined &&
1173
+ !definitelyEmptyCloseCommand &&
1174
+ !alwaysHides &&
1175
+ this.entryExportedFunction("commandMsg") === null
1176
+ ) {
1177
+ productionErrors += 1;
1178
+ this.report(
1179
+ "NS1033",
1180
+ "A quit-close `onCloseCommand` requires `commandMsg(name: string): Msg | null`; otherwise the generated launcher cannot map the command to the Msg that removes the window declaration.",
1181
+ closeCommand,
1182
+ );
1183
+ }
1184
+ };
1185
+
1186
+ const validateFunction = (fn: ts.FunctionDeclaration, kind: ProducedKind): void => {
1187
+ const validating = kind === "collection" ? validatingCollections : validatingDescriptors;
1188
+ const validated = kind === "collection" ? validatedCollections : validatedDescriptors;
1189
+ if (validated.has(fn) || validating.has(fn)) return;
1190
+ validating.add(fn);
1191
+ const returns = returnExpressions(fn);
1192
+ if (returns.length === 0) reportProduction(fn.name ?? fn, kind);
1193
+ for (const expression of returns) validateExpression(expression, kind);
1194
+ validating.delete(fn);
1195
+ validated.add(fn);
1196
+ };
1197
+
1198
+ const validateExpression = (raw: ts.Expression, kind: ProducedKind): void => {
1199
+ const expression = unwrap(raw);
1200
+ if (ts.isConditionalExpression(expression)) {
1201
+ validateExpression(expression.whenTrue, kind);
1202
+ validateExpression(expression.whenFalse, kind);
1203
+ return;
1204
+ }
1205
+ if (kind === "collection" && ts.isArrayLiteralExpression(expression)) {
1206
+ for (const element of expression.elements) {
1207
+ if (ts.isSpreadElement(element)) validateExpression(element.expression, "collection");
1208
+ else validateExpression(element, "descriptor");
1209
+ }
1210
+ return;
1211
+ }
1212
+ if (kind === "descriptor" && ts.isIdentifier(expression)) {
1213
+ const declaration = this.tast.declarationOf(expression);
1214
+ if (
1215
+ declaration &&
1216
+ ts.isVariableDeclaration(declaration) &&
1217
+ declaration.initializer &&
1218
+ ts.isVariableDeclarationList(declaration.parent) &&
1219
+ (declaration.parent.flags & ts.NodeFlags.Const) !== 0
1220
+ ) {
1221
+ validateExpression(declaration.initializer, "descriptor");
1222
+ return;
1223
+ }
1224
+ }
1225
+ if (ts.isCallExpression(expression)) {
1226
+ if (kind === "descriptor" && this.sdkRootFunctionName(expression.expression) === "windowDescriptor") {
1227
+ validateConstructor(expression);
1228
+ return;
1229
+ }
1230
+ const helper = appFunctionTarget(expression);
1231
+ if (helper) {
1232
+ validateFunction(helper, kind);
1233
+ return;
1234
+ }
1235
+ }
1236
+ reportProduction(expression, kind);
1237
+ };
1238
+
1239
+ validateFunction(windowsDecl, "collection");
1240
+
1241
+ if (!sawConstructor && productionErrors === 0) {
1242
+ this.report(
1243
+ "NS1033",
1244
+ "`windows` must construct each possible entry with `windowDescriptor({ label: asciiBytes(\"<label>\"), ... })` so the generated launcher can prove its `src/windows/<label>.native` view exists.",
1245
+ windowsDecl.name ?? windowsDecl,
1246
+ );
1247
+ }
1248
+ }
1249
+
1250
+ private checkStatusItemsHelper(): void {
1251
+ let decl: ts.FunctionDeclaration | null = null;
1252
+ for (const stmt of this.entry.statements) {
1253
+ if (ts.isFunctionDeclaration(stmt) && stmt.name?.text === "statusItems" && hasExportModifier(stmt)) {
1254
+ decl = stmt;
1255
+ break;
1256
+ }
1257
+ }
1258
+ if (decl === null) {
1259
+ for (const binding of exportListBindings(this.tast, this.entry)) {
1260
+ if (
1261
+ binding.exportedName === "statusItems" &&
1262
+ binding.target !== null &&
1263
+ binding.target !== undefined &&
1264
+ ts.isFunctionDeclaration(binding.target) &&
1265
+ binding.target.getSourceFile() === this.entry
1266
+ ) {
1267
+ decl = binding.target;
1268
+ break;
1269
+ }
1270
+ }
1271
+ }
1272
+ if (decl === null) return;
1273
+ if (this.table.modelHelperDecls().some((candidate) => candidate.name === "statusItem")) {
1274
+ this.report("NS1033", "Export either `statusItem` or `statusItems`, not both.", decl.name ?? decl);
1275
+ }
1276
+ const helper = this.table.modelHelperDecls().find(
1277
+ (candidate) => candidate.name === "statusItems" && candidate.decl === decl,
1278
+ );
1279
+ if (helper === undefined || decl.type === undefined) {
1280
+ this.report(
1281
+ "NS1033",
1282
+ "`statusItems` must be a single-Model-parameter helper with an explicit return type.",
1283
+ decl.name ?? decl,
1284
+ );
1285
+ return;
1286
+ }
1287
+ const returns = this.table.resolveTypeNode(decl.type);
1288
+ const descriptorType = returns.k === "slice" && returns.elem.k === "struct" ? returns.elem : null;
1289
+ const descriptor = descriptorType === null ? undefined : this.table.structs.get(descriptorType.name);
1290
+ const names = descriptor?.fields.map((field) => field.tsName).sort() ?? [];
1291
+ const field = (name: string) => descriptor?.fields.find((candidate) => candidate.tsName === name);
1292
+ const id = field("id");
1293
+ const visible = field("visible");
1294
+ const byteFields = ["iconPath", "tooltip", "activationCommand", "alternateActivationCommand", "openCommand"].map(field);
1295
+ const presentationField = field("presentation");
1296
+ const presentationType = presentationField?.type.k === "struct" ? presentationField.type : null;
1297
+ const presentation = presentationType === null ? undefined : this.table.structs.get(presentationType.name);
1298
+ const presentationNames = presentation?.fields.map((candidate) => candidate.tsName).sort() ?? [];
1299
+ const presentationFieldNamed = (name: string) => presentation?.fields.find((candidate) => candidate.tsName === name);
1300
+ const title = presentationFieldNamed("title");
1301
+ const width = presentationFieldNamed("width");
1302
+ const tone = presentationFieldNamed("tone");
1303
+ const iconOpacity = presentationFieldNamed("iconOpacity");
1304
+ const monospaced = presentationFieldNamed("monospaced");
1305
+ const items = field("items");
1306
+ const itemType = items?.type.k === "slice" && items.type.elem.k === "struct" ? items.type.elem : null;
1307
+ const item = itemType === null ? undefined : this.table.structs.get(itemType.name);
1308
+ const itemNames = item?.fields.map((candidate) => candidate.tsName).sort() ?? [];
1309
+ const itemField = (name: string) => item?.fields.find((candidate) => candidate.tsName === name);
1310
+ const itemId = itemField("id");
1311
+ const label = itemField("label");
1312
+ const command = itemField("command");
1313
+ const separator = itemField("separator");
1314
+ const enabled = itemField("enabled");
1315
+ const detail = itemField("detail");
1316
+ const role = itemField("role");
1317
+ const key = itemField("key");
1318
+ const modifiersField = itemField("modifiers");
1319
+ const modifiersType = modifiersField?.type.k === "struct" ? modifiersField.type : null;
1320
+ const modifiers = modifiersType === null ? undefined : this.table.structs.get(modifiersType.name);
1321
+ const modifierNames = modifiers?.fields.map((candidate) => candidate.tsName).sort() ?? [];
1322
+ const numericId = id !== undefined && ["number", "i64", "f64", "numAlias"].includes(id.type.k);
1323
+ const numericItemId = itemId !== undefined && ["number", "i64", "f64", "numAlias"].includes(itemId.type.k);
1324
+ const numericWidth = width !== undefined && ["number", "i64", "f64", "numAlias"].includes(width.type.k);
1325
+ const numericOpacity = iconOpacity !== undefined && ["number", "i64", "f64", "numAlias"].includes(iconOpacity.type.k);
1326
+ const enumMembersAre = (candidate: typeof tone, expected: readonly string[]): boolean => {
1327
+ if (candidate?.type.k !== "enum") return false;
1328
+ const found = this.table.enums.get(candidate.type.name)?.members.slice().sort() ?? [];
1329
+ return found.join(",") === expected.slice().sort().join(",");
1330
+ };
1331
+ const boolModifierFields = modifiers !== undefined && modifiers.fields.every((candidate) => candidate.type.k === "bool");
1332
+ const valid =
1333
+ names.join(",") === "activationCommand,alternateActivationCommand,iconPath,id,items,openCommand,presentation,tooltip,visible" &&
1334
+ numericId &&
1335
+ visible?.type.k === "bool" &&
1336
+ byteFields.every((candidate) => candidate?.type.k === "bytes") &&
1337
+ presentationNames.join(",") === "iconOpacity,monospaced,title,tone,width" &&
1338
+ title?.type.k === "bytes" &&
1339
+ numericWidth &&
1340
+ enumMembersAre(tone, ["normal", "warning", "critical"]) &&
1341
+ numericOpacity &&
1342
+ monospaced?.type.k === "bool" &&
1343
+ itemNames.join(",") === "command,detail,enabled,id,key,label,modifiers,role,separator" &&
1344
+ numericItemId &&
1345
+ label?.type.k === "bytes" &&
1346
+ command?.type.k === "bytes" &&
1347
+ separator?.type.k === "bool" &&
1348
+ enabled?.type.k === "bool" &&
1349
+ detail?.type.k === "bytes" &&
1350
+ enumMembersAre(role, ["command", "info", "header", "hero", "agent", "context"]) &&
1351
+ key?.type.k === "bytes" &&
1352
+ modifierNames.join(",") === "command,control,option,primary,shift" &&
1353
+ boolModifierFields;
1354
+ if (!valid) {
1355
+ this.report(
1356
+ "NS1033",
1357
+ "`statusItems` must return `readonly StatusItemDescriptor[]`; import StatusItemDescriptor from `@native-sdk/core/events`.",
1358
+ decl.type,
1359
+ );
1360
+ }
1361
+ }
1362
+
1363
+ /// `windows(model)` is the TypeScript launcher's model-declared secondary
1364
+ /// window set. Keep the descriptor exact: the Zig adapter projects it into
1365
+ /// UiApp.WindowDescriptor, including close-command routing and closePolicy.
1366
+ private checkWindowsHelper(): void {
1367
+ let decl: ts.FunctionDeclaration | null = null;
1368
+ for (const stmt of this.entry.statements) {
1369
+ if (ts.isFunctionDeclaration(stmt) && stmt.name?.text === "windows" && hasExportModifier(stmt)) {
1370
+ decl = stmt;
1371
+ break;
1372
+ }
1373
+ }
1374
+ if (decl === null) {
1375
+ for (const binding of exportListBindings(this.tast, this.entry)) {
1376
+ if (
1377
+ binding.exportedName === "windows" &&
1378
+ binding.target !== null &&
1379
+ binding.target !== undefined &&
1380
+ ts.isFunctionDeclaration(binding.target) &&
1381
+ binding.target.getSourceFile() === this.entry
1382
+ ) {
1383
+ decl = binding.target;
1384
+ break;
1385
+ }
1386
+ }
1387
+ }
1388
+ if (decl === null) return;
1389
+ const helper = this.table.modelHelperDecls().find(
1390
+ (candidate) => candidate.name === "windows" && candidate.decl === decl,
1391
+ );
1392
+ if (helper === undefined || decl.type === undefined) {
1393
+ this.report(
1394
+ "NS1033",
1395
+ "`windows` must be a single-Model-parameter helper with an explicit `readonly WindowDescriptor[]` return type.",
1396
+ decl.name ?? decl,
1397
+ );
1398
+ return;
1399
+ }
1400
+ const returns = this.table.resolveTypeNode(decl.type);
1401
+ const descriptorType = returns.k === "slice" && returns.elem.k === "struct" ? returns.elem : null;
1402
+ const descriptor = descriptorType === null ? undefined : this.table.structs.get(descriptorType.name);
1403
+ const names = descriptor?.fields.map((field) => field.tsName).sort() ?? [];
1404
+ const field = (name: string) => descriptor?.fields.find((candidate) => candidate.tsName === name);
1405
+ const numeric = (name: string): boolean => {
1406
+ const candidate = field(name);
1407
+ return candidate !== undefined && ["number", "i64", "f64", "numAlias"].includes(candidate.type.k);
1408
+ };
1409
+ const enumMembersAre = (name: string, expected: readonly string[]): boolean => {
1410
+ const candidate = field(name);
1411
+ if (candidate?.type.k !== "enum") return false;
1412
+ const found = this.table.enums.get(candidate.type.name)?.members.slice().sort() ?? [];
1413
+ return found.join(",") === expected.slice().sort().join(",");
1414
+ };
1415
+ const optionalNumeric = (name: string): boolean => {
1416
+ const candidate = field(name);
1417
+ return candidate?.type.k === "optional" && ["number", "i64", "f64", "numAlias"].includes(candidate.type.inner.k);
1418
+ };
1419
+ const valid =
1420
+ names.join(",") === "activateOnShow,allowsFullscreen,alwaysOnTop,canvasLabel,clickThrough,closePolicy,height,label,minHeight,minWidth,onCloseCommand,resizable,title,titlebar,transparent,width,x,y" &&
1421
+ field("label")?.type.k === "bytes" &&
1422
+ field("canvasLabel")?.type.k === "bytes" &&
1423
+ field("title")?.type.k === "bytes" &&
1424
+ numeric("width") && numeric("height") && optionalNumeric("x") && optionalNumeric("y") &&
1425
+ field("resizable")?.type.k === "bool" && numeric("minWidth") && numeric("minHeight") &&
1426
+ enumMembersAre("titlebar", ["standard", "hidden_inset", "hidden_inset_tall", "chromeless"]) &&
1427
+ field("transparent")?.type.k === "bool" && field("alwaysOnTop")?.type.k === "bool" &&
1428
+ field("clickThrough")?.type.k === "bool" && field("activateOnShow")?.type.k === "bool" &&
1429
+ field("allowsFullscreen")?.type.k === "bool" && enumMembersAre("closePolicy", ["quit", "hide"]) &&
1430
+ field("onCloseCommand")?.type.k === "bytes";
1431
+ if (!valid) {
1432
+ const shape = descriptor?.fields.map((candidate) => `${candidate.tsName}:${candidate.type.k}${candidate.type.k === "optional" ? `(${candidate.type.inner.k}${candidate.type.inner.k === "union" ? `:${candidate.type.inner.name}` : ""})` : candidate.type.k === "enum" ? `:${candidate.type.name}` : ""}`).join(", ") ?? `missing descriptor (return=${returns.k}${returns.k === "slice" ? ` elem=${returns.elem.k}` : ""})`;
1433
+ this.report(
1434
+ "NS1033",
1435
+ `\`windows\` must return \`readonly WindowDescriptor[]\`; import \`WindowDescriptor\` from \`@native-sdk/core/events\` and construct entries with \`windowDescriptor(...)\`. Resolved: ${shape}`,
1436
+ decl.type,
1437
+ );
1438
+ return;
1439
+ }
1440
+ this.checkWindowViewRegistry(decl);
1441
+ }
1442
+
997
1443
  /// NS1032 — `export const viewUnbound = [...] as const`: the dead-state
998
1444
  /// lint opt-out. Every entry must be a string literal naming a Model
999
1445
  /// field, an exported model helper, or a Msg kind; the emitter routes the
@@ -1425,7 +1871,7 @@ export class SubsetChecker {
1425
1871
  /// entry points, but the exports themselves live in the entry module.
1426
1872
  private static readonly entryOnlyExports = new Set([
1427
1873
  "update", "initialModel", "subscriptions", "migrate",
1428
- "commandMsg", "keyMsg", "frameMsg", "pinchMsg", "dropMsg", "appearanceMsg", "chromeMsg", "envMsgs", "themePack", "statusItem",
1874
+ "commandMsg", "keyMsg", "frameMsg", "pinchMsg", "dropMsg", "appearanceMsg", "chromeMsg", "envMsgs", "themePack", "statusItem", "statusItems", "windows",
1429
1875
  "viewUnbound", "modelUnbound", "msgUnbound",
1430
1876
  ]);
1431
1877
 
@@ -2510,6 +2956,28 @@ export class SubsetChecker {
2510
2956
  }
2511
2957
  }
2512
2958
 
2959
+ // NS1074 — best-effort literal-path lint for the runtime filesystem
2960
+ // gate. App-dir paths normally arrive as bytes from envMsgs and remain
2961
+ // dynamic here; a literal absolute path or a lexical parent escape is
2962
+ // certainly external and should name the missing permission now.
2963
+ if (
2964
+ ts.isCallExpression(node) &&
2965
+ ts.isPropertyAccessExpression(node.expression) &&
2966
+ ["readFile", "writeFile", "appendFile", "statFile", "deleteFile", "readFileStream", "writeFileStream"].includes(node.expression.name.text) &&
2967
+ ts.isIdentifier(node.expression.expression) &&
2968
+ this.cmdNames.has(node.expression.expression.text) &&
2969
+ this.isSdkReference(node.expression.expression) &&
2970
+ !this.permissions.has("filesystem")
2971
+ ) {
2972
+ const pathArg = node.expression.name.text === "writeFileStream" ? node.arguments[1] : node.arguments[0];
2973
+ if (pathArg && ts.isCallExpression(pathArg) && ["asciiBytes", "utf8Bytes"].includes(this.sdkRootFunctionName(pathArg.expression) ?? "")) {
2974
+ const literal = pathArg.arguments[0];
2975
+ if (literal && ts.isStringLiteral(literal) && (/^(?:\/|[A-Za-z]:[\\/])/.test(literal.text) || literal.text.split(/[\\/]+/).includes(".."))) {
2976
+ this.report("NS1074", `\`Cmd.${node.expression.name.text}\` uses a literal path outside the app-directory exemption without the \`filesystem\` permission.`, pathArg);
2977
+ }
2978
+ }
2979
+ }
2980
+
2513
2981
  // NS1069 — the nested record-store factories remain capability-bound;
2514
2982
  // recognizing the SDK Cmd symbol (rather than its spelling alone) keeps
2515
2983
  // local objects named Cmd out of this cross-file contract check.
@@ -35,6 +35,8 @@ function main(argv: string[]): number {
35
35
  let persistNone: string | null = null;
36
36
  let persistErr: string | null = null;
37
37
  let sdkCorePath: string | null = null;
38
+ let windowViewsEnabled = false;
39
+ const windowViews: string[] = [];
38
40
  const capabilities: string[] = [];
39
41
  const permissions: string[] = [];
40
42
  const servicePackages: ServicePackage[] = [];
@@ -109,6 +111,16 @@ function main(argv: string[]): number {
109
111
  console.error("--sdk-core requires a generated core.ts path");
110
112
  return 2;
111
113
  }
114
+ } else if (args[i] === "--window-views") {
115
+ windowViewsEnabled = true;
116
+ } else if (args[i] === "--window-view") {
117
+ windowViewsEnabled = true;
118
+ const label = args[++i] ?? null;
119
+ if (label === null || label.length === 0) {
120
+ console.error("--window-view requires a non-empty label");
121
+ return 2;
122
+ }
123
+ windowViews.push(label);
112
124
  } else if (args[i] === "-o" || args[i] === "--out") {
113
125
  console.error(
114
126
  "-o named the removed TS-to-Zig emitter (v0.7.0 removed it): TypeScript cores compile through the external core compiler now, and this CLI checks the core and emits its contract sidecar (--contract). Drop the flag.",
@@ -148,6 +160,7 @@ function main(argv: string[]): number {
148
160
  persistStatePath: persistStatePath ?? undefined,
149
161
  persistRoutes,
150
162
  sdkCorePath: sdkCorePath ?? undefined,
163
+ windowViews: windowViewsEnabled ? windowViews : undefined,
151
164
  };
152
165
  const result = checkFile(entry, options);
153
166
  for (const e of result.typeErrors) console.error(e);
@@ -462,6 +462,8 @@ class ContractEmitter {
462
462
  // check that this one helper is intentionally shell-bound without
463
463
  // making every app repeat it in `viewUnbound`.
464
464
  if (helperNames.includes("statusItem") && !model.includes("statusItem")) model.push("statusItem");
465
+ if (helperNames.includes("statusItems") && !model.includes("statusItems")) model.push("statusItems");
466
+ if (helperNames.includes("windows") && !model.includes("windows")) model.push("windows");
465
467
  return { model, msg };
466
468
  }
467
469
 
@@ -666,7 +668,7 @@ class ContractEmitter {
666
668
  return (
667
669
  "{\n" +
668
670
  ' "format": 1,\n' +
669
- ' "wire_version": 4,\n' +
671
+ ' "wire_version": 7,\n' +
670
672
  ' "abi_version": 2,\n' +
671
673
  ' "compiler_version": "0.0.1",\n' +
672
674
  ` "entry": ${js(this.entry)},\n` +
@@ -91,6 +91,8 @@ let appId = "app";
91
91
  const servicePackages: { name: string; version: string; content_hash: string }[] = [];
92
92
  const capabilities = new Set<string>();
93
93
  const permissions = new Set<string>();
94
+ let windowViewsEnabled = false;
95
+ const windowViews: string[] = [];
94
96
  for (let i = 0; i < args.length; i++) {
95
97
  if (args[i] === "--script") script = args[++i] ?? null;
96
98
  else if (args[i] === "--capability") {
@@ -103,6 +105,13 @@ for (let i = 0; i < args.length; i++) {
103
105
  if (permission === null) usage();
104
106
  permissions.add(permission);
105
107
  }
108
+ else if (args[i] === "--window-views") windowViewsEnabled = true;
109
+ else if (args[i] === "--window-view") {
110
+ windowViewsEnabled = true;
111
+ const label = args[++i] ?? null;
112
+ if (label === null || label.length === 0) usage();
113
+ windowViews.push(label);
114
+ }
106
115
  else if (args[i] === "--persist-ok") persistOk = args[++i] ?? null;
107
116
  else if (args[i] === "--persist-none") persistNone = args[++i] ?? null;
108
117
  else if (args[i] === "--persist-err") persistErr = args[++i] ?? null;
@@ -143,7 +152,7 @@ if (serviceCwd !== null) {
143
152
  const persistRouteCount = [persistOk, persistNone, persistErr].filter((route) => route !== null).length;
144
153
  if (persistRouteCount !== 0 && persistRouteCount !== 3) usage();
145
154
  let checked: ReturnType<typeof checkFile> | null = null;
146
- if (capabilities.size > 0 || permissions.size > 0 || (persistOk !== null && persistNone !== null && persistErr !== null) || fs.existsSync(path.join(path.dirname(path.resolve(entry)), "services"))) {
155
+ if (capabilities.size > 0 || permissions.size > 0 || windowViewsEnabled || (persistOk !== null && persistNone !== null && persistErr !== null) || fs.existsSync(path.join(path.dirname(path.resolve(entry)), "services"))) {
147
156
  // Type information is erased by the time this module imports the app core.
148
157
  // Run the frontend inside the watched process so every node --watch restart
149
158
  // revalidates manifest-owned routes against the newly edited Msg union.
@@ -154,6 +163,7 @@ if (capabilities.size > 0 || permissions.size > 0 || (persistOk !== null && pers
154
163
  servicesContract: true,
155
164
  servicePackages,
156
165
  sdkCorePath: sdkCore ?? undefined,
166
+ windowViews: windowViewsEnabled ? windowViews : undefined,
157
167
  });
158
168
  for (const error of checked.typeErrors) console.error(error);
159
169
  for (const diagnostic of checked.diagnostics) console.error(formatDiagnostic(diagnostic));
@@ -1792,6 +1802,25 @@ function performCmd(cmd: Cmdish): void {
1792
1802
  case "db_exec":
1793
1803
  performDbCmd(cmd);
1794
1804
  return;
1805
+ case "read_file":
1806
+ case "write_file":
1807
+ case "append_file":
1808
+ case "stat_file":
1809
+ case "delete_file":
1810
+ case "read_file_stream":
1811
+ case "write_file_stream":
1812
+ case "write_file_chunk":
1813
+ case "write_file_close": {
1814
+ // The logic-only host deliberately performs no ambient filesystem IO;
1815
+ // it still names the runtime policy so dev transcripts cannot imply
1816
+ // these commands bypass the manifest gate.
1817
+ const details = Object.entries(cmd)
1818
+ .filter(([k]) => k !== "op")
1819
+ .map(([k, v]) => `${k}=${JSON.stringify(jsonable(v))}`)
1820
+ .join(" ");
1821
+ say(`cmd ${cmd.op} ${details}`.trimEnd() + " (not performed by the virtual host; runtime requires filesystem permission outside app dirs)");
1822
+ return;
1823
+ }
1795
1824
  case "show_notification": {
1796
1825
  const details = Object.entries(cmd)
1797
1826
  .filter(([k]) => k !== "op")