@vibest/cli 0.0.2-beta.1 → 0.0.2-beta.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.
@@ -1,1340 +0,0 @@
1
- // @bun
2
- // ../plugin-harnesses/src/cursor-plugin.ts
3
- import { Effect as Effect12 } from "effect";
4
-
5
- // ../plugin-harnesses/src/cursor.ts
6
- import { Effect as Effect10, FileSystem as FileSystem5, Path as Path5, Predicate as Predicate5 } from "effect";
7
- import * as ChildProcessSpawner4 from "effect/process/ChildProcessSpawner";
8
-
9
- // ../plugin-harnesses/src/models.ts
10
- import { Option, Schema } from "effect";
11
- var opt = (flag, value) => value ? [flag, value] : [];
12
- var noProvider = (harness) => (provider) => provider ? `${harness} has no provider option` : undefined;
13
-
14
- // ../../node_modules/.pnpm/@effect+platform-node-shared@4.0.2_effect@4.0.2/node_modules/@effect/platform-node-shared/dist/NodeChildProcessSpawner.js
15
- import * as Deferred from "effect/Deferred";
16
- import * as Duration from "effect/Duration";
17
- import * as Effect3 from "effect/Effect";
18
- import * as Exit2 from "effect/Exit";
19
- import * as FileSystem from "effect/FileSystem";
20
- import * as Layer from "effect/Layer";
21
- import * as Path from "effect/Path";
22
- import * as Predicate from "effect/Predicate";
23
- import * as ChildProcess from "effect/process/ChildProcess";
24
- import { ChildProcessSpawner, ExitCode, make as makeSpawner, makeHandle, ProcessId } from "effect/process/ChildProcessSpawner";
25
- import * as Sink2 from "effect/Sink";
26
- import * as Stream2 from "effect/Stream";
27
- import * as NodeChildProcess from "child_process";
28
- import { PassThrough } from "stream";
29
-
30
- // ../../node_modules/.pnpm/@effect+platform-node-shared@4.0.2_effect@4.0.2/node_modules/@effect/platform-node-shared/dist/internal/nodeChildProcessSpawner.js
31
- var buildSpawnOptions = (options, base, platform) => {
32
- const detached = options.detached ?? platform !== "win32";
33
- return {
34
- ...base,
35
- detached,
36
- shell: options.shell,
37
- windowsHide: options.windowsHide ?? !detached
38
- };
39
- };
40
-
41
- // ../../node_modules/.pnpm/@effect+platform-node-shared@4.0.2_effect@4.0.2/node_modules/@effect/platform-node-shared/dist/internal/utils.js
42
- import * as PlatformError from "effect/PlatformError";
43
- var handleErrnoException = (module, method) => (err, [path]) => {
44
- let reason = "Unknown";
45
- switch (err.code) {
46
- case "ENOENT":
47
- reason = "NotFound";
48
- break;
49
- case "EACCES":
50
- reason = "PermissionDenied";
51
- break;
52
- case "EEXIST":
53
- reason = "AlreadyExists";
54
- break;
55
- case "EISDIR":
56
- reason = "BadResource";
57
- break;
58
- case "ENOTDIR":
59
- reason = "BadResource";
60
- break;
61
- case "EBUSY":
62
- reason = "Busy";
63
- break;
64
- case "ELOOP":
65
- reason = "BadResource";
66
- break;
67
- }
68
- return PlatformError.systemError({
69
- _tag: reason,
70
- module,
71
- method,
72
- pathOrDescriptor: path,
73
- syscall: err.syscall,
74
- cause: err
75
- });
76
- };
77
-
78
- // ../../node_modules/.pnpm/@effect+platform-node-shared@4.0.2_effect@4.0.2/node_modules/@effect/platform-node-shared/dist/NodeSink.js
79
- import * as Cause from "effect/Cause";
80
- import * as Channel from "effect/Channel";
81
- import * as Effect from "effect/Effect";
82
- import { identity } from "effect/Function";
83
- import * as Pull from "effect/Pull";
84
- import * as Sink from "effect/Sink";
85
- var fromWritable = (options) => Sink.fromChannel(Channel.mapDone(fromWritableChannel(options), (_) => [_]));
86
- var fromWritableChannel = (options) => Channel.fromTransform((pull) => {
87
- const writable = options.evaluate();
88
- return Effect.succeed(pullIntoWritable({
89
- ...options,
90
- writable,
91
- pull
92
- }));
93
- });
94
- var pullIntoWritable = (options) => options.pull.pipe(Effect.flatMap((chunk) => {
95
- let i = 0;
96
- return Effect.callback((resume) => {
97
- let cancelled = false;
98
- const loop = () => {
99
- for (;i < chunk.length; ) {
100
- if (cancelled) {
101
- return;
102
- }
103
- const success = options.writable.write(chunk[i++], options.encoding);
104
- if (!success) {
105
- if (!cancelled) {
106
- options.writable.once("drain", loop);
107
- }
108
- return;
109
- }
110
- }
111
- if (!cancelled) {
112
- resume(Effect.void);
113
- }
114
- };
115
- loop();
116
- return Effect.sync(() => {
117
- cancelled = true;
118
- options.writable.off("drain", loop);
119
- });
120
- });
121
- }), Effect.forever({
122
- disableYield: true
123
- }), options.endOnDone !== false ? Pull.catchDone((_) => {
124
- if ("closed" in options.writable && options.writable.closed) {
125
- return Cause.done(_);
126
- }
127
- return Effect.callback((resume) => {
128
- const onFinish = () => resume(Cause.done(_));
129
- options.writable.once("finish", onFinish);
130
- options.writable.end();
131
- return Effect.sync(() => {
132
- options.writable.off("finish", onFinish);
133
- });
134
- });
135
- }) : identity, Effect.raceFirst(Effect.callback((resume) => {
136
- const onError = (error) => resume(Effect.fail(options.onError(error)));
137
- options.writable.once("error", onError);
138
- return Effect.sync(() => {
139
- options.writable.off("error", onError);
140
- });
141
- })));
142
-
143
- // ../../node_modules/.pnpm/@effect+platform-node-shared@4.0.2_effect@4.0.2/node_modules/@effect/platform-node-shared/dist/NodeStream.js
144
- import * as Arr from "effect/Array";
145
- import * as ByteSize from "effect/ByteSize";
146
- import * as Cause2 from "effect/Cause";
147
- import * as Channel2 from "effect/Channel";
148
- import * as Context from "effect/Context";
149
- import * as Effect2 from "effect/Effect";
150
- import * as Exit from "effect/Exit";
151
- import * as Fiber from "effect/Fiber";
152
- import { dual } from "effect/Function";
153
- import * as Latch from "effect/Latch";
154
- import * as MutableRef from "effect/MutableRef";
155
- import * as Pull2 from "effect/Pull";
156
- import * as Scope from "effect/Scope";
157
- import * as Stream from "effect/Stream";
158
- var fromReadable = (options) => Stream.fromChannel(fromReadableChannel(options));
159
- var fromReadableChannel = (options) => Channel2.fromTransform((_, scope) => readableToPullUnsafe({
160
- scope,
161
- readable: options.evaluate(),
162
- onError: options.onError ?? defaultOnError,
163
- chunkSize: options.chunkSize,
164
- closeOnDone: options.closeOnDone
165
- }));
166
- var readableToPullUnsafe = (options) => {
167
- const readable = options.readable;
168
- const closeOnDone = options.closeOnDone ?? true;
169
- const exit = options.exit ?? MutableRef.make(undefined);
170
- const latch = options.latch ?? Latch.makeUnsafe(false);
171
- function onReadable() {
172
- latch.openUnsafe();
173
- }
174
- function onError(error) {
175
- exit.current = Exit.fail(options.onError(error));
176
- latch.openUnsafe();
177
- }
178
- function onEnd() {
179
- exit.current = Exit.fail(Cause2.Done());
180
- latch.openUnsafe();
181
- }
182
- readable.on("readable", onReadable);
183
- readable.once("error", onError);
184
- readable.once("end", onEnd);
185
- const pull = Effect2.suspend(function loop() {
186
- let item = options.readable.read(options.chunkSize);
187
- if (item === null) {
188
- if (exit.current) {
189
- return exit.current;
190
- }
191
- if (readable.readableEnded) {
192
- return Effect2.fail(Cause2.Done());
193
- }
194
- latch.closeUnsafe();
195
- return Effect2.flatMap(latch.await, loop);
196
- }
197
- const chunk = Arr.of(item);
198
- while (true) {
199
- item = options.readable.read(options.chunkSize);
200
- if (item === null)
201
- break;
202
- chunk.push(item);
203
- }
204
- return Effect2.succeed(chunk);
205
- });
206
- return Effect2.as(Scope.addFinalizer(options.scope, Effect2.sync(() => {
207
- readable.off("readable", onReadable);
208
- readable.off("error", onError);
209
- readable.off("end", onEnd);
210
- if (closeOnDone && "closed" in options.readable && !options.readable.closed) {
211
- options.readable.destroy();
212
- }
213
- })), pull);
214
- };
215
- var defaultOnError = (error) => new Cause2.UnknownError(error);
216
-
217
- // ../../node_modules/.pnpm/@effect+platform-node-shared@4.0.2_effect@4.0.2/node_modules/@effect/platform-node-shared/dist/NodeChildProcessSpawner.js
218
- var toError = (error) => error instanceof globalThis.Error ? error : new globalThis.Error(String(error));
219
- var toPlatformError = (method, error, command) => {
220
- const {
221
- commands
222
- } = flattenCommand(command);
223
- const commandStr = commands.reduce((acc, curr) => {
224
- const cmd = `${curr.command} ${curr.args.join(" ")}`;
225
- return acc.length === 0 ? cmd : `${acc} | ${cmd}`;
226
- }, "");
227
- return handleErrnoException("ChildProcess", method)(error, [commandStr]);
228
- };
229
- var processGroupGraceMillis = 1000;
230
- var processGroupPollIntervalMillis = 10;
231
- var isProcessAlive = (childProcess, exitSignal) => {
232
- if (!Deferred.isDoneUnsafe(exitSignal)) {
233
- return true;
234
- }
235
- if (globalThis.process.platform === "win32") {
236
- return false;
237
- }
238
- try {
239
- globalThis.process.kill(-childProcess.pid, 0);
240
- return true;
241
- } catch {
242
- return false;
243
- }
244
- };
245
- var taskkill = (childProcess, onExit = () => {}) => NodeChildProcess.execFile("taskkill", ["/pid", String(childProcess.pid), "/T", "/F"], {
246
- windowsHide: true
247
- }, onExit);
248
- var make3 = /* @__PURE__ */ Effect3.gen(function* () {
249
- const fs = yield* FileSystem.FileSystem;
250
- const path = yield* Path.Path;
251
- const resolveWorkingDirectory = Effect3.fnUntraced(function* (options) {
252
- if (Predicate.isUndefined(options.cwd))
253
- return;
254
- yield* fs.access(options.cwd);
255
- return path.resolve(options.cwd);
256
- });
257
- const resolveEnvironment = (options) => {
258
- return options.extendEnv ? {
259
- ...globalThis.process.env,
260
- ...options.env
261
- } : options.env;
262
- };
263
- const inputToStdioOption = (input) => Stream2.isStream(input) ? "pipe" : input;
264
- const outputToStdioOption = (input) => Sink2.isSink(input) ? "pipe" : input;
265
- const resolveStdinOption = (options) => {
266
- const defaultConfig = {
267
- stream: "pipe",
268
- encoding: "utf-8",
269
- endOnDone: true
270
- };
271
- if (Predicate.isUndefined(options.stdin)) {
272
- return defaultConfig;
273
- }
274
- if (typeof options.stdin === "string") {
275
- return {
276
- ...defaultConfig,
277
- stream: options.stdin
278
- };
279
- }
280
- if (Stream2.isStream(options.stdin)) {
281
- return {
282
- ...defaultConfig,
283
- stream: options.stdin
284
- };
285
- }
286
- return {
287
- stream: options.stdin.stream,
288
- encoding: options.stdin.encoding ?? defaultConfig.encoding,
289
- endOnDone: options.stdin.endOnDone ?? defaultConfig.endOnDone
290
- };
291
- };
292
- const resolveOutputOption = (options, streamName) => {
293
- const option = options[streamName];
294
- if (Predicate.isUndefined(option)) {
295
- return {
296
- stream: "pipe"
297
- };
298
- }
299
- if (typeof option === "string") {
300
- return {
301
- stream: option
302
- };
303
- }
304
- if (Sink2.isSink(option)) {
305
- return {
306
- stream: option
307
- };
308
- }
309
- return {
310
- stream: option.stream
311
- };
312
- };
313
- const resolveAdditionalFds = (options) => {
314
- if (Predicate.isUndefined(options.additionalFds)) {
315
- return [];
316
- }
317
- const result = [];
318
- for (const [name, config] of Object.entries(options.additionalFds)) {
319
- const fd = ChildProcess.parseFdName(name);
320
- if (Predicate.isNotUndefined(fd)) {
321
- result.push({
322
- fd,
323
- config
324
- });
325
- }
326
- }
327
- return result.sort((a, b) => a.fd - b.fd);
328
- };
329
- const buildStdioArray = (stdinConfig, stdoutConfig, stderrConfig, additionalFds) => {
330
- const stdio = [inputToStdioOption(stdinConfig.stream), outputToStdioOption(stdoutConfig.stream), outputToStdioOption(stderrConfig.stream)];
331
- if (additionalFds.length === 0) {
332
- return stdio;
333
- }
334
- const maxFd = additionalFds.reduce((max, {
335
- fd
336
- }) => Math.max(max, fd), 2);
337
- for (let i = 3;i <= maxFd; i++) {
338
- stdio[i] = "ignore";
339
- }
340
- for (const {
341
- fd
342
- } of additionalFds) {
343
- stdio[fd] = "pipe";
344
- }
345
- return stdio;
346
- };
347
- const setupAdditionalFds = Effect3.fnUntraced(function* (command, childProcess, additionalFds) {
348
- if (additionalFds.length === 0) {
349
- return {
350
- getInputFd: () => Sink2.drain,
351
- getOutputFd: () => Stream2.empty
352
- };
353
- }
354
- const inputSinks = new Map;
355
- const outputStreams = new Map;
356
- for (const {
357
- config,
358
- fd
359
- } of additionalFds) {
360
- const nodeStream = childProcess.stdio[fd];
361
- switch (config.type) {
362
- case "input": {
363
- let sink = Sink2.drain;
364
- if (nodeStream && "write" in nodeStream) {
365
- sink = fromWritable({
366
- evaluate: () => nodeStream,
367
- onError: (error) => toPlatformError(`fromWritable(fd${fd})`, toError(error), command)
368
- });
369
- }
370
- if (config.stream) {
371
- yield* Effect3.forkScoped(Stream2.run(config.stream, sink));
372
- }
373
- inputSinks.set(fd, sink);
374
- break;
375
- }
376
- case "output": {
377
- let stream = Stream2.empty;
378
- if (nodeStream && "read" in nodeStream) {
379
- const passThrough = new PassThrough;
380
- nodeStream.on("error", (error) => passThrough.destroy(error));
381
- nodeStream.pipe(passThrough);
382
- stream = fromReadable({
383
- evaluate: () => passThrough,
384
- onError: (error) => toPlatformError(`fromReadable(fd${fd})`, toError(error), command)
385
- });
386
- }
387
- if (config.sink) {
388
- stream = Stream2.transduce(stream, config.sink);
389
- }
390
- outputStreams.set(fd, stream);
391
- break;
392
- }
393
- }
394
- }
395
- return {
396
- getInputFd: (fd) => inputSinks.get(fd) ?? Sink2.drain,
397
- getOutputFd: (fd) => outputStreams.get(fd) ?? Stream2.empty
398
- };
399
- });
400
- const setupChildStdin = (command, childProcess, config) => Effect3.suspend(() => {
401
- let sink = Sink2.drain;
402
- if (Predicate.isNotNull(childProcess.stdin)) {
403
- sink = fromWritable({
404
- evaluate: () => childProcess.stdin,
405
- onError: (error) => toPlatformError("fromWritable(stdin)", toError(error), command),
406
- endOnDone: config.endOnDone,
407
- encoding: config.encoding
408
- });
409
- }
410
- if (Stream2.isStream(config.stream)) {
411
- return Effect3.as(Effect3.forkScoped(Stream2.run(config.stream, sink)), sink);
412
- }
413
- return Effect3.succeed(sink);
414
- });
415
- const setupChildOutputStreams = (command, childProcess, stdoutConfig, stderrConfig) => {
416
- let stdout = childProcess.stdout ? (() => {
417
- const passThrough = new PassThrough;
418
- childProcess.stdout.on("error", (error) => passThrough.destroy(error));
419
- childProcess.stdout.pipe(passThrough);
420
- return fromReadable({
421
- evaluate: () => passThrough,
422
- onError: (error) => toPlatformError("fromReadable(stdout)", toError(error), command)
423
- });
424
- })() : Stream2.empty;
425
- let stderr = childProcess.stderr ? (() => {
426
- const passThrough = new PassThrough;
427
- childProcess.stderr.on("error", (error) => passThrough.destroy(error));
428
- childProcess.stderr.pipe(passThrough);
429
- return fromReadable({
430
- evaluate: () => passThrough,
431
- onError: (error) => toPlatformError("fromReadable(stderr)", toError(error), command)
432
- });
433
- })() : Stream2.empty;
434
- if (Sink2.isSink(stdoutConfig.stream)) {
435
- stdout = Stream2.transduce(stdout, stdoutConfig.stream);
436
- }
437
- if (Sink2.isSink(stderrConfig.stream)) {
438
- stderr = Stream2.transduce(stderr, stderrConfig.stream);
439
- }
440
- const all = Stream2.merge(stdout, stderr);
441
- return {
442
- stdout,
443
- stderr,
444
- all
445
- };
446
- };
447
- const spawn2 = (command, spawnOptions) => Effect3.callback((resume) => {
448
- const deferred = Deferred.makeUnsafe();
449
- const handle = NodeChildProcess.spawn(command.command, command.args, spawnOptions);
450
- handle.on("error", (error) => {
451
- resume(Effect3.fail(toPlatformError("spawn", error, command)));
452
- });
453
- handle.on("exit", (...args) => {
454
- Deferred.doneUnsafe(deferred, Exit2.succeed(args));
455
- });
456
- handle.on("spawn", () => {
457
- resume(Effect3.succeed([handle, deferred]));
458
- });
459
- return Effect3.sync(() => {
460
- handle.kill("SIGTERM");
461
- });
462
- });
463
- const killProcessGroup = (command, childProcess, signal) => {
464
- if (globalThis.process.platform === "win32") {
465
- return Effect3.callback((resume) => {
466
- taskkill(childProcess, (error) => {
467
- if (error) {
468
- resume(Effect3.fail(toPlatformError("kill", toError(error), command)));
469
- } else {
470
- resume(Effect3.void);
471
- }
472
- });
473
- });
474
- }
475
- return Effect3.try({
476
- try: () => {
477
- globalThis.process.kill(-childProcess.pid, signal);
478
- },
479
- catch: (error) => toPlatformError("kill", toError(error), command)
480
- });
481
- };
482
- const killProcessGroupOnExit = (childProcess, signal) => {
483
- if (globalThis.process.platform === "win32") {
484
- taskkill(childProcess);
485
- return;
486
- }
487
- try {
488
- globalThis.process.kill(-childProcess.pid, signal);
489
- } catch {}
490
- };
491
- const killProcess = (command, childProcess, signal) => Effect3.suspend(() => {
492
- const killed = childProcess.kill(signal);
493
- if (!killed) {
494
- const error = new globalThis.Error("Failed to kill child process");
495
- return Effect3.fail(toPlatformError("kill", error, command));
496
- }
497
- return Effect3.void;
498
- });
499
- const awaitProcessExit = (childProcess, exitSignal, timeoutMillis) => Effect3.callback((resume) => {
500
- const deadline = Date.now() + timeoutMillis;
501
- let timer;
502
- const stop = () => {
503
- clearTimeout(timer);
504
- childProcess.removeListener("exit", poll);
505
- };
506
- const poll = () => {
507
- clearTimeout(timer);
508
- if (Date.now() >= deadline || !isProcessAlive(childProcess, exitSignal)) {
509
- stop();
510
- resume(Effect3.void);
511
- return;
512
- }
513
- timer = setTimeout(poll, processGroupPollIntervalMillis);
514
- };
515
- childProcess.on("exit", poll);
516
- poll();
517
- return Effect3.sync(stop);
518
- });
519
- const terminateProcessGroup = Effect3.fnUntraced(function* (command, childProcess, exitSignal, options) {
520
- const signalGroup = (signal) => killProcessGroup(command, childProcess, signal).pipe(Effect3.catch(() => killProcess(command, childProcess, signal)));
521
- yield* signalGroup(options?.killSignal ?? "SIGTERM");
522
- if (Predicate.isUndefined(options?.forceKillAfter)) {
523
- yield* awaitProcessExit(childProcess, exitSignal, processGroupGraceMillis);
524
- } else {
525
- yield* awaitProcessExit(childProcess, exitSignal, Duration.toMillis(options.forceKillAfter));
526
- if (isProcessAlive(childProcess, exitSignal)) {
527
- yield* signalGroup("SIGKILL");
528
- yield* awaitProcessExit(childProcess, exitSignal, processGroupGraceMillis);
529
- }
530
- }
531
- yield* Deferred.await(exitSignal);
532
- });
533
- const getSourceStream = (handle, from) => {
534
- const fromOption = from ?? "stdout";
535
- switch (fromOption) {
536
- case "stdout":
537
- return handle.stdout;
538
- case "stderr":
539
- return handle.stderr;
540
- case "all":
541
- return handle.all;
542
- default: {
543
- const fd = ChildProcess.parseFdName(fromOption);
544
- if (Predicate.isNotUndefined(fd)) {
545
- return handle.getOutputFd(fd);
546
- }
547
- return handle.stdout;
548
- }
549
- }
550
- };
551
- const spawnCommand = Effect3.fnUntraced(function* (cmd) {
552
- switch (cmd._tag) {
553
- case "StandardCommand": {
554
- const stdinConfig = resolveStdinOption(cmd.options);
555
- const stdoutConfig = resolveOutputOption(cmd.options, "stdout");
556
- const stderrConfig = resolveOutputOption(cmd.options, "stderr");
557
- const resolvedAdditionalFds = resolveAdditionalFds(cmd.options);
558
- let isReferenced = true;
559
- const cwd = yield* resolveWorkingDirectory(cmd.options);
560
- const env = resolveEnvironment(cmd.options);
561
- const stdio = buildStdioArray(stdinConfig, stdoutConfig, stderrConfig, resolvedAdditionalFds);
562
- const [childProcess, exitSignal] = yield* Effect3.acquireRelease(spawn2(cmd, buildSpawnOptions(cmd.options, {
563
- cwd,
564
- env,
565
- stdio
566
- }, process.platform)), Effect3.fnUntraced(function* ([childProcess, exitSignal]) {
567
- const exited = yield* Deferred.isDone(exitSignal);
568
- if (exited) {
569
- const [code] = yield* Deferred.await(exitSignal);
570
- if (code !== 0 && Predicate.isNotNull(code)) {
571
- yield* Effect3.ignore(terminateProcessGroup(cmd, childProcess, exitSignal, cmd.options));
572
- } else if (isReferenced && process.platform !== "win32" && cmd.options.detached !== false) {
573
- yield* Effect3.ignore(terminateProcessGroup(cmd, childProcess, exitSignal, cmd.options));
574
- }
575
- return;
576
- }
577
- if (!isReferenced) {
578
- return;
579
- }
580
- yield* Effect3.ignore(terminateProcessGroup(cmd, childProcess, exitSignal, cmd.options));
581
- }));
582
- const pid = ProcessId(childProcess.pid);
583
- childProcess.on("exit", (code) => {
584
- if (code !== 0 && Predicate.isNotNull(code)) {
585
- killProcessGroupOnExit(childProcess, cmd.options.killSignal ?? "SIGTERM");
586
- }
587
- });
588
- const reref = Effect3.sync(() => {
589
- if (!isReferenced) {
590
- childProcess.ref();
591
- isReferenced = true;
592
- }
593
- });
594
- const unref = Effect3.sync(() => {
595
- if (isReferenced) {
596
- childProcess.unref();
597
- isReferenced = false;
598
- }
599
- return reref;
600
- });
601
- const stdin = yield* setupChildStdin(cmd, childProcess, stdinConfig);
602
- const {
603
- all,
604
- stderr,
605
- stdout
606
- } = setupChildOutputStreams(cmd, childProcess, stdoutConfig, stderrConfig);
607
- const {
608
- getInputFd,
609
- getOutputFd
610
- } = yield* setupAdditionalFds(cmd, childProcess, resolvedAdditionalFds);
611
- const isRunning = Effect3.map(Deferred.isDone(exitSignal), (done) => !done);
612
- const exitCode = Effect3.flatMap(Deferred.await(exitSignal), ([code, signal]) => {
613
- if (Predicate.isNotNull(code)) {
614
- return Effect3.succeed(ExitCode(code));
615
- }
616
- const error = new globalThis.Error(`Process interrupted due to receipt of signal: '${signal}'`);
617
- return Effect3.fail(toPlatformError("exitCode", error, cmd));
618
- });
619
- const kill = (options) => terminateProcessGroup(cmd, childProcess, exitSignal, options);
620
- return makeHandle({
621
- pid,
622
- exitCode,
623
- isRunning,
624
- kill,
625
- stdin,
626
- stdout,
627
- stderr,
628
- all,
629
- getInputFd,
630
- getOutputFd,
631
- unref
632
- });
633
- }
634
- case "PipedCommand": {
635
- const {
636
- commands,
637
- pipeOptions
638
- } = flattenCommand(cmd);
639
- const [root, ...pipeline] = commands;
640
- const handles = [yield* spawnCommand(root)];
641
- for (let i = 0;i < pipeline.length; i++) {
642
- const command = pipeline[i];
643
- const options = pipeOptions[i] ?? {};
644
- const stdinConfig = resolveStdinOption(command.options);
645
- const sourceStream = Stream2.unwrap(Effect3.succeed(getSourceStream(handles[handles.length - 1], options.from)));
646
- const toOption = options.to ?? "stdin";
647
- if (toOption === "stdin") {
648
- handles.push(yield* spawnCommand(ChildProcess.make(command.command, command.args, {
649
- ...command.options,
650
- stdin: {
651
- ...stdinConfig,
652
- stream: sourceStream
653
- }
654
- })));
655
- } else {
656
- const fd = ChildProcess.parseFdName(toOption);
657
- if (Predicate.isNotUndefined(fd)) {
658
- const fdName2 = ChildProcess.fdName(fd);
659
- const existingFds = command.options.additionalFds ?? {};
660
- handles.push(yield* spawnCommand(ChildProcess.make(command.command, command.args, {
661
- ...command.options,
662
- additionalFds: {
663
- ...existingFds,
664
- [fdName2]: {
665
- type: "input",
666
- stream: sourceStream
667
- }
668
- }
669
- })));
670
- } else {
671
- handles.push(yield* spawnCommand(ChildProcess.make(command.command, command.args, {
672
- ...command.options,
673
- stdin: {
674
- ...stdinConfig,
675
- stream: sourceStream
676
- }
677
- })));
678
- }
679
- }
680
- }
681
- const handle = handles[handles.length - 1];
682
- const kill = (options) => Effect3.forEach([...handles].reverse(), (handle) => Effect3.ignore(handle.kill(options)), {
683
- discard: true
684
- });
685
- const unref = Effect3.gen(function* () {
686
- const rerefs = [];
687
- for (const handle of handles) {
688
- rerefs.push(yield* handle.unref);
689
- }
690
- return Effect3.forEach([...rerefs].reverse(), (reref) => reref, {
691
- discard: true
692
- });
693
- });
694
- return makeHandle({
695
- pid: handle.pid,
696
- exitCode: handle.exitCode,
697
- isRunning: handle.isRunning,
698
- kill,
699
- stdin: handles[0].stdin,
700
- stdout: handle.stdout,
701
- stderr: handle.stderr,
702
- all: handle.all,
703
- getInputFd: handle.getInputFd,
704
- getOutputFd: handle.getOutputFd,
705
- unref
706
- });
707
- }
708
- }
709
- });
710
- return makeSpawner(spawnCommand);
711
- });
712
- var layer = /* @__PURE__ */ Layer.effect(ChildProcessSpawner, make3);
713
- var flattenCommand = (command) => {
714
- const commands = [];
715
- const pipeOptions = [];
716
- const flatten = (cmd) => {
717
- switch (cmd._tag) {
718
- case "StandardCommand": {
719
- commands.push(cmd);
720
- break;
721
- }
722
- case "PipedCommand": {
723
- flatten(cmd.left);
724
- pipeOptions.push(cmd.options);
725
- flatten(cmd.right);
726
- break;
727
- }
728
- }
729
- };
730
- flatten(command);
731
- if (commands.length === 0) {
732
- throw new Error("flattenCommand produced empty commands array");
733
- }
734
- const [first, ...rest] = commands;
735
- const nonEmptyCommands = [first, ...rest];
736
- return {
737
- commands: nonEmptyCommands,
738
- pipeOptions
739
- };
740
- };
741
-
742
- // ../../node_modules/.pnpm/@effect+platform-node-shared@4.0.2_effect@4.0.2/node_modules/@effect/platform-node-shared/dist/NodeFileSystem.js
743
- import * as BI from "effect/BigInt";
744
- import * as ByteSize2 from "effect/ByteSize";
745
- import * as Cause3 from "effect/Cause";
746
- import * as Effect4 from "effect/Effect";
747
- import { effectify } from "effect/Effect";
748
- import * as FileSystem3 from "effect/FileSystem";
749
- import { pipe } from "effect/Function";
750
- import * as Layer2 from "effect/Layer";
751
- import * as Option2 from "effect/Option";
752
- import * as Error2 from "effect/PlatformError";
753
- import * as Queue from "effect/Queue";
754
- import * as Stream3 from "effect/Stream";
755
- import * as Crypto from "crypto";
756
- import * as NFS from "fs";
757
- import * as OS from "os";
758
- import * as Path3 from "path";
759
- var handleBadArgument = (method) => (err) => Error2.badArgument({
760
- module: "FileSystem",
761
- method,
762
- description: err.message ?? String(err)
763
- });
764
- var bigintToNumber = (value, field) => {
765
- const number = Number(value);
766
- if (!Number.isSafeInteger(number)) {
767
- throw new RangeError(`${field} exceeds the safe integer range: ${value}`);
768
- }
769
- return number;
770
- };
771
- var bigintToNumberOption = (value) => Option2.flatMap(Option2.fromNullishOr(value), BI.toNumber);
772
- var positionToNumber = (position, method) => Effect4.try({
773
- try: () => bigintToNumber(position, "position"),
774
- catch: handleBadArgument(method)
775
- });
776
- var access2 = /* @__PURE__ */ (() => {
777
- const nodeAccess = /* @__PURE__ */ effectify(NFS.access, /* @__PURE__ */ handleErrnoException("FileSystem", "access"), /* @__PURE__ */ handleBadArgument("access"));
778
- return (path, options) => {
779
- let mode = NFS.constants.F_OK;
780
- if (options?.readable) {
781
- mode |= NFS.constants.R_OK;
782
- }
783
- if (options?.writable) {
784
- mode |= NFS.constants.W_OK;
785
- }
786
- return nodeAccess(path, mode);
787
- };
788
- })();
789
- var copy = /* @__PURE__ */ (() => {
790
- const nodeCp = /* @__PURE__ */ effectify(NFS.cp, /* @__PURE__ */ handleErrnoException("FileSystem", "copy"), /* @__PURE__ */ handleBadArgument("copy"));
791
- return (fromPath, toPath, options) => nodeCp(fromPath, toPath, {
792
- force: options?.overwrite ?? false,
793
- preserveTimestamps: options?.preserveTimestamps ?? false,
794
- recursive: true
795
- });
796
- })();
797
- var copyFile2 = /* @__PURE__ */ (() => {
798
- const nodeCopyFile = /* @__PURE__ */ effectify(NFS.copyFile, /* @__PURE__ */ handleErrnoException("FileSystem", "copyFile"), /* @__PURE__ */ handleBadArgument("copyFile"));
799
- return (fromPath, toPath) => nodeCopyFile(fromPath, toPath);
800
- })();
801
- var chmod2 = /* @__PURE__ */ (() => {
802
- const nodeChmod = /* @__PURE__ */ effectify(NFS.chmod, /* @__PURE__ */ handleErrnoException("FileSystem", "chmod"), /* @__PURE__ */ handleBadArgument("chmod"));
803
- return (path, mode) => nodeChmod(path, mode);
804
- })();
805
- var chown2 = /* @__PURE__ */ (() => {
806
- const nodeChown = /* @__PURE__ */ effectify(NFS.chown, /* @__PURE__ */ handleErrnoException("FileSystem", "chown"), /* @__PURE__ */ handleBadArgument("chown"));
807
- return (path, uid, gid) => nodeChown(path, uid, gid);
808
- })();
809
- var glob2 = /* @__PURE__ */ (() => {
810
- const nodeGlob = /* @__PURE__ */ effectify(NFS.glob, /* @__PURE__ */ handleErrnoException("FileSystem", "glob"), /* @__PURE__ */ handleBadArgument("glob"));
811
- return (pattern, options) => nodeGlob(pattern, {
812
- cwd: options?.root,
813
- exclude: options?.exclude
814
- });
815
- })();
816
- var link2 = /* @__PURE__ */ (() => {
817
- const nodeLink = /* @__PURE__ */ effectify(NFS.link, /* @__PURE__ */ handleErrnoException("FileSystem", "link"), /* @__PURE__ */ handleBadArgument("link"));
818
- return (existingPath, newPath) => nodeLink(existingPath, newPath);
819
- })();
820
- var makeDirectory = /* @__PURE__ */ (() => {
821
- const nodeMkdir = /* @__PURE__ */ effectify(NFS.mkdir, /* @__PURE__ */ handleErrnoException("FileSystem", "makeDirectory"), /* @__PURE__ */ handleBadArgument("makeDirectory"));
822
- return (path, options) => nodeMkdir(path, {
823
- recursive: options?.recursive ?? false,
824
- mode: options?.mode
825
- });
826
- })();
827
- var makeTempDirectoryFactory = (method) => {
828
- const nodeMkdtemp = effectify(NFS.mkdtemp, handleErrnoException("FileSystem", method), handleBadArgument(method));
829
- return (options) => Effect4.suspend(() => {
830
- const prefix = options?.prefix ?? "";
831
- const directory = typeof options?.directory === "string" ? Path3.join(options.directory, ".") : OS.tmpdir();
832
- return nodeMkdtemp(prefix ? Path3.join(directory, prefix) : directory + "/");
833
- });
834
- };
835
- var makeTempDirectory = /* @__PURE__ */ makeTempDirectoryFactory("makeTempDirectory");
836
- var removeFactory = (method) => {
837
- const nodeRm = effectify(NFS.rm, handleErrnoException("FileSystem", method), handleBadArgument(method));
838
- return (path, options) => nodeRm(path, {
839
- recursive: options?.recursive ?? false,
840
- force: options?.force ?? false
841
- });
842
- };
843
- var remove = /* @__PURE__ */ removeFactory("remove");
844
- var makeTempDirectoryScoped = /* @__PURE__ */ (() => {
845
- const makeDirectory = /* @__PURE__ */ makeTempDirectoryFactory("makeTempDirectoryScoped");
846
- const removeDirectory = /* @__PURE__ */ removeFactory("makeTempDirectoryScoped");
847
- return (options) => Effect4.acquireRelease(makeDirectory(options), (directory) => Effect4.orDie(removeDirectory(directory, {
848
- recursive: true
849
- })));
850
- })();
851
- var openFactory = (method) => {
852
- const nodeOpen = effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
853
- const nodeClose = effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
854
- return (path, options) => pipe(Effect4.acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) => Effect4.orDie(nodeClose(fd))), Effect4.map((fd) => makeFile(fd, options?.flag?.startsWith("a") ?? false)));
855
- };
856
- var open2 = /* @__PURE__ */ openFactory("open");
857
- var makeFile = /* @__PURE__ */ (() => {
858
- const nodeReadFactory = (method) => effectify(NFS.read, handleErrnoException("FileSystem", method), handleBadArgument(method));
859
- const nodeRead = /* @__PURE__ */ nodeReadFactory("read");
860
- const nodeReadAlloc = /* @__PURE__ */ nodeReadFactory("readAlloc");
861
- const nodeStat = /* @__PURE__ */ effectify(NFS.fstat, /* @__PURE__ */ handleErrnoException("FileSystem", "stat"), /* @__PURE__ */ handleBadArgument("stat"));
862
- const nodeTruncate = /* @__PURE__ */ effectify(NFS.ftruncate, /* @__PURE__ */ handleErrnoException("FileSystem", "truncate"), /* @__PURE__ */ handleBadArgument("truncate"));
863
- const nodeSync = /* @__PURE__ */ effectify(NFS.fsync, /* @__PURE__ */ handleErrnoException("FileSystem", "sync"), /* @__PURE__ */ handleBadArgument("sync"));
864
- const nodeWriteFactory = (method) => effectify(NFS.write, handleErrnoException("FileSystem", method), handleBadArgument(method));
865
- const nodeWrite = /* @__PURE__ */ nodeWriteFactory("write");
866
- const nodeWriteAll = /* @__PURE__ */ nodeWriteFactory("writeAll");
867
-
868
- class FileImpl {
869
- [FileSystem3.FileTypeId];
870
- fd;
871
- append;
872
- position = /* @__PURE__ */ BigInt(0);
873
- constructor(fd, append) {
874
- this[FileSystem3.FileTypeId] = FileSystem3.FileTypeId;
875
- this.fd = fd;
876
- this.append = append;
877
- }
878
- get stat() {
879
- return Effect4.flatMap(nodeStat(this.fd, {
880
- bigint: true
881
- }), makeFileInfo);
882
- }
883
- get sync() {
884
- return nodeSync(this.fd);
885
- }
886
- seek(offset, from) {
887
- return Effect4.suspend(() => {
888
- const position = from === "start" ? offset : this.position + offset;
889
- if (position < BigInt(0)) {
890
- return Effect4.fail(Error2.badArgument({
891
- module: "FileSystem",
892
- method: "seek",
893
- description: "Cannot seek before the start of the file"
894
- }));
895
- }
896
- this.position = position;
897
- return Effect4.succeed(position);
898
- });
899
- }
900
- read(buffer) {
901
- return Effect4.suspend(() => {
902
- const position = this.position;
903
- return Effect4.map(nodeRead(this.fd, {
904
- buffer,
905
- position
906
- }), (bytesRead) => {
907
- this.position = position + BigInt(bytesRead);
908
- return bytesRead;
909
- });
910
- });
911
- }
912
- readAlloc(size) {
913
- return Effect4.suspend(() => {
914
- try {
915
- if (!Number.isInteger(size) || size < 0) {
916
- throw new RangeError("size must be a non-negative integer");
917
- }
918
- const buffer = Buffer.allocUnsafeSlow(size);
919
- const position = this.position;
920
- return Effect4.map(nodeReadAlloc(this.fd, {
921
- buffer,
922
- position
923
- }), (bytesRead) => {
924
- if (bytesRead === 0) {
925
- return Option2.none();
926
- }
927
- this.position = position + BigInt(bytesRead);
928
- if (bytesRead === size) {
929
- return Option2.some(buffer);
930
- }
931
- const dst = Buffer.allocUnsafeSlow(bytesRead);
932
- buffer.copy(dst, 0, 0, bytesRead);
933
- return Option2.some(dst);
934
- });
935
- } catch (cause) {
936
- return Effect4.fail(handleBadArgument("readAlloc")(cause));
937
- }
938
- });
939
- }
940
- truncate(length) {
941
- return Effect4.map(nodeTruncate(this.fd, length || undefined), () => {
942
- if (!this.append) {
943
- const len = BigInt(length ?? 0);
944
- if (this.position > len) {
945
- this.position = len;
946
- }
947
- }
948
- });
949
- }
950
- write(buffer) {
951
- return Effect4.suspend(() => {
952
- const position = this.position;
953
- return Effect4.flatMap(this.append ? Effect4.succeed(undefined) : positionToNumber(position, "write"), (nodePosition) => Effect4.map(nodeWrite(this.fd, buffer, undefined, undefined, nodePosition), (bytesWritten) => {
954
- if (!this.append) {
955
- this.position = position + BigInt(bytesWritten);
956
- }
957
- return bytesWritten;
958
- }));
959
- });
960
- }
961
- writeAllChunk(buffer) {
962
- return Effect4.suspend(() => {
963
- const position = this.position;
964
- return Effect4.flatMap(this.append ? Effect4.succeed(undefined) : positionToNumber(position, "writeAll"), (nodePosition) => Effect4.flatMap(nodeWriteAll(this.fd, buffer, undefined, undefined, nodePosition), (bytesWritten) => {
965
- if (bytesWritten === 0) {
966
- return Effect4.fail(Error2.systemError({
967
- module: "FileSystem",
968
- method: "writeAll",
969
- _tag: "WriteZero",
970
- pathOrDescriptor: this.fd,
971
- description: "write returned 0 bytes written"
972
- }));
973
- }
974
- if (!this.append) {
975
- this.position = position + BigInt(bytesWritten);
976
- }
977
- return bytesWritten < buffer.length ? this.writeAllChunk(buffer.subarray(bytesWritten)) : Effect4.void;
978
- }));
979
- });
980
- }
981
- writeAll(buffer) {
982
- return buffer.length === 0 ? Effect4.void : this.writeAllChunk(buffer);
983
- }
984
- }
985
- return (fd, append) => new FileImpl(fd, append);
986
- })();
987
- var makeTempFileFactory = (method) => {
988
- const makeDirectory = makeTempDirectoryFactory(method);
989
- return Effect4.fnUntraced(function* (options) {
990
- const directory = yield* makeDirectory(options);
991
- const random = Crypto.randomBytes(6).toString("hex");
992
- const name = Path3.join(directory, options?.suffix ? `${random}${options.suffix}` : random);
993
- yield* writeFile2(name, new Uint8Array(0));
994
- return name;
995
- });
996
- };
997
- var makeTempFile = /* @__PURE__ */ makeTempFileFactory("makeTempFile");
998
- var makeTempFileScoped = /* @__PURE__ */ (() => {
999
- const makeFile = /* @__PURE__ */ makeTempFileFactory("makeTempFileScoped");
1000
- const removeDirectory = /* @__PURE__ */ removeFactory("makeTempFileScoped");
1001
- return (options) => Effect4.acquireRelease(makeFile(options), (file) => Effect4.orDie(removeDirectory(Path3.dirname(file), {
1002
- recursive: true
1003
- })));
1004
- })();
1005
- var readDirectory = (path, options) => Effect4.tryPromise({
1006
- try: () => NFS.promises.readdir(path, options),
1007
- catch: (err) => handleErrnoException("FileSystem", "readDirectory")(err, [path])
1008
- });
1009
- var readFile2 = (path) => Effect4.callback((resume, signal) => {
1010
- try {
1011
- NFS.readFile(path, {
1012
- signal
1013
- }, (err, data) => {
1014
- if (err) {
1015
- resume(Effect4.fail(handleErrnoException("FileSystem", "readFile")(err, [path])));
1016
- } else {
1017
- resume(Effect4.succeed(data));
1018
- }
1019
- });
1020
- } catch (err) {
1021
- resume(Effect4.fail(handleBadArgument("readFile")(err)));
1022
- }
1023
- });
1024
- var readLink = /* @__PURE__ */ (() => {
1025
- const nodeReadLink = /* @__PURE__ */ effectify(NFS.readlink, /* @__PURE__ */ handleErrnoException("FileSystem", "readLink"), /* @__PURE__ */ handleBadArgument("readLink"));
1026
- return (path) => nodeReadLink(path);
1027
- })();
1028
- var realPath = /* @__PURE__ */ (() => {
1029
- const nodeRealPath = /* @__PURE__ */ effectify(NFS.realpath, /* @__PURE__ */ handleErrnoException("FileSystem", "realPath"), /* @__PURE__ */ handleBadArgument("realPath"));
1030
- return (path) => nodeRealPath(path);
1031
- })();
1032
- var rename2 = /* @__PURE__ */ (() => {
1033
- const nodeRename = /* @__PURE__ */ effectify(NFS.rename, /* @__PURE__ */ handleErrnoException("FileSystem", "rename"), /* @__PURE__ */ handleBadArgument("rename"));
1034
- return (oldPath, newPath) => nodeRename(oldPath, newPath);
1035
- })();
1036
- var makeFileInfo = (stat) => Effect4.try({
1037
- try: () => ({
1038
- type: stat.isFile() ? "File" : stat.isDirectory() ? "Directory" : stat.isSymbolicLink() ? "SymbolicLink" : stat.isBlockDevice() ? "BlockDevice" : stat.isCharacterDevice() ? "CharacterDevice" : stat.isFIFO() ? "FIFO" : stat.isSocket() ? "Socket" : "Unknown",
1039
- mtime: Option2.fromNullishOr(stat.mtime),
1040
- atime: Option2.fromNullishOr(stat.atime),
1041
- birthtime: Option2.fromNullishOr(stat.birthtime),
1042
- dev: bigintToNumber(stat.dev, "dev"),
1043
- rdev: bigintToNumberOption(stat.rdev),
1044
- ino: bigintToNumberOption(stat.ino),
1045
- mode: bigintToNumber(stat.mode, "mode"),
1046
- nlink: bigintToNumberOption(stat.nlink),
1047
- uid: bigintToNumberOption(stat.uid),
1048
- gid: bigintToNumberOption(stat.gid),
1049
- size: ByteSize2.bytes(stat.size),
1050
- blksize: stat.blksize !== undefined ? Option2.some(ByteSize2.bytes(stat.blksize)) : Option2.none(),
1051
- blocks: bigintToNumberOption(stat.blocks)
1052
- }),
1053
- catch: handleBadArgument("stat")
1054
- });
1055
- var stat2 = /* @__PURE__ */ (() => {
1056
- const nodeStat = /* @__PURE__ */ effectify(NFS.stat, /* @__PURE__ */ handleErrnoException("FileSystem", "stat"), /* @__PURE__ */ handleBadArgument("stat"));
1057
- return (path) => Effect4.flatMap(nodeStat(path, {
1058
- bigint: true
1059
- }), makeFileInfo);
1060
- })();
1061
- var symlink2 = /* @__PURE__ */ (() => {
1062
- const nodeSymlink = /* @__PURE__ */ effectify(NFS.symlink, /* @__PURE__ */ handleErrnoException("FileSystem", "symlink"), /* @__PURE__ */ handleBadArgument("symlink"));
1063
- return (target, path) => nodeSymlink(target, path);
1064
- })();
1065
- var truncate2 = /* @__PURE__ */ (() => {
1066
- const nodeTruncate = /* @__PURE__ */ effectify(NFS.truncate, /* @__PURE__ */ handleErrnoException("FileSystem", "truncate"), /* @__PURE__ */ handleBadArgument("truncate"));
1067
- return (path, length) => nodeTruncate(path, length);
1068
- })();
1069
- var utimes2 = /* @__PURE__ */ (() => {
1070
- const nodeUtimes = /* @__PURE__ */ effectify(NFS.utimes, /* @__PURE__ */ handleErrnoException("FileSystem", "utime"), /* @__PURE__ */ handleBadArgument("utime"));
1071
- return (path, atime, mtime) => nodeUtimes(path, atime, mtime);
1072
- })();
1073
- var watchNode = (path, info, options) => Stream3.callback((queue) => Effect4.acquireRelease(Effect4.sync(() => {
1074
- const directory = info.type === "Directory" ? path : Path3.dirname(path);
1075
- const watcher = NFS.watch(path, {
1076
- recursive: options?.recursive ?? false
1077
- }, (event, path) => {
1078
- if (!path)
1079
- return;
1080
- switch (event) {
1081
- case "rename": {
1082
- Effect4.runFork(Effect4.matchEffect(stat2(Path3.resolve(directory, path)), {
1083
- onSuccess: (_) => Queue.offer(queue, {
1084
- _tag: "Create",
1085
- path
1086
- }),
1087
- onFailure: (_) => Queue.offer(queue, {
1088
- _tag: "Remove",
1089
- path
1090
- })
1091
- }));
1092
- return;
1093
- }
1094
- case "change": {
1095
- Queue.offerUnsafe(queue, {
1096
- _tag: "Update",
1097
- path
1098
- });
1099
- return;
1100
- }
1101
- }
1102
- });
1103
- watcher.on("error", (error) => {
1104
- Queue.failCauseUnsafe(queue, Cause3.fail(Error2.systemError({
1105
- module: "FileSystem",
1106
- _tag: "Unknown",
1107
- method: "watch",
1108
- pathOrDescriptor: path,
1109
- cause: error
1110
- })));
1111
- });
1112
- watcher.on("close", () => {
1113
- Queue.endUnsafe(queue);
1114
- });
1115
- return watcher;
1116
- }), (watcher) => Effect4.sync(() => watcher.close())));
1117
- var watch2 = (backend, path, options) => stat2(path).pipe(Effect4.map((stat) => backend.pipe(Option2.flatMap((_) => _.register(path, stat, options)), Option2.getOrElse(() => watchNode(path, stat, options)))), Stream3.unwrap);
1118
- var writeFile2 = (path, data, options) => Effect4.callback((resume, signal) => {
1119
- try {
1120
- NFS.writeFile(path, data, {
1121
- signal,
1122
- flag: options?.flag,
1123
- mode: options?.mode
1124
- }, (err) => {
1125
- if (err) {
1126
- resume(Effect4.fail(handleErrnoException("FileSystem", "writeFile")(err, [path])));
1127
- } else {
1128
- resume(Effect4.void);
1129
- }
1130
- });
1131
- } catch (err) {
1132
- resume(Effect4.fail(handleBadArgument("writeFile")(err)));
1133
- }
1134
- });
1135
- var makeFileSystem = /* @__PURE__ */ Effect4.map(/* @__PURE__ */ Effect4.serviceOption(FileSystem3.WatchBackend), (backend) => FileSystem3.make({
1136
- access: access2,
1137
- chmod: chmod2,
1138
- chown: chown2,
1139
- copy,
1140
- copyFile: copyFile2,
1141
- glob: glob2,
1142
- link: link2,
1143
- makeDirectory,
1144
- makeTempDirectory,
1145
- makeTempDirectoryScoped,
1146
- makeTempFile,
1147
- makeTempFileScoped,
1148
- open: open2,
1149
- readDirectory,
1150
- readFile: readFile2,
1151
- readLink,
1152
- realPath,
1153
- remove,
1154
- rename: rename2,
1155
- stat: stat2,
1156
- symlink: symlink2,
1157
- truncate: truncate2,
1158
- utimes: utimes2,
1159
- watch(path, options) {
1160
- return watch2(backend, path, options);
1161
- },
1162
- writeFile: writeFile2
1163
- }));
1164
- var layer2 = /* @__PURE__ */ Layer2.effect(FileSystem3.FileSystem)(makeFileSystem);
1165
-
1166
- // ../../node_modules/.pnpm/@effect+platform-node-shared@4.0.2_effect@4.0.2/node_modules/@effect/platform-node-shared/dist/NodePath.js
1167
- import * as Effect5 from "effect/Effect";
1168
- import * as Layer3 from "effect/Layer";
1169
- import { Path as Path4, TypeId } from "effect/Path";
1170
- import { BadArgument } from "effect/PlatformError";
1171
- import * as NodePath from "path";
1172
- import * as NodeUrl from "url";
1173
- var fileUrlOps = (windows) => ({
1174
- fromFileUrl: (url) => Effect5.try({
1175
- try: () => NodeUrl.fileURLToPath(url, {
1176
- windows
1177
- }),
1178
- catch: (cause) => new BadArgument({
1179
- module: "Path",
1180
- method: "fromFileUrl",
1181
- cause
1182
- })
1183
- }),
1184
- toFileUrl: (path) => Effect5.try({
1185
- try: () => NodeUrl.pathToFileURL(path, {
1186
- windows
1187
- }),
1188
- catch: (cause) => new BadArgument({
1189
- module: "Path",
1190
- method: "toFileUrl",
1191
- cause
1192
- })
1193
- })
1194
- });
1195
- var layerPosix = /* @__PURE__ */ Layer3.succeed(Path4)({
1196
- [TypeId]: TypeId,
1197
- ...NodePath.posix,
1198
- .../* @__PURE__ */ fileUrlOps(false)
1199
- });
1200
- var layerWin32 = /* @__PURE__ */ Layer3.succeed(Path4)({
1201
- [TypeId]: TypeId,
1202
- ...NodePath.win32,
1203
- .../* @__PURE__ */ fileUrlOps(true)
1204
- });
1205
- var layer3 = /* @__PURE__ */ Layer3.succeed(Path4)({
1206
- [TypeId]: TypeId,
1207
- ...NodePath,
1208
- .../* @__PURE__ */ fileUrlOps(undefined)
1209
- });
1210
-
1211
- // ../plugin-harnesses/src/node-platform.ts
1212
- import { Layer as Layer4 } from "effect";
1213
- var nodePlatform = layer.pipe(Layer4.provideMerge(Layer4.merge(layer2, layer3)));
1214
-
1215
- // ../plugin-harnesses/src/subscriptions/cursor.ts
1216
- import { Effect as Effect9, Predicate as Predicate4 } from "effect";
1217
-
1218
- // ../plugin-harnesses/src/subscriptions/index.ts
1219
- import { capture } from "@vibest/plugin/effect";
1220
- import { Effect as Effect8, Schema as Schema4 } from "effect";
1221
- import * as ChildProcessSpawner2 from "effect/process/ChildProcessSpawner";
1222
-
1223
- // ../plugin-harnesses/src/subscriptions/claude.ts
1224
- import { Effect as Effect6, Predicate as Predicate2 } from "effect";
1225
- // ../plugin-harnesses/src/subscriptions/pi.ts
1226
- import { Effect as Effect7, Predicate as Predicate3 } from "effect";
1227
-
1228
- // ../plugin-harnesses/src/subscriptions/index.ts
1229
- var isJsonObject = Schema4.is(Schema4.JsonObject);
1230
- var record = (u) => isJsonObject(u) ? u : undefined;
1231
- var CLI_TIMEOUT = "10 seconds";
1232
- var parseJson = (text) => {
1233
- if (text === undefined || text.trim() === "")
1234
- return;
1235
- try {
1236
- return JSON.parse(text);
1237
- } catch {
1238
- return;
1239
- }
1240
- };
1241
- var runCli = (spawner, command, args, cwd) => capture(command, args, {
1242
- stdin: "ignore",
1243
- cwd,
1244
- env: { HOME: cwd },
1245
- extendEnv: true,
1246
- timeout: CLI_TIMEOUT
1247
- }).pipe(Effect8.provideService(ChildProcessSpawner2.ChildProcessSpawner, spawner), Effect8.map((run) => run === undefined ? undefined : run.stdout), Effect8.orElseSucceed(() => {
1248
- return;
1249
- }));
1250
-
1251
- // ../plugin-harnesses/src/subscriptions/cursor.ts
1252
- var cursorAccount = (status, about) => {
1253
- if (record(status)?.isAuthenticated !== true)
1254
- return { kind: "none" };
1255
- const tier = record(about)?.subscriptionTier;
1256
- return Predicate4.isString(tier) ? { kind: "subscription", plan: tier } : { kind: "subscription" };
1257
- };
1258
- var cursorSubscription = (spawner) => (home, problem) => Effect9.gen(function* () {
1259
- if (problem)
1260
- return [{ provider: "", error: problem }];
1261
- const status = parseJson(yield* runCli(spawner, "cursor-agent", ["status", "--format", "json"], home));
1262
- if (status === undefined)
1263
- return [{ provider: "", error: "cursor-agent status failed" }];
1264
- const account = cursorAccount(status, parseJson(yield* runCli(spawner, "cursor-agent", ["about", "--format", "json"], home)));
1265
- return [{ provider: "", account, limits: [] }];
1266
- });
1267
-
1268
- // ../plugin-harnesses/src/cursor.ts
1269
- var cursorModels = (lines) => {
1270
- if (!lines.some((l) => l.startsWith("Available models")))
1271
- return;
1272
- return lines.flatMap((l) => {
1273
- const m = /^(\S+) - (.+?)(?: \(([^)]*)\))?$/.exec(l.trim());
1274
- return m ? [{ model: m[1], name: m[2], default: (m[3] ?? "").split(/,\s*/).includes("current") }] : [];
1275
- });
1276
- };
1277
- var keychainProblem = (home) => Effect10.gen(function* () {
1278
- if (process.platform !== "darwin")
1279
- return;
1280
- const fs = yield* FileSystem5.FileSystem;
1281
- const path = yield* Path5.Path;
1282
- const keychain = path.join(home, "Library", "Keychains", "login.keychain-db");
1283
- const present = home !== "" && (yield* fs.stat(keychain).pipe(Effect10.map((info) => info.type === "File"), Effect10.orElseSucceed(() => false)));
1284
- return present ? undefined : `Cursor is disabled: HOME has no login keychain file (${keychain}); use the macOS login home to avoid Cursor's keychain probe dialog`;
1285
- });
1286
- var cursorEnvironment = (home) => keychainProblem(home).pipe(Effect10.provide(nodePlatform));
1287
- var cursor = {
1288
- id: "cursor",
1289
- binary: "cursor-agent",
1290
- checkEnvironment: cursorEnvironment,
1291
- delivery: "typed",
1292
- ownSessionId: false,
1293
- systemPromptInPrompt: true,
1294
- interruptKey: "ctrl+c",
1295
- replyField: "text",
1296
- ready: "runtime",
1297
- promptArgs: ["--"],
1298
- clearKeys: ["ctrl+u"],
1299
- checkProvider: noProvider("cursor"),
1300
- launchArgs: (i) => [
1301
- ...i.resume && i.sessionId ? [`--resume=${i.sessionId}`] : [],
1302
- "--add-dir",
1303
- i.projectDir,
1304
- "--trust",
1305
- "--force",
1306
- "--plugin-dir",
1307
- i.pluginDir,
1308
- ...opt("--model", i.model)
1309
- ],
1310
- models: { args: () => ["models"], answer: cursorModels },
1311
- subscription: (home) => Effect10.gen(function* () {
1312
- const spawner = yield* Effect10.service(ChildProcessSpawner4.ChildProcessSpawner);
1313
- return yield* cursorSubscription(spawner)(home, yield* cursorEnvironment(home));
1314
- }).pipe(Effect10.provide(nodePlatform)),
1315
- guardAnswer: (reason) => reason ? { permission: "deny", user_message: reason, agent_message: reason } : { permission: "allow" },
1316
- conversationOf: (event) => Predicate5.isString(event.conversation_id) ? event.conversation_id : undefined,
1317
- userPrompt: (event) => {
1318
- if (event.hook_event_name === "afterAgentThought" || event.hook_event_name === "postToolUse")
1319
- return { text: "" };
1320
- if (event.hook_event_name !== "beforeSubmitPrompt" || !Predicate5.isString(event.prompt) || !event.prompt.trim())
1321
- return;
1322
- return { text: event.prompt };
1323
- },
1324
- executionEnd: (event) => event.hook_event_name === "afterAgentResponse" ? { end: event } : undefined
1325
- };
1326
-
1327
- // ../plugin-harnesses/src/harness-plugin.ts
1328
- import { Plugin } from "@vibest/plugin/effect";
1329
- import { Effect as Effect11 } from "effect";
1330
- import * as ChildProcessSpawner6 from "effect/process/ChildProcessSpawner";
1331
- var harnessPlugin = (definition, subscription) => Effect11.map(Effect11.service(ChildProcessSpawner6.ChildProcessSpawner), (spawner) => Plugin.define({
1332
- id: `harness-${definition.id}`,
1333
- effect: (ctx) => ctx.harness.transform((editor) => editor.add(subscription ? { ...definition, subscription: subscription(spawner) } : definition)).pipe(Effect11.asVoid)
1334
- }));
1335
-
1336
- // ../plugin-harnesses/src/cursor-plugin.ts
1337
- var cursor_plugin_default = Effect12.runSync(harnessPlugin(cursor).pipe(Effect12.provide(nodePlatform)));
1338
- export {
1339
- cursor_plugin_default as default
1340
- };