@equationalapplications/core-llm-wiki 4.17.3 → 4.18.1

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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-D02cdI9A.mjs';
2
- export { E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, O as OntologyConfig, i as OntologyEdgeType, j as OntologyManifest, k as OntologyMode, l as OntologyNodeType, m as OntologyPromptContext, n as OntologyUpdates, P as PromptOverrides, o as PromptService, p as PrunePartialFailureError, V as VectorRanker, q as VectorRankerFallback, r as VectorRankerRankArgs, s as VectorRankerSemanticResult, t as WikiBusyError, u as WikiBusyOperation, v as WikiCheckpoint, w as WikiConfig, x as WikiEdge, y as WikiEvent, z as WikiFact, A as WikiMemoryTestAccess, B as WikiOutboxEvent, C as WikiTask } from './testing-D02cdI9A.mjs';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-BfxdUHg9.mjs';
2
+ export { E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, O as OntologyConfig, i as OntologyEdgeType, j as OntologyManifest, k as OntologyMode, l as OntologyNodeType, m as OntologyPromptContext, n as OntologyUpdates, P as PromptOverrides, o as PromptService, p as PrunePartialFailureError, V as VectorRanker, q as VectorRankerFallback, r as VectorRankerRankArgs, s as VectorRankerSemanticResult, t as WikiBusyError, u as WikiBusyOperation, v as WikiCheckpoint, w as WikiConfig, x as WikiEdge, y as WikiEvent, z as WikiFact, A as WikiMemoryTestAccess, B as WikiOutboxEvent, C as WikiTask } from './testing-BfxdUHg9.mjs';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
  import 'minisearch';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-D02cdI9A.js';
2
- export { E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, O as OntologyConfig, i as OntologyEdgeType, j as OntologyManifest, k as OntologyMode, l as OntologyNodeType, m as OntologyPromptContext, n as OntologyUpdates, P as PromptOverrides, o as PromptService, p as PrunePartialFailureError, V as VectorRanker, q as VectorRankerFallback, r as VectorRankerRankArgs, s as VectorRankerSemanticResult, t as WikiBusyError, u as WikiBusyOperation, v as WikiCheckpoint, w as WikiConfig, x as WikiEdge, y as WikiEvent, z as WikiFact, A as WikiMemoryTestAccess, B as WikiOutboxEvent, C as WikiTask } from './testing-D02cdI9A.js';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-BfxdUHg9.js';
2
+ export { E as EntityStatus, d as ExtractedFact, e as ExtractedFactEdge, f as ExtractedFactWithOntology, g as ExtractedTask, h as GraphTraversalOptions, H as HOOK_TIMEOUT_MARKER, L as LLMProvider, O as OntologyConfig, i as OntologyEdgeType, j as OntologyManifest, k as OntologyMode, l as OntologyNodeType, m as OntologyPromptContext, n as OntologyUpdates, P as PromptOverrides, o as PromptService, p as PrunePartialFailureError, V as VectorRanker, q as VectorRankerFallback, r as VectorRankerRankArgs, s as VectorRankerSemanticResult, t as WikiBusyError, u as WikiBusyOperation, v as WikiCheckpoint, w as WikiConfig, x as WikiEdge, y as WikiEvent, z as WikiFact, A as WikiMemoryTestAccess, B as WikiOutboxEvent, C as WikiTask } from './testing-BfxdUHg9.js';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
  import 'minisearch';
5
5
 
package/dist/index.js CHANGED
@@ -5205,6 +5205,7 @@ function formatMemoryDump(dump) {
5205
5205
  files
5206
5206
  };
5207
5207
  }
5208
+ var LLM_WIKI_PROFILE = "llm-wiki/1";
5208
5209
  function factFrontmatter(f) {
5209
5210
  return {
5210
5211
  type: f.okf_type ?? "fact",
@@ -5240,30 +5241,61 @@ function taskFrontmatter(t) {
5240
5241
  function formatLogDate(timestampMs) {
5241
5242
  return new Date(timestampMs).toISOString().slice(0, 10);
5242
5243
  }
5244
+ function conceptRelativePath(sourceFilePath, targetFilePath) {
5245
+ const sourceDir = sourceFilePath.slice(0, sourceFilePath.lastIndexOf("/"));
5246
+ const targetDir = targetFilePath.slice(0, targetFilePath.lastIndexOf("/"));
5247
+ const targetName = targetFilePath.slice(targetFilePath.lastIndexOf("/") + 1);
5248
+ if (sourceDir === targetDir) return `./${targetName}`;
5249
+ if (sourceDir.endsWith("/facts") && targetDir.endsWith("/tasks")) return `../tasks/${targetName}`;
5250
+ if (sourceDir.endsWith("/tasks") && targetDir.endsWith("/facts")) return `../facts/${targetName}`;
5251
+ return targetFilePath.replace(/^entities\/[^/]+\//, "");
5252
+ }
5243
5253
  function buildEventLogEntries(events, factIdToFilename) {
5244
5254
  return events.map((e) => {
5245
5255
  const factFilename = e.related_entry_id ? factIdToFilename.get(e.related_entry_id) : void 0;
5246
5256
  const summary = e.summary.replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]").replace(/\r?\n/g, " ");
5247
5257
  const text = factFilename ? `(${e.event_type}) [${summary}](./facts/${factFilename}.md)` : `(${e.event_type}) ${summary}`;
5248
- return { date: formatLogDate(e.created_at), text };
5258
+ return { date: formatLogDate(e.created_at), text: coreOkf.appendEventIdComment(text, e.id) };
5249
5259
  });
5250
5260
  }
5251
5261
  function formatOkfBundle(dump) {
5252
5262
  const files = [];
5253
5263
  const rootEntries = [];
5254
5264
  for (const [entityId, bundle] of Object.entries(dump.entities)) {
5265
+ let relatedLinksFor2 = function(sourcePath, sourceId) {
5266
+ return (edgesBySource.get(sourceId) ?? []).map((edge) => {
5267
+ const targetPath = idToConceptPath.get(edge.target_id);
5268
+ if (!targetPath) return null;
5269
+ return { edge_type: edge.edge_type, path: conceptRelativePath(sourcePath, targetPath) };
5270
+ }).filter((link) => link != null);
5271
+ };
5255
5272
  const dir = sanitizeForFilename(entityId);
5256
5273
  const factIdToFilename = new Map(
5257
5274
  bundle.facts.map((f) => [f.id, sanitizeConceptId(f.id)])
5258
5275
  );
5276
+ const idToConceptPath = /* @__PURE__ */ new Map();
5277
+ for (const f of bundle.facts) {
5278
+ idToConceptPath.set(f.id, `entities/${dir}/facts/${factIdToFilename.get(f.id)}.md`);
5279
+ }
5280
+ for (const t of bundle.tasks) {
5281
+ idToConceptPath.set(t.id, `entities/${dir}/tasks/${sanitizeConceptId(t.id)}.md`);
5282
+ }
5283
+ const edgesBySource = /* @__PURE__ */ new Map();
5284
+ for (const edge of bundle.edges ?? []) {
5285
+ const group = edgesBySource.get(edge.source_id) ?? [];
5286
+ group.push(edge);
5287
+ edgesBySource.set(edge.source_id, group);
5288
+ }
5259
5289
  const factEntries = bundle.facts.map((f) => ({
5260
5290
  path: `facts/${factIdToFilename.get(f.id)}.md`,
5261
5291
  title: f.title
5262
5292
  }));
5263
5293
  for (const f of bundle.facts) {
5294
+ const factPath = `entities/${dir}/facts/${factIdToFilename.get(f.id)}.md`;
5295
+ const factBody = coreOkf.appendRelatedSection(f.body, relatedLinksFor2(factPath, f.id));
5264
5296
  files.push({
5265
- path: `entities/${dir}/facts/${factIdToFilename.get(f.id)}.md`,
5266
- content: coreOkf.buildConceptDocument(factFrontmatter(f), f.body)
5297
+ path: factPath,
5298
+ content: coreOkf.buildConceptDocument(factFrontmatter(f), factBody)
5267
5299
  });
5268
5300
  }
5269
5301
  const taskEntries = bundle.tasks.map((t) => ({
@@ -5271,9 +5303,11 @@ function formatOkfBundle(dump) {
5271
5303
  title: t.description
5272
5304
  }));
5273
5305
  for (const t of bundle.tasks) {
5306
+ const taskPath = `entities/${dir}/tasks/${sanitizeConceptId(t.id)}.md`;
5307
+ const taskBody = coreOkf.appendRelatedSection("", relatedLinksFor2(taskPath, t.id));
5274
5308
  files.push({
5275
- path: `entities/${dir}/tasks/${sanitizeConceptId(t.id)}.md`,
5276
- content: coreOkf.buildConceptDocument(taskFrontmatter(t), "")
5309
+ path: taskPath,
5310
+ content: coreOkf.buildConceptDocument(taskFrontmatter(t), taskBody)
5277
5311
  });
5278
5312
  }
5279
5313
  files.push({
@@ -5286,8 +5320,10 @@ function formatOkfBundle(dump) {
5286
5320
  ];
5287
5321
  files.push({
5288
5322
  path: `entities/${dir}/index.md`,
5289
- content: `${coreOkf.buildIndexMd(entityIndexSections)}[Event log](./log.md)
5290
- `
5323
+ content: coreOkf.buildEntityIndexMd({
5324
+ summary: bundle.summary,
5325
+ sections: entityIndexSections
5326
+ })
5291
5327
  });
5292
5328
  rootEntries.push({ path: `entities/${dir}/index.md`, title: entityId });
5293
5329
  }
@@ -5295,7 +5331,8 @@ function formatOkfBundle(dump) {
5295
5331
  path: "index.md",
5296
5332
  content: coreOkf.buildRootIndexMd(
5297
5333
  "0.1",
5298
- rootEntries.length > 0 ? [{ heading: "Entities", entries: rootEntries }] : []
5334
+ rootEntries.length > 0 ? [{ heading: "Entities", entries: rootEntries }] : [],
5335
+ { profile: LLM_WIKI_PROFILE }
5299
5336
  )
5300
5337
  });
5301
5338
  return { files };
@@ -5340,6 +5377,14 @@ function resolveRelativePath(fromFile, linkPath) {
5340
5377
  }
5341
5378
  return resolved.join("/");
5342
5379
  }
5380
+ function decodeLinkPath(path) {
5381
+ if (!path.includes("%")) return path;
5382
+ try {
5383
+ return decodeURIComponent(path);
5384
+ } catch {
5385
+ return path;
5386
+ }
5387
+ }
5343
5388
  function addPathAliases(map, filePath, resolvedId) {
5344
5389
  map.set(filePath, resolvedId);
5345
5390
  const withoutDot = filePath.replace(/^\.\//, "");
@@ -5437,10 +5482,56 @@ function frontmatterToTask(entityId, id, frontmatter, now) {
5437
5482
  function findLogMdPath(files) {
5438
5483
  return files.find((f) => f.path.endsWith("/log.md") || f.path === "log.md")?.path;
5439
5484
  }
5485
+ function extractEdgesFromLinks(filePath, resolvedId, links, pathToResolvedId, entityId, now, seenEdges, edges) {
5486
+ for (const link of links) {
5487
+ const strippedPath = stripLinkSuffix(decodeLinkPath(link.path));
5488
+ const directTargetId = lookupResolvedId(pathToResolvedId, strippedPath);
5489
+ const resolvedTargetPath = resolveRelativePath(filePath, strippedPath);
5490
+ if (isStructuralPath(strippedPath) || isStructuralPath(resolvedTargetPath)) continue;
5491
+ const targetId = directTargetId ?? lookupResolvedId(pathToResolvedId, resolvedTargetPath);
5492
+ if (!targetId) continue;
5493
+ const edgeKey = `${resolvedId}\0${targetId}\0${link.text}`;
5494
+ if (seenEdges.has(edgeKey)) continue;
5495
+ seenEdges.add(edgeKey);
5496
+ edges.push({
5497
+ id: generateId(),
5498
+ entity_id: entityId,
5499
+ source_id: resolvedId,
5500
+ target_id: targetId,
5501
+ edge_type: link.text,
5502
+ created_at: now
5503
+ });
5504
+ }
5505
+ }
5440
5506
  function parseOkfBundle(entityId, files, options) {
5441
5507
  const now = Date.now();
5508
+ const normalizeOkfPath = (p) => p.replace(/^\.\//, "").replace(/\\/g, "/");
5509
+ const normalizedFiles = files.map((f) => ({ ...f, path: normalizeOkfPath(f.path) }));
5510
+ const allowlistedFiles = normalizedFiles.filter((f) => coreOkf.isAllowedOkfPath(f.path));
5511
+ const entityDirs = new Set(
5512
+ allowlistedFiles.map((f) => /^entities\/([^/]+)\//.exec(f.path)?.[1]).filter((dir) => !!dir)
5513
+ );
5514
+ if (entityDirs.size > 1) {
5515
+ throw new Error(
5516
+ `parseOkfBundle: expected a single-entity bundle for "${entityId}", found entities: ${Array.from(entityDirs).join(", ")}`
5517
+ );
5518
+ }
5519
+ const entityDir = entityDirs.values().next().value ?? entityId;
5520
+ const entityPrefix = `entities/${entityDir}/`;
5521
+ const allowedFiles = allowlistedFiles.filter(
5522
+ (f) => f.path === "index.md" || f.path.startsWith(entityPrefix)
5523
+ );
5524
+ const rootIndex = allowedFiles.find((f) => f.path === "index.md");
5525
+ const profileMeta = rootIndex ? coreOkf.parseRootIndexMd(rootIndex.content) : {};
5526
+ const isProfile1 = profileMeta.profile === "llm-wiki/1";
5527
+ let entitySummary;
5528
+ const entityIndex = allowedFiles.find((f) => f.path === `${entityPrefix}index.md`);
5529
+ if (isProfile1 && entityIndex) {
5530
+ const summary = coreOkf.parseEntityIndexMd(entityIndex.content).summary;
5531
+ entitySummary = summary || void 0;
5532
+ }
5442
5533
  const pathToResolvedId = /* @__PURE__ */ new Map();
5443
- for (const file of files) {
5534
+ for (const file of allowedFiles) {
5444
5535
  if (!isConceptFile(file.path)) continue;
5445
5536
  const { frontmatter } = coreOkf.parseConcept(file.content);
5446
5537
  const route = resolveRoute(file.path, frontmatter.type ?? "", options);
@@ -5452,8 +5543,8 @@ function parseOkfBundle(entityId, files, options) {
5452
5543
  const tasks = [];
5453
5544
  const edges = [];
5454
5545
  let logContent = null;
5455
- const logMdPath = findLogMdPath(files);
5456
- for (const file of files) {
5546
+ const logMdPath = findLogMdPath(allowedFiles);
5547
+ for (const file of allowedFiles) {
5457
5548
  if (file.path.endsWith("/log.md") || file.path === "log.md") {
5458
5549
  logContent = file.content;
5459
5550
  continue;
@@ -5463,41 +5554,38 @@ function parseOkfBundle(entityId, files, options) {
5463
5554
  const route = resolveRoute(file.path, frontmatter.type ?? "", options);
5464
5555
  if (route === "ignore") continue;
5465
5556
  const resolvedId = typeof frontmatter.id === "string" && frontmatter.id ? frontmatter.id : basenameMd(file.path);
5557
+ const { body: storedBody, relatedLinks } = coreOkf.splitRelatedSection(body);
5558
+ const edgeLinks = isProfile1 ? relatedLinks : [...relatedLinks, ...coreOkf.extractMarkdownLinks(storedBody)];
5466
5559
  if (route === "fact") {
5467
- facts.push(frontmatterToFact(entityId, resolvedId, frontmatter, body, now));
5560
+ facts.push(frontmatterToFact(entityId, resolvedId, frontmatter, storedBody, now));
5468
5561
  } else {
5469
5562
  tasks.push(frontmatterToTask(entityId, resolvedId, frontmatter, now));
5470
5563
  }
5471
5564
  const seenEdges = /* @__PURE__ */ new Set();
5472
- for (const link of coreOkf.extractMarkdownLinks(body)) {
5473
- const strippedPath = stripLinkSuffix(link.path);
5474
- const directTargetId = lookupResolvedId(pathToResolvedId, strippedPath);
5475
- const resolvedTargetPath = resolveRelativePath(file.path, strippedPath);
5476
- if (isStructuralPath(strippedPath) || isStructuralPath(resolvedTargetPath)) continue;
5477
- const targetId = directTargetId ?? lookupResolvedId(pathToResolvedId, resolvedTargetPath);
5478
- if (!targetId) continue;
5479
- const edgeKey = `${resolvedId}\0${targetId}\0${link.text}`;
5480
- if (seenEdges.has(edgeKey)) continue;
5481
- seenEdges.add(edgeKey);
5482
- edges.push({
5483
- id: generateId(),
5484
- entity_id: entityId,
5485
- source_id: resolvedId,
5486
- target_id: targetId,
5487
- edge_type: link.text,
5488
- created_at: now
5489
- });
5490
- }
5565
+ extractEdgesFromLinks(
5566
+ file.path,
5567
+ resolvedId,
5568
+ edgeLinks,
5569
+ pathToResolvedId,
5570
+ entityId,
5571
+ now,
5572
+ seenEdges,
5573
+ edges
5574
+ );
5491
5575
  }
5492
5576
  const events = [];
5493
5577
  if (logContent != null) {
5494
5578
  const logPath = logMdPath ?? `entities/${entityId}/log.md`;
5495
5579
  for (const entry of coreOkf.parseLogMd(logContent)) {
5496
- const parsed = parseLogEntryText(entry.text);
5580
+ const { text, eventId } = coreOkf.parseEventIdComment(entry.text);
5581
+ const parsed = parseLogEntryText(text);
5497
5582
  if (!parsed) continue;
5498
5583
  let related_entry_id = null;
5499
5584
  if (parsed.linkPath) {
5500
- const targetPath = resolveRelativePath(logPath, stripLinkSuffix(parsed.linkPath));
5585
+ const targetPath = resolveRelativePath(
5586
+ logPath,
5587
+ stripLinkSuffix(decodeLinkPath(parsed.linkPath))
5588
+ );
5501
5589
  if (!isStructuralPath(targetPath) && targetPath.includes("/facts/")) {
5502
5590
  related_entry_id = lookupResolvedId(pathToResolvedId, targetPath) ?? null;
5503
5591
  }
@@ -5505,7 +5593,7 @@ function parseOkfBundle(entityId, files, options) {
5505
5593
  const created_at = (/* @__PURE__ */ new Date(`${entry.date}T00:00:00.000Z`)).getTime();
5506
5594
  if (!Number.isFinite(created_at)) continue;
5507
5595
  events.push({
5508
- id: generateId("evt_"),
5596
+ id: eventId ?? generateId("evt_"),
5509
5597
  entity_id: entityId,
5510
5598
  event_type: parsed.event_type,
5511
5599
  summary: parsed.summary,
@@ -5517,7 +5605,7 @@ function parseOkfBundle(entityId, files, options) {
5517
5605
  return {
5518
5606
  generatedAt: now,
5519
5607
  entities: {
5520
- [entityId]: { facts, tasks, events, edges }
5608
+ [entityId]: { facts, tasks, events, edges, summary: entitySummary }
5521
5609
  }
5522
5610
  };
5523
5611
  }