@bun-native/runtime 0.33.1 → 0.33.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  Bun Native host process lifecycle and bridge runtime.
4
4
 
5
- Part of [Bun Native](https://github.com/0xPlayerOne/bun-native), an experimental developer preview. Version 0.33.1 was built from [c56fdd675365](https://github.com/0xPlayerOne/bun-native/tree/c56fdd6753653a10144a4167c1d3dfb3c38a0647) and published from GitHub Actions with npm provenance. Use the Bun revision pinned in that commit's toolchain.json. Start with the [getting-started guide](https://github.com/0xPlayerOne/bun-native/blob/c56fdd6753653a10144a4167c1d3dfb3c38a0647/docs/getting-started.md); `bun-native host install` fetches the matching release host. The license notice is in LICENSE.
5
+ Part of [Bun Native](https://github.com/0xPlayerOne/bun-native), an experimental developer preview. Version 0.33.2 was built from [577f6fc5015b](https://github.com/0xPlayerOne/bun-native/tree/577f6fc5015b6eeef956efcc63f97e2a749d74ff) and published from GitHub Actions with npm provenance. Use the Bun revision pinned in that commit's toolchain.json. Start with the [getting-started guide](https://github.com/0xPlayerOne/bun-native/blob/577f6fc5015b6eeef956efcc63f97e2a749d74ff/docs/getting-started.md); `bun-native host install` fetches the matching release host. The license notice is in LICENSE.
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "commit": "c56fdd6753653a10144a4167c1d3dfb3c38a0647",
4
- "tree": "c6e81b3f9d041e11dd0413b5fdd7a50910383854",
3
+ "commit": "577f6fc5015b6eeef956efcc63f97e2a749d74ff",
4
+ "tree": "c599e781af2ce0749d5e3a6d8700834690e872f4",
5
5
  "files": {
6
6
  "package.json": {
7
- "bytes": 2115,
8
- "sha256": "caf866d56f3cd7530d5735ecbf62512e9e22526bc44c75a4b48a18c26352c0b8"
7
+ "bytes": 2258,
8
+ "sha256": "38e2f0f89b5f6c4ba80b3baefcdf0806dd73c684294153df74ab470fda6bf3f9"
9
9
  },
10
10
  "packages/runtime/package.json": {
11
11
  "bytes": 195,
@@ -16,8 +16,8 @@
16
16
  "sha256": "0c93ad077ad4cfcdf32a8092da1aff6cdc0f65322feadf538768439d67b11e06"
17
17
  },
18
18
  "packages/runtime/src/index.ts": {
19
- "bytes": 39579,
20
- "sha256": "a5f20057a2baa2117176a59c29e65438904f3758bfed3e29e981b55758e93adb"
19
+ "bytes": 32606,
20
+ "sha256": "7f13b852fcc6e66d6b2c96374da757af8a97aea7f4710cd098363fd0ad1ef435"
21
21
  },
22
22
  "packages/runtime/src/installation.ts": {
23
23
  "bytes": 1871,
@@ -37,7 +37,7 @@
37
37
  "sha256": "9f4d9362cb4cc38c0f4e705295789a0cbfec46ffdd007e0541b9441a7c3003a7"
38
38
  },
39
39
  "dependencyLock": {
40
- "bytes": 28357,
41
- "sha256": "65e3dbd01be4a1889367690faf1a9c3f08fb31d22dbd273d9bb9f39dd6baa6fb"
40
+ "bytes": 28430,
41
+ "sha256": "9d321f65b9224958ec99286628d652232a16e3242ea9536a396bceaf72892460"
42
42
  }
43
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bun-native/runtime",
3
- "version": "0.33.1",
3
+ "version": "0.33.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -15,7 +15,7 @@
15
15
  "exports": "./src/index.ts",
16
16
  "description": "Bun Native host process lifecycle and bridge runtime.",
17
17
  "dependencies": {
18
- "@bun-native/protocol": "0.33.1"
18
+ "@bun-native/protocol": "0.33.2"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  REQUIRED_CAPABILITIES,
14
14
  ProtocolError,
15
15
  type Command,
16
+ type OperationList,
16
17
  type NativeEvent,
17
18
  type ErrorCode,
18
19
  type Limits,
@@ -35,77 +36,79 @@ export {
35
36
  export { installedRelease, reportHealthy, type InstalledRelease } from './installation.ts'
36
37
  export type { ApplicationEvent, HostEvent, WindowEvent } from '@bun-native/protocol'
37
38
 
38
- type WithoutId<T> = T extends { id: number } ? Omit<T, 'id'> : never
39
- export type WindowCommand = WithoutId<
40
- Extract<
41
- Command,
42
- {
43
- type:
44
- | 'open'
45
- | 'batch'
46
- | 'close'
47
- | 'display_snapshot'
48
- | 'clipboard_read'
49
- | 'clipboard_write'
50
- | 'register_global_shortcut'
51
- | 'unregister_global_shortcut'
52
- | 'post_notification'
53
- | 'withdraw_notification'
54
- | 'open_file_grant'
55
- | 'close_file_grant'
56
- | 'file_request'
57
- | 'spawn_process'
58
- | 'write_process'
59
- | 'close_process_input'
60
- | 'resize_process'
61
- | 'signal_process'
62
- | 'acknowledge_process_output'
63
- | 'release_process'
64
- | 'show_file_dialog'
65
- | 'close_file_dialog'
66
- | 'show_message_dialog'
67
- | 'close_message_dialog'
68
- | 'show_context_menu'
69
- | 'close_context_menu'
70
- | 'register_drop_target'
71
- | 'unregister_drop_target'
72
- | 'resolve_dropped_item'
73
- | 'set_app_menu'
74
- }
75
- >
76
- >
77
- export type HostResponse = Extract<
78
- NativeEvent,
79
- {
80
- type:
81
- | 'ack'
82
- | 'opened'
83
- | 'applied'
84
- | 'display_snapshot'
85
- | 'clipboard_text'
86
- | 'clipboard_written'
87
- | 'global_shortcut_registered'
88
- | 'global_shortcut_unregistered'
89
- | 'notification_posted'
90
- | 'notification_withdrawn'
91
- | 'file_grant_opened'
92
- | 'file_grant_closed'
93
- | 'file_result'
94
- | 'process_spawned'
95
- | 'process_updated'
96
- | 'process_released'
97
- | 'file_dialog_opened'
98
- | 'file_dialog_closed'
99
- | 'message_dialog_opened'
100
- | 'message_dialog_closed'
101
- | 'context_menu_opened'
102
- | 'context_menu_closed'
103
- | 'drop_target_registered'
104
- | 'drop_target_unregistered'
105
- | 'dropped_item_resolved'
106
- | 'app_menu_set'
39
+ /** A command as callers submit it; a batch may carry core's checked `OperationList`. */
40
+ type WithoutId<T> = T extends { id: number }
41
+ ? T extends { type: 'batch'; operations: infer O }
42
+ ? Omit<T, 'id' | 'operations'> & { operations: O | OperationList }
43
+ : Omit<T, 'id'>
44
+ : never
45
+ export type WindowCommand = WithoutId<Exclude<Command, { type: 'hello' | 'shutdown' }>>
46
+
47
+ type Field<C extends Command['type']> = Exclude<keyof Extract<Command, { type: C }>, 'type' | 'id'>
48
+
49
+ /**
50
+ * Each command's one response type and the request fields the response must echo. `open`,
51
+ * `batch` and `file_request` also check the revision or result they answer (`matchesResponse`).
52
+ */
53
+ const RESPONSES = {
54
+ hello: { type: 'ack', echoes: [] },
55
+ shutdown: { type: 'ack', echoes: [] },
56
+ open: { type: 'opened', echoes: ['window_id', 'root_id'] },
57
+ batch: { type: 'applied', echoes: ['window_id'] },
58
+ close: { type: 'ack', echoes: [] },
59
+ display_snapshot: { type: 'display_snapshot', echoes: ['window_id'] },
60
+ clipboard_read: { type: 'clipboard_text', echoes: ['window_id'] },
61
+ clipboard_write: { type: 'clipboard_written', echoes: ['window_id'] },
62
+ register_global_shortcut: {
63
+ type: 'global_shortcut_registered',
64
+ echoes: ['window_id', 'shortcut_id'],
65
+ },
66
+ unregister_global_shortcut: {
67
+ type: 'global_shortcut_unregistered',
68
+ echoes: ['window_id', 'shortcut_id'],
69
+ },
70
+ post_notification: { type: 'notification_posted', echoes: ['window_id', 'notification_id'] },
71
+ withdraw_notification: {
72
+ type: 'notification_withdrawn',
73
+ echoes: ['window_id', 'notification_id'],
74
+ },
75
+ open_file_grant: { type: 'file_grant_opened', echoes: ['window_id', 'grant_id'] },
76
+ close_file_grant: { type: 'file_grant_closed', echoes: ['window_id', 'grant_id'] },
77
+ file_request: { type: 'file_result', echoes: ['window_id', 'grant_id'] },
78
+ spawn_process: { type: 'process_spawned', echoes: ['window_id', 'process_id'] },
79
+ write_process: { type: 'process_updated', echoes: ['window_id', 'process_id'] },
80
+ close_process_input: { type: 'process_updated', echoes: ['window_id', 'process_id'] },
81
+ resize_process: { type: 'process_updated', echoes: ['window_id', 'process_id'] },
82
+ signal_process: { type: 'process_updated', echoes: ['window_id', 'process_id'] },
83
+ acknowledge_process_output: { type: 'process_updated', echoes: ['window_id', 'process_id'] },
84
+ release_process: { type: 'process_released', echoes: ['window_id', 'process_id'] },
85
+ show_file_dialog: { type: 'file_dialog_opened', echoes: ['window_id', 'dialog_id'] },
86
+ close_file_dialog: { type: 'file_dialog_closed', echoes: ['window_id', 'dialog_id'] },
87
+ show_message_dialog: { type: 'message_dialog_opened', echoes: ['window_id', 'dialog_id'] },
88
+ close_message_dialog: { type: 'message_dialog_closed', echoes: ['window_id', 'dialog_id'] },
89
+ show_context_menu: { type: 'context_menu_opened', echoes: ['window_id', 'menu_id'] },
90
+ close_context_menu: { type: 'context_menu_closed', echoes: ['window_id', 'menu_id'] },
91
+ register_drop_target: { type: 'drop_target_registered', echoes: ['window_id', 'target_id'] },
92
+ unregister_drop_target: {
93
+ type: 'drop_target_unregistered',
94
+ echoes: ['window_id', 'target_id'],
95
+ },
96
+ resolve_dropped_item: {
97
+ type: 'dropped_item_resolved',
98
+ echoes: ['window_id', 'target_id', 'drop_id', 'item', 'root'],
99
+ },
100
+ set_app_menu: { type: 'app_menu_set', echoes: ['menu_id'] },
101
+ } as const satisfies {
102
+ [C in Command['type']]: {
103
+ type: NativeEvent['type']
104
+ echoes: readonly Field<C>[]
107
105
  }
108
- >
106
+ }
107
+ type ResponseType<C extends Command['type']> = (typeof RESPONSES)[C]['type']
108
+ export type HostResponse = Extract<NativeEvent, { type: ResponseType<Command['type']> }>
109
+ const RESPONSE_TYPES: ReadonlySet<string> = new Set(
110
+ Object.values(RESPONSES).map((response) => response.type)
111
+ )
109
112
 
110
113
  export interface ProcessLimitPermissions {
111
114
  /** CPU seconds before the child is stopped (SIGXCPU on POSIX). */
@@ -307,6 +310,10 @@ function samePolicy(left: Readonly<ServicePolicy>, right: Readonly<ServicePolicy
307
310
  )
308
311
  }
309
312
 
313
+ function isResponse(event: NativeEvent): event is HostResponse {
314
+ return RESPONSE_TYPES.has(event.type)
315
+ }
316
+
310
317
  type Pending = {
311
318
  command: Command
312
319
  resolve: (response: HostResponse) => void
@@ -391,6 +398,10 @@ export class NativeHost implements AsyncIterable<HostEvent> {
391
398
  stdin: 'pipe',
392
399
  stdout: 'pipe',
393
400
  stderr: 'pipe',
401
+ // The host inherits the environment as this process holds it now. The
402
+ // pinned Bun otherwise passes the environment it started with, without
403
+ // later `process.env` changes (such as an opt-in host trace).
404
+ env: { ...process.env },
394
405
  // A terminal's Ctrl-C signals its whole foreground process group. The
395
406
  // application owns the host's lifetime and ends it through `shutdown`
396
407
  // (or closed stdin), so the host runs in its own session on POSIX.
@@ -452,95 +463,9 @@ export class NativeHost implements AsyncIterable<HostEvent> {
452
463
  }
453
464
 
454
465
  /** Resolves after the native UI thread acknowledges the operation. */
455
- send(
456
- command: Extract<WindowCommand, { type: 'open' }>
457
- ): Promise<Extract<HostResponse, { type: 'opened' }>>
458
- send(
459
- command: Extract<WindowCommand, { type: 'batch' }>
460
- ): Promise<Extract<HostResponse, { type: 'applied' }>>
461
- send(
462
- command: Extract<WindowCommand, { type: 'close' }>
463
- ): Promise<Extract<HostResponse, { type: 'ack' }>>
464
- send(
465
- command: Extract<WindowCommand, { type: 'display_snapshot' }>
466
- ): Promise<Extract<HostResponse, { type: 'display_snapshot' }>>
467
- send(
468
- command: Extract<WindowCommand, { type: 'clipboard_read' }>
469
- ): Promise<Extract<HostResponse, { type: 'clipboard_text' }>>
470
- send(
471
- command: Extract<WindowCommand, { type: 'clipboard_write' }>
472
- ): Promise<Extract<HostResponse, { type: 'clipboard_written' }>>
473
- send(
474
- command: Extract<WindowCommand, { type: 'register_global_shortcut' }>
475
- ): Promise<Extract<HostResponse, { type: 'global_shortcut_registered' }>>
476
- send(
477
- command: Extract<WindowCommand, { type: 'unregister_global_shortcut' }>
478
- ): Promise<Extract<HostResponse, { type: 'global_shortcut_unregistered' }>>
479
- send(
480
- command: Extract<WindowCommand, { type: 'post_notification' }>
481
- ): Promise<Extract<HostResponse, { type: 'notification_posted' }>>
482
- send(
483
- command: Extract<WindowCommand, { type: 'withdraw_notification' }>
484
- ): Promise<Extract<HostResponse, { type: 'notification_withdrawn' }>>
485
- send(
486
- command: Extract<WindowCommand, { type: 'open_file_grant' }>
487
- ): Promise<Extract<HostResponse, { type: 'file_grant_opened' }>>
488
- send(
489
- command: Extract<WindowCommand, { type: 'close_file_grant' }>
490
- ): Promise<Extract<HostResponse, { type: 'file_grant_closed' }>>
491
- send(
492
- command: Extract<WindowCommand, { type: 'file_request' }>
493
- ): Promise<Extract<HostResponse, { type: 'file_result' }>>
494
- send(
495
- command: Extract<WindowCommand, { type: 'spawn_process' }>
496
- ): Promise<Extract<HostResponse, { type: 'process_spawned' }>>
497
- send(
498
- command: Extract<WindowCommand, { type: 'release_process' }>
499
- ): Promise<Extract<HostResponse, { type: 'process_released' }>>
500
- send(
501
- command: Extract<
502
- WindowCommand,
503
- {
504
- type:
505
- | 'write_process'
506
- | 'close_process_input'
507
- | 'resize_process'
508
- | 'signal_process'
509
- | 'acknowledge_process_output'
510
- }
511
- >
512
- ): Promise<Extract<HostResponse, { type: 'process_updated' }>>
513
- send(
514
- command: Extract<WindowCommand, { type: 'show_file_dialog' }>
515
- ): Promise<Extract<HostResponse, { type: 'file_dialog_opened' }>>
516
- send(
517
- command: Extract<WindowCommand, { type: 'close_file_dialog' }>
518
- ): Promise<Extract<HostResponse, { type: 'file_dialog_closed' }>>
519
- send(
520
- command: Extract<WindowCommand, { type: 'show_message_dialog' }>
521
- ): Promise<Extract<HostResponse, { type: 'message_dialog_opened' }>>
522
- send(
523
- command: Extract<WindowCommand, { type: 'close_message_dialog' }>
524
- ): Promise<Extract<HostResponse, { type: 'message_dialog_closed' }>>
525
- send(
526
- command: Extract<WindowCommand, { type: 'show_context_menu' }>
527
- ): Promise<Extract<HostResponse, { type: 'context_menu_opened' }>>
528
- send(
529
- command: Extract<WindowCommand, { type: 'close_context_menu' }>
530
- ): Promise<Extract<HostResponse, { type: 'context_menu_closed' }>>
531
- send(
532
- command: Extract<WindowCommand, { type: 'register_drop_target' }>
533
- ): Promise<Extract<HostResponse, { type: 'drop_target_registered' }>>
534
- send(
535
- command: Extract<WindowCommand, { type: 'unregister_drop_target' }>
536
- ): Promise<Extract<HostResponse, { type: 'drop_target_unregistered' }>>
537
- send(
538
- command: Extract<WindowCommand, { type: 'resolve_dropped_item' }>
539
- ): Promise<Extract<HostResponse, { type: 'dropped_item_resolved' }>>
540
- send(
541
- command: Extract<WindowCommand, { type: 'set_app_menu' }>
542
- ): Promise<Extract<HostResponse, { type: 'app_menu_set' }>>
543
- send(command: WindowCommand): Promise<HostResponse>
466
+ send<C extends WindowCommand>(
467
+ command: C
468
+ ): Promise<Extract<HostResponse, { type: ResponseType<C['type']> }>>
544
469
  send(command: WindowCommand): Promise<HostResponse> {
545
470
  if (this.phase !== 'running') return Promise.reject(this.closedError())
546
471
  return this.request(command)
@@ -839,35 +764,7 @@ export class NativeHost implements AsyncIterable<HostEvent> {
839
764
  this.ready = true
840
765
  return
841
766
  }
842
- if (
843
- event.type === 'ack' ||
844
- event.type === 'opened' ||
845
- event.type === 'applied' ||
846
- event.type === 'display_snapshot' ||
847
- event.type === 'clipboard_text' ||
848
- event.type === 'clipboard_written' ||
849
- event.type === 'global_shortcut_registered' ||
850
- event.type === 'global_shortcut_unregistered' ||
851
- event.type === 'notification_posted' ||
852
- event.type === 'notification_withdrawn' ||
853
- event.type === 'file_grant_opened' ||
854
- event.type === 'file_grant_closed' ||
855
- event.type === 'file_result' ||
856
- event.type === 'process_spawned' ||
857
- event.type === 'process_updated' ||
858
- event.type === 'process_released' ||
859
- event.type === 'file_dialog_opened' ||
860
- event.type === 'file_dialog_closed' ||
861
- event.type === 'message_dialog_opened' ||
862
- event.type === 'message_dialog_closed' ||
863
- event.type === 'context_menu_opened' ||
864
- event.type === 'context_menu_closed' ||
865
- event.type === 'drop_target_registered' ||
866
- event.type === 'drop_target_unregistered' ||
867
- event.type === 'dropped_item_resolved' ||
868
- event.type === 'app_menu_set' ||
869
- event.type === 'error'
870
- ) {
767
+ if (event.type === 'error' || isResponse(event)) {
871
768
  if (event.type === 'error' && event.id === undefined)
872
769
  throw new ProtocolError(`Native ${event.code}: ${event.message}`)
873
770
  const requestId = event.id
@@ -899,142 +796,17 @@ export class NativeHost implements AsyncIterable<HostEvent> {
899
796
  }
900
797
 
901
798
  private matchesResponse(command: Command, response: HostResponse): boolean {
902
- switch (command.type) {
903
- case 'display_snapshot':
904
- return response.type === 'display_snapshot' && response.window_id === command.window_id
905
- case 'clipboard_read':
906
- return response.type === 'clipboard_text' && response.window_id === command.window_id
907
- case 'clipboard_write':
908
- return response.type === 'clipboard_written' && response.window_id === command.window_id
909
- case 'register_global_shortcut':
910
- return (
911
- response.type === 'global_shortcut_registered' &&
912
- response.window_id === command.window_id &&
913
- response.shortcut_id === command.shortcut_id
914
- )
915
- case 'unregister_global_shortcut':
916
- return (
917
- response.type === 'global_shortcut_unregistered' &&
918
- response.window_id === command.window_id &&
919
- response.shortcut_id === command.shortcut_id
920
- )
921
- case 'post_notification':
922
- return (
923
- response.type === 'notification_posted' &&
924
- response.window_id === command.window_id &&
925
- response.notification_id === command.notification_id
926
- )
927
- case 'withdraw_notification':
928
- return (
929
- response.type === 'notification_withdrawn' &&
930
- response.window_id === command.window_id &&
931
- response.notification_id === command.notification_id
932
- )
933
- case 'open_file_grant':
934
- case 'close_file_grant':
935
- return (
936
- response.type ===
937
- (command.type === 'open_file_grant' ? 'file_grant_opened' : 'file_grant_closed') &&
938
- response.window_id === command.window_id &&
939
- response.grant_id === command.grant_id
940
- )
941
- case 'file_request':
942
- return (
943
- response.type === 'file_result' &&
944
- response.window_id === command.window_id &&
945
- response.grant_id === command.grant_id &&
946
- fileResultAnswers(command.operation, response.result)
947
- )
948
- case 'spawn_process':
949
- case 'write_process':
950
- case 'close_process_input':
951
- case 'resize_process':
952
- case 'signal_process':
953
- case 'acknowledge_process_output':
954
- case 'release_process':
955
- return (
956
- response.type ===
957
- (command.type === 'spawn_process'
958
- ? 'process_spawned'
959
- : command.type === 'release_process'
960
- ? 'process_released'
961
- : 'process_updated') &&
962
- response.window_id === command.window_id &&
963
- response.process_id === command.process_id
964
- )
965
- case 'show_file_dialog':
966
- return (
967
- response.type === 'file_dialog_opened' &&
968
- response.window_id === command.window_id &&
969
- response.dialog_id === command.dialog_id
970
- )
971
- case 'close_file_dialog':
972
- return (
973
- response.type === 'file_dialog_closed' &&
974
- response.window_id === command.window_id &&
975
- response.dialog_id === command.dialog_id
976
- )
977
- case 'show_message_dialog':
978
- return (
979
- response.type === 'message_dialog_opened' &&
980
- response.window_id === command.window_id &&
981
- response.dialog_id === command.dialog_id
982
- )
983
- case 'close_message_dialog':
984
- return (
985
- response.type === 'message_dialog_closed' &&
986
- response.window_id === command.window_id &&
987
- response.dialog_id === command.dialog_id
988
- )
989
- case 'show_context_menu':
990
- case 'close_context_menu':
991
- return (
992
- response.type ===
993
- (command.type === 'show_context_menu'
994
- ? 'context_menu_opened'
995
- : 'context_menu_closed') &&
996
- response.window_id === command.window_id &&
997
- response.menu_id === command.menu_id
998
- )
999
- case 'register_drop_target':
1000
- case 'unregister_drop_target':
1001
- return (
1002
- response.type ===
1003
- (command.type === 'register_drop_target'
1004
- ? 'drop_target_registered'
1005
- : 'drop_target_unregistered') &&
1006
- response.window_id === command.window_id &&
1007
- response.target_id === command.target_id
1008
- )
1009
- case 'resolve_dropped_item':
1010
- return (
1011
- response.type === 'dropped_item_resolved' &&
1012
- response.window_id === command.window_id &&
1013
- response.target_id === command.target_id &&
1014
- response.drop_id === command.drop_id &&
1015
- response.item === command.item &&
1016
- response.root === command.root
1017
- )
1018
- case 'set_app_menu':
1019
- return response.type === 'app_menu_set' && response.menu_id === command.menu_id
1020
- case 'open':
1021
- return (
1022
- response.type === 'opened' &&
1023
- response.window_id === command.window_id &&
1024
- response.root_id === command.root_id &&
1025
- response.tree_revision === 0
1026
- )
1027
- case 'batch':
1028
- return (
1029
- response.type === 'applied' &&
1030
- response.window_id === command.window_id &&
1031
- response.tree_revision === command.base_revision + 1
1032
- )
1033
- case 'hello':
1034
- case 'close':
1035
- case 'shutdown':
1036
- return response.type === 'ack'
1037
- }
799
+ const expected = RESPONSES[command.type]
800
+ if (response.type !== expected.type) return false
801
+ const request = command as unknown as Readonly<Record<string, unknown>>
802
+ const answer = response as unknown as Readonly<Record<string, unknown>>
803
+ if (!expected.echoes.every((field: string) => answer[field] === request[field])) return false
804
+ if (command.type === 'open' && response.type === 'opened') return response.tree_revision === 0
805
+ if (command.type === 'batch' && response.type === 'applied')
806
+ return response.tree_revision === command.base_revision + 1
807
+ if (command.type === 'file_request' && response.type === 'file_result')
808
+ return fileResultAnswers(command.operation, response.result)
809
+ return true
1038
810
  }
1039
811
 
1040
812
  private closedError(): Error {