@cerefox/memory 0.9.5 → 0.9.7

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.
@@ -7184,7 +7184,7 @@ var exports_meta = {};
7184
7184
  __export(exports_meta, {
7185
7185
  PKG_VERSION: () => PKG_VERSION
7186
7186
  });
7187
- var PKG_VERSION = "0.9.5";
7187
+ var PKG_VERSION = "0.9.7";
7188
7188
  var init_meta = () => {};
7189
7189
 
7190
7190
  // ../../node_modules/.bun/tslib@2.8.1/node_modules/tslib/tslib.js
@@ -78063,9 +78063,9 @@ var serveStatic = (options = { root: "" }) => {
78063
78063
  };
78064
78064
 
78065
78065
  // src/web/server.ts
78066
- import { existsSync as existsSync15 } from "node:fs";
78067
- import { readFileSync as readFileSync14 } from "node:fs";
78068
- import { join as join15 } from "node:path";
78066
+ import { existsSync as existsSync16 } from "node:fs";
78067
+ import { readFileSync as readFileSync15 } from "node:fs";
78068
+ import { join as join16 } from "node:path";
78069
78069
 
78070
78070
  // ../../node_modules/.bun/hono@4.12.23/node_modules/hono/dist/compose.js
78071
78071
  var compose = (middleware, onError, onNotFound) => {
@@ -79965,6 +79965,30 @@ async function countActiveDocuments(ctx) {
79965
79965
  throw error3;
79966
79966
  return count ?? 0;
79967
79967
  }
79968
+ async function getCorpusTotals(ctx) {
79969
+ const { data, error: error3 } = await ctx.supabase.rpc("cerefox_corpus_totals");
79970
+ if (error3)
79971
+ return { total_chunks: 0, total_chars: 0 };
79972
+ const row = Array.isArray(data) ? data[0] : data;
79973
+ return {
79974
+ total_chunks: Number(row?.total_chunks ?? 0),
79975
+ total_chars: Number(row?.total_chars ?? 0)
79976
+ };
79977
+ }
79978
+ async function getRecentDocAuthors(ctx, docIds) {
79979
+ if (docIds.length === 0)
79980
+ return {};
79981
+ const { data, error: error3 } = await ctx.supabase.rpc("cerefox_recent_doc_authors", {
79982
+ p_doc_ids: docIds
79983
+ });
79984
+ if (error3)
79985
+ return {};
79986
+ const out = {};
79987
+ for (const r of data ?? []) {
79988
+ out[String(r.document_id)] = { author: r.author, author_type: r.author_type };
79989
+ }
79990
+ return out;
79991
+ }
79968
79992
  async function countDocumentsForProject(ctx, projectId) {
79969
79993
  const { data, error: error3 } = await ctx.supabase.from("cerefox_document_projects").select("document_id, cerefox_documents(deleted_at)").eq("project_id", projectId);
79970
79994
  if (error3)
@@ -80232,21 +80256,28 @@ function registerDiscoveryRoutes(app, ctx) {
80232
80256
  })));
80233
80257
  });
80234
80258
  app.get("/api/v1/dashboard", async (c2) => {
80235
- const [recentDocs, projects, docCount] = await Promise.all([
80259
+ const [recentDocs, projects, docCount, totals] = await Promise.all([
80236
80260
  listDocuments(ctx, { limit: 10 }),
80237
80261
  listAllProjects(ctx),
80238
- countActiveDocuments(ctx)
80262
+ countActiveDocuments(ctx),
80263
+ getCorpusTotals(ctx)
80239
80264
  ]);
80240
80265
  const projectIds = projects.map((p) => String(p.id));
80241
80266
  const docIds = recentDocs.map((d) => String(d.id));
80242
- const [docProjectsMap, counts] = await Promise.all([
80267
+ const [docProjectsMap, counts, authors] = await Promise.all([
80243
80268
  getProjectsForDocuments(ctx, docIds, projects),
80244
- getProjectDocCounts(ctx, projectIds)
80269
+ getProjectDocCounts(ctx, projectIds),
80270
+ getRecentDocAuthors(ctx, docIds)
80245
80271
  ]);
80246
80272
  const recent = recentDocs.map((d) => {
80247
80273
  const id = String(d.id);
80248
80274
  const pids = (docProjectsMap[id] ?? []).map((p) => String(p.id));
80249
- return dashboardDocFromRow(d, pids);
80275
+ const a = authors[id];
80276
+ return {
80277
+ ...dashboardDocFromRow(d, pids),
80278
+ author: a?.author ?? null,
80279
+ author_type: a?.author_type ?? null
80280
+ };
80250
80281
  });
80251
80282
  const projectsOut = projects.map((p) => ({
80252
80283
  id: p.id,
@@ -80257,6 +80288,8 @@ function registerDiscoveryRoutes(app, ctx) {
80257
80288
  }));
80258
80289
  return c2.json({
80259
80290
  doc_count: docCount,
80291
+ total_chunks: totals.total_chunks,
80292
+ total_chars: totals.total_chars,
80260
80293
  project_count: projects.length,
80261
80294
  recent_docs: recent,
80262
80295
  projects: projectsOut,
@@ -81012,19 +81045,22 @@ function listBundledDocs2() {
81012
81045
  return entries;
81013
81046
  }
81014
81047
  function readDoc(docPath) {
81015
- const { pkgTopLevel, repoTopLevel } = resolveDocsRoots();
81016
- const roots = [pkgTopLevel, repoTopLevel].filter((r) => r !== null);
81017
- for (const root of roots) {
81018
- const candidate = resolve5(root, docPath);
81019
- if (!candidate.startsWith(resolve5(root) + "/") && candidate !== resolve5(root)) {
81020
- continue;
81021
- }
81022
- if (existsSync13(candidate) && statSync6(candidate).isFile()) {
81023
- try {
81024
- return readFileSync13(candidate, "utf8");
81025
- } catch {
81026
- return null;
81027
- }
81048
+ const { pkgGuides, pkgTopLevel, repoGuides, repoTopLevel } = resolveDocsRoots();
81049
+ const isGuide = docPath.startsWith("guides/");
81050
+ const root = isGuide ? pkgGuides ?? repoGuides : pkgTopLevel ?? repoTopLevel;
81051
+ if (!root)
81052
+ return null;
81053
+ const rel = isGuide ? docPath.slice("guides/".length) : docPath;
81054
+ const rootResolved = resolve5(root);
81055
+ const candidate = resolve5(rootResolved, rel);
81056
+ if (!candidate.startsWith(rootResolved + "/") && candidate !== rootResolved) {
81057
+ return null;
81058
+ }
81059
+ if (existsSync13(candidate) && statSync6(candidate).isFile()) {
81060
+ try {
81061
+ return readFileSync13(candidate, "utf8");
81062
+ } catch {
81063
+ return null;
81028
81064
  }
81029
81065
  }
81030
81066
  return null;
@@ -81126,6 +81162,45 @@ function registerMetaRoutes(app, ctx) {
81126
81162
  });
81127
81163
  }
81128
81164
 
81165
+ // src/web/routes/preferences.ts
81166
+ init_config();
81167
+ import { existsSync as existsSync14, mkdirSync as mkdirSync4, readFileSync as readFileSync14, writeFileSync as writeFileSync5 } from "node:fs";
81168
+ import { join as join14 } from "node:path";
81169
+ function isTheme(v) {
81170
+ return v === "auto" || v === "light" || v === "dark";
81171
+ }
81172
+ function prefsFile() {
81173
+ return join14(userStateDir(), "web-prefs.json");
81174
+ }
81175
+ function readPrefs() {
81176
+ try {
81177
+ const raw2 = JSON.parse(readFileSync14(prefsFile(), "utf8"));
81178
+ if (isTheme(raw2.theme))
81179
+ return { theme: raw2.theme };
81180
+ } catch {}
81181
+ return { theme: "auto" };
81182
+ }
81183
+ function registerPreferencesRoutes(app) {
81184
+ app.get("/api/v1/preferences", (c2) => c2.json(readPrefs()));
81185
+ app.put("/api/v1/preferences", async (c2) => {
81186
+ const body = await c2.req.json().catch(() => ({}));
81187
+ if (!isTheme(body.theme)) {
81188
+ return c2.json({ detail: "theme must be one of: auto, light, dark" }, 400);
81189
+ }
81190
+ const next = { ...readPrefs(), theme: body.theme };
81191
+ try {
81192
+ const dir = userStateDir();
81193
+ if (!existsSync14(dir))
81194
+ mkdirSync4(dir, { recursive: true });
81195
+ writeFileSync5(prefsFile(), `${JSON.stringify(next, null, 2)}
81196
+ `);
81197
+ } catch (err) {
81198
+ return c2.json({ detail: err instanceof Error ? err.message : String(err) }, 500);
81199
+ }
81200
+ return c2.json(next);
81201
+ });
81202
+ }
81203
+
81129
81204
  // src/web/routes/projects.ts
81130
81205
  function projectRowToResponse(row) {
81131
81206
  return {
@@ -81187,21 +81262,21 @@ function registerProjectsRoutes(app, ctx) {
81187
81262
  }
81188
81263
 
81189
81264
  // src/web/static.ts
81190
- import { existsSync as existsSync14, statSync as statSync7 } from "node:fs";
81191
- import { dirname as dirname6, join as join14 } from "node:path";
81265
+ import { existsSync as existsSync15, statSync as statSync7 } from "node:fs";
81266
+ import { dirname as dirname6, join as join15 } from "node:path";
81192
81267
  import { fileURLToPath as fileURLToPath4 } from "node:url";
81193
81268
  function moduleDir3() {
81194
81269
  return dirname6(fileURLToPath4(import.meta.url));
81195
81270
  }
81196
81271
  function isUsableSpaDir(dir) {
81197
- return existsSync14(dir) && statSync7(dir).isDirectory() && existsSync14(join14(dir, "index.html"));
81272
+ return existsSync15(dir) && statSync7(dir).isDirectory() && existsSync15(join15(dir, "index.html"));
81198
81273
  }
81199
81274
  function resolveSpaDist() {
81200
81275
  const here = moduleDir3();
81201
81276
  const candidates = [
81202
- join14(here, "..", "frontend"),
81203
- join14(here, "..", "..", "..", "..", "frontend", "dist"),
81204
- join14(here, "..", "..", "dist", "frontend")
81277
+ join15(here, "..", "frontend"),
81278
+ join15(here, "..", "..", "..", "..", "frontend", "dist"),
81279
+ join15(here, "..", "..", "dist", "frontend")
81205
81280
  ];
81206
81281
  for (const c2 of candidates) {
81207
81282
  if (isUsableSpaDir(c2))
@@ -81212,11 +81287,11 @@ function resolveSpaDist() {
81212
81287
  function resolveStaticDir() {
81213
81288
  const here = moduleDir3();
81214
81289
  const candidates = [
81215
- join14(here, "..", "static"),
81216
- join14(here, "..", "..", "..", "..", "web", "static")
81290
+ join15(here, "..", "static"),
81291
+ join15(here, "..", "..", "..", "..", "web", "static")
81217
81292
  ];
81218
81293
  for (const c2 of candidates) {
81219
- if (existsSync14(c2) && statSync7(c2).isDirectory())
81294
+ if (existsSync15(c2) && statSync7(c2).isDirectory())
81220
81295
  return c2;
81221
81296
  }
81222
81297
  return null;
@@ -81267,6 +81342,7 @@ function buildApp(ctx = buildWebContext()) {
81267
81342
  app.use(logger((message, ...rest) => console.log(`${localTimestamp()} ${message}`, ...rest)));
81268
81343
  }
81269
81344
  registerMetaRoutes(app, ctx);
81345
+ registerPreferencesRoutes(app);
81270
81346
  if (ctx) {
81271
81347
  registerDiscoveryRoutes(app, ctx);
81272
81348
  registerDocumentReadRoutes(app, ctx);
@@ -81300,9 +81376,9 @@ function buildApp(ctx = buildWebContext()) {
81300
81376
  root: spaDist,
81301
81377
  rewriteRequestPath: (path) => path.replace(/^\/app/, "") || "/"
81302
81378
  }));
81303
- const indexPath = join15(spaDist, "index.html");
81304
- if (existsSync15(indexPath)) {
81305
- const indexHtml = readFileSync14(indexPath, "utf8");
81379
+ const indexPath = join16(spaDist, "index.html");
81380
+ if (existsSync16(indexPath)) {
81381
+ const indexHtml = readFileSync15(indexPath, "utf8");
81306
81382
  app.get("/app/*", (c2) => c2.html(indexHtml));
81307
81383
  }
81308
81384
  }
@@ -81360,28 +81436,28 @@ async function buildWebServer(options = {}) {
81360
81436
  // src/web/daemon.ts
81361
81437
  import { spawn } from "node:child_process";
81362
81438
  import {
81363
- existsSync as existsSync16,
81364
- mkdirSync as mkdirSync4,
81439
+ existsSync as existsSync17,
81440
+ mkdirSync as mkdirSync5,
81365
81441
  openSync,
81366
- readFileSync as readFileSync15,
81442
+ readFileSync as readFileSync16,
81367
81443
  rmSync,
81368
- writeFileSync as writeFileSync5
81444
+ writeFileSync as writeFileSync6
81369
81445
  } from "node:fs";
81370
81446
  import { homedir as homedir8 } from "node:os";
81371
- import { join as join16 } from "node:path";
81372
- var STATE_DIR = join16(homedir8(), ".cerefox");
81373
- var PID_FILE = join16(STATE_DIR, "web.pid");
81374
- var LOG_FILE = join16(STATE_DIR, "web.log");
81447
+ import { join as join17 } from "node:path";
81448
+ var STATE_DIR = join17(homedir8(), ".cerefox");
81449
+ var PID_FILE = join17(STATE_DIR, "web.pid");
81450
+ var LOG_FILE = join17(STATE_DIR, "web.log");
81375
81451
  var daemonPaths = { stateDir: STATE_DIR, pidFile: PID_FILE, logFile: LOG_FILE };
81376
81452
  function ensureStateDir() {
81377
- if (!existsSync16(STATE_DIR))
81378
- mkdirSync4(STATE_DIR, { recursive: true });
81453
+ if (!existsSync17(STATE_DIR))
81454
+ mkdirSync5(STATE_DIR, { recursive: true });
81379
81455
  }
81380
81456
  function readPidFile() {
81381
- if (!existsSync16(PID_FILE))
81457
+ if (!existsSync17(PID_FILE))
81382
81458
  return null;
81383
81459
  try {
81384
- const parsed = JSON.parse(readFileSync15(PID_FILE, "utf8"));
81460
+ const parsed = JSON.parse(readFileSync16(PID_FILE, "utf8"));
81385
81461
  if (typeof parsed.pid !== "number")
81386
81462
  return null;
81387
81463
  return {
@@ -81396,7 +81472,7 @@ function readPidFile() {
81396
81472
  }
81397
81473
  function writePidFile(info3) {
81398
81474
  ensureStateDir();
81399
- writeFileSync5(PID_FILE, JSON.stringify(info3, null, 2) + `
81475
+ writeFileSync6(PID_FILE, JSON.stringify(info3, null, 2) + `
81400
81476
  `, "utf8");
81401
81477
  }
81402
81478
  function removePidFile() {
@@ -81740,7 +81816,7 @@ Learn more:
81740
81816
 
81741
81817
  // src/bin/cerefox.ts
81742
81818
  async function bareEntryPoint() {
81743
- const { existsSync: existsSync17 } = await import("node:fs");
81819
+ const { existsSync: existsSync18 } = await import("node:fs");
81744
81820
  const { resolveEnvFile: resolveEnvFile2 } = await Promise.resolve().then(() => (init_config(), exports_config));
81745
81821
  const { c: c2, println: println2 } = await Promise.resolve().then(() => (init_cli_core(), exports_cli_core));
81746
81822
  const { PKG_VERSION: PKG_VERSION2 } = await Promise.resolve().then(() => (init_meta(), exports_meta));
@@ -81749,7 +81825,7 @@ async function bareEntryPoint() {
81749
81825
  println2("");
81750
81826
  let configExists = false;
81751
81827
  try {
81752
- configExists = existsSync17(resolveEnvFile2());
81828
+ configExists = existsSync18(resolveEnvFile2());
81753
81829
  } catch {}
81754
81830
  if (!configExists) {
81755
81831
  println2(c2.yellow("⚠ No config detected."));