kb-core 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/index.cjs +38 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -44
- package/dist/index.js.map +1 -1
- package/dist/llm.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,WAAW,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,GAAG,EAAE;QACH,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,WAAW,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,GAAG,EAAE;QACH,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;QACpD,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,YAAY,EAAE,MAAM,CAClB,MAAM,EACN;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAChE,CAAC;CACH;AA0CD,wBAAsB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwEvE"}
|
package/dist/index.cjs
CHANGED
|
@@ -728,7 +728,9 @@ function stripHtml(html) {
|
|
|
728
728
|
return text;
|
|
729
729
|
}
|
|
730
730
|
async function readPdf(filePath) {
|
|
731
|
-
const pdfParse = await import("pdf-parse").then((m) => m.default ?? m)
|
|
731
|
+
const pdfParse = await import("pdf-parse").then((m) => m.default ?? m).catch(() => {
|
|
732
|
+
throw new Error("PDF support requires pdf-parse: run `npm install pdf-parse` in your project");
|
|
733
|
+
});
|
|
732
734
|
const buffer = await (0, import_promises6.readFile)(filePath);
|
|
733
735
|
const data = await pdfParse(buffer);
|
|
734
736
|
return data.text;
|
|
@@ -1035,7 +1037,7 @@ Integrate this source into the wiki following the schema above.`;
|
|
|
1035
1037
|
};
|
|
1036
1038
|
}
|
|
1037
1039
|
|
|
1038
|
-
// src/query.
|
|
1040
|
+
// src/query.js
|
|
1039
1041
|
var import_promises8 = require("fs/promises");
|
|
1040
1042
|
var import_node_fs = require("fs");
|
|
1041
1043
|
var import_node_path7 = require("path");
|
|
@@ -1047,9 +1049,7 @@ function assertWithinRoot2(absPath, root) {
|
|
|
1047
1049
|
const resolvedPath = (0, import_node_path7.resolve)(absPath);
|
|
1048
1050
|
const resolvedRoot = (0, import_node_path7.resolve)(root) + "/";
|
|
1049
1051
|
if (!resolvedPath.startsWith(resolvedRoot)) {
|
|
1050
|
-
throw new Error(
|
|
1051
|
-
`Unsafe path rejected: "${absPath}" is outside project root`
|
|
1052
|
-
);
|
|
1052
|
+
throw new Error(`Unsafe path rejected: "${absPath}" is outside project root`);
|
|
1053
1053
|
}
|
|
1054
1054
|
}
|
|
1055
1055
|
async function readFileSafe2(filePath) {
|
|
@@ -1087,10 +1087,7 @@ ${question}
|
|
|
1087
1087
|
## Relevant Wiki Pages
|
|
1088
1088
|
|
|
1089
1089
|
${pagesSection}`;
|
|
1090
|
-
const answer = await llm.complete(
|
|
1091
|
-
[{ role: "user", content: userMessage }],
|
|
1092
|
-
SYSTEM_PROMPT2
|
|
1093
|
-
);
|
|
1090
|
+
const answer = await llm.complete([{ role: "user", content: userMessage }], SYSTEM_PROMPT2);
|
|
1094
1091
|
const sources = pages.map((p) => p.path);
|
|
1095
1092
|
if (options?.save) {
|
|
1096
1093
|
const saveRelPath = options.save;
|
|
@@ -1111,7 +1108,7 @@ Saved to: ${saveRelPath}
|
|
|
1111
1108
|
return { answer, sources };
|
|
1112
1109
|
}
|
|
1113
1110
|
|
|
1114
|
-
// src/lint.
|
|
1111
|
+
// src/lint.js
|
|
1115
1112
|
var import_promises9 = require("fs/promises");
|
|
1116
1113
|
var import_node_path8 = require("path");
|
|
1117
1114
|
async function collectMdFiles2(dir) {
|
|
@@ -1122,7 +1119,8 @@ async function collectMdFiles2(dir) {
|
|
|
1122
1119
|
});
|
|
1123
1120
|
return entries.filter((e) => e.isFile() && e.name.endsWith(".md")).map((e) => (0, import_node_path8.join)(e.parentPath ?? e.path, e.name));
|
|
1124
1121
|
} catch (err) {
|
|
1125
|
-
if (err.code !== "ENOENT")
|
|
1122
|
+
if (err.code !== "ENOENT")
|
|
1123
|
+
throw err;
|
|
1126
1124
|
return [];
|
|
1127
1125
|
}
|
|
1128
1126
|
}
|
|
@@ -1134,7 +1132,8 @@ async function collectSourceFiles(dir) {
|
|
|
1134
1132
|
});
|
|
1135
1133
|
return entries.filter((e) => e.isFile()).map((e) => (0, import_node_path8.join)(e.parentPath ?? e.path, e.name));
|
|
1136
1134
|
} catch (err) {
|
|
1137
|
-
if (err.code !== "ENOENT")
|
|
1135
|
+
if (err.code !== "ENOENT")
|
|
1136
|
+
throw err;
|
|
1138
1137
|
return [];
|
|
1139
1138
|
}
|
|
1140
1139
|
}
|
|
@@ -1159,17 +1158,11 @@ async function lintProject(project) {
|
|
|
1159
1158
|
const relWikiPaths = absWikiFiles.map((f) => (0, import_node_path8.relative)(project.root, f));
|
|
1160
1159
|
const pagesChecked = relWikiPaths.length;
|
|
1161
1160
|
const sourceFiles = await collectSourceFiles(project.sourcesDir);
|
|
1162
|
-
const sourcesChecked = sourceFiles.filter(
|
|
1163
|
-
(f) => (0, import_node_path8.basename)(f) !== ".gitkeep"
|
|
1164
|
-
).length;
|
|
1161
|
+
const sourcesChecked = sourceFiles.filter((f) => (0, import_node_path8.basename)(f) !== ".gitkeep").length;
|
|
1165
1162
|
if (pagesChecked === 0) {
|
|
1166
1163
|
return { issues, pagesChecked: 0, sourcesChecked };
|
|
1167
1164
|
}
|
|
1168
|
-
const pageKeySet = buildPageKeySet(
|
|
1169
|
-
relWikiPaths,
|
|
1170
|
-
project.root,
|
|
1171
|
-
project.wikiDir
|
|
1172
|
-
);
|
|
1165
|
+
const pageKeySet = buildPageKeySet(relWikiPaths, project.root, project.wikiDir);
|
|
1173
1166
|
const db = openDb(project);
|
|
1174
1167
|
let rows;
|
|
1175
1168
|
try {
|
|
@@ -1193,12 +1186,7 @@ async function lintProject(project) {
|
|
|
1193
1186
|
links = [];
|
|
1194
1187
|
}
|
|
1195
1188
|
for (const link of links) {
|
|
1196
|
-
const resolved = resolveLink(
|
|
1197
|
-
link,
|
|
1198
|
-
relWikiPaths,
|
|
1199
|
-
project.root,
|
|
1200
|
-
project.wikiDir
|
|
1201
|
-
);
|
|
1189
|
+
const resolved = resolveLink(link, relWikiPaths, project.root, project.wikiDir);
|
|
1202
1190
|
if (resolved !== null) {
|
|
1203
1191
|
const set = inboundLinks.get(resolved);
|
|
1204
1192
|
if (set) {
|
|
@@ -1219,12 +1207,7 @@ async function lintProject(project) {
|
|
|
1219
1207
|
links = [];
|
|
1220
1208
|
}
|
|
1221
1209
|
for (const link of links) {
|
|
1222
|
-
const resolved = resolveLink(
|
|
1223
|
-
link,
|
|
1224
|
-
relWikiPaths,
|
|
1225
|
-
project.root,
|
|
1226
|
-
project.wikiDir
|
|
1227
|
-
);
|
|
1210
|
+
const resolved = resolveLink(link, relWikiPaths, project.root, project.wikiDir);
|
|
1228
1211
|
if (resolved !== null) {
|
|
1229
1212
|
indexLinks.add(resolved);
|
|
1230
1213
|
}
|
|
@@ -1232,7 +1215,8 @@ async function lintProject(project) {
|
|
|
1232
1215
|
}
|
|
1233
1216
|
}
|
|
1234
1217
|
for (const rp of relWikiPaths) {
|
|
1235
|
-
if ((0, import_node_path8.basename)(rp) === "_index.md")
|
|
1218
|
+
if ((0, import_node_path8.basename)(rp) === "_index.md")
|
|
1219
|
+
continue;
|
|
1236
1220
|
const inbound = inboundLinks.get(rp);
|
|
1237
1221
|
if (!inbound || inbound.size === 0) {
|
|
1238
1222
|
issues.push({
|
|
@@ -1263,7 +1247,8 @@ async function lintProject(project) {
|
|
|
1263
1247
|
}
|
|
1264
1248
|
}
|
|
1265
1249
|
for (const row of rows) {
|
|
1266
|
-
if ((0, import_node_path8.basename)(row.path) === "_index.md")
|
|
1250
|
+
if ((0, import_node_path8.basename)(row.path) === "_index.md")
|
|
1251
|
+
continue;
|
|
1267
1252
|
let links = [];
|
|
1268
1253
|
try {
|
|
1269
1254
|
links = JSON.parse(row.outgoing_links);
|
|
@@ -1283,17 +1268,20 @@ async function lintProject(project) {
|
|
|
1283
1268
|
for (const rp of relWikiPaths) {
|
|
1284
1269
|
const absWikiPage = (0, import_node_path8.join)(project.root, rp);
|
|
1285
1270
|
const relToWikiSources = (0, import_node_path8.relative)(wikiSourcesDir, absWikiPage);
|
|
1286
|
-
if (relToWikiSources.startsWith(".."))
|
|
1271
|
+
if (relToWikiSources.startsWith(".."))
|
|
1272
|
+
continue;
|
|
1287
1273
|
const summaryBasename = (0, import_node_path8.basename)(rp, ".md");
|
|
1288
1274
|
const sourceBasename = summaryBasename.endsWith("-summary") ? summaryBasename.slice(0, -"-summary".length) : summaryBasename;
|
|
1289
1275
|
const matchingSource = sourceFiles.find((sf) => {
|
|
1290
1276
|
const sfBase = (0, import_node_path8.basename)(sf, (0, import_node_path8.extname)(sf));
|
|
1291
1277
|
return sfBase === sourceBasename;
|
|
1292
1278
|
});
|
|
1293
|
-
if (!matchingSource)
|
|
1279
|
+
if (!matchingSource)
|
|
1280
|
+
continue;
|
|
1294
1281
|
try {
|
|
1295
1282
|
const summaryRow = metaMap.get(rp);
|
|
1296
|
-
if (!summaryRow)
|
|
1283
|
+
if (!summaryRow)
|
|
1284
|
+
continue;
|
|
1297
1285
|
const [sourceStat, summaryStat] = await Promise.all([
|
|
1298
1286
|
(0, import_promises9.stat)(matchingSource),
|
|
1299
1287
|
(0, import_promises9.stat)((0, import_node_path8.join)(project.root, summaryRow.path))
|
|
@@ -1311,7 +1299,8 @@ async function lintProject(project) {
|
|
|
1311
1299
|
}
|
|
1312
1300
|
}
|
|
1313
1301
|
for (const rp of relWikiPaths) {
|
|
1314
|
-
if ((0, import_node_path8.basename)(rp) === "_index.md")
|
|
1302
|
+
if ((0, import_node_path8.basename)(rp) === "_index.md")
|
|
1303
|
+
continue;
|
|
1315
1304
|
if (!indexPath) {
|
|
1316
1305
|
continue;
|
|
1317
1306
|
}
|
|
@@ -1332,8 +1321,10 @@ async function lintProject(project) {
|
|
|
1332
1321
|
function resolveLink(link, relPaths, projectRoot, wikiDir) {
|
|
1333
1322
|
for (const rp of relPaths) {
|
|
1334
1323
|
const fname = (0, import_node_path8.basename)(rp, ".md");
|
|
1335
|
-
if (fname === link)
|
|
1336
|
-
|
|
1324
|
+
if (fname === link)
|
|
1325
|
+
return rp;
|
|
1326
|
+
if (rp === link || rp === `${link}.md`)
|
|
1327
|
+
return rp;
|
|
1337
1328
|
const absPath = (0, import_node_path8.join)(projectRoot, rp);
|
|
1338
1329
|
const relToWiki = (0, import_node_path8.relative)(wikiDir, absPath);
|
|
1339
1330
|
if (relToWiki === link || relToWiki.replace(/\.md$/i, "") === link) {
|
|
@@ -1346,15 +1337,18 @@ function isLinkResolvable(link, pageKeySet) {
|
|
|
1346
1337
|
return pageKeySet.has(link);
|
|
1347
1338
|
}
|
|
1348
1339
|
|
|
1349
|
-
// src/log-parser.
|
|
1340
|
+
// src/log-parser.js
|
|
1350
1341
|
function parseLogEntries(content) {
|
|
1351
1342
|
const entries = [];
|
|
1352
1343
|
const sections = content.split(/^(?=## )/m);
|
|
1353
1344
|
for (const section of sections) {
|
|
1354
1345
|
const trimmed = section.trim();
|
|
1355
|
-
if (!trimmed)
|
|
1356
|
-
|
|
1357
|
-
if (
|
|
1346
|
+
if (!trimmed)
|
|
1347
|
+
continue;
|
|
1348
|
+
if (trimmed.startsWith("# "))
|
|
1349
|
+
continue;
|
|
1350
|
+
if (!trimmed.startsWith("## "))
|
|
1351
|
+
continue;
|
|
1358
1352
|
const newlineIdx = trimmed.indexOf("\n");
|
|
1359
1353
|
if (newlineIdx === -1) {
|
|
1360
1354
|
entries.push({ heading: trimmed.slice(3).trim(), body: "" });
|