@native-sdk/cli 0.7.2 → 0.8.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.
Files changed (61) hide show
  1. package/build/app.zig +265 -65
  2. package/build/ts_run.mjs +6 -8
  3. package/build.zig +292 -349
  4. package/package.json +13 -11
  5. package/packages/core/compile-surface/core.ts +559 -0
  6. package/packages/core/package-lock.json +375 -12
  7. package/packages/core/package.json +9 -6
  8. package/packages/core/scripts/compiler_typecheck.mjs +58 -0
  9. package/packages/core/scripts/gen_case_tables.mjs +130 -0
  10. package/packages/core/scripts/gen_declarations.mjs +97 -0
  11. package/packages/core/scripts/run_external_core_compiler.mjs +108 -0
  12. package/packages/core/scripts/stage_external_core.mjs +148 -0
  13. package/packages/core/sdk/core.d.ts +363 -0
  14. package/packages/core/sdk/events.d.ts +65 -0
  15. package/packages/core/sdk/text.d.ts +51 -0
  16. package/packages/core/src/checker.ts +3 -3
  17. package/packages/core/src/cli.ts +40 -38
  18. package/packages/core/src/contract.ts +749 -0
  19. package/packages/core/src/devhost.ts +4 -3
  20. package/packages/core/src/diagnostics.ts +5 -7
  21. package/packages/core/src/{transpile.ts → frontend.ts} +38 -50
  22. package/packages/core/src/infer.ts +1 -1
  23. package/packages/core/src/typed_ast.ts +16 -15
  24. package/packages/core/src/wyhash.ts +79 -0
  25. package/skill-data/native-ui/SKILL.md +3 -2
  26. package/skill-data/ts-core/SKILL.md +29 -29
  27. package/src/platform/macos/appkit_host.h +4 -4
  28. package/src/platform/macos/appkit_host.m +24 -4
  29. package/src/platform/macos/cef_host.mm +22 -6
  30. package/src/platform/macos/root.zig +2 -2
  31. package/src/primitives/canvas/markdown.zig +2010 -57
  32. package/src/primitives/canvas/markdown_hostile_tests.zig +40 -0
  33. package/src/primitives/canvas/markdown_tests.zig +778 -3
  34. package/src/primitives/canvas/ui_markup.zig +9 -1
  35. package/src/primitives/canvas/ui_markup_compiled.zig +29 -0
  36. package/src/primitives/canvas/ui_markup_contract.zig +11 -0
  37. package/src/primitives/canvas/ui_markup_view.zig +20 -0
  38. package/src/primitives/canvas/ui_markup_view_tests.zig +13 -1
  39. package/src/primitives/canvas/ui_schema.zig +3 -0
  40. package/src/primitives/canvas/ui_schema_tests.zig +4 -3
  41. package/src/primitives/canvas/widget_layout.zig +26 -3
  42. package/src/primitives/canvas/widget_metrics.zig +21 -3
  43. package/src/primitives/canvas/widget_render.zig +6 -1
  44. package/src/runtime/effects.zig +9 -0
  45. package/src/runtime/effects_fetch_tests.zig +21 -0
  46. package/src/runtime/ts_core_host.zig +38 -38
  47. package/src/runtime/ts_ui_app.zig +12 -12
  48. package/src/tooling/manifest.zig +32 -0
  49. package/src/tooling/raw_manifest.zig +4 -0
  50. package/src/tooling/templates.zig +25 -20
  51. package/src/tooling/ts_core.zig +55 -34
  52. package/src/tooling/verbs.zig +1 -1
  53. package/tools/corewire/core_abi.zig +169 -0
  54. package/tools/corewire/emit.zig +2418 -0
  55. package/tools/corewire/emit_facade.zig +3984 -0
  56. package/tools/corewire/emit_profile.zig +501 -0
  57. package/tools/corewire/main.zig +561 -0
  58. package/tools/corewire/shim_rt.zig +632 -0
  59. package/tools/corewire/sidecar.zig +2507 -0
  60. package/packages/core/rt/rt.zig +0 -1986
  61. package/packages/core/src/emitter.ts +0 -11898
@@ -0,0 +1,363 @@
1
+ export declare function asciiBytes(s: string): Uint8Array;
2
+ export type Msgish = {
3
+ readonly kind: string;
4
+ };
5
+ export type TimestampKind<M extends Msgish> = M extends Msgish ? {
6
+ [K in Exclude<keyof M, "kind">]-?: M[K] extends number ? [Exclude<keyof M, "kind">] extends [K] ? M["kind"] : never : never;
7
+ }[Exclude<keyof M, "kind">] : never;
8
+ export type BytesKind<M extends Msgish> = M extends Msgish ? {
9
+ [K in Exclude<keyof M, "kind">]-?: M[K] extends Uint8Array ? [Exclude<keyof M, "kind">] extends [K] ? M["kind"] : never : never;
10
+ }[Exclude<keyof M, "kind">] : never;
11
+ export type EmptyKind<M extends Msgish> = M extends Msgish ? [Exclude<keyof M, "kind">] extends [never] ? M["kind"] : never : never;
12
+ export type FetchedKind<M extends Msgish> = M extends Msgish ? {
13
+ [K in Exclude<keyof M, "kind">]-?: M[K] extends Uint8Array ? Exclude<keyof M, "kind" | K> extends infer O ? O extends keyof M ? M[O] extends number ? [Exclude<keyof M, "kind" | K | O>] extends [never] ? M["kind"] : never : never : never : never : never;
14
+ }[Exclude<keyof M, "kind">] : never;
15
+ export interface EnvMsg<M extends Msgish> {
16
+ readonly env: string;
17
+ readonly msg: BytesKind<M>;
18
+ }
19
+ export type AudioState = "loaded" | "position" | "completed" | "failed" | "rejected" | "spectrum";
20
+ export type AudioEventArm = {
21
+ readonly state: AudioState;
22
+ readonly positionMs: number;
23
+ readonly durationMs: number;
24
+ readonly playing: boolean;
25
+ readonly buffering: boolean;
26
+ readonly bands: Uint8Array;
27
+ };
28
+ export type AudioEventKind<M extends Msgish> = M extends Msgish ? [Exclude<keyof M, "kind">] extends [keyof AudioEventArm] ? [keyof AudioEventArm] extends [Exclude<keyof M, "kind">] ? M extends Msgish & AudioEventArm ? [AudioState] extends [M["state"]] ? M["kind"] : never : never : never : never : never;
29
+ export type VideoState = "loaded" | "position" | "completed" | "failed" | "rejected";
30
+ export type VideoEventArm = {
31
+ readonly state: VideoState;
32
+ readonly positionMs: number;
33
+ readonly durationMs: number;
34
+ readonly playing: boolean;
35
+ readonly buffering: boolean;
36
+ readonly width: number;
37
+ readonly height: number;
38
+ };
39
+ export type VideoEventKind<M extends Msgish> = M extends Msgish ? [Exclude<keyof M, "kind">] extends [keyof VideoEventArm] ? [keyof VideoEventArm] extends [Exclude<keyof M, "kind">] ? M extends Msgish & VideoEventArm ? [VideoState] extends [M["state"]] ? M["kind"] : never : never : never : never : never;
40
+ export type ImageState = "loaded" | "rejected" | "not_found" | "io_failed" | "connect_failed" | "tls_failed" | "protocol_failed" | "timed_out" | "http_status" | "cancelled" | "too_large" | "unsupported" | "decode_failed" | "registry_full" | "alloc_failed";
41
+ export type ImageEventArm = {
42
+ readonly id: number;
43
+ readonly state: ImageState;
44
+ readonly width: number;
45
+ readonly height: number;
46
+ readonly status: number;
47
+ };
48
+ export type ImageEventKind<M extends Msgish> = M extends Msgish ? [Exclude<keyof M, "kind">] extends [keyof ImageEventArm] ? [keyof ImageEventArm] extends [Exclude<keyof M, "kind">] ? M extends Msgish & ImageEventArm ? [ImageState] extends [M["state"]] ? M["kind"] : never : never : never : never : never;
49
+ export type ChannelState = "data" | "closed" | "rejected";
50
+ export type ChannelEventArm = {
51
+ readonly key: number;
52
+ readonly state: ChannelState;
53
+ readonly bytes: Uint8Array;
54
+ readonly droppedPending: number;
55
+ readonly droppedTotal: number;
56
+ };
57
+ export type ChannelEventKind<M extends Msgish> = M extends Msgish ? [Exclude<keyof M, "kind">] extends [keyof ChannelEventArm] ? [keyof ChannelEventArm] extends [Exclude<keyof M, "kind">] ? M extends Msgish & ChannelEventArm ? [ChannelState] extends [M["state"]] ? M["kind"] : never : never : never : never : never;
58
+ export interface ChannelRoute<M extends Msgish> {
59
+ readonly event: ChannelEventKind<M>;
60
+ }
61
+ export type PtyState = "output" | "exit";
62
+ export type PtyExitReason = "exited" | "signaled" | "cancelled" | "rejected" | "spawn_failed";
63
+ export type PtyEventArm = {
64
+ readonly key: string;
65
+ readonly state: PtyState;
66
+ readonly bytes: Uint8Array;
67
+ readonly code: number;
68
+ readonly reason: PtyExitReason;
69
+ readonly signal: number;
70
+ readonly droppedWrites: number;
71
+ };
72
+ export type PtyEventKind<M extends Msgish> = M extends Msgish ? [Exclude<keyof M, "kind">] extends [keyof PtyEventArm] ? [keyof PtyEventArm] extends [Exclude<keyof M, "kind">] ? M extends Msgish & PtyEventArm ? [PtyState] extends [M["state"]] ? [PtyExitReason] extends [M["reason"]] ? M["kind"] : never : never : never : never : never : never;
73
+ export interface PtyRoute<M extends Msgish> {
74
+ readonly key?: string;
75
+ readonly cols?: number;
76
+ readonly rows?: number;
77
+ readonly term?: string;
78
+ readonly event: PtyEventKind<M>;
79
+ }
80
+ export type HostScalar = number | boolean | Uint8Array;
81
+ export type HostRecord = {
82
+ readonly [field: string]: HostScalar;
83
+ };
84
+ export interface RequestRoute<M extends Msgish> {
85
+ readonly key?: string;
86
+ readonly ok: BytesKind<M>;
87
+ readonly err: BytesKind<M>;
88
+ }
89
+ export interface WriteRoute<M extends Msgish> {
90
+ readonly key?: string;
91
+ readonly ok: EmptyKind<M>;
92
+ readonly err: BytesKind<M>;
93
+ }
94
+ export interface FetchRoute<M extends Msgish> {
95
+ readonly key?: string;
96
+ readonly ok: FetchedKind<M>;
97
+ readonly err: BytesKind<M>;
98
+ }
99
+ export interface SpawnRoute<M extends Msgish> {
100
+ readonly key?: string;
101
+ readonly stdin?: Uint8Array;
102
+ readonly line?: BytesKind<M>;
103
+ readonly exit: TimestampKind<M>;
104
+ readonly err: BytesKind<M>;
105
+ }
106
+ export interface SpawnCollectRoute<M extends Msgish> {
107
+ readonly key?: string;
108
+ readonly stdin?: Uint8Array;
109
+ readonly collect: true;
110
+ readonly exit: FetchedKind<M>;
111
+ readonly err: BytesKind<M>;
112
+ }
113
+ export interface AudioSource {
114
+ readonly path?: Uint8Array;
115
+ readonly url?: Uint8Array;
116
+ readonly cachePath?: Uint8Array;
117
+ readonly expectedBytes?: number;
118
+ }
119
+ export interface AudioRoute<M extends Msgish> {
120
+ readonly event: AudioEventKind<M>;
121
+ }
122
+ export interface VideoSource {
123
+ readonly surface: number;
124
+ readonly path?: Uint8Array;
125
+ readonly url?: Uint8Array;
126
+ readonly autoplay?: boolean;
127
+ readonly loop?: boolean;
128
+ readonly muted?: boolean;
129
+ }
130
+ export interface VideoRoute<M extends Msgish> {
131
+ readonly event: VideoEventKind<M>;
132
+ }
133
+ export interface ImageSource {
134
+ readonly path?: Uint8Array;
135
+ readonly url?: Uint8Array;
136
+ readonly cachePath?: Uint8Array;
137
+ readonly expectedBytes?: number;
138
+ }
139
+ export interface ImageRoute<M extends Msgish> {
140
+ readonly event: ImageEventKind<M>;
141
+ }
142
+ export type FetchMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD";
143
+ export interface FetchSpec {
144
+ readonly url: Uint8Array;
145
+ readonly method?: FetchMethod;
146
+ readonly headers?: {
147
+ readonly [name: string]: string | Uint8Array;
148
+ };
149
+ readonly body?: Uint8Array;
150
+ readonly timeoutMs?: number;
151
+ }
152
+ export type Cmd<M extends Msgish> = {
153
+ readonly op: "none";
154
+ } | {
155
+ readonly op: "persist";
156
+ } | {
157
+ readonly op: "now";
158
+ readonly msgKind: string;
159
+ } | {
160
+ readonly op: "host";
161
+ readonly name: string;
162
+ readonly args: readonly number[];
163
+ } | {
164
+ readonly op: "host_bytes";
165
+ readonly name: string;
166
+ readonly payload: Uint8Array;
167
+ } | {
168
+ readonly op: "request";
169
+ readonly name: string;
170
+ readonly key: string;
171
+ readonly okKind: string;
172
+ readonly errKind: string;
173
+ readonly payload: Uint8Array;
174
+ } | {
175
+ readonly op: "cancel";
176
+ readonly key: string;
177
+ } | {
178
+ readonly op: "read_file";
179
+ readonly key: string;
180
+ readonly okKind: string;
181
+ readonly errKind: string;
182
+ readonly path: Uint8Array;
183
+ } | {
184
+ readonly op: "write_file";
185
+ readonly key: string;
186
+ readonly okKind: string;
187
+ readonly errKind: string;
188
+ readonly path: Uint8Array;
189
+ readonly bytes: Uint8Array;
190
+ } | {
191
+ readonly op: "fetch";
192
+ readonly key: string;
193
+ readonly okKind: string;
194
+ readonly errKind: string;
195
+ readonly method: FetchMethod;
196
+ readonly timeoutMs: number;
197
+ readonly url: Uint8Array;
198
+ readonly headers: readonly {
199
+ readonly name: string;
200
+ readonly value: string | Uint8Array;
201
+ }[];
202
+ readonly body: Uint8Array;
203
+ } | {
204
+ readonly op: "clip_write";
205
+ readonly bytes: Uint8Array;
206
+ } | {
207
+ readonly op: "clip_read";
208
+ readonly key: string;
209
+ readonly okKind: string;
210
+ readonly errKind: string;
211
+ } | {
212
+ readonly op: "delay";
213
+ readonly key: string;
214
+ readonly afterMs: number;
215
+ readonly msgKind: string;
216
+ } | {
217
+ readonly op: "spawn";
218
+ readonly key: string;
219
+ readonly lineKind: string;
220
+ readonly exitKind: string;
221
+ readonly errKind: string;
222
+ readonly collect: boolean;
223
+ readonly argv: readonly Uint8Array[];
224
+ readonly stdin: Uint8Array;
225
+ } | {
226
+ readonly op: "audio_play";
227
+ readonly key: string;
228
+ readonly eventKind: string;
229
+ readonly path: Uint8Array;
230
+ readonly url: Uint8Array;
231
+ readonly cachePath: Uint8Array;
232
+ readonly expectedBytes: number;
233
+ } | {
234
+ readonly op: "audio_ctl";
235
+ readonly key: string;
236
+ readonly verb: "pause" | "resume" | "stop" | "seek" | "volume";
237
+ readonly value: number;
238
+ } | {
239
+ readonly op: "video_load";
240
+ readonly key: string;
241
+ readonly eventKind: string;
242
+ readonly surface: number;
243
+ readonly path: Uint8Array;
244
+ readonly url: Uint8Array;
245
+ readonly autoplay: boolean;
246
+ readonly loop: boolean;
247
+ readonly muted: boolean;
248
+ } | {
249
+ readonly op: "video_ctl";
250
+ readonly key: string;
251
+ readonly verb: "play" | "pause" | "stop" | "seek" | "volume" | "muted" | "loop";
252
+ readonly value: number;
253
+ } | {
254
+ readonly op: "window_show";
255
+ readonly label: string;
256
+ } | {
257
+ readonly op: "quit_app";
258
+ } | {
259
+ readonly op: "image_load";
260
+ readonly id: number;
261
+ readonly eventKind: string;
262
+ readonly path: Uint8Array;
263
+ readonly url: Uint8Array;
264
+ readonly cachePath: Uint8Array;
265
+ readonly expectedBytes: number;
266
+ } | {
267
+ readonly op: "image_cancel";
268
+ readonly id: number;
269
+ } | {
270
+ readonly op: "image_unregister";
271
+ readonly id: number;
272
+ } | {
273
+ readonly op: "channel_open";
274
+ readonly key: number;
275
+ readonly eventKind: string;
276
+ } | {
277
+ readonly op: "channel_close";
278
+ readonly key: number;
279
+ } | {
280
+ readonly op: "pty_spawn";
281
+ readonly key: string;
282
+ readonly eventKind: string;
283
+ readonly cols: number;
284
+ readonly rows: number;
285
+ readonly term: string;
286
+ readonly argv: readonly Uint8Array[];
287
+ } | {
288
+ readonly op: "pty_write";
289
+ readonly key: string;
290
+ readonly bytes: Uint8Array;
291
+ } | {
292
+ readonly op: "pty_resize";
293
+ readonly key: string;
294
+ readonly cols: number;
295
+ readonly rows: number;
296
+ } | {
297
+ readonly op: "pty_kill";
298
+ readonly key: string;
299
+ } | {
300
+ readonly op: "batch";
301
+ readonly cmds: readonly Cmd<M>[];
302
+ };
303
+ export declare function hostRecordBytes(payload: HostRecord): Uint8Array;
304
+ declare function hostCmd(name: string, payload: Uint8Array | HostRecord): Cmd<never>;
305
+ declare function hostCmd(name: string, ...args: readonly number[]): Cmd<never>;
306
+ export declare const Cmd: {
307
+ none: Cmd<never>;
308
+ persist(): Cmd<never>;
309
+ now<M extends Msgish>(msgKind: TimestampKind<M>): Cmd<M>;
310
+ host: typeof hostCmd;
311
+ request<M extends Msgish>(name: string, payload: Uint8Array | HostRecord, route: RequestRoute<M>): Cmd<M>;
312
+ cancel(key: string): Cmd<never>;
313
+ readFile<M extends Msgish>(path: Uint8Array, route: RequestRoute<M>): Cmd<M>;
314
+ writeFile<M extends Msgish>(path: Uint8Array, bytes: Uint8Array, route: WriteRoute<M>): Cmd<M>;
315
+ fetch<M extends Msgish>(spec: FetchSpec, route: FetchRoute<M>): Cmd<M>;
316
+ clipboardWrite(bytes: Uint8Array): Cmd<never>;
317
+ clipboardRead<M extends Msgish>(route: RequestRoute<M>): Cmd<M>;
318
+ delay<M extends Msgish>(key: string, ms: number, msgKind: TimestampKind<M>): Cmd<M>;
319
+ spawn<M extends Msgish>(argv: readonly Uint8Array[], route: SpawnRoute<M> | SpawnCollectRoute<M>): Cmd<M>;
320
+ audioPlay<M extends Msgish>(key: string, source: AudioSource, route: AudioRoute<M>): Cmd<M>;
321
+ audioPause(key: string): Cmd<never>;
322
+ audioResume(key: string): Cmd<never>;
323
+ audioStop(key: string): Cmd<never>;
324
+ audioSeek(key: string, ms: number): Cmd<never>;
325
+ audioSetVolume(key: string, volume: number): Cmd<never>;
326
+ videoLoad<M extends Msgish>(key: string, source: VideoSource, route: VideoRoute<M>): Cmd<M>;
327
+ videoPlay(key: string): Cmd<never>;
328
+ videoPause(key: string): Cmd<never>;
329
+ videoStop(key: string): Cmd<never>;
330
+ videoSeek(key: string, ms: number): Cmd<never>;
331
+ videoSetVolume(key: string, volume: number): Cmd<never>;
332
+ videoSetMuted(key: string, muted: boolean): Cmd<never>;
333
+ videoSetLoop(key: string, loop: boolean): Cmd<never>;
334
+ showWindow(label: string): Cmd<never>;
335
+ quitApp(): Cmd<never>;
336
+ imageLoad<M extends Msgish>(id: number, source: ImageSource, route: ImageRoute<M>): Cmd<M>;
337
+ imageCancel(id: number): Cmd<never>;
338
+ imageUnregister(id: number): Cmd<never>;
339
+ channelOpen<M extends Msgish>(key: number, route: ChannelRoute<M>): Cmd<M>;
340
+ channelClose(key: number): Cmd<never>;
341
+ ptySpawn<M extends Msgish>(argv: readonly Uint8Array[], route: PtyRoute<M>): Cmd<M>;
342
+ ptyWrite(key: string, bytes: Uint8Array): Cmd<never>;
343
+ ptyResize(key: string, cols: number, rows: number): Cmd<never>;
344
+ ptyKill(key: string): Cmd<never>;
345
+ batch<M extends Msgish>(cmds: readonly Cmd<M>[]): Cmd<M>;
346
+ };
347
+ export type Sub<M extends Msgish> = {
348
+ readonly op: "none";
349
+ } | {
350
+ readonly op: "timer";
351
+ readonly key: string;
352
+ readonly everyMs: number;
353
+ readonly msgKind: string;
354
+ } | {
355
+ readonly op: "batch";
356
+ readonly subs: readonly Sub<M>[];
357
+ };
358
+ export declare const Sub: {
359
+ none: Sub<never>;
360
+ timer<M extends Msgish>(key: string, everyMs: number, msgKind: TimestampKind<M>): Sub<M>;
361
+ batch<M extends Msgish>(subs: readonly Sub<M>[]): Sub<M>;
362
+ };
363
+ export {};
@@ -0,0 +1,65 @@
1
+ export type { TextCaretDirection, TextCaretMove, TextSelection, TextInputEvent } from "./text.js";
2
+ export interface ScrollState {
3
+ readonly offsetX: number;
4
+ readonly offsetY: number;
5
+ readonly velocityX: number;
6
+ readonly velocityY: number;
7
+ readonly viewportExtentX: number;
8
+ readonly viewportExtentY: number;
9
+ readonly contentExtentX: number;
10
+ readonly contentExtentY: number;
11
+ }
12
+ export interface FrameEvent {
13
+ readonly width: number;
14
+ readonly height: number;
15
+ readonly timestampMs: number;
16
+ readonly intervalMs: number;
17
+ }
18
+ export interface KeyEvent {
19
+ readonly key: string;
20
+ readonly shift: boolean;
21
+ readonly control: boolean;
22
+ readonly alt: boolean;
23
+ readonly super: boolean;
24
+ }
25
+ export type PinchPhase = "begin" | "change" | "end";
26
+ export interface PinchEvent {
27
+ readonly windowId: number;
28
+ readonly label: string;
29
+ readonly phase: PinchPhase;
30
+ readonly scale: number;
31
+ readonly x: number;
32
+ readonly y: number;
33
+ }
34
+ export type ColorScheme = "light" | "dark";
35
+ export interface AppearanceEvent {
36
+ readonly colorScheme: ColorScheme;
37
+ readonly reduceMotion: boolean;
38
+ readonly highContrast: boolean;
39
+ }
40
+ export interface ChromeInsets {
41
+ readonly top: number;
42
+ readonly right: number;
43
+ readonly bottom: number;
44
+ readonly left: number;
45
+ }
46
+ export interface ChromeButtons {
47
+ readonly x: number;
48
+ readonly y: number;
49
+ readonly width: number;
50
+ readonly height: number;
51
+ }
52
+ export interface ChromeEvent {
53
+ readonly insets: ChromeInsets;
54
+ readonly buttons: ChromeButtons;
55
+ readonly tabsProjected: boolean;
56
+ }
57
+ export type AudioState = "loaded" | "position" | "completed" | "failed" | "rejected" | "spectrum";
58
+ export interface AudioEvent {
59
+ readonly state: AudioState;
60
+ readonly positionMs: number;
61
+ readonly durationMs: number;
62
+ readonly playing: boolean;
63
+ readonly buffering: boolean;
64
+ readonly bands: Uint8Array;
65
+ }
@@ -0,0 +1,51 @@
1
+ export interface TextRange {
2
+ readonly start: number;
3
+ readonly end: number;
4
+ }
5
+ export interface TextSelection {
6
+ readonly anchor: number;
7
+ readonly focus: number;
8
+ }
9
+ export type TextCaretDirection = "previous" | "next" | "previous_word" | "next_word" | "start" | "end";
10
+ export interface TextCaretMove {
11
+ readonly direction: TextCaretDirection;
12
+ readonly extend: boolean;
13
+ }
14
+ export type TextInputEvent = {
15
+ readonly kind: "insert_text";
16
+ readonly text: Uint8Array;
17
+ } | {
18
+ readonly kind: "delete_backward";
19
+ } | {
20
+ readonly kind: "delete_forward";
21
+ } | {
22
+ readonly kind: "delete_word_backward";
23
+ } | {
24
+ readonly kind: "delete_word_forward";
25
+ } | {
26
+ readonly kind: "clear";
27
+ } | {
28
+ readonly kind: "move_caret";
29
+ readonly move: TextCaretMove;
30
+ } | {
31
+ readonly kind: "set_selection";
32
+ readonly selection: TextSelection;
33
+ } | {
34
+ readonly kind: "set_composition";
35
+ readonly text: Uint8Array;
36
+ readonly cursor: number | null;
37
+ } | {
38
+ readonly kind: "commit_composition";
39
+ } | {
40
+ readonly kind: "cancel_composition";
41
+ };
42
+ export interface TextEditState {
43
+ readonly text: Uint8Array;
44
+ readonly selection: TextSelection;
45
+ readonly composition: TextRange | null;
46
+ }
47
+ export declare function applyTextInputEvent(state: TextEditState, event: TextInputEvent, capacity: number): TextEditState | null;
48
+ export declare function clampedInsertEvent(state: TextEditState, event: TextInputEvent, capacity: number): TextInputEvent | null;
49
+ export declare function containsIgnoreCase(haystack: Uint8Array, needle: Uint8Array): boolean;
50
+ export declare function orderIgnoreCase(a: Uint8Array, b: Uint8Array): number;
51
+ export declare function trimAsciiSpaces(text: Uint8Array): Uint8Array;
@@ -1142,10 +1142,10 @@ export class SubsetChecker {
1142
1142
  }
1143
1143
  }
1144
1144
 
1145
- /// NS1038 — one flat emitted namespace: type names (which the whole
1145
+ /// NS1038 — one flat compiled namespace: type names (which the whole
1146
1146
  /// pipeline resolves by name) and EXPORTED value names must be unique
1147
1147
  /// across the core's modules. Private value collisions are fine — the
1148
- /// emitter uniques those with a per-module prefix.
1148
+ /// compile uniques those per module.
1149
1149
  private checkNameCollisions(): void {
1150
1150
  interface Claim {
1151
1151
  readonly file: ts.SourceFile;
@@ -1754,7 +1754,7 @@ export class SubsetChecker {
1754
1754
  // NS1045 — destructuring: record fields into const locals only.
1755
1755
  if (ts.isArrayBindingPattern(node)) {
1756
1756
  // `for (const [i, x] of xs.entries())` keeps its own tailored
1757
- // teaching (the emitter names the classic-loop rewrite).
1757
+ // teaching (it names the classic-loop rewrite).
1758
1758
  if (!isEntriesLoopBinding(node)) {
1759
1759
  this.report("NS1045", "Array destructuring binds element positions.", node);
1760
1760
  }
@@ -1,44 +1,38 @@
1
1
  #!/usr/bin/env node
2
- // @native-sdk/core: transpile an app-core subset TypeScript module to Zig.
2
+ // @native-sdk/core: check an app-core subset TypeScript module and emit
3
+ // its contract sidecar. The external core compiler does the compiling;
4
+ // this CLI is the frontend — the subset's teaching surface and the
5
+ // contract source.
3
6
  //
4
- // native-core <entry.ts> -o <out.zig> [--frame-cap <bytes>] [--heap-cap <bytes>]
7
+ // native-core <entry.ts> [--contract <out.contract.json>] [--contract-entry <spelling>]
5
8
  //
6
- // --frame-cap / --heap-cap set the emitted core's rt kernel capacities (the
7
- // frame arena and the per-space model heap) as comptime constants; omitted,
8
- // the rt defaults apply.
9
+ // --contract writes the contract sidecar (core.contract.json, schema
10
+ // format 1) emitted directly from the checked program — the document the
11
+ // external core compiler's projections consume. --contract-entry sets the
12
+ // entry spelling the document states (default: the entry argument as
13
+ // given, POSIX separators).
9
14
  //
10
- // Exit codes: 0 emitted; 1 subset/type errors (teaching diagnostics on
11
- // stderr); 2 usage.
15
+ // Exit codes: 0 checked (and contract written when asked); 1 subset/type
16
+ // errors (teaching diagnostics on stderr); 2 usage.
12
17
 
13
- import { transpileFile, formatDiagnostic, type TranspileOptions } from "./transpile.ts";
18
+ import { checkFile, formatDiagnostic, type FrontendOptions } from "./frontend.ts";
14
19
  import fs from "node:fs";
15
20
 
16
- function parseByteCount(flag: string, raw: string | undefined): number | null {
17
- const v = raw === undefined ? NaN : Number(raw);
18
- if (!Number.isSafeInteger(v) || v <= 0) {
19
- console.error(`${flag} needs a positive integer byte count, got ${raw ?? "<missing>"}`);
20
- return null;
21
- }
22
- return v;
23
- }
24
-
25
21
  function main(argv: string[]): number {
26
22
  const args = argv.slice(2);
27
23
  let entry: string | null = null;
28
- let out: string | null = null;
29
- let frameCap: number | undefined;
30
- let heapCap: number | undefined;
24
+ let contractOut: string | null = null;
25
+ let contractEntry: string | null = null;
31
26
  for (let i = 0; i < args.length; i++) {
32
- if (args[i] === "-o" || args[i] === "--out") {
33
- out = args[++i] ?? null;
34
- } else if (args[i] === "--frame-cap") {
35
- const v = parseByteCount("--frame-cap", args[++i]);
36
- if (v === null) return 2;
37
- frameCap = v;
38
- } else if (args[i] === "--heap-cap") {
39
- const v = parseByteCount("--heap-cap", args[++i]);
40
- if (v === null) return 2;
41
- heapCap = v;
27
+ if (args[i] === "--contract") {
28
+ contractOut = args[++i] ?? null;
29
+ } else if (args[i] === "--contract-entry") {
30
+ contractEntry = args[++i] ?? null;
31
+ } else if (args[i] === "-o" || args[i] === "--out") {
32
+ console.error(
33
+ "-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.",
34
+ );
35
+ return 2;
42
36
  } else if (!args[i].startsWith("-")) {
43
37
  entry = args[i];
44
38
  } else {
@@ -47,20 +41,28 @@ function main(argv: string[]): number {
47
41
  }
48
42
  }
49
43
  if (!entry) {
50
- console.error("usage: native-core <entry.ts> -o <out.zig> [--frame-cap <bytes>] [--heap-cap <bytes>]");
44
+ console.error(
45
+ "usage: native-core <entry.ts> [--contract <out.contract.json>] [--contract-entry <spelling>]",
46
+ );
51
47
  return 2;
52
48
  }
53
- const options: TranspileOptions = { frameCap, heapCap };
54
- const result = transpileFile(entry, options);
49
+ const options: FrontendOptions = {
50
+ // The document's entry spelling defaults to the argument's own,
51
+ // POSIX separators (the sidecar/facade contract is platform-free).
52
+ contractEntry: contractOut !== null ? (contractEntry ?? entry.split("\\").join("/")) : undefined,
53
+ };
54
+ const result = checkFile(entry, options);
55
55
  for (const e of result.typeErrors) console.error(e);
56
56
  for (const d of result.diagnostics) console.error(formatDiagnostic(d));
57
57
  // Teaching notices (NS1028): printed, never failing the build.
58
58
  for (const w of result.warnings) console.error(formatDiagnostic(w, "warning"));
59
- if (!result.ok || result.zig === null) return 1;
60
- if (out) {
61
- fs.writeFileSync(out, result.zig);
62
- } else {
63
- process.stdout.write(result.zig);
59
+ if (!result.ok) return 1;
60
+ if (contractOut !== null) {
61
+ if (result.contract === null) {
62
+ console.error("internal: the check produced no contract sidecar");
63
+ return 1;
64
+ }
65
+ fs.writeFileSync(contractOut, result.contract);
64
66
  }
65
67
  return 0;
66
68
  }