clanka 0.17.0 → 0.17.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 (62) hide show
  1. package/dist/Agent.d.ts +4 -0
  2. package/dist/Agent.d.ts.map +1 -1
  3. package/dist/Agent.js +5 -1
  4. package/dist/Agent.js.map +1 -1
  5. package/dist/Agent.test.js +35 -0
  6. package/dist/Agent.test.js.map +1 -1
  7. package/dist/AgentCallerConfig.test.js +5 -3
  8. package/dist/AgentCallerConfig.test.js.map +1 -1
  9. package/dist/ChunkRepo.d.ts +1 -1
  10. package/dist/ClaudeAgent.d.ts.map +1 -1
  11. package/dist/ClaudeAgent.js +46 -17
  12. package/dist/ClaudeAgent.js.map +1 -1
  13. package/dist/ClaudeAgent.test.js +87 -16
  14. package/dist/ClaudeAgent.test.js.map +1 -1
  15. package/dist/Compaction.test.js +2 -1
  16. package/dist/Compaction.test.js.map +1 -1
  17. package/dist/CompactionTokens.test.js +15 -8
  18. package/dist/CompactionTokens.test.js.map +1 -1
  19. package/dist/bin/{Effect-On-1ks2z.mjs → Effect-DNYYQ84C.mjs} +421 -367
  20. package/dist/bin/Effect-DNYYQ84C.mjs.map +1 -0
  21. package/dist/bin/Latch-BSlIwuxI.mjs +7 -0
  22. package/dist/bin/Latch-BSlIwuxI.mjs.map +1 -0
  23. package/dist/bin/{McpClient-iwrW83Si.mjs → McpClient-C7ctqJWo.mjs} +4 -5
  24. package/dist/bin/{McpClient-iwrW83Si.mjs.map → McpClient-C7ctqJWo.mjs.map} +1 -1
  25. package/dist/bin/{OutputFormatter-DeNaqhQM.mjs → OutputFormatter-DXej05JW.mjs} +8 -13
  26. package/dist/bin/{OutputFormatter-DeNaqhQM.mjs.map → OutputFormatter-DXej05JW.mjs.map} +1 -1
  27. package/dist/bin/{Schema-B3pFcw4E.mjs → Schema-CSQN_Zso.mjs} +754 -800
  28. package/dist/bin/Schema-CSQN_Zso.mjs.map +1 -0
  29. package/dist/bin/{SemanticSearch-BZIXkWYz.mjs → SemanticSearch-BiwCnpKX.mjs} +241 -148
  30. package/dist/bin/SemanticSearch-BiwCnpKX.mjs.map +1 -0
  31. package/dist/bin/{Stream-DCB3_nIX.mjs → Stream-Dwvj9X5X.mjs} +161 -116
  32. package/dist/bin/Stream-Dwvj9X5X.mjs.map +1 -0
  33. package/dist/bin/cli.mjs +4022 -3231
  34. package/dist/bin/cli.mjs.map +1 -1
  35. package/dist/bin/{helpers-BPLUsjsL.mjs → helpers-CljL9OKa.mjs} +143 -177
  36. package/dist/bin/helpers-CljL9OKa.mjs.map +1 -0
  37. package/dist/bin/index.min-ClUfQ5ji.mjs +3782 -0
  38. package/dist/bin/index.min-ClUfQ5ji.mjs.map +1 -0
  39. package/dist/bin/{rolldown-runtime-Cjv6nE1W.mjs → rolldown-runtime-5zChB7MF.mjs} +1 -2
  40. package/dist/bin/{server-CBmuybpI.mjs → server-HlLriZxF.mjs} +5 -7
  41. package/dist/bin/{server-CBmuybpI.mjs.map → server-HlLriZxF.mjs.map} +1 -1
  42. package/dist/bin/{turndown.cjs-cie0BXQQ.mjs → turndown.cjs-C2WBxeA-.mjs} +56 -110
  43. package/dist/bin/{turndown.cjs-cie0BXQQ.mjs.map → turndown.cjs-C2WBxeA-.mjs.map} +1 -1
  44. package/dist/bin/{types-RT_9fFNm.mjs → types-LcwjLVkt.mjs} +20 -38
  45. package/dist/bin/{types-RT_9fFNm.mjs.map → types-LcwjLVkt.mjs.map} +1 -1
  46. package/dist/bin/upgrade-BSNjCnra.mjs +342 -0
  47. package/dist/bin/upgrade-BSNjCnra.mjs.map +1 -0
  48. package/package.json +14 -20
  49. package/src/Agent.test.ts +69 -0
  50. package/src/Agent.ts +5 -1
  51. package/src/AgentCallerConfig.test.ts +5 -3
  52. package/src/ClaudeAgent.test.ts +120 -21
  53. package/src/ClaudeAgent.ts +59 -19
  54. package/src/Compaction.test.ts +2 -1
  55. package/src/CompactionTokens.test.ts +15 -11
  56. package/dist/bin/Effect-On-1ks2z.mjs.map +0 -1
  57. package/dist/bin/Schema-B3pFcw4E.mjs.map +0 -1
  58. package/dist/bin/SemanticSearch-BZIXkWYz.mjs.map +0 -1
  59. package/dist/bin/Stream-DCB3_nIX.mjs.map +0 -1
  60. package/dist/bin/helpers-BPLUsjsL.mjs.map +0 -1
  61. package/dist/bin/index.min-Bkz7vIWv.mjs +0 -3300
  62. package/dist/bin/index.min-Bkz7vIWv.mjs.map +0 -1
@@ -1,29 +1,29 @@
1
- import { $i as suspend$3, $r as doneUnsafe, Ai as exitZipRight, Bi as getCurrentFiber, Bn as matchEffect, Bo as isSome, Br as addFinalizer, Bt as scopedWith, Cc as dual, D as contextWith, Da as lastNonEmpty, Dt as provideService$2, E as context, Et as provideContext$2, Fi as fiberInterruptAs, Ft as runPromiseWith, G as forkChild, Gt as succeedNone$1, Ho as map$4, Hr as close, Ia as headUnsafe, Ii as fiberJoin, In as catchDone, Ji as onExitPrimitive, Jt as sync, K as forkIn, Kr as makeUnsafe$2, Kt as succeedSome, L as flatMap$2, Li as fiberRunIn, Ln as doneExitFromCause, M as exit, Mi as fiberInterrupt, N as fail$3, Ni as fiberInterruptAll, Oi as exitInterrupt$1, Os as toJson, Ot as raceFirst, P as failCause$3, Pi as fiberInterruptAllAs, Pt as runForkWith, Q as interrupt$2, Qi as succeedNone, R as flatMapEager, Ra as fail$4, Ri as flatMap$3, Rn as filterDone, Sa as isArrayNonEmpty, Sc as constant, Si as callback$2, Sr as squash, Tc as identity, U as forEach, Ua as isFailure, Ui as makeLatch, Un as nextPow2, V as fnUntraced, Vr as addFinalizerExit, W as forever, Wa as isSuccess$1, Wi as makeLatchUnsafe, Wo as none, Wr as forkUnsafe, Wt as succeed$3, X as gen, Xa as normalizeNonEmpty, Xs as hasProperty, Ya as normalize, Yt as tap$1, Zi as succeed$4, _o as get$1, _s as exitSucceed, _t as onError, a as andThen, ai as makeUnsafe$3, ar as findError, bi as andThen$1, bs as withFiber$1, bt as onInterrupt, c as as, ci as fail$5, cn as void_, cs as Done, di as interrupt$1, dn as withFiber, ea as sync$1, ei as interruptWith, en as tryPromise, fc as isString$1, fi as isExit$1, fs as args, gi as void_$2, go as empty$2, gs as exitFailCause, gt as never, hi as succeed$2, hn as yieldNow, hs as exitFail, j as ensuring$2, ja as of, jc as pipeArguments, ji as fiberAwait, ka as map$3, ki as exitVoid, li as failCause$4, ln as when, lr as hasInterruptsOnly, m as catchCause$1, mc as isTagged, mi as isSuccess, ms as evaluate, mt as matchCauseEffect, nr as done, nt as logError, oi as asVoidAll, p as callback$1, pi as isFailure$1, ps as causeFail, q as forkScoped, qa as succeed$5, qo as some, qr as provide, qt as suspend$2, ra as void_$1, rn as uninterruptible, si as die$3, st as map$2, t as acquireRelease, ta as uninterruptibleMask, tr as die$2, u as asVoid, un as whileLoop, us as PipeInspectableProto, vs as isExit, vt as onExit$2, w as catch_$2, wa as isReadonlyArrayNonEmpty, wt as promise, xc as constVoid, xi as asSome, ya as fromIterable$1, yc as constTrue, ys as makePrimitive, yt as onExitPrimitive$1, z as flatten$2, zn as isDoneCause, zr as Scope } from "./Effect-On-1ks2z.mjs";
2
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/String.js
1
+ import { $ as ignoreCause, $o as some, $s as random, $t as tapError$2, A as ensuring$2, Aa as isReadonlyArrayNonEmpty, Ac as constant, At as raceFirst, Bi as findRecoverableError, Bn as doneExitFromCause, Ci as andThen$1, Cs as exitFailCause, Dc as constTrue, Ds as withFiber$1, E as contextWith, Es as makePrimitive, Et as promise, Fa as map$3, Fi as fiberInterrupt, Fs as toJson, G as forkChild, Gn as nextPow2, Ha as headUnsafe, Hn as isDoneCause, Hr as addFinalizer, Ht as scopedWith, Ii as fiberInterruptAll, It as runForkWith, J as forkScoped, Ja as isFailure, Jo as map$4, Jr as makeUnsafe$1, Jt as succeedSome, Ko as isSome, Kr as forkUnsafe, Kt as succeed$3, L as flatMap$2, La as of, Li as fiberInterruptAllAs, Lt as runPromiseWith, M as fail$3, Mi as exitVoid, N as failCause$3, Na as lastNonEmpty, Nc as identity, Ni as exitZipRight, O as die$3, Oa as isArrayNonEmpty, Ot as provideContext$2, Pi as fiberAwait, Qa as succeed$5, Qi as onExitUnsafe, R as flatMapEager, Ri as fiberJoin, Sc as isTagged, So as get$1, Ss as exitFail, St as onInterrupt, T as context, Ta as fromIterable$1, Ti as callback$2, Ts as isExit, U as forEach, Ua as fail$4, Ui as getCurrentFiber, Un as matchEffect, Ur as addFinalizerExit, V as fnUntraced, Vi as flatMap$3, Vn as filterDone, Vr as Scope, W as forever, Wr as close, Xo as none, Xt as sync, Ya as isSuccess$1, Yn as Done$1, Yr as provide, Yt as suspend$2, Z as gen, Zi as onExitPrimitive, Zt as tap$1, _i as isSuccess, _s as PipeInspectableProto, a as andThen, aa as sync$1, bc as isString$1, bs as causeFail, bt as onExit$2, c as as, ca as void_$1, cr as fromReasons, di as fail$5, dn as void_, ea as scope, ei as doneUnsafe, eo as normalize, et as interrupt$2, fi as failCause$4, fn as when, fr as isCause, ft as mapError$2, gi as isFailure$1, gt as matchCauseEffect, hi as isExit$1, hs as Done, ia as suspend$3, ic as hasProperty, ir as done, it as logError, j as exit, jc as dual, ji as exitInterrupt$1, kc as constVoid, kt as provideService$2, li as asVoidAll, lt as map$2, m as catchCause$2, mi as interrupt$1, mn as withFiber, mr as isDone, na as succeed$4, ni as interruptWith, oa as uninterruptibleMask, on as uninterruptible, p as callback$1, pn as whileLoop, q as forkIn, qs as symbol, qt as succeedNone$1, ra as succeedNone, rc as symbol$1, rn as tryPromise, rr as die$2, si as makeUnsafe$2, t as acquireRelease, ta as scopeAddFinalizer, to as normalizeNonEmpty, u as asVoid, ui as die$4, ur as hasInterruptsOnly, vi as succeed$2, vn as yieldNow, vt as never, w as catch_$2, wi as asSome, wr as squash, ws as exitSucceed, xo as empty$2, xs as evaluate, xt as onExitPrimitive$1, yi as void_$2, ys as args, yt as onError, z as flatten$2, zc as pipeArguments, zi as fiberRunIn, zn as catchDone } from "./Effect-DNYYQ84C.mjs";
2
+ import { n as makeUnsafe$3, t as make$5 } from "./Latch-BSlIwuxI.mjs";
3
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/String.js
3
4
  const String = globalThis.String;
4
5
  const isString = isString$1;
5
6
  const toLowerCase = (self) => self.toLowerCase();
6
7
  const camelToSnake = (self) => self.replace(/([A-Z])/g, "_$1").toLowerCase();
7
- //#endregion
8
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/Fiber.js
8
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Fiber.js
9
9
  const await_ = fiberAwait;
10
10
  const join = fiberJoin;
11
11
  const interrupt = fiberInterrupt;
12
- const interruptAs = fiberInterruptAs;
13
12
  const interruptAll = fiberInterruptAll;
14
13
  const interruptAllAs = fiberInterruptAllAs;
15
14
  const getCurrent = getCurrentFiber;
16
15
  const runIn = fiberRunIn;
17
- //#endregion
18
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/Latch.js
19
- const makeUnsafe$1 = makeLatchUnsafe;
20
- const make$5 = makeLatch;
21
- //#endregion
22
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/MutableRef.js
16
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/MutableRef.js
23
17
  const TypeId$5 = "~effect/MutableRef";
24
18
  const MutableRefProto = {
25
19
  [TypeId$5]: TypeId$5,
26
20
  ...PipeInspectableProto,
21
+ [symbol](that) {
22
+ return this === that;
23
+ },
24
+ [symbol$1]() {
25
+ return random(this);
26
+ },
27
27
  toJSON() {
28
28
  return {
29
29
  _id: "MutableRef",
@@ -42,8 +42,7 @@ const set = dual(2, (self, value) => {
42
42
  return self;
43
43
  });
44
44
  const update = dual(2, (self, f) => set(self, f(get(self))));
45
- //#endregion
46
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/MutableList.js
45
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/MutableList.js
47
46
  const Empty = Symbol.for("effect/MutableList/Empty");
48
47
  const make$3 = () => ({
49
48
  head: void 0,
@@ -84,7 +83,7 @@ const prepend = (self, message) => {
84
83
  if (!self.tail) self.tail = self.head;
85
84
  self.length++;
86
85
  };
87
- const appendAll = (self, messages) => appendAllUnsafe(self, fromIterable$1(messages), !Array.isArray(messages));
86
+ const appendAll = (self, messages) => appendAllUnsafe(self, Array.from(messages), true);
88
87
  const appendAllUnsafe = (self, messages, mutable = false) => {
89
88
  if (messages.length === 0) return 0;
90
89
  const chunk = {
@@ -166,11 +165,10 @@ const filter$1 = (self, f) => {
166
165
  self.length = array.length;
167
166
  };
168
167
  const remove = (self, value) => filter$1(self, (v) => v !== value);
169
- //#endregion
170
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/PubSub.js
168
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/PubSub.js
171
169
  const TypeId$4 = "~effect/PubSub";
172
170
  const SubscriptionTypeId = "~effect/PubSub/Subscription";
173
- const make$2 = (options) => sync(() => makePubSubUnsafe(options.atomicPubSub(), new Map(), makeUnsafe$2(), makeUnsafe$1(false), make$4(false), options.strategy(), make$4(none())));
171
+ const make$2 = (options) => sync(() => makePubSubUnsafe(options.atomicPubSub(), new Map(), makeUnsafe$1(), makeUnsafe$3(false), make$4(false), options.strategy(), make$4(none())));
174
172
  const bounded$1 = (capacity) => make$2({
175
173
  atomicPubSub: () => makeAtomicBounded(capacity),
176
174
  strategy: () => new BackPressureStrategy()
@@ -179,7 +177,7 @@ const dropping = (capacity) => make$2({
179
177
  atomicPubSub: () => makeAtomicBounded(capacity),
180
178
  strategy: () => new DroppingStrategy()
181
179
  });
182
- const sliding = (capacity) => make$2({
180
+ const sliding$1 = (capacity) => make$2({
183
181
  atomicPubSub: () => makeAtomicBounded(capacity),
184
182
  strategy: () => new SlidingStrategy()
185
183
  });
@@ -284,7 +282,7 @@ const pollForItem = (self) => callback$1((resume) => {
284
282
  }
285
283
  return resume(succeed$3(self.ended.current.value));
286
284
  }
287
- const deferred = makeUnsafe$3();
285
+ const deferred = makeUnsafe$2();
288
286
  let set = self.subscribers.get(self.subscription);
289
287
  if (!set) {
290
288
  set = new Set();
@@ -308,7 +306,7 @@ const removeSubscribers = (subscribers, subscription, pollers) => {
308
306
  set.delete(pollers);
309
307
  if (set.size === 0) subscribers.delete(subscription);
310
308
  };
311
- const makeSubscriptionUnsafe = (pubsub, subscribers, strategy, ended) => new SubscriptionImpl(pubsub, subscribers, pubsub.subscribe(), make$3(), makeUnsafe$1(false), make$4(false), strategy, pubsub.replayWindow(), ended);
309
+ const makeSubscriptionUnsafe = (pubsub, subscribers, strategy, ended) => new SubscriptionImpl(pubsub, subscribers, pubsub.subscribe(), make$3(), makeUnsafe$3(false), make$4(false), strategy, pubsub.replayWindow(), ended);
312
310
  var BoundedPubSubArb = class {
313
311
  array;
314
312
  replayIndices;
@@ -918,7 +916,7 @@ var BackPressureStrategy = class {
918
916
  handleSurplus(pubsub, subscribers, elements, isShutdown, ended) {
919
917
  return callback$1((resume) => {
920
918
  if (isSome(ended.current)) return resume(succeed$3(false));
921
- const deferred = makeUnsafe$3();
919
+ const deferred = makeUnsafe$2();
922
920
  this.offerUnsafe(elements, deferred);
923
921
  this.onPubSubEmptySpaceUnsafe(pubsub, subscribers);
924
922
  this.completeSubscribersUnsafe(pubsub, subscribers);
@@ -937,11 +935,11 @@ var BackPressureStrategy = class {
937
935
  const publisher = take$3(this.publishers);
938
936
  if (publisher === Empty) keepPolling = false;
939
937
  else {
940
- const [value, deferred] = publisher;
938
+ const [value, deferred, last] = publisher;
941
939
  const published = pubsub.publish(value);
942
- if (published && publisher[2]) doneUnsafe(deferred, succeed$2(true));
943
- else if (!published) prepend(this.publishers, publisher);
940
+ if (!published) prepend(this.publishers, publisher);
944
941
  this.completeSubscribersUnsafe(pubsub, subscribers);
942
+ if (published && last) doneUnsafe(deferred, succeed$2(true));
945
943
  }
946
944
  }
947
945
  }
@@ -1078,8 +1076,12 @@ var ReplayBuffer = class {
1078
1076
  next: null
1079
1077
  };
1080
1078
  this.tail = this.tail.next;
1081
- if (this.size === this.capacity) this.head = this.head.next;
1082
- else this.size += 1;
1079
+ if (this.size === this.capacity) {
1080
+ const dropped = this.head;
1081
+ this.head = dropped.next;
1082
+ dropped.next = null;
1083
+ dropped.value = AbsentValue;
1084
+ } else this.size += 1;
1083
1085
  return index;
1084
1086
  }
1085
1087
  offerAll(as) {
@@ -1152,8 +1154,7 @@ const emptyReplayWindow = {
1152
1154
  takeAll: () => [],
1153
1155
  close: () => void 0
1154
1156
  };
1155
- //#endregion
1156
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/Queue.js
1157
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Queue.js
1157
1158
  const TypeId$3 = "~effect/Queue";
1158
1159
  const EnqueueTypeId = "~effect/Queue/Enqueue";
1159
1160
  const DequeueTypeId = "~effect/Queue/Dequeue";
@@ -1190,6 +1191,10 @@ const make$1 = (options) => withFiber$1((fiber) => {
1190
1191
  return succeed$4(self);
1191
1192
  });
1192
1193
  const bounded = (capacity) => make$1({ capacity });
1194
+ const sliding = (capacity) => make$1({
1195
+ capacity,
1196
+ strategy: "sliding"
1197
+ });
1193
1198
  const unbounded = () => make$1();
1194
1199
  const offer = dual(2, (self, message) => suspend$3(() => offerUnsafe(self, message) ? exitTrue : self.state._tag === "Open" && self.strategy === "suspend" ? offerOrWait(self, message) : exitFalse));
1195
1200
  const offerUnsafe = (self, message) => {
@@ -1416,20 +1421,36 @@ const finalize = (self, exit) => {
1416
1421
  for (const awaiter of openState.awaiters) awaiter(exit);
1417
1422
  openState.awaiters.clear();
1418
1423
  };
1419
- //#endregion
1420
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/Semaphore.js
1424
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Semaphore.js
1421
1425
  const makeUnsafe = (permits) => new SemaphoreImpl(permits);
1422
- const waitForPermits = (self, n, effect) => callback$2((resume) => {
1423
- if (self.free >= n) return resume(effect);
1424
- const observer = () => {
1425
- if (self.free < n) return;
1426
- self.waiters.delete(observer);
1427
- resume(effect);
1426
+ const firstAvailableWaiter = (self) => {
1427
+ for (const waiter of self.waiters) if (waiter.permits <= self.free) return waiter;
1428
+ };
1429
+ const takePermits = (self, n, onAcquire, restore = identity) => withFiber$1((fiber) => {
1430
+ if (self.free >= n && firstAvailableWaiter(self) === void 0) {
1431
+ self.taken += n;
1432
+ return onAcquire();
1433
+ }
1434
+ const waiter = {
1435
+ permits: n,
1436
+ resume: void 0
1428
1437
  };
1429
- self.waiters.add(observer);
1430
- return sync$1(() => {
1431
- self.waiters.delete(observer);
1438
+ const remove = () => {
1439
+ if (self.waiters.delete(waiter)) self.releaseUnsafe(fiber, 0);
1440
+ };
1441
+ self.waiters.add(waiter);
1442
+ onExitUnsafe(fiber, remove);
1443
+ const wait = restore(callback$2((resume) => {
1444
+ if (firstAvailableWaiter(self) === waiter) resume(void_$1);
1445
+ else waiter.resume = resume;
1446
+ }));
1447
+ const loop = flatMap$3(wait, () => {
1448
+ if (firstAvailableWaiter(self) !== waiter) return loop;
1449
+ self.taken += n;
1450
+ remove();
1451
+ return onAcquire();
1432
1452
  });
1453
+ return loop;
1433
1454
  });
1434
1455
  var SemaphoreImpl = class {
1435
1456
  waiters = new Set();
@@ -1442,12 +1463,10 @@ var SemaphoreImpl = class {
1442
1463
  return this.permits - this.taken;
1443
1464
  }
1444
1465
  take(n) {
1445
- const take = suspend$3(() => {
1446
- if (this.free < n) return waitForPermits(this, n, take);
1447
- this.taken += n;
1448
- return succeed$4(n);
1449
- });
1450
- return take;
1466
+ return takePermits(this, n, () => succeed$4(n));
1467
+ }
1468
+ takeScoped(n) {
1469
+ return uninterruptibleMask((restore) => flatMap$3(scope, (scope) => takePermits(this, n, () => scopeAddFinalizer(scope, this.release(n)), restore)));
1451
1470
  }
1452
1471
  takeIfAvailable(n) {
1453
1472
  return suspend$3(() => {
@@ -1459,9 +1478,13 @@ var SemaphoreImpl = class {
1459
1478
  releaseUnsafe(fiber, n) {
1460
1479
  this.taken -= n;
1461
1480
  if (this.waiters.size > 0) fiber.currentDispatcher.scheduleTask(() => {
1462
- for (const observer of this.waiters) {
1463
- if (this.free <= 0) break;
1464
- observer();
1481
+ let remaining = this.free;
1482
+ for (const waiter of Array.from(this.waiters)) {
1483
+ if (!this.waiters.has(waiter) || waiter.permits > remaining) continue;
1484
+ remaining -= waiter.permits;
1485
+ const resume = waiter.resume;
1486
+ waiter.resume = void 0;
1487
+ resume?.(void_$1);
1465
1488
  }
1466
1489
  }, 0);
1467
1490
  return this.free;
@@ -1481,19 +1504,9 @@ var SemaphoreImpl = class {
1481
1504
  return withFiber$1((fiber) => succeed$4(this.releaseUnsafe(fiber, this.taken)));
1482
1505
  }
1483
1506
  withPermits(n) {
1484
- return (self) => uninterruptibleMask((restore) => {
1485
- const acquire = suspend$3(() => {
1486
- if (this.free < n) {
1487
- const wait = waitForPermits(this, n, void_$1);
1488
- return flatMap$3(restore(wait), () => acquire);
1489
- }
1490
- this.taken += n;
1491
- return onExitPrimitive(restore(self), () => {
1492
- this.releaseUnsafe(getCurrentFiber(), n);
1493
- }, true);
1494
- });
1495
- return acquire;
1496
- });
1507
+ return (self) => uninterruptibleMask((restore) => takePermits(this, n, () => onExitPrimitive(restore(self), () => {
1508
+ this.releaseUnsafe(getCurrentFiber(), n);
1509
+ }, true), restore));
1497
1510
  }
1498
1511
  withPermit = this.withPermits(1);
1499
1512
  withPermitsIfAvailable(n) {
@@ -1507,11 +1520,9 @@ var SemaphoreImpl = class {
1507
1520
  }
1508
1521
  };
1509
1522
  const make = (permits) => sync$1(() => new SemaphoreImpl(permits));
1510
- //#endregion
1511
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/Take.js
1523
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Take.js
1512
1524
  const toPull = (take) => isExit$1(take) ? isSuccess(take) ? done(take.value) : take : succeed$3(take);
1513
- //#endregion
1514
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/Channel.js
1525
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Channel.js
1515
1526
  const TypeId$2 = "~effect/Channel";
1516
1527
  const isChannel = (u) => hasProperty(u, TypeId$2);
1517
1528
  const ChannelProto = {
@@ -1528,7 +1539,7 @@ const ChannelProto = {
1528
1539
  };
1529
1540
  const fromTransform = (transform) => {
1530
1541
  const self = Object.create(ChannelProto);
1531
- self.transform = (upstream, scope) => catchCause$1(transform(upstream, scope), (cause) => succeed$3(failCause$3(cause)));
1542
+ self.transform = (upstream, scope) => catchCause$2(transform(upstream, scope), (cause) => succeed$3(failCause$3(cause)));
1532
1543
  return self;
1533
1544
  };
1534
1545
  const transformPull$1 = (self, f) => fromTransform((upstream, scope) => flatMap$2(toTransform(self)(upstream, scope), (pull) => f(pull, scope)));
@@ -1544,7 +1555,7 @@ const DefaultChunkSize = 4096;
1544
1555
  const asyncQueue = (scope, f, options) => make$1({
1545
1556
  capacity: options?.bufferSize,
1546
1557
  strategy: options?.strategy
1547
- }).pipe(tap$1((queue) => addFinalizer(scope, shutdown(queue))), tap$1((queue) => provide(f(queue), scope).pipe(catchCause$1((cause) => failCause$2(queue, cause)), forkIn(scope))));
1558
+ }).pipe(tap$1((queue) => addFinalizer(scope, shutdown(queue))), tap$1((queue) => provide(f(queue), scope).pipe(catchCause$2((cause) => failCause$2(queue, cause)), forkIn(scope, { startImmediately: true }))));
1548
1559
  const callbackArray = (f, options) => fromTransform((_, scope) => map$2(asyncQueue(scope, f, options), takeAll));
1549
1560
  const suspend$1 = (evaluate) => fromTransform((upstream, scope) => suspend$2(() => toTransform(evaluate())(upstream, scope)));
1550
1561
  const fromIterator = (iterator) => fromPull$1(sync(() => {
@@ -1558,15 +1569,15 @@ const fromIteratorArray = (iterator, chunkSize = DefaultChunkSize) => {
1558
1569
  const size = normalizeNonEmpty(chunkSize);
1559
1570
  return fromPull$1(sync(() => {
1560
1571
  const iter = iterator();
1561
- let done$15 = none();
1572
+ let done$9 = none();
1562
1573
  return suspend$2(() => {
1563
- if (done$15._tag === "Some") return done(done$15.value);
1574
+ if (done$9._tag === "Some") return done(done$9.value);
1564
1575
  const buffer = [];
1565
1576
  while (buffer.length < size) {
1566
1577
  const state = iter.next();
1567
1578
  if (state.done) {
1568
1579
  if (buffer.length === 0) return done(state.value);
1569
- done$15 = some(state.value);
1580
+ done$9 = some(state.value);
1570
1581
  break;
1571
1582
  }
1572
1583
  buffer.push(state.value);
@@ -1582,13 +1593,14 @@ const fail$1 = (error) => fromPull$1(succeed$3(fail$3(error)));
1582
1593
  const failCause$1 = (cause) => fromPull$1(failCause$3(cause));
1583
1594
  const die$1 = (defect) => failCause$1(die$2(defect));
1584
1595
  const fromEffect$1 = (effect) => fromPull$1(sync(() => {
1585
- let done$16 = false;
1596
+ let done$10 = false;
1586
1597
  return suspend$2(() => {
1587
- if (done$16) return done();
1588
- done$16 = true;
1598
+ if (done$10) return done();
1599
+ done$10 = true;
1589
1600
  return effect;
1590
1601
  });
1591
1602
  }));
1603
+ const fromEffectDrain = (effect) => fromPull$1(flatMap$2(effect, () => done()));
1592
1604
  const fromEffectTake = (effect) => fromPull$1(succeed$3(flatMap$2(effect, toPull)));
1593
1605
  const fromQueueArray = (queue) => fromPull$1(succeed$3(takeAll(queue)));
1594
1606
  const fromSubscriptionArray = (subscription) => fromPull$1(succeed$3(onInterrupt(takeAll$1(subscription), () => done())));
@@ -1610,13 +1622,13 @@ const readableStreamToPullUnsafe = (options) => {
1610
1622
  catch: options.onError
1611
1623
  }), {
1612
1624
  onFailure: (cause) => exit.current ?? failCause$3(cause),
1613
- onSuccess: ({ done: done$10, value }) => {
1625
+ onSuccess: ({ done: done$12, value }) => {
1614
1626
  if (exit.current) return exit.current;
1615
- return done$10 ? done() : succeed$3(of(value));
1627
+ return done$12 ? done() : succeed$3(of(value));
1616
1628
  }
1617
1629
  });
1618
1630
  });
1619
- return as(addFinalizer(options.scope, options.releaseLockOnEnd ? sync(() => reader.releaseLock()) : promise(() => reader.cancel().catch(constVoid))), pull);
1631
+ return as(addFinalizer(options.scope, options.releaseLockOnEnd ? sync(() => reader.releaseLock()) : promise(() => reader.cancel().catch((error) => reader.closed.then(() => Promise.reject(error), constVoid))).pipe(ensuring$2(sync(() => reader.releaseLock())))), pull);
1620
1632
  };
1621
1633
  const fromAsyncIterable$1 = (iterable, onError) => fromTransform(fnUntraced(function* (_, scope) {
1622
1634
  const iter = iterable[Symbol.asyncIterator]();
@@ -1649,7 +1661,7 @@ const mapEffectSequential = (self, f) => fromTransform((upstream, scope) => {
1649
1661
  const mapEffectConcurrent = (self, f, options) => fromTransformBracket(fnUntraced(function* (upstream, scope, forkedScope) {
1650
1662
  let i = 0;
1651
1663
  const pull = yield* toTransform(self)(upstream, scope);
1652
- const concurrencyN = options.concurrency === "unbounded" ? Number.MAX_SAFE_INTEGER : options.concurrency;
1664
+ const concurrencyN = options.concurrency === "unbounded" ? Number.MAX_SAFE_INTEGER : Math.min(options.concurrency, Number.MAX_SAFE_INTEGER);
1653
1665
  const queue = yield* bounded(0);
1654
1666
  yield* addFinalizer(forkedScope, shutdown(queue));
1655
1667
  const runFork = runForkWith(yield* context());
@@ -1665,11 +1677,11 @@ const mapEffectConcurrent = (self, f, options) => fromTransformBracket(fnUntrace
1665
1677
  const index = i++;
1666
1678
  trackFiber(runFork(handle(suspend$2(() => f(value, index)))));
1667
1679
  return void_;
1668
- }), forever({ disableYield: true }), catchCause$1((cause) => semaphore.withPermits(concurrencyN - 1)(failCause$2(queue, cause))), forkIn(forkedScope));
1680
+ }), forever({ disableYield: true }), catchCause$2((cause) => semaphore.withPermits(concurrencyN - 1)(failCause$2(queue, cause))), forkIn(forkedScope));
1669
1681
  } else {
1670
1682
  const effects = yield* bounded(concurrencyN - 2);
1671
1683
  yield* addFinalizer(forkedScope, shutdown(effects));
1672
- yield* take$1(effects).pipe(flatten$2, flatMap$2((value) => offer(queue, value)), forever({ disableYield: true }), catchCause$1((cause) => failCause$2(queue, cause)), forkIn(forkedScope));
1684
+ yield* take$1(effects).pipe(flatten$2, flatMap$2((value) => offer(queue, value)), forever({ disableYield: true }), catchCause$2((cause) => failCause$2(queue, cause)), forkIn(forkedScope));
1673
1685
  let errorCause;
1674
1686
  const onExit = (exit) => {
1675
1687
  if (exit._tag === "Success") return;
@@ -1683,7 +1695,7 @@ const mapEffectConcurrent = (self, f, options) => fromTransformBracket(fnUntrace
1683
1695
  trackFiber(fiber);
1684
1696
  fiber.addObserver(onExit);
1685
1697
  return offer(effects, join(fiber));
1686
- }), forever({ disableYield: true }), catchCause$1((cause) => offer(effects, failCause$4(cause)).pipe(andThen(failCause$2(effects, cause)))), forkIn(forkedScope));
1698
+ }), forever({ disableYield: true }), catchCause$2((cause) => offer(effects, failCause$4(cause)).pipe(andThen(failCause$2(effects, cause)))), forkIn(forkedScope));
1687
1699
  }
1688
1700
  return take$1(queue);
1689
1701
  }));
@@ -1744,10 +1756,10 @@ const filterMapArray = dual(2, (self, filter) => transformPull$1(self, (pull) =>
1744
1756
  }
1745
1757
  return isReadonlyArrayNonEmpty(passes) ? succeed$3(passes) : flatMap$2(pull, loop);
1746
1758
  }))));
1747
- const catchCause = dual(2, (self, f) => fromTransform((upstream, scope) => {
1759
+ const catchCause$1 = dual(2, (self, f) => fromTransform((upstream, scope) => {
1748
1760
  let forkedScope = forkUnsafe(scope);
1749
1761
  return map$2(toTransform(self)(upstream, forkedScope), (pull) => {
1750
- let currentPull = pull.pipe(catchCause$1((cause) => {
1762
+ let currentPull = pull.pipe(catchCause$2((cause) => {
1751
1763
  if (isDoneCause(cause)) return failCause$3(cause);
1752
1764
  const toClose = forkedScope;
1753
1765
  forkedScope = forkUnsafe(scope);
@@ -1759,11 +1771,12 @@ const catchCause = dual(2, (self, f) => fromTransform((upstream, scope) => {
1759
1771
  return suspend$2(() => currentPull);
1760
1772
  });
1761
1773
  }));
1762
- const catchCauseFilter = dual(3, (self, filter, f) => catchCause(self, (cause) => {
1774
+ const catchCauseFilter = dual(3, (self, filter, f) => catchCause$1(self, (cause) => {
1763
1775
  const result = filter(cause);
1764
1776
  return isFailure(result) ? failCause$1(result.failure) : f(result.success, cause);
1765
1777
  }));
1766
- const catch_$1 = dual(2, (self, f) => catchCauseFilter(self, findError, (e) => f(e)));
1778
+ const catch_$1 = dual(2, (self, f) => catchCauseFilter(self, findRecoverableError, (e) => f(e)));
1779
+ const tapError$1 = dual(2, (self, f) => transformPull$1(self, (pull) => succeed$3(tapError$2(pull, (err) => isDone(err) ? void_ : asVoid(f(err))))));
1767
1780
  const catchIf$1 = dual((args) => isChannel(args[0]), (self, predicate, f, orElse) => catch_$1(self, (err) => {
1768
1781
  return predicate(err) ? f(err) : orElse ? orElse(err) : fail$1(err);
1769
1782
  }));
@@ -1779,13 +1792,13 @@ const catchReason$1 = dual((args) => isChannel(args[0]), (self, errorTag, reason
1779
1792
  }
1780
1793
  return fail$1(error);
1781
1794
  }));
1782
- const mapError$1 = dual(2, (self, f) => catch_$1(self, (err) => fail$1(f(err))));
1795
+ const mapError$1 = dual(2, (self, f) => transformPull$1(self, (pull) => succeed$3(mapError$2(pull, (err) => isDone(err) ? err : f(err)))));
1783
1796
  const orDie$1 = (self) => catch_$1(self, die$1);
1784
1797
  const mergeAll$1 = dual(2, (channels, { bufferSize = 16, concurrency, switch: switch_ = false }) => fromTransformBracket(fnUntraced(function* (upstream, scope, forkedScope) {
1785
1798
  const concurrencyN = concurrency === "unbounded" ? Number.MAX_SAFE_INTEGER : Math.max(1, concurrency);
1786
1799
  const semaphore = switch_ ? void 0 : makeUnsafe(concurrencyN);
1787
1800
  const doneLatch = yield* make$5(true);
1788
- const fibers = new Set();
1801
+ const fibers = new Map();
1789
1802
  const queue = yield* bounded(bufferSize);
1790
1803
  yield* addFinalizer(forkedScope, shutdown(queue));
1791
1804
  const pull = yield* toTransform(channels)(upstream, scope);
@@ -1803,10 +1816,11 @@ const mergeAll$1 = dual(2, (channels, { bufferSize = 16, concurrency, switch: sw
1803
1816
  const childScope = forkUnsafe(forkedScope);
1804
1817
  const childPull = yield* toTransform(channel)(upstream, childScope);
1805
1818
  while (fibers.size >= concurrencyN) {
1806
- const fiber = headUnsafe(fibers);
1819
+ const [fiber, fiberScope] = headUnsafe(fibers);
1807
1820
  fibers.delete(fiber);
1808
1821
  if (fibers.size === 0) yield* doneLatch.open;
1809
1822
  yield* interrupt(fiber);
1823
+ yield* ignoreCause(close(fiberScope, interrupt$1()));
1810
1824
  }
1811
1825
  const fiber = yield* childPull.pipe(tap$1(() => yieldNow), flatMap$2((value) => offer(queue, value)), forever({ disableYield: true }), onError(fnUntraced(function* (cause) {
1812
1826
  const exit$1 = doneExitFromCause(cause);
@@ -1819,9 +1833,9 @@ const mergeAll$1 = dual(2, (channels, { bufferSize = 16, concurrency, switch: sw
1819
1833
  if (fibers.size === 0) yield* doneLatch.open;
1820
1834
  })), forkChild);
1821
1835
  doneLatch.closeUnsafe();
1822
- fibers.add(fiber);
1836
+ fibers.set(fiber, childScope);
1823
1837
  }
1824
- }).pipe(catchCause$1((cause) => {
1838
+ }).pipe(catchCause$2((cause) => {
1825
1839
  const halt = filterDone(cause);
1826
1840
  if (isSuccess$1(halt)) return doneLatch.whenOpen(failCause$2(queue, cause));
1827
1841
  return failCause$2(queue, cause);
@@ -1851,10 +1865,11 @@ const merge$1 = dual((args) => isChannel(args[0]) && isChannel(args[1]), (left,
1851
1865
  yield* runSide("right", right, forkUnsafe(forkedScope));
1852
1866
  return take$1(queue);
1853
1867
  })));
1868
+ const mergeEffect$1 = dual(2, (self, effect) => merge$1(self, fromEffectDrain(effect), { haltStrategy: "left" }));
1854
1869
  const splitLines$1 = () => fromTransform((upstream, _scope) => sync(() => {
1855
1870
  let stringBuilder = "";
1856
1871
  let midCRLF = false;
1857
- let done$12 = none();
1872
+ let done$11 = none();
1858
1873
  function splitLinesArray(chunk) {
1859
1874
  const chunkBuilder = [];
1860
1875
  function pushLine(segment) {
@@ -1899,12 +1914,12 @@ const splitLines$1 = () => fromTransform((upstream, _scope) => sync(() => {
1899
1914
  return isReadonlyArrayNonEmpty(chunkBuilder) ? chunkBuilder : null;
1900
1915
  }
1901
1916
  const pullOrFlush = suspend$2(() => {
1902
- if (done$12._tag === "Some") return done(done$12.value);
1917
+ if (done$11._tag === "Some") return done(done$11.value);
1903
1918
  return matchEffect(upstream, {
1904
1919
  onSuccess: loop,
1905
1920
  onFailure: failCause$3,
1906
1921
  onDone: (leftover) => {
1907
- done$12 = some(leftover);
1922
+ done$11 = some(leftover);
1908
1923
  if (stringBuilder.length > 0) {
1909
1924
  const last = stringBuilder;
1910
1925
  stringBuilder = "";
@@ -1921,7 +1936,22 @@ const splitLines$1 = () => fromTransform((upstream, _scope) => sync(() => {
1921
1936
  }
1922
1937
  return pullOrFlush;
1923
1938
  }));
1939
+ const decodeText$1 = (encoding, options) => fromTransform((upstream, _scope) => sync(() => {
1940
+ const decoder = new TextDecoder(encoding, options);
1941
+ const streamOptions = { stream: true };
1942
+ let pull = upstream.pipe(map$2(map$3((bytes) => decoder.decode(bytes, streamOptions))), catchDone((leftover) => {
1943
+ pull = done(leftover);
1944
+ const last = decoder.decode();
1945
+ return last.length > 0 ? succeed$3(of(last)) : pull;
1946
+ }));
1947
+ return suspend$2(() => pull);
1948
+ }));
1924
1949
  const pipeTo = dual(2, (self, that) => fromTransform((upstream, scope) => flatMap$2(toTransform(self)(upstream, scope), (upstream) => toTransform(that)(upstream, scope))));
1950
+ const isUpstreamFailure = (reason) => reason._tag === "Die" && isDone(reason.defect) && isCause(reason.defect.value);
1951
+ const hasUpstreamFailure = (cause) => cause.reasons.some(isUpstreamFailure);
1952
+ const upstreamFailureToDefect = (pull) => catchCause$2(pull, (cause) => isDoneCause(cause) ? failCause$3(cause) : die$3(Done$1(cause)));
1953
+ const unwrapUpstreamFailure = (cause) => hasUpstreamFailure(cause) ? fromReasons(cause.reasons.flatMap((reason) => isUpstreamFailure(reason) ? reason.defect.value.reasons : [reason])) : cause;
1954
+ const restoreUpstreamFailure = (effect) => catchCause$2(effect, (cause) => failCause$3(unwrapUpstreamFailure(cause)));
1925
1955
  const unwrap$1 = (channel) => fromTransform((upstream, scope) => {
1926
1956
  let pull;
1927
1957
  return succeed$3(suspend$2(() => {
@@ -1931,10 +1961,9 @@ const unwrap$1 = (channel) => fromTransform((upstream, scope) => {
1931
1961
  });
1932
1962
  const scoped$1 = (self) => fromTransformBracket((upstream, scope, forkedScope) => map$2(provide(toTransform(self)(upstream, scope), forkedScope), provide(forkedScope)));
1933
1963
  const onExit$1 = dual(2, (self, finalizer) => fromTransformBracket((upstream, scope, forkedScope) => addFinalizerExit(forkedScope, finalizer).pipe(andThen(toTransform(self)(upstream, scope)))));
1934
- const onEnd$1 = dual(2, (self, onEnd) => transformPull$1(self, (pull) => succeed$3(catchDone(pull, (leftover) => flatMap$2(onEnd, () => done(leftover))))));
1935
1964
  const ensuring$1 = dual(2, (self, finalizer) => onExit$1(self, (_) => finalizer));
1936
1965
  const runWith = (self, f, onHalt) => suspend$2(() => {
1937
- const scope = makeUnsafe$2();
1966
+ const scope = makeUnsafe$1();
1938
1967
  const makePull = toTransform(self)(done(), scope);
1939
1968
  return catchDone(flatMap$2(makePull, f), onHalt ? onHalt : succeed$3).pipe(onExit$2((exit) => close(scope, exit)));
1940
1969
  });
@@ -1961,15 +1990,14 @@ const runFold$1 = dual(3, (self, initial, f) => suspend$2(() => {
1961
1990
  }), () => succeed$3(state));
1962
1991
  }));
1963
1992
  const toPullScoped = (self, scope) => toTransform(self)(done(), scope);
1964
- const makePubSub = (options) => acquireRelease(options.capacity === "unbounded" ? unbounded$1(options) : options.strategy === "dropping" ? dropping(options) : options.strategy === "sliding" ? sliding(options) : bounded$1(options), shutdown$1);
1993
+ const makePubSub = (options) => acquireRelease(options.capacity === "unbounded" ? unbounded$1(options) : options.strategy === "dropping" ? dropping(options) : options.strategy === "sliding" ? sliding$1(options) : bounded$1(options), shutdown$1);
1965
1994
  const runIntoPubSubArray = dual((args) => isChannel(args[0]), (self, pubsub, options) => runForEach$1(self, (value) => publishAll(pubsub, value)).pipe(options?.shutdownOnEnd === true ? ensuring$2(shutdown$1(pubsub)) : identity));
1966
1995
  const toPubSubTake$1 = dual(2, fnUntraced(function* (self, options) {
1967
1996
  const pubsub = yield* makePubSub(options);
1968
1997
  yield* runForEach$1(self, (value) => publish(pubsub, value)).pipe(onExit$2((exit) => end$1(pubsub, exit)), forkScoped);
1969
1998
  return pubsub;
1970
1999
  }));
1971
- //#endregion
1972
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/internal/stream.js
2000
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/internal/stream.js
1973
2001
  const TypeId$1 = "~effect/Stream";
1974
2002
  const streamVariance = {
1975
2003
  _R: identity,
@@ -1986,8 +2014,7 @@ Stream.prototype = {
1986
2014
  }
1987
2015
  };
1988
2016
  const fromChannel$1 = (channel) => new Stream(channel);
1989
- //#endregion
1990
- //#region node_modules/.pnpm/effect@4.0.5/node_modules/effect/dist/Stream.js
2017
+ // node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Stream.js
1991
2018
  const TypeId = "~effect/Stream";
1992
2019
  const isStream = (u) => hasProperty(u, TypeId);
1993
2020
  const fromChannel = fromChannel$1;
@@ -1998,7 +2025,12 @@ const toChannel = (stream) => stream.channel;
1998
2025
  const callback = (f, options) => fromChannel(callbackArray(f, options));
1999
2026
  const empty = fromChannel(empty$1);
2000
2027
  const succeed = (value) => fromChannel(succeed$1(of(value)));
2001
- const suspend = (stream) => fromChannel(suspend$1(() => stream().channel));
2028
+ const suspend = (stream) => {
2029
+ const suspended = fromChannel(suspend$1(() => stream().channel));
2030
+ suspendedStreams.set(suspended, stream);
2031
+ return suspended;
2032
+ };
2033
+ const suspendedStreams = new WeakMap();
2002
2034
  const fail = (error) => fromChannel(fail$1(error));
2003
2035
  const failCause = (cause) => fromChannel(failCause$1(cause));
2004
2036
  const die = (defect) => fromChannel(die$1(defect));
@@ -2023,6 +2055,7 @@ const tap = dual((args) => isStream(args[0]), (self, f, options) => mapEffect(se
2023
2055
  const flatMap = dual((args) => isStream(args[0]), (self, f, options) => self.channel.pipe(flattenArray$1, flatMap$1((a) => f(a).channel, options), fromChannel));
2024
2056
  const flatten = dual((args) => isStream(args[0]), (self, options) => flatMap(self, identity, options));
2025
2057
  const flattenArray = (self) => fromChannel(flattenArray$1(self.channel));
2058
+ const drainFork = dual(2, (self, that) => mergeEffect(self, runDrain(that)));
2026
2059
  const flattenIterable = (self) => flatMap(self, fromIterable);
2027
2060
  const concat = dual(2, (self, that) => {
2028
2061
  const stream = fromChannel(flatten$1(fromIterator(() => concatChannels(self, that))));
@@ -2035,15 +2068,31 @@ function* concatChannels(self, that) {
2035
2068
  while (stack.length > 0) {
2036
2069
  const stream = stack.pop();
2037
2070
  const parts = concatParts.get(stream);
2038
- if (parts === void 0) yield stream.channel;
2039
- else stack.push(parts[1], parts[0]);
2071
+ if (parts !== void 0) {
2072
+ stack.push(parts[1], parts[0]);
2073
+ continue;
2074
+ }
2075
+ const evaluate = suspendedStreams.get(stream);
2076
+ if (evaluate === void 0) {
2077
+ yield stream.channel;
2078
+ continue;
2079
+ }
2080
+ try {
2081
+ stack.push(evaluate());
2082
+ } catch (defect) {
2083
+ stack.push(die(defect));
2084
+ }
2085
+ yield empty$1;
2040
2086
  }
2041
2087
  }
2042
2088
  const merge = dual((args) => isStream(args[0]) && isStream(args[1]), (self, that, options) => fromChannel(merge$1(toChannel(self), toChannel(that), options)));
2089
+ const mergeEffect = dual(2, (self, effect) => self.channel.pipe(mergeEffect$1(effect), fromChannel));
2043
2090
  const mergeAll = dual(2, (streams, options) => flatten(fromIterable(streams), options));
2044
2091
  const filter = dual(2, (self, predicate) => fromChannel(filterArray(toChannel(self), predicate)));
2045
2092
  const filterMap = dual(2, (self, filter) => fromChannel(filterMapArray(toChannel(self), filter)));
2093
+ const catchCause = dual(2, (self, f) => self.channel.pipe(catchCause$1((cause) => f(cause).channel), fromChannel));
2046
2094
  const catch_ = dual(2, (self, f) => fromChannel(catch_$1(self.channel, (error) => f(error).channel)));
2095
+ const tapError = dual(2, (self, f) => self.channel.pipe(tapError$1(f), fromChannel));
2047
2096
  const catchIf = dual((args) => isStream(args[0]), (self, predicate, f, orElse) => fromChannel(catchIf$1(toChannel(self), predicate, (e) => f(e).channel, orElse && ((e) => orElse(e).channel))));
2048
2097
  const catchFilter = dual((args) => isStream(args[0]), (self, filter, f, orElse) => fromChannel(catchFilter$1(toChannel(self), filter, (e) => f(e).channel, orElse && ((e) => orElse(e).channel))));
2049
2098
  const catchTags = dual((args) => isStream(args[0]), (self, cases, orElse) => {
@@ -2104,7 +2153,7 @@ const drop = dual(2, (self, n) => {
2104
2153
  }));
2105
2154
  });
2106
2155
  const transduce = dual(2, (self, sink) => transformPull(self, (upstream, scope) => sync(() => {
2107
- let done$1;
2156
+ let done$8;
2108
2157
  let leftover;
2109
2158
  const upstreamWithLeftover = suspend$2(() => {
2110
2159
  if (leftover !== void 0) {
@@ -2114,28 +2163,25 @@ const transduce = dual(2, (self, sink) => transformPull(self, (upstream, scope)
2114
2163
  }
2115
2164
  return upstream;
2116
2165
  }).pipe(catch_$2((error) => {
2117
- done$1 = fail$5(error);
2166
+ done$8 = fail$5(error);
2118
2167
  return done();
2119
2168
  }));
2120
2169
  const pull = map$2(suspend$2(() => sink.transform(upstreamWithLeftover, scope)), ([value, leftover_]) => {
2121
2170
  leftover = leftover_;
2122
2171
  return of(value);
2123
2172
  });
2124
- return suspend$2(() => done$1 ? done$1 : pull);
2173
+ return suspend$2(() => done$8 ? done$8 : pull);
2125
2174
  })));
2126
2175
  const broadcast = dual(2, (self, options) => map$2(toPubSubTake(self, options), fromPubSubTake));
2127
2176
  const pipeThroughChannel = dual(2, (self, channel) => fromChannel(pipeTo(self.channel, channel)));
2128
- const decodeText = dual((args) => isStream(args[0]), (self, options) => suspend(() => {
2129
- const decoder = new TextDecoder(options?.encoding);
2130
- return map(self, (chunk) => decoder.decode(chunk, { stream: true }));
2131
- }));
2177
+ const decodeText = dual((args) => isStream(args[0]), (self, options) => self.channel.pipe(pipeTo(decodeText$1(options?.encoding)), fromChannel));
2132
2178
  const splitLines = (self) => self.channel.pipe(pipeTo(splitLines$1()), fromChannel);
2133
2179
  const onExit = dual(2, (self, finalizer) => fromChannel(onExit$1(self.channel, finalizer)));
2134
- const onEnd = dual(2, (self, onEnd) => fromChannel(onEnd$1(self.channel, onEnd)));
2135
2180
  const ensuring = dual(2, (self, finalizer) => fromChannel(ensuring$1(self.channel, finalizer)));
2136
2181
  const provideContext = dual(2, (self, context) => fromChannel(provideContext$1(self.channel, context)));
2137
2182
  const provideService = dual(3, (self, key, service) => fromChannel(provideService$1(self.channel, key, service)));
2138
- const run = dual(2, (self, sink) => scopedWith((scope) => toPullScoped(self.channel, scope).pipe(flatMap$2((upstream) => sink.transform(upstream, scope)), map$2(([a]) => a))));
2183
+ const run = dual(2, (self, sink) => scopedWith((scope) => toPullScoped(self.channel, scope).pipe(flatMap$2((upstream) => runSink(sink, upstream, scope)), map$2(([a]) => a))));
2184
+ const runSink = (sink, upstream, scope) => restoreUpstreamFailure(sink.transform(upstreamFailureToDefect(upstream), scope));
2139
2185
  const runCollect = (self) => runFold$1(self.channel, () => [], (acc, chunk) => {
2140
2186
  for (let i = 0; i < chunk.length; i++) acc.push(chunk[i]);
2141
2187
  return acc;
@@ -2159,7 +2205,7 @@ const mkString = (self) => runFold$1(self.channel, () => "", (acc, chunk) => acc
2159
2205
  const toAsyncIterableWith = dual(2, (self, context) => ({ [Symbol.asyncIterator]() {
2160
2206
  const runPromise = runPromiseWith(context);
2161
2207
  const runFork = runForkWith(context);
2162
- const scope = makeUnsafe$2();
2208
+ const scope = makeUnsafe$1();
2163
2209
  let pull;
2164
2210
  let currentIter;
2165
2211
  let currentFiber;
@@ -2207,7 +2253,7 @@ const toAsyncIterableWith = dual(2, (self, context) => ({ [Symbol.asyncIterator]
2207
2253
  return close$1(void_$2);
2208
2254
  },
2209
2255
  async throw(error) {
2210
- await closeAndReportError(die$3(error));
2256
+ await closeAndReportError(die$4(error));
2211
2257
  throw error;
2212
2258
  }
2213
2259
  };
@@ -2215,7 +2261,6 @@ const toAsyncIterableWith = dual(2, (self, context) => ({ [Symbol.asyncIterator]
2215
2261
  const toAsyncIterable = (self) => toAsyncIterableWith(self, empty$2());
2216
2262
  const runIntoPubSub = dual((args) => isStream(args[0]), (self, pubsub, options) => runIntoPubSubArray(self.channel, pubsub, options));
2217
2263
  const toPubSubTake = dual(2, (self, options) => toPubSubTake$1(self.channel, options));
2218
- //#endregion
2219
- export { splitLines as $, map as A, unbounded$1 as At, orDie as B, interruptAs as Bt, fromChannel as C, offerAll as Ct, fromQueue as D, shutdownUnsafe as Dt, fromPull as E, poll as Et, merge as F, await_ as Ft, runCollect as G, provideContext as H, runIn as Ht, mergeAll as I, getCurrent as It, runForEach as J, runDrain as K, mkString as L, interrupt as Lt, mapArrayEffect as M, set as Mt, mapEffect as N, update as Nt, fromReadableStream as O, take$1 as Ot, mapError as P, makeUnsafe$1 as Pt, scoped as Q, onEnd as R, interruptAll as Rt, fromAsyncIterable as S, offer as St, fromPubSub as T, offerUnsafe as Tt, provideService as U, camelToSnake as Ut, pipeThroughChannel as V, join as Vt, run as W, toLowerCase as Wt, runIntoPubSub as X, runForEachArray as Y, runLast as Z, flatMap as _, endUnsafe as _t, catchTags as a, tap as at, fromArray as b, failCauseUnsafe as bt, decodeText as c, unwrap as ct, empty as d, toTransform as dt, succeed as et, ensuring as f, unwrap$1 as ft, filterMap as g, end as gt, filter as h, bounded as ht, catchReason as i, takeWhile as it, mapArray as j, make$4 as jt, isStream as k, unbounded as kt, die as l, fromTransform as lt, failCause as m, makeUnsafe as mt, callback as n, take as nt, catch_ as o, toAsyncIterable as ot, fail as p, make as pt, runFold as q, catchIf as r, takeUntil as rt, concat as s, transduce as st, broadcast as t, suspend as tt, drop as u, mapDone as ut, flattenArray as v, fail$2 as vt, fromEffect as w, offerAllUnsafe as wt, fromArrayEffect as x, make$1 as xt, flattenIterable as y, failCause$2 as yt, onExit as z, interruptAllAs as zt };
2264
+ export { runLast as $, fromQueue as A, shutdownUnsafe as At, mkString as B, interrupt as Bt, fromArray as C, failCauseUnsafe as Ct, fromEffect as D, offerAllUnsafe as Dt, fromChannel as E, offerAll as Et, mapArrayEffect as F, make$4 as Ft, provideService as G, camelToSnake as Gt, orDie as H, interruptAllAs as Ht, mapEffect as I, set as It, runDrain as J, run as K, toLowerCase as Kt, mapError as L, update as Lt, isStream as M, take$1 as Mt, map as N, unbounded as Nt, fromPubSub as O, offerUnsafe as Ot, mapArray as P, unbounded$1 as Pt, runIntoPubSub as Q, merge as R, await_ as Rt, flattenIterable as S, failCause$2 as St, fromAsyncIterable as T, offer as Tt, pipeThroughChannel as U, join as Ut, onExit as V, interruptAll as Vt, provideContext as W, runIn as Wt, runForEach as X, runFold as Y, runForEachArray as Z, filter as _, makeUnsafe as _t, catchReason as a, takeUntil as at, flatten as b, endUnsafe as bt, concat as c, tapError as ct, drainFork as d, unwrap as dt, scoped as et, drop as f, fromTransform as ft, failCause as g, make as gt, fail as h, unwrap$1 as ht, catchIf as i, take as it, fromReadableStream as j, sliding as jt, fromPull as k, poll as kt, decodeText as l, toAsyncIterable as lt, ensuring as m, toTransform as mt, callback as n, succeed as nt, catchTags as o, takeWhile as ot, empty as p, mapDone as pt, runCollect as q, catchCause as r, suspend as rt, catch_ as s, tap as st, broadcast as t, splitLines as tt, die as u, transduce as ut, filterMap as v, bounded as vt, fromArrayEffect as w, make$1 as wt, flattenArray as x, fail$2 as xt, flatMap as y, end as yt, mergeAll as z, getCurrent as zt };
2220
2265
 
2221
- //# sourceMappingURL=Stream-DCB3_nIX.mjs.map
2266
+ //# sourceMappingURL=Stream-Dwvj9X5X.mjs.map