@native-sdk/cli 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/build/app.zig +50 -3
  2. package/build.zig +134 -360
  3. package/native-sdk.d.ts +4 -0
  4. package/package.json +9 -9
  5. package/packages/core/compile-surface/core.ts +90 -1
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/sdk/core.d.ts +65 -2
  9. package/packages/core/sdk/core.ts +189 -33
  10. package/packages/core/sdk/events.d.ts +14 -0
  11. package/packages/core/sdk/events.ts +18 -0
  12. package/packages/core/src/checker.ts +61 -1
  13. package/packages/core/src/devhost.ts +3 -3
  14. package/packages/core/src/diagnostics.ts +4 -4
  15. package/skill-data/core/SKILL.md +4 -2
  16. package/skill-data/core/references/project-anatomy.md +2 -1
  17. package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
  18. package/skill-data/native-ui/SKILL.md +8 -8
  19. package/skill-data/ts-core/SKILL.md +16 -13
  20. package/src/app_runner/app_assets.zig +138 -0
  21. package/src/app_runner/root.zig +2 -0
  22. package/src/app_runner/ts_core_main.zig +27 -3
  23. package/src/embed/host.zig +6 -0
  24. package/src/embed/ui_host.zig +2 -0
  25. package/src/platform/linux/root.zig +1 -0
  26. package/src/platform/macos/appkit_host.h +10 -0
  27. package/src/platform/macos/appkit_host.m +515 -93
  28. package/src/platform/macos/capture_info_plist.c +25 -0
  29. package/src/platform/macos/cef_host.mm +22 -0
  30. package/src/platform/macos/root.zig +68 -0
  31. package/src/platform/null_platform.zig +58 -0
  32. package/src/platform/root.zig +7 -0
  33. package/src/platform/types.zig +100 -0
  34. package/src/platform/windows/root.zig +56 -0
  35. package/src/platform/windows/webview2_host.cpp +171 -0
  36. package/src/primitives/app_manifest/types.zig +2 -0
  37. package/src/primitives/canvas/code_tests.zig +9 -9
  38. package/src/primitives/canvas/events.zig +12 -11
  39. package/src/primitives/canvas/frame.zig +44 -9
  40. package/src/primitives/canvas/icons/mic.svg +1 -0
  41. package/src/primitives/canvas/icons.zig +2 -0
  42. package/src/primitives/canvas/root.zig +8 -0
  43. package/src/primitives/canvas/text_span_tests.zig +39 -0
  44. package/src/primitives/canvas/ui.zig +23 -4
  45. package/src/primitives/canvas/ui_markup.zig +15 -0
  46. package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
  47. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
  48. package/src/primitives/canvas/ui_markup_tests.zig +5 -0
  49. package/src/primitives/canvas/ui_markup_view.zig +9 -0
  50. package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
  51. package/src/primitives/canvas/ui_schema.zig +19 -10
  52. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  53. package/src/primitives/canvas/ui_tests.zig +18 -4
  54. package/src/primitives/canvas/widget_invalidation.zig +9 -2
  55. package/src/primitives/canvas/widget_render.zig +321 -115
  56. package/src/primitives/canvas/widget_runtime_tests.zig +173 -0
  57. package/src/primitives/canvas/widget_text_input.zig +10 -10
  58. package/src/primitives/canvas/widget_tree.zig +1 -1
  59. package/src/primitives/canvas/widgets.zig +41 -5
  60. package/src/root.zig +10 -0
  61. package/src/runtime/automation_widget_dispatch.zig +1 -0
  62. package/src/runtime/bridge_payload.zig +2 -0
  63. package/src/runtime/canvas_frame.zig +13 -2
  64. package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
  65. package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
  66. package/src/runtime/canvas_widget_event_tests.zig +1 -0
  67. package/src/runtime/canvas_widget_events.zig +69 -24
  68. package/src/runtime/canvas_widget_runtime.zig +101 -6
  69. package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
  70. package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
  71. package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
  72. package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
  73. package/src/runtime/canvas_widget_state.zig +10 -1
  74. package/src/runtime/canvas_widget_text_tests.zig +112 -3
  75. package/src/runtime/effects.zig +313 -2
  76. package/src/runtime/effects_audio_capture_tests.zig +251 -0
  77. package/src/runtime/root.zig +3 -0
  78. package/src/runtime/tests.zig +1 -0
  79. package/src/runtime/ts_core_host.zig +401 -32
  80. package/src/runtime/ts_core_host_tests.zig +407 -0
  81. package/src/runtime/ts_ui_app.zig +39 -1
  82. package/src/runtime/ui_app.zig +18 -3
  83. package/src/runtime/ui_app_tests.zig +48 -0
  84. package/src/runtime/view.zig +2 -0
  85. package/src/runtime/view_widget_scroll.zig +56 -5
  86. package/src/runtime/view_widget_text.zig +24 -5
  87. package/src/runtime/view_widget_tree.zig +1 -1
  88. package/src/tooling/manifest.zig +1034 -0
  89. package/src/tooling/package.zig +841 -10
  90. package/src/tooling/raw_manifest.zig +35 -0
  91. package/src/tooling/templates.zig +55 -0
  92. package/tools/corewire/emit_facade.zig +36 -0
package/native-sdk.d.ts CHANGED
@@ -453,6 +453,10 @@ export type NativeSdkPlatformFeature =
453
453
  | "audioStreaming"
454
454
  | "audio_spectrum"
455
455
  | "audioSpectrum"
456
+ | "microphone_capture"
457
+ | "microphoneCapture"
458
+ | "system_audio_capture"
459
+ | "systemAudioCapture"
456
460
  | "window_hide_on_close"
457
461
  | "windowHideOnClose"
458
462
  | "video_playback"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,14 +34,14 @@
34
34
  "scriptc": "0.0.22"
35
35
  },
36
36
  "optionalDependencies": {
37
- "@native-sdk/cli-darwin-arm64": "0.8.2",
38
- "@native-sdk/cli-darwin-x64": "0.8.2",
39
- "@native-sdk/cli-linux-arm64-gnu": "0.8.2",
40
- "@native-sdk/cli-linux-arm64-musl": "0.8.2",
41
- "@native-sdk/cli-linux-x64-gnu": "0.8.2",
42
- "@native-sdk/cli-linux-x64-musl": "0.8.2",
43
- "@native-sdk/cli-win32-arm64": "0.8.2",
44
- "@native-sdk/cli-win32-x64": "0.8.2"
37
+ "@native-sdk/cli-darwin-arm64": "0.8.4",
38
+ "@native-sdk/cli-darwin-x64": "0.8.4",
39
+ "@native-sdk/cli-linux-arm64-gnu": "0.8.4",
40
+ "@native-sdk/cli-linux-arm64-musl": "0.8.4",
41
+ "@native-sdk/cli-linux-x64-gnu": "0.8.4",
42
+ "@native-sdk/cli-linux-x64-musl": "0.8.4",
43
+ "@native-sdk/cli-win32-arm64": "0.8.4",
44
+ "@native-sdk/cli-win32-x64": "0.8.4"
45
45
  },
46
46
  "repository": {
47
47
  "type": "git",
@@ -67,6 +67,13 @@ export interface FetchRoute<M extends Msgish> {
67
67
  readonly err: M["kind"];
68
68
  }
69
69
 
70
+ export interface FetchStreamRoute<M extends Msgish> {
71
+ readonly key?: string;
72
+ readonly line: M["kind"];
73
+ readonly ok: M["kind"];
74
+ readonly err: M["kind"];
75
+ }
76
+
70
77
  export interface SpawnRoute<M extends Msgish> {
71
78
  readonly key?: string;
72
79
  readonly stdin?: Uint8Array;
@@ -122,6 +129,36 @@ export interface ChannelRoute<M extends Msgish> {
122
129
  readonly event: M["kind"];
123
130
  }
124
131
 
132
+ export type AudioCaptureSource = "microphone" | "system";
133
+ export type AudioCaptureState = "started" | "data" | "failed" | "stopped" | "rejected";
134
+ export type AudioCaptureSampleRate = 16000 | 24000 | 48000;
135
+ export type AudioCaptureChannels = 1 | 2;
136
+
137
+ export interface AudioCaptureSpec {
138
+ // Inline the event-module alias here: the external-compile stager
139
+ // deliberately deduplicates aliases shared by core.ts and events.ts.
140
+ readonly source: "microphone" | "system";
141
+ readonly sampleRate?: AudioCaptureSampleRate;
142
+ readonly channels?: AudioCaptureChannels;
143
+ }
144
+
145
+ export type AudioCaptureEventArm = {
146
+ readonly key: number;
147
+ readonly state: "started" | "data" | "failed" | "stopped" | "rejected";
148
+ readonly source: "microphone" | "system";
149
+ readonly sampleRate: number;
150
+ readonly channels: number;
151
+ readonly timestampMs: number;
152
+ readonly frames: number;
153
+ readonly pcm: Uint8Array;
154
+ readonly droppedPending: number;
155
+ readonly droppedTotal: number;
156
+ };
157
+
158
+ export interface AudioCaptureRoute<M extends Msgish> {
159
+ readonly event: M["kind"];
160
+ }
161
+
125
162
  export interface PtyRoute<M extends Msgish> {
126
163
  readonly key?: string;
127
164
  readonly cols?: number;
@@ -140,6 +177,10 @@ export interface FetchSpec {
140
177
  readonly timeoutMs?: number;
141
178
  }
142
179
 
180
+ export interface FetchStreamSpec extends FetchSpec {
181
+ readonly maxLineBytes?: number;
182
+ }
183
+
143
184
  export interface NotificationSpec {
144
185
  readonly title: Uint8Array;
145
186
  readonly subtitle?: Uint8Array;
@@ -190,6 +231,19 @@ export type CmdData =
190
231
  readonly headers: readonly { readonly name: string; readonly value: string | Uint8Array }[];
191
232
  readonly body: Uint8Array;
192
233
  }
234
+ | {
235
+ readonly op: "fetch_stream";
236
+ readonly key: string;
237
+ readonly lineKind: string;
238
+ readonly okKind: string;
239
+ readonly errKind: string;
240
+ readonly method: FetchMethod;
241
+ readonly timeoutMs: number;
242
+ readonly maxLineBytes: number;
243
+ readonly url: Uint8Array;
244
+ readonly headers: readonly { readonly name: string; readonly value: string | Uint8Array }[];
245
+ readonly body: Uint8Array;
246
+ }
193
247
  | { readonly op: "clip_write"; readonly bytes: Uint8Array }
194
248
  | { readonly op: "clip_read"; readonly key: string; readonly okKind: string; readonly errKind: string }
195
249
  | { readonly op: "show_notification"; readonly title: Uint8Array; readonly subtitle: Uint8Array; readonly body: Uint8Array }
@@ -251,6 +305,8 @@ export type CmdData =
251
305
  | { readonly op: "image_unregister"; readonly id: number }
252
306
  | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string }
253
307
  | { readonly op: "channel_close"; readonly key: number }
308
+ | { readonly op: "audio_capture_start"; readonly key: number; readonly source: "microphone" | "system"; readonly sampleRate: number; readonly channels: number; readonly eventKind: string }
309
+ | { readonly op: "audio_capture_stop"; readonly key: number }
254
310
  | {
255
311
  readonly op: "pty_spawn";
256
312
  readonly key: string;
@@ -359,12 +415,30 @@ export const Cmd = {
359
415
  return { op: "write_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path, bytes };
360
416
  },
361
417
 
362
- fetch(spec: FetchSpec, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
418
+ fetch(
419
+ spec: FetchStreamSpec,
420
+ route: { readonly key?: string; readonly line?: string; readonly ok: string; readonly err: string },
421
+ ): CmdData {
363
422
  const names = Object.keys(spec.headers ?? {}).sort();
364
423
  const headers: { readonly name: string; readonly value: string | Uint8Array }[] = [];
365
424
  for (const n of names) {
366
425
  headers.push({ name: n, value: spec.headers![n]! });
367
426
  }
427
+ if (route.line !== undefined) {
428
+ return {
429
+ op: "fetch_stream",
430
+ key: route.key ?? "",
431
+ lineKind: route.line,
432
+ okKind: route.ok,
433
+ errKind: route.err,
434
+ method: spec.method ?? "GET",
435
+ timeoutMs: spec.timeoutMs ?? 0,
436
+ maxLineBytes: spec.maxLineBytes ?? 0,
437
+ url: spec.url,
438
+ headers: headers,
439
+ body: spec.body ?? new Uint8Array(0),
440
+ };
441
+ }
368
442
  return {
369
443
  op: "fetch",
370
444
  key: route.key ?? "",
@@ -526,6 +600,21 @@ export const Cmd = {
526
600
  return { op: "channel_close", key };
527
601
  },
528
602
 
603
+ audioCaptureStart(key: number, spec: AudioCaptureSpec, route: { readonly event: string }): CmdData {
604
+ return {
605
+ op: "audio_capture_start",
606
+ key,
607
+ source: spec.source,
608
+ sampleRate: spec.sampleRate ?? 48000,
609
+ channels: spec.channels ?? 1,
610
+ eventKind: route.event,
611
+ };
612
+ },
613
+
614
+ audioCaptureStop(key: number): CmdData {
615
+ return { op: "audio_capture_stop", key };
616
+ },
617
+
529
618
  ptySpawn(argv: readonly Uint8Array[], route: { readonly key?: string; readonly cols?: number; readonly rows?: number; readonly term?: string; readonly event: string }): CmdData {
530
619
  return {
531
620
  op: "pty_spawn",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.8.2",
9
+ "version": "0.8.4",
10
10
  "dependencies": {
11
11
  "scriptc": "0.0.22"
12
12
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its checker and contract frontend, the exact-pinned core compiler dependency, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -58,10 +58,35 @@ export type ChannelEventKind<M extends Msgish> = M extends Msgish ? [Exclude<key
58
58
  export interface ChannelRoute<M extends Msgish> {
59
59
  readonly event: ChannelEventKind<M>;
60
60
  }
61
+ export type AudioCaptureSource = "microphone" | "system";
62
+ export type AudioCaptureState = "started" | "data" | "failed" | "stopped" | "rejected";
63
+ export type AudioCaptureSampleRate = 16000 | 24000 | 48000;
64
+ export type AudioCaptureChannels = 1 | 2;
65
+ export interface AudioCaptureSpec {
66
+ readonly source: AudioCaptureSource;
67
+ readonly sampleRate?: AudioCaptureSampleRate;
68
+ readonly channels?: AudioCaptureChannels;
69
+ }
70
+ export type AudioCaptureEventArm = {
71
+ readonly key: number;
72
+ readonly state: AudioCaptureState;
73
+ readonly source: AudioCaptureSource;
74
+ readonly sampleRate: number;
75
+ readonly channels: number;
76
+ readonly timestampMs: number;
77
+ readonly frames: number;
78
+ readonly pcm: Uint8Array;
79
+ readonly droppedPending: number;
80
+ readonly droppedTotal: number;
81
+ };
82
+ export type AudioCaptureEventKind<M extends Msgish> = M extends Msgish ? [Exclude<keyof M, "kind">] extends [keyof AudioCaptureEventArm] ? [keyof AudioCaptureEventArm] extends [Exclude<keyof M, "kind">] ? M extends Msgish & AudioCaptureEventArm ? [AudioCaptureState] extends [M["state"]] ? [AudioCaptureSource] extends [M["source"]] ? M["kind"] : never : never : never : never : never : never;
83
+ export interface AudioCaptureRoute<M extends Msgish> {
84
+ readonly event: AudioCaptureEventKind<M>;
85
+ }
61
86
  export type PtyState = "output" | "exit";
62
87
  export type PtyExitReason = "exited" | "signaled" | "cancelled" | "rejected" | "spawn_failed";
63
88
  export type PtyEventArm = {
64
- readonly key: string;
89
+ readonly key: Uint8Array;
65
90
  readonly state: PtyState;
66
91
  readonly bytes: Uint8Array;
67
92
  readonly code: number;
@@ -96,6 +121,12 @@ export interface FetchRoute<M extends Msgish> {
96
121
  readonly ok: FetchedKind<M>;
97
122
  readonly err: BytesKind<M>;
98
123
  }
124
+ export interface FetchStreamRoute<M extends Msgish> {
125
+ readonly key?: string;
126
+ readonly line: BytesKind<M>;
127
+ readonly ok: TimestampKind<M>;
128
+ readonly err: BytesKind<M>;
129
+ }
99
130
  export interface SpawnRoute<M extends Msgish> {
100
131
  readonly key?: string;
101
132
  readonly stdin?: Uint8Array;
@@ -149,6 +180,9 @@ export interface FetchSpec {
149
180
  readonly body?: Uint8Array;
150
181
  readonly timeoutMs?: number;
151
182
  }
183
+ export interface FetchStreamSpec extends FetchSpec {
184
+ readonly maxLineBytes?: number;
185
+ }
152
186
  export interface NotificationSpec {
153
187
  readonly title: Uint8Array;
154
188
  readonly subtitle?: Uint8Array;
@@ -205,6 +239,21 @@ export type Cmd<M extends Msgish> = {
205
239
  readonly value: string | Uint8Array;
206
240
  }[];
207
241
  readonly body: Uint8Array;
242
+ } | {
243
+ readonly op: "fetch_stream";
244
+ readonly key: string;
245
+ readonly lineKind: string;
246
+ readonly okKind: string;
247
+ readonly errKind: string;
248
+ readonly method: FetchMethod;
249
+ readonly timeoutMs: number;
250
+ readonly maxLineBytes: number;
251
+ readonly url: Uint8Array;
252
+ readonly headers: readonly {
253
+ readonly name: string;
254
+ readonly value: string | Uint8Array;
255
+ }[];
256
+ readonly body: Uint8Array;
208
257
  } | {
209
258
  readonly op: "clip_write";
210
259
  readonly bytes: Uint8Array;
@@ -286,6 +335,16 @@ export type Cmd<M extends Msgish> = {
286
335
  } | {
287
336
  readonly op: "channel_close";
288
337
  readonly key: number;
338
+ } | {
339
+ readonly op: "audio_capture_start";
340
+ readonly key: number;
341
+ readonly source: AudioCaptureSource;
342
+ readonly sampleRate: number;
343
+ readonly channels: number;
344
+ readonly eventKind: string;
345
+ } | {
346
+ readonly op: "audio_capture_stop";
347
+ readonly key: number;
289
348
  } | {
290
349
  readonly op: "pty_spawn";
291
350
  readonly key: string;
@@ -313,6 +372,8 @@ export type Cmd<M extends Msgish> = {
313
372
  export declare function hostRecordBytes(payload: HostRecord): Uint8Array;
314
373
  declare function hostCmd(name: string, payload: Uint8Array | HostRecord): Cmd<never>;
315
374
  declare function hostCmd(name: string, ...args: readonly number[]): Cmd<never>;
375
+ declare function fetchCmd<M extends Msgish>(spec: FetchSpec, route: FetchRoute<M>): Cmd<M>;
376
+ declare function fetchCmd<M extends Msgish>(spec: FetchStreamSpec, route: FetchStreamRoute<M>): Cmd<M>;
316
377
  export declare const Cmd: {
317
378
  none: Cmd<never>;
318
379
  persist(): Cmd<never>;
@@ -322,7 +383,7 @@ export declare const Cmd: {
322
383
  cancel(key: string): Cmd<never>;
323
384
  readFile<M extends Msgish>(path: Uint8Array, route: RequestRoute<M>): Cmd<M>;
324
385
  writeFile<M extends Msgish>(path: Uint8Array, bytes: Uint8Array, route: WriteRoute<M>): Cmd<M>;
325
- fetch<M extends Msgish>(spec: FetchSpec, route: FetchRoute<M>): Cmd<M>;
386
+ fetch: typeof fetchCmd;
326
387
  clipboardWrite(bytes: Uint8Array): Cmd<never>;
327
388
  clipboardRead<M extends Msgish>(route: RequestRoute<M>): Cmd<M>;
328
389
  showNotification(spec: NotificationSpec): Cmd<never>;
@@ -349,6 +410,8 @@ export declare const Cmd: {
349
410
  imageUnregister(id: number): Cmd<never>;
350
411
  channelOpen<M extends Msgish>(key: number, route: ChannelRoute<M>): Cmd<M>;
351
412
  channelClose(key: number): Cmd<never>;
413
+ audioCaptureStart<M extends Msgish>(key: number, spec: AudioCaptureSpec, route: AudioCaptureRoute<M>): Cmd<M>;
414
+ audioCaptureStop(key: number): Cmd<never>;
352
415
  ptySpawn<M extends Msgish>(argv: readonly Uint8Array[], route: PtyRoute<M>): Cmd<M>;
353
416
  ptyWrite(key: string, bytes: Uint8Array): Cmd<never>;
354
417
  ptyResize(key: string, cols: number, rows: number): Cmd<never>;
@@ -34,10 +34,9 @@
34
34
  // Cmd.cancel(key) drop the in-flight keyed effect — request,
35
35
  // readFile/writeFile/fetch/clipboardRead, or
36
36
  // delay — SILENTLY (no terminal arm dispatch).
37
- // Aimed at a live spawn it stays LOUD: the
38
- // child dies and the err arm runs with
39
- // "cancelled" — killing a process is an
40
- // observable event
37
+ // Aimed at a live spawn or streaming fetch it
38
+ // stays LOUD: the err arm runs with
39
+ // "cancelled" — ending a stream is observable
41
40
  // Cmd.batch([a, b, ...]) several commands from one dispatch
42
41
  //
43
42
  // The named engine ops (each maps onto the host's effect engine directly;
@@ -61,6 +60,13 @@
61
60
  // the reason bytes ("connect_failed",
62
61
  // "tls_failed", "protocol_failed", "timed_out",
63
62
  // "rejected", "truncated")
63
+ // Cmd.fetch({ ..., maxLineBytes? }, { key?, line, ok, err })
64
+ // streaming HTTP(S) exchange; each complete
65
+ // response line dispatches the one-bytes-field
66
+ // `line` arm, then exactly one terminal follows:
67
+ // `ok` with the HTTP status as its one number
68
+ // field, or `err` with the transport reason
69
+ // (or "truncated" if any line was cut/dropped)
64
70
  // Cmd.clipboardWrite(bytes) fire-and-forget clipboard write
65
71
  // Cmd.clipboardRead({ key?, ok, err })
66
72
  // clipboard read; ok arm carries the text bytes,
@@ -232,10 +238,10 @@
232
238
  // The keyed-effect discipline is ONE rule: a keyed effect REPLACES its live
233
239
  // predecessor (the superseded effect's result is dropped — no message), and
234
240
  // Cmd.cancel drops it silently. That holds for request, readFile, writeFile,
235
- // fetch, clipboardRead, and delay alike. The ONE exception is a live spawn
236
- // key: a duplicate REJECTS the new spawn (err arm "rejected") — a running
237
- // subprocess is never killed implicitly; cancel it first. And spawn's cancel
238
- // stays loud (err arm "cancelled"): killing a process is an observable event.
241
+ // buffered fetch, clipboardRead, and delay alike. Live spawn and streaming-
242
+ // fetch keys are the exceptions: a duplicate REJECTS the new stream (err arm
243
+ // "rejected") so results from two sources are never spliced together. Cancel
244
+ // either stream first; its err arm runs with "cancelled".
239
245
  //
240
246
  // `Sub` is the recurring-effects surface: an app may export
241
247
  // `subscriptions(model): Sub<Msg>` returning declarative descriptors the
@@ -559,6 +565,64 @@ export interface ChannelRoute<M extends Msgish> {
559
565
  readonly event: ChannelEventKind<M>;
560
566
  }
561
567
 
568
+ /// The native capture source. "microphone" captures the selected/default
569
+ /// input device; "system" captures the process-independent desktop output
570
+ /// mix (the OS may present a screen/audio consent prompt).
571
+ export type AudioCaptureSource = "microphone" | "system";
572
+
573
+ /// Capture stream states. A successful stream begins with "started", emits
574
+ /// zero or more "data" chunks, and ends with "stopped" after
575
+ /// `Cmd.audioCaptureStop`. "failed" reports a source/permission failure;
576
+ /// stop that stream to retire it. "rejected" means the runtime refused the
577
+ /// start before a native source was opened.
578
+ export type AudioCaptureState = "started" | "data" | "failed" | "stopped" | "rejected";
579
+
580
+ export type AudioCaptureSampleRate = 16000 | 24000 | 48000;
581
+ export type AudioCaptureChannels = 1 | 2;
582
+
583
+ /// Requested canonical output format. Native inputs are converted to
584
+ /// interleaved signed 16-bit little-endian PCM before delivery.
585
+ export interface AudioCaptureSpec {
586
+ readonly source: AudioCaptureSource;
587
+ readonly sampleRate?: AudioCaptureSampleRate;
588
+ readonly channels?: AudioCaptureChannels;
589
+ }
590
+
591
+ /// The payload shape of an audio-capture event arm, matched by field name.
592
+ /// `pcm` is populated only for "data" and is valid for this dispatch; copy
593
+ /// bytes retained by the model. Chunks are at most 20ms. Drop counters make
594
+ /// bounded-queue back-pressure observable rather than silent.
595
+ export type AudioCaptureEventArm = {
596
+ readonly key: number;
597
+ readonly state: AudioCaptureState;
598
+ readonly source: AudioCaptureSource;
599
+ readonly sampleRate: number;
600
+ readonly channels: number;
601
+ readonly timestampMs: number;
602
+ readonly frames: number;
603
+ readonly pcm: Uint8Array;
604
+ readonly droppedPending: number;
605
+ readonly droppedTotal: number;
606
+ };
607
+
608
+ export type AudioCaptureEventKind<M extends Msgish> = M extends Msgish
609
+ ? [Exclude<keyof M, "kind">] extends [keyof AudioCaptureEventArm]
610
+ ? [keyof AudioCaptureEventArm] extends [Exclude<keyof M, "kind">]
611
+ ? M extends Msgish & AudioCaptureEventArm
612
+ ? [AudioCaptureState] extends [M["state"]]
613
+ ? [AudioCaptureSource] extends [M["source"]]
614
+ ? M["kind"]
615
+ : never
616
+ : never
617
+ : never
618
+ : never
619
+ : never
620
+ : never;
621
+
622
+ export interface AudioCaptureRoute<M extends Msgish> {
623
+ readonly event: AudioCaptureEventKind<M>;
624
+ }
625
+
562
626
  /// The pty session event states, mirroring the engine's vocabulary:
563
627
  /// "output" is one coalesced batch of child output; "exit" is the
564
628
  /// exactly-one terminal every session produces — a clean end, a signal,
@@ -575,8 +639,9 @@ export type PtyExitReason = "exited" | "signaled" | "cancelled" | "rejected" | "
575
639
 
576
640
  /// The payload shape of a pty event arm — seven fields, matched by NAME
577
641
  /// (the AudioEventArm convention). `key` is the app's own session key
578
- /// (the `Cmd.ptySpawn` `key`, or "" when the spawn named none) — two
579
- /// sessions routing one event arm are told apart by this field. `state`
642
+ /// as byte text (the `Cmd.ptySpawn` `key`, or empty bytes when the spawn
643
+ /// named none) — two sessions routing one event arm are told apart by
644
+ /// this field. `state`
580
645
  /// must be a named string-literal-union alias carrying exactly the two
581
646
  /// PtyState members and `reason` one carrying exactly the five
582
647
  /// PtyExitReason members (any declaration order — the host matches
@@ -587,7 +652,7 @@ export type PtyExitReason = "exited" | "signaled" | "cancelled" | "rejected" | "
587
652
  /// payloads refused over the session's life — zero means every write
588
653
  /// reached the child, never a silent drop.
589
654
  export type PtyEventArm = {
590
- readonly key: string;
655
+ readonly key: Uint8Array;
591
656
  readonly state: PtyState;
592
657
  readonly bytes: Uint8Array;
593
658
  readonly code: number;
@@ -597,7 +662,7 @@ export type PtyEventArm = {
597
662
  };
598
663
 
599
664
  /// The Msg arms a pty session may target: arms whose payload is exactly
600
- /// the six PtyEventArm fields. The `state` and `reason` checks run BOTH
665
+ /// the seven PtyEventArm fields. The `state` and `reason` checks run BOTH
601
666
  /// directions (the AudioEventKind convention): the `&` constraint holds
602
667
  /// the arm's unions to PtyState/PtyExitReason, and the tuple-wrapped
603
668
  /// reverse checks hold them to the arm's — a narrower union would
@@ -618,7 +683,7 @@ export type PtyEventKind<M extends Msgish> = M extends Msgish
618
683
  : never;
619
684
 
620
685
  /// `Cmd.ptySpawn` routing: every session event dispatches the `event`
621
- /// arm (the six-field PtyEventArm record, matched by field name).
686
+ /// arm (the seven-field PtyEventArm record, matched by field name).
622
687
  /// `cols`/`rows` are the initial grid the child observes (80x24 when
623
688
  /// omitted); `term` is the TERM the child starts with (omitted = the
624
689
  /// engine's default). The optional `key` names the session for
@@ -665,6 +730,18 @@ export interface FetchRoute<M extends Msgish> {
665
730
  readonly err: BytesKind<M>;
666
731
  }
667
732
 
733
+ /// Streaming `Cmd.fetch` routing: each complete response line dispatches the
734
+ /// `line` arm with its bytes; the one successful terminal dispatches `ok` with
735
+ /// the HTTP status. A cut/dropped line dispatches `err` with `"truncated"` at
736
+ /// the terminal; transport failure and cancellation dispatch `err` with their
737
+ /// machine-readable reason bytes.
738
+ export interface FetchStreamRoute<M extends Msgish> {
739
+ readonly key?: string;
740
+ readonly line: BytesKind<M>;
741
+ readonly ok: TimestampKind<M>;
742
+ readonly err: BytesKind<M>;
743
+ }
744
+
668
745
  /// `Cmd.spawn` routing, line mode: each stdout line dispatches the optional
669
746
  /// `line` arm (one bytes field; omitted = lines dropped), a clean exit the
670
747
  /// `exit` arm (one number field — the exit code), every other end the `err`
@@ -767,6 +844,15 @@ export interface FetchSpec {
767
844
  readonly timeoutMs?: number;
768
845
  }
769
846
 
847
+ /// A line-streamed fetch request. `maxLineBytes` overrides the engine's 4 KiB
848
+ /// per-line default for SSE/NDJSON protocols whose individual records are
849
+ /// larger; it is bounded by the engine's 256 KiB per-line ceiling. If a line
850
+ /// is cut or dropped, the stream still ends through `err: "truncated"` rather
851
+ /// than reporting a successful terminal.
852
+ export interface FetchStreamSpec extends FetchSpec {
853
+ readonly maxLineBytes?: number;
854
+ }
855
+
770
856
  /// A desktop notification request. Text is bytes so every field may come
771
857
  /// directly from model data; subtitle and body default to empty. Delivery is
772
858
  /// fire-and-forget because the OS may suppress an accepted request through
@@ -826,6 +912,19 @@ export type Cmd<M extends Msgish> =
826
912
  readonly headers: readonly { readonly name: string; readonly value: string | Uint8Array }[];
827
913
  readonly body: Uint8Array;
828
914
  }
915
+ | {
916
+ readonly op: "fetch_stream";
917
+ readonly key: string;
918
+ readonly lineKind: string;
919
+ readonly okKind: string;
920
+ readonly errKind: string;
921
+ readonly method: FetchMethod;
922
+ readonly timeoutMs: number;
923
+ readonly maxLineBytes: number;
924
+ readonly url: Uint8Array;
925
+ readonly headers: readonly { readonly name: string; readonly value: string | Uint8Array }[];
926
+ readonly body: Uint8Array;
927
+ }
829
928
  | { readonly op: "clip_write"; readonly bytes: Uint8Array }
830
929
  | { readonly op: "clip_read"; readonly key: string; readonly okKind: string; readonly errKind: string }
831
930
  | { readonly op: "show_notification"; readonly title: Uint8Array; readonly subtitle: Uint8Array; readonly body: Uint8Array }
@@ -892,6 +991,15 @@ export type Cmd<M extends Msgish> =
892
991
  | { readonly op: "image_unregister"; readonly id: number }
893
992
  | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string }
894
993
  | { readonly op: "channel_close"; readonly key: number }
994
+ | {
995
+ readonly op: "audio_capture_start";
996
+ readonly key: number;
997
+ readonly source: AudioCaptureSource;
998
+ readonly sampleRate: number;
999
+ readonly channels: number;
1000
+ readonly eventKind: string;
1001
+ }
1002
+ | { readonly op: "audio_capture_stop"; readonly key: number }
895
1003
  | {
896
1004
  readonly op: "pty_spawn";
897
1005
  readonly key: string;
@@ -959,6 +1067,48 @@ function hostCmd(name: string, ...rest: readonly (number | Uint8Array | HostReco
959
1067
  return { op: "host", name, args: rest as readonly number[] };
960
1068
  }
961
1069
 
1070
+ /// HTTP(S) as effect data. The two-field `{ ok, err }` route buffers the whole
1071
+ /// response. Adding `line` selects line streaming: each complete line arrives
1072
+ /// through that one-bytes-field arm, then `ok` receives the terminal HTTP
1073
+ /// status as its one number payload. A non-2xx status is still `ok` because the
1074
+ /// server delivered a response; cut/dropped stream lines, transport failures,
1075
+ /// and cancellation use `err` (`"truncated"` for stream data loss).
1076
+ function fetchCmd<M extends Msgish>(spec: FetchSpec, route: FetchRoute<M>): Cmd<M>;
1077
+ function fetchCmd<M extends Msgish>(spec: FetchStreamSpec, route: FetchStreamRoute<M>): Cmd<M>;
1078
+ function fetchCmd<M extends Msgish>(
1079
+ spec: FetchStreamSpec,
1080
+ route: FetchRoute<M> | FetchStreamRoute<M>,
1081
+ ): Cmd<M> {
1082
+ const names = Object.keys(spec.headers ?? {}).sort();
1083
+ const headers = names.map((n) => ({ name: n, value: spec.headers![n] }));
1084
+ if ("line" in route) {
1085
+ return {
1086
+ op: "fetch_stream",
1087
+ key: route.key ?? "",
1088
+ lineKind: route.line,
1089
+ okKind: route.ok,
1090
+ errKind: route.err,
1091
+ method: spec.method ?? "GET",
1092
+ timeoutMs: spec.timeoutMs ?? 0,
1093
+ maxLineBytes: spec.maxLineBytes ?? 0,
1094
+ url: spec.url,
1095
+ headers,
1096
+ body: spec.body ?? new Uint8Array(0),
1097
+ };
1098
+ }
1099
+ return {
1100
+ op: "fetch",
1101
+ key: route.key ?? "",
1102
+ okKind: route.ok,
1103
+ errKind: route.err,
1104
+ method: spec.method ?? "GET",
1105
+ timeoutMs: spec.timeoutMs ?? 0,
1106
+ url: spec.url,
1107
+ headers,
1108
+ body: spec.body ?? new Uint8Array(0),
1109
+ };
1110
+ }
1111
+
962
1112
  export const Cmd = {
963
1113
  /// No effects. `return model` is sugar for `return [model, Cmd.none]`.
964
1114
  none: { op: "none" } as Cmd<never>,
@@ -999,8 +1149,8 @@ export const Cmd = {
999
1149
 
1000
1150
  /// Drop the in-flight keyed effect — request, named engine op, or delay —
1001
1151
  /// with this key, if any, SILENTLY (neither routing arm is dispatched for
1002
- /// it). The exception is a live spawn: cancel ends the child and its err
1003
- /// arm runs with "cancelled" — killing a process is an observable event.
1152
+ /// it). Live spawn and streaming-fetch operations are the exceptions:
1153
+ /// cancel ends the stream and its err arm runs with "cancelled".
1004
1154
  cancel(key: string): Cmd<never> {
1005
1155
  return { op: "cancel", key };
1006
1156
  },
@@ -1019,24 +1169,7 @@ export const Cmd = {
1019
1169
  return { op: "write_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path, bytes };
1020
1170
  },
1021
1171
 
1022
- /// A buffered HTTP(S) exchange. Exactly one terminal Msg: the `ok` arm
1023
- /// with `{ status, body }` (one number field, one bytes field — a non-2xx
1024
- /// status is still ok: an HTTP-level error is a delivered response), or
1025
- /// the `err` arm with the reason bytes.
1026
- fetch<M extends Msgish>(spec: FetchSpec, route: FetchRoute<M>): Cmd<M> {
1027
- const names = Object.keys(spec.headers ?? {}).sort();
1028
- return {
1029
- op: "fetch",
1030
- key: route.key ?? "",
1031
- okKind: route.ok,
1032
- errKind: route.err,
1033
- method: spec.method ?? "GET",
1034
- timeoutMs: spec.timeoutMs ?? 0,
1035
- url: spec.url,
1036
- headers: names.map((n) => ({ name: n, value: spec.headers![n] })),
1037
- body: spec.body ?? new Uint8Array(0),
1038
- };
1039
- },
1172
+ fetch: fetchCmd,
1040
1173
 
1041
1174
  /// Put bytes on the system clipboard, fire-and-forget (an over-bound or
1042
1175
  /// refused write is dropped — there is no route to report on).
@@ -1336,6 +1469,29 @@ export const Cmd = {
1336
1469
  return { op: "channel_close", key };
1337
1470
  },
1338
1471
 
1472
+ /// Start microphone or system-output capture under a positive numeric
1473
+ /// `key`. The stream is normalized to interleaved signed 16-bit LE PCM
1474
+ /// at the requested rate/channels (48kHz mono by default). Microphone and
1475
+ /// system capture may run concurrently; only one stream per source may
1476
+ /// be live. The event stream is bounded and journal/replay aware.
1477
+ audioCaptureStart<M extends Msgish>(key: number, spec: AudioCaptureSpec, route: AudioCaptureRoute<M>): Cmd<M> {
1478
+ return {
1479
+ op: "audio_capture_start",
1480
+ key,
1481
+ source: spec.source,
1482
+ sampleRate: spec.sampleRate ?? 48000,
1483
+ channels: spec.channels ?? 1,
1484
+ eventKind: route.event,
1485
+ };
1486
+ },
1487
+
1488
+ /// Stop capture under `key`. Native callbacks quiesce synchronously,
1489
+ /// accepted backlog drains, then exactly one "stopped" event retires the
1490
+ /// stream. A key with no live capture is a no-op.
1491
+ audioCaptureStop(key: number): Cmd<never> {
1492
+ return { op: "audio_capture_stop", key };
1493
+ },
1494
+
1339
1495
  /// Open a pseudo-terminal session — a spawn with a different
1340
1496
  /// transport: run `argv` on a fresh pty (same argv budgets, same
1341
1497
  /// child environment policy) whose initial grid is `cols` x `rows`