clanka 0.8.3 → 0.8.5

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 (40) hide show
  1. package/dist/AgentExecutor.d.ts.map +1 -1
  2. package/dist/AgentExecutor.js +1 -1
  3. package/dist/AgentExecutor.js.map +1 -1
  4. package/dist/AgentExecutor.test.d.ts +2 -0
  5. package/dist/AgentExecutor.test.d.ts.map +1 -0
  6. package/dist/AgentExecutor.test.js +87 -0
  7. package/dist/AgentExecutor.test.js.map +1 -0
  8. package/dist/AgentSkills.test.js +1 -0
  9. package/dist/AgentSkills.test.js.map +1 -1
  10. package/dist/AgentTools.d.ts.map +1 -1
  11. package/dist/AgentTools.js +2 -1
  12. package/dist/AgentTools.js.map +1 -1
  13. package/dist/Compaction.test.js +1 -0
  14. package/dist/Compaction.test.js.map +1 -1
  15. package/dist/bin/{Effect-BCeySOy1.mjs → Effect-BEUn4I5E.mjs} +339 -288
  16. package/dist/bin/Effect-BEUn4I5E.mjs.map +1 -0
  17. package/dist/bin/{McpClient-DP4jlaD1.mjs → McpClient-C0FVuDj2.mjs} +218 -62
  18. package/dist/bin/McpClient-C0FVuDj2.mjs.map +1 -0
  19. package/dist/bin/{OutputFormatter-Ch8yFytV.mjs → OutputFormatter-DffD5oxX.mjs} +8 -8
  20. package/dist/bin/OutputFormatter-DffD5oxX.mjs.map +1 -0
  21. package/dist/bin/{Schema-C9JQ5hI0.mjs → Schema-CjUGw2Xh.mjs} +480 -384
  22. package/dist/bin/Schema-CjUGw2Xh.mjs.map +1 -0
  23. package/dist/bin/{SemanticSearch-BJGnYhFt.mjs → SemanticSearch-CFB73IPb.mjs} +321 -268
  24. package/dist/bin/SemanticSearch-CFB73IPb.mjs.map +1 -0
  25. package/dist/bin/{Stream-CgH3SuLu.mjs → Stream-Cu6P7ZHo.mjs} +180 -172
  26. package/dist/bin/Stream-Cu6P7ZHo.mjs.map +1 -0
  27. package/dist/bin/cli.mjs +306 -259
  28. package/dist/bin/cli.mjs.map +1 -1
  29. package/package.json +20 -20
  30. package/src/AgentExecutor.test.ts +133 -0
  31. package/src/AgentExecutor.ts +1 -2
  32. package/src/AgentSkills.test.ts +1 -0
  33. package/src/AgentTools.ts +2 -1
  34. package/src/Compaction.test.ts +1 -0
  35. package/dist/bin/Effect-BCeySOy1.mjs.map +0 -1
  36. package/dist/bin/McpClient-DP4jlaD1.mjs.map +0 -1
  37. package/dist/bin/OutputFormatter-Ch8yFytV.mjs.map +0 -1
  38. package/dist/bin/Schema-C9JQ5hI0.mjs.map +0 -1
  39. package/dist/bin/SemanticSearch-BJGnYhFt.mjs.map +0 -1
  40. package/dist/bin/Stream-CgH3SuLu.mjs.map +0 -1
@@ -1,17 +1,17 @@
1
- import { $ as isEffect, $a as map$1, $o as symbol$1, $t as uninterruptibleMask, Aa as getOrUndefined, Ai as ParentSpan, Ao as assignProperty, B as fnUntraced, Br as succeed$2, C as catch_, Cs as constUndefined, D as delay, Di as updateContext, Dr as doneUnsafe, Ds as flow, E as contextWith, Ea as add, Er as done, Es as dual, Et as provideService, F as filterOrFail, Fa as merge, Fr as failCause, Go as equals, Gt as tap, H as forEach, Hr as ClockRef, I as flatMap, It as scope, Jr as contextWith$1, K as forkScoped, Ko as symbol, Ln as filterInterruptors, Lt as scoped, M as fail$1, Ma as getUnsafe, Mr as makeUnsafe$2, Mt as runFork, Na as make$9, Nt as runForkWith, O as die, Oa as get$1, Oi as void_$2, Oo as withFiber$1, Os as identity, Pi as empty, Pr as fail, Ps as pipeArguments, Qr as exitHasInterrupts, Ra as filter, Ri as flatMapNullishOr, Rr as isFailure, S as catchTags, Si as succeed$1, St as orElseSucceed, T as context, Ta as Service, Tt as provideContext, U as forever, Ua as fromNullishOr, Ut as suspend, Va as flatten, Vi as isArrayNonEmpty, Vn as hasInterruptsOnly, Vr as void_$3, Vt as succeed, Wo as byReferenceUnsafe, Wt as sync, X as ignore, Xt as try_, Y as gen, Ya as isNone, Yo as hash, Yt as tryPromise, Z as interrupt, Za as isSome, Zi as sort, Zr as endSpan, _a as minutes, _r as close, _t as onExit, a as andThen, at as makeSpanScoped, ba as seconds, c as as, co as Number$1, da as fromInputUnsafe, eo as match, er as effect, es as hasProperty, et as logDebug, fa as infinity, fn as Class$1, ft as matchCauseEager, ga as millis, gi as makeSpanUnsafe, h as catchDefect, ha as isZero, hr as addFinalizer, i as all, io as some, js as pipe, ka as getOption, kn as NoSuchElementError, kr as into, kt as request$1, ln as withSpan, lr as provide$1, lt as mapError, m as catchCause, ma as isFinite, mo as make$10, mr as Scope, n as acquireUseRelease, nn as useSpan, nr as effectDiscard, o as annotateCurrentSpan, on as withFiber, ot as map, qi as map$2, ri as fiberInterrupt, rn as void_$1, rt as logInfo, s as annotateLogs, si as fiberJoin, sn as withLogSpan, ss as isNotNull, t as acquireRelease, to as none, tr as effectContext, u as asVoid, ui as forkUnsafe, ur as provideMerge, vi as onExit$1, vo as Prototype, vt as onExitPrimitive, wa as Reference, wr as TracerTimingEnabled, x as catchTag, xa as toMillis, xo as PipeInspectableProto, xr as provide, xt as orDie, y as catchNoSuchElement, yr as make$8, z as fn, zi as fromIterable, zr as isSuccess, zt as serviceOption } from "./Effect-BCeySOy1.mjs";
2
- import { $ as tap$1, At as getCurrent, B as provideService$1, Ft as join$1, H as runCollect, It as runIn, Pt as interruptAs, T as fromQueue, U as runDrain, bt as offerUnsafe, c as die$1, ct as make$12, g as flatMap$1, gt as make$11, ht as failCauseUnsafe, lt as makeUnsafe$3, tt as unwrap, v as fromArray, y as fromArrayEffect } from "./Stream-CgH3SuLu.mjs";
3
- import { A as OptionFromNullOr, Cn as transform, D as NullOr, Dt as mutable, F as String$1, Ft as toType, I as Struct$2, In as formatIsoDate, It as withConstructorDefault, J as Union$2, Jn as TaggedError$1, O as Number$2, Ot as optional, Rn as now, S as Natural, St as isSchema, Wn as Clock, Z as brand, _n as transform$1, bn as dateTimeUtcFromInput, c as DateTimeUtcFromDate, d as Defect, i as BooleanFromBit, k as Option, kt as optionalKey, l as DateTimeUtcFromMillis, n as ArraySchema, nt as decodeTo, o as Class$2, ot as encodeEffect, r as Boolean, rt as decodeUnknownEffect, s as DateTimeUtc, u as DateTimeUtcFromString, ut as instanceOf, xn as map$3, yn as transformOptional, z as TaggedError, zn as removeTime, zt as evolve } from "./Schema-C9JQ5hI0.mjs";
4
- import { C as set, D as toPredicate, E as has, S as remove, T as compose, _ as empty$1, a as makeGrouped, b as isEmpty, c as SemanticSearch, d as map$4, f as make$14, g as FileSystem, h as Path, i as batchN, l as maybeRemoveFile, m as Console, n as EmbeddingModel, o as setDelay, p as ChildProcessSpawner, r as EmbeddingRequest, s as withSpan$1, t as Dimensions, u as maybeUpdateFile, v as forEach$1, w as size, x as make$13, y as get$2 } from "./cli.mjs";
1
+ import { $r as exitHasInterrupts, Aa as getOption, An as NoSuchElementError, Ar as into, At as request$1, B as fn, Bi as fromIterable, Br as isSuccess, Bt as serviceOption, C as catchTags, Ci as succeed$1, Ct as orElseSucceed, D as contextWith, Da as add, Dr as done, Ds as dual, Dt as provideService, E as context, Ea as Service, Et as provideContext, Fi as empty, Fr as fail$1, Fs as pipeArguments, Go as byReferenceUnsafe, Gt as sync, Ha as flatten, Hi as isArrayNonEmpty, Hn as hasInterruptsOnly, Hr as void_$3, Ht as succeed, I as filterOrFail, Ia as merge, Ir as failCause, Ji as map$2, Ko as equals, Kt as tap, L as flatMap, Lt as scope, Ms as pipe, Mt as retry, N as fail, Na as getUnsafe, Nr as makeUnsafe$2, Nt as runFork, O as delay, Oi as updateContext, Or as doneUnsafe, Os as flow, Pa as make$8, Pt as runForkWith, Q as interrupt, Qa as isSome, Qi as sort, Qr as endSpan, Rn as filterInterruptors, Rt as scoped, S as catchTag, Sa as toMillis, So as PipeInspectableProto, Sr as provide, St as orDie, Ta as Reference, Tr as TracerTimingEnabled, U as forEach, Ur as ClockRef, V as fnUntraced, Vr as succeed$2, W as forever, Wa as fromNullishOr, Wt as suspend, X as gen, Xa as isNone, Xo as hash, Xt as tryPromise, Yr as contextWith$1, Z as ignore, Zt as try_, _a as millis, _i as makeSpanUnsafe, _t as onError, a as andThen, ao as some, b as catchNoSuchElement, bi as onExit$1, bn as spaced, br as make$7, c as as, ci as fiberJoin, cn as withLogSpan, cs as isNotNull, di as forkUnsafe, dr as provideMerge, en as uninterruptibleMask, eo as map$1, es as symbol$1, et as isEffect, fa as fromInputUnsafe, g as catchDefect, ga as isZero, gr as addFinalizer, ha as isFinite, ho as make$9, hr as Scope, i as all, ii as fiberInterrupt, in as void_$1, it as logInfo, ja as getOrUndefined, ji as ParentSpan, jo as assignProperty, k as die, ka as get$1, ki as void_$2, ko as withFiber$1, ks as identity, lo as Number$1, m as catchCause, mt as matchCauseEffect, n as acquireUseRelease, no as none, nr as effectContext, o as annotateCurrentSpan, ot as makeSpanScoped, pa as infinity, pn as Class$1, pt as matchCauseEager, q as forkScoped, qo as symbol, qt as tapCause, rn as useSpan, rr as effectDiscard, s as annotateLogs, sn as withFiber, st as map, t as acquireRelease, to as match, tr as effect, ts as hasProperty, tt as logDebug, u as asVoid, un as withSpan, ur as provide$1, ut as mapError, va as minutes, vr as close, vt as onExit, w as catch_, wa as zero, ws as constUndefined, xa as seconds, y as catchIf, yo as Prototype, yt as onExitPrimitive, za as filter, zi as flatMapNullishOr, zr as isFailure } from "./Effect-BEUn4I5E.mjs";
2
+ import { $ as tap$1, B as provideService$1, Ft as interruptAs, H as runCollect, It as join$1, Lt as runIn, T as fromQueue, U as runDrain, bt as offerUnsafe, c as die$1, ct as make$11, g as flatMap$1, gt as make$10, ht as failCauseUnsafe, lt as makeUnsafe$3, tt as unwrap, v as fromArray, y as fromArrayEffect } from "./Stream-Cu6P7ZHo.mjs";
3
+ import { A as OptionFromNullOr, Cn as transform, D as NullOr, Dt as mutable, F as String$1, Ft as toType, Gn as monotonicTimeNanos, I as Struct$2, In as formatIsoDate, It as withConstructorDefault, J as Union$2, O as Number$2, Ot as optional, Rn as now, S as Natural, St as isSchema, Wn as Clock, Yn as TaggedError$1, Z as brand, _n as transform$1, bn as dateTimeUtcFromInput, c as DateTimeUtcFromDate, d as Defect, i as BooleanFromBit, k as Option, kt as optionalKey, l as DateTimeUtcFromMillis, n as ArraySchema, nt as decodeTo, o as Class$2, ot as encodeEffect, r as Boolean, rt as decodeUnknownEffect, s as DateTimeUtc, u as DateTimeUtcFromString, ut as instanceOf, xn as map$3, yn as transformOptional, z as TaggedError, zn as removeTime, zt as evolve } from "./Schema-CjUGw2Xh.mjs";
4
+ import { C as set, D as toPredicate, E as has, S as remove, T as compose, _ as empty$1, a as makeGrouped, b as isEmpty, c as SemanticSearch, d as map$4, f as make$13, g as FileSystem, h as Path, i as batchN, l as maybeRemoveFile, m as Console, n as EmbeddingModel, o as setDelay, p as ChildProcessSpawner, r as EmbeddingRequest, s as withSpan$1, t as Dimensions, u as maybeUpdateFile, v as forEach$1, w as size, x as make$12, y as get$2 } from "./cli.mjs";
5
5
  import { createHash } from "node:crypto";
6
6
  import { DatabaseSync, backup } from "node:sqlite";
7
7
  import TreeSitter from "tree-sitter";
8
8
  import TreeSitterJavaScript from "tree-sitter-javascript";
9
9
  import TreeSitterTypeScript from "tree-sitter-typescript";
10
10
  import { getLoadablePath } from "sqlite-vec";
11
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/reactivity/Reactivity.js
11
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/reactivity/Reactivity.js
12
12
  const TypeId$6 = "~effect/reactivity/Reactivity";
13
13
  const Reactivity = Service("effect/reactivity/Reactivity");
14
- const make$7 = sync(() => {
14
+ const make$6 = sync(() => {
15
15
  const handlers = new Map();
16
16
  const invalidateUnsafe = (keys) => {
17
17
  keysToHashes(keys, (hash) => {
@@ -52,7 +52,7 @@ const make$7 = sync(() => {
52
52
  const query = (keys, effect) => gen(function* () {
53
53
  const services = yield* context();
54
54
  const scope = get$1(services, Scope);
55
- const results = yield* make$11();
55
+ const results = yield* make$10();
56
56
  const runFork = flow(runForkWith(services), runIn(scope));
57
57
  let running = false;
58
58
  let pending = false;
@@ -100,7 +100,7 @@ const make$7 = sync(() => {
100
100
  });
101
101
  });
102
102
  var PendingInvalidation = class extends Service()("effect/reactivity/Reactivity/PendingInvalidation") {};
103
- const layer$5 = effect(Reactivity)(make$7);
103
+ const layer$5 = effect(Reactivity)(make$6);
104
104
  function stringOrHash(u) {
105
105
  switch (typeof u) {
106
106
  case "string":
@@ -122,7 +122,181 @@ const keysToHashes = (keys, f) => {
122
122
  }
123
123
  };
124
124
  //#endregion
125
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/sql/Statement.js
125
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlError.js
126
+ const TypeId$5 = "~effect/sql/SqlError";
127
+ const ReasonTypeId = "~effect/sql/SqlError/Reason";
128
+ const ReasonFields = {
129
+ cause: Defect(),
130
+ message: optional(String$1),
131
+ operation: optional(String$1)
132
+ };
133
+ var ConnectionError = class extends TaggedError("effect/sql/SqlError/ConnectionError")("ConnectionError", ReasonFields) {
134
+ [ReasonTypeId] = ReasonTypeId;
135
+ get isRetryable() {
136
+ return true;
137
+ }
138
+ };
139
+ var AuthenticationError = class extends TaggedError("effect/sql/SqlError/AuthenticationError")("AuthenticationError", ReasonFields) {
140
+ [ReasonTypeId] = ReasonTypeId;
141
+ get isRetryable() {
142
+ return false;
143
+ }
144
+ };
145
+ var AuthorizationError = class extends TaggedError("effect/sql/SqlError/AuthorizationError")("AuthorizationError", ReasonFields) {
146
+ [ReasonTypeId] = ReasonTypeId;
147
+ get isRetryable() {
148
+ return false;
149
+ }
150
+ };
151
+ var SqlSyntaxError = class extends TaggedError("effect/sql/SqlError/SqlSyntaxError")("SqlSyntaxError", ReasonFields) {
152
+ [ReasonTypeId] = ReasonTypeId;
153
+ get isRetryable() {
154
+ return false;
155
+ }
156
+ };
157
+ const UniqueViolationFields = {
158
+ ...ReasonFields,
159
+ constraint: String$1
160
+ };
161
+ var UniqueViolation = class extends TaggedError("effect/sql/SqlError/UniqueViolation")("UniqueViolation", UniqueViolationFields) {
162
+ [ReasonTypeId] = ReasonTypeId;
163
+ get isRetryable() {
164
+ return false;
165
+ }
166
+ };
167
+ var ConstraintError = class extends TaggedError("effect/sql/SqlError/ConstraintError")("ConstraintError", ReasonFields) {
168
+ [ReasonTypeId] = ReasonTypeId;
169
+ get isRetryable() {
170
+ return false;
171
+ }
172
+ };
173
+ var DeadlockError = class extends TaggedError("effect/sql/SqlError/DeadlockError")("DeadlockError", ReasonFields) {
174
+ [ReasonTypeId] = ReasonTypeId;
175
+ get isRetryable() {
176
+ return true;
177
+ }
178
+ };
179
+ var SerializationError = class extends TaggedError("effect/sql/SqlError/SerializationError")("SerializationError", ReasonFields) {
180
+ [ReasonTypeId] = ReasonTypeId;
181
+ get isRetryable() {
182
+ return true;
183
+ }
184
+ };
185
+ var LockTimeoutError = class extends TaggedError("effect/sql/SqlError/LockTimeoutError")("LockTimeoutError", ReasonFields) {
186
+ [ReasonTypeId] = ReasonTypeId;
187
+ get isRetryable() {
188
+ return true;
189
+ }
190
+ };
191
+ var StatementTimeoutError = class extends TaggedError("effect/sql/SqlError/StatementTimeoutError")("StatementTimeoutError", ReasonFields) {
192
+ [ReasonTypeId] = ReasonTypeId;
193
+ get isRetryable() {
194
+ return true;
195
+ }
196
+ };
197
+ var UnknownError = class extends TaggedError("effect/sql/SqlError/UnknownError")("UnknownError", ReasonFields) {
198
+ [ReasonTypeId] = ReasonTypeId;
199
+ get isRetryable() {
200
+ return false;
201
+ }
202
+ };
203
+ const SqlErrorReason = Union$2([
204
+ ConnectionError,
205
+ AuthenticationError,
206
+ AuthorizationError,
207
+ SqlSyntaxError,
208
+ UniqueViolation,
209
+ ConstraintError,
210
+ DeadlockError,
211
+ SerializationError,
212
+ LockTimeoutError,
213
+ StatementTimeoutError,
214
+ UnknownError
215
+ ]);
216
+ var SqlError = class extends TaggedError("effect/sql/SqlError")("SqlError", { reason: SqlErrorReason }) {
217
+ [TypeId$5] = TypeId$5;
218
+ cause = this.reason;
219
+ get message() {
220
+ return this.reason.message || this.reason._tag;
221
+ }
222
+ get isRetryable() {
223
+ return this.reason.isRetryable;
224
+ }
225
+ };
226
+ const sqliteCodeFromCause = (cause) => {
227
+ if (!hasProperty(cause, "code")) return;
228
+ const code = cause.code;
229
+ return typeof code === "string" || typeof code === "number" ? code : void 0;
230
+ };
231
+ const sqliteNumericCodeFromCause = (cause) => {
232
+ const code = sqliteCodeFromCause(cause);
233
+ if (typeof code === "number") return code;
234
+ if (!hasProperty(cause, "errno")) return;
235
+ const errno = cause.errno;
236
+ return typeof errno === "number" ? errno : void 0;
237
+ };
238
+ const matchesSqliteNumericCode = (cause, expected) => {
239
+ if (sqliteCodeFromCause(cause) === expected) return true;
240
+ if (!hasProperty(cause, "errno")) return false;
241
+ return cause.errno === expected;
242
+ };
243
+ const matchesSqliteCode = (code, expected) => code === expected || code.startsWith(expected + "_");
244
+ const UNKNOWN_CONSTRAINT = "unknown";
245
+ const SQLITE_CONSTRAINT_UNIQUE = "SQLITE_CONSTRAINT_UNIQUE";
246
+ const SQLITE_CONSTRAINT_UNIQUE_CODE = 2067;
247
+ const normalizeConstraintIdentifier = (identifier) => {
248
+ if (typeof identifier !== "string") return UNKNOWN_CONSTRAINT;
249
+ const trimmed = identifier.trim();
250
+ return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed;
251
+ };
252
+ const sqliteUniqueConstraintFromCause = (cause) => {
253
+ if (hasProperty(cause, "constraint")) return normalizeConstraintIdentifier(cause.constraint);
254
+ if (!hasProperty(cause, "message")) return UNKNOWN_CONSTRAINT;
255
+ const message = cause.message;
256
+ if (typeof message !== "string") return UNKNOWN_CONSTRAINT;
257
+ const index = message.indexOf("UNIQUE constraint failed:");
258
+ return index === -1 ? UNKNOWN_CONSTRAINT : normalizeConstraintIdentifier(message.slice(index + 25));
259
+ };
260
+ const classifySqliteError = (cause, { message, operation } = {}) => {
261
+ const props = {
262
+ cause,
263
+ message,
264
+ operation
265
+ };
266
+ const code = sqliteCodeFromCause(cause);
267
+ const numericCode = sqliteNumericCodeFromCause(cause);
268
+ if (code === SQLITE_CONSTRAINT_UNIQUE || matchesSqliteNumericCode(cause, SQLITE_CONSTRAINT_UNIQUE_CODE)) return new UniqueViolation({
269
+ ...props,
270
+ constraint: sqliteUniqueConstraintFromCause(cause)
271
+ });
272
+ if (typeof code === "string") {
273
+ if (matchesSqliteCode(code, "SQLITE_AUTH")) return new AuthenticationError(props);
274
+ if (matchesSqliteCode(code, "SQLITE_PERM")) return new AuthorizationError(props);
275
+ if (matchesSqliteCode(code, "SQLITE_CONSTRAINT")) return new ConstraintError(props);
276
+ if (matchesSqliteCode(code, "SQLITE_BUSY") || matchesSqliteCode(code, "SQLITE_LOCKED")) return new LockTimeoutError(props);
277
+ if (matchesSqliteCode(code, "SQLITE_CANTOPEN")) return new ConnectionError(props);
278
+ }
279
+ if (typeof numericCode === "number") switch (numericCode & 255) {
280
+ case 23: return new AuthenticationError(props);
281
+ case 3: return new AuthorizationError(props);
282
+ case 19: return new ConstraintError(props);
283
+ case 5:
284
+ case 6: return new LockTimeoutError(props);
285
+ case 14: return new ConnectionError(props);
286
+ default: return new UnknownError(props);
287
+ }
288
+ return new UnknownError(props);
289
+ };
290
+ var ResultLengthMismatch = class extends TaggedError("effect/sql/ResultLengthMismatch")("ResultLengthMismatch", {
291
+ expected: Natural,
292
+ actual: Natural
293
+ }) {
294
+ get message() {
295
+ return `Expected ${this.expected} results but got ${this.actual}`;
296
+ }
297
+ };
298
+ //#endregion
299
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/Statement.js
126
300
  const FragmentTypeId = "~effect/sql/Statement/Fragment";
127
301
  const fragment = (segments) => ({
128
302
  [FragmentTypeId]: FragmentTypeId,
@@ -178,7 +352,7 @@ const recordUpdateHelperSingle = (value, omit) => Object.assign(Object.create(Re
178
352
  omit,
179
353
  returningIdentifier: void 0
180
354
  });
181
- const make$6 = (acquirer, compiler, spanAttributes, transformRows, borrower) => {
355
+ const make$5 = (acquirer, compiler, spanAttributes, transformRows, borrower) => {
182
356
  const cache = transformRows === void 0 ? constructorCache.noTransforms : constructorCache.transforms;
183
357
  if (cache.has(acquirer)) return cache.get(acquirer);
184
358
  const self = Object.assign(function sql(strings, ...args) {
@@ -557,7 +731,7 @@ const StatementProto = {
557
731
  const withStatement = (self, span, f) => withFiber((fiber) => {
558
732
  const transform = fiber.getRef(CurrentTransformer);
559
733
  if (transform === void 0) return f(self, fiber);
560
- return flatMap(transform(self, make$6(self.acquirer, self.compiler, self.spanAttributes, self.transformRows, self.borrower), fiber, span), (statement) => f(statement, fiber));
734
+ return flatMap(transform(self, make$5(self.acquirer, self.compiler, self.spanAttributes, self.transformRows, self.borrower), fiber, span), (statement) => f(statement, fiber));
561
735
  });
562
736
  const isSegment = (u) => {
563
737
  if (!hasProperty(u, "_tag")) return false;
@@ -612,12 +786,12 @@ function in_() {
612
786
  }
613
787
  const neverFragment = fragment([literal("1=0")]);
614
788
  //#endregion
615
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/sql/SqlClient.js
616
- const TypeId$5 = "~effect/sql/SqlClient";
789
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlClient.js
790
+ const TypeId$4 = "~effect/sql/SqlClient";
617
791
  const SqlClient = Service("effect/sql/SqlClient");
618
792
  let clientIdCounter = 0;
619
793
  let transactionSemaphoreIdCounter = 0;
620
- const make$5 = fnUntraced(function* (options) {
794
+ const make$4 = fnUntraced(function* (options) {
621
795
  const transactionService = options.transactionService ?? TransactionConnection(clientIdCounter++);
622
796
  const getConnection = flatMap(serviceOption(transactionService), match({
623
797
  onNone: () => options.acquirer,
@@ -634,11 +808,12 @@ const make$5 = fnUntraced(function* (options) {
634
808
  const withTransaction = makeWithTransaction({
635
809
  transactionService,
636
810
  spanAttributes: options.spanAttributes,
637
- acquireConnection: flatMap(make$8(), (scope) => map(provide(transactionAcquirer, scope), (conn) => [scope, conn])),
811
+ acquireConnection: flatMap(make$7(), (scope) => provide(transactionAcquirer, scope).pipe(onError((cause) => close(scope, failCause(cause))), map((conn) => [scope, conn]))),
638
812
  begin: (conn) => control(conn, beginTransaction),
639
813
  savepoint: (conn, id) => control(conn, savepoint(`effect_sql_${id}`)),
640
814
  releaseSavepoint: releaseSavepoint ? (conn, id) => control(conn, releaseSavepoint(`effect_sql_${id}`)) : void 0,
641
- commit: (conn) => control(conn, commit),
815
+ commit: typeof commit === "string" ? (conn) => control(conn, commit) : commit,
816
+ onCommitFailure: options.onCommitFailure,
642
817
  rollback: (conn) => control(conn, rollback),
643
818
  rollbackSavepoint: (conn, id) => control(conn, rollbackSavepoint(`effect_sql_${id}`))
644
819
  });
@@ -647,15 +822,15 @@ const make$5 = fnUntraced(function* (options) {
647
822
  onNone: () => options.borrower(f),
648
823
  onSome: ([conn]) => f(conn)
649
824
  }));
650
- const client = Object.assign(make$6(getConnection, options.compiler, options.spanAttributes, options.transformRows, borrower), {
651
- [TypeId$5]: TypeId$5,
825
+ const client = Object.assign(make$5(getConnection, options.compiler, options.spanAttributes, options.transformRows, borrower), {
826
+ [TypeId$4]: TypeId$4,
652
827
  safe: void 0,
653
828
  withTransaction,
654
829
  transactionService,
655
830
  reserve: transactionAcquirer,
656
831
  withoutTransforms() {
657
832
  if (options.transformRows === void 0) return this;
658
- const statement = make$6(getConnection, options.compiler.withoutTransform, options.spanAttributes, void 0, borrower);
833
+ const statement = make$5(getConnection, options.compiler.withoutTransform, options.spanAttributes, void 0, borrower);
659
834
  const client = Object.assign(statement, {
660
835
  ...this,
661
836
  ...statement
@@ -670,6 +845,39 @@ const make$5 = fnUntraced(function* (options) {
670
845
  client.safe = client;
671
846
  return client;
672
847
  });
848
+ const makeSqliteAcquirers = (options) => {
849
+ const { isTransaction, semaphore } = options;
850
+ let poisoned;
851
+ const poison = (cause) => poisoned = new SqlError({ reason: new ConnectionError({
852
+ message: "SQLite connection cannot be reused after failed COMMIT cleanup",
853
+ operation: "rollback",
854
+ cause
855
+ }) });
856
+ const rollback = (conn) => {
857
+ if (isTransaction) return isTransaction(conn) ? asVoid(conn.executeUnprepared("ROLLBACK", [], void 0)) : void_$1;
858
+ return conn.executeUnprepared("ROLLBACK", [], void 0).pipe(asVoid, catchIf(isNoTransactionError, () => void_$1));
859
+ };
860
+ const available = flatMap(options.connection, (conn) => {
861
+ if (poisoned === void 0) return succeed(conn);
862
+ return matchCauseEffect(rollback(conn), {
863
+ onFailure: (cause) => fail(poison(cause)),
864
+ onSuccess: () => {
865
+ poisoned = void 0;
866
+ return succeed(conn);
867
+ }
868
+ });
869
+ });
870
+ return {
871
+ acquirer: semaphore.withPermits(1)(available),
872
+ transactionAcquirer: uninterruptibleMask((restore) => flatMap(scope, (scope) => restore(semaphore.take(1)).pipe(andThen(addFinalizer(scope, semaphore.release(1))), andThen(available)))),
873
+ onCommitFailure: (conn) => tapCause(rollback(conn), (cause) => sync(() => poison(cause)))
874
+ };
875
+ };
876
+ const isNoTransactionError = (error) => {
877
+ const cause = error.reason.cause;
878
+ const message = typeof cause === "string" ? cause : hasProperty(cause, "message") && typeof cause.message === "string" ? cause.message : "";
879
+ return /no transaction is active/i.test(message);
880
+ };
673
881
  const makeWithTransaction = (options) => {
674
882
  const transactionSemaphore = Service(`effect/sql/SqlClient/TransactionSemaphore/${transactionSemaphoreIdCounter++}`);
675
883
  return (effect) => uninterruptibleMask((restore) => useSpan("sql.transaction", { kind: "client" }, (span) => withFiber((fiber) => {
@@ -684,7 +892,9 @@ const makeWithTransaction = (options) => {
684
892
  if (isSuccess(exit)) {
685
893
  if (id === 0) {
686
894
  span.event("db.transaction.commit", clock.currentTimeNanosUnsafe());
895
+ const onCommitFailure = options.onCommitFailure;
687
896
  effect = orDie(options.commit(conn));
897
+ if (onCommitFailure) effect = onError(effect, () => orDie(onCommitFailure(conn)));
688
898
  } else {
689
899
  span.event("db.transaction.savepoint", clock.currentTimeNanosUnsafe());
690
900
  effect = void_$1;
@@ -702,23 +912,19 @@ const makeWithTransaction = (options) => {
702
912
  const TransactionConnection = (clientId) => Service(`effect/sql/SqlClient/TransactionConnection/${clientId}`);
703
913
  const SafeIntegers = Reference("effect/sql/SqlClient/SafeIntegers", { defaultValue: () => false });
704
914
  //#endregion
705
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/Cache.js
706
- const TypeId$4 = "~effect/Cache";
915
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/Cache.js
916
+ const TypeId$3 = "~effect/Cache";
707
917
  const makeWith = (lookup, options) => contextWith$1((context) => {
708
918
  const self = Object.create(Proto$1);
709
919
  self.lookup = (key) => updateContext(lookup(key), (input) => merge(context, input));
710
- self.map = make$13();
920
+ self.map = make$12();
711
921
  self.capacity = options.capacity;
712
922
  self.timeToLive = options.timeToLive ? (exit, key) => fromInputUnsafe(options.timeToLive(exit, key)) : defaultTimeToLive;
713
923
  return succeed$1(self);
714
924
  });
715
- const make$4 = (options) => makeWith(options.lookup, {
716
- ...options,
717
- timeToLive: options.timeToLive !== void 0 ? () => options.timeToLive : defaultTimeToLive
718
- });
719
925
  const Proto$1 = {
720
926
  ...PipeInspectableProto,
721
- [TypeId$4]: TypeId$4,
927
+ [TypeId$3]: TypeId$3,
722
928
  toJSON() {
723
929
  return {
724
930
  _id: "Cache",
@@ -730,24 +936,30 @@ const Proto$1 = {
730
936
  const defaultTimeToLive = (_, _key) => infinity;
731
937
  const get = dual(2, (self, key) => withFiber$1((fiber) => {
732
938
  const oentry = get$2(self.map, key);
733
- if (isSome(oentry) && !hasExpired(oentry.value, fiber)) {
939
+ if (isSome(oentry)) {
734
940
  remove(self.map, key);
735
- set(self.map, key, oentry.value);
736
- return oentry.value.await();
941
+ if (!hasExpired(oentry.value, fiber)) {
942
+ set(self.map, key, oentry.value);
943
+ return oentry.value.await();
944
+ }
737
945
  }
738
946
  const entry = new EntryImpl(fiber, self.lookup(key));
947
+ entry.onInterrupt = () => removeEntry(self, key, entry);
948
+ let skipCache = false;
739
949
  entry.fiber.addObserver((exit) => {
950
+ entry.onInterrupt = void 0;
740
951
  if (exitHasInterrupts(exit)) {
741
- const current = get$2(self.map, key);
742
- if (isSome(current) && current.value === entry) remove(self.map, key);
952
+ removeEntry(self, key, entry);
743
953
  return;
744
954
  }
745
955
  const ttl = self.timeToLive(exit, key);
746
- if (isFinite(ttl)) entry.expiresAt = fiber.getRef(ClockRef).currentTimeMillisUnsafe() + toMillis(ttl);
747
- else if (isZero(ttl)) remove(self.map, key);
956
+ if (isZero(ttl)) {
957
+ skipCache = true;
958
+ removeEntry(self, key, entry);
959
+ } else if (isFinite(ttl)) entry.expiresAt = fiber.getRef(ClockRef).currentTimeMillisUnsafe() + toMillis(ttl);
748
960
  });
749
961
  const exit = entry.fiber.pollUnsafe();
750
- if (exit === void 0 || !exitHasInterrupts(exit)) set(self.map, key, entry);
962
+ if (!skipCache && (exit === void 0 || !exitHasInterrupts(exit))) set(self.map, key, entry);
751
963
  if (Number.isFinite(self.capacity)) checkCapacity(self);
752
964
  return entry.await();
753
965
  }));
@@ -755,6 +967,7 @@ var EntryImpl = class {
755
967
  expiresAt;
756
968
  awaiters;
757
969
  fiber;
970
+ onInterrupt;
758
971
  constructor(parent, valueEffect) {
759
972
  this.fiber = forkUnsafe(parent, valueEffect, true, true);
760
973
  this.awaiters = 0;
@@ -767,10 +980,15 @@ var EntryImpl = class {
767
980
  return onExit$1(fiberJoin(this.fiber), () => {
768
981
  this.awaiters--;
769
982
  if (this.awaiters > 0 || this.fiber.pollUnsafe()) return void_$2;
983
+ this.onInterrupt?.();
770
984
  return fiberInterrupt(this.fiber);
771
985
  });
772
986
  }
773
987
  };
988
+ const removeEntry = (self, key, entry) => {
989
+ const current = get$2(self.map, key);
990
+ if (isSome(current) && current.value === entry) remove(self.map, key);
991
+ };
774
992
  const hasExpired = (entry, fiber) => {
775
993
  if (entry.expiresAt === void 0) return false;
776
994
  return fiber.getRef(ClockRef).currentTimeMillisUnsafe() >= entry.expiresAt;
@@ -785,11 +1003,11 @@ const checkCapacity = (self) => {
785
1003
  }
786
1004
  };
787
1005
  //#endregion
788
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/schema/VariantSchema.js
789
- const TypeId$3 = "~effect/schema/VariantSchema";
790
- const cacheSymbol = Symbol.for(`${TypeId$3}/cache`);
791
- const defaultCacheSymbol = Symbol.for(`${TypeId$3}/defaultCache`);
792
- const isStruct = (u) => hasProperty(u, TypeId$3);
1006
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/schema/VariantSchema.js
1007
+ const TypeId$2 = "~effect/schema/VariantSchema";
1008
+ const cacheSymbol = Symbol.for(`${TypeId$2}/cache`);
1009
+ const defaultCacheSymbol = Symbol.for(`${TypeId$2}/defaultCache`);
1010
+ const isStruct = (u) => hasProperty(u, TypeId$2);
793
1011
  const FieldTypeId = "~effect/schema/VariantSchema/Field";
794
1012
  const isField = (u) => hasProperty(u, FieldTypeId);
795
1013
  const extract$1 = dual((args) => isStruct(args[0]), (self, variant, options) => {
@@ -797,8 +1015,8 @@ const extract$1 = dual((args) => isStruct(args[0]), (self, variant, options) =>
797
1015
  const cache = options?.isDefault === true ? self[defaultCacheSymbol] ?? (self[defaultCacheSymbol] = Object.create(null)) : self[cacheSymbol] ?? (self[cacheSymbol] = Object.create(null));
798
1016
  if (Object.hasOwn(cache, variant)) return cache[variant];
799
1017
  const fields = {};
800
- for (const key of Object.keys(self[TypeId$3])) {
801
- const value = self[TypeId$3][key];
1018
+ for (const key of Object.keys(self[TypeId$2])) {
1019
+ const value = self[TypeId$2][key];
802
1020
  if (value === void 0) continue;
803
1021
  if ("~effect/schema/VariantSchema" in value) {
804
1022
  if (options?.isDefault === true && isSchema(value)) assignProperty(fields, key, value);
@@ -821,7 +1039,7 @@ const make$3 = (options) => {
821
1039
  const schema = extract$1(variantStruct, options.defaultVariant, { isDefault: true });
822
1040
  const SClass = Class$2;
823
1041
  class Base extends SClass(identifier)(schema.fields, annotations) {
824
- static [TypeId$3] = fields;
1042
+ static [TypeId$2] = fields;
825
1043
  }
826
1044
  for (const variant of options.variants) Object.defineProperty(Base, variant, { value: extract$1(variantStruct, variant).annotate({
827
1045
  id: `${identifier}.${variant}`,
@@ -870,7 +1088,7 @@ const StructProto = { pipe() {
870
1088
  } };
871
1089
  const Struct$1 = (fields) => {
872
1090
  const self = Object.create(StructProto);
873
- self[TypeId$3] = fields;
1091
+ self[TypeId$2] = fields;
874
1092
  return self;
875
1093
  };
876
1094
  const FieldProto = {
@@ -890,7 +1108,7 @@ const Union$1 = (members, defaultVariant, variants) => {
890
1108
  return VariantUnion;
891
1109
  };
892
1110
  //#endregion
893
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/schema/Model.js
1111
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/schema/Model.js
894
1112
  const { Class, Field, FieldExcept, FieldOnly, Struct, Union, extract, fieldEvolve } = make$3({
895
1113
  variants: [
896
1114
  "select",
@@ -964,181 +1182,7 @@ const DateTimeUpdateFromNumber = Field({
964
1182
  json: DateTimeUtcFromMillis
965
1183
  });
966
1184
  //#endregion
967
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/sql/SqlError.js
968
- const TypeId$2 = "~effect/sql/SqlError";
969
- const ReasonTypeId = "~effect/sql/SqlError/Reason";
970
- const ReasonFields = {
971
- cause: Defect(),
972
- message: optional(String$1),
973
- operation: optional(String$1)
974
- };
975
- var ConnectionError = class extends TaggedError("effect/sql/SqlError/ConnectionError")("ConnectionError", ReasonFields) {
976
- [ReasonTypeId] = ReasonTypeId;
977
- get isRetryable() {
978
- return true;
979
- }
980
- };
981
- var AuthenticationError = class extends TaggedError("effect/sql/SqlError/AuthenticationError")("AuthenticationError", ReasonFields) {
982
- [ReasonTypeId] = ReasonTypeId;
983
- get isRetryable() {
984
- return false;
985
- }
986
- };
987
- var AuthorizationError = class extends TaggedError("effect/sql/SqlError/AuthorizationError")("AuthorizationError", ReasonFields) {
988
- [ReasonTypeId] = ReasonTypeId;
989
- get isRetryable() {
990
- return false;
991
- }
992
- };
993
- var SqlSyntaxError = class extends TaggedError("effect/sql/SqlError/SqlSyntaxError")("SqlSyntaxError", ReasonFields) {
994
- [ReasonTypeId] = ReasonTypeId;
995
- get isRetryable() {
996
- return false;
997
- }
998
- };
999
- const UniqueViolationFields = {
1000
- ...ReasonFields,
1001
- constraint: String$1
1002
- };
1003
- var UniqueViolation = class extends TaggedError("effect/sql/SqlError/UniqueViolation")("UniqueViolation", UniqueViolationFields) {
1004
- [ReasonTypeId] = ReasonTypeId;
1005
- get isRetryable() {
1006
- return false;
1007
- }
1008
- };
1009
- var ConstraintError = class extends TaggedError("effect/sql/SqlError/ConstraintError")("ConstraintError", ReasonFields) {
1010
- [ReasonTypeId] = ReasonTypeId;
1011
- get isRetryable() {
1012
- return false;
1013
- }
1014
- };
1015
- var DeadlockError = class extends TaggedError("effect/sql/SqlError/DeadlockError")("DeadlockError", ReasonFields) {
1016
- [ReasonTypeId] = ReasonTypeId;
1017
- get isRetryable() {
1018
- return true;
1019
- }
1020
- };
1021
- var SerializationError = class extends TaggedError("effect/sql/SqlError/SerializationError")("SerializationError", ReasonFields) {
1022
- [ReasonTypeId] = ReasonTypeId;
1023
- get isRetryable() {
1024
- return true;
1025
- }
1026
- };
1027
- var LockTimeoutError = class extends TaggedError("effect/sql/SqlError/LockTimeoutError")("LockTimeoutError", ReasonFields) {
1028
- [ReasonTypeId] = ReasonTypeId;
1029
- get isRetryable() {
1030
- return true;
1031
- }
1032
- };
1033
- var StatementTimeoutError = class extends TaggedError("effect/sql/SqlError/StatementTimeoutError")("StatementTimeoutError", ReasonFields) {
1034
- [ReasonTypeId] = ReasonTypeId;
1035
- get isRetryable() {
1036
- return true;
1037
- }
1038
- };
1039
- var UnknownError = class extends TaggedError("effect/sql/SqlError/UnknownError")("UnknownError", ReasonFields) {
1040
- [ReasonTypeId] = ReasonTypeId;
1041
- get isRetryable() {
1042
- return false;
1043
- }
1044
- };
1045
- const SqlErrorReason = Union$2([
1046
- ConnectionError,
1047
- AuthenticationError,
1048
- AuthorizationError,
1049
- SqlSyntaxError,
1050
- UniqueViolation,
1051
- ConstraintError,
1052
- DeadlockError,
1053
- SerializationError,
1054
- LockTimeoutError,
1055
- StatementTimeoutError,
1056
- UnknownError
1057
- ]);
1058
- var SqlError = class extends TaggedError("effect/sql/SqlError")("SqlError", { reason: SqlErrorReason }) {
1059
- [TypeId$2] = TypeId$2;
1060
- cause = this.reason;
1061
- get message() {
1062
- return this.reason.message || this.reason._tag;
1063
- }
1064
- get isRetryable() {
1065
- return this.reason.isRetryable;
1066
- }
1067
- };
1068
- const sqliteCodeFromCause = (cause) => {
1069
- if (!hasProperty(cause, "code")) return;
1070
- const code = cause.code;
1071
- return typeof code === "string" || typeof code === "number" ? code : void 0;
1072
- };
1073
- const sqliteNumericCodeFromCause = (cause) => {
1074
- const code = sqliteCodeFromCause(cause);
1075
- if (typeof code === "number") return code;
1076
- if (!hasProperty(cause, "errno")) return;
1077
- const errno = cause.errno;
1078
- return typeof errno === "number" ? errno : void 0;
1079
- };
1080
- const matchesSqliteNumericCode = (cause, expected) => {
1081
- if (sqliteCodeFromCause(cause) === expected) return true;
1082
- if (!hasProperty(cause, "errno")) return false;
1083
- return cause.errno === expected;
1084
- };
1085
- const matchesSqliteCode = (code, expected) => code === expected || code.startsWith(expected + "_");
1086
- const UNKNOWN_CONSTRAINT = "unknown";
1087
- const SQLITE_CONSTRAINT_UNIQUE = "SQLITE_CONSTRAINT_UNIQUE";
1088
- const SQLITE_CONSTRAINT_UNIQUE_CODE = 2067;
1089
- const normalizeConstraintIdentifier = (identifier) => {
1090
- if (typeof identifier !== "string") return UNKNOWN_CONSTRAINT;
1091
- const trimmed = identifier.trim();
1092
- return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed;
1093
- };
1094
- const sqliteUniqueConstraintFromCause = (cause) => {
1095
- if (hasProperty(cause, "constraint")) return normalizeConstraintIdentifier(cause.constraint);
1096
- if (!hasProperty(cause, "message")) return UNKNOWN_CONSTRAINT;
1097
- const message = cause.message;
1098
- if (typeof message !== "string") return UNKNOWN_CONSTRAINT;
1099
- const index = message.indexOf("UNIQUE constraint failed:");
1100
- return index === -1 ? UNKNOWN_CONSTRAINT : normalizeConstraintIdentifier(message.slice(index + 25));
1101
- };
1102
- const classifySqliteError = (cause, { message, operation } = {}) => {
1103
- const props = {
1104
- cause,
1105
- message,
1106
- operation
1107
- };
1108
- const code = sqliteCodeFromCause(cause);
1109
- const numericCode = sqliteNumericCodeFromCause(cause);
1110
- if (code === SQLITE_CONSTRAINT_UNIQUE || matchesSqliteNumericCode(cause, SQLITE_CONSTRAINT_UNIQUE_CODE)) return new UniqueViolation({
1111
- ...props,
1112
- constraint: sqliteUniqueConstraintFromCause(cause)
1113
- });
1114
- if (typeof code === "string") {
1115
- if (matchesSqliteCode(code, "SQLITE_AUTH")) return new AuthenticationError(props);
1116
- if (matchesSqliteCode(code, "SQLITE_PERM")) return new AuthorizationError(props);
1117
- if (matchesSqliteCode(code, "SQLITE_CONSTRAINT")) return new ConstraintError(props);
1118
- if (matchesSqliteCode(code, "SQLITE_BUSY") || matchesSqliteCode(code, "SQLITE_LOCKED")) return new LockTimeoutError(props);
1119
- if (matchesSqliteCode(code, "SQLITE_CANTOPEN")) return new ConnectionError(props);
1120
- }
1121
- if (typeof numericCode === "number") switch (numericCode & 255) {
1122
- case 23: return new AuthenticationError(props);
1123
- case 3: return new AuthorizationError(props);
1124
- case 19: return new ConstraintError(props);
1125
- case 5:
1126
- case 6: return new LockTimeoutError(props);
1127
- case 14: return new ConnectionError(props);
1128
- default: return new UnknownError(props);
1129
- }
1130
- return new UnknownError(props);
1131
- };
1132
- var ResultLengthMismatch = class extends TaggedError("effect/sql/ResultLengthMismatch")("ResultLengthMismatch", {
1133
- expected: Natural,
1134
- actual: Natural
1135
- }) {
1136
- get message() {
1137
- return `Expected ${this.expected} results but got ${this.actual}`;
1138
- }
1139
- };
1140
- //#endregion
1141
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/sql/SqlResolver.js
1185
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlResolver.js
1142
1186
  const SqlRequestProto = {
1143
1187
  ...Class$1.prototype,
1144
1188
  [symbol](that) {
@@ -1210,7 +1254,7 @@ const void_ = (options) => makeGrouped({
1210
1254
  for (let i = 0; i < entries.length; i++) entries[i].completeUnsafe(void_$3);
1211
1255
  })
1212
1256
  });
1213
- const constNoSuchElement = fail(new NoSuchElementError());
1257
+ const constNoSuchElement = fail$1(new NoSuchElementError());
1214
1258
  const partitionRequests = function* (requests, schema) {
1215
1259
  const len = requests.length;
1216
1260
  const inputs = empty();
@@ -1269,14 +1313,14 @@ function transactionKey(entry) {
1269
1313
  return byReferenceUnsafe(conn);
1270
1314
  }
1271
1315
  //#endregion
1272
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/sql/SqlSchema.js
1316
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlSchema.js
1273
1317
  const findAll = (options) => {
1274
1318
  const encodeRequest = encodeEffect(options.Request);
1275
1319
  const decode = decodeUnknownEffect(mutable(ArraySchema(options.Result)));
1276
1320
  return (request) => flatMap(flatMap(encodeRequest(request), options.execute), decode);
1277
1321
  };
1278
1322
  //#endregion
1279
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/sql/SqlModel.js
1323
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlModel.js
1280
1324
  const makeResolvers = (Model, options) => gen(function* () {
1281
1325
  const sql = yield* SqlClient;
1282
1326
  const idSchema = Model.fields[options.idColumn];
@@ -1406,18 +1450,18 @@ const layer$4 = effect(ChunkRepo, gen(function* () {
1406
1450
  insert: (insert) => request(insert, insertResolver).pipe(catchTags({
1407
1451
  SchemaError: die,
1408
1452
  ResultLengthMismatch: die
1409
- }, (reason) => fail$1(new ChunkRepoError({ reason })))),
1453
+ }, (reason) => fail(new ChunkRepoError({ reason })))),
1410
1454
  findById: (id) => request(id, findByIdResolver).pipe(catchTags({
1411
1455
  SchemaError: die,
1412
- SqlError: (reason) => fail$1(new ChunkRepoError({ reason }))
1456
+ SqlError: (reason) => fail(new ChunkRepoError({ reason }))
1413
1457
  })),
1414
1458
  exists: (hash) => request(hash, exists).pipe(map((result) => result.id), catchNoSuchElement, catchTags({
1415
- SqlError: (reason) => fail$1(new ChunkRepoError({ reason })),
1459
+ SqlError: (reason) => fail(new ChunkRepoError({ reason })),
1416
1460
  SchemaError: die
1417
1461
  })),
1418
1462
  search: fn("ChunkRepo.search")(function* (options) {
1419
1463
  return yield* search(options).pipe(catchTags({
1420
- SqlError: (reason) => fail$1(new ChunkRepoError({ reason })),
1464
+ SqlError: (reason) => fail(new ChunkRepoError({ reason })),
1421
1465
  SchemaError: die
1422
1466
  }));
1423
1467
  }),
@@ -1842,7 +1886,7 @@ const layer$3 = effect(CodeChunker, gen(function* () {
1842
1886
  const listFiles = fn("CodeChunker.listFiles")(function* (options) {
1843
1887
  const root = pathService.resolve(options.root);
1844
1888
  const maxFileSize = options.maxFileSize ?? "1M";
1845
- return yield* pipe(spawner.streamLines(make$14("rg", [
1889
+ return yield* pipe(spawner.streamLines(make$13("rg", [
1846
1890
  "--files",
1847
1891
  "--hidden",
1848
1892
  "--max-filesize",
@@ -1890,7 +1934,7 @@ const layer$3 = effect(CodeChunker, gen(function* () {
1890
1934
  });
1891
1935
  }));
1892
1936
  //#endregion
1893
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/FiberHandle.js
1937
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/FiberHandle.js
1894
1938
  const TypeId$1 = "~effect/FiberHandle";
1895
1939
  const isFiberHandle = (u) => hasProperty(u, TypeId$1);
1896
1940
  const Proto = {
@@ -1955,50 +1999,64 @@ const run$1 = function() {
1955
1999
  const runImpl = (self, effect, options) => withFiber((parent) => {
1956
2000
  if (self.state._tag === "Closed") return interrupt;
1957
2001
  else if (self.state.fiber !== void 0 && options?.onlyIfMissing === true) return sync(constInterruptedFiber);
1958
- const fiber = runForkWith(parent.context)(effect);
2002
+ const fiber = forkUnsafe(parent, effect, options?.startImmediately ?? true, true);
1959
2003
  setUnsafe(self, fiber, options);
1960
2004
  return succeed(fiber);
1961
2005
  });
1962
2006
  //#endregion
1963
- //#region node_modules/.pnpm/@effect+sql-sqlite-node@https+++pkg.pr.new+Effect-TS+effect+@effect+sql-sqlite-node@b30_35f9412091f754d7278f29eda52a67a4/node_modules/@effect/sql-sqlite-node/dist/SqliteClient.js
2007
+ //#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.1_effect@4.0.1/node_modules/@effect/sql-sqlite-node/dist/SqliteClient.js
1964
2008
  const ATTR_DB_SYSTEM_NAME = "db.system.name";
1965
2009
  const MAX_BUSY_TIMEOUT = 2147483647;
2010
+ const NANOS_PER_MILLI = BigInt(1e6);
1966
2011
  const TypeId = "~@effect/sql-sqlite-node/SqliteClient";
1967
2012
  const SqliteClient = Service("@effect/sql-sqlite-node/SqliteClient");
1968
2013
  const make$1 = (options) => gen(function* () {
1969
2014
  const compiler = makeCompilerSqlite(options.transformQueryNames);
1970
2015
  const transformRows = options.transformResultNames ? defaultTransforms(options.transformResultNames).array : void 0;
1971
- const makeConnection = gen(function* () {
1972
- const scope$1 = yield* scope;
1973
- const db = new DatabaseSync(options.filename, {
1974
- readOnly: options.readonly ?? false,
1975
- allowExtension: true
1976
- });
1977
- yield* addFinalizer(scope$1, sync(() => db.close()));
2016
+ const connection = yield* gen(function* () {
2017
+ const db = yield* acquireRelease(try_({
2018
+ try: () => new DatabaseSync(options.filename, {
2019
+ readOnly: options.readonly ?? false,
2020
+ allowExtension: true
2021
+ }),
2022
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to open database", "connect") })
2023
+ }), (db) => sync(() => db.close()));
1978
2024
  db.enableLoadExtension(false);
1979
2025
  const busyTimeout = Math.min(MAX_BUSY_TIMEOUT, Math.max(0, Math.round(toMillis(options.busyTimeout ?? seconds(5)))));
1980
- db.exec(`PRAGMA busy_timeout = ${busyTimeout}`);
1981
- if (options.disableWAL !== true) db.exec("PRAGMA journal_mode = WAL");
2026
+ const exec = (sql) => try_({
2027
+ try: () => db.exec(sql),
2028
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to configure database", "connect") })
2029
+ });
2030
+ yield* exec(`PRAGMA busy_timeout = ${busyTimeout}`);
2031
+ if (options.disableWAL !== true && !options.readonly) {
2032
+ const deadline = (yield* monotonicTimeNanos) + BigInt(busyTimeout) * NANOS_PER_MILLI;
2033
+ const remainingMillis = map(monotonicTimeNanos, (now) => Math.max(0, Number((deadline - now) / NANOS_PER_MILLI)));
2034
+ yield* remainingMillis.pipe(flatMap((remaining) => exec(`PRAGMA busy_timeout = ${remaining}`)), andThen(exec("PRAGMA journal_mode = WAL")), retry({
2035
+ while: (error) => error.reason._tag === "LockTimeoutError" && map(remainingMillis, (remaining) => remaining > 0),
2036
+ schedule: spaced("10 millis")
2037
+ }));
2038
+ yield* exec(`PRAGMA busy_timeout = ${busyTimeout}`);
2039
+ }
1982
2040
  const prepare = (sql) => try_({
1983
2041
  try: () => db.prepare(sql),
1984
2042
  catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to prepare statement", "prepare") })
1985
2043
  });
1986
- const prepareCache = yield* make$4({
2044
+ const prepareCacheTTL = options.prepareCacheTTL ?? minutes(10);
2045
+ const prepareCache = yield* makeWith(prepare, {
1987
2046
  capacity: options.prepareCacheSize ?? 200,
1988
- timeToLive: options.prepareCacheTTL ?? minutes(10),
1989
- lookup: prepare
2047
+ timeToLive: (exit) => isSuccess(exit) ? prepareCacheTTL : zero
1990
2048
  });
1991
2049
  const runStatement = (statement, params, raw) => withFiber((fiber) => {
1992
2050
  const useSafeIntegers = get$1(fiber.context, SafeIntegers);
1993
2051
  return try_({
1994
2052
  try: () => {
1995
2053
  statement.setReadBigInts(useSafeIntegers);
1996
- if (statement.columns().length > 0) return statement.all(...params);
2054
+ if (!raw || statement.columns().length > 0) return statement.all(...params);
1997
2055
  const result = statement.run(...params);
1998
- return raw ? {
2056
+ return {
1999
2057
  changes: result.changes,
2000
2058
  lastInsertRowid: result.lastInsertRowid
2001
- } : [];
2059
+ };
2002
2060
  },
2003
2061
  catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
2004
2062
  });
@@ -2008,9 +2066,7 @@ const make$1 = (options) => gen(function* () {
2008
2066
  return try_({
2009
2067
  try: () => {
2010
2068
  statement.setReadBigInts(useSafeIntegers);
2011
- if (statement.columns().length > 0) return statement.all(...params);
2012
- statement.run(...params);
2013
- return [];
2069
+ return statement.all(...params);
2014
2070
  },
2015
2071
  catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
2016
2072
  });
@@ -2021,9 +2077,7 @@ const make$1 = (options) => gen(function* () {
2021
2077
  try: () => {
2022
2078
  statement.setReadBigInts(useSafeIntegers);
2023
2079
  statement.setReturnArrays(true);
2024
- if (statement.columns().length > 0) return statement.all(...params);
2025
- statement.run(...params);
2026
- return [];
2080
+ return statement.all(...params);
2027
2081
  },
2028
2082
  catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
2029
2083
  });
@@ -2035,6 +2089,7 @@ const make$1 = (options) => gen(function* () {
2035
2089
  }, (statement) => sync(() => statement.setReturnArrays(false)));
2036
2090
  const runValuesUnprepared = (sql, params) => flatMap(prepare(sql), (statement) => runStatementValuesUnprepared(statement, params));
2037
2091
  return identity({
2092
+ isTransaction: () => db.isTransaction,
2038
2093
  execute(sql, params, transformRows) {
2039
2094
  return transformRows ? map(run(sql, params), transformRows) : run(sql, params);
2040
2095
  },
@@ -2076,18 +2131,16 @@ const make$1 = (options) => gen(function* () {
2076
2131
  }
2077
2132
  });
2078
2133
  });
2079
- const semaphore = yield* make$12(1);
2080
- const connection = yield* makeConnection;
2081
- const acquirer = semaphore.withPermits(1)(succeed(connection));
2082
- const transactionAcquirer = uninterruptibleMask((restore) => {
2083
- const fiber = getCurrent();
2084
- const scope = getUnsafe(fiber.context, Scope);
2085
- return as(tap(restore(semaphore.take(1)), () => addFinalizer(scope, semaphore.release(1))), connection);
2134
+ const { acquirer, onCommitFailure, transactionAcquirer } = makeSqliteAcquirers({
2135
+ connection: succeed(connection),
2136
+ semaphore: yield* make$11(1),
2137
+ isTransaction: (conn) => conn.isTransaction()
2086
2138
  });
2087
- return Object.assign(yield* make$5({
2139
+ return Object.assign(yield* make$4({
2088
2140
  acquirer,
2089
2141
  compiler,
2090
2142
  transactionAcquirer,
2143
+ onCommitFailure,
2091
2144
  releaseSavepoint: (name) => `RELEASE SAVEPOINT ${name}`,
2092
2145
  beginTransaction: options.readonly === true ? "BEGIN" : "BEGIN IMMEDIATE",
2093
2146
  spanAttributes: [...options.spanAttributes ? Object.entries(options.spanAttributes) : [], [ATTR_DB_SYSTEM_NAME, "sqlite"]],
@@ -2099,7 +2152,7 @@ const make$1 = (options) => gen(function* () {
2099
2152
  loadExtension: (path) => flatMap(acquirer, (_) => _.loadExtension(path))
2100
2153
  });
2101
2154
  });
2102
- const layer$2 = (config) => effectContext(map(make$1(config), (client) => make$9(SqliteClient, client).pipe(add(SqlClient, client)))).pipe(provide$1(layer$5));
2155
+ const layer$2 = (config) => effectContext(map(make$1(config), (client) => make$8(SqliteClient, client).pipe(add(SqlClient, client)))).pipe(provide$1(layer$5));
2103
2156
  const classifyError = (cause, message, operation) => classifySqliteError(sqliteCauseWithErrno(cause), {
2104
2157
  message,
2105
2158
  operation
@@ -2111,7 +2164,7 @@ const sqliteCauseWithErrno = (cause) => {
2111
2164
  return Object.assign(cause, { errno: errcode });
2112
2165
  };
2113
2166
  //#endregion
2114
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/sql/Migrator.js
2167
+ //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/Migrator.js
2115
2168
  var __rewriteRelativeImportExtension = void 0 && (void 0).__rewriteRelativeImportExtension || function(path, preserveJsx) {
2116
2169
  if (typeof path === "string" && /^\.\.?\//.test(path)) return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function(m, tsx, d, ext, cm) {
2117
2170
  return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : d + ext + "." + cm.toLowerCase() + "js";
@@ -2154,10 +2207,10 @@ const make = ({ dumpSchema = () => void_$1 }) => ({ loader, schemaDirectory, tab
2154
2207
  name,
2155
2208
  createdAt: created_at
2156
2209
  })));
2157
- const loadMigration = ([id, name, load]) => catchDefect(load, (_) => fail$1(new MigrationError({
2210
+ const loadMigration = ([id, name, load]) => catchDefect(load, (_) => fail(new MigrationError({
2158
2211
  kind: "ImportError",
2159
2212
  message: `Could not import migration "${id}_${name}"\n\n${_}`
2160
- }))).pipe(flatMap((_) => isEffect(_) ? succeed(_) : _.default ? succeed(_.default?.default ?? _.default) : fail$1(new MigrationError({
2213
+ }))).pipe(flatMap((_) => isEffect(_) ? succeed(_) : _.default ? succeed(_.default?.default ?? _.default) : fail(new MigrationError({
2161
2214
  kind: "ImportError",
2162
2215
  message: `Default export not found for migration "${id}_${name}"`
2163
2216
  }))), filterOrFail((_) => isEffect(_), () => new MigrationError({
@@ -2204,11 +2257,11 @@ const make = ({ dumpSchema = () => void_$1 }) => ({ loader, schemaDirectory, tab
2204
2257
  return required.map(([id, name]) => [id, name]);
2205
2258
  });
2206
2259
  yield* ensureMigrationsTable;
2207
- const completed = yield* pipe(sql.withTransaction(run), catchTag("MigrationError", (_) => _.kind === "Locked" ? as(logDebug(_.message), []) : fail$1(_)));
2260
+ const completed = yield* pipe(sql.withTransaction(run), catchTag("MigrationError", (_) => _.kind === "Locked" ? as(logDebug(_.message), []) : fail(_)));
2208
2261
  if (schemaDirectory && completed.length > 0) yield* dumpSchema(`${schemaDirectory}/_schema.sql`, table).pipe(catchCause((cause) => logInfo("Could not dump schema", cause)));
2209
2262
  return completed;
2210
2263
  });
2211
- const migrationOrder = make$10(([a], [b]) => Number$1(a, b));
2264
+ const migrationOrder = make$9(([a], [b]) => Number$1(a, b));
2212
2265
  const isConstraintConflict = (error) => error.reason._tag === "ConstraintError" || error.reason._tag === "UniqueViolation";
2213
2266
  const fromRecord = (migrations) => pipe(Object.keys(migrations), flatMapNullishOr((_) => _.match(/^(\d+)_(.+)$/)), map$2(([key, id, name]) => [
2214
2267
  Number(id),
@@ -2216,7 +2269,7 @@ const fromRecord = (migrations) => pipe(Object.keys(migrations), flatMapNullishO
2216
2269
  succeed(migrations[key])
2217
2270
  ]), sort(migrationOrder), succeed);
2218
2271
  //#endregion
2219
- //#region node_modules/.pnpm/@effect+sql-sqlite-node@https+++pkg.pr.new+Effect-TS+effect+@effect+sql-sqlite-node@b30_35f9412091f754d7278f29eda52a67a4/node_modules/@effect/sql-sqlite-node/dist/SqliteMigrator.js
2272
+ //#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.1_effect@4.0.1/node_modules/@effect/sql-sqlite-node/dist/SqliteMigrator.js
2220
2273
  const run = make({});
2221
2274
  const layer$1 = (options) => effectDiscard(run(options));
2222
2275
  //#endregion
@@ -2360,4 +2413,4 @@ const layer = (options) => effect(SemanticSearch, gen(function* () {
2360
2413
  //#endregion
2361
2414
  export { SemanticSearch, chunkEmbeddingInput, layer, makeEmbeddingResolver, maybeRemoveFile, maybeUpdateFile };
2362
2415
 
2363
- //# sourceMappingURL=SemanticSearch-BJGnYhFt.mjs.map
2416
+ //# sourceMappingURL=SemanticSearch-CFB73IPb.mjs.map