claude-memory-layer 1.0.34 → 1.0.36

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
@@ -3580,6 +3580,16 @@ var SQLiteEventStore = class {
3580
3580
  getDatabase() {
3581
3581
  return this.db;
3582
3582
  }
3583
+ hasTableColumn(tableName, columnName) {
3584
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName))
3585
+ return false;
3586
+ try {
3587
+ const rows = sqliteAll(this.db, `PRAGMA table_info("${tableName}")`, []);
3588
+ return rows.some((row) => row.name === columnName);
3589
+ } catch {
3590
+ return false;
3591
+ }
3592
+ }
3583
3593
  async recordRetrievalTrace(input) {
3584
3594
  await this.initialize();
3585
3595
  const traceId = randomUUID5();
@@ -3645,17 +3655,18 @@ var SQLiteEventStore = class {
3645
3655
  async getRetrievalTraceStats() {
3646
3656
  await this.initialize();
3647
3657
  try {
3658
+ const rewrittenQueryRewriteKindSql = this.hasTableColumn("retrieval_traces", "query_rewrite_kind") ? REWRITTEN_QUERY_REWRITE_KIND_SQL : "0";
3648
3659
  const row = sqliteGet(
3649
3660
  this.db,
3650
3661
  `SELECT
3651
3662
  COUNT(*) as total_queries,
3652
3663
  AVG(candidate_count) as avg_candidate_count,
3653
3664
  AVG(selected_count) as avg_selected_count,
3654
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN 1 ELSE 0 END) as rewritten_queries,
3655
- SUM(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3656
- SUM(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3657
- AVG(CASE WHEN ${REWRITTEN_QUERY_REWRITE_KIND_SQL} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3658
- AVG(CASE WHEN NOT (${REWRITTEN_QUERY_REWRITE_KIND_SQL}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3665
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN 1 ELSE 0 END) as rewritten_queries,
3666
+ SUM(CASE WHEN ${rewrittenQueryRewriteKindSql} AND selected_count > 0 THEN 1 ELSE 0 END) as rewritten_queries_with_selection,
3667
+ SUM(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) AND selected_count > 0 THEN 1 ELSE 0 END) as raw_queries_with_selection,
3668
+ AVG(CASE WHEN ${rewrittenQueryRewriteKindSql} THEN selected_count END) as avg_selected_count_for_rewritten_queries,
3669
+ AVG(CASE WHEN NOT (${rewrittenQueryRewriteKindSql}) THEN selected_count END) as avg_selected_count_for_raw_queries,
3659
3670
  CASE
3660
3671
  WHEN SUM(candidate_count) > 0 THEN (SUM(selected_count) * 1.0 / SUM(candidate_count))
3661
3672
  ELSE 0
@@ -10360,7 +10371,7 @@ var sessionsRouter = new Hono();
10360
10371
  sessionsRouter.get("/", async (c) => {
10361
10372
  const page = parseInt(c.req.query("page") || "1", 10);
10362
10373
  const pageSize = parseInt(c.req.query("pageSize") || "20", 10);
10363
- const memoryService = getServiceFromQuery(c);
10374
+ const memoryService = getLightweightServiceFromQuery(c);
10364
10375
  try {
10365
10376
  await memoryService.initialize();
10366
10377
  const recentEvents = await memoryService.getRecentEvents(1e3);
@@ -10404,7 +10415,7 @@ sessionsRouter.get("/", async (c) => {
10404
10415
  });
10405
10416
  sessionsRouter.get("/:id", async (c) => {
10406
10417
  const { id } = c.req.param();
10407
- const memoryService = getServiceFromQuery(c);
10418
+ const memoryService = getLightweightServiceFromQuery(c);
10408
10419
  try {
10409
10420
  await memoryService.initialize();
10410
10421
  const events = await memoryService.getSessionHistory(id);
@@ -10450,7 +10461,7 @@ eventsRouter.get("/", async (c) => {
10450
10461
  const q = (c.req.query("q") || "").trim().toLowerCase();
10451
10462
  const limit = parseInt(c.req.query("limit") || "100", 10);
10452
10463
  const offset = parseInt(c.req.query("offset") || "0", 10);
10453
- const memoryService = getServiceFromQuery(c);
10464
+ const memoryService = getLightweightServiceFromQuery(c);
10454
10465
  try {
10455
10466
  await memoryService.initialize();
10456
10467
  let events;
@@ -10506,7 +10517,7 @@ eventsRouter.get("/", async (c) => {
10506
10517
  });
10507
10518
  eventsRouter.get("/:id", async (c) => {
10508
10519
  const { id } = c.req.param();
10509
- const memoryService = getServiceFromQuery(c);
10520
+ const memoryService = getLightweightServiceFromQuery(c);
10510
10521
  try {
10511
10522
  await memoryService.initialize();
10512
10523
  const recentEvents = await memoryService.getRecentEvents(1e4);
@@ -10545,6 +10556,10 @@ eventsRouter.get("/:id", async (c) => {
10545
10556
  // src/apps/server/api/search.ts
10546
10557
  import { Hono as Hono3 } from "hono";
10547
10558
  var searchRouter = new Hono3();
10559
+ function isEmbeddingBackendUnavailable(error) {
10560
+ const message = error instanceof Error ? error.message : String(error);
10561
+ return /model file path or buffer|onnxruntime|transformers|embedding backend/i.test(message);
10562
+ }
10548
10563
  searchRouter.post("/", async (c) => {
10549
10564
  const memoryService = getServiceFromQuery(c);
10550
10565
  try {
@@ -10586,15 +10601,41 @@ searchRouter.post("/", async (c) => {
10586
10601
  });
10587
10602
  searchRouter.post("/disclosure", async (c) => {
10588
10603
  let memoryService;
10604
+ let body;
10589
10605
  try {
10590
- const body = await c.req.json();
10606
+ body = await c.req.json();
10591
10607
  if (!body.query) {
10592
10608
  return c.json({ error: "Query is required" }, 400);
10593
10609
  }
10594
- memoryService = body.options?.strategy === "fast" ? getLightweightServiceFromQuery(c) : getServiceFromQuery(c);
10595
- await memoryService.initialize();
10596
- const result = await memoryService.searchDisclosure(body.query, body.options);
10597
- return c.json(result);
10610
+ const useFastStrategy = body.options?.strategy === "fast";
10611
+ memoryService = useFastStrategy ? getLightweightServiceFromQuery(c) : getServiceFromQuery(c);
10612
+ try {
10613
+ await memoryService.initialize();
10614
+ const result = await memoryService.searchDisclosure(body.query, body.options);
10615
+ return c.json(result);
10616
+ } catch (error) {
10617
+ if (!useFastStrategy && isEmbeddingBackendUnavailable(error)) {
10618
+ await memoryService.shutdown();
10619
+ memoryService = getLightweightServiceFromQuery(c);
10620
+ await memoryService.initialize();
10621
+ const result = await memoryService.searchDisclosure(body.query, {
10622
+ ...body.options,
10623
+ strategy: "fast"
10624
+ });
10625
+ return c.json({
10626
+ ...result,
10627
+ meta: {
10628
+ ...result.meta,
10629
+ fallbackApplied: true,
10630
+ fallbackTrace: [
10631
+ ...result.meta.fallbackTrace || [],
10632
+ "fallback:embedding-backend-unavailable:fast"
10633
+ ]
10634
+ }
10635
+ });
10636
+ }
10637
+ throw error;
10638
+ }
10598
10639
  } catch (error) {
10599
10640
  return c.json({ error: error.message }, 500);
10600
10641
  } finally {
@@ -10602,7 +10643,7 @@ searchRouter.post("/disclosure", async (c) => {
10602
10643
  }
10603
10644
  });
10604
10645
  searchRouter.get("/disclosure/:resultId/expand", async (c) => {
10605
- const memoryService = getServiceFromQuery(c);
10646
+ const memoryService = getLightweightServiceFromQuery(c);
10606
10647
  try {
10607
10648
  const resultId = c.req.param("resultId");
10608
10649
  const rawWindowSize = c.req.query("windowSize");
@@ -10622,7 +10663,7 @@ searchRouter.get("/disclosure/:resultId/expand", async (c) => {
10622
10663
  }
10623
10664
  });
10624
10665
  searchRouter.get("/disclosure/:resultId/source", async (c) => {
10625
- const memoryService = getServiceFromQuery(c);
10666
+ const memoryService = getLightweightServiceFromQuery(c);
10626
10667
  try {
10627
10668
  const resultId = c.req.param("resultId");
10628
10669
  const result = await memoryService.sourceDisclosure(resultId);
@@ -13971,7 +14012,7 @@ async function runMarketContextCommand(options) {
13971
14012
  }
13972
14013
  }
13973
14014
  var program = new Command();
13974
- program.name("claude-memory-layer").description("Claude Code Memory Plugin CLI").version("1.0.34");
14015
+ program.name("claude-memory-layer").description("Claude Code Memory Plugin CLI").version("1.0.36");
13975
14016
  program.command("market-context").description("Fetch read-only DART/FRED/Finnhub context with structured MarketContextSnapshot bull/bear/risk/catalyst analysis").option("--company <name>", "Company name for DART fallback search and report subject").option("--dart-corp-code <code>", "Exact DART corp_code for issuer-specific filings").option("--symbol <ticker>", "Listed ticker for Finnhub company profile").option("--providers <list>", "Comma-separated providers: dart,fred,finnhub").option("--fred-series <list>", "Comma-separated FRED series IDs").option("--json", "Print structured JSON including analysis.marketSnapshot").option("--no-snapshot", "Disable MarketContextSnapshot and DART company snapshot analysis").action(async (options) => {
13976
14017
  try {
13977
14018
  await runMarketContextCommand(options);