@legendapp/spark 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/native.d.cts +6 -3
  2. package/package.json +36 -28
  3. package/patches/react-native-enriched-markdown@1.1.1.patch +141 -10
  4. package/skills/spark/UPGRADING.md +88 -3
  5. package/vendor/node_modules/@legendapp/spark-ai/package.json +5 -5
  6. package/vendor/node_modules/@legendapp/spark-audio/package.json +5 -5
  7. package/vendor/node_modules/@legendapp/spark-audio/src/index.macos.ts +1 -0
  8. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +6 -6
  9. package/vendor/node_modules/@legendapp/spark-auth-session/src/index.macos.ts +1 -0
  10. package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +2 -2
  11. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +11 -2
  12. package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +4 -2
  13. package/vendor/node_modules/@legendapp/spark-cli/dist/create.js +8 -4
  14. package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +45 -1
  15. package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +8 -1
  16. package/vendor/node_modules/@legendapp/spark-cli/dist/examples.js +2 -2
  17. package/vendor/node_modules/@legendapp/spark-cli/dist/expo-dev-patch.cjs +3 -3
  18. package/vendor/node_modules/@legendapp/spark-cli/dist/expo-dev-preload.cjs +3 -0
  19. package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +26 -7
  20. package/vendor/node_modules/@legendapp/spark-cli/dist/metro.cjs +3 -1
  21. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +20 -5
  22. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +1 -0
  23. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +7 -2
  24. package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +3 -3
  25. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +16 -10
  26. package/vendor/node_modules/@legendapp/spark-cli/dist/release-runner-root.js +108 -0
  27. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +13 -13
  28. package/vendor/node_modules/@legendapp/spark-cli/dist/watchman.js +12 -0
  29. package/vendor/node_modules/@legendapp/spark-cli/dist/windows-geometry.js +2 -2
  30. package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +1 -1
  31. package/vendor/node_modules/@legendapp/spark-cli/package.json +3 -3
  32. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/desktop.config.json +1 -1
  33. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +27 -25
  34. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/desktop.config.json +1 -1
  35. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +35 -33
  36. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +29 -27
  37. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +5 -5
  38. package/vendor/node_modules/@legendapp/spark-clipboard/src/index.macos.ts +1 -0
  39. package/vendor/node_modules/@legendapp/spark-codex/package.json +4 -4
  40. package/vendor/node_modules/@legendapp/spark-commands/package.json +7 -7
  41. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +4 -4
  42. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +7 -2
  43. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +3 -3
  44. package/vendor/node_modules/@legendapp/spark-desktop-config/accessibility-state.cjs +2 -2
  45. package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +12 -0
  46. package/vendor/node_modules/@legendapp/spark-desktop-config/autolinking.cjs +4 -4
  47. package/vendor/node_modules/@legendapp/spark-desktop-config/config.d.cts +1 -1
  48. package/vendor/node_modules/@legendapp/spark-desktop-config/fabric-lifecycle.cjs +1 -1
  49. package/vendor/node_modules/@legendapp/spark-desktop-config/keyboard-events.cjs +2 -2
  50. package/vendor/node_modules/@legendapp/spark-desktop-config/macos-host.cjs +39 -0
  51. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +47 -12
  52. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +2 -1
  53. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +8 -6
  54. package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-scroll-view.cjs +2 -2
  55. package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-text-alignment.cjs +2 -2
  56. package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-text-input-alignment.cjs +2 -2
  57. package/vendor/node_modules/@legendapp/spark-desktop-config/text-input-accessibility.cjs +2 -2
  58. package/vendor/node_modules/@legendapp/spark-desktop-host/macos/AppDelegate.h +6 -0
  59. package/vendor/node_modules/@legendapp/spark-desktop-host/macos/Main.storyboard +684 -0
  60. package/vendor/node_modules/@legendapp/spark-desktop-host/macos/main.m +5 -0
  61. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +3 -2
  62. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +5 -5
  63. package/vendor/node_modules/@legendapp/spark-desktop-links/src/index.macos.ts +1 -0
  64. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +4 -4
  65. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +68 -17
  66. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +5 -5
  67. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +2 -1
  68. package/vendor/node_modules/@legendapp/spark-documents/package.json +9 -9
  69. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +4 -4
  70. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +4 -4
  71. package/vendor/node_modules/@legendapp/spark-file-system/macos/RNDesktopFileSystem.mm +14 -5
  72. package/vendor/node_modules/@legendapp/spark-file-system/package.json +4 -4
  73. package/vendor/node_modules/@legendapp/spark-file-system/src/index.ts +1 -1
  74. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +4 -4
  75. package/vendor/node_modules/@legendapp/spark-html/package.json +4 -4
  76. package/vendor/node_modules/@legendapp/spark-markdown/package.json +4 -4
  77. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +4 -4
  78. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +4 -4
  79. package/vendor/node_modules/@legendapp/spark-notifications/package.json +4 -4
  80. package/vendor/node_modules/@legendapp/spark-processes/macos/RNDesktopProcesses.mm +110 -19
  81. package/vendor/node_modules/@legendapp/spark-processes/package.json +4 -4
  82. package/vendor/node_modules/@legendapp/spark-processes/src/index.ts +17 -3
  83. package/vendor/node_modules/@legendapp/spark-processes/src/types.ts +6 -0
  84. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +4 -4
  85. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +5 -5
  86. package/vendor/node_modules/@legendapp/spark-secure-storage/src/index.macos.ts +1 -0
  87. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  88. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +6 -6
  89. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +12 -5
  90. package/vendor/node_modules/@legendapp/spark-system/package.json +4 -4
  91. package/vendor/node_modules/@legendapp/spark-tray/package.json +4 -4
  92. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +82 -18
  93. package/vendor/node_modules/@legendapp/spark-ui/package.json +6 -6
  94. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +4 -0
  95. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +11 -9
  96. package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +20 -10
  97. package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +15 -10
  98. package/vendor/node_modules/@legendapp/spark-ui/src/index.macos.tsx +1 -0
  99. package/vendor/node_modules/@legendapp/spark-updates/package.json +4 -4
  100. package/vendor/node_modules/@legendapp/spark-webview/package.json +11 -4
  101. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
  102. package/camera.ts +0 -13
@@ -3,9 +3,14 @@
3
3
  #import <RNDesktopApp/SparkDesktop.h>
4
4
  #import <signal.h>
5
5
  #import <AppKit/AppKit.h>
6
+ #import <libproc.h>
6
7
  #import <spawn.h>
8
+ #import <sys/ioctl.h>
9
+ #import <sys/proc.h>
7
10
  #import <sys/wait.h>
11
+ #import <util.h>
8
12
  #import <vector>
13
+ #import <chrono>
9
14
  static NSString *ResolveCommandPath(NSString *command)
10
15
  {
11
16
  NSString *homeDirectory = NSHomeDirectory();
@@ -52,10 +57,47 @@ static NSString *ResolveCommandPath(NSString *command)
52
57
  @property BOOL truncated;
53
58
  @property BOOL ended;
54
59
  @property BOOL inputClosed;
60
+ @property BOOL pty;
55
61
  @property dispatch_queue_t inputQueue;
62
+ @property dispatch_queue_t signalQueue;
56
63
  @end
57
64
  @implementation SparkProcess
58
65
  @end
66
+ // Terminal job control moves background jobs into their own process groups,
67
+ // so a terminal child is signalled as its whole session.
68
+ static BOOL SignalProcess(SparkProcess *process, int signal)
69
+ {
70
+ if (!process.pty) return kill(-process.pid, signal) == 0 || errno == ESRCH;
71
+ auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(2);
72
+ int capacity = proc_listallpids(NULL, 0);
73
+ if (capacity <= 0) return NO;
74
+ std::vector<pid_t> pids(capacity + 64);
75
+ while (YES) {
76
+ int count = proc_listallpids(pids.data(), (int)(pids.size() * sizeof(pid_t)));
77
+ if (count <= 0) return NO;
78
+ if (count >= pids.size()) {
79
+ if (std::chrono::steady_clock::now() >= deadline) { errno = ETIMEDOUT; return NO; }
80
+ pids.resize(pids.size() * 2);
81
+ continue;
82
+ }
83
+ BOOL remaining = NO;
84
+ for (int index = 0; index < count; index++) {
85
+ if (pids[index] <= 0 || getsid(pids[index]) != process.pid) continue;
86
+ struct proc_bsdshortinfo info = {};
87
+ if (proc_pidinfo(pids[index], PROC_PIDT_SHORTBSDINFO, 0, &info, sizeof(info)) != sizeof(info)) {
88
+ if (errno == ESRCH) { remaining = YES; continue; }
89
+ return NO;
90
+ }
91
+ // The root stays unreaped during cleanup; zombies cannot fork or hold terminal handles.
92
+ if (info.pbsi_status == SZOMB) continue;
93
+ remaining = YES;
94
+ if (kill(pids[index], signal) != 0 && errno != ESRCH) return NO;
95
+ }
96
+ if (signal != SIGKILL || !remaining) return YES;
97
+ if (std::chrono::steady_clock::now() >= deadline) { errno = ETIMEDOUT; return NO; }
98
+ usleep(10000);
99
+ }
100
+ }
59
101
  @interface RNDesktopProcesses ()
60
102
  @property NSMutableDictionary<NSString *, SparkProcess *> *processes;
61
103
  @property BOOL invalidated;
@@ -71,14 +113,18 @@ RCT_EXPORT_MODULE(NativeDesktopProcesses)
71
113
  }
72
114
  return self;
73
115
  }
74
- - (void)stopAll { for (SparkProcess *process in self.processes.allValues) if (process.running) kill(-process.pid, SIGKILL); }
116
+ - (void)stopAll {
117
+ for (SparkProcess *process in self.processes.allValues) dispatch_async(process.signalQueue, ^{
118
+ if (process.running && !SignalProcess(process, SIGKILL)) NSLog(@"Process cleanup failed: %s", strerror(errno));
119
+ });
120
+ }
75
121
  - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; }
76
122
 
77
123
  - (BOOL)terminate:(SparkProcess *)process {
78
124
  if (process.running) {
79
- if (kill(-process.pid, SIGTERM) != 0 && errno != ESRCH) return NO;
80
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
81
- if (process.running) kill(-process.pid, SIGKILL);
125
+ if (!SignalProcess(process, SIGTERM)) return NO;
126
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), process.signalQueue, ^{
127
+ if (process.running && !SignalProcess(process, SIGKILL)) NSLog(@"Process cleanup failed: %s", strerror(errno));
82
128
  });
83
129
  }
84
130
  return YES;
@@ -117,11 +163,21 @@ RCT_EXPORT_MODULE(NativeDesktopProcesses)
117
163
  if (captureLimit > 8 * 1024 * 1024) { SparkInvalid(reject, @"Invalid capture limit"); return; }
118
164
  NSData *initialInput = args[@"bytes"];
119
165
  if (args[@"bytes"] && ![initialInput isKindOfClass:NSData.class]) { SparkInvalid(reject, @"Invalid process input"); return; }
166
+ NSDictionary *pty = args[@"pty"];
167
+ if (pty && (![pty isKindOfClass:NSDictionary.class] || [pty[@"cols"] integerValue] < 1 || [pty[@"cols"] integerValue] > UINT16_MAX || [pty[@"rows"] integerValue] < 1 || [pty[@"rows"] integerValue] > UINT16_MAX)) { SparkInvalid(reject, @"Invalid terminal size"); return; }
120
168
  process = [SparkProcess new];
121
169
  process.inputQueue = dispatch_queue_create("desktop.process.input", DISPATCH_QUEUE_SERIAL);
170
+ process.signalQueue = dispatch_queue_create("desktop.process.signal", DISPATCH_QUEUE_SERIAL);
122
171
  NSMutableDictionary *environment = [NSProcessInfo.processInfo.environment mutableCopy]; [environment addEntriesFromDictionary:args[@"env"] ?: @{}];
123
- NSPipe *input = [NSPipe pipe], *output = [NSPipe pipe], *errorPipe = [NSPipe pipe];
124
- process.input = input.fileHandleForWriting;
172
+ int controller = -1, terminal = -1;
173
+ if (pty) {
174
+ struct winsize size = { .ws_row = (unsigned short)[pty[@"rows"] integerValue], .ws_col = (unsigned short)[pty[@"cols"] integerValue] };
175
+ if (openpty(&controller, &terminal, NULL, NULL, &size) != 0) { SparkReject(reject, [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil]); return; }
176
+ fcntl(controller, F_SETFD, FD_CLOEXEC);
177
+ process.pty = YES;
178
+ }
179
+ NSPipe *input = pty ? nil : [NSPipe pipe], *output = pty ? nil : [NSPipe pipe], *errorPipe = pty ? nil : [NSPipe pipe];
180
+ process.input = pty ? [[NSFileHandle alloc] initWithFileDescriptor:dup(controller) closeOnDealloc:YES] : input.fileHandleForWriting;
125
181
  // Create the process group atomically, before executable code can fork.
126
182
  // NSTask + setpgid after launch has a race and cannot provide this contract.
127
183
  posix_spawnattr_t attributes; posix_spawnattr_init(&attributes);
@@ -129,12 +185,21 @@ RCT_EXPORT_MODULE(NativeDesktopProcesses)
129
185
  // inherit that state or cooperative SIGTERM degrades into forced SIGKILL.
130
186
  sigset_t mask, defaults; sigemptyset(&mask); sigfillset(&defaults);
131
187
  posix_spawnattr_setsigmask(&attributes, &mask); posix_spawnattr_setsigdefault(&attributes, &defaults);
132
- posix_spawnattr_setflags(&attributes, POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_CLOEXEC_DEFAULT | POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF);
133
- posix_spawnattr_setpgroup(&attributes, 0);
188
+ // A terminal child leads its own session: opening the terminal in that session
189
+ // makes it the controlling terminal, so resize and Ctrl+C deliver signals.
190
+ // The session id doubles as the process group id that termination targets.
191
+ posix_spawnattr_setflags(&attributes, (pty ? POSIX_SPAWN_SETSID : POSIX_SPAWN_SETPGROUP) | POSIX_SPAWN_CLOEXEC_DEFAULT | POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF);
192
+ if (!pty) posix_spawnattr_setpgroup(&attributes, 0);
134
193
  posix_spawn_file_actions_t actions; posix_spawn_file_actions_init(&actions);
135
- posix_spawn_file_actions_adddup2(&actions, input.fileHandleForReading.fileDescriptor, STDIN_FILENO);
136
- posix_spawn_file_actions_adddup2(&actions, output.fileHandleForWriting.fileDescriptor, STDOUT_FILENO);
137
- posix_spawn_file_actions_adddup2(&actions, errorPipe.fileHandleForWriting.fileDescriptor, STDERR_FILENO);
194
+ if (pty) {
195
+ posix_spawn_file_actions_addopen(&actions, STDIN_FILENO, ptsname(controller), O_RDWR, 0);
196
+ posix_spawn_file_actions_adddup2(&actions, STDIN_FILENO, STDOUT_FILENO);
197
+ posix_spawn_file_actions_adddup2(&actions, STDIN_FILENO, STDERR_FILENO);
198
+ } else {
199
+ posix_spawn_file_actions_adddup2(&actions, input.fileHandleForReading.fileDescriptor, STDIN_FILENO);
200
+ posix_spawn_file_actions_adddup2(&actions, output.fileHandleForWriting.fileDescriptor, STDOUT_FILENO);
201
+ posix_spawn_file_actions_adddup2(&actions, errorPipe.fileHandleForWriting.fileDescriptor, STDERR_FILENO);
202
+ }
138
203
  if (args[@"cwd"]) posix_spawn_file_actions_addchdir_np(&actions, [args[@"cwd"] fileSystemRepresentation]);
139
204
  NSArray *arguments = [@[executable] arrayByAddingObjectsFromArray:args[@"args"] ?: @[]];
140
205
  NSMutableArray *variables = [NSMutableArray new];
@@ -145,13 +210,16 @@ RCT_EXPORT_MODULE(NativeDesktopProcesses)
145
210
  pid_t pid = 0;
146
211
  int error = posix_spawn(&pid, executable.fileSystemRepresentation, &actions, &attributes, argv.data(), envp.data());
147
212
  posix_spawn_file_actions_destroy(&actions); posix_spawnattr_destroy(&attributes);
213
+ // Closing the terminal before the child opens it would reset its size.
214
+ if (pty) close(terminal);
148
215
  [input.fileHandleForReading closeFile]; [output.fileHandleForWriting closeFile]; [errorPipe.fileHandleForWriting closeFile];
149
- if (error) { [process.input closeFile]; [output.fileHandleForReading closeFile]; [errorPipe.fileHandleForReading closeFile]; SparkReject(reject, [NSError errorWithDomain:NSPOSIXErrorDomain code:error userInfo:nil]); return; }
216
+ NSFileHandle *controllerHandle = pty ? [[NSFileHandle alloc] initWithFileDescriptor:controller closeOnDealloc:YES] : nil;
217
+ if (error) { [process.input closeFile]; [controllerHandle closeFile]; [output.fileHandleForReading closeFile]; [errorPipe.fileHandleForReading closeFile]; SparkReject(reject, [NSError errorWithDomain:NSPOSIXErrorDomain code:error userInfo:nil]); return; }
150
218
  process.pid = pid; process.running = YES;
151
219
  self.processes[key] = process;
152
220
  NSMutableData *stdoutData = [NSMutableData new], *stderrData = [NSMutableData new];
153
221
  dispatch_group_t group = dispatch_group_create();
154
- NSArray *streams = @[output.fileHandleForReading, errorPipe.fileHandleForReading];
222
+ NSArray *streams = pty ? @[controllerHandle] : @[output.fileHandleForReading, errorPipe.fileHandleForReading];
155
223
  for (NSUInteger index = 0; index < streams.count; index++) {
156
224
  NSFileHandle *handle = streams[index]; NSMutableData *buffer = index ? stderrData : stdoutData;
157
225
  NSString *stream = index ? @"stderr" : @"stdout";
@@ -179,11 +247,14 @@ RCT_EXPORT_MODULE(NativeDesktopProcesses)
179
247
  });
180
248
  }
181
249
  dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
182
- int status = 0; while (waitpid(process.pid, &status, 0) < 0 && errno == EINTR) {}
183
- dispatch_sync(dispatch_get_main_queue(), ^{
250
+ // Reserve the root PID/session ID until descendant cleanup finishes.
251
+ siginfo_t info = {}; while (waitid(P_PID, process.pid, &info, WEXITED | WNOWAIT) < 0 && errno == EINTR) {}
252
+ dispatch_sync(process.signalQueue, ^{
184
253
  // Descendants must not keep the output pipes (and exited promise) alive.
185
- kill(-process.pid, SIGKILL); process.running = NO;
254
+ if (!SignalProcess(process, SIGKILL)) NSLog(@"Process cleanup failed: %s", strerror(errno));
255
+ process.running = NO;
186
256
  });
257
+ int status = 0; while (waitpid(process.pid, &status, 0) < 0 && errno == EINTR) {}
187
258
  dispatch_group_notify(group, dispatch_get_main_queue(), ^{
188
259
  int terminationStatus = status;
189
260
  process.ended = YES;
@@ -196,13 +267,26 @@ RCT_EXPORT_MODULE(NativeDesktopProcesses)
196
267
  });
197
268
  });
198
269
  if (initialInput) { NSData *data = initialInput; dispatch_async(process.inputQueue, ^{ @try { [process.input writeData:data]; } @catch (NSException *exception) {} }); }
199
- if (args[@"timeoutMs"]) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, [args[@"timeoutMs"] doubleValue] * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
270
+ if (args[@"timeoutMs"]) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, [args[@"timeoutMs"] doubleValue] * NSEC_PER_MSEC), process.signalQueue, ^{
200
271
  if (process.running) { process.timedOut = YES; [self terminate:process]; }
201
272
  });
202
273
  } else {
203
274
  if (!process || process.ended) { if ([method isEqual:@"terminate"] || [method isEqual:@"closeInput"]) { resolve(binary ? NSNull.null : @"null"); return; } reject(@"E_CLOSED", @"Process has exited", nil); return; }
204
275
  if ([method isEqual:@"terminate"]) {
205
- if (![self terminate:process]) { SparkReject(reject, [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil]); return; }
276
+ dispatch_async(process.signalQueue, ^{
277
+ if (![self terminate:process]) SparkReject(reject, [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil]);
278
+ else resolve(binary ? NSNull.null : @"null");
279
+ }); return;
280
+ }
281
+ else if ([method isEqual:@"resize"]) {
282
+ NSInteger cols = [args[@"cols"] integerValue], rows = [args[@"rows"] integerValue];
283
+ if (!process.pty) { reject(@"E_UNSUPPORTED_OPTION", @"Process has no terminal", nil); return; }
284
+ if (cols < 1 || cols > UINT16_MAX || rows < 1 || rows > UINT16_MAX) { SparkInvalid(reject, @"Invalid terminal size"); return; }
285
+ dispatch_async(process.inputQueue, ^{
286
+ struct winsize size = { .ws_row = (unsigned short)rows, .ws_col = (unsigned short)cols };
287
+ if (process.ended || ioctl(process.input.fileDescriptor, TIOCSWINSZ, &size) != 0) { reject(@"E_CLOSED", @"Process terminal is closed", nil); return; }
288
+ resolve(binary ? NSNull.null : @"null");
289
+ }); return;
206
290
  }
207
291
  else if ([method isEqual:@"write"] || [method isEqual:@"closeInput"]) {
208
292
  NSData *data = [method isEqual:@"write"] ? args[@"bytes"] : nil;
@@ -212,7 +296,14 @@ RCT_EXPORT_MODULE(NativeDesktopProcesses)
212
296
  if ([method isEqual:@"write"]) {
213
297
  if (process.inputClosed) { reject(@"E_CLOSED", @"Process input is closed", nil); return; }
214
298
  [process.input writeData:data];
215
- } else if (!process.inputClosed) { [process.input closeFile]; process.inputClosed = YES; }
299
+ } else if (!process.inputClosed) {
300
+ // The reader keeps the terminal open, so closing the writer would not reach the child.
301
+ // Ctrl+D ends a pending line; only a Ctrl+D on an empty line reads as end-of-file.
302
+ // The terminal stays open for resize until the process ends.
303
+ if (process.pty) [process.input writeData:[NSData dataWithBytes:"\x04\x04" length:2]];
304
+ else [process.input closeFile];
305
+ process.inputClosed = YES;
306
+ }
216
307
  resolve(binary ? NSNull.null : @"null");
217
308
  } @catch (NSException *exception) { reject(@"E_CLOSED", @"Process input is closed", nil); }
218
309
  }); return;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-processes",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -12,8 +12,8 @@
12
12
  "react-native.config.js"
13
13
  ],
14
14
  "peerDependencies": {
15
- "react": "^19.1.0",
16
- "react-native": "0.81.6"
15
+ "react": "^19.2.0",
16
+ "react-native": "0.83.10"
17
17
  },
18
18
  "codegenConfig": {
19
19
  "name": "RNDesktopProcessesSpec",
@@ -41,7 +41,7 @@
41
41
  ]
42
42
  },
43
43
  "dependencies": {
44
- "@legendapp/spark-desktop-app": "0.0.1"
44
+ "@legendapp/spark-desktop-app": "0.0.2"
45
45
  },
46
46
  "private": true
47
47
  }
@@ -4,7 +4,7 @@ import Native from "./NativeDesktopProcesses";
4
4
  import { onDesktopEvent } from "@legendapp/spark-desktop-app/src/events";
5
5
  import { SparkError, invokeNative, nativeError, type Availability } from "@legendapp/spark-desktop-app/src/contracts";
6
6
  import { nativePath } from "@legendapp/spark-desktop-app/src/contracts/path";
7
- import type { ProcessOptions, RunCommandOptions, ProcessInput, ProcessResult, ProcessHandle } from "./types";
7
+ import type { ProcessOptions, RunCommandOptions, ProcessInput, ProcessResult, ProcessHandle, TerminalSize } from "./types";
8
8
  export type * from "./types";
9
9
  export function getProcessAvailability(): Availability {
10
10
  if (Platform.OS !== "macos" && Platform.OS !== "windows") return { available: false, reason: "unsupported-platform" };
@@ -33,6 +33,12 @@ export async function resolveCommand(name: string): Promise<string | null> {
33
33
  if (value === null) return null;
34
34
  try { return nativePath(value, Platform.OS); } catch (cause) { throw new SparkError("E_INVALID_DATA", "Resolved command path is invalid", { cause }); }
35
35
  }
36
+ function terminalSize(value: unknown): TerminalSize {
37
+ object(value, ["cols", "rows"]);
38
+ const { cols, rows } = value;
39
+ if (!Number.isInteger(cols) || !Number.isInteger(rows) || (cols as number) < 1 || (rows as number) < 1 || (cols as number) > 0xffff || (rows as number) > 0xffff) invalid("Terminal cols and rows must be integers from 1 to 65535");
40
+ return { cols: cols as number, rows: rows as number };
41
+ }
36
42
  function inputBytes(input: ProcessInput): Uint8Array {
37
43
  if (typeof input === "string") return new TextEncoder().encode(input);
38
44
  if (!(input instanceof Uint8Array)) invalid("Process input must be UTF-8 text or Uint8Array");
@@ -46,7 +52,7 @@ function result(value: unknown, aborted: boolean, limit: number): ProcessResult
46
52
  }
47
53
  let sequence = 0;
48
54
  export async function spawn(options: ProcessOptions): Promise<ProcessHandle> {
49
- object(options, ["target", "args", "cwd", "env", "input", "timeoutMs", "signal", "captureLimitBytes", "onOutput"]);
55
+ object(options, ["target", "args", "cwd", "env", "input", "timeoutMs", "signal", "captureLimitBytes", "onOutput", "pty"]);
50
56
  object(options.target, ["type", "path", "name"]);
51
57
  const { target, signal, onOutput } = options;
52
58
  let executable: string;
@@ -62,9 +68,11 @@ export async function spawn(options: ProcessOptions): Promise<ProcessHandle> {
62
68
  if (options.timeoutMs !== undefined && (!Number.isInteger(options.timeoutMs) || options.timeoutMs < 1 || options.timeoutMs > 0xfffffffe)) invalid("timeoutMs must be an integer from 1 to 4294967294");
63
69
  const captureLimitBytes = options.captureLimitBytes ?? 8 * 1024 * 1024;
64
70
  if (!Number.isInteger(captureLimitBytes) || captureLimitBytes < 0 || captureLimitBytes > 8 * 1024 * 1024) invalid("captureLimitBytes must be an integer from 0 to 8388608");
71
+ const pty = options.pty === undefined ? undefined : terminalSize(options.pty);
72
+ if (pty && Platform.OS !== "macos") throw new SparkError("E_UNSUPPORTED_OPTION", "Process terminals are available on macOS");
65
73
  if (onOutput !== undefined && typeof onOutput !== "function") invalid("onOutput must be a function");
66
74
  if (signal !== undefined && (!signal || typeof signal.aborted !== "boolean" || typeof signal.addEventListener !== "function" || typeof signal.removeEventListener !== "function")) invalid("Expected an AbortSignal");
67
- const wire = { executable, command: target.type === "command", args: options.args ?? [], cwd, env: options.env ?? {}, bytes: options.input === undefined ? undefined : inputBytes(options.input), timeoutMs: options.timeoutMs, captureLimitBytes, streamOutput: !!onOutput };
75
+ const wire = { executable, command: target.type === "command", args: options.args ?? [], cwd, env: options.env ?? {}, bytes: options.input === undefined ? undefined : inputBytes(options.input), timeoutMs: options.timeoutMs, captureLimitBytes, streamOutput: !!onOutput, pty };
68
76
  if (signal?.aborted) throw new SparkError("E_ABORTED", "Process launch was aborted");
69
77
  const availability = getProcessAvailability();
70
78
  if (!availability.available) throw new SparkError(availability.reason === "missing-module" ? "E_MODULE_UNAVAILABLE" : "E_UNSUPPORTED_PLATFORM", "Process execution is unavailable");
@@ -122,6 +130,12 @@ export async function spawn(options: ProcessOptions): Promise<ProcessHandle> {
122
130
  return closingInput ??= command("closeInput", { id }).catch(error => { closingInput = undefined; throw error; });
123
131
  },
124
132
  terminate,
133
+ async resize(size) {
134
+ const { cols, rows } = terminalSize(size);
135
+ if (!pty) throw new SparkError("E_UNSUPPORTED_OPTION", "Process has no terminal");
136
+ if (ended) throw new SparkError("E_CLOSED", "Process terminal is closed");
137
+ return command("resize", { id, cols, rows });
138
+ },
125
139
  };
126
140
  }
127
141
  export async function runCommand(options: RunCommandOptions): Promise<ProcessResult> {
@@ -1,5 +1,6 @@
1
1
  export type ProcessTarget = { type: "executable"; path: string } | { type: "helper"; name: string } | { type: "command"; name: string };
2
2
  export type ProcessInput = string | Uint8Array;
3
+ export type TerminalSize = { cols: number; rows: number };
3
4
  export type ProcessOutput = { stream: "stdout" | "stderr"; bytes: Uint8Array };
4
5
  export type ProcessOptions = {
5
6
  target: ProcessTarget;
@@ -12,6 +13,8 @@ export type ProcessOptions = {
12
13
  /** Maximum captured bytes per stream, 0–8 MiB; streaming remains complete. */
13
14
  captureLimitBytes?: number;
14
15
  onOutput?: (output: ProcessOutput) => void;
16
+ /** Run the child on a pseudo-terminal of this size (macOS). Output, including terminal echo, arrives as one merged `stdout` stream. */
17
+ pty?: TerminalSize;
15
18
  };
16
19
  export type RunCommandOptions = ProcessOptions;
17
20
  export type ProcessExit = { type: "exited"; code: number } | { type: "terminated"; signal: number | null };
@@ -28,7 +31,10 @@ export interface ProcessHandle {
28
31
  readonly exited: Promise<ProcessResult>;
29
32
  /** Strings use UTF-8; byte arrays pass through unchanged. Calls preserve order. */
30
33
  write(input: ProcessInput): Promise<void>;
34
+ /** With `pty`, inject two Ctrl+D EOF characters (canonical mode/default VEOF), rather than a pipe half-close. */
31
35
  closeInput(): Promise<void>;
32
36
  /** Resolve after the process tree exits and its output drains. Retry on failure. */
33
37
  terminate(): Promise<void>;
38
+ /** Resize the terminal of a process spawned with `pty`; the child receives SIGWINCH. */
39
+ resize(size: TerminalSize): Promise<void>;
34
40
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-rich-text",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "main": "src/index.ts",
@@ -9,10 +9,10 @@
9
9
  "src"
10
10
  ],
11
11
  "peerDependencies": {
12
- "react": "^19.1.0",
13
- "react-native": "0.81.6"
12
+ "react": "^19.2.0",
13
+ "react-native": "0.83.10"
14
14
  },
15
15
  "dependencies": {
16
- "@legendapp/spark-desktop-shortcuts": "0.0.1"
16
+ "@legendapp/spark-desktop-shortcuts": "0.0.2"
17
17
  }
18
18
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-secure-storage",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "main": "src/index",
6
6
  "react-native": "src/index",
@@ -12,9 +12,9 @@
12
12
  "windows"
13
13
  ],
14
14
  "peerDependencies": {
15
- "react": "^19.1.0",
16
- "react-native": "0.81.6",
17
- "expo-secure-store": "~15.0.8"
15
+ "react": "^19.2.0",
16
+ "react-native": "0.83.10",
17
+ "expo-secure-store": "~55.0.18"
18
18
  },
19
19
  "codegenConfig": {
20
20
  "name": "RNDesktopSecureStorageSpec",
@@ -41,7 +41,7 @@
41
41
  ]
42
42
  },
43
43
  "dependencies": {
44
- "@legendapp/spark-desktop-app": "0.0.1"
44
+ "@legendapp/spark-desktop-app": "0.0.2"
45
45
  },
46
46
  "peerDependenciesMeta": {
47
47
  "expo-secure-store": {
@@ -0,0 +1 @@
1
+ export * from "./desktop";
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@legendapp/spark-settings",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "files": [
7
7
  "src"
8
8
  ],
9
9
  "dependencies": {
10
- "@legendapp/spark-file-system": "0.0.1",
10
+ "@legendapp/spark-file-system": "0.0.2",
11
11
  "@legendapp/state": "^3.0.0-beta.42",
12
- "@legendapp/spark-desktop-app": "0.0.1"
12
+ "@legendapp/spark-desktop-app": "0.0.2"
13
13
  },
14
14
  "private": true,
15
15
  "spark": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-settings-ui",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "main": "src/index.tsx",
@@ -8,13 +8,13 @@
8
8
  "src"
9
9
  ],
10
10
  "dependencies": {
11
- "@legendapp/spark-ui": "0.0.1",
12
- "@legendapp/spark-desktop-windows": "0.0.1",
13
- "@legendapp/spark-desktop-app": "0.0.1"
11
+ "@legendapp/spark-ui": "0.0.2",
12
+ "@legendapp/spark-desktop-windows": "0.0.2",
13
+ "@legendapp/spark-desktop-app": "0.0.2"
14
14
  },
15
15
  "peerDependencies": {
16
- "react": "^19.1.0",
17
- "react-native": "0.81.6",
16
+ "react": "^19.2.0",
17
+ "react-native": "0.83.10",
18
18
  "@legendapp/list": ">=3.3.0"
19
19
  }
20
20
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-sqlite",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -8,9 +8,16 @@
8
8
  "src"
9
9
  ],
10
10
  "dependencies": {
11
- "@op-engineering/op-sqlite": "18.2.1",
12
- "@legendapp/spark-desktop-app": "0.0.1",
13
- "@legendapp/spark-file-system": "0.0.1"
11
+ "@legendapp/spark-desktop-app": "0.0.2",
12
+ "@legendapp/spark-file-system": "0.0.2"
14
13
  },
15
- "private": true
14
+ "private": true,
15
+ "peerDependencies": {
16
+ "@op-engineering/op-sqlite": "18.2.1"
17
+ },
18
+ "peerDependenciesMeta": {
19
+ "@op-engineering/op-sqlite": {
20
+ "optional": true
21
+ }
22
+ }
16
23
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-system",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -12,8 +12,8 @@
12
12
  "react-native.config.js"
13
13
  ],
14
14
  "peerDependencies": {
15
- "react": "^19.1.0",
16
- "react-native": "0.81.6"
15
+ "react": "^19.2.0",
16
+ "react-native": "0.83.10"
17
17
  },
18
18
  "codegenConfig": {
19
19
  "name": "RNDesktopSystemSpec",
@@ -40,7 +40,7 @@
40
40
  ]
41
41
  },
42
42
  "dependencies": {
43
- "@legendapp/spark-desktop-app": "0.0.1"
43
+ "@legendapp/spark-desktop-app": "0.0.2"
44
44
  },
45
45
  "private": true
46
46
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-tray",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -12,8 +12,8 @@
12
12
  "react-native.config.js"
13
13
  ],
14
14
  "peerDependencies": {
15
- "react": "^19.1.0",
16
- "react-native": "0.81.6"
15
+ "react": "^19.2.0",
16
+ "react-native": "0.83.10"
17
17
  },
18
18
  "codegenConfig": {
19
19
  "name": "RNDesktopTraySpec",
@@ -40,7 +40,7 @@
40
40
  ]
41
41
  },
42
42
  "dependencies": {
43
- "@legendapp/spark-desktop-app": "0.0.1"
43
+ "@legendapp/spark-desktop-app": "0.0.2"
44
44
  },
45
45
  "private": true
46
46
  }