chat-logbook 0.10.0 → 0.11.0

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/api/dist/index.js CHANGED
@@ -5,11 +5,11 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/index.ts
8
- import fs6 from "fs";
8
+ import fs7 from "fs";
9
9
  import os from "os";
10
- import path4 from "path";
10
+ import path5 from "path";
11
11
  import { exec } from "child_process";
12
- import { fileURLToPath as fileURLToPath3 } from "url";
12
+ import { fileURLToPath as fileURLToPath4 } from "url";
13
13
 
14
14
  // ../node_modules/.pnpm/@hono+node-server@1.19.11_hono@4.12.9/node_modules/@hono/node-server/dist/index.mjs
15
15
  import { createServer as createServerHTTP } from "http";
@@ -705,26 +705,26 @@ var handleParsingNestedValues = (form, key, value) => {
705
705
  };
706
706
 
707
707
  // ../node_modules/.pnpm/hono@4.12.9/node_modules/hono/dist/utils/url.js
708
- var splitPath = (path5) => {
709
- const paths = path5.split("/");
708
+ var splitPath = (path6) => {
709
+ const paths = path6.split("/");
710
710
  if (paths[0] === "") {
711
711
  paths.shift();
712
712
  }
713
713
  return paths;
714
714
  };
715
715
  var splitRoutingPath = (routePath) => {
716
- const { groups, path: path5 } = extractGroupsFromPath(routePath);
717
- const paths = splitPath(path5);
716
+ const { groups, path: path6 } = extractGroupsFromPath(routePath);
717
+ const paths = splitPath(path6);
718
718
  return replaceGroupMarks(paths, groups);
719
719
  };
720
- var extractGroupsFromPath = (path5) => {
720
+ var extractGroupsFromPath = (path6) => {
721
721
  const groups = [];
722
- path5 = path5.replace(/\{[^}]+\}/g, (match2, index) => {
722
+ path6 = path6.replace(/\{[^}]+\}/g, (match2, index) => {
723
723
  const mark = `@${index}`;
724
724
  groups.push([mark, match2]);
725
725
  return mark;
726
726
  });
727
- return { groups, path: path5 };
727
+ return { groups, path: path6 };
728
728
  };
729
729
  var replaceGroupMarks = (paths, groups) => {
730
730
  for (let i = groups.length - 1; i >= 0; i--) {
@@ -781,8 +781,8 @@ var getPath = (request) => {
781
781
  const queryIndex = url.indexOf("?", i);
782
782
  const hashIndex = url.indexOf("#", i);
783
783
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
784
- const path5 = url.slice(start, end);
785
- return tryDecodeURI(path5.includes("%25") ? path5.replace(/%25/g, "%2525") : path5);
784
+ const path6 = url.slice(start, end);
785
+ return tryDecodeURI(path6.includes("%25") ? path6.replace(/%25/g, "%2525") : path6);
786
786
  } else if (charCode === 63 || charCode === 35) {
787
787
  break;
788
788
  }
@@ -799,11 +799,11 @@ var mergePath = (base, sub, ...rest) => {
799
799
  }
800
800
  return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
801
801
  };
802
- var checkOptionalParameter = (path5) => {
803
- if (path5.charCodeAt(path5.length - 1) !== 63 || !path5.includes(":")) {
802
+ var checkOptionalParameter = (path6) => {
803
+ if (path6.charCodeAt(path6.length - 1) !== 63 || !path6.includes(":")) {
804
804
  return null;
805
805
  }
806
- const segments = path5.split("/");
806
+ const segments = path6.split("/");
807
807
  const results = [];
808
808
  let basePath = "";
809
809
  segments.forEach((segment) => {
@@ -944,9 +944,9 @@ var HonoRequest = class {
944
944
  */
945
945
  path;
946
946
  bodyCache = {};
947
- constructor(request, path5 = "/", matchResult = [[]]) {
947
+ constructor(request, path6 = "/", matchResult = [[]]) {
948
948
  this.raw = request;
949
- this.path = path5;
949
+ this.path = path6;
950
950
  this.#matchResult = matchResult;
951
951
  this.#validatedData = {};
952
952
  }
@@ -1683,8 +1683,8 @@ var Hono = class _Hono {
1683
1683
  return this;
1684
1684
  };
1685
1685
  });
1686
- this.on = (method, path5, ...handlers) => {
1687
- for (const p of [path5].flat()) {
1686
+ this.on = (method, path6, ...handlers) => {
1687
+ for (const p of [path6].flat()) {
1688
1688
  this.#path = p;
1689
1689
  for (const m of [method].flat()) {
1690
1690
  handlers.map((handler) => {
@@ -1741,8 +1741,8 @@ var Hono = class _Hono {
1741
1741
  * app.route("/api", app2) // GET /api/user
1742
1742
  * ```
1743
1743
  */
1744
- route(path5, app2) {
1745
- const subApp = this.basePath(path5);
1744
+ route(path6, app2) {
1745
+ const subApp = this.basePath(path6);
1746
1746
  app2.routes.map((r) => {
1747
1747
  let handler;
1748
1748
  if (app2.errorHandler === errorHandler) {
@@ -1768,9 +1768,9 @@ var Hono = class _Hono {
1768
1768
  * const api = new Hono().basePath('/api')
1769
1769
  * ```
1770
1770
  */
1771
- basePath(path5) {
1771
+ basePath(path6) {
1772
1772
  const subApp = this.#clone();
1773
- subApp._basePath = mergePath(this._basePath, path5);
1773
+ subApp._basePath = mergePath(this._basePath, path6);
1774
1774
  return subApp;
1775
1775
  }
1776
1776
  /**
@@ -1844,7 +1844,7 @@ var Hono = class _Hono {
1844
1844
  * })
1845
1845
  * ```
1846
1846
  */
1847
- mount(path5, applicationHandler, options) {
1847
+ mount(path6, applicationHandler, options) {
1848
1848
  let replaceRequest;
1849
1849
  let optionHandler;
1850
1850
  if (options) {
@@ -1871,7 +1871,7 @@ var Hono = class _Hono {
1871
1871
  return [c.env, executionContext];
1872
1872
  };
1873
1873
  replaceRequest ||= (() => {
1874
- const mergedPath = mergePath(this._basePath, path5);
1874
+ const mergedPath = mergePath(this._basePath, path6);
1875
1875
  const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
1876
1876
  return (request) => {
1877
1877
  const url = new URL(request.url);
@@ -1886,14 +1886,14 @@ var Hono = class _Hono {
1886
1886
  }
1887
1887
  await next();
1888
1888
  };
1889
- this.#addRoute(METHOD_NAME_ALL, mergePath(path5, "*"), handler);
1889
+ this.#addRoute(METHOD_NAME_ALL, mergePath(path6, "*"), handler);
1890
1890
  return this;
1891
1891
  }
1892
- #addRoute(method, path5, handler) {
1892
+ #addRoute(method, path6, handler) {
1893
1893
  method = method.toUpperCase();
1894
- path5 = mergePath(this._basePath, path5);
1895
- const r = { basePath: this._basePath, path: path5, method, handler };
1896
- this.router.add(method, path5, [handler, r]);
1894
+ path6 = mergePath(this._basePath, path6);
1895
+ const r = { basePath: this._basePath, path: path6, method, handler };
1896
+ this.router.add(method, path6, [handler, r]);
1897
1897
  this.routes.push(r);
1898
1898
  }
1899
1899
  #handleError(err, c) {
@@ -1906,10 +1906,10 @@ var Hono = class _Hono {
1906
1906
  if (method === "HEAD") {
1907
1907
  return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
1908
1908
  }
1909
- const path5 = this.getPath(request, { env });
1910
- const matchResult = this.router.match(method, path5);
1909
+ const path6 = this.getPath(request, { env });
1910
+ const matchResult = this.router.match(method, path6);
1911
1911
  const c = new Context(request, {
1912
- path: path5,
1912
+ path: path6,
1913
1913
  matchResult,
1914
1914
  env,
1915
1915
  executionCtx,
@@ -2009,7 +2009,7 @@ var Hono = class _Hono {
2009
2009
 
2010
2010
  // ../node_modules/.pnpm/hono@4.12.9/node_modules/hono/dist/router/reg-exp-router/matcher.js
2011
2011
  var emptyParam = [];
2012
- function match(method, path5) {
2012
+ function match(method, path6) {
2013
2013
  const matchers = this.buildAllMatchers();
2014
2014
  const match2 = ((method2, path22) => {
2015
2015
  const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
@@ -2025,7 +2025,7 @@ function match(method, path5) {
2025
2025
  return [matcher[1][index], match3];
2026
2026
  });
2027
2027
  this.match = match2;
2028
- return match2(method, path5);
2028
+ return match2(method, path6);
2029
2029
  }
2030
2030
 
2031
2031
  // ../node_modules/.pnpm/hono@4.12.9/node_modules/hono/dist/router/reg-exp-router/node.js
@@ -2140,12 +2140,12 @@ var Node = class _Node {
2140
2140
  var Trie = class {
2141
2141
  #context = { varIndex: 0 };
2142
2142
  #root = new Node();
2143
- insert(path5, index, pathErrorCheckOnly) {
2143
+ insert(path6, index, pathErrorCheckOnly) {
2144
2144
  const paramAssoc = [];
2145
2145
  const groups = [];
2146
2146
  for (let i = 0; ; ) {
2147
2147
  let replaced = false;
2148
- path5 = path5.replace(/\{[^}]+\}/g, (m) => {
2148
+ path6 = path6.replace(/\{[^}]+\}/g, (m) => {
2149
2149
  const mark = `@\\${i}`;
2150
2150
  groups[i] = [mark, m];
2151
2151
  i++;
@@ -2156,7 +2156,7 @@ var Trie = class {
2156
2156
  break;
2157
2157
  }
2158
2158
  }
2159
- const tokens = path5.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
2159
+ const tokens = path6.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
2160
2160
  for (let i = groups.length - 1; i >= 0; i--) {
2161
2161
  const [mark] = groups[i];
2162
2162
  for (let j = tokens.length - 1; j >= 0; j--) {
@@ -2195,9 +2195,9 @@ var Trie = class {
2195
2195
  // ../node_modules/.pnpm/hono@4.12.9/node_modules/hono/dist/router/reg-exp-router/router.js
2196
2196
  var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
2197
2197
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
2198
- function buildWildcardRegExp(path5) {
2199
- return wildcardRegExpCache[path5] ??= new RegExp(
2200
- path5 === "*" ? "" : `^${path5.replace(
2198
+ function buildWildcardRegExp(path6) {
2199
+ return wildcardRegExpCache[path6] ??= new RegExp(
2200
+ path6 === "*" ? "" : `^${path6.replace(
2201
2201
  /\/\*$|([.\\+*[^\]$()])/g,
2202
2202
  (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
2203
2203
  )}$`
@@ -2219,17 +2219,17 @@ function buildMatcherFromPreprocessedRoutes(routes) {
2219
2219
  );
2220
2220
  const staticMap = /* @__PURE__ */ Object.create(null);
2221
2221
  for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
2222
- const [pathErrorCheckOnly, path5, handlers] = routesWithStaticPathFlag[i];
2222
+ const [pathErrorCheckOnly, path6, handlers] = routesWithStaticPathFlag[i];
2223
2223
  if (pathErrorCheckOnly) {
2224
- staticMap[path5] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
2224
+ staticMap[path6] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
2225
2225
  } else {
2226
2226
  j++;
2227
2227
  }
2228
2228
  let paramAssoc;
2229
2229
  try {
2230
- paramAssoc = trie.insert(path5, j, pathErrorCheckOnly);
2230
+ paramAssoc = trie.insert(path6, j, pathErrorCheckOnly);
2231
2231
  } catch (e) {
2232
- throw e === PATH_ERROR ? new UnsupportedPathError(path5) : e;
2232
+ throw e === PATH_ERROR ? new UnsupportedPathError(path6) : e;
2233
2233
  }
2234
2234
  if (pathErrorCheckOnly) {
2235
2235
  continue;
@@ -2263,12 +2263,12 @@ function buildMatcherFromPreprocessedRoutes(routes) {
2263
2263
  }
2264
2264
  return [regexp, handlerMap, staticMap];
2265
2265
  }
2266
- function findMiddleware(middleware, path5) {
2266
+ function findMiddleware(middleware, path6) {
2267
2267
  if (!middleware) {
2268
2268
  return void 0;
2269
2269
  }
2270
2270
  for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
2271
- if (buildWildcardRegExp(k).test(path5)) {
2271
+ if (buildWildcardRegExp(k).test(path6)) {
2272
2272
  return [...middleware[k]];
2273
2273
  }
2274
2274
  }
@@ -2282,7 +2282,7 @@ var RegExpRouter = class {
2282
2282
  this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
2283
2283
  this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
2284
2284
  }
2285
- add(method, path5, handler) {
2285
+ add(method, path6, handler) {
2286
2286
  const middleware = this.#middleware;
2287
2287
  const routes = this.#routes;
2288
2288
  if (!middleware || !routes) {
@@ -2297,18 +2297,18 @@ var RegExpRouter = class {
2297
2297
  });
2298
2298
  });
2299
2299
  }
2300
- if (path5 === "/*") {
2301
- path5 = "*";
2300
+ if (path6 === "/*") {
2301
+ path6 = "*";
2302
2302
  }
2303
- const paramCount = (path5.match(/\/:/g) || []).length;
2304
- if (/\*$/.test(path5)) {
2305
- const re = buildWildcardRegExp(path5);
2303
+ const paramCount = (path6.match(/\/:/g) || []).length;
2304
+ if (/\*$/.test(path6)) {
2305
+ const re = buildWildcardRegExp(path6);
2306
2306
  if (method === METHOD_NAME_ALL) {
2307
2307
  Object.keys(middleware).forEach((m) => {
2308
- middleware[m][path5] ||= findMiddleware(middleware[m], path5) || findMiddleware(middleware[METHOD_NAME_ALL], path5) || [];
2308
+ middleware[m][path6] ||= findMiddleware(middleware[m], path6) || findMiddleware(middleware[METHOD_NAME_ALL], path6) || [];
2309
2309
  });
2310
2310
  } else {
2311
- middleware[method][path5] ||= findMiddleware(middleware[method], path5) || findMiddleware(middleware[METHOD_NAME_ALL], path5) || [];
2311
+ middleware[method][path6] ||= findMiddleware(middleware[method], path6) || findMiddleware(middleware[METHOD_NAME_ALL], path6) || [];
2312
2312
  }
2313
2313
  Object.keys(middleware).forEach((m) => {
2314
2314
  if (method === METHOD_NAME_ALL || method === m) {
@@ -2326,7 +2326,7 @@ var RegExpRouter = class {
2326
2326
  });
2327
2327
  return;
2328
2328
  }
2329
- const paths = checkOptionalParameter(path5) || [path5];
2329
+ const paths = checkOptionalParameter(path6) || [path6];
2330
2330
  for (let i = 0, len = paths.length; i < len; i++) {
2331
2331
  const path22 = paths[i];
2332
2332
  Object.keys(routes).forEach((m) => {
@@ -2353,13 +2353,13 @@ var RegExpRouter = class {
2353
2353
  const routes = [];
2354
2354
  let hasOwnRoute = method === METHOD_NAME_ALL;
2355
2355
  [this.#middleware, this.#routes].forEach((r) => {
2356
- const ownRoute = r[method] ? Object.keys(r[method]).map((path5) => [path5, r[method][path5]]) : [];
2356
+ const ownRoute = r[method] ? Object.keys(r[method]).map((path6) => [path6, r[method][path6]]) : [];
2357
2357
  if (ownRoute.length !== 0) {
2358
2358
  hasOwnRoute ||= true;
2359
2359
  routes.push(...ownRoute);
2360
2360
  } else if (method !== METHOD_NAME_ALL) {
2361
2361
  routes.push(
2362
- ...Object.keys(r[METHOD_NAME_ALL]).map((path5) => [path5, r[METHOD_NAME_ALL][path5]])
2362
+ ...Object.keys(r[METHOD_NAME_ALL]).map((path6) => [path6, r[METHOD_NAME_ALL][path6]])
2363
2363
  );
2364
2364
  }
2365
2365
  });
@@ -2379,13 +2379,13 @@ var SmartRouter = class {
2379
2379
  constructor(init) {
2380
2380
  this.#routers = init.routers;
2381
2381
  }
2382
- add(method, path5, handler) {
2382
+ add(method, path6, handler) {
2383
2383
  if (!this.#routes) {
2384
2384
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
2385
2385
  }
2386
- this.#routes.push([method, path5, handler]);
2386
+ this.#routes.push([method, path6, handler]);
2387
2387
  }
2388
- match(method, path5) {
2388
+ match(method, path6) {
2389
2389
  if (!this.#routes) {
2390
2390
  throw new Error("Fatal error");
2391
2391
  }
@@ -2400,7 +2400,7 @@ var SmartRouter = class {
2400
2400
  for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
2401
2401
  router.add(...routes[i2]);
2402
2402
  }
2403
- res = router.match(method, path5);
2403
+ res = router.match(method, path6);
2404
2404
  } catch (e) {
2405
2405
  if (e instanceof UnsupportedPathError) {
2406
2406
  continue;
@@ -2450,10 +2450,10 @@ var Node2 = class _Node2 {
2450
2450
  }
2451
2451
  this.#patterns = [];
2452
2452
  }
2453
- insert(method, path5, handler) {
2453
+ insert(method, path6, handler) {
2454
2454
  this.#order = ++this.#order;
2455
2455
  let curNode = this;
2456
- const parts = splitRoutingPath(path5);
2456
+ const parts = splitRoutingPath(path6);
2457
2457
  const possibleKeys = [];
2458
2458
  for (let i = 0, len = parts.length; i < len; i++) {
2459
2459
  const p = parts[i];
@@ -2502,12 +2502,12 @@ var Node2 = class _Node2 {
2502
2502
  }
2503
2503
  }
2504
2504
  }
2505
- search(method, path5) {
2505
+ search(method, path6) {
2506
2506
  const handlerSets = [];
2507
2507
  this.#params = emptyParams;
2508
2508
  const curNode = this;
2509
2509
  let curNodes = [curNode];
2510
- const parts = splitPath(path5);
2510
+ const parts = splitPath(path6);
2511
2511
  const curNodesQueue = [];
2512
2512
  const len = parts.length;
2513
2513
  let partOffsets = null;
@@ -2549,13 +2549,13 @@ var Node2 = class _Node2 {
2549
2549
  if (matcher instanceof RegExp) {
2550
2550
  if (partOffsets === null) {
2551
2551
  partOffsets = new Array(len);
2552
- let offset = path5[0] === "/" ? 1 : 0;
2552
+ let offset = path6[0] === "/" ? 1 : 0;
2553
2553
  for (let p = 0; p < len; p++) {
2554
2554
  partOffsets[p] = offset;
2555
2555
  offset += parts[p].length + 1;
2556
2556
  }
2557
2557
  }
2558
- const restPathString = path5.substring(partOffsets[i]);
2558
+ const restPathString = path6.substring(partOffsets[i]);
2559
2559
  const m = matcher.exec(restPathString);
2560
2560
  if (m) {
2561
2561
  params[name] = m[0];
@@ -2608,18 +2608,18 @@ var TrieRouter = class {
2608
2608
  constructor() {
2609
2609
  this.#node = new Node2();
2610
2610
  }
2611
- add(method, path5, handler) {
2612
- const results = checkOptionalParameter(path5);
2611
+ add(method, path6, handler) {
2612
+ const results = checkOptionalParameter(path6);
2613
2613
  if (results) {
2614
2614
  for (let i = 0, len = results.length; i < len; i++) {
2615
2615
  this.#node.insert(method, results[i], handler);
2616
2616
  }
2617
2617
  return;
2618
2618
  }
2619
- this.#node.insert(method, path5, handler);
2619
+ this.#node.insert(method, path6, handler);
2620
2620
  }
2621
- match(method, path5) {
2622
- return this.#node.search(method, path5);
2621
+ match(method, path6) {
2622
+ return this.#node.search(method, path6);
2623
2623
  }
2624
2624
  };
2625
2625
 
@@ -2750,10 +2750,10 @@ var createStreamBody = (stream) => {
2750
2750
  });
2751
2751
  return body;
2752
2752
  };
2753
- var getStats = (path5) => {
2753
+ var getStats = (path6) => {
2754
2754
  let stats;
2755
2755
  try {
2756
- stats = statSync(path5);
2756
+ stats = statSync(path6);
2757
2757
  } catch {
2758
2758
  }
2759
2759
  return stats;
@@ -2796,21 +2796,21 @@ var serveStatic = (options = { root: "" }) => {
2796
2796
  return next();
2797
2797
  }
2798
2798
  }
2799
- let path5 = join(
2799
+ let path6 = join(
2800
2800
  root,
2801
2801
  !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
2802
2802
  );
2803
- let stats = getStats(path5);
2803
+ let stats = getStats(path6);
2804
2804
  if (stats && stats.isDirectory()) {
2805
2805
  const indexFile = options.index ?? "index.html";
2806
- path5 = join(path5, indexFile);
2807
- stats = getStats(path5);
2806
+ path6 = join(path6, indexFile);
2807
+ stats = getStats(path6);
2808
2808
  }
2809
2809
  if (!stats) {
2810
- await options.onNotFound?.(path5, c);
2810
+ await options.onNotFound?.(path6, c);
2811
2811
  return next();
2812
2812
  }
2813
- const mimeType = getMimeType(path5);
2813
+ const mimeType = getMimeType(path6);
2814
2814
  c.header("Content-Type", mimeType || "application/octet-stream");
2815
2815
  if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
2816
2816
  const acceptEncodingSet = new Set(
@@ -2820,12 +2820,12 @@ var serveStatic = (options = { root: "" }) => {
2820
2820
  if (!acceptEncodingSet.has(encoding)) {
2821
2821
  continue;
2822
2822
  }
2823
- const precompressedStats = getStats(path5 + ENCODINGS[encoding]);
2823
+ const precompressedStats = getStats(path6 + ENCODINGS[encoding]);
2824
2824
  if (precompressedStats) {
2825
2825
  c.header("Content-Encoding", encoding);
2826
2826
  c.header("Vary", "Accept-Encoding", { append: true });
2827
2827
  stats = precompressedStats;
2828
- path5 = path5 + ENCODINGS[encoding];
2828
+ path6 = path6 + ENCODINGS[encoding];
2829
2829
  break;
2830
2830
  }
2831
2831
  }
@@ -2839,7 +2839,7 @@ var serveStatic = (options = { root: "" }) => {
2839
2839
  result = c.body(null);
2840
2840
  } else if (!range) {
2841
2841
  c.header("Content-Length", size.toString());
2842
- result = c.body(createStreamBody(createReadStream(path5)), 200);
2842
+ result = c.body(createStreamBody(createReadStream(path6)), 200);
2843
2843
  } else {
2844
2844
  c.header("Accept-Ranges", "bytes");
2845
2845
  c.header("Date", stats.birthtime.toUTCString());
@@ -2850,12 +2850,12 @@ var serveStatic = (options = { root: "" }) => {
2850
2850
  end = size - 1;
2851
2851
  }
2852
2852
  const chunksize = end - start + 1;
2853
- const stream = createReadStream(path5, { start, end });
2853
+ const stream = createReadStream(path6, { start, end });
2854
2854
  c.header("Content-Length", chunksize.toString());
2855
2855
  c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
2856
2856
  result = c.body(createStreamBody(stream), 206);
2857
2857
  }
2858
- await options.onFound?.(path5, c);
2858
+ await options.onFound?.(path6, c);
2859
2859
  return result;
2860
2860
  };
2861
2861
  };
@@ -4173,7 +4173,7 @@ var QueryPromise = class {
4173
4173
  function mapResultRow(columns, row, joinsNotNullableMap) {
4174
4174
  const nullifyMap = {};
4175
4175
  const result = columns.reduce(
4176
- (result2, { path: path5, field }, columnIndex) => {
4176
+ (result2, { path: path6, field }, columnIndex) => {
4177
4177
  let decoder;
4178
4178
  if (is(field, Column)) {
4179
4179
  decoder = field;
@@ -4185,8 +4185,8 @@ function mapResultRow(columns, row, joinsNotNullableMap) {
4185
4185
  decoder = field.sql.decoder;
4186
4186
  }
4187
4187
  let node = result2;
4188
- for (const [pathChunkIndex, pathChunk] of path5.entries()) {
4189
- if (pathChunkIndex < path5.length - 1) {
4188
+ for (const [pathChunkIndex, pathChunk] of path6.entries()) {
4189
+ if (pathChunkIndex < path6.length - 1) {
4190
4190
  if (!(pathChunk in node)) {
4191
4191
  node[pathChunk] = {};
4192
4192
  }
@@ -4194,8 +4194,8 @@ function mapResultRow(columns, row, joinsNotNullableMap) {
4194
4194
  } else {
4195
4195
  const rawValue = row[columnIndex];
4196
4196
  const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
4197
- if (joinsNotNullableMap && is(field, Column) && path5.length === 2) {
4198
- const objectName = path5[0];
4197
+ if (joinsNotNullableMap && is(field, Column) && path6.length === 2) {
4198
+ const objectName = path6[0];
4199
4199
  if (!(objectName in nullifyMap)) {
4200
4200
  nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
4201
4201
  } else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== getTableName(field.table)) {
@@ -4758,7 +4758,6 @@ function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelect
4758
4758
  var schema_exports = {};
4759
4759
  __export(schema_exports, {
4760
4760
  archiveMeta: () => archiveMeta,
4761
- chatScanState: () => chatScanState,
4762
4761
  chats: () => chats,
4763
4762
  ingestionEvents: () => ingestionEvents,
4764
4763
  messages: () => messages,
@@ -8225,21 +8224,6 @@ var messages = sqliteTable(
8225
8224
  uniqueIndex("messages_canonical_idx").on(t.agent, t.sourceId, t.messageId)
8226
8225
  ]
8227
8226
  );
8228
- var chatScanState = sqliteTable(
8229
- "session_scan_state",
8230
- {
8231
- id: integer("id").primaryKey({ autoIncrement: true }),
8232
- agent: text("agent").notNull(),
8233
- sourceId: text("source_id").notNull(),
8234
- sourcePath: text("source_path").notNull(),
8235
- lastMtimeMs: integer("last_mtime_ms").notNull(),
8236
- lastSizeBytes: integer("last_size_bytes").notNull(),
8237
- lastScannedAt: integer("last_scanned_at", {
8238
- mode: "timestamp_ms"
8239
- }).notNull()
8240
- },
8241
- (t) => [uniqueIndex("session_scan_state_idx").on(t.agent, t.sourceId)]
8242
- );
8243
8227
  var ingestionEvents = sqliteTable("ingestion_events", {
8244
8228
  id: integer("id").primaryKey({ autoIncrement: true }),
8245
8229
  agent: text("agent").notNull(),
@@ -8694,12 +8678,105 @@ function createArchiveRepository({
8694
8678
  };
8695
8679
  }
8696
8680
 
8697
- // src/metadata/repository.ts
8681
+ // src/checkpoint/repository.ts
8698
8682
  import fs3 from "fs";
8699
8683
  import path2 from "path";
8700
8684
  import { fileURLToPath as fileURLToPath2 } from "url";
8701
8685
  import Database2 from "better-sqlite3";
8702
8686
 
8687
+ // src/checkpoint/schema.ts
8688
+ var schema_exports2 = {};
8689
+ __export(schema_exports2, {
8690
+ chatScanState: () => chatScanState
8691
+ });
8692
+ var chatScanState = sqliteTable(
8693
+ "chat_scan_state",
8694
+ {
8695
+ id: integer("id").primaryKey({ autoIncrement: true }),
8696
+ agent: text("agent").notNull(),
8697
+ sourceId: text("source_id").notNull(),
8698
+ sourcePath: text("source_path").notNull(),
8699
+ lastMtimeMs: integer("last_mtime_ms").notNull(),
8700
+ lastSizeBytes: integer("last_size_bytes").notNull(),
8701
+ lastScannedAt: integer("last_scanned_at", {
8702
+ mode: "timestamp_ms"
8703
+ }).notNull()
8704
+ },
8705
+ (t) => [uniqueIndex("chat_scan_state_idx").on(t.agent, t.sourceId)]
8706
+ );
8707
+
8708
+ // src/checkpoint/repository.ts
8709
+ function resolveMigrationsFolder2() {
8710
+ const here = path2.dirname(fileURLToPath2(import.meta.url));
8711
+ const candidates = [
8712
+ path2.join(here, "../../drizzle/checkpoint"),
8713
+ path2.join(here, "./drizzle/checkpoint")
8714
+ ];
8715
+ const found = candidates.find((p) => fs3.existsSync(p));
8716
+ if (!found) {
8717
+ throw new Error("Could not locate checkpoint drizzle migrations folder");
8718
+ }
8719
+ return found;
8720
+ }
8721
+ function createCheckpointRepository({
8722
+ dataDir: dataDir2
8723
+ }) {
8724
+ fs3.mkdirSync(dataDir2, { recursive: true });
8725
+ const sqlite = new Database2(path2.join(dataDir2, "checkpoint.db"));
8726
+ const db = drizzle(sqlite, { schema: schema_exports2 });
8727
+ migrate(db, { migrationsFolder: resolveMigrationsFolder2() });
8728
+ return {
8729
+ db,
8730
+ getScanState(agent, sourceId) {
8731
+ const row = db.select({
8732
+ lastMtimeMs: chatScanState.lastMtimeMs,
8733
+ lastSizeBytes: chatScanState.lastSizeBytes,
8734
+ lastScannedAt: chatScanState.lastScannedAt
8735
+ }).from(chatScanState).where(
8736
+ and(
8737
+ eq(chatScanState.agent, agent),
8738
+ eq(chatScanState.sourceId, sourceId)
8739
+ )
8740
+ ).get();
8741
+ return row ?? void 0;
8742
+ },
8743
+ recordScanState(agent, sourceId, sourcePath, stat4, scannedAt) {
8744
+ const existing = db.select({ id: chatScanState.id }).from(chatScanState).where(
8745
+ and(
8746
+ eq(chatScanState.agent, agent),
8747
+ eq(chatScanState.sourceId, sourceId)
8748
+ )
8749
+ ).get();
8750
+ if (existing) {
8751
+ db.update(chatScanState).set({
8752
+ sourcePath,
8753
+ lastMtimeMs: stat4.mtimeMs,
8754
+ lastSizeBytes: stat4.sizeBytes,
8755
+ lastScannedAt: scannedAt
8756
+ }).where(eq(chatScanState.id, existing.id)).run();
8757
+ } else {
8758
+ db.insert(chatScanState).values({
8759
+ agent,
8760
+ sourceId,
8761
+ sourcePath,
8762
+ lastMtimeMs: stat4.mtimeMs,
8763
+ lastSizeBytes: stat4.sizeBytes,
8764
+ lastScannedAt: scannedAt
8765
+ }).run();
8766
+ }
8767
+ },
8768
+ close() {
8769
+ sqlite.close();
8770
+ }
8771
+ };
8772
+ }
8773
+
8774
+ // src/metadata/repository.ts
8775
+ import fs4 from "fs";
8776
+ import path3 from "path";
8777
+ import { fileURLToPath as fileURLToPath3 } from "url";
8778
+ import Database3 from "better-sqlite3";
8779
+
8703
8780
  // src/metadata/schema.ts
8704
8781
  var chatsMeta = sqliteTable("chats_meta", {
8705
8782
  id: text("id").primaryKey(),
@@ -8713,28 +8790,38 @@ var chatsMeta = sqliteTable("chats_meta", {
8713
8790
  });
8714
8791
 
8715
8792
  // src/metadata/repository.ts
8716
- function resolveMigrationsFolder2() {
8717
- const here = path2.dirname(fileURLToPath2(import.meta.url));
8793
+ function resolveMigrationsFolder3() {
8794
+ const here = path3.dirname(fileURLToPath3(import.meta.url));
8718
8795
  const candidates = [
8719
- path2.join(here, "../../drizzle"),
8720
- path2.join(here, "./drizzle")
8796
+ path3.join(here, "../../drizzle"),
8797
+ path3.join(here, "./drizzle")
8721
8798
  ];
8722
- const found = candidates.find((p) => fs3.existsSync(p));
8799
+ const found = candidates.find((p) => fs4.existsSync(p));
8723
8800
  if (!found) {
8724
8801
  throw new Error("Could not locate drizzle migrations folder");
8725
8802
  }
8726
8803
  return found;
8727
8804
  }
8805
+ var DB_FILE = "metadata.db";
8806
+ var LEGACY_DB_FILE = "data.db";
8807
+ function migrateLegacyDbFile(dataDir2) {
8808
+ const legacy = path3.join(dataDir2, LEGACY_DB_FILE);
8809
+ const current = path3.join(dataDir2, DB_FILE);
8810
+ if (!fs4.existsSync(legacy)) return;
8811
+ if (fs4.existsSync(current)) return;
8812
+ fs4.renameSync(legacy, current);
8813
+ }
8728
8814
  var CLAUDE_CODE_AGENT2 = "claude-code";
8729
8815
  function createMetadataRepository({
8730
8816
  dataDir: dataDir2,
8731
8817
  lookupInternalId,
8732
8818
  ensureChat: ensureChat2
8733
8819
  }) {
8734
- fs3.mkdirSync(dataDir2, { recursive: true });
8735
- const sqlite = new Database2(path2.join(dataDir2, "data.db"));
8820
+ fs4.mkdirSync(dataDir2, { recursive: true });
8821
+ migrateLegacyDbFile(dataDir2);
8822
+ const sqlite = new Database3(path3.join(dataDir2, DB_FILE));
8736
8823
  const db = drizzle(sqlite);
8737
- migrate(db, { migrationsFolder: resolveMigrationsFolder2() });
8824
+ migrate(db, { migrationsFolder: resolveMigrationsFolder3() });
8738
8825
  if (lookupInternalId) {
8739
8826
  rekeyLegacyRows(sqlite, db, lookupInternalId, ensureChat2);
8740
8827
  }
@@ -8805,25 +8892,20 @@ function rekeyLegacyRows(sqlite, db, lookupInternalId, ensureChat2) {
8805
8892
 
8806
8893
  // src/ingestion/ingest.ts
8807
8894
  import crypto6 from "crypto";
8808
- import fs4 from "fs";
8895
+ import fs5 from "fs";
8809
8896
  async function runIngestion(opts) {
8810
8897
  const now = opts.now ?? (() => /* @__PURE__ */ new Date());
8811
8898
  const result = {
8812
8899
  scanned: 0,
8813
8900
  rawInserted: 0,
8814
- canonicalUpserted: 0,
8901
+ normalizedUpserted: 0,
8815
8902
  skippedByMtime: 0
8816
8903
  };
8817
8904
  for (const plugin of opts.plugins) {
8818
8905
  for await (const ref of plugin.discover(opts.env)) {
8819
8906
  result.scanned += 1;
8820
8907
  const stat4 = safeStat(ref.sourcePath);
8821
- const prior = opts.archive.db.select().from(chatScanState).where(
8822
- and(
8823
- eq(chatScanState.agent, plugin.id),
8824
- eq(chatScanState.sourceId, ref.sourceId)
8825
- )
8826
- ).get();
8908
+ const prior = opts.checkpoint.getScanState(plugin.id, ref.sourceId);
8827
8909
  ensureChat(
8828
8910
  opts.archive,
8829
8911
  plugin.id,
@@ -8862,24 +8944,23 @@ async function runIngestion(opts) {
8862
8944
  rawId = inserted.id;
8863
8945
  result.rawInserted += 1;
8864
8946
  }
8865
- const canonical = plugin.normalize(raw2);
8866
- if (!canonical) continue;
8867
- const upserted = upsertCanonical(
8947
+ const normalized = plugin.normalize(raw2);
8948
+ if (!normalized) continue;
8949
+ const upserted = upsertNormalized(
8868
8950
  opts.archive,
8869
8951
  plugin.id,
8870
8952
  ref.sourceId,
8871
- canonical,
8953
+ normalized,
8872
8954
  rawId
8873
8955
  );
8874
- if (upserted) result.canonicalUpserted += 1;
8956
+ if (upserted) result.normalizedUpserted += 1;
8875
8957
  }
8876
8958
  if (stat4) {
8877
- recordScanState(
8878
- opts.archive,
8959
+ opts.checkpoint.recordScanState(
8879
8960
  plugin.id,
8880
8961
  ref.sourceId,
8881
8962
  ref.sourcePath,
8882
- stat4,
8963
+ { mtimeMs: stat4.mtimeMs, sizeBytes: stat4.size },
8883
8964
  now()
8884
8965
  );
8885
8966
  }
@@ -8889,33 +8970,11 @@ async function runIngestion(opts) {
8889
8970
  }
8890
8971
  function safeStat(p) {
8891
8972
  try {
8892
- return fs4.statSync(p);
8973
+ return fs5.statSync(p);
8893
8974
  } catch {
8894
8975
  return null;
8895
8976
  }
8896
8977
  }
8897
- function recordScanState(archive2, agent, sourceId, sourcePath, stat4, scannedAt) {
8898
- const existing = archive2.db.select({ id: chatScanState.id }).from(chatScanState).where(
8899
- and(eq(chatScanState.agent, agent), eq(chatScanState.sourceId, sourceId))
8900
- ).get();
8901
- if (existing) {
8902
- archive2.db.update(chatScanState).set({
8903
- sourcePath,
8904
- lastMtimeMs: stat4.mtimeMs,
8905
- lastSizeBytes: stat4.size,
8906
- lastScannedAt: scannedAt
8907
- }).where(eq(chatScanState.id, existing.id)).run();
8908
- } else {
8909
- archive2.db.insert(chatScanState).values({
8910
- agent,
8911
- sourceId,
8912
- sourcePath,
8913
- lastMtimeMs: stat4.mtimeMs,
8914
- lastSizeBytes: stat4.size,
8915
- lastScannedAt: scannedAt
8916
- }).run();
8917
- }
8918
- }
8919
8978
  function ensureChat(archive2, agent, sourceId, firstSeenAt, project, projectPath) {
8920
8979
  const existing = archive2.db.select().from(chats).where(and(eq(chats.agent, agent), eq(chats.sourceId, sourceId))).get();
8921
8980
  if (existing) {
@@ -8942,7 +9001,7 @@ function ensureChat(archive2, agent, sourceId, firstSeenAt, project, projectPath
8942
9001
  }).run();
8943
9002
  return id;
8944
9003
  }
8945
- function upsertCanonical(archive2, agent, sourceId, msg, rawId) {
9004
+ function upsertNormalized(archive2, agent, sourceId, msg, rawId) {
8946
9005
  const existing = archive2.db.select().from(messages).where(
8947
9006
  and(
8948
9007
  eq(messages.agent, agent),
@@ -9085,7 +9144,7 @@ var ReaddirpStream = class extends Readable3 {
9085
9144
  this._directoryFilter = normalizeFilter(opts.directoryFilter);
9086
9145
  const statMethod = opts.lstat ? lstat : stat;
9087
9146
  if (wantBigintFsStats) {
9088
- this._stat = (path5) => statMethod(path5, { bigint: true });
9147
+ this._stat = (path6) => statMethod(path6, { bigint: true });
9089
9148
  } else {
9090
9149
  this._stat = statMethod;
9091
9150
  }
@@ -9110,8 +9169,8 @@ var ReaddirpStream = class extends Readable3 {
9110
9169
  const par = this.parent;
9111
9170
  const fil = par && par.files;
9112
9171
  if (fil && fil.length > 0) {
9113
- const { path: path5, depth } = par;
9114
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path5));
9172
+ const { path: path6, depth } = par;
9173
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path6));
9115
9174
  const awaited = await Promise.all(slice);
9116
9175
  for (const entry of awaited) {
9117
9176
  if (!entry)
@@ -9151,20 +9210,20 @@ var ReaddirpStream = class extends Readable3 {
9151
9210
  this.reading = false;
9152
9211
  }
9153
9212
  }
9154
- async _exploreDir(path5, depth) {
9213
+ async _exploreDir(path6, depth) {
9155
9214
  let files;
9156
9215
  try {
9157
- files = await readdir(path5, this._rdOptions);
9216
+ files = await readdir(path6, this._rdOptions);
9158
9217
  } catch (error) {
9159
9218
  this._onError(error);
9160
9219
  }
9161
- return { files, depth, path: path5 };
9220
+ return { files, depth, path: path6 };
9162
9221
  }
9163
- async _formatEntry(dirent, path5) {
9222
+ async _formatEntry(dirent, path6) {
9164
9223
  let entry;
9165
9224
  const basename3 = this._isDirent ? dirent.name : dirent;
9166
9225
  try {
9167
- const fullPath = presolve(pjoin(path5, basename3));
9226
+ const fullPath = presolve(pjoin(path6, basename3));
9168
9227
  entry = { path: prelative(this._root, fullPath), fullPath, basename: basename3 };
9169
9228
  entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
9170
9229
  } catch (err) {
@@ -9564,16 +9623,16 @@ var delFromSet = (main, prop, item) => {
9564
9623
  };
9565
9624
  var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
9566
9625
  var FsWatchInstances = /* @__PURE__ */ new Map();
9567
- function createFsWatchInstance(path5, options, listener, errHandler, emitRaw) {
9626
+ function createFsWatchInstance(path6, options, listener, errHandler, emitRaw) {
9568
9627
  const handleEvent = (rawEvent, evPath) => {
9569
- listener(path5);
9570
- emitRaw(rawEvent, evPath, { watchedPath: path5 });
9571
- if (evPath && path5 !== evPath) {
9572
- fsWatchBroadcast(sp.resolve(path5, evPath), KEY_LISTENERS, sp.join(path5, evPath));
9628
+ listener(path6);
9629
+ emitRaw(rawEvent, evPath, { watchedPath: path6 });
9630
+ if (evPath && path6 !== evPath) {
9631
+ fsWatchBroadcast(sp.resolve(path6, evPath), KEY_LISTENERS, sp.join(path6, evPath));
9573
9632
  }
9574
9633
  };
9575
9634
  try {
9576
- return fs_watch(path5, {
9635
+ return fs_watch(path6, {
9577
9636
  persistent: options.persistent
9578
9637
  }, handleEvent);
9579
9638
  } catch (error) {
@@ -9589,12 +9648,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
9589
9648
  listener(val1, val2, val3);
9590
9649
  });
9591
9650
  };
9592
- var setFsWatchListener = (path5, fullPath, options, handlers) => {
9651
+ var setFsWatchListener = (path6, fullPath, options, handlers) => {
9593
9652
  const { listener, errHandler, rawEmitter } = handlers;
9594
9653
  let cont = FsWatchInstances.get(fullPath);
9595
9654
  let watcher2;
9596
9655
  if (!options.persistent) {
9597
- watcher2 = createFsWatchInstance(path5, options, listener, errHandler, rawEmitter);
9656
+ watcher2 = createFsWatchInstance(path6, options, listener, errHandler, rawEmitter);
9598
9657
  if (!watcher2)
9599
9658
  return;
9600
9659
  return watcher2.close.bind(watcher2);
@@ -9605,7 +9664,7 @@ var setFsWatchListener = (path5, fullPath, options, handlers) => {
9605
9664
  addAndConvert(cont, KEY_RAW, rawEmitter);
9606
9665
  } else {
9607
9666
  watcher2 = createFsWatchInstance(
9608
- path5,
9667
+ path6,
9609
9668
  options,
9610
9669
  fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
9611
9670
  errHandler,
@@ -9620,7 +9679,7 @@ var setFsWatchListener = (path5, fullPath, options, handlers) => {
9620
9679
  cont.watcherUnusable = true;
9621
9680
  if (isWindows && error.code === "EPERM") {
9622
9681
  try {
9623
- const fd = await open(path5, "r");
9682
+ const fd = await open(path6, "r");
9624
9683
  await fd.close();
9625
9684
  broadcastErr(error);
9626
9685
  } catch (err) {
@@ -9651,7 +9710,7 @@ var setFsWatchListener = (path5, fullPath, options, handlers) => {
9651
9710
  };
9652
9711
  };
9653
9712
  var FsWatchFileInstances = /* @__PURE__ */ new Map();
9654
- var setFsWatchFileListener = (path5, fullPath, options, handlers) => {
9713
+ var setFsWatchFileListener = (path6, fullPath, options, handlers) => {
9655
9714
  const { listener, rawEmitter } = handlers;
9656
9715
  let cont = FsWatchFileInstances.get(fullPath);
9657
9716
  const copts = cont && cont.options;
@@ -9673,7 +9732,7 @@ var setFsWatchFileListener = (path5, fullPath, options, handlers) => {
9673
9732
  });
9674
9733
  const currmtime = curr.mtimeMs;
9675
9734
  if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
9676
- foreach(cont.listeners, (listener2) => listener2(path5, curr));
9735
+ foreach(cont.listeners, (listener2) => listener2(path6, curr));
9677
9736
  }
9678
9737
  })
9679
9738
  };
@@ -9703,13 +9762,13 @@ var NodeFsHandler = class {
9703
9762
  * @param listener on fs change
9704
9763
  * @returns closer for the watcher instance
9705
9764
  */
9706
- _watchWithNodeFs(path5, listener) {
9765
+ _watchWithNodeFs(path6, listener) {
9707
9766
  const opts = this.fsw.options;
9708
- const directory = sp.dirname(path5);
9709
- const basename3 = sp.basename(path5);
9767
+ const directory = sp.dirname(path6);
9768
+ const basename3 = sp.basename(path6);
9710
9769
  const parent = this.fsw._getWatchedDir(directory);
9711
9770
  parent.add(basename3);
9712
- const absolutePath = sp.resolve(path5);
9771
+ const absolutePath = sp.resolve(path6);
9713
9772
  const options = {
9714
9773
  persistent: opts.persistent
9715
9774
  };
@@ -9719,12 +9778,12 @@ var NodeFsHandler = class {
9719
9778
  if (opts.usePolling) {
9720
9779
  const enableBin = opts.interval !== opts.binaryInterval;
9721
9780
  options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
9722
- closer = setFsWatchFileListener(path5, absolutePath, options, {
9781
+ closer = setFsWatchFileListener(path6, absolutePath, options, {
9723
9782
  listener,
9724
9783
  rawEmitter: this.fsw._emitRaw
9725
9784
  });
9726
9785
  } else {
9727
- closer = setFsWatchListener(path5, absolutePath, options, {
9786
+ closer = setFsWatchListener(path6, absolutePath, options, {
9728
9787
  listener,
9729
9788
  errHandler: this._boundHandleError,
9730
9789
  rawEmitter: this.fsw._emitRaw
@@ -9746,7 +9805,7 @@ var NodeFsHandler = class {
9746
9805
  let prevStats = stats;
9747
9806
  if (parent.has(basename3))
9748
9807
  return;
9749
- const listener = async (path5, newStats) => {
9808
+ const listener = async (path6, newStats) => {
9750
9809
  if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
9751
9810
  return;
9752
9811
  if (!newStats || newStats.mtimeMs === 0) {
@@ -9760,11 +9819,11 @@ var NodeFsHandler = class {
9760
9819
  this.fsw._emit(EV.CHANGE, file, newStats2);
9761
9820
  }
9762
9821
  if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
9763
- this.fsw._closeFile(path5);
9822
+ this.fsw._closeFile(path6);
9764
9823
  prevStats = newStats2;
9765
9824
  const closer2 = this._watchWithNodeFs(file, listener);
9766
9825
  if (closer2)
9767
- this.fsw._addPathCloser(path5, closer2);
9826
+ this.fsw._addPathCloser(path6, closer2);
9768
9827
  } else {
9769
9828
  prevStats = newStats2;
9770
9829
  }
@@ -9796,7 +9855,7 @@ var NodeFsHandler = class {
9796
9855
  * @param item basename of this item
9797
9856
  * @returns true if no more processing is needed for this entry.
9798
9857
  */
9799
- async _handleSymlink(entry, directory, path5, item) {
9858
+ async _handleSymlink(entry, directory, path6, item) {
9800
9859
  if (this.fsw.closed) {
9801
9860
  return;
9802
9861
  }
@@ -9806,7 +9865,7 @@ var NodeFsHandler = class {
9806
9865
  this.fsw._incrReadyCount();
9807
9866
  let linkPath;
9808
9867
  try {
9809
- linkPath = await fsrealpath(path5);
9868
+ linkPath = await fsrealpath(path6);
9810
9869
  } catch (e) {
9811
9870
  this.fsw._emitReady();
9812
9871
  return true;
@@ -9816,12 +9875,12 @@ var NodeFsHandler = class {
9816
9875
  if (dir.has(item)) {
9817
9876
  if (this.fsw._symlinkPaths.get(full) !== linkPath) {
9818
9877
  this.fsw._symlinkPaths.set(full, linkPath);
9819
- this.fsw._emit(EV.CHANGE, path5, entry.stats);
9878
+ this.fsw._emit(EV.CHANGE, path6, entry.stats);
9820
9879
  }
9821
9880
  } else {
9822
9881
  dir.add(item);
9823
9882
  this.fsw._symlinkPaths.set(full, linkPath);
9824
- this.fsw._emit(EV.ADD, path5, entry.stats);
9883
+ this.fsw._emit(EV.ADD, path6, entry.stats);
9825
9884
  }
9826
9885
  this.fsw._emitReady();
9827
9886
  return true;
@@ -9851,9 +9910,9 @@ var NodeFsHandler = class {
9851
9910
  return;
9852
9911
  }
9853
9912
  const item = entry.path;
9854
- let path5 = sp.join(directory, item);
9913
+ let path6 = sp.join(directory, item);
9855
9914
  current.add(item);
9856
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path5, item)) {
9915
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path6, item)) {
9857
9916
  return;
9858
9917
  }
9859
9918
  if (this.fsw.closed) {
@@ -9862,8 +9921,8 @@ var NodeFsHandler = class {
9862
9921
  }
9863
9922
  if (item === target || !target && !previous.has(item)) {
9864
9923
  this.fsw._incrReadyCount();
9865
- path5 = sp.join(dir, sp.relative(dir, path5));
9866
- this._addToNodeFs(path5, initialAdd, wh, depth + 1);
9924
+ path6 = sp.join(dir, sp.relative(dir, path6));
9925
+ this._addToNodeFs(path6, initialAdd, wh, depth + 1);
9867
9926
  }
9868
9927
  }).on(EV.ERROR, this._boundHandleError);
9869
9928
  return new Promise((resolve3, reject) => {
@@ -9932,13 +9991,13 @@ var NodeFsHandler = class {
9932
9991
  * @param depth Child path actually targeted for watch
9933
9992
  * @param target Child path actually targeted for watch
9934
9993
  */
9935
- async _addToNodeFs(path5, initialAdd, priorWh, depth, target) {
9994
+ async _addToNodeFs(path6, initialAdd, priorWh, depth, target) {
9936
9995
  const ready = this.fsw._emitReady;
9937
- if (this.fsw._isIgnored(path5) || this.fsw.closed) {
9996
+ if (this.fsw._isIgnored(path6) || this.fsw.closed) {
9938
9997
  ready();
9939
9998
  return false;
9940
9999
  }
9941
- const wh = this.fsw._getWatchHelpers(path5);
10000
+ const wh = this.fsw._getWatchHelpers(path6);
9942
10001
  if (priorWh) {
9943
10002
  wh.filterPath = (entry) => priorWh.filterPath(entry);
9944
10003
  wh.filterDir = (entry) => priorWh.filterDir(entry);
@@ -9954,8 +10013,8 @@ var NodeFsHandler = class {
9954
10013
  const follow = this.fsw.options.followSymlinks;
9955
10014
  let closer;
9956
10015
  if (stats.isDirectory()) {
9957
- const absPath = sp.resolve(path5);
9958
- const targetPath = follow ? await fsrealpath(path5) : path5;
10016
+ const absPath = sp.resolve(path6);
10017
+ const targetPath = follow ? await fsrealpath(path6) : path6;
9959
10018
  if (this.fsw.closed)
9960
10019
  return;
9961
10020
  closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
@@ -9965,29 +10024,29 @@ var NodeFsHandler = class {
9965
10024
  this.fsw._symlinkPaths.set(absPath, targetPath);
9966
10025
  }
9967
10026
  } else if (stats.isSymbolicLink()) {
9968
- const targetPath = follow ? await fsrealpath(path5) : path5;
10027
+ const targetPath = follow ? await fsrealpath(path6) : path6;
9969
10028
  if (this.fsw.closed)
9970
10029
  return;
9971
10030
  const parent = sp.dirname(wh.watchPath);
9972
10031
  this.fsw._getWatchedDir(parent).add(wh.watchPath);
9973
10032
  this.fsw._emit(EV.ADD, wh.watchPath, stats);
9974
- closer = await this._handleDir(parent, stats, initialAdd, depth, path5, wh, targetPath);
10033
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path6, wh, targetPath);
9975
10034
  if (this.fsw.closed)
9976
10035
  return;
9977
10036
  if (targetPath !== void 0) {
9978
- this.fsw._symlinkPaths.set(sp.resolve(path5), targetPath);
10037
+ this.fsw._symlinkPaths.set(sp.resolve(path6), targetPath);
9979
10038
  }
9980
10039
  } else {
9981
10040
  closer = this._handleFile(wh.watchPath, stats, initialAdd);
9982
10041
  }
9983
10042
  ready();
9984
10043
  if (closer)
9985
- this.fsw._addPathCloser(path5, closer);
10044
+ this.fsw._addPathCloser(path6, closer);
9986
10045
  return false;
9987
10046
  } catch (error) {
9988
10047
  if (this.fsw._handleError(error)) {
9989
10048
  ready();
9990
- return path5;
10049
+ return path6;
9991
10050
  }
9992
10051
  }
9993
10052
  }
@@ -10030,24 +10089,24 @@ function createPattern(matcher) {
10030
10089
  }
10031
10090
  return () => false;
10032
10091
  }
10033
- function normalizePath(path5) {
10034
- if (typeof path5 !== "string")
10092
+ function normalizePath(path6) {
10093
+ if (typeof path6 !== "string")
10035
10094
  throw new Error("string expected");
10036
- path5 = sp2.normalize(path5);
10037
- path5 = path5.replace(/\\/g, "/");
10095
+ path6 = sp2.normalize(path6);
10096
+ path6 = path6.replace(/\\/g, "/");
10038
10097
  let prepend = false;
10039
- if (path5.startsWith("//"))
10098
+ if (path6.startsWith("//"))
10040
10099
  prepend = true;
10041
- path5 = path5.replace(DOUBLE_SLASH_RE, "/");
10100
+ path6 = path6.replace(DOUBLE_SLASH_RE, "/");
10042
10101
  if (prepend)
10043
- path5 = "/" + path5;
10044
- return path5;
10102
+ path6 = "/" + path6;
10103
+ return path6;
10045
10104
  }
10046
10105
  function matchPatterns(patterns, testString, stats) {
10047
- const path5 = normalizePath(testString);
10106
+ const path6 = normalizePath(testString);
10048
10107
  for (let index = 0; index < patterns.length; index++) {
10049
10108
  const pattern = patterns[index];
10050
- if (pattern(path5, stats)) {
10109
+ if (pattern(path6, stats)) {
10051
10110
  return true;
10052
10111
  }
10053
10112
  }
@@ -10085,19 +10144,19 @@ var toUnix = (string) => {
10085
10144
  }
10086
10145
  return str;
10087
10146
  };
10088
- var normalizePathToUnix = (path5) => toUnix(sp2.normalize(toUnix(path5)));
10089
- var normalizeIgnored = (cwd = "") => (path5) => {
10090
- if (typeof path5 === "string") {
10091
- return normalizePathToUnix(sp2.isAbsolute(path5) ? path5 : sp2.join(cwd, path5));
10147
+ var normalizePathToUnix = (path6) => toUnix(sp2.normalize(toUnix(path6)));
10148
+ var normalizeIgnored = (cwd = "") => (path6) => {
10149
+ if (typeof path6 === "string") {
10150
+ return normalizePathToUnix(sp2.isAbsolute(path6) ? path6 : sp2.join(cwd, path6));
10092
10151
  } else {
10093
- return path5;
10152
+ return path6;
10094
10153
  }
10095
10154
  };
10096
- var getAbsolutePath = (path5, cwd) => {
10097
- if (sp2.isAbsolute(path5)) {
10098
- return path5;
10155
+ var getAbsolutePath = (path6, cwd) => {
10156
+ if (sp2.isAbsolute(path6)) {
10157
+ return path6;
10099
10158
  }
10100
- return sp2.join(cwd, path5);
10159
+ return sp2.join(cwd, path6);
10101
10160
  };
10102
10161
  var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
10103
10162
  var DirEntry = class {
@@ -10162,10 +10221,10 @@ var WatchHelper = class {
10162
10221
  dirParts;
10163
10222
  followSymlinks;
10164
10223
  statMethod;
10165
- constructor(path5, follow, fsw) {
10224
+ constructor(path6, follow, fsw) {
10166
10225
  this.fsw = fsw;
10167
- const watchPath = path5;
10168
- this.path = path5 = path5.replace(REPLACER_RE, "");
10226
+ const watchPath = path6;
10227
+ this.path = path6 = path6.replace(REPLACER_RE, "");
10169
10228
  this.watchPath = watchPath;
10170
10229
  this.fullWatchPath = sp2.resolve(watchPath);
10171
10230
  this.dirParts = [];
@@ -10305,20 +10364,20 @@ var FSWatcher = class extends EventEmitter {
10305
10364
  this._closePromise = void 0;
10306
10365
  let paths = unifyPaths(paths_);
10307
10366
  if (cwd) {
10308
- paths = paths.map((path5) => {
10309
- const absPath = getAbsolutePath(path5, cwd);
10367
+ paths = paths.map((path6) => {
10368
+ const absPath = getAbsolutePath(path6, cwd);
10310
10369
  return absPath;
10311
10370
  });
10312
10371
  }
10313
- paths.forEach((path5) => {
10314
- this._removeIgnoredPath(path5);
10372
+ paths.forEach((path6) => {
10373
+ this._removeIgnoredPath(path6);
10315
10374
  });
10316
10375
  this._userIgnored = void 0;
10317
10376
  if (!this._readyCount)
10318
10377
  this._readyCount = 0;
10319
10378
  this._readyCount += paths.length;
10320
- Promise.all(paths.map(async (path5) => {
10321
- const res = await this._nodeFsHandler._addToNodeFs(path5, !_internal, void 0, 0, _origAdd);
10379
+ Promise.all(paths.map(async (path6) => {
10380
+ const res = await this._nodeFsHandler._addToNodeFs(path6, !_internal, void 0, 0, _origAdd);
10322
10381
  if (res)
10323
10382
  this._emitReady();
10324
10383
  return res;
@@ -10340,17 +10399,17 @@ var FSWatcher = class extends EventEmitter {
10340
10399
  return this;
10341
10400
  const paths = unifyPaths(paths_);
10342
10401
  const { cwd } = this.options;
10343
- paths.forEach((path5) => {
10344
- if (!sp2.isAbsolute(path5) && !this._closers.has(path5)) {
10402
+ paths.forEach((path6) => {
10403
+ if (!sp2.isAbsolute(path6) && !this._closers.has(path6)) {
10345
10404
  if (cwd)
10346
- path5 = sp2.join(cwd, path5);
10347
- path5 = sp2.resolve(path5);
10405
+ path6 = sp2.join(cwd, path6);
10406
+ path6 = sp2.resolve(path6);
10348
10407
  }
10349
- this._closePath(path5);
10350
- this._addIgnoredPath(path5);
10351
- if (this._watched.has(path5)) {
10408
+ this._closePath(path6);
10409
+ this._addIgnoredPath(path6);
10410
+ if (this._watched.has(path6)) {
10352
10411
  this._addIgnoredPath({
10353
- path: path5,
10412
+ path: path6,
10354
10413
  recursive: true
10355
10414
  });
10356
10415
  }
@@ -10414,38 +10473,38 @@ var FSWatcher = class extends EventEmitter {
10414
10473
  * @param stats arguments to be passed with event
10415
10474
  * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
10416
10475
  */
10417
- async _emit(event, path5, stats) {
10476
+ async _emit(event, path6, stats) {
10418
10477
  if (this.closed)
10419
10478
  return;
10420
10479
  const opts = this.options;
10421
10480
  if (isWindows)
10422
- path5 = sp2.normalize(path5);
10481
+ path6 = sp2.normalize(path6);
10423
10482
  if (opts.cwd)
10424
- path5 = sp2.relative(opts.cwd, path5);
10425
- const args = [path5];
10483
+ path6 = sp2.relative(opts.cwd, path6);
10484
+ const args = [path6];
10426
10485
  if (stats != null)
10427
10486
  args.push(stats);
10428
10487
  const awf = opts.awaitWriteFinish;
10429
10488
  let pw;
10430
- if (awf && (pw = this._pendingWrites.get(path5))) {
10489
+ if (awf && (pw = this._pendingWrites.get(path6))) {
10431
10490
  pw.lastChange = /* @__PURE__ */ new Date();
10432
10491
  return this;
10433
10492
  }
10434
10493
  if (opts.atomic) {
10435
10494
  if (event === EVENTS.UNLINK) {
10436
- this._pendingUnlinks.set(path5, [event, ...args]);
10495
+ this._pendingUnlinks.set(path6, [event, ...args]);
10437
10496
  setTimeout(() => {
10438
- this._pendingUnlinks.forEach((entry, path6) => {
10497
+ this._pendingUnlinks.forEach((entry, path7) => {
10439
10498
  this.emit(...entry);
10440
10499
  this.emit(EVENTS.ALL, ...entry);
10441
- this._pendingUnlinks.delete(path6);
10500
+ this._pendingUnlinks.delete(path7);
10442
10501
  });
10443
10502
  }, typeof opts.atomic === "number" ? opts.atomic : 100);
10444
10503
  return this;
10445
10504
  }
10446
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path5)) {
10505
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path6)) {
10447
10506
  event = EVENTS.CHANGE;
10448
- this._pendingUnlinks.delete(path5);
10507
+ this._pendingUnlinks.delete(path6);
10449
10508
  }
10450
10509
  }
10451
10510
  if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
@@ -10463,16 +10522,16 @@ var FSWatcher = class extends EventEmitter {
10463
10522
  this.emitWithAll(event, args);
10464
10523
  }
10465
10524
  };
10466
- this._awaitWriteFinish(path5, awf.stabilityThreshold, event, awfEmit);
10525
+ this._awaitWriteFinish(path6, awf.stabilityThreshold, event, awfEmit);
10467
10526
  return this;
10468
10527
  }
10469
10528
  if (event === EVENTS.CHANGE) {
10470
- const isThrottled = !this._throttle(EVENTS.CHANGE, path5, 50);
10529
+ const isThrottled = !this._throttle(EVENTS.CHANGE, path6, 50);
10471
10530
  if (isThrottled)
10472
10531
  return this;
10473
10532
  }
10474
10533
  if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
10475
- const fullPath = opts.cwd ? sp2.join(opts.cwd, path5) : path5;
10534
+ const fullPath = opts.cwd ? sp2.join(opts.cwd, path6) : path6;
10476
10535
  let stats2;
10477
10536
  try {
10478
10537
  stats2 = await stat3(fullPath);
@@ -10503,23 +10562,23 @@ var FSWatcher = class extends EventEmitter {
10503
10562
  * @param timeout duration of time to suppress duplicate actions
10504
10563
  * @returns tracking object or false if action should be suppressed
10505
10564
  */
10506
- _throttle(actionType, path5, timeout) {
10565
+ _throttle(actionType, path6, timeout) {
10507
10566
  if (!this._throttled.has(actionType)) {
10508
10567
  this._throttled.set(actionType, /* @__PURE__ */ new Map());
10509
10568
  }
10510
10569
  const action2 = this._throttled.get(actionType);
10511
10570
  if (!action2)
10512
10571
  throw new Error("invalid throttle");
10513
- const actionPath = action2.get(path5);
10572
+ const actionPath = action2.get(path6);
10514
10573
  if (actionPath) {
10515
10574
  actionPath.count++;
10516
10575
  return false;
10517
10576
  }
10518
10577
  let timeoutObject;
10519
10578
  const clear = () => {
10520
- const item = action2.get(path5);
10579
+ const item = action2.get(path6);
10521
10580
  const count = item ? item.count : 0;
10522
- action2.delete(path5);
10581
+ action2.delete(path6);
10523
10582
  clearTimeout(timeoutObject);
10524
10583
  if (item)
10525
10584
  clearTimeout(item.timeoutObject);
@@ -10527,7 +10586,7 @@ var FSWatcher = class extends EventEmitter {
10527
10586
  };
10528
10587
  timeoutObject = setTimeout(clear, timeout);
10529
10588
  const thr = { timeoutObject, clear, count: 0 };
10530
- action2.set(path5, thr);
10589
+ action2.set(path6, thr);
10531
10590
  return thr;
10532
10591
  }
10533
10592
  _incrReadyCount() {
@@ -10541,44 +10600,44 @@ var FSWatcher = class extends EventEmitter {
10541
10600
  * @param event
10542
10601
  * @param awfEmit Callback to be called when ready for event to be emitted.
10543
10602
  */
10544
- _awaitWriteFinish(path5, threshold, event, awfEmit) {
10603
+ _awaitWriteFinish(path6, threshold, event, awfEmit) {
10545
10604
  const awf = this.options.awaitWriteFinish;
10546
10605
  if (typeof awf !== "object")
10547
10606
  return;
10548
10607
  const pollInterval = awf.pollInterval;
10549
10608
  let timeoutHandler;
10550
- let fullPath = path5;
10551
- if (this.options.cwd && !sp2.isAbsolute(path5)) {
10552
- fullPath = sp2.join(this.options.cwd, path5);
10609
+ let fullPath = path6;
10610
+ if (this.options.cwd && !sp2.isAbsolute(path6)) {
10611
+ fullPath = sp2.join(this.options.cwd, path6);
10553
10612
  }
10554
10613
  const now = /* @__PURE__ */ new Date();
10555
10614
  const writes = this._pendingWrites;
10556
10615
  function awaitWriteFinishFn(prevStat) {
10557
10616
  statcb(fullPath, (err, curStat) => {
10558
- if (err || !writes.has(path5)) {
10617
+ if (err || !writes.has(path6)) {
10559
10618
  if (err && err.code !== "ENOENT")
10560
10619
  awfEmit(err);
10561
10620
  return;
10562
10621
  }
10563
10622
  const now2 = Number(/* @__PURE__ */ new Date());
10564
10623
  if (prevStat && curStat.size !== prevStat.size) {
10565
- writes.get(path5).lastChange = now2;
10624
+ writes.get(path6).lastChange = now2;
10566
10625
  }
10567
- const pw = writes.get(path5);
10626
+ const pw = writes.get(path6);
10568
10627
  const df = now2 - pw.lastChange;
10569
10628
  if (df >= threshold) {
10570
- writes.delete(path5);
10629
+ writes.delete(path6);
10571
10630
  awfEmit(void 0, curStat);
10572
10631
  } else {
10573
10632
  timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
10574
10633
  }
10575
10634
  });
10576
10635
  }
10577
- if (!writes.has(path5)) {
10578
- writes.set(path5, {
10636
+ if (!writes.has(path6)) {
10637
+ writes.set(path6, {
10579
10638
  lastChange: now,
10580
10639
  cancelWait: () => {
10581
- writes.delete(path5);
10640
+ writes.delete(path6);
10582
10641
  clearTimeout(timeoutHandler);
10583
10642
  return event;
10584
10643
  }
@@ -10589,8 +10648,8 @@ var FSWatcher = class extends EventEmitter {
10589
10648
  /**
10590
10649
  * Determines whether user has asked to ignore this path.
10591
10650
  */
10592
- _isIgnored(path5, stats) {
10593
- if (this.options.atomic && DOT_RE.test(path5))
10651
+ _isIgnored(path6, stats) {
10652
+ if (this.options.atomic && DOT_RE.test(path6))
10594
10653
  return true;
10595
10654
  if (!this._userIgnored) {
10596
10655
  const { cwd } = this.options;
@@ -10600,17 +10659,17 @@ var FSWatcher = class extends EventEmitter {
10600
10659
  const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
10601
10660
  this._userIgnored = anymatch(list, void 0);
10602
10661
  }
10603
- return this._userIgnored(path5, stats);
10662
+ return this._userIgnored(path6, stats);
10604
10663
  }
10605
- _isntIgnored(path5, stat4) {
10606
- return !this._isIgnored(path5, stat4);
10664
+ _isntIgnored(path6, stat4) {
10665
+ return !this._isIgnored(path6, stat4);
10607
10666
  }
10608
10667
  /**
10609
10668
  * Provides a set of common helpers and properties relating to symlink handling.
10610
10669
  * @param path file or directory pattern being watched
10611
10670
  */
10612
- _getWatchHelpers(path5) {
10613
- return new WatchHelper(path5, this.options.followSymlinks, this);
10671
+ _getWatchHelpers(path6) {
10672
+ return new WatchHelper(path6, this.options.followSymlinks, this);
10614
10673
  }
10615
10674
  // Directory helpers
10616
10675
  // -----------------
@@ -10642,63 +10701,63 @@ var FSWatcher = class extends EventEmitter {
10642
10701
  * @param item base path of item/directory
10643
10702
  */
10644
10703
  _remove(directory, item, isDirectory) {
10645
- const path5 = sp2.join(directory, item);
10646
- const fullPath = sp2.resolve(path5);
10647
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path5) || this._watched.has(fullPath);
10648
- if (!this._throttle("remove", path5, 100))
10704
+ const path6 = sp2.join(directory, item);
10705
+ const fullPath = sp2.resolve(path6);
10706
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path6) || this._watched.has(fullPath);
10707
+ if (!this._throttle("remove", path6, 100))
10649
10708
  return;
10650
10709
  if (!isDirectory && this._watched.size === 1) {
10651
10710
  this.add(directory, item, true);
10652
10711
  }
10653
- const wp = this._getWatchedDir(path5);
10712
+ const wp = this._getWatchedDir(path6);
10654
10713
  const nestedDirectoryChildren = wp.getChildren();
10655
- nestedDirectoryChildren.forEach((nested) => this._remove(path5, nested));
10714
+ nestedDirectoryChildren.forEach((nested) => this._remove(path6, nested));
10656
10715
  const parent = this._getWatchedDir(directory);
10657
10716
  const wasTracked = parent.has(item);
10658
10717
  parent.remove(item);
10659
10718
  if (this._symlinkPaths.has(fullPath)) {
10660
10719
  this._symlinkPaths.delete(fullPath);
10661
10720
  }
10662
- let relPath = path5;
10721
+ let relPath = path6;
10663
10722
  if (this.options.cwd)
10664
- relPath = sp2.relative(this.options.cwd, path5);
10723
+ relPath = sp2.relative(this.options.cwd, path6);
10665
10724
  if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
10666
10725
  const event = this._pendingWrites.get(relPath).cancelWait();
10667
10726
  if (event === EVENTS.ADD)
10668
10727
  return;
10669
10728
  }
10670
- this._watched.delete(path5);
10729
+ this._watched.delete(path6);
10671
10730
  this._watched.delete(fullPath);
10672
10731
  const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
10673
- if (wasTracked && !this._isIgnored(path5))
10674
- this._emit(eventName, path5);
10675
- this._closePath(path5);
10732
+ if (wasTracked && !this._isIgnored(path6))
10733
+ this._emit(eventName, path6);
10734
+ this._closePath(path6);
10676
10735
  }
10677
10736
  /**
10678
10737
  * Closes all watchers for a path
10679
10738
  */
10680
- _closePath(path5) {
10681
- this._closeFile(path5);
10682
- const dir = sp2.dirname(path5);
10683
- this._getWatchedDir(dir).remove(sp2.basename(path5));
10739
+ _closePath(path6) {
10740
+ this._closeFile(path6);
10741
+ const dir = sp2.dirname(path6);
10742
+ this._getWatchedDir(dir).remove(sp2.basename(path6));
10684
10743
  }
10685
10744
  /**
10686
10745
  * Closes only file-specific watchers
10687
10746
  */
10688
- _closeFile(path5) {
10689
- const closers = this._closers.get(path5);
10747
+ _closeFile(path6) {
10748
+ const closers = this._closers.get(path6);
10690
10749
  if (!closers)
10691
10750
  return;
10692
10751
  closers.forEach((closer) => closer());
10693
- this._closers.delete(path5);
10752
+ this._closers.delete(path6);
10694
10753
  }
10695
- _addPathCloser(path5, closer) {
10754
+ _addPathCloser(path6, closer) {
10696
10755
  if (!closer)
10697
10756
  return;
10698
- let list = this._closers.get(path5);
10757
+ let list = this._closers.get(path6);
10699
10758
  if (!list) {
10700
10759
  list = [];
10701
- this._closers.set(path5, list);
10760
+ this._closers.set(path6, list);
10702
10761
  }
10703
10762
  list.push(closer);
10704
10763
  }
@@ -10788,13 +10847,22 @@ function startWatcher(opts) {
10788
10847
  void runIngestion({
10789
10848
  plugins: opts.plugins,
10790
10849
  archive: opts.archive,
10850
+ checkpoint: opts.checkpoint,
10791
10851
  env: opts.env
10792
- }).catch((err) => onError(err));
10852
+ }).then((result) => opts.onIngest?.(result)).catch((err) => onError(err));
10793
10853
  }, debounceMs);
10794
10854
  pendingTimers.set(changedPath, timer);
10795
10855
  }
10796
10856
  return {
10797
10857
  ready,
10858
+ notifyChange(path6) {
10859
+ if (watcher2) watcher2.emit("change", path6);
10860
+ else scheduleIngest(path6);
10861
+ },
10862
+ notifyUnlink(path6) {
10863
+ if (watcher2) watcher2.emit("unlink", path6);
10864
+ else recordUnlink(path6);
10865
+ },
10798
10866
  async close() {
10799
10867
  closed = true;
10800
10868
  for (const t of pendingTimers.values()) clearTimeout(t);
@@ -10805,38 +10873,38 @@ function startWatcher(opts) {
10805
10873
  }
10806
10874
 
10807
10875
  // src/plugins/claude-code/plugin.ts
10808
- import fs5 from "fs";
10809
- import path3 from "path";
10876
+ import fs6 from "fs";
10877
+ import path4 from "path";
10810
10878
  import readline from "readline";
10811
10879
  var ClaudeCodePlugin = class {
10812
10880
  id = "claude-code";
10813
10881
  displayName = "Claude Code";
10814
10882
  async *discover(env) {
10815
- const projectsDir = path3.join(env.homeDir, ".claude", "projects");
10816
- if (!fs5.existsSync(projectsDir)) return;
10817
- const projects = fs5.readdirSync(projectsDir, { withFileTypes: true });
10883
+ const projectsDir = path4.join(env.homeDir, ".claude", "projects");
10884
+ if (!fs6.existsSync(projectsDir)) return;
10885
+ const projects = fs6.readdirSync(projectsDir, { withFileTypes: true });
10818
10886
  for (const project of projects) {
10819
10887
  if (!project.isDirectory()) continue;
10820
- const projectPath = path3.join(projectsDir, project.name);
10821
- const files = fs5.readdirSync(projectPath, { withFileTypes: true });
10888
+ const projectPath = path4.join(projectsDir, project.name);
10889
+ const files = fs6.readdirSync(projectPath, { withFileTypes: true });
10822
10890
  for (const file of files) {
10823
10891
  if (!file.isFile() || !file.name.endsWith(".jsonl")) continue;
10824
- const sourcePath = path3.join(projectPath, file.name);
10892
+ const sourcePath = path4.join(projectPath, file.name);
10825
10893
  const sourceId = file.name.replace(/\.jsonl$/, "");
10826
10894
  const cwd = await readCwdFromJsonl(sourcePath);
10827
10895
  yield {
10828
10896
  sourceId,
10829
10897
  sourcePath,
10830
10898
  watchPaths: [sourcePath],
10831
- project: cwd ? path3.basename(cwd) : void 0,
10899
+ project: cwd ? path4.basename(cwd) : void 0,
10832
10900
  projectPath: cwd ?? void 0
10833
10901
  };
10834
10902
  }
10835
10903
  }
10836
10904
  }
10837
10905
  async *extractRaw(ref) {
10838
- if (!fs5.existsSync(ref.sourcePath)) return;
10839
- const stream = fs5.createReadStream(ref.sourcePath, { encoding: "utf-8" });
10906
+ if (!fs6.existsSync(ref.sourcePath)) return;
10907
+ const stream = fs6.createReadStream(ref.sourcePath, { encoding: "utf-8" });
10840
10908
  const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
10841
10909
  let lineNo = 0;
10842
10910
  for await (const line of rl) {
@@ -10885,7 +10953,7 @@ var ClaudeCodePlugin = class {
10885
10953
  };
10886
10954
  async function readCwdFromJsonl(sourcePath) {
10887
10955
  try {
10888
- const stream = fs5.createReadStream(sourcePath, { encoding: "utf-8" });
10956
+ const stream = fs6.createReadStream(sourcePath, { encoding: "utf-8" });
10889
10957
  const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
10890
10958
  try {
10891
10959
  for await (const line of rl) {
@@ -10992,9 +11060,9 @@ Environment:
10992
11060
  `;
10993
11061
 
10994
11062
  // src/index.ts
10995
- var __dirname = path4.dirname(fileURLToPath3(import.meta.url));
10996
- var pkgPath = path4.join(__dirname, "../../package.json");
10997
- var pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf-8"));
11063
+ var __dirname = path5.dirname(fileURLToPath4(import.meta.url));
11064
+ var pkgPath = path5.join(__dirname, "../../package.json");
11065
+ var pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf-8"));
10998
11066
  var action = parseCliArgs(process.argv.slice(2), {
10999
11067
  PORT: process.env.PORT
11000
11068
  });
@@ -11011,20 +11079,23 @@ if (action.kind === "error") {
11011
11079
  process.exit(1);
11012
11080
  }
11013
11081
  updateNotifier({ pkg }).notify({ defer: false, isGlobal: true });
11014
- var dataDir = path4.join(os.homedir(), ".chat-logbook");
11015
- var webDistDir = path4.join(__dirname, "../../web/dist");
11082
+ var dataDir = path5.join(os.homedir(), ".chat-logbook");
11083
+ var webDistDir = path5.join(__dirname, "../../web/dist");
11016
11084
  var port = action.port;
11017
11085
  var archive = createArchiveRepository({ dataDir });
11086
+ var checkpoint = createCheckpointRepository({ dataDir });
11018
11087
  var metadata = createMetadataRepository({ dataDir });
11019
11088
  var app = createApp({ archive, metadata, webDistDir });
11020
11089
  var initialIngest = startIngestionInBackground({
11021
11090
  plugins,
11022
11091
  archive,
11092
+ checkpoint,
11023
11093
  env: { homeDir: os.homedir() }
11024
11094
  });
11025
11095
  var watcher = startWatcher({
11026
11096
  plugins,
11027
11097
  archive,
11098
+ checkpoint,
11028
11099
  env: { homeDir: os.homedir() }
11029
11100
  });
11030
11101
  void initialIngest.done.then(() => watcher.ready).catch(() => {