@hasna/mementos 0.14.11 → 0.14.13

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/index.js CHANGED
@@ -9398,154 +9398,9 @@ See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode de
9398
9398
  init_adapter();
9399
9399
  });
9400
9400
 
9401
- // src/db/database.ts
9402
- var exports_database = {};
9403
- __export(exports_database, {
9404
- uuid: () => uuid,
9405
- shortUuid: () => shortUuid,
9406
- resolvePartialId: () => resolvePartialId,
9407
- resetDatabase: () => resetDatabase,
9408
- now: () => now,
9409
- getDbPath: () => getDbPath2,
9410
- getDatabase: () => getDatabase,
9411
- closeDatabase: () => closeDatabase
9412
- });
9413
- import { existsSync as existsSync4, mkdirSync as mkdirSync3, cpSync } from "fs";
9414
- import { dirname as dirname2, join as join5, resolve } from "path";
9415
- function isInMemoryDb(path) {
9416
- return path === ":memory:" || path.startsWith("file::memory:");
9417
- }
9418
- function findNearestMementosDb(startDir) {
9419
- let dir = resolve(startDir);
9420
- while (true) {
9421
- const candidate = join5(dir, ".mementos", "mementos.db");
9422
- if (existsSync4(candidate))
9423
- return candidate;
9424
- const parent = dirname2(dir);
9425
- if (parent === dir)
9426
- break;
9427
- dir = parent;
9428
- }
9429
- return null;
9430
- }
9431
- function findGitRoot(startDir) {
9432
- let dir = resolve(startDir);
9433
- while (true) {
9434
- if (existsSync4(join5(dir, ".git")))
9435
- return dir;
9436
- const parent = dirname2(dir);
9437
- if (parent === dir)
9438
- break;
9439
- dir = parent;
9440
- }
9441
- return null;
9442
- }
9443
- function migrateGlobalDir() {
9444
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
9445
- const newDir = join5(home, ".hasna", "mementos");
9446
- const oldDir = join5(home, ".mementos");
9447
- if (!existsSync4(newDir) && existsSync4(oldDir)) {
9448
- mkdirSync3(join5(home, ".hasna"), { recursive: true });
9449
- cpSync(oldDir, newDir, { recursive: true });
9450
- }
9451
- }
9452
- function getDbPath2() {
9453
- const envPath = process.env["HASNA_MEMENTOS_DB_PATH"] ?? process.env["MEMENTOS_DB_PATH"];
9454
- if (envPath) {
9455
- return envPath;
9456
- }
9457
- const cwd = process.cwd();
9458
- const nearest = findNearestMementosDb(cwd);
9459
- if (nearest)
9460
- return nearest;
9461
- if (process.env["MEMENTOS_DB_SCOPE"] === "project") {
9462
- const gitRoot = findGitRoot(cwd);
9463
- if (gitRoot) {
9464
- return join5(gitRoot, ".mementos", "mementos.db");
9465
- }
9466
- }
9467
- migrateGlobalDir();
9468
- const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
9469
- return join5(home, ".hasna", "mementos", "mementos.db");
9470
- }
9471
- function ensureDir(filePath) {
9472
- if (isInMemoryDb(filePath))
9473
- return;
9474
- const dir = dirname2(resolve(filePath));
9475
- if (!existsSync4(dir)) {
9476
- mkdirSync3(dir, { recursive: true });
9477
- }
9478
- }
9479
- function getDatabase(dbPath) {
9480
- if (_db)
9481
- return _db;
9482
- const path = dbPath || getDbPath2();
9483
- ensureDir(path);
9484
- _db = new SqliteAdapter(path, { create: true });
9485
- _db.run("PRAGMA journal_mode = WAL");
9486
- _db.run("PRAGMA busy_timeout = 5000");
9487
- _db.run("PRAGMA foreign_keys = ON");
9488
- runMigrations(_db);
9489
- _db.run(`CREATE TABLE IF NOT EXISTS feedback (
9490
- id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
9491
- message TEXT NOT NULL,
9492
- email TEXT,
9493
- category TEXT DEFAULT 'general',
9494
- version TEXT,
9495
- machine_id TEXT,
9496
- created_at TEXT NOT NULL DEFAULT (datetime('now'))
9497
- )`);
9498
- return _db;
9499
- }
9500
- function runMigrations(db) {
9501
- try {
9502
- const result = db.query("SELECT MAX(id) as max_id FROM _migrations").get();
9503
- const currentLevel = result?.max_id ?? 0;
9504
- for (let i = currentLevel;i < MIGRATIONS.length; i++) {
9505
- try {
9506
- db.exec(MIGRATIONS[i]);
9507
- } catch {}
9508
- }
9509
- } catch {
9510
- for (const migration of MIGRATIONS) {
9511
- try {
9512
- db.exec(migration);
9513
- } catch {}
9514
- }
9515
- }
9516
- }
9517
- function closeDatabase() {
9518
- if (_db) {
9519
- _db.close();
9520
- _db = null;
9521
- }
9522
- }
9523
- function resetDatabase() {
9524
- _db = null;
9525
- }
9526
- function now() {
9527
- return new Date().toISOString();
9528
- }
9529
- function uuid() {
9530
- return crypto.randomUUID();
9531
- }
9532
- function shortUuid() {
9533
- return crypto.randomUUID().slice(0, 8);
9534
- }
9535
- function resolvePartialId(db, table, partialId) {
9536
- if (partialId.length >= 36) {
9537
- const row = db.query(`SELECT id FROM ${table} WHERE id = ?`).get(partialId);
9538
- return row?.id ?? null;
9539
- }
9540
- const rows = db.query(`SELECT id FROM ${table} WHERE id LIKE ?`).all(`${partialId}%`);
9541
- if (rows.length === 1) {
9542
- return rows[0].id;
9543
- }
9544
- return null;
9545
- }
9546
- var MIGRATIONS, _db = null;
9547
- var init_database = __esm(() => {
9548
- init_dist();
9401
+ // src/db/migrations.ts
9402
+ var MIGRATIONS;
9403
+ var init_migrations = __esm(() => {
9549
9404
  MIGRATIONS = [
9550
9405
  `
9551
9406
  CREATE TABLE IF NOT EXISTS projects (
@@ -10291,6 +10146,157 @@ INSERT OR IGNORE INTO _migrations (id) VALUES (32);
10291
10146
  ];
10292
10147
  });
10293
10148
 
10149
+ // src/db/database.ts
10150
+ var exports_database = {};
10151
+ __export(exports_database, {
10152
+ uuid: () => uuid,
10153
+ shortUuid: () => shortUuid,
10154
+ resolvePartialId: () => resolvePartialId,
10155
+ resetDatabase: () => resetDatabase,
10156
+ now: () => now,
10157
+ getDbPath: () => getDbPath2,
10158
+ getDatabase: () => getDatabase,
10159
+ closeDatabase: () => closeDatabase
10160
+ });
10161
+ import { existsSync as existsSync4, mkdirSync as mkdirSync3, cpSync } from "fs";
10162
+ import { dirname as dirname2, join as join5, resolve } from "path";
10163
+ function isInMemoryDb(path) {
10164
+ return path === ":memory:" || path.startsWith("file::memory:");
10165
+ }
10166
+ function findNearestMementosDb(startDir) {
10167
+ let dir = resolve(startDir);
10168
+ while (true) {
10169
+ const candidate = join5(dir, ".mementos", "mementos.db");
10170
+ if (existsSync4(candidate))
10171
+ return candidate;
10172
+ const parent = dirname2(dir);
10173
+ if (parent === dir)
10174
+ break;
10175
+ dir = parent;
10176
+ }
10177
+ return null;
10178
+ }
10179
+ function findGitRoot(startDir) {
10180
+ let dir = resolve(startDir);
10181
+ while (true) {
10182
+ if (existsSync4(join5(dir, ".git")))
10183
+ return dir;
10184
+ const parent = dirname2(dir);
10185
+ if (parent === dir)
10186
+ break;
10187
+ dir = parent;
10188
+ }
10189
+ return null;
10190
+ }
10191
+ function migrateGlobalDir() {
10192
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
10193
+ const newDir = join5(home, ".hasna", "mementos");
10194
+ const oldDir = join5(home, ".mementos");
10195
+ if (!existsSync4(newDir) && existsSync4(oldDir)) {
10196
+ mkdirSync3(join5(home, ".hasna"), { recursive: true });
10197
+ cpSync(oldDir, newDir, { recursive: true });
10198
+ }
10199
+ }
10200
+ function getDbPath2() {
10201
+ const envPath = process.env["HASNA_MEMENTOS_DB_PATH"] ?? process.env["MEMENTOS_DB_PATH"];
10202
+ if (envPath) {
10203
+ return envPath;
10204
+ }
10205
+ const cwd = process.cwd();
10206
+ const nearest = findNearestMementosDb(cwd);
10207
+ if (nearest)
10208
+ return nearest;
10209
+ if (process.env["MEMENTOS_DB_SCOPE"] === "project") {
10210
+ const gitRoot = findGitRoot(cwd);
10211
+ if (gitRoot) {
10212
+ return join5(gitRoot, ".mementos", "mementos.db");
10213
+ }
10214
+ }
10215
+ migrateGlobalDir();
10216
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
10217
+ return join5(home, ".hasna", "mementos", "mementos.db");
10218
+ }
10219
+ function ensureDir(filePath) {
10220
+ if (isInMemoryDb(filePath))
10221
+ return;
10222
+ const dir = dirname2(resolve(filePath));
10223
+ if (!existsSync4(dir)) {
10224
+ mkdirSync3(dir, { recursive: true });
10225
+ }
10226
+ }
10227
+ function getDatabase(dbPath) {
10228
+ if (_db)
10229
+ return _db;
10230
+ const path = dbPath || getDbPath2();
10231
+ ensureDir(path);
10232
+ _db = new SqliteAdapter(path, { create: true });
10233
+ _db.run("PRAGMA journal_mode = WAL");
10234
+ _db.run("PRAGMA busy_timeout = 5000");
10235
+ _db.run("PRAGMA foreign_keys = ON");
10236
+ runMigrations(_db);
10237
+ _db.run(`CREATE TABLE IF NOT EXISTS feedback (
10238
+ id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
10239
+ message TEXT NOT NULL,
10240
+ email TEXT,
10241
+ category TEXT DEFAULT 'general',
10242
+ version TEXT,
10243
+ machine_id TEXT,
10244
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
10245
+ )`);
10246
+ return _db;
10247
+ }
10248
+ function runMigrations(db) {
10249
+ try {
10250
+ const result = db.query("SELECT MAX(id) as max_id FROM _migrations").get();
10251
+ const currentLevel = result?.max_id ?? 0;
10252
+ for (let i = currentLevel;i < MIGRATIONS.length; i++) {
10253
+ try {
10254
+ db.exec(MIGRATIONS[i]);
10255
+ } catch {}
10256
+ }
10257
+ } catch {
10258
+ for (const migration of MIGRATIONS) {
10259
+ try {
10260
+ db.exec(migration);
10261
+ } catch {}
10262
+ }
10263
+ }
10264
+ }
10265
+ function closeDatabase() {
10266
+ if (_db) {
10267
+ _db.close();
10268
+ _db = null;
10269
+ }
10270
+ }
10271
+ function resetDatabase() {
10272
+ _db = null;
10273
+ }
10274
+ function now() {
10275
+ return new Date().toISOString();
10276
+ }
10277
+ function uuid() {
10278
+ return crypto.randomUUID();
10279
+ }
10280
+ function shortUuid() {
10281
+ return crypto.randomUUID().slice(0, 8);
10282
+ }
10283
+ function resolvePartialId(db, table, partialId) {
10284
+ if (partialId.length >= 36) {
10285
+ const row = db.query(`SELECT id FROM ${table} WHERE id = ?`).get(partialId);
10286
+ return row?.id ?? null;
10287
+ }
10288
+ const rows = db.query(`SELECT id FROM ${table} WHERE id LIKE ?`).all(`${partialId}%`);
10289
+ if (rows.length === 1) {
10290
+ return rows[0].id;
10291
+ }
10292
+ return null;
10293
+ }
10294
+ var _db = null;
10295
+ var init_database = __esm(() => {
10296
+ init_dist();
10297
+ init_migrations();
10298
+ });
10299
+
10294
10300
  // src/types/index.ts
10295
10301
  class AgentConflictError extends Error {
10296
10302
  conflict = true;