chat-logbook 0.9.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/README.md +35 -105
- package/api/dist/drizzle/0003_add_deleted_at.sql +2 -0
- package/api/dist/drizzle/archive/0007_drop_session_scan_state.sql +2 -0
- package/api/dist/drizzle/archive/meta/_journal.json +7 -0
- package/api/dist/drizzle/checkpoint/0000_sour_zeigeist.sql +11 -0
- package/api/dist/drizzle/checkpoint/meta/0000_snapshot.json +83 -0
- package/api/dist/drizzle/checkpoint/meta/_journal.json +13 -0
- package/api/dist/drizzle/meta/_journal.json +7 -0
- package/api/dist/index.js +410 -325
- package/package.json +4 -2
- package/web/dist/assets/index-DHnNZHtV.js +57 -0
- package/web/dist/assets/index-DSNHfjXl.css +2 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-BCIIypHs.js +0 -57
- package/web/dist/assets/index-rSLP4i1P.css +0 -2
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
|
|
8
|
+
import fs7 from "fs";
|
|
9
9
|
import os from "os";
|
|
10
|
-
import
|
|
10
|
+
import path5 from "path";
|
|
11
11
|
import { exec } from "child_process";
|
|
12
|
-
import { fileURLToPath as
|
|
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 = (
|
|
709
|
-
const paths =
|
|
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:
|
|
717
|
-
const paths = splitPath(
|
|
716
|
+
const { groups, path: path6 } = extractGroupsFromPath(routePath);
|
|
717
|
+
const paths = splitPath(path6);
|
|
718
718
|
return replaceGroupMarks(paths, groups);
|
|
719
719
|
};
|
|
720
|
-
var extractGroupsFromPath = (
|
|
720
|
+
var extractGroupsFromPath = (path6) => {
|
|
721
721
|
const groups = [];
|
|
722
|
-
|
|
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:
|
|
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
|
|
785
|
-
return tryDecodeURI(
|
|
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 = (
|
|
803
|
-
if (
|
|
802
|
+
var checkOptionalParameter = (path6) => {
|
|
803
|
+
if (path6.charCodeAt(path6.length - 1) !== 63 || !path6.includes(":")) {
|
|
804
804
|
return null;
|
|
805
805
|
}
|
|
806
|
-
const segments =
|
|
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,
|
|
947
|
+
constructor(request, path6 = "/", matchResult = [[]]) {
|
|
948
948
|
this.raw = request;
|
|
949
|
-
this.path =
|
|
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,
|
|
1687
|
-
for (const p of [
|
|
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(
|
|
1745
|
-
const subApp = this.basePath(
|
|
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(
|
|
1771
|
+
basePath(path6) {
|
|
1772
1772
|
const subApp = this.#clone();
|
|
1773
|
-
subApp._basePath = mergePath(this._basePath,
|
|
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(
|
|
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,
|
|
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(
|
|
1889
|
+
this.#addRoute(METHOD_NAME_ALL, mergePath(path6, "*"), handler);
|
|
1890
1890
|
return this;
|
|
1891
1891
|
}
|
|
1892
|
-
#addRoute(method,
|
|
1892
|
+
#addRoute(method, path6, handler) {
|
|
1893
1893
|
method = method.toUpperCase();
|
|
1894
|
-
|
|
1895
|
-
const r = { basePath: this._basePath, path:
|
|
1896
|
-
this.router.add(method,
|
|
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
|
|
1910
|
-
const matchResult = this.router.match(method,
|
|
1909
|
+
const path6 = this.getPath(request, { env });
|
|
1910
|
+
const matchResult = this.router.match(method, path6);
|
|
1911
1911
|
const c = new Context(request, {
|
|
1912
|
-
path:
|
|
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,
|
|
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,
|
|
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(
|
|
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
|
-
|
|
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 =
|
|
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(
|
|
2199
|
-
return wildcardRegExpCache[
|
|
2200
|
-
|
|
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,
|
|
2222
|
+
const [pathErrorCheckOnly, path6, handlers] = routesWithStaticPathFlag[i];
|
|
2223
2223
|
if (pathErrorCheckOnly) {
|
|
2224
|
-
staticMap[
|
|
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(
|
|
2230
|
+
paramAssoc = trie.insert(path6, j, pathErrorCheckOnly);
|
|
2231
2231
|
} catch (e) {
|
|
2232
|
-
throw e === PATH_ERROR ? new UnsupportedPathError(
|
|
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,
|
|
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(
|
|
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,
|
|
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 (
|
|
2301
|
-
|
|
2300
|
+
if (path6 === "/*") {
|
|
2301
|
+
path6 = "*";
|
|
2302
2302
|
}
|
|
2303
|
-
const paramCount = (
|
|
2304
|
-
if (/\*$/.test(
|
|
2305
|
-
const re = buildWildcardRegExp(
|
|
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][
|
|
2308
|
+
middleware[m][path6] ||= findMiddleware(middleware[m], path6) || findMiddleware(middleware[METHOD_NAME_ALL], path6) || [];
|
|
2309
2309
|
});
|
|
2310
2310
|
} else {
|
|
2311
|
-
middleware[method][
|
|
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(
|
|
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((
|
|
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((
|
|
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,
|
|
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,
|
|
2386
|
+
this.#routes.push([method, path6, handler]);
|
|
2387
2387
|
}
|
|
2388
|
-
match(method,
|
|
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,
|
|
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,
|
|
2453
|
+
insert(method, path6, handler) {
|
|
2454
2454
|
this.#order = ++this.#order;
|
|
2455
2455
|
let curNode = this;
|
|
2456
|
-
const parts = splitRoutingPath(
|
|
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,
|
|
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(
|
|
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 =
|
|
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 =
|
|
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,
|
|
2612
|
-
const results = checkOptionalParameter(
|
|
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,
|
|
2619
|
+
this.#node.insert(method, path6, handler);
|
|
2620
2620
|
}
|
|
2621
|
-
match(method,
|
|
2622
|
-
return this.#node.search(method,
|
|
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 = (
|
|
2753
|
+
var getStats = (path6) => {
|
|
2754
2754
|
let stats;
|
|
2755
2755
|
try {
|
|
2756
|
-
stats = statSync(
|
|
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
|
|
2799
|
+
let path6 = join(
|
|
2800
2800
|
root,
|
|
2801
2801
|
!optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
|
|
2802
2802
|
);
|
|
2803
|
-
let stats = getStats(
|
|
2803
|
+
let stats = getStats(path6);
|
|
2804
2804
|
if (stats && stats.isDirectory()) {
|
|
2805
2805
|
const indexFile = options.index ?? "index.html";
|
|
2806
|
-
|
|
2807
|
-
stats = getStats(
|
|
2806
|
+
path6 = join(path6, indexFile);
|
|
2807
|
+
stats = getStats(path6);
|
|
2808
2808
|
}
|
|
2809
2809
|
if (!stats) {
|
|
2810
|
-
await options.onNotFound?.(
|
|
2810
|
+
await options.onNotFound?.(path6, c);
|
|
2811
2811
|
return next();
|
|
2812
2812
|
}
|
|
2813
|
-
const mimeType = getMimeType(
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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?.(
|
|
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:
|
|
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
|
|
4189
|
-
if (pathChunkIndex <
|
|
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) &&
|
|
4198
|
-
const objectName =
|
|
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(),
|
|
@@ -8252,11 +8236,16 @@ var ingestionEvents = sqliteTable("ingestion_events", {
|
|
|
8252
8236
|
|
|
8253
8237
|
// src/visibility.ts
|
|
8254
8238
|
function loadChatVisibility(metadata2, opts) {
|
|
8255
|
-
const
|
|
8239
|
+
const deleted = metadata2.listDeleted();
|
|
8240
|
+
const trashed = new Set(deleted.map((r) => r.id));
|
|
8241
|
+
const deletedAtById = new Map(
|
|
8242
|
+
deleted.map((r) => [r.id, r.deletedAt?.getTime() ?? null])
|
|
8243
|
+
);
|
|
8256
8244
|
const showTrashed = opts.includeTrashed === true;
|
|
8257
8245
|
return {
|
|
8258
8246
|
isTrashed: (internalId) => trashed.has(internalId),
|
|
8259
|
-
isVisible: (internalId) => showTrashed || !trashed.has(internalId)
|
|
8247
|
+
isVisible: (internalId) => showTrashed || !trashed.has(internalId),
|
|
8248
|
+
deletedAt: (internalId) => deletedAtById.get(internalId) ?? null
|
|
8260
8249
|
};
|
|
8261
8250
|
}
|
|
8262
8251
|
|
|
@@ -8311,7 +8300,8 @@ function createApp({ archive: archive2, metadata: metadata2, webDistDir: webDist
|
|
|
8311
8300
|
projectPath: row.projectPath ?? null,
|
|
8312
8301
|
sourceFilePath: latestRaw?.sourcePath ?? null,
|
|
8313
8302
|
createdAt: tsRange?.minTs ?? firstSeenAtMs,
|
|
8314
|
-
updatedAt: tsRange?.maxTs ?? firstSeenAtMs
|
|
8303
|
+
updatedAt: tsRange?.maxTs ?? firstSeenAtMs,
|
|
8304
|
+
deletedAt: visibility.deletedAt(row.id)
|
|
8315
8305
|
};
|
|
8316
8306
|
if (isDeleted) chat.isDeleted = true;
|
|
8317
8307
|
chats2.push(chat);
|
|
@@ -8688,44 +8678,150 @@ function createArchiveRepository({
|
|
|
8688
8678
|
};
|
|
8689
8679
|
}
|
|
8690
8680
|
|
|
8691
|
-
// src/
|
|
8681
|
+
// src/checkpoint/repository.ts
|
|
8692
8682
|
import fs3 from "fs";
|
|
8693
8683
|
import path2 from "path";
|
|
8694
8684
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
8695
8685
|
import Database2 from "better-sqlite3";
|
|
8696
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
|
+
|
|
8697
8780
|
// src/metadata/schema.ts
|
|
8698
8781
|
var chatsMeta = sqliteTable("chats_meta", {
|
|
8699
8782
|
id: text("id").primaryKey(),
|
|
8700
8783
|
isDeleted: integer("is_deleted", { mode: "boolean" }).notNull().default(false),
|
|
8701
8784
|
customTitle: text("custom_title"),
|
|
8702
8785
|
createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
|
|
8703
|
-
updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull()
|
|
8786
|
+
updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull(),
|
|
8787
|
+
// Set when a chat is moved to Trash; null while active. Drives the Trash
|
|
8788
|
+
// view's independent "Deleted time" sort axis.
|
|
8789
|
+
deletedAt: integer("deleted_at", { mode: "timestamp_ms" })
|
|
8704
8790
|
});
|
|
8705
8791
|
|
|
8706
8792
|
// src/metadata/repository.ts
|
|
8707
|
-
function
|
|
8708
|
-
const here =
|
|
8793
|
+
function resolveMigrationsFolder3() {
|
|
8794
|
+
const here = path3.dirname(fileURLToPath3(import.meta.url));
|
|
8709
8795
|
const candidates = [
|
|
8710
|
-
|
|
8711
|
-
|
|
8796
|
+
path3.join(here, "../../drizzle"),
|
|
8797
|
+
path3.join(here, "./drizzle")
|
|
8712
8798
|
];
|
|
8713
|
-
const found = candidates.find((p) =>
|
|
8799
|
+
const found = candidates.find((p) => fs4.existsSync(p));
|
|
8714
8800
|
if (!found) {
|
|
8715
8801
|
throw new Error("Could not locate drizzle migrations folder");
|
|
8716
8802
|
}
|
|
8717
8803
|
return found;
|
|
8718
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
|
+
}
|
|
8719
8814
|
var CLAUDE_CODE_AGENT2 = "claude-code";
|
|
8720
8815
|
function createMetadataRepository({
|
|
8721
8816
|
dataDir: dataDir2,
|
|
8722
8817
|
lookupInternalId,
|
|
8723
8818
|
ensureChat: ensureChat2
|
|
8724
8819
|
}) {
|
|
8725
|
-
|
|
8726
|
-
|
|
8820
|
+
fs4.mkdirSync(dataDir2, { recursive: true });
|
|
8821
|
+
migrateLegacyDbFile(dataDir2);
|
|
8822
|
+
const sqlite = new Database3(path3.join(dataDir2, DB_FILE));
|
|
8727
8823
|
const db = drizzle(sqlite);
|
|
8728
|
-
migrate(db, { migrationsFolder:
|
|
8824
|
+
migrate(db, { migrationsFolder: resolveMigrationsFolder3() });
|
|
8729
8825
|
if (lookupInternalId) {
|
|
8730
8826
|
rekeyLegacyRows(sqlite, db, lookupInternalId, ensureChat2);
|
|
8731
8827
|
}
|
|
@@ -8736,23 +8832,28 @@ function createMetadataRepository({
|
|
|
8736
8832
|
id: internalId,
|
|
8737
8833
|
isDeleted: true,
|
|
8738
8834
|
createdAt: now,
|
|
8739
|
-
updatedAt: now
|
|
8835
|
+
updatedAt: now,
|
|
8836
|
+
deletedAt: now
|
|
8740
8837
|
}).onConflictDoUpdate({
|
|
8741
8838
|
target: chatsMeta.id,
|
|
8742
|
-
set: { isDeleted: true, updatedAt: now }
|
|
8839
|
+
set: { isDeleted: true, updatedAt: now, deletedAt: now }
|
|
8743
8840
|
}).run();
|
|
8744
8841
|
},
|
|
8745
8842
|
restore(internalId) {
|
|
8746
8843
|
const now = /* @__PURE__ */ new Date();
|
|
8747
|
-
db.update(chatsMeta).set({ isDeleted: false, updatedAt: now }).where(eq(chatsMeta.id, internalId)).run();
|
|
8844
|
+
db.update(chatsMeta).set({ isDeleted: false, updatedAt: now, deletedAt: null }).where(eq(chatsMeta.id, internalId)).run();
|
|
8748
8845
|
},
|
|
8749
8846
|
isDeleted(internalId) {
|
|
8750
8847
|
const row = db.select({ isDeleted: chatsMeta.isDeleted }).from(chatsMeta).where(eq(chatsMeta.id, internalId)).get();
|
|
8751
8848
|
return row?.isDeleted ?? false;
|
|
8752
8849
|
},
|
|
8753
|
-
|
|
8754
|
-
const
|
|
8755
|
-
return
|
|
8850
|
+
getDeletedAt(internalId) {
|
|
8851
|
+
const row = db.select({ deletedAt: chatsMeta.deletedAt }).from(chatsMeta).where(eq(chatsMeta.id, internalId)).get();
|
|
8852
|
+
return row?.deletedAt ?? null;
|
|
8853
|
+
},
|
|
8854
|
+
listDeleted() {
|
|
8855
|
+
const rows = db.select({ id: chatsMeta.id, deletedAt: chatsMeta.deletedAt }).from(chatsMeta).where(eq(chatsMeta.isDeleted, true)).all();
|
|
8856
|
+
return rows.map((r) => ({ id: r.id, deletedAt: r.deletedAt ?? null }));
|
|
8756
8857
|
},
|
|
8757
8858
|
getCustomTitle(internalId) {
|
|
8758
8859
|
const row = db.select({ customTitle: chatsMeta.customTitle }).from(chatsMeta).where(eq(chatsMeta.id, internalId)).get();
|
|
@@ -8791,25 +8892,20 @@ function rekeyLegacyRows(sqlite, db, lookupInternalId, ensureChat2) {
|
|
|
8791
8892
|
|
|
8792
8893
|
// src/ingestion/ingest.ts
|
|
8793
8894
|
import crypto6 from "crypto";
|
|
8794
|
-
import
|
|
8895
|
+
import fs5 from "fs";
|
|
8795
8896
|
async function runIngestion(opts) {
|
|
8796
8897
|
const now = opts.now ?? (() => /* @__PURE__ */ new Date());
|
|
8797
8898
|
const result = {
|
|
8798
8899
|
scanned: 0,
|
|
8799
8900
|
rawInserted: 0,
|
|
8800
|
-
|
|
8901
|
+
normalizedUpserted: 0,
|
|
8801
8902
|
skippedByMtime: 0
|
|
8802
8903
|
};
|
|
8803
8904
|
for (const plugin of opts.plugins) {
|
|
8804
8905
|
for await (const ref of plugin.discover(opts.env)) {
|
|
8805
8906
|
result.scanned += 1;
|
|
8806
8907
|
const stat4 = safeStat(ref.sourcePath);
|
|
8807
|
-
const prior = opts.
|
|
8808
|
-
and(
|
|
8809
|
-
eq(chatScanState.agent, plugin.id),
|
|
8810
|
-
eq(chatScanState.sourceId, ref.sourceId)
|
|
8811
|
-
)
|
|
8812
|
-
).get();
|
|
8908
|
+
const prior = opts.checkpoint.getScanState(plugin.id, ref.sourceId);
|
|
8813
8909
|
ensureChat(
|
|
8814
8910
|
opts.archive,
|
|
8815
8911
|
plugin.id,
|
|
@@ -8848,24 +8944,23 @@ async function runIngestion(opts) {
|
|
|
8848
8944
|
rawId = inserted.id;
|
|
8849
8945
|
result.rawInserted += 1;
|
|
8850
8946
|
}
|
|
8851
|
-
const
|
|
8852
|
-
if (!
|
|
8853
|
-
const upserted =
|
|
8947
|
+
const normalized = plugin.normalize(raw2);
|
|
8948
|
+
if (!normalized) continue;
|
|
8949
|
+
const upserted = upsertNormalized(
|
|
8854
8950
|
opts.archive,
|
|
8855
8951
|
plugin.id,
|
|
8856
8952
|
ref.sourceId,
|
|
8857
|
-
|
|
8953
|
+
normalized,
|
|
8858
8954
|
rawId
|
|
8859
8955
|
);
|
|
8860
|
-
if (upserted) result.
|
|
8956
|
+
if (upserted) result.normalizedUpserted += 1;
|
|
8861
8957
|
}
|
|
8862
8958
|
if (stat4) {
|
|
8863
|
-
recordScanState(
|
|
8864
|
-
opts.archive,
|
|
8959
|
+
opts.checkpoint.recordScanState(
|
|
8865
8960
|
plugin.id,
|
|
8866
8961
|
ref.sourceId,
|
|
8867
8962
|
ref.sourcePath,
|
|
8868
|
-
stat4,
|
|
8963
|
+
{ mtimeMs: stat4.mtimeMs, sizeBytes: stat4.size },
|
|
8869
8964
|
now()
|
|
8870
8965
|
);
|
|
8871
8966
|
}
|
|
@@ -8875,33 +8970,11 @@ async function runIngestion(opts) {
|
|
|
8875
8970
|
}
|
|
8876
8971
|
function safeStat(p) {
|
|
8877
8972
|
try {
|
|
8878
|
-
return
|
|
8973
|
+
return fs5.statSync(p);
|
|
8879
8974
|
} catch {
|
|
8880
8975
|
return null;
|
|
8881
8976
|
}
|
|
8882
8977
|
}
|
|
8883
|
-
function recordScanState(archive2, agent, sourceId, sourcePath, stat4, scannedAt) {
|
|
8884
|
-
const existing = archive2.db.select({ id: chatScanState.id }).from(chatScanState).where(
|
|
8885
|
-
and(eq(chatScanState.agent, agent), eq(chatScanState.sourceId, sourceId))
|
|
8886
|
-
).get();
|
|
8887
|
-
if (existing) {
|
|
8888
|
-
archive2.db.update(chatScanState).set({
|
|
8889
|
-
sourcePath,
|
|
8890
|
-
lastMtimeMs: stat4.mtimeMs,
|
|
8891
|
-
lastSizeBytes: stat4.size,
|
|
8892
|
-
lastScannedAt: scannedAt
|
|
8893
|
-
}).where(eq(chatScanState.id, existing.id)).run();
|
|
8894
|
-
} else {
|
|
8895
|
-
archive2.db.insert(chatScanState).values({
|
|
8896
|
-
agent,
|
|
8897
|
-
sourceId,
|
|
8898
|
-
sourcePath,
|
|
8899
|
-
lastMtimeMs: stat4.mtimeMs,
|
|
8900
|
-
lastSizeBytes: stat4.size,
|
|
8901
|
-
lastScannedAt: scannedAt
|
|
8902
|
-
}).run();
|
|
8903
|
-
}
|
|
8904
|
-
}
|
|
8905
8978
|
function ensureChat(archive2, agent, sourceId, firstSeenAt, project, projectPath) {
|
|
8906
8979
|
const existing = archive2.db.select().from(chats).where(and(eq(chats.agent, agent), eq(chats.sourceId, sourceId))).get();
|
|
8907
8980
|
if (existing) {
|
|
@@ -8928,7 +9001,7 @@ function ensureChat(archive2, agent, sourceId, firstSeenAt, project, projectPath
|
|
|
8928
9001
|
}).run();
|
|
8929
9002
|
return id;
|
|
8930
9003
|
}
|
|
8931
|
-
function
|
|
9004
|
+
function upsertNormalized(archive2, agent, sourceId, msg, rawId) {
|
|
8932
9005
|
const existing = archive2.db.select().from(messages).where(
|
|
8933
9006
|
and(
|
|
8934
9007
|
eq(messages.agent, agent),
|
|
@@ -9071,7 +9144,7 @@ var ReaddirpStream = class extends Readable3 {
|
|
|
9071
9144
|
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
|
9072
9145
|
const statMethod = opts.lstat ? lstat : stat;
|
|
9073
9146
|
if (wantBigintFsStats) {
|
|
9074
|
-
this._stat = (
|
|
9147
|
+
this._stat = (path6) => statMethod(path6, { bigint: true });
|
|
9075
9148
|
} else {
|
|
9076
9149
|
this._stat = statMethod;
|
|
9077
9150
|
}
|
|
@@ -9096,8 +9169,8 @@ var ReaddirpStream = class extends Readable3 {
|
|
|
9096
9169
|
const par = this.parent;
|
|
9097
9170
|
const fil = par && par.files;
|
|
9098
9171
|
if (fil && fil.length > 0) {
|
|
9099
|
-
const { path:
|
|
9100
|
-
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent,
|
|
9172
|
+
const { path: path6, depth } = par;
|
|
9173
|
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path6));
|
|
9101
9174
|
const awaited = await Promise.all(slice);
|
|
9102
9175
|
for (const entry of awaited) {
|
|
9103
9176
|
if (!entry)
|
|
@@ -9137,20 +9210,20 @@ var ReaddirpStream = class extends Readable3 {
|
|
|
9137
9210
|
this.reading = false;
|
|
9138
9211
|
}
|
|
9139
9212
|
}
|
|
9140
|
-
async _exploreDir(
|
|
9213
|
+
async _exploreDir(path6, depth) {
|
|
9141
9214
|
let files;
|
|
9142
9215
|
try {
|
|
9143
|
-
files = await readdir(
|
|
9216
|
+
files = await readdir(path6, this._rdOptions);
|
|
9144
9217
|
} catch (error) {
|
|
9145
9218
|
this._onError(error);
|
|
9146
9219
|
}
|
|
9147
|
-
return { files, depth, path:
|
|
9220
|
+
return { files, depth, path: path6 };
|
|
9148
9221
|
}
|
|
9149
|
-
async _formatEntry(dirent,
|
|
9222
|
+
async _formatEntry(dirent, path6) {
|
|
9150
9223
|
let entry;
|
|
9151
9224
|
const basename3 = this._isDirent ? dirent.name : dirent;
|
|
9152
9225
|
try {
|
|
9153
|
-
const fullPath = presolve(pjoin(
|
|
9226
|
+
const fullPath = presolve(pjoin(path6, basename3));
|
|
9154
9227
|
entry = { path: prelative(this._root, fullPath), fullPath, basename: basename3 };
|
|
9155
9228
|
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
9156
9229
|
} catch (err) {
|
|
@@ -9550,16 +9623,16 @@ var delFromSet = (main, prop, item) => {
|
|
|
9550
9623
|
};
|
|
9551
9624
|
var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
|
|
9552
9625
|
var FsWatchInstances = /* @__PURE__ */ new Map();
|
|
9553
|
-
function createFsWatchInstance(
|
|
9626
|
+
function createFsWatchInstance(path6, options, listener, errHandler, emitRaw) {
|
|
9554
9627
|
const handleEvent = (rawEvent, evPath) => {
|
|
9555
|
-
listener(
|
|
9556
|
-
emitRaw(rawEvent, evPath, { watchedPath:
|
|
9557
|
-
if (evPath &&
|
|
9558
|
-
fsWatchBroadcast(sp.resolve(
|
|
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));
|
|
9559
9632
|
}
|
|
9560
9633
|
};
|
|
9561
9634
|
try {
|
|
9562
|
-
return fs_watch(
|
|
9635
|
+
return fs_watch(path6, {
|
|
9563
9636
|
persistent: options.persistent
|
|
9564
9637
|
}, handleEvent);
|
|
9565
9638
|
} catch (error) {
|
|
@@ -9575,12 +9648,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
|
|
9575
9648
|
listener(val1, val2, val3);
|
|
9576
9649
|
});
|
|
9577
9650
|
};
|
|
9578
|
-
var setFsWatchListener = (
|
|
9651
|
+
var setFsWatchListener = (path6, fullPath, options, handlers) => {
|
|
9579
9652
|
const { listener, errHandler, rawEmitter } = handlers;
|
|
9580
9653
|
let cont = FsWatchInstances.get(fullPath);
|
|
9581
9654
|
let watcher2;
|
|
9582
9655
|
if (!options.persistent) {
|
|
9583
|
-
watcher2 = createFsWatchInstance(
|
|
9656
|
+
watcher2 = createFsWatchInstance(path6, options, listener, errHandler, rawEmitter);
|
|
9584
9657
|
if (!watcher2)
|
|
9585
9658
|
return;
|
|
9586
9659
|
return watcher2.close.bind(watcher2);
|
|
@@ -9591,7 +9664,7 @@ var setFsWatchListener = (path5, fullPath, options, handlers) => {
|
|
|
9591
9664
|
addAndConvert(cont, KEY_RAW, rawEmitter);
|
|
9592
9665
|
} else {
|
|
9593
9666
|
watcher2 = createFsWatchInstance(
|
|
9594
|
-
|
|
9667
|
+
path6,
|
|
9595
9668
|
options,
|
|
9596
9669
|
fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
|
|
9597
9670
|
errHandler,
|
|
@@ -9606,7 +9679,7 @@ var setFsWatchListener = (path5, fullPath, options, handlers) => {
|
|
|
9606
9679
|
cont.watcherUnusable = true;
|
|
9607
9680
|
if (isWindows && error.code === "EPERM") {
|
|
9608
9681
|
try {
|
|
9609
|
-
const fd = await open(
|
|
9682
|
+
const fd = await open(path6, "r");
|
|
9610
9683
|
await fd.close();
|
|
9611
9684
|
broadcastErr(error);
|
|
9612
9685
|
} catch (err) {
|
|
@@ -9637,7 +9710,7 @@ var setFsWatchListener = (path5, fullPath, options, handlers) => {
|
|
|
9637
9710
|
};
|
|
9638
9711
|
};
|
|
9639
9712
|
var FsWatchFileInstances = /* @__PURE__ */ new Map();
|
|
9640
|
-
var setFsWatchFileListener = (
|
|
9713
|
+
var setFsWatchFileListener = (path6, fullPath, options, handlers) => {
|
|
9641
9714
|
const { listener, rawEmitter } = handlers;
|
|
9642
9715
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
9643
9716
|
const copts = cont && cont.options;
|
|
@@ -9659,7 +9732,7 @@ var setFsWatchFileListener = (path5, fullPath, options, handlers) => {
|
|
|
9659
9732
|
});
|
|
9660
9733
|
const currmtime = curr.mtimeMs;
|
|
9661
9734
|
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
|
9662
|
-
foreach(cont.listeners, (listener2) => listener2(
|
|
9735
|
+
foreach(cont.listeners, (listener2) => listener2(path6, curr));
|
|
9663
9736
|
}
|
|
9664
9737
|
})
|
|
9665
9738
|
};
|
|
@@ -9689,13 +9762,13 @@ var NodeFsHandler = class {
|
|
|
9689
9762
|
* @param listener on fs change
|
|
9690
9763
|
* @returns closer for the watcher instance
|
|
9691
9764
|
*/
|
|
9692
|
-
_watchWithNodeFs(
|
|
9765
|
+
_watchWithNodeFs(path6, listener) {
|
|
9693
9766
|
const opts = this.fsw.options;
|
|
9694
|
-
const directory = sp.dirname(
|
|
9695
|
-
const basename3 = sp.basename(
|
|
9767
|
+
const directory = sp.dirname(path6);
|
|
9768
|
+
const basename3 = sp.basename(path6);
|
|
9696
9769
|
const parent = this.fsw._getWatchedDir(directory);
|
|
9697
9770
|
parent.add(basename3);
|
|
9698
|
-
const absolutePath = sp.resolve(
|
|
9771
|
+
const absolutePath = sp.resolve(path6);
|
|
9699
9772
|
const options = {
|
|
9700
9773
|
persistent: opts.persistent
|
|
9701
9774
|
};
|
|
@@ -9705,12 +9778,12 @@ var NodeFsHandler = class {
|
|
|
9705
9778
|
if (opts.usePolling) {
|
|
9706
9779
|
const enableBin = opts.interval !== opts.binaryInterval;
|
|
9707
9780
|
options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
|
|
9708
|
-
closer = setFsWatchFileListener(
|
|
9781
|
+
closer = setFsWatchFileListener(path6, absolutePath, options, {
|
|
9709
9782
|
listener,
|
|
9710
9783
|
rawEmitter: this.fsw._emitRaw
|
|
9711
9784
|
});
|
|
9712
9785
|
} else {
|
|
9713
|
-
closer = setFsWatchListener(
|
|
9786
|
+
closer = setFsWatchListener(path6, absolutePath, options, {
|
|
9714
9787
|
listener,
|
|
9715
9788
|
errHandler: this._boundHandleError,
|
|
9716
9789
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -9732,7 +9805,7 @@ var NodeFsHandler = class {
|
|
|
9732
9805
|
let prevStats = stats;
|
|
9733
9806
|
if (parent.has(basename3))
|
|
9734
9807
|
return;
|
|
9735
|
-
const listener = async (
|
|
9808
|
+
const listener = async (path6, newStats) => {
|
|
9736
9809
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
9737
9810
|
return;
|
|
9738
9811
|
if (!newStats || newStats.mtimeMs === 0) {
|
|
@@ -9746,11 +9819,11 @@ var NodeFsHandler = class {
|
|
|
9746
9819
|
this.fsw._emit(EV.CHANGE, file, newStats2);
|
|
9747
9820
|
}
|
|
9748
9821
|
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
|
|
9749
|
-
this.fsw._closeFile(
|
|
9822
|
+
this.fsw._closeFile(path6);
|
|
9750
9823
|
prevStats = newStats2;
|
|
9751
9824
|
const closer2 = this._watchWithNodeFs(file, listener);
|
|
9752
9825
|
if (closer2)
|
|
9753
|
-
this.fsw._addPathCloser(
|
|
9826
|
+
this.fsw._addPathCloser(path6, closer2);
|
|
9754
9827
|
} else {
|
|
9755
9828
|
prevStats = newStats2;
|
|
9756
9829
|
}
|
|
@@ -9782,7 +9855,7 @@ var NodeFsHandler = class {
|
|
|
9782
9855
|
* @param item basename of this item
|
|
9783
9856
|
* @returns true if no more processing is needed for this entry.
|
|
9784
9857
|
*/
|
|
9785
|
-
async _handleSymlink(entry, directory,
|
|
9858
|
+
async _handleSymlink(entry, directory, path6, item) {
|
|
9786
9859
|
if (this.fsw.closed) {
|
|
9787
9860
|
return;
|
|
9788
9861
|
}
|
|
@@ -9792,7 +9865,7 @@ var NodeFsHandler = class {
|
|
|
9792
9865
|
this.fsw._incrReadyCount();
|
|
9793
9866
|
let linkPath;
|
|
9794
9867
|
try {
|
|
9795
|
-
linkPath = await fsrealpath(
|
|
9868
|
+
linkPath = await fsrealpath(path6);
|
|
9796
9869
|
} catch (e) {
|
|
9797
9870
|
this.fsw._emitReady();
|
|
9798
9871
|
return true;
|
|
@@ -9802,12 +9875,12 @@ var NodeFsHandler = class {
|
|
|
9802
9875
|
if (dir.has(item)) {
|
|
9803
9876
|
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
|
9804
9877
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
9805
|
-
this.fsw._emit(EV.CHANGE,
|
|
9878
|
+
this.fsw._emit(EV.CHANGE, path6, entry.stats);
|
|
9806
9879
|
}
|
|
9807
9880
|
} else {
|
|
9808
9881
|
dir.add(item);
|
|
9809
9882
|
this.fsw._symlinkPaths.set(full, linkPath);
|
|
9810
|
-
this.fsw._emit(EV.ADD,
|
|
9883
|
+
this.fsw._emit(EV.ADD, path6, entry.stats);
|
|
9811
9884
|
}
|
|
9812
9885
|
this.fsw._emitReady();
|
|
9813
9886
|
return true;
|
|
@@ -9837,9 +9910,9 @@ var NodeFsHandler = class {
|
|
|
9837
9910
|
return;
|
|
9838
9911
|
}
|
|
9839
9912
|
const item = entry.path;
|
|
9840
|
-
let
|
|
9913
|
+
let path6 = sp.join(directory, item);
|
|
9841
9914
|
current.add(item);
|
|
9842
|
-
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory,
|
|
9915
|
+
if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path6, item)) {
|
|
9843
9916
|
return;
|
|
9844
9917
|
}
|
|
9845
9918
|
if (this.fsw.closed) {
|
|
@@ -9848,8 +9921,8 @@ var NodeFsHandler = class {
|
|
|
9848
9921
|
}
|
|
9849
9922
|
if (item === target || !target && !previous.has(item)) {
|
|
9850
9923
|
this.fsw._incrReadyCount();
|
|
9851
|
-
|
|
9852
|
-
this._addToNodeFs(
|
|
9924
|
+
path6 = sp.join(dir, sp.relative(dir, path6));
|
|
9925
|
+
this._addToNodeFs(path6, initialAdd, wh, depth + 1);
|
|
9853
9926
|
}
|
|
9854
9927
|
}).on(EV.ERROR, this._boundHandleError);
|
|
9855
9928
|
return new Promise((resolve3, reject) => {
|
|
@@ -9918,13 +9991,13 @@ var NodeFsHandler = class {
|
|
|
9918
9991
|
* @param depth Child path actually targeted for watch
|
|
9919
9992
|
* @param target Child path actually targeted for watch
|
|
9920
9993
|
*/
|
|
9921
|
-
async _addToNodeFs(
|
|
9994
|
+
async _addToNodeFs(path6, initialAdd, priorWh, depth, target) {
|
|
9922
9995
|
const ready = this.fsw._emitReady;
|
|
9923
|
-
if (this.fsw._isIgnored(
|
|
9996
|
+
if (this.fsw._isIgnored(path6) || this.fsw.closed) {
|
|
9924
9997
|
ready();
|
|
9925
9998
|
return false;
|
|
9926
9999
|
}
|
|
9927
|
-
const wh = this.fsw._getWatchHelpers(
|
|
10000
|
+
const wh = this.fsw._getWatchHelpers(path6);
|
|
9928
10001
|
if (priorWh) {
|
|
9929
10002
|
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
|
9930
10003
|
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
|
@@ -9940,8 +10013,8 @@ var NodeFsHandler = class {
|
|
|
9940
10013
|
const follow = this.fsw.options.followSymlinks;
|
|
9941
10014
|
let closer;
|
|
9942
10015
|
if (stats.isDirectory()) {
|
|
9943
|
-
const absPath = sp.resolve(
|
|
9944
|
-
const targetPath = follow ? await fsrealpath(
|
|
10016
|
+
const absPath = sp.resolve(path6);
|
|
10017
|
+
const targetPath = follow ? await fsrealpath(path6) : path6;
|
|
9945
10018
|
if (this.fsw.closed)
|
|
9946
10019
|
return;
|
|
9947
10020
|
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
|
@@ -9951,29 +10024,29 @@ var NodeFsHandler = class {
|
|
|
9951
10024
|
this.fsw._symlinkPaths.set(absPath, targetPath);
|
|
9952
10025
|
}
|
|
9953
10026
|
} else if (stats.isSymbolicLink()) {
|
|
9954
|
-
const targetPath = follow ? await fsrealpath(
|
|
10027
|
+
const targetPath = follow ? await fsrealpath(path6) : path6;
|
|
9955
10028
|
if (this.fsw.closed)
|
|
9956
10029
|
return;
|
|
9957
10030
|
const parent = sp.dirname(wh.watchPath);
|
|
9958
10031
|
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
|
9959
10032
|
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
|
9960
|
-
closer = await this._handleDir(parent, stats, initialAdd, depth,
|
|
10033
|
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path6, wh, targetPath);
|
|
9961
10034
|
if (this.fsw.closed)
|
|
9962
10035
|
return;
|
|
9963
10036
|
if (targetPath !== void 0) {
|
|
9964
|
-
this.fsw._symlinkPaths.set(sp.resolve(
|
|
10037
|
+
this.fsw._symlinkPaths.set(sp.resolve(path6), targetPath);
|
|
9965
10038
|
}
|
|
9966
10039
|
} else {
|
|
9967
10040
|
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
|
9968
10041
|
}
|
|
9969
10042
|
ready();
|
|
9970
10043
|
if (closer)
|
|
9971
|
-
this.fsw._addPathCloser(
|
|
10044
|
+
this.fsw._addPathCloser(path6, closer);
|
|
9972
10045
|
return false;
|
|
9973
10046
|
} catch (error) {
|
|
9974
10047
|
if (this.fsw._handleError(error)) {
|
|
9975
10048
|
ready();
|
|
9976
|
-
return
|
|
10049
|
+
return path6;
|
|
9977
10050
|
}
|
|
9978
10051
|
}
|
|
9979
10052
|
}
|
|
@@ -10016,24 +10089,24 @@ function createPattern(matcher) {
|
|
|
10016
10089
|
}
|
|
10017
10090
|
return () => false;
|
|
10018
10091
|
}
|
|
10019
|
-
function normalizePath(
|
|
10020
|
-
if (typeof
|
|
10092
|
+
function normalizePath(path6) {
|
|
10093
|
+
if (typeof path6 !== "string")
|
|
10021
10094
|
throw new Error("string expected");
|
|
10022
|
-
|
|
10023
|
-
|
|
10095
|
+
path6 = sp2.normalize(path6);
|
|
10096
|
+
path6 = path6.replace(/\\/g, "/");
|
|
10024
10097
|
let prepend = false;
|
|
10025
|
-
if (
|
|
10098
|
+
if (path6.startsWith("//"))
|
|
10026
10099
|
prepend = true;
|
|
10027
|
-
|
|
10100
|
+
path6 = path6.replace(DOUBLE_SLASH_RE, "/");
|
|
10028
10101
|
if (prepend)
|
|
10029
|
-
|
|
10030
|
-
return
|
|
10102
|
+
path6 = "/" + path6;
|
|
10103
|
+
return path6;
|
|
10031
10104
|
}
|
|
10032
10105
|
function matchPatterns(patterns, testString, stats) {
|
|
10033
|
-
const
|
|
10106
|
+
const path6 = normalizePath(testString);
|
|
10034
10107
|
for (let index = 0; index < patterns.length; index++) {
|
|
10035
10108
|
const pattern = patterns[index];
|
|
10036
|
-
if (pattern(
|
|
10109
|
+
if (pattern(path6, stats)) {
|
|
10037
10110
|
return true;
|
|
10038
10111
|
}
|
|
10039
10112
|
}
|
|
@@ -10071,19 +10144,19 @@ var toUnix = (string) => {
|
|
|
10071
10144
|
}
|
|
10072
10145
|
return str;
|
|
10073
10146
|
};
|
|
10074
|
-
var normalizePathToUnix = (
|
|
10075
|
-
var normalizeIgnored = (cwd = "") => (
|
|
10076
|
-
if (typeof
|
|
10077
|
-
return normalizePathToUnix(sp2.isAbsolute(
|
|
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));
|
|
10078
10151
|
} else {
|
|
10079
|
-
return
|
|
10152
|
+
return path6;
|
|
10080
10153
|
}
|
|
10081
10154
|
};
|
|
10082
|
-
var getAbsolutePath = (
|
|
10083
|
-
if (sp2.isAbsolute(
|
|
10084
|
-
return
|
|
10155
|
+
var getAbsolutePath = (path6, cwd) => {
|
|
10156
|
+
if (sp2.isAbsolute(path6)) {
|
|
10157
|
+
return path6;
|
|
10085
10158
|
}
|
|
10086
|
-
return sp2.join(cwd,
|
|
10159
|
+
return sp2.join(cwd, path6);
|
|
10087
10160
|
};
|
|
10088
10161
|
var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
|
|
10089
10162
|
var DirEntry = class {
|
|
@@ -10148,10 +10221,10 @@ var WatchHelper = class {
|
|
|
10148
10221
|
dirParts;
|
|
10149
10222
|
followSymlinks;
|
|
10150
10223
|
statMethod;
|
|
10151
|
-
constructor(
|
|
10224
|
+
constructor(path6, follow, fsw) {
|
|
10152
10225
|
this.fsw = fsw;
|
|
10153
|
-
const watchPath =
|
|
10154
|
-
this.path =
|
|
10226
|
+
const watchPath = path6;
|
|
10227
|
+
this.path = path6 = path6.replace(REPLACER_RE, "");
|
|
10155
10228
|
this.watchPath = watchPath;
|
|
10156
10229
|
this.fullWatchPath = sp2.resolve(watchPath);
|
|
10157
10230
|
this.dirParts = [];
|
|
@@ -10291,20 +10364,20 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10291
10364
|
this._closePromise = void 0;
|
|
10292
10365
|
let paths = unifyPaths(paths_);
|
|
10293
10366
|
if (cwd) {
|
|
10294
|
-
paths = paths.map((
|
|
10295
|
-
const absPath = getAbsolutePath(
|
|
10367
|
+
paths = paths.map((path6) => {
|
|
10368
|
+
const absPath = getAbsolutePath(path6, cwd);
|
|
10296
10369
|
return absPath;
|
|
10297
10370
|
});
|
|
10298
10371
|
}
|
|
10299
|
-
paths.forEach((
|
|
10300
|
-
this._removeIgnoredPath(
|
|
10372
|
+
paths.forEach((path6) => {
|
|
10373
|
+
this._removeIgnoredPath(path6);
|
|
10301
10374
|
});
|
|
10302
10375
|
this._userIgnored = void 0;
|
|
10303
10376
|
if (!this._readyCount)
|
|
10304
10377
|
this._readyCount = 0;
|
|
10305
10378
|
this._readyCount += paths.length;
|
|
10306
|
-
Promise.all(paths.map(async (
|
|
10307
|
-
const res = await this._nodeFsHandler._addToNodeFs(
|
|
10379
|
+
Promise.all(paths.map(async (path6) => {
|
|
10380
|
+
const res = await this._nodeFsHandler._addToNodeFs(path6, !_internal, void 0, 0, _origAdd);
|
|
10308
10381
|
if (res)
|
|
10309
10382
|
this._emitReady();
|
|
10310
10383
|
return res;
|
|
@@ -10326,17 +10399,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10326
10399
|
return this;
|
|
10327
10400
|
const paths = unifyPaths(paths_);
|
|
10328
10401
|
const { cwd } = this.options;
|
|
10329
|
-
paths.forEach((
|
|
10330
|
-
if (!sp2.isAbsolute(
|
|
10402
|
+
paths.forEach((path6) => {
|
|
10403
|
+
if (!sp2.isAbsolute(path6) && !this._closers.has(path6)) {
|
|
10331
10404
|
if (cwd)
|
|
10332
|
-
|
|
10333
|
-
|
|
10405
|
+
path6 = sp2.join(cwd, path6);
|
|
10406
|
+
path6 = sp2.resolve(path6);
|
|
10334
10407
|
}
|
|
10335
|
-
this._closePath(
|
|
10336
|
-
this._addIgnoredPath(
|
|
10337
|
-
if (this._watched.has(
|
|
10408
|
+
this._closePath(path6);
|
|
10409
|
+
this._addIgnoredPath(path6);
|
|
10410
|
+
if (this._watched.has(path6)) {
|
|
10338
10411
|
this._addIgnoredPath({
|
|
10339
|
-
path:
|
|
10412
|
+
path: path6,
|
|
10340
10413
|
recursive: true
|
|
10341
10414
|
});
|
|
10342
10415
|
}
|
|
@@ -10400,38 +10473,38 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10400
10473
|
* @param stats arguments to be passed with event
|
|
10401
10474
|
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
|
10402
10475
|
*/
|
|
10403
|
-
async _emit(event,
|
|
10476
|
+
async _emit(event, path6, stats) {
|
|
10404
10477
|
if (this.closed)
|
|
10405
10478
|
return;
|
|
10406
10479
|
const opts = this.options;
|
|
10407
10480
|
if (isWindows)
|
|
10408
|
-
|
|
10481
|
+
path6 = sp2.normalize(path6);
|
|
10409
10482
|
if (opts.cwd)
|
|
10410
|
-
|
|
10411
|
-
const args = [
|
|
10483
|
+
path6 = sp2.relative(opts.cwd, path6);
|
|
10484
|
+
const args = [path6];
|
|
10412
10485
|
if (stats != null)
|
|
10413
10486
|
args.push(stats);
|
|
10414
10487
|
const awf = opts.awaitWriteFinish;
|
|
10415
10488
|
let pw;
|
|
10416
|
-
if (awf && (pw = this._pendingWrites.get(
|
|
10489
|
+
if (awf && (pw = this._pendingWrites.get(path6))) {
|
|
10417
10490
|
pw.lastChange = /* @__PURE__ */ new Date();
|
|
10418
10491
|
return this;
|
|
10419
10492
|
}
|
|
10420
10493
|
if (opts.atomic) {
|
|
10421
10494
|
if (event === EVENTS.UNLINK) {
|
|
10422
|
-
this._pendingUnlinks.set(
|
|
10495
|
+
this._pendingUnlinks.set(path6, [event, ...args]);
|
|
10423
10496
|
setTimeout(() => {
|
|
10424
|
-
this._pendingUnlinks.forEach((entry,
|
|
10497
|
+
this._pendingUnlinks.forEach((entry, path7) => {
|
|
10425
10498
|
this.emit(...entry);
|
|
10426
10499
|
this.emit(EVENTS.ALL, ...entry);
|
|
10427
|
-
this._pendingUnlinks.delete(
|
|
10500
|
+
this._pendingUnlinks.delete(path7);
|
|
10428
10501
|
});
|
|
10429
10502
|
}, typeof opts.atomic === "number" ? opts.atomic : 100);
|
|
10430
10503
|
return this;
|
|
10431
10504
|
}
|
|
10432
|
-
if (event === EVENTS.ADD && this._pendingUnlinks.has(
|
|
10505
|
+
if (event === EVENTS.ADD && this._pendingUnlinks.has(path6)) {
|
|
10433
10506
|
event = EVENTS.CHANGE;
|
|
10434
|
-
this._pendingUnlinks.delete(
|
|
10507
|
+
this._pendingUnlinks.delete(path6);
|
|
10435
10508
|
}
|
|
10436
10509
|
}
|
|
10437
10510
|
if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
|
|
@@ -10449,16 +10522,16 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10449
10522
|
this.emitWithAll(event, args);
|
|
10450
10523
|
}
|
|
10451
10524
|
};
|
|
10452
|
-
this._awaitWriteFinish(
|
|
10525
|
+
this._awaitWriteFinish(path6, awf.stabilityThreshold, event, awfEmit);
|
|
10453
10526
|
return this;
|
|
10454
10527
|
}
|
|
10455
10528
|
if (event === EVENTS.CHANGE) {
|
|
10456
|
-
const isThrottled = !this._throttle(EVENTS.CHANGE,
|
|
10529
|
+
const isThrottled = !this._throttle(EVENTS.CHANGE, path6, 50);
|
|
10457
10530
|
if (isThrottled)
|
|
10458
10531
|
return this;
|
|
10459
10532
|
}
|
|
10460
10533
|
if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
|
|
10461
|
-
const fullPath = opts.cwd ? sp2.join(opts.cwd,
|
|
10534
|
+
const fullPath = opts.cwd ? sp2.join(opts.cwd, path6) : path6;
|
|
10462
10535
|
let stats2;
|
|
10463
10536
|
try {
|
|
10464
10537
|
stats2 = await stat3(fullPath);
|
|
@@ -10489,23 +10562,23 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10489
10562
|
* @param timeout duration of time to suppress duplicate actions
|
|
10490
10563
|
* @returns tracking object or false if action should be suppressed
|
|
10491
10564
|
*/
|
|
10492
|
-
_throttle(actionType,
|
|
10565
|
+
_throttle(actionType, path6, timeout) {
|
|
10493
10566
|
if (!this._throttled.has(actionType)) {
|
|
10494
10567
|
this._throttled.set(actionType, /* @__PURE__ */ new Map());
|
|
10495
10568
|
}
|
|
10496
10569
|
const action2 = this._throttled.get(actionType);
|
|
10497
10570
|
if (!action2)
|
|
10498
10571
|
throw new Error("invalid throttle");
|
|
10499
|
-
const actionPath = action2.get(
|
|
10572
|
+
const actionPath = action2.get(path6);
|
|
10500
10573
|
if (actionPath) {
|
|
10501
10574
|
actionPath.count++;
|
|
10502
10575
|
return false;
|
|
10503
10576
|
}
|
|
10504
10577
|
let timeoutObject;
|
|
10505
10578
|
const clear = () => {
|
|
10506
|
-
const item = action2.get(
|
|
10579
|
+
const item = action2.get(path6);
|
|
10507
10580
|
const count = item ? item.count : 0;
|
|
10508
|
-
action2.delete(
|
|
10581
|
+
action2.delete(path6);
|
|
10509
10582
|
clearTimeout(timeoutObject);
|
|
10510
10583
|
if (item)
|
|
10511
10584
|
clearTimeout(item.timeoutObject);
|
|
@@ -10513,7 +10586,7 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10513
10586
|
};
|
|
10514
10587
|
timeoutObject = setTimeout(clear, timeout);
|
|
10515
10588
|
const thr = { timeoutObject, clear, count: 0 };
|
|
10516
|
-
action2.set(
|
|
10589
|
+
action2.set(path6, thr);
|
|
10517
10590
|
return thr;
|
|
10518
10591
|
}
|
|
10519
10592
|
_incrReadyCount() {
|
|
@@ -10527,44 +10600,44 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10527
10600
|
* @param event
|
|
10528
10601
|
* @param awfEmit Callback to be called when ready for event to be emitted.
|
|
10529
10602
|
*/
|
|
10530
|
-
_awaitWriteFinish(
|
|
10603
|
+
_awaitWriteFinish(path6, threshold, event, awfEmit) {
|
|
10531
10604
|
const awf = this.options.awaitWriteFinish;
|
|
10532
10605
|
if (typeof awf !== "object")
|
|
10533
10606
|
return;
|
|
10534
10607
|
const pollInterval = awf.pollInterval;
|
|
10535
10608
|
let timeoutHandler;
|
|
10536
|
-
let fullPath =
|
|
10537
|
-
if (this.options.cwd && !sp2.isAbsolute(
|
|
10538
|
-
fullPath = sp2.join(this.options.cwd,
|
|
10609
|
+
let fullPath = path6;
|
|
10610
|
+
if (this.options.cwd && !sp2.isAbsolute(path6)) {
|
|
10611
|
+
fullPath = sp2.join(this.options.cwd, path6);
|
|
10539
10612
|
}
|
|
10540
10613
|
const now = /* @__PURE__ */ new Date();
|
|
10541
10614
|
const writes = this._pendingWrites;
|
|
10542
10615
|
function awaitWriteFinishFn(prevStat) {
|
|
10543
10616
|
statcb(fullPath, (err, curStat) => {
|
|
10544
|
-
if (err || !writes.has(
|
|
10617
|
+
if (err || !writes.has(path6)) {
|
|
10545
10618
|
if (err && err.code !== "ENOENT")
|
|
10546
10619
|
awfEmit(err);
|
|
10547
10620
|
return;
|
|
10548
10621
|
}
|
|
10549
10622
|
const now2 = Number(/* @__PURE__ */ new Date());
|
|
10550
10623
|
if (prevStat && curStat.size !== prevStat.size) {
|
|
10551
|
-
writes.get(
|
|
10624
|
+
writes.get(path6).lastChange = now2;
|
|
10552
10625
|
}
|
|
10553
|
-
const pw = writes.get(
|
|
10626
|
+
const pw = writes.get(path6);
|
|
10554
10627
|
const df = now2 - pw.lastChange;
|
|
10555
10628
|
if (df >= threshold) {
|
|
10556
|
-
writes.delete(
|
|
10629
|
+
writes.delete(path6);
|
|
10557
10630
|
awfEmit(void 0, curStat);
|
|
10558
10631
|
} else {
|
|
10559
10632
|
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
|
10560
10633
|
}
|
|
10561
10634
|
});
|
|
10562
10635
|
}
|
|
10563
|
-
if (!writes.has(
|
|
10564
|
-
writes.set(
|
|
10636
|
+
if (!writes.has(path6)) {
|
|
10637
|
+
writes.set(path6, {
|
|
10565
10638
|
lastChange: now,
|
|
10566
10639
|
cancelWait: () => {
|
|
10567
|
-
writes.delete(
|
|
10640
|
+
writes.delete(path6);
|
|
10568
10641
|
clearTimeout(timeoutHandler);
|
|
10569
10642
|
return event;
|
|
10570
10643
|
}
|
|
@@ -10575,8 +10648,8 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10575
10648
|
/**
|
|
10576
10649
|
* Determines whether user has asked to ignore this path.
|
|
10577
10650
|
*/
|
|
10578
|
-
_isIgnored(
|
|
10579
|
-
if (this.options.atomic && DOT_RE.test(
|
|
10651
|
+
_isIgnored(path6, stats) {
|
|
10652
|
+
if (this.options.atomic && DOT_RE.test(path6))
|
|
10580
10653
|
return true;
|
|
10581
10654
|
if (!this._userIgnored) {
|
|
10582
10655
|
const { cwd } = this.options;
|
|
@@ -10586,17 +10659,17 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10586
10659
|
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
|
10587
10660
|
this._userIgnored = anymatch(list, void 0);
|
|
10588
10661
|
}
|
|
10589
|
-
return this._userIgnored(
|
|
10662
|
+
return this._userIgnored(path6, stats);
|
|
10590
10663
|
}
|
|
10591
|
-
_isntIgnored(
|
|
10592
|
-
return !this._isIgnored(
|
|
10664
|
+
_isntIgnored(path6, stat4) {
|
|
10665
|
+
return !this._isIgnored(path6, stat4);
|
|
10593
10666
|
}
|
|
10594
10667
|
/**
|
|
10595
10668
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
10596
10669
|
* @param path file or directory pattern being watched
|
|
10597
10670
|
*/
|
|
10598
|
-
_getWatchHelpers(
|
|
10599
|
-
return new WatchHelper(
|
|
10671
|
+
_getWatchHelpers(path6) {
|
|
10672
|
+
return new WatchHelper(path6, this.options.followSymlinks, this);
|
|
10600
10673
|
}
|
|
10601
10674
|
// Directory helpers
|
|
10602
10675
|
// -----------------
|
|
@@ -10628,63 +10701,63 @@ var FSWatcher = class extends EventEmitter {
|
|
|
10628
10701
|
* @param item base path of item/directory
|
|
10629
10702
|
*/
|
|
10630
10703
|
_remove(directory, item, isDirectory) {
|
|
10631
|
-
const
|
|
10632
|
-
const fullPath = sp2.resolve(
|
|
10633
|
-
isDirectory = isDirectory != null ? isDirectory : this._watched.has(
|
|
10634
|
-
if (!this._throttle("remove",
|
|
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))
|
|
10635
10708
|
return;
|
|
10636
10709
|
if (!isDirectory && this._watched.size === 1) {
|
|
10637
10710
|
this.add(directory, item, true);
|
|
10638
10711
|
}
|
|
10639
|
-
const wp = this._getWatchedDir(
|
|
10712
|
+
const wp = this._getWatchedDir(path6);
|
|
10640
10713
|
const nestedDirectoryChildren = wp.getChildren();
|
|
10641
|
-
nestedDirectoryChildren.forEach((nested) => this._remove(
|
|
10714
|
+
nestedDirectoryChildren.forEach((nested) => this._remove(path6, nested));
|
|
10642
10715
|
const parent = this._getWatchedDir(directory);
|
|
10643
10716
|
const wasTracked = parent.has(item);
|
|
10644
10717
|
parent.remove(item);
|
|
10645
10718
|
if (this._symlinkPaths.has(fullPath)) {
|
|
10646
10719
|
this._symlinkPaths.delete(fullPath);
|
|
10647
10720
|
}
|
|
10648
|
-
let relPath =
|
|
10721
|
+
let relPath = path6;
|
|
10649
10722
|
if (this.options.cwd)
|
|
10650
|
-
relPath = sp2.relative(this.options.cwd,
|
|
10723
|
+
relPath = sp2.relative(this.options.cwd, path6);
|
|
10651
10724
|
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
|
10652
10725
|
const event = this._pendingWrites.get(relPath).cancelWait();
|
|
10653
10726
|
if (event === EVENTS.ADD)
|
|
10654
10727
|
return;
|
|
10655
10728
|
}
|
|
10656
|
-
this._watched.delete(
|
|
10729
|
+
this._watched.delete(path6);
|
|
10657
10730
|
this._watched.delete(fullPath);
|
|
10658
10731
|
const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
|
|
10659
|
-
if (wasTracked && !this._isIgnored(
|
|
10660
|
-
this._emit(eventName,
|
|
10661
|
-
this._closePath(
|
|
10732
|
+
if (wasTracked && !this._isIgnored(path6))
|
|
10733
|
+
this._emit(eventName, path6);
|
|
10734
|
+
this._closePath(path6);
|
|
10662
10735
|
}
|
|
10663
10736
|
/**
|
|
10664
10737
|
* Closes all watchers for a path
|
|
10665
10738
|
*/
|
|
10666
|
-
_closePath(
|
|
10667
|
-
this._closeFile(
|
|
10668
|
-
const dir = sp2.dirname(
|
|
10669
|
-
this._getWatchedDir(dir).remove(sp2.basename(
|
|
10739
|
+
_closePath(path6) {
|
|
10740
|
+
this._closeFile(path6);
|
|
10741
|
+
const dir = sp2.dirname(path6);
|
|
10742
|
+
this._getWatchedDir(dir).remove(sp2.basename(path6));
|
|
10670
10743
|
}
|
|
10671
10744
|
/**
|
|
10672
10745
|
* Closes only file-specific watchers
|
|
10673
10746
|
*/
|
|
10674
|
-
_closeFile(
|
|
10675
|
-
const closers = this._closers.get(
|
|
10747
|
+
_closeFile(path6) {
|
|
10748
|
+
const closers = this._closers.get(path6);
|
|
10676
10749
|
if (!closers)
|
|
10677
10750
|
return;
|
|
10678
10751
|
closers.forEach((closer) => closer());
|
|
10679
|
-
this._closers.delete(
|
|
10752
|
+
this._closers.delete(path6);
|
|
10680
10753
|
}
|
|
10681
|
-
_addPathCloser(
|
|
10754
|
+
_addPathCloser(path6, closer) {
|
|
10682
10755
|
if (!closer)
|
|
10683
10756
|
return;
|
|
10684
|
-
let list = this._closers.get(
|
|
10757
|
+
let list = this._closers.get(path6);
|
|
10685
10758
|
if (!list) {
|
|
10686
10759
|
list = [];
|
|
10687
|
-
this._closers.set(
|
|
10760
|
+
this._closers.set(path6, list);
|
|
10688
10761
|
}
|
|
10689
10762
|
list.push(closer);
|
|
10690
10763
|
}
|
|
@@ -10774,13 +10847,22 @@ function startWatcher(opts) {
|
|
|
10774
10847
|
void runIngestion({
|
|
10775
10848
|
plugins: opts.plugins,
|
|
10776
10849
|
archive: opts.archive,
|
|
10850
|
+
checkpoint: opts.checkpoint,
|
|
10777
10851
|
env: opts.env
|
|
10778
|
-
}).catch((err) => onError(err));
|
|
10852
|
+
}).then((result) => opts.onIngest?.(result)).catch((err) => onError(err));
|
|
10779
10853
|
}, debounceMs);
|
|
10780
10854
|
pendingTimers.set(changedPath, timer);
|
|
10781
10855
|
}
|
|
10782
10856
|
return {
|
|
10783
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
|
+
},
|
|
10784
10866
|
async close() {
|
|
10785
10867
|
closed = true;
|
|
10786
10868
|
for (const t of pendingTimers.values()) clearTimeout(t);
|
|
@@ -10791,38 +10873,38 @@ function startWatcher(opts) {
|
|
|
10791
10873
|
}
|
|
10792
10874
|
|
|
10793
10875
|
// src/plugins/claude-code/plugin.ts
|
|
10794
|
-
import
|
|
10795
|
-
import
|
|
10876
|
+
import fs6 from "fs";
|
|
10877
|
+
import path4 from "path";
|
|
10796
10878
|
import readline from "readline";
|
|
10797
10879
|
var ClaudeCodePlugin = class {
|
|
10798
10880
|
id = "claude-code";
|
|
10799
10881
|
displayName = "Claude Code";
|
|
10800
10882
|
async *discover(env) {
|
|
10801
|
-
const projectsDir =
|
|
10802
|
-
if (!
|
|
10803
|
-
const projects =
|
|
10883
|
+
const projectsDir = path4.join(env.homeDir, ".claude", "projects");
|
|
10884
|
+
if (!fs6.existsSync(projectsDir)) return;
|
|
10885
|
+
const projects = fs6.readdirSync(projectsDir, { withFileTypes: true });
|
|
10804
10886
|
for (const project of projects) {
|
|
10805
10887
|
if (!project.isDirectory()) continue;
|
|
10806
|
-
const projectPath =
|
|
10807
|
-
const files =
|
|
10888
|
+
const projectPath = path4.join(projectsDir, project.name);
|
|
10889
|
+
const files = fs6.readdirSync(projectPath, { withFileTypes: true });
|
|
10808
10890
|
for (const file of files) {
|
|
10809
10891
|
if (!file.isFile() || !file.name.endsWith(".jsonl")) continue;
|
|
10810
|
-
const sourcePath =
|
|
10892
|
+
const sourcePath = path4.join(projectPath, file.name);
|
|
10811
10893
|
const sourceId = file.name.replace(/\.jsonl$/, "");
|
|
10812
10894
|
const cwd = await readCwdFromJsonl(sourcePath);
|
|
10813
10895
|
yield {
|
|
10814
10896
|
sourceId,
|
|
10815
10897
|
sourcePath,
|
|
10816
10898
|
watchPaths: [sourcePath],
|
|
10817
|
-
project: cwd ?
|
|
10899
|
+
project: cwd ? path4.basename(cwd) : void 0,
|
|
10818
10900
|
projectPath: cwd ?? void 0
|
|
10819
10901
|
};
|
|
10820
10902
|
}
|
|
10821
10903
|
}
|
|
10822
10904
|
}
|
|
10823
10905
|
async *extractRaw(ref) {
|
|
10824
|
-
if (!
|
|
10825
|
-
const stream =
|
|
10906
|
+
if (!fs6.existsSync(ref.sourcePath)) return;
|
|
10907
|
+
const stream = fs6.createReadStream(ref.sourcePath, { encoding: "utf-8" });
|
|
10826
10908
|
const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
|
|
10827
10909
|
let lineNo = 0;
|
|
10828
10910
|
for await (const line of rl) {
|
|
@@ -10871,7 +10953,7 @@ var ClaudeCodePlugin = class {
|
|
|
10871
10953
|
};
|
|
10872
10954
|
async function readCwdFromJsonl(sourcePath) {
|
|
10873
10955
|
try {
|
|
10874
|
-
const stream =
|
|
10956
|
+
const stream = fs6.createReadStream(sourcePath, { encoding: "utf-8" });
|
|
10875
10957
|
const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
|
|
10876
10958
|
try {
|
|
10877
10959
|
for await (const line of rl) {
|
|
@@ -10978,9 +11060,9 @@ Environment:
|
|
|
10978
11060
|
`;
|
|
10979
11061
|
|
|
10980
11062
|
// src/index.ts
|
|
10981
|
-
var __dirname =
|
|
10982
|
-
var pkgPath =
|
|
10983
|
-
var pkg = JSON.parse(
|
|
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"));
|
|
10984
11066
|
var action = parseCliArgs(process.argv.slice(2), {
|
|
10985
11067
|
PORT: process.env.PORT
|
|
10986
11068
|
});
|
|
@@ -10997,20 +11079,23 @@ if (action.kind === "error") {
|
|
|
10997
11079
|
process.exit(1);
|
|
10998
11080
|
}
|
|
10999
11081
|
updateNotifier({ pkg }).notify({ defer: false, isGlobal: true });
|
|
11000
|
-
var dataDir =
|
|
11001
|
-
var webDistDir =
|
|
11082
|
+
var dataDir = path5.join(os.homedir(), ".chat-logbook");
|
|
11083
|
+
var webDistDir = path5.join(__dirname, "../../web/dist");
|
|
11002
11084
|
var port = action.port;
|
|
11003
11085
|
var archive = createArchiveRepository({ dataDir });
|
|
11086
|
+
var checkpoint = createCheckpointRepository({ dataDir });
|
|
11004
11087
|
var metadata = createMetadataRepository({ dataDir });
|
|
11005
11088
|
var app = createApp({ archive, metadata, webDistDir });
|
|
11006
11089
|
var initialIngest = startIngestionInBackground({
|
|
11007
11090
|
plugins,
|
|
11008
11091
|
archive,
|
|
11092
|
+
checkpoint,
|
|
11009
11093
|
env: { homeDir: os.homedir() }
|
|
11010
11094
|
});
|
|
11011
11095
|
var watcher = startWatcher({
|
|
11012
11096
|
plugins,
|
|
11013
11097
|
archive,
|
|
11098
|
+
checkpoint,
|
|
11014
11099
|
env: { homeDir: os.homedir() }
|
|
11015
11100
|
});
|
|
11016
11101
|
void initialIngest.done.then(() => watcher.ready).catch(() => {
|