@native-sdk/cli 0.9.3 → 0.9.5

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 (84) hide show
  1. package/README.md +3 -3
  2. package/build/app.zig +323 -76
  3. package/build/ts_run.mjs +15 -18
  4. package/build.zig +83 -8
  5. package/package.json +14 -10
  6. package/packages/core/compile-surface/core.ts +1 -0
  7. package/packages/core/package-lock.json +16 -13
  8. package/packages/core/package.json +5 -2
  9. package/packages/core/scripts/compiler_command.mjs +71 -0
  10. package/packages/core/scripts/compiler_typecheck.mjs +4 -4
  11. package/packages/core/scripts/embed_markup_c.mjs +25 -0
  12. package/packages/core/scripts/npm_static_spike.mjs +3 -3
  13. package/packages/core/scripts/run_external_core_compiler.mjs +21 -10
  14. package/packages/core/scripts/run_external_service_compiler.mjs +17 -7
  15. package/packages/core/scripts/vendor_service_packages.mjs +121 -8
  16. package/packages/core/sdk/core.ts +1 -0
  17. package/packages/core/sdk/events.d.ts +36 -4
  18. package/packages/core/sdk/events.ts +49 -6
  19. package/packages/core/src/checker.ts +106 -10
  20. package/packages/core/src/modules.ts +6 -2
  21. package/packages/core/src/sqlite_cli.ts +22 -2
  22. package/packages/core/src/typed_ast.ts +4 -2
  23. package/packages/core/src/types.ts +8 -8
  24. package/schemas/app.schema.json +435 -0
  25. package/skill-data/core/SKILL.md +53 -15
  26. package/skill-data/core/references/project-anatomy.md +6 -6
  27. package/skill-data/native-ui/SKILL.md +28 -6
  28. package/skill-data/ts-core/SKILL.md +9 -6
  29. package/skill-data/ts-services/references/service-surface.md +1 -1
  30. package/skills/native-sdk/SKILL.md +2 -2
  31. package/src/app_runner/ts_core_main.zig +12 -4
  32. package/src/app_runner/ts_core_mobile.zig +6 -2
  33. package/src/automation/snapshot.zig +91 -3
  34. package/src/platform/macos/appkit_host.h +41 -2
  35. package/src/platform/macos/appkit_host.m +198 -9
  36. package/src/platform/macos/cef_host.mm +191 -9
  37. package/src/platform/macos/root.zig +110 -3
  38. package/src/platform/null_platform.zig +50 -1
  39. package/src/platform/null_platform_tests.zig +53 -0
  40. package/src/platform/root.zig +9 -0
  41. package/src/platform/types.zig +58 -0
  42. package/src/platform/windows/root.zig +88 -15
  43. package/src/primitives/canvas/reference.zig +37 -15
  44. package/src/primitives/canvas/reference_tests.zig +63 -0
  45. package/src/primitives/canvas/ui.zig +9 -0
  46. package/src/primitives/canvas/ui_markup.zig +29 -0
  47. package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
  48. package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
  49. package/src/primitives/canvas/ui_markup_contract.zig +7 -0
  50. package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
  51. package/src/primitives/canvas/ui_markup_tests.zig +6 -0
  52. package/src/primitives/canvas/ui_markup_view.zig +28 -0
  53. package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
  54. package/src/primitives/canvas/ui_schema.zig +9 -0
  55. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  56. package/src/primitives/canvas/ui_tests.zig +4 -2
  57. package/src/primitives/canvas/widget_render.zig +7 -2
  58. package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
  59. package/src/root.zig +4 -0
  60. package/src/runtime/automation_snapshot.zig +3 -0
  61. package/src/runtime/flow.zig +1 -1
  62. package/src/runtime/state.zig +14 -0
  63. package/src/runtime/system_services.zig +62 -0
  64. package/src/runtime/ts_ui_app.zig +181 -39
  65. package/src/runtime/ui_app.zig +40 -1
  66. package/src/runtime/ui_app_tests.zig +63 -0
  67. package/src/runtime/ui_app_window_tests.zig +23 -0
  68. package/src/runtime/validation.zig +87 -1
  69. package/src/tooling/android.zig +5 -4
  70. package/src/tooling/buildgraph.zig +24 -8
  71. package/src/tooling/db.zig +1 -1
  72. package/src/tooling/doctor.zig +1 -1
  73. package/src/tooling/ios.zig +5 -4
  74. package/src/tooling/json_to_zon.zig +136 -0
  75. package/src/tooling/manifest.zig +120 -33
  76. package/src/tooling/raw_manifest.zig +4 -0
  77. package/src/tooling/root.zig +1 -0
  78. package/src/tooling/templates.zig +171 -118
  79. package/src/tooling/ts_core.zig +12 -8
  80. package/src/tooling/verbs.zig +233 -5
  81. package/src/tooling/web_engine.zig +17 -1
  82. package/tools/corewire/emit_profile.zig +20 -7
  83. package/tools/corewire/emit_service.zig +49 -24
  84. package/tools/corewire/main.zig +21 -2
@@ -17,6 +17,7 @@ import { spawnSync } from "node:child_process";
17
17
  import fs from "node:fs";
18
18
  import os from "node:os";
19
19
  import path from "node:path";
20
+ import { compilerArgv, publishedScriptcArgv } from "./compiler_command.mjs";
20
21
 
21
22
  function parseArgs(argv) {
22
23
  const args = {};
@@ -24,7 +25,7 @@ function parseArgs(argv) {
24
25
  const key = argv[i];
25
26
  const value = argv[i + 1];
26
27
  if (!key?.startsWith("--") || value === undefined) {
27
- console.error("usage: run_external_service_compiler.mjs --stage <dir> --manifest <package.json> --contract <services.contract.json> (--out-exe <file> | --out-archive <file>) --host-platform <arch-os-abi> --target-platform <arch-os-abi> [--zig-exe <path>] [--android-ndk <dir>] (--compiler <cmd> | --compiler-js <main.js>)");
28
+ console.error("usage: run_external_service_compiler.mjs --stage <dir> --manifest <package.json> --contract <services.contract.json> (--out-exe <file> | --out-archive <file>) --host-platform <arch-os-abi> --target-platform <arch-os-abi> [--zig-exe <path>] [--android-ndk <dir>] (--compiler <cmd> | --compiler-js <main.js> | --compiler-package-origin <package.json>)");
28
29
  process.exit(2);
29
30
  }
30
31
  args[key.slice(2)] = value;
@@ -39,8 +40,9 @@ function parseArgs(argv) {
39
40
  console.error("run_external_service_compiler.mjs: supply --out-exe, --out-archive, or both");
40
41
  process.exit(2);
41
42
  }
42
- if (!args.compiler && !args["compiler-js"]) {
43
- console.error("run_external_service_compiler.mjs: supply --compiler or --compiler-js");
43
+ const compilerModes = [args.compiler, args["compiler-js"], args["compiler-package-origin"]].filter(Boolean);
44
+ if (compilerModes.length !== 1) {
45
+ console.error("run_external_service_compiler.mjs: supply exactly one of --compiler, --compiler-js, or --compiler-package-origin");
44
46
  process.exit(2);
45
47
  }
46
48
  return args;
@@ -139,12 +141,20 @@ if (args["out-archive"]) {
139
141
  process.exit(2);
140
142
  }
141
143
  }
142
- for (const key of ["stage", "manifest", "contract", "out-exe", "out-archive", "compiler-js", "zig-exe", "android-ndk"]) {
144
+ for (const key of ["stage", "manifest", "contract", "out-exe", "out-archive", "compiler-js", "compiler-package-origin", "zig-exe", "android-ndk"]) {
143
145
  if (args[key]) args[key] = path.resolve(args[key]);
144
146
  }
145
- const argv0 = args.compiler
146
- ? (fs.existsSync(args.compiler) ? [args.compiler] : args.compiler.split(/\s+/))
147
- : [process.execPath, args["compiler-js"]];
147
+ let argv0;
148
+ try {
149
+ argv0 = args.compiler
150
+ ? compilerArgv(args.compiler)
151
+ : args["compiler-js"]
152
+ ? [process.execPath, args["compiler-js"]]
153
+ : publishedScriptcArgv(args["compiler-package-origin"]);
154
+ } catch (error) {
155
+ console.error(`the external TypeScript compiler is not installed or has no valid published bin: ${error instanceof Error ? error.message : String(error)} — reinstall @native-sdk/cli, or point NATIVE_SDK_CORE_COMPILER at the pinned release's command`);
156
+ process.exit(2);
157
+ }
148
158
 
149
159
  // Cross compiles hand the compiler its zig-cc lane: the target triple as
150
160
  // SCRIPTC_TARGET (the compiler's own mobile spellings for iOS/Android), and
@@ -80,7 +80,106 @@ function servicePackagesField(source) {
80
80
  throw new Error("app.zon service_packages field is not balanced");
81
81
  }
82
82
 
83
- export function readServicePackages(source) {
83
+ function parseJsonManifest(source) {
84
+ const manifest = JSON.parse(source);
85
+ if (manifest === null || Array.isArray(manifest) || typeof manifest !== "object") throw new Error("app.json must contain one object");
86
+ return manifest;
87
+ }
88
+
89
+ function skipJsonWhitespace(source, start) {
90
+ let at = start;
91
+ while (/\s/.test(source[at] ?? "")) at++;
92
+ return at;
93
+ }
94
+
95
+ function scanJsonString(source, start) {
96
+ let escaped = false;
97
+ for (let at = start + 1; at < source.length; at++) {
98
+ const char = source[at];
99
+ if (escaped) escaped = false;
100
+ else if (char === "\\") escaped = true;
101
+ else if (char === '"') return at + 1;
102
+ }
103
+ throw new Error("app.json contains an unterminated string");
104
+ }
105
+
106
+ function scanJsonValue(source, start) {
107
+ const first = source[start];
108
+ if (first === '"') return scanJsonString(source, start);
109
+ if (first === "{" || first === "[") {
110
+ const close = first === "{" ? "}" : "]";
111
+ let depth = 1;
112
+ let string = false;
113
+ let escaped = false;
114
+ for (let at = start + 1; at < source.length; at++) {
115
+ const char = source[at];
116
+ if (string) {
117
+ if (escaped) escaped = false;
118
+ else if (char === "\\") escaped = true;
119
+ else if (char === '"') string = false;
120
+ continue;
121
+ }
122
+ if (char === '"') string = true;
123
+ else if (char === first) depth++;
124
+ else if (char === close && --depth === 0) return at + 1;
125
+ }
126
+ throw new Error("app.json contains an unterminated value");
127
+ }
128
+ let at = start;
129
+ while (at < source.length && !/[\s,}\]]/.test(source[at])) at++;
130
+ return at;
131
+ }
132
+
133
+ function jsonObjectField(source, fieldName) {
134
+ let at = skipJsonWhitespace(source, 0);
135
+ if (source[at] !== "{") throw new Error("app.json must contain one object");
136
+ at = skipJsonWhitespace(source, at + 1);
137
+ let memberCount = 0;
138
+ let match = null;
139
+ while (source[at] !== "}") {
140
+ if (source[at] !== '"') throw new Error("app.json contains an invalid object key");
141
+ const keyStart = at;
142
+ const keyEnd = scanJsonString(source, keyStart);
143
+ const key = JSON.parse(source.slice(keyStart, keyEnd));
144
+ at = skipJsonWhitespace(source, keyEnd);
145
+ if (source[at] !== ":") throw new Error("app.json contains an invalid object field");
146
+ const valueStart = skipJsonWhitespace(source, at + 1);
147
+ const valueEnd = scanJsonValue(source, valueStart);
148
+ memberCount++;
149
+ if (key === fieldName) {
150
+ if (match !== null) throw new Error(`app.json contains duplicate ${fieldName} fields`);
151
+ match = { valueStart, valueEnd };
152
+ }
153
+ at = skipJsonWhitespace(source, valueEnd);
154
+ if (source[at] === ",") at = skipJsonWhitespace(source, at + 1);
155
+ else if (source[at] !== "}") throw new Error("app.json contains an invalid object separator");
156
+ }
157
+ return { match, close: at, memberCount };
158
+ }
159
+
160
+ function jsonTopLevelIndent(source, close) {
161
+ const firstKey = source.indexOf('"', source.indexOf("{") + 1);
162
+ const key = firstKey >= 0 && firstKey < close ? firstKey : close;
163
+ const lineStart = source.lastIndexOf("\n", key - 1) + 1;
164
+ const indent = source.slice(lineStart, key);
165
+ return /^[ \t]+$/.test(indent) ? indent : " ";
166
+ }
167
+
168
+ function renderJsonValue(value, indent) {
169
+ return JSON.stringify(value, null, 2).replaceAll("\n", `\n${indent}`);
170
+ }
171
+
172
+ export function readServicePackages(source, format = "zon") {
173
+ if (format === "json") {
174
+ const entries = parseJsonManifest(source).service_packages ?? [];
175
+ if (!Array.isArray(entries)) throw new Error("app.json service_packages must be an array");
176
+ return entries.map((entry) => {
177
+ if (entry === null || typeof entry !== "object" || typeof entry.name !== "string" || typeof entry.version !== "string" || typeof entry.content_hash !== "string") {
178
+ throw new Error("app.json service_packages contains an invalid package fact");
179
+ }
180
+ return { name: entry.name, version: entry.version, content_hash: entry.content_hash };
181
+ });
182
+ }
84
183
  const field = servicePackagesField(source);
85
184
  if (!field) return [];
86
185
  const body = source.slice(field.open + 1, field.close);
@@ -104,13 +203,24 @@ function packageNameFromSpec(spec) {
104
203
  return spec.slice(0, spec.lastIndexOf("@"));
105
204
  }
106
205
 
107
- export function mergePackageSpecs(source, requested) {
108
- const specs = new Map(readServicePackages(source).map((entry) => [entry.name, `${entry.name}@${entry.version}`]));
206
+ export function mergePackageSpecs(source, requested, format = "zon") {
207
+ const specs = new Map(readServicePackages(source, format).map((entry) => [entry.name, `${entry.name}@${entry.version}`]));
109
208
  for (const spec of requested) specs.set(packageNameFromSpec(spec), spec);
110
209
  return [...specs].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, spec]) => spec);
111
210
  }
112
211
 
113
- export function replaceServicePackages(source, entries) {
212
+ export function replaceServicePackages(source, entries, format = "zon") {
213
+ if (format === "json") {
214
+ parseJsonManifest(source);
215
+ const field = jsonObjectField(source, "service_packages");
216
+ const indent = jsonTopLevelIndent(source, field.close);
217
+ const rendered = renderJsonValue(entries, indent);
218
+ if (field.match) {
219
+ return source.slice(0, field.match.valueStart) + rendered + source.slice(field.match.valueEnd);
220
+ }
221
+ const comma = field.memberCount === 0 ? "" : ",";
222
+ return `${source.slice(0, field.close).trimEnd()}${comma}\n${indent}"service_packages": ${rendered}\n${source.slice(field.close)}`;
223
+ }
114
224
  const rendered = [
115
225
  " .service_packages = .{",
116
226
  ...entries.map((entry) => ` .{ .name = ${JSON.stringify(entry.name)}, .version = ${JSON.stringify(entry.version)}, .content_hash = ${JSON.stringify(entry.content_hash)} },`),
@@ -139,10 +249,13 @@ function main(argv) {
139
249
  return 2;
140
250
  }
141
251
 
142
- const manifestPath = path.join(appRoot, "app.zon");
252
+ const jsonPath = path.join(appRoot, "app.json");
253
+ const zonPath = path.join(appRoot, "app.zon");
254
+ const manifestPath = fs.existsSync(jsonPath) ? jsonPath : zonPath;
143
255
  if (!fs.existsSync(manifestPath)) throw new Error(`${manifestPath} does not exist`);
256
+ const format = manifestPath.endsWith(".json") ? "json" : "zon";
144
257
  const current = fs.readFileSync(manifestPath, "utf8");
145
- const installSpecs = mergePackageSpecs(current, requested);
258
+ const installSpecs = mergePackageSpecs(current, requested, format);
146
259
  const work = fs.mkdtempSync(path.join(os.tmpdir(), "native-service-vendor-"));
147
260
  const servicesRoot = path.join(appRoot, "src", "services");
148
261
  const stageRoot = path.join(appRoot, ".native", `.service-vendor-stage-${process.pid}-${Date.now()}`);
@@ -169,8 +282,8 @@ function main(argv) {
169
282
  entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
170
283
  const vendorRoot = path.join(servicesRoot, "vendor");
171
284
  replaceVendorTree(vendorRoot, stageRoot);
172
- fs.writeFileSync(manifestPath, replaceServicePackages(current, entries));
173
- console.log(`vendored ${entries.length} package${entries.length === 1 ? "" : "s"} into src/services/vendor and updated app.zon`);
285
+ fs.writeFileSync(manifestPath, replaceServicePackages(current, entries, format));
286
+ console.log(`vendored ${entries.length} package${entries.length === 1 ? "" : "s"} into src/services/vendor and updated ${path.basename(manifestPath)}`);
174
287
  for (const entry of entries) console.log(` ${entry.name}@${entry.version} ${entry.content_hash}`);
175
288
  return 0;
176
289
  } finally {
@@ -388,6 +388,7 @@ export function windowDescriptor(spec: WindowDescriptorSpec): WindowDescriptor {
388
388
  x: spec.x ?? null,
389
389
  y: spec.y ?? null,
390
390
  resizable: spec.resizable ?? true,
391
+ restorePolicy: spec.restorePolicy ?? "clamp_to_visible_screen",
391
392
  minWidth: spec.minWidth ?? 0,
392
393
  minHeight: spec.minHeight ?? 0,
393
394
  titlebar: spec.titlebar ?? "standard",
@@ -7,7 +7,8 @@ export type ThemeState = {
7
7
  readonly accent?: string;
8
8
  };
9
9
  export type StatusItemTone = "normal" | "warning" | "critical";
10
- export type StatusItemMenuRole = "command" | "info" | "header" | "hero" | "agent" | "context";
10
+ export type StatusItemFontWeight = "regular" | "medium" | "semibold" | "bold";
11
+ export type StatusItemMenuRole = "command" | "info" | "header" | "hero" | "agent" | "context" | "segmented" | "chart";
11
12
  export interface StatusItemModifiers {
12
13
  readonly primary: boolean;
13
14
  readonly command: boolean;
@@ -15,14 +16,39 @@ export interface StatusItemModifiers {
15
16
  readonly option: boolean;
16
17
  readonly shift: boolean;
17
18
  }
18
- export interface StatusItemPresentation {
19
+ export type StatusItemPresentation = {
19
20
  readonly title: Uint8Array;
20
21
  readonly width: number;
21
22
  readonly tone: StatusItemTone;
22
23
  readonly iconOpacity: number;
23
24
  readonly monospaced: boolean;
25
+ readonly fontSize?: number;
26
+ readonly fontWeight?: StatusItemFontWeight;
27
+ };
28
+ export interface StatusItemSegmentOption {
29
+ readonly id: number;
30
+ readonly label: Uint8Array;
31
+ readonly command: Uint8Array;
32
+ readonly selected: boolean;
33
+ readonly enabled: boolean;
24
34
  }
25
- export interface StatusItemMenuItem {
35
+ export interface StatusItemSegmentedRow {
36
+ readonly options: readonly StatusItemSegmentOption[];
37
+ }
38
+ export interface StatusItemMetricRow {
39
+ readonly primaryText: Uint8Array;
40
+ readonly secondaryText: Uint8Array;
41
+ readonly accessibilityLabel: Uint8Array;
42
+ }
43
+ export interface StatusItemChartRow {
44
+ readonly values: readonly number[];
45
+ readonly minValue: number;
46
+ readonly maxValue: number;
47
+ readonly leadingCaption: Uint8Array;
48
+ readonly trailingSummary: Uint8Array;
49
+ readonly accessibilityLabel: Uint8Array;
50
+ }
51
+ export type StatusItemMenuItem = {
26
52
  readonly id: number;
27
53
  readonly label: Uint8Array;
28
54
  readonly command: Uint8Array;
@@ -32,7 +58,10 @@ export interface StatusItemMenuItem {
32
58
  readonly role: StatusItemMenuRole;
33
59
  readonly key: Uint8Array;
34
60
  readonly modifiers: StatusItemModifiers;
35
- }
61
+ readonly segmented?: StatusItemSegmentedRow;
62
+ readonly metric?: StatusItemMetricRow;
63
+ readonly chart?: StatusItemChartRow;
64
+ };
36
65
  export interface StatusItemState {
37
66
  readonly iconPath: Uint8Array;
38
67
  readonly tooltip: Uint8Array;
@@ -55,6 +84,7 @@ export interface StatusItemDescriptor {
55
84
  }
56
85
  export type WindowClosePolicy = "quit" | "hide";
57
86
  export type WindowTitlebarStyle = "standard" | "hidden_inset" | "hidden_inset_tall" | "chromeless";
87
+ export type WindowRestorePolicy = "clamp_to_visible_screen" | "center_on_primary";
58
88
  export interface WindowDescriptorSpec {
59
89
  readonly label: Uint8Array;
60
90
  readonly canvasLabel: Uint8Array;
@@ -64,6 +94,7 @@ export interface WindowDescriptorSpec {
64
94
  readonly x?: number | null;
65
95
  readonly y?: number | null;
66
96
  readonly resizable?: boolean;
97
+ readonly restorePolicy?: WindowRestorePolicy;
67
98
  readonly minWidth?: number;
68
99
  readonly minHeight?: number;
69
100
  readonly titlebar?: WindowTitlebarStyle;
@@ -84,6 +115,7 @@ export interface WindowDescriptor {
84
115
  readonly x: number | null;
85
116
  readonly y: number | null;
86
117
  readonly resizable: boolean;
118
+ readonly restorePolicy: WindowRestorePolicy;
87
119
  readonly minWidth: number;
88
120
  readonly minHeight: number;
89
121
  readonly titlebar: WindowTitlebarStyle;
@@ -63,12 +63,14 @@ export type ThemeState = {
63
63
  /// One row in a menu-bar status item's menu. Non-separator rows need a
64
64
  /// unique non-zero `id`, a non-empty `label`, and (when actionable) a
65
65
  /// command name accepted by `commandMsg`. Rich readout roles may carry
66
- /// secondary `detail`; command rows may carry a key equivalent. Spell
67
- /// every field explicitly because app-core records have one exact shape.
66
+ /// secondary `detail`; command rows may carry a key equivalent. Core row
67
+ /// records have one exact shape; only the documented rich payloads and
68
+ /// presentation typography may be omitted.
68
69
  /// A status item may expose at most 32 rows.
69
70
  export type StatusItemTone = "normal" | "warning" | "critical";
71
+ export type StatusItemFontWeight = "regular" | "medium" | "semibold" | "bold";
70
72
 
71
- export type StatusItemMenuRole = "command" | "info" | "header" | "hero" | "agent" | "context";
73
+ export type StatusItemMenuRole = "command" | "info" | "header" | "hero" | "agent" | "context" | "segmented" | "chart";
72
74
 
73
75
  export interface StatusItemModifiers {
74
76
  readonly primary: boolean;
@@ -78,15 +80,46 @@ export interface StatusItemModifiers {
78
80
  readonly shift: boolean;
79
81
  }
80
82
 
81
- export interface StatusItemPresentation {
83
+ export type StatusItemPresentation = {
82
84
  readonly title: Uint8Array;
83
85
  readonly width: number;
84
86
  readonly tone: StatusItemTone;
85
87
  readonly iconOpacity: number;
86
88
  readonly monospaced: boolean;
89
+ /// Omit to keep the platform menu-bar default size.
90
+ readonly fontSize?: number;
91
+ /// Omit to keep regular weight.
92
+ readonly fontWeight?: StatusItemFontWeight;
93
+ };
94
+
95
+ export interface StatusItemSegmentOption {
96
+ readonly id: number;
97
+ readonly label: Uint8Array;
98
+ readonly command: Uint8Array;
99
+ readonly selected: boolean;
100
+ readonly enabled: boolean;
101
+ }
102
+
103
+ export interface StatusItemSegmentedRow {
104
+ readonly options: readonly StatusItemSegmentOption[];
87
105
  }
88
106
 
89
- export interface StatusItemMenuItem {
107
+ export interface StatusItemMetricRow {
108
+ readonly primaryText: Uint8Array;
109
+ readonly secondaryText: Uint8Array;
110
+ readonly accessibilityLabel: Uint8Array;
111
+ }
112
+
113
+ export interface StatusItemChartRow {
114
+ readonly values: readonly number[];
115
+ readonly minValue: number;
116
+ readonly maxValue: number;
117
+ readonly leadingCaption: Uint8Array;
118
+ readonly trailingSummary: Uint8Array;
119
+ readonly accessibilityLabel: Uint8Array;
120
+ }
121
+
122
+ export type StatusItemMenuItem = {
90
123
  readonly id: number;
91
124
  readonly label: Uint8Array;
92
125
  readonly command: Uint8Array;
@@ -96,7 +129,13 @@ export interface StatusItemMenuItem {
96
129
  readonly role: StatusItemMenuRole;
97
130
  readonly key: Uint8Array;
98
131
  readonly modifiers: StatusItemModifiers;
99
- }
132
+ /// Present exactly when `role` is `segmented`.
133
+ readonly segmented?: StatusItemSegmentedRow;
134
+ /// Present on a `hero` row to declare a typed dropdown metric block.
135
+ readonly metric?: StatusItemMetricRow;
136
+ /// Present exactly when `role` is `chart`.
137
+ readonly chart?: StatusItemChartRow;
138
+ };
100
139
 
101
140
  /// The generated launcher's model-derived menu-bar status item. Export
102
141
  /// `statusItem(model: Model): StatusItemState` from `src/core.ts`; its
@@ -135,6 +174,8 @@ export type WindowClosePolicy = "quit" | "hide";
135
174
 
136
175
  export type WindowTitlebarStyle = "standard" | "hidden_inset" | "hidden_inset_tall" | "chromeless";
137
176
 
177
+ export type WindowRestorePolicy = "clamp_to_visible_screen" | "center_on_primary";
178
+
138
179
  /// Author-facing input to `windowDescriptor`; omitted fields receive the
139
180
  /// same defaults as UiApp.WindowDescriptor.
140
181
  export interface WindowDescriptorSpec {
@@ -146,6 +187,7 @@ export interface WindowDescriptorSpec {
146
187
  readonly x?: number | null;
147
188
  readonly y?: number | null;
148
189
  readonly resizable?: boolean;
190
+ readonly restorePolicy?: WindowRestorePolicy;
149
191
  readonly minWidth?: number;
150
192
  readonly minHeight?: number;
151
193
  readonly titlebar?: WindowTitlebarStyle;
@@ -172,6 +214,7 @@ export interface WindowDescriptor {
172
214
  readonly x: number | null;
173
215
  readonly y: number | null;
174
216
  readonly resizable: boolean;
217
+ readonly restorePolicy: WindowRestorePolicy;
175
218
  readonly minWidth: number;
176
219
  readonly minHeight: number;
177
220
  readonly titlebar: WindowTitlebarStyle;
@@ -992,6 +992,8 @@ export class SubsetChecker {
992
992
  const tone = presentation?.fields.find((field) => field.tsName === "tone");
993
993
  const iconOpacity = presentation?.fields.find((field) => field.tsName === "iconOpacity");
994
994
  const monospaced = presentation?.fields.find((field) => field.tsName === "monospaced");
995
+ const fontSize = presentation?.fields.find((field) => field.tsName === "fontSize");
996
+ const fontWeight = presentation?.fields.find((field) => field.tsName === "fontWeight");
995
997
  const itemType = items?.type.k === "slice" && items.type.elem.k === "struct" ? items.type.elem : null;
996
998
  const item = itemType === null ? undefined : this.table.structs.get(itemType.name);
997
999
  const itemNames = item?.fields.map((field) => field.tsName).sort() ?? [];
@@ -1004,9 +1006,27 @@ export class SubsetChecker {
1004
1006
  const role = item?.fields.find((field) => field.tsName === "role");
1005
1007
  const key = item?.fields.find((field) => field.tsName === "key");
1006
1008
  const modifiersField = item?.fields.find((field) => field.tsName === "modifiers");
1009
+ const segmentedField = item?.fields.find((field) => field.tsName === "segmented");
1010
+ const metricField = item?.fields.find((field) => field.tsName === "metric");
1011
+ const chartField = item?.fields.find((field) => field.tsName === "chart");
1007
1012
  const modifiersType = modifiersField?.type.k === "struct" ? modifiersField.type : null;
1008
1013
  const modifiers = modifiersType === null ? undefined : this.table.structs.get(modifiersType.name);
1009
1014
  const modifierNames = modifiers?.fields.map((field) => field.tsName).sort() ?? [];
1015
+ const optionalStruct = (field: typeof segmentedField) =>
1016
+ field?.type.k === "optional" && field.type.inner.k === "struct" ? this.table.structs.get(field.type.inner.name) : undefined;
1017
+ const segmented = optionalStruct(segmentedField);
1018
+ const segmentedNames = segmented?.fields.map((field) => field.tsName).sort() ?? [];
1019
+ const segmentOptions = segmented?.fields.find((field) => field.tsName === "options");
1020
+ const segmentOptionType = segmentOptions?.type.k === "slice" && segmentOptions.type.elem.k === "struct" ? segmentOptions.type.elem : null;
1021
+ const segmentOption = segmentOptionType === null ? undefined : this.table.structs.get(segmentOptionType.name);
1022
+ const segmentOptionNames = segmentOption?.fields.map((field) => field.tsName).sort() ?? [];
1023
+ const segmentOptionField = (name: string) => segmentOption?.fields.find((field) => field.tsName === name);
1024
+ const chart = optionalStruct(chartField);
1025
+ const chartNames = chart?.fields.map((field) => field.tsName).sort() ?? [];
1026
+ const chartFieldNamed = (name: string) => chart?.fields.find((field) => field.tsName === name);
1027
+ const metric = optionalStruct(metricField);
1028
+ const metricNames = metric?.fields.map((field) => field.tsName).sort() ?? [];
1029
+ const metricFieldNamed = (name: string) => metric?.fields.find((field) => field.tsName === name);
1010
1030
  const allByteFields = [iconPath, tooltip, activationCommand, alternateActivationCommand, openCommand].every(
1011
1031
  (field) => field?.type.k === "bytes",
1012
1032
  );
@@ -1019,27 +1039,54 @@ export class SubsetChecker {
1019
1039
  const numericId = id !== undefined && ["number", "i64", "f64", "numAlias"].includes(id.type.k);
1020
1040
  const numericWidth = width !== undefined && ["number", "i64", "f64", "numAlias"].includes(width.type.k);
1021
1041
  const numericOpacity = iconOpacity !== undefined && ["number", "i64", "f64", "numAlias"].includes(iconOpacity.type.k);
1042
+ const optionalNumeric = (field: typeof fontSize): boolean =>
1043
+ field?.type.k === "optional" && ["number", "i64", "f64", "numAlias"].includes(field.type.inner.k);
1044
+ const optionalEnumMembersAre = (field: typeof fontWeight, expected: readonly string[]): boolean => {
1045
+ if (field?.type.k !== "optional" || field.type.inner.k !== "enum") return false;
1046
+ const found = this.table.enums.get(field.type.inner.name)?.members.slice().sort() ?? [];
1047
+ return found.join(",") === expected.slice().sort().join(",");
1048
+ };
1022
1049
  const valid =
1023
1050
  stateNames.join(",") === "activationCommand,alternateActivationCommand,iconPath,items,openCommand,presentation,tooltip" &&
1024
1051
  allByteFields &&
1025
- presentationNames.join(",") === "iconOpacity,monospaced,title,tone,width" &&
1052
+ presentationNames.join(",") === "fontSize,fontWeight,iconOpacity,monospaced,title,tone,width" &&
1026
1053
  title?.type.k === "bytes" &&
1027
1054
  numericWidth &&
1028
1055
  enumMembersAre(tone, ["normal", "warning", "critical"]) &&
1029
1056
  numericOpacity &&
1030
1057
  monospaced?.type.k === "bool" &&
1058
+ optionalNumeric(fontSize) &&
1059
+ optionalEnumMembersAre(fontWeight, ["regular", "medium", "semibold", "bold"]) &&
1031
1060
  item !== undefined &&
1032
- itemNames.join(",") === "command,detail,enabled,id,key,label,modifiers,role,separator" &&
1061
+ itemNames.join(",") === "chart,command,detail,enabled,id,key,label,metric,modifiers,role,segmented,separator" &&
1033
1062
  numericId &&
1034
1063
  label?.type.k === "bytes" &&
1035
1064
  command?.type.k === "bytes" &&
1036
1065
  separator?.type.k === "bool" &&
1037
1066
  enabled?.type.k === "bool" &&
1038
1067
  detail?.type.k === "bytes" &&
1039
- enumMembersAre(role, ["command", "info", "header", "hero", "agent", "context"]) &&
1068
+ enumMembersAre(role, ["command", "info", "header", "hero", "agent", "context", "segmented", "chart"]) &&
1040
1069
  key?.type.k === "bytes" &&
1041
1070
  modifierNames.join(",") === "command,control,option,primary,shift" &&
1042
- boolModifierFields;
1071
+ boolModifierFields &&
1072
+ segmentedNames.join(",") === "options" &&
1073
+ segmentOptionNames.join(",") === "command,enabled,id,label,selected" &&
1074
+ segmentOptionField("id") !== undefined && ["number", "i64", "f64", "numAlias"].includes(segmentOptionField("id")!.type.k) &&
1075
+ segmentOptionField("label")?.type.k === "bytes" &&
1076
+ segmentOptionField("command")?.type.k === "bytes" &&
1077
+ segmentOptionField("selected")?.type.k === "bool" &&
1078
+ segmentOptionField("enabled")?.type.k === "bool" &&
1079
+ metricNames.join(",") === "accessibilityLabel,primaryText,secondaryText" &&
1080
+ metricFieldNamed("primaryText")?.type.k === "bytes" &&
1081
+ metricFieldNamed("secondaryText")?.type.k === "bytes" &&
1082
+ metricFieldNamed("accessibilityLabel")?.type.k === "bytes" &&
1083
+ chartNames.join(",") === "accessibilityLabel,leadingCaption,maxValue,minValue,trailingSummary,values" &&
1084
+ chartFieldNamed("values")?.type.k === "slice" && chartFieldNamed("values")?.type.elem.k === "number" &&
1085
+ chartFieldNamed("minValue") !== undefined && ["number", "i64", "f64", "numAlias"].includes(chartFieldNamed("minValue")!.type.k) &&
1086
+ chartFieldNamed("maxValue") !== undefined && ["number", "i64", "f64", "numAlias"].includes(chartFieldNamed("maxValue")!.type.k) &&
1087
+ chartFieldNamed("leadingCaption")?.type.k === "bytes" &&
1088
+ chartFieldNamed("trailingSummary")?.type.k === "bytes" &&
1089
+ chartFieldNamed("accessibilityLabel")?.type.k === "bytes";
1043
1090
  if (!valid) {
1044
1091
  this.report(
1045
1092
  "NS1033",
@@ -1352,6 +1399,8 @@ export class SubsetChecker {
1352
1399
  const tone = presentationFieldNamed("tone");
1353
1400
  const iconOpacity = presentationFieldNamed("iconOpacity");
1354
1401
  const monospaced = presentationFieldNamed("monospaced");
1402
+ const fontSize = presentationFieldNamed("fontSize");
1403
+ const fontWeight = presentationFieldNamed("fontWeight");
1355
1404
  const items = field("items");
1356
1405
  const itemType = items?.type.k === "slice" && items.type.elem.k === "struct" ? items.type.elem : null;
1357
1406
  const item = itemType === null ? undefined : this.table.structs.get(itemType.name);
@@ -1366,41 +1415,87 @@ export class SubsetChecker {
1366
1415
  const role = itemField("role");
1367
1416
  const key = itemField("key");
1368
1417
  const modifiersField = itemField("modifiers");
1418
+ const segmentedField = itemField("segmented");
1419
+ const metricField = itemField("metric");
1420
+ const chartField = itemField("chart");
1369
1421
  const modifiersType = modifiersField?.type.k === "struct" ? modifiersField.type : null;
1370
1422
  const modifiers = modifiersType === null ? undefined : this.table.structs.get(modifiersType.name);
1371
1423
  const modifierNames = modifiers?.fields.map((candidate) => candidate.tsName).sort() ?? [];
1424
+ const optionalStruct = (candidate: typeof segmentedField) =>
1425
+ candidate?.type.k === "optional" && candidate.type.inner.k === "struct" ? this.table.structs.get(candidate.type.inner.name) : undefined;
1426
+ const segmented = optionalStruct(segmentedField);
1427
+ const segmentedNames = segmented?.fields.map((candidate) => candidate.tsName).sort() ?? [];
1428
+ const segmentOptions = segmented?.fields.find((candidate) => candidate.tsName === "options");
1429
+ const segmentOptionType = segmentOptions?.type.k === "slice" && segmentOptions.type.elem.k === "struct" ? segmentOptions.type.elem : null;
1430
+ const segmentOption = segmentOptionType === null ? undefined : this.table.structs.get(segmentOptionType.name);
1431
+ const segmentOptionNames = segmentOption?.fields.map((candidate) => candidate.tsName).sort() ?? [];
1432
+ const segmentOptionField = (name: string) => segmentOption?.fields.find((candidate) => candidate.tsName === name);
1433
+ const chart = optionalStruct(chartField);
1434
+ const chartNames = chart?.fields.map((candidate) => candidate.tsName).sort() ?? [];
1435
+ const chartFieldNamed = (name: string) => chart?.fields.find((candidate) => candidate.tsName === name);
1436
+ const chartValues = chartFieldNamed("values");
1437
+ const metric = optionalStruct(metricField);
1438
+ const metricNames = metric?.fields.map((candidate) => candidate.tsName).sort() ?? [];
1439
+ const metricFieldNamed = (name: string) => metric?.fields.find((candidate) => candidate.tsName === name);
1372
1440
  const numericId = id !== undefined && ["number", "i64", "f64", "numAlias"].includes(id.type.k);
1373
1441
  const numericItemId = itemId !== undefined && ["number", "i64", "f64", "numAlias"].includes(itemId.type.k);
1374
1442
  const numericWidth = width !== undefined && ["number", "i64", "f64", "numAlias"].includes(width.type.k);
1375
1443
  const numericOpacity = iconOpacity !== undefined && ["number", "i64", "f64", "numAlias"].includes(iconOpacity.type.k);
1444
+ const optionalNumeric = (candidate: typeof fontSize): boolean =>
1445
+ candidate?.type.k === "optional" && ["number", "i64", "f64", "numAlias"].includes(candidate.type.inner.k);
1376
1446
  const enumMembersAre = (candidate: typeof tone, expected: readonly string[]): boolean => {
1377
1447
  if (candidate?.type.k !== "enum") return false;
1378
1448
  const found = this.table.enums.get(candidate.type.name)?.members.slice().sort() ?? [];
1379
1449
  return found.join(",") === expected.slice().sort().join(",");
1380
1450
  };
1451
+ const optionalEnumMembersAre = (candidate: typeof fontWeight, expected: readonly string[]): boolean => {
1452
+ if (candidate?.type.k !== "optional" || candidate.type.inner.k !== "enum") return false;
1453
+ const found = this.table.enums.get(candidate.type.inner.name)?.members.slice().sort() ?? [];
1454
+ return found.join(",") === expected.slice().sort().join(",");
1455
+ };
1381
1456
  const boolModifierFields = modifiers !== undefined && modifiers.fields.every((candidate) => candidate.type.k === "bool");
1382
1457
  const valid =
1383
1458
  names.join(",") === "activationCommand,alternateActivationCommand,iconPath,id,items,openCommand,presentation,tooltip,visible" &&
1384
1459
  numericId &&
1385
1460
  visible?.type.k === "bool" &&
1386
1461
  byteFields.every((candidate) => candidate?.type.k === "bytes") &&
1387
- presentationNames.join(",") === "iconOpacity,monospaced,title,tone,width" &&
1462
+ presentationNames.join(",") === "fontSize,fontWeight,iconOpacity,monospaced,title,tone,width" &&
1388
1463
  title?.type.k === "bytes" &&
1389
1464
  numericWidth &&
1390
1465
  enumMembersAre(tone, ["normal", "warning", "critical"]) &&
1391
1466
  numericOpacity &&
1392
1467
  monospaced?.type.k === "bool" &&
1393
- itemNames.join(",") === "command,detail,enabled,id,key,label,modifiers,role,separator" &&
1468
+ optionalNumeric(fontSize) &&
1469
+ optionalEnumMembersAre(fontWeight, ["regular", "medium", "semibold", "bold"]) &&
1470
+ itemNames.join(",") === "chart,command,detail,enabled,id,key,label,metric,modifiers,role,segmented,separator" &&
1394
1471
  numericItemId &&
1395
1472
  label?.type.k === "bytes" &&
1396
1473
  command?.type.k === "bytes" &&
1397
1474
  separator?.type.k === "bool" &&
1398
1475
  enabled?.type.k === "bool" &&
1399
1476
  detail?.type.k === "bytes" &&
1400
- enumMembersAre(role, ["command", "info", "header", "hero", "agent", "context"]) &&
1477
+ enumMembersAre(role, ["command", "info", "header", "hero", "agent", "context", "segmented", "chart"]) &&
1401
1478
  key?.type.k === "bytes" &&
1402
1479
  modifierNames.join(",") === "command,control,option,primary,shift" &&
1403
- boolModifierFields;
1480
+ boolModifierFields &&
1481
+ segmentedNames.join(",") === "options" &&
1482
+ segmentOptionNames.join(",") === "command,enabled,id,label,selected" &&
1483
+ segmentOptionField("id") !== undefined && ["number", "i64", "f64", "numAlias"].includes(segmentOptionField("id")!.type.k) &&
1484
+ segmentOptionField("label")?.type.k === "bytes" &&
1485
+ segmentOptionField("command")?.type.k === "bytes" &&
1486
+ segmentOptionField("selected")?.type.k === "bool" &&
1487
+ segmentOptionField("enabled")?.type.k === "bool" &&
1488
+ metricNames.join(",") === "accessibilityLabel,primaryText,secondaryText" &&
1489
+ metricFieldNamed("primaryText")?.type.k === "bytes" &&
1490
+ metricFieldNamed("secondaryText")?.type.k === "bytes" &&
1491
+ metricFieldNamed("accessibilityLabel")?.type.k === "bytes" &&
1492
+ chartNames.join(",") === "accessibilityLabel,leadingCaption,maxValue,minValue,trailingSummary,values" &&
1493
+ chartValues?.type.k === "slice" && chartValues.type.elem.k === "number" &&
1494
+ chartFieldNamed("minValue") !== undefined && ["number", "i64", "f64", "numAlias"].includes(chartFieldNamed("minValue")!.type.k) &&
1495
+ chartFieldNamed("maxValue") !== undefined && ["number", "i64", "f64", "numAlias"].includes(chartFieldNamed("maxValue")!.type.k) &&
1496
+ chartFieldNamed("leadingCaption")?.type.k === "bytes" &&
1497
+ chartFieldNamed("trailingSummary")?.type.k === "bytes" &&
1498
+ chartFieldNamed("accessibilityLabel")?.type.k === "bytes";
1404
1499
  if (!valid) {
1405
1500
  this.report(
1406
1501
  "NS1033",
@@ -1467,12 +1562,13 @@ export class SubsetChecker {
1467
1562
  return candidate?.type.k === "optional" && ["number", "i64", "f64", "numAlias"].includes(candidate.type.inner.k);
1468
1563
  };
1469
1564
  const valid =
1470
- names.join(",") === "activateOnShow,allowsFullscreen,alwaysOnTop,canvasLabel,clickThrough,closePolicy,height,label,minHeight,minWidth,onCloseCommand,resizable,title,titlebar,transparent,width,x,y" &&
1565
+ names.join(",") === "activateOnShow,allowsFullscreen,alwaysOnTop,canvasLabel,clickThrough,closePolicy,height,label,minHeight,minWidth,onCloseCommand,resizable,restorePolicy,title,titlebar,transparent,width,x,y" &&
1471
1566
  field("label")?.type.k === "bytes" &&
1472
1567
  field("canvasLabel")?.type.k === "bytes" &&
1473
1568
  field("title")?.type.k === "bytes" &&
1474
1569
  numeric("width") && numeric("height") && optionalNumeric("x") && optionalNumeric("y") &&
1475
- field("resizable")?.type.k === "bool" && numeric("minWidth") && numeric("minHeight") &&
1570
+ field("resizable")?.type.k === "bool" && enumMembersAre("restorePolicy", ["clamp_to_visible_screen", "center_on_primary"]) &&
1571
+ numeric("minWidth") && numeric("minHeight") &&
1476
1572
  enumMembersAre("titlebar", ["standard", "hidden_inset", "hidden_inset_tall", "chromeless"]) &&
1477
1573
  field("transparent")?.type.k === "bool" && field("alwaysOnTop")?.type.k === "bool" &&
1478
1574
  field("clickThrough")?.type.k === "bool" && field("activateOnShow")?.type.k === "bool" &&