opencode-swarm 7.121.3 → 7.121.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  getPluginLockFilePaths,
8
8
  package_default,
9
9
  resolveCommand
10
- } from "./index-fs2q8jyf.js";
10
+ } from "./index-q0fv0xec.js";
11
11
  import"./index-kyvg2cmp.js";
12
12
  import"./index-vqcgmy4y.js";
13
13
  import"./index-emkb0bbe.js";
@@ -7,7 +7,11 @@
7
7
  * normalized directory path.
8
8
  * - `qa-gate-profile`: service layer for per-plan QA gate profiles stored
9
9
  * in the project DB.
10
+ * - `sqlite-loader`: runtime-portable SQLite `Database` constructor resolver
11
+ * (native `bun:sqlite` under Bun, a `node:sqlite` adapter under Node — issue
12
+ * #1873). Used by `global-db`, `project-db`, and the memory SQLite provider.
10
13
  */
11
14
  export { closeGlobalDb, getGlobalDb, runGlobalMigrations, } from './global-db.js';
12
15
  export { closeAllProjectDbs, closeProjectDb, getProjectDb, projectDbExists, projectDbPath, runProjectMigrations, } from './project-db.js';
13
16
  export { computeProfileHash, DEFAULT_QA_GATES, getEffectiveGates, getOrCreateProfile, getProfile, lockProfile, type QaGateProfile, type QaGates, setGates, } from './qa-gate-profile.js';
17
+ export { loadDatabaseCtor } from './sqlite-loader.js';
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Runtime-portable SQLite driver loader for opencode-swarm.
3
+ *
4
+ * Why this exists (issue #1873): the published plugin bundle (`dist/index.js`) is
5
+ * built `--target node` and OpenCode Desktop loads it inside a **Node.js** Electron
6
+ * `utilityProcess` sidecar. The previous DB layer resolved the driver with a lazy
7
+ * `createRequire(import.meta.url)('bun:sqlite')` and **no fallback**. `bun:sqlite` is
8
+ * a Bun-only built-in, so under Node every SQLite-backed tool threw
9
+ * `Error: Cannot find module 'bun:sqlite'` (`swarm_memory_recall`, the QA-gate tools,
10
+ * `get_approved_plan`, …).
11
+ *
12
+ * The lazy require kept `bun:sqlite` out of the bundle's top-level ESM imports (which
13
+ * is what invariant #2 / issue #675 requires — a static `import … from 'bun:…'` breaks
14
+ * Node's ESM resolver with `ERR_UNSUPPORTED_ESM_URL_SCHEME`), but it still assumed a
15
+ * Bun runtime at call time.
16
+ *
17
+ * This module is the single, sanctioned place that resolves a `bun:sqlite`-shaped
18
+ * `Database` constructor:
19
+ * 1. Under Bun: return the native `bun:sqlite` `Database` (behaviour unchanged).
20
+ * 2. Under Node: wrap `node:sqlite`'s `DatabaseSync` (flag-free in Node 22.13+; added
21
+ * behind `--experimental-sqlite` in 22.5; shipped by Electron 42+) in a small
22
+ * adapter that presents the exact `Database` subset the
23
+ * codebase uses — `run(sql, params?)`, `query(sql).{get,all,iterate}`,
24
+ * `transaction(fn)`, `inTransaction`, `loadExtension(path)`, `close()`. A bare
25
+ * constructor swap is NOT enough: `DatabaseSync` has none of
26
+ * `run/query/transaction/inTransaction`.
27
+ * 3. If neither driver is available: throw one clear, combined diagnostic.
28
+ *
29
+ * Portability contract (invariant #2): all three former call sites
30
+ * (`project-db.ts`, `global-db.ts`, `memory/sqlite-provider.ts`) now import
31
+ * `loadDatabaseCtor` from here. No new lazy `require('bun:…')` may be added elsewhere —
32
+ * `tests/unit/build/bundle-portability.test.ts` enforces this statically, and
33
+ * `scripts/repro-1873.mjs` exercises the real Node driver end-to-end in CI.
34
+ */
35
+ import type { Database } from 'bun:sqlite';
36
+ interface NodeStatementSync {
37
+ get(...params: unknown[]): unknown;
38
+ all(...params: unknown[]): unknown[];
39
+ iterate(...params: unknown[]): IterableIterator<unknown>;
40
+ run(...params: unknown[]): {
41
+ changes: number | bigint;
42
+ lastInsertRowid: number | bigint;
43
+ };
44
+ }
45
+ interface NodeDatabaseSync {
46
+ exec(sql: string): void;
47
+ prepare(sql: string): NodeStatementSync;
48
+ readonly isTransaction: boolean;
49
+ enableLoadExtension(enable: boolean): void;
50
+ loadExtension(path: string): void;
51
+ close(): void;
52
+ }
53
+ type NodeDatabaseSyncCtor = new (filename: string, options?: {
54
+ allowExtension?: boolean;
55
+ }) => NodeDatabaseSync;
56
+ /**
57
+ * Build a `bun:sqlite`-`Database`-compatible constructor backed by `node:sqlite`'s
58
+ * `DatabaseSync`. Exported for direct unit testing under Bun (which lacks
59
+ * `node:sqlite`) via an injected fake `DatabaseSync`.
60
+ */
61
+ export declare function createNodeDatabaseCtor(DatabaseSyncCtor: NodeDatabaseSyncCtor): typeof Database;
62
+ /**
63
+ * Internal seam for tests: `requireModule` is dependency-injected so a Bun test can
64
+ * force the Node fallback path with a fake `node:sqlite`, and `reset()` clears the
65
+ * module-level cache between cases. Not part of the public API.
66
+ */
67
+ export declare const _internals: {
68
+ requireModule(id: string): unknown;
69
+ reset(): void;
70
+ };
71
+ /**
72
+ * Resolve a `bun:sqlite`-`Database`-compatible constructor for the current runtime.
73
+ * Cached after first resolution.
74
+ *
75
+ * Order: native `bun:sqlite` (Bun) → `node:sqlite` adapter (Node) → clear error.
76
+ */
77
+ export declare function loadDatabaseCtor(): typeof Database;
78
+ export {};