agenr 0.4.0 → 0.4.1

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-main.js CHANGED
@@ -880,6 +880,24 @@ import { createClient } from "@libsql/client";
880
880
  import os3 from "os";
881
881
  import path3 from "path";
882
882
 
883
+ // src/version.ts
884
+ import { createRequire } from "module";
885
+ var require2 = createRequire(import.meta.url);
886
+ var APP_VERSION = (() => {
887
+ try {
888
+ const raw = require2("../package.json");
889
+ if (typeof raw.version === "string" && raw.version.trim().length > 0) {
890
+ return raw.version.trim();
891
+ }
892
+ } catch {
893
+ }
894
+ const fromEnv = process.env.npm_package_version;
895
+ if (typeof fromEnv === "string" && fromEnv.trim().length > 0) {
896
+ return fromEnv.trim();
897
+ }
898
+ return "0.0.0";
899
+ })();
900
+
883
901
  // src/db/schema.ts
884
902
  var CREATE_IDX_ENTRIES_EMBEDDING_SQL = `
885
903
  CREATE INDEX IF NOT EXISTS idx_entries_embedding ON entries (
@@ -887,6 +905,13 @@ var CREATE_IDX_ENTRIES_EMBEDDING_SQL = `
887
905
  )
888
906
  `;
889
907
  var CREATE_TABLE_AND_TRIGGER_STATEMENTS = [
908
+ `
909
+ CREATE TABLE IF NOT EXISTS _meta (
910
+ key TEXT PRIMARY KEY,
911
+ value TEXT NOT NULL,
912
+ updated_at TEXT NOT NULL
913
+ )
914
+ `,
890
915
  `
891
916
  CREATE TABLE IF NOT EXISTS entries (
892
917
  id TEXT PRIMARY KEY,
@@ -1053,6 +1078,22 @@ async function initSchema(client) {
1053
1078
  for (const statement of CREATE_INDEX_STATEMENTS) {
1054
1079
  await client.execute(statement);
1055
1080
  }
1081
+ await client.execute({
1082
+ sql: `
1083
+ INSERT INTO _meta (key, value, updated_at)
1084
+ VALUES ('db_created_at', datetime('now'), datetime('now'))
1085
+ ON CONFLICT(key) DO NOTHING
1086
+ `,
1087
+ args: []
1088
+ });
1089
+ await client.execute({
1090
+ sql: `
1091
+ INSERT INTO _meta (key, value, updated_at)
1092
+ VALUES ('schema_version', ?, datetime('now'))
1093
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at
1094
+ `,
1095
+ args: [APP_VERSION]
1096
+ });
1056
1097
  }
1057
1098
 
1058
1099
  // src/db/client.ts
@@ -1235,6 +1276,29 @@ function resolveEffectiveDbPath(inputPath) {
1235
1276
  }
1236
1277
  return resolveDbFilePath(DEFAULT_DB_PATH);
1237
1278
  }
1279
+ async function hasMetaTable(db) {
1280
+ const result = await db.execute({
1281
+ sql: "SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = '_meta' LIMIT 1",
1282
+ args: []
1283
+ });
1284
+ return result.rows.length > 0;
1285
+ }
1286
+ async function readMetaRow(db, key) {
1287
+ const result = await db.execute({
1288
+ sql: "SELECT value, updated_at FROM _meta WHERE key = ? LIMIT 1",
1289
+ args: [key]
1290
+ });
1291
+ const row = result.rows[0];
1292
+ if (!row) {
1293
+ return null;
1294
+ }
1295
+ const value = toStringValue(row.value);
1296
+ const updatedAt = toStringValue(row.updated_at);
1297
+ if (!value && !updatedAt) {
1298
+ return null;
1299
+ }
1300
+ return { value, updatedAt };
1301
+ }
1238
1302
  async function getTagsByEntryId(db, ids) {
1239
1303
  if (ids.length === 0) {
1240
1304
  return /* @__PURE__ */ new Map();
@@ -1367,6 +1431,13 @@ async function runDbStatsCommand(options, deps) {
1367
1431
  const db = resolvedDeps.getDbFn(configured);
1368
1432
  try {
1369
1433
  await resolvedDeps.initDbFn(db);
1434
+ let schemaVersionLabel = "unknown (pre-0.4.0)";
1435
+ if (await hasMetaTable(db)) {
1436
+ const versionRow = await readMetaRow(db, "schema_version");
1437
+ if (versionRow?.value) {
1438
+ schemaVersionLabel = versionRow.value;
1439
+ }
1440
+ }
1370
1441
  const totalResult = await db.execute("SELECT COUNT(*) AS count FROM entries WHERE superseded_by IS NULL");
1371
1442
  const total = Number.isFinite(toNumber2(totalResult.rows[0]?.count)) ? toNumber2(totalResult.rows[0]?.count) : 0;
1372
1443
  const byTypeResult = await db.execute(`
@@ -1408,6 +1479,7 @@ async function runDbStatsCommand(options, deps) {
1408
1479
  clack.note(
1409
1480
  [
1410
1481
  formatLabel("Database", resolvedPath),
1482
+ formatLabel("Schema Version", schemaVersionLabel),
1411
1483
  formatLabel("Entries", String(total)),
1412
1484
  formatLabel("File Size", fileSizeBytes === null ? "n/a" : `${fileSizeBytes} bytes`),
1413
1485
  formatLabel("Oldest", oldest ?? "n/a"),
@@ -1435,6 +1507,48 @@ async function runDbStatsCommand(options, deps) {
1435
1507
  resolvedDeps.closeDbFn(db);
1436
1508
  }
1437
1509
  }
1510
+ async function runDbVersionCommand(options, deps) {
1511
+ const resolvedDeps = {
1512
+ readConfigFn: deps?.readConfigFn ?? readConfig,
1513
+ getDbFn: deps?.getDbFn ?? getDb,
1514
+ initDbFn: deps?.initDbFn ?? initDb,
1515
+ initSchemaFn: deps?.initSchemaFn ?? initSchema,
1516
+ closeDbFn: deps?.closeDbFn ?? closeDb
1517
+ };
1518
+ const config = resolvedDeps.readConfigFn(process.env);
1519
+ const configured = options.db?.trim() || config?.db?.path || DEFAULT_DB_PATH;
1520
+ const db = resolvedDeps.getDbFn(configured);
1521
+ try {
1522
+ const hasMeta = await hasMetaTable(db);
1523
+ if (!hasMeta) {
1524
+ const lines2 = [
1525
+ `agenr v${APP_VERSION}`,
1526
+ "Database schema version: unknown (pre-0.4.0)",
1527
+ "Database created: unknown",
1528
+ "Last migration: unknown"
1529
+ ];
1530
+ process.stdout.write(`${lines2.join("\n")}
1531
+ `);
1532
+ return { schemaVersion: null, dbCreatedAt: null, lastMigrationAt: null };
1533
+ }
1534
+ const schemaRow = await readMetaRow(db, "schema_version");
1535
+ const createdRow = await readMetaRow(db, "db_created_at");
1536
+ const schemaVersion = schemaRow?.value ?? null;
1537
+ const dbCreatedAt = createdRow?.value ?? null;
1538
+ const lastMigrationAt = schemaRow?.updatedAt ?? null;
1539
+ const lines = [
1540
+ `agenr v${APP_VERSION}`,
1541
+ `Database schema version: ${schemaVersion ?? "unknown (pre-0.4.0)"}`,
1542
+ `Database created: ${dbCreatedAt ?? "unknown"}`,
1543
+ `Last migration: ${lastMigrationAt ?? "unknown"}`
1544
+ ];
1545
+ process.stdout.write(`${lines.join("\n")}
1546
+ `);
1547
+ return { schemaVersion, dbCreatedAt, lastMigrationAt };
1548
+ } finally {
1549
+ resolvedDeps.closeDbFn(db);
1550
+ }
1551
+ }
1438
1552
  async function runDbExportCommand(options, deps) {
1439
1553
  const resolvedDeps = {
1440
1554
  readConfigFn: deps?.readConfigFn ?? readConfig,
@@ -10085,26 +10199,6 @@ import os12 from "os";
10085
10199
  import path19 from "path";
10086
10200
  import * as readline from "readline";
10087
10201
  import { once } from "events";
10088
-
10089
- // src/version.ts
10090
- import { createRequire } from "module";
10091
- var require2 = createRequire(import.meta.url);
10092
- var APP_VERSION = (() => {
10093
- try {
10094
- const raw = require2("../package.json");
10095
- if (typeof raw.version === "string" && raw.version.trim().length > 0) {
10096
- return raw.version.trim();
10097
- }
10098
- } catch {
10099
- }
10100
- const fromEnv = process.env.npm_package_version;
10101
- if (typeof fromEnv === "string" && fromEnv.trim().length > 0) {
10102
- return fromEnv.trim();
10103
- }
10104
- return "0.0.0";
10105
- })();
10106
-
10107
- // src/mcp/server.ts
10108
10202
  var MCP_PROTOCOL_VERSION = "2024-11-05";
10109
10203
  var JSON_RPC_PARSE_ERROR = -32700;
10110
10204
  var JSON_RPC_INVALID_REQUEST = -32600;
@@ -13284,6 +13378,10 @@ function createProgram() {
13284
13378
  await runDbStatsCommand({ db: opts.db });
13285
13379
  process.exitCode = 0;
13286
13380
  });
13381
+ dbCommand.command("version").description("Show database schema version information").option("--db <path>", "Database path override").action(async (opts) => {
13382
+ await runDbVersionCommand({ db: opts.db });
13383
+ process.exitCode = 0;
13384
+ });
13287
13385
  dbCommand.command("export").description("Export all non-superseded entries").option("--json", "Export JSON", false).option("--md", "Export markdown", false).option("--db <path>", "Database path override").action(async (opts) => {
13288
13386
  await runDbExportCommand({
13289
13387
  db: opts.db,
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  // src/cli.ts
4
4
  import { pathToFileURL } from "url";
5
+ import { realpathSync } from "fs";
5
6
  var originalEmit = process.emit;
6
7
  process.emit = function(event, ...args) {
7
8
  if (event === "warning" && typeof args[0] === "object" && args[0] !== null && args[0].name === "DeprecationWarning" && String(args[0].message).includes("punycode")) {
@@ -13,7 +14,8 @@ function stderrLine(message) {
13
14
  process.stderr.write(`${message}
14
15
  `);
15
16
  }
16
- var isDirectRun = process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
17
+ var resolvedArgv = process.argv[1] ? pathToFileURL(realpathSync(process.argv[1])).href : "";
18
+ var isDirectRun = process.argv[1] && (import.meta.url === resolvedArgv || import.meta.url === pathToFileURL(process.argv[1]).href);
17
19
  if (isDirectRun) {
18
20
  const { createProgram } = await import("./cli-main.js");
19
21
  createProgram().parseAsync(process.argv).catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agenr",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "AGENt memoRy -- Memory infrastructure for AI agents",
5
5
  "type": "module",
6
6
  "bin": {