@tangle-network/agent-knowledge 6.2.0 → 7.0.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +1 -1
  3. package/dist/benchmarks/index.d.ts +1 -1
  4. package/dist/benchmarks/index.js +1 -1
  5. package/dist/{benchmarks-CmW6iORW.js → benchmarks-C8L7HJb4.js} +2 -2
  6. package/dist/{benchmarks-CmW6iORW.js.map → benchmarks-C8L7HJb4.js.map} +1 -1
  7. package/dist/cli.js +1 -1
  8. package/dist/{ids-DRqPZ42_.js → ids-Bevz_pXV.js} +6 -2
  9. package/dist/ids-Bevz_pXV.js.map +1 -0
  10. package/dist/{index-3z3lFJnE.d.ts → index-D0wc4GYg.d.ts} +2 -2
  11. package/dist/{index-3z3lFJnE.d.ts.map → index-D0wc4GYg.d.ts.map} +1 -1
  12. package/dist/{index-DHebFLgU.d.ts → index-Dwp3Mx-w.d.ts} +3 -3
  13. package/dist/{index-DHebFLgU.d.ts.map → index-Dwp3Mx-w.d.ts.map} +1 -1
  14. package/dist/index.d.ts +42 -16
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +86 -35
  17. package/dist/index.js.map +1 -1
  18. package/dist/{inspect-LUMkas6A.js → inspect-CJQGYuKa.js} +156 -33
  19. package/dist/inspect-CJQGYuKa.js.map +1 -0
  20. package/dist/memory/index.d.ts +2 -2
  21. package/dist/memory/index.js +2 -2
  22. package/dist/{memory-C6KPRhoU.js → memory-CIYRB_Q8.js} +3 -3
  23. package/dist/{memory-C6KPRhoU.js.map → memory-CIYRB_Q8.js.map} +1 -1
  24. package/dist/sources/index.js +1 -1
  25. package/dist/{types-Cd57BPRt.d.ts → types-BOfmvDe-.d.ts} +21 -6
  26. package/dist/{types-Cd57BPRt.d.ts.map → types-BOfmvDe-.d.ts.map} +1 -1
  27. package/dist/viz/index.d.ts +1 -1
  28. package/docs/architecture.md +4 -2
  29. package/package.json +1 -1
  30. package/dist/ids-DRqPZ42_.js.map +0 -1
  31. package/dist/inspect-LUMkas6A.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { $ as SCAFFOLD_PAGE_BASENAMES, A as KnowledgePageSchema, At as withSafeDirectory, B as assertResearchClaimLedgerIntegrity, C as assertClaimLedgerId, Ct as listRegularFilesWithinRoot, D as KnowledgeGraphEdgeSchema, Dt as renameDurable, E as KnowledgeEventSchema, Et as removeDurable, F as SourceRecordSchema, Ft as mediaTypeFor, G as deepQuestionId, H as claimEvidenceId, I as KNOWLEDGE_EVENT_TYPES, It as textSourceAdapter, J as materializeRegisteredClaimEvidence, K as emptyClaimLedger, L as ClaimLedgerGoalConflictError, M as ResearchClaimLedgerSchema, Mt as writeFileDurableWithinRoot, N as ResearchClaimRecordSchema, Nt as writeJsonDurable, O as KnowledgeGraphNodeSchema, Ot as syncDirectory, P as SourceAnchorSchema, Pt as writeJsonDurableWithinRoot, Q as buildKnowledgeGraph, R as assertDeepQuestionIntegrity, S as MemoryKbStore, St as isMissingFile, T as KnowledgeBaseCandidateSchema, Tt as readRegularFileWithinRoot, U as claimId, V as assertTrackedClaimIntegrity, W as claimSourceHost, X as mergeTrackedClaims, Y as mergeClaimLedgers, Z as normalizeClaimText, _ as FileSystemKbStore, _t as finishKnowledgeFileTransaction, a as applyKnowledgeWriteBlocksFile, at as WIKILINK_REGEX, b as KB_INDEX_PATH, bt as rollbackKnowledgeFileTransaction, c as validateKnowledgeIndex, ct as formatFrontmatter, d as writeKnowledgeIndex, dt as inspectPendingKnowledgeMutation, et as initKnowledgeBase, f as addSourcePath, ft as recoverPendingKnowledgeMutation, g as writeSourceRegistry, gt as assertKnowledgeMutationPath, h as sourceRegistryPath, ht as applyKnowledgeFileTransaction, i as applyKnowledgeWriteBlocks, it as writeJson, j as ResearchClaimEvidenceSchema, jt as writeFileDurable, k as KnowledgeIndexSchema, kt as withSafeDescendant, l as lintKnowledgeIndex, lt as parseFrontmatter, m as loadSourceRegistry, mt as withKnowledgeRead, n as inspectKnowledgeIndex, nt as layoutFor, o as isSafeKnowledgePath, ot as extractWikilinks, p as addSourceText, pt as withKnowledgeMutation, q as linkClaimContradictions, r as stringMetadata, rt as loadKnowledgePages, s as parseKnowledgeWriteBlocks, st as normalizeLinkTarget, t as explainKnowledgeTarget, tt as isScaffoldPath, u as buildKnowledgeIndex, ut as acquireDurableFileLock, v as KB_CLAIM_LEDGER_DIR, vt as knowledgeFileTransactionPlanHash, w as DeepQuestionSchema, wt as readRegularFileNoFollow, x as KB_STORE_DIR, xt as isKernelAnchoredPath, y as KB_EVENTS_PATH, yt as prepareKnowledgeFileTransaction, z as assertResearchClaimEvidenceIntegrity } from "./inspect-LUMkas6A.js";
2
- import { n as slugify, r as stableId, t as sha256 } from "./ids-DRqPZ42_.js";
3
- import { A as assertImmutableRef, C as resetRetrievalHoldoutRegistry, D as jsonObjectCandidateCodec, E as jsonCandidateCodec, O as runSerializedKnowledgeOptimization, S as emitRetrievalHoldoutBypass, T as toOffPolicyTrajectory, _ as defaultGetMemoryContext, a as createNeo4jAgentMemoryAdapter, b as applySessionStickyRetrievalHoldout, c as runAgentMemoryImprovement, d as runAgentMemoryExperiment, f as agentMemorySequenceJudge, g as forkAgentMemoryBranchSnapshot, h as createAgentMemoryBranch, i as AgentMemoryWriteInputSchema, k as scenarioContentFingerprint, l as createGraphitiMemoryAdapter, m as buildAgentMemorySequencesFromBenchmarkCases, n as AgentMemoryKindSchema, o as createMem0MemoryAdapter, p as buildAgentMemorySequenceScenarios, r as AgentMemoryScopeSchema, s as mem0MemoryAdapterIdentity, t as AgentMemoryHitSchema, u as graphitiMemoryAdapterIdentity, v as renderMemoryContext, w as retrievalHoldoutConfigHash, x as deterministicRng, y as applyRetrievalHoldout } from "./memory-C6KPRhoU.js";
1
+ import { $ as mergeTrackedClaims, A as KnowledgeGraphNodeSchema, At as removeDurable, B as ClaimLedgerGoalConflictError, Bt as textSourceAdapter, C as KB_STORE_DIR, Ct as prepareKnowledgeFileTransaction, D as KnowledgeBaseCandidateSchema, Dt as listRegularFilesWithinRoot, E as DeepQuestionSchema, Et as isMissingFile, F as ResearchClaimRecordSchema, Ft as writeFileDurable, G as claimEvidenceId, H as assertResearchClaimEvidenceIntegrity, I as ResearchSourceVersionSchema, It as writeFileDurableWithinRoot, J as deepQuestionId, K as claimId, L as SourceAnchorSchema, Lt as writeJsonDurable, M as KnowledgePageSchema, Mt as syncDirectory, N as ResearchClaimEvidenceSchema, Nt as withSafeDescendant, O as KnowledgeEventSchema, Ot as readRegularFileNoFollow, P as ResearchClaimLedgerSchema, Pt as withSafeDirectory, Q as mergeClaimLedgers, R as SourceRecordSchema, Rt as writeJsonDurableWithinRoot, S as KB_INDEX_PATH, St as knowledgeFileTransactionPlanHash, T as assertClaimLedgerId, Tt as isKernelAnchoredPath, U as assertResearchClaimLedgerIntegrity, V as assertDeepQuestionIntegrity, W as assertTrackedClaimIntegrity, X as linkClaimContradictions, Y as emptyClaimLedger, Z as materializeRegisteredClaimEvidence, _ as writeSourceRegistry, _t as withKnowledgeMutation, a as applyKnowledgeWriteBlocksFile, at as isScaffoldPath, b as KB_CLAIM_LEDGER_DIR, bt as assertKnowledgeMutationPath, c as validateKnowledgeIndex, ct as writeJson, d as writeKnowledgeIndex, dt as normalizeLinkTarget, et as normalizeClaimText, f as addSourcePath, ft as formatFrontmatter, g as sourceRegistryPath, gt as recoverPendingKnowledgeMutation, h as snapshotSourceTextInput, ht as inspectPendingKnowledgeMutation, i as applyKnowledgeWriteBlocks, it as initKnowledgeBase, j as KnowledgeIndexSchema, jt as renameDurable, k as KnowledgeGraphEdgeSchema, kt as readRegularFileWithinRoot, l as lintKnowledgeIndex, lt as WIKILINK_REGEX, m as loadSourceRegistry, mt as acquireDurableFileLock, n as inspectKnowledgeIndex, nt as buildKnowledgeGraph, o as isSafeKnowledgePath, ot as layoutFor, p as addSourceText, pt as parseFrontmatter, q as claimSourceHost, r as stringMetadata, rt as SCAFFOLD_PAGE_BASENAMES, s as parseKnowledgeWriteBlocks, st as loadKnowledgePages, t as explainKnowledgeTarget, tt as researchSourceVersionKey, u as buildKnowledgeIndex, ut as extractWikilinks, v as ClaimLedgerMigrationRequiredError, vt as withKnowledgeRead, w as MemoryKbStore, wt as rollbackKnowledgeFileTransaction, x as KB_EVENTS_PATH, xt as finishKnowledgeFileTransaction, y as FileSystemKbStore, yt as applyKnowledgeFileTransaction, z as KNOWLEDGE_EVENT_TYPES, zt as mediaTypeFor } from "./inspect-CJQGYuKa.js";
2
+ import { i as textSourceId, n as slugify, r as stableId, t as sha256 } from "./ids-Bevz_pXV.js";
3
+ import { A as assertImmutableRef, C as resetRetrievalHoldoutRegistry, D as jsonObjectCandidateCodec, E as jsonCandidateCodec, O as runSerializedKnowledgeOptimization, S as emitRetrievalHoldoutBypass, T as toOffPolicyTrajectory, _ as defaultGetMemoryContext, a as createNeo4jAgentMemoryAdapter, b as applySessionStickyRetrievalHoldout, c as runAgentMemoryImprovement, d as runAgentMemoryExperiment, f as agentMemorySequenceJudge, g as forkAgentMemoryBranchSnapshot, h as createAgentMemoryBranch, i as AgentMemoryWriteInputSchema, k as scenarioContentFingerprint, l as createGraphitiMemoryAdapter, m as buildAgentMemorySequencesFromBenchmarkCases, n as AgentMemoryKindSchema, o as createMem0MemoryAdapter, p as buildAgentMemorySequenceScenarios, r as AgentMemoryScopeSchema, s as mem0MemoryAdapterIdentity, t as AgentMemoryHitSchema, u as graphitiMemoryAdapterIdentity, v as renderMemoryContext, w as retrievalHoldoutConfigHash, x as deterministicRng, y as applyRetrievalHoldout } from "./memory-CIYRB_Q8.js";
4
4
  import { n as searchKnowledge, r as tokenizeQuery, t as reciprocalRankFusion } from "./search-CP0QtBJZ.js";
5
- import { A as INDUSTRY_RAG_BENCHMARKS, B as memoryWriteResultToSourceRecord, F as respondToIndustryRagBenchmarkSmokeCase, G as retrievalRecallJudge, H as partitionRetrievalScenarios, I as isKnowledgeMemoryBenchmarkCase, K as scoreRetrievalArtifact, L as createInMemoryBenchmarkAdapter, M as buildIndustryMemoryBenchmarkSmokeCases, N as buildIndustryRagBenchmarkSmokeCases, P as respondToIndustryMemoryBenchmarkSmokeCase, R as createNoopMemoryBenchmarkAdapter, U as retrievalConfigFromSurface, V as buildRetrievalEvalDispatch, W as retrievalConfigSurface, _ as memoryRecoveryDelayMs, a as buildKnowledgeBenchmarkScenarios, b as runBoundedMemoryLifecycle, c as runKnowledgeBenchmarkSuite, d as summarizeKnowledgeBenchmarkCampaign, f as acquireAgentMemoryRunLease, g as createMemoryExecutionPool, h as DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, i as runMemoryAdapterBenchmark, j as buildFirstPartyMemoryLifecycleBenchmarkCases, k as INDUSTRY_MEMORY_BENCHMARKS, l as scoreKnowledgeBenchmarkArtifact, m as AgentMemoryLifecycleUnsafeError, n as parseKnowledgeBenchmarkJsonl, o as knowledgeBenchmarkJudge, p as AgentMemoryLifecycleTimeoutError, r as parseKnowledgeBenchmarkQrels, s as renderKnowledgeBenchmarkReportMarkdown, t as buildRetrievalBenchmarkCasesFromQrels, u as scoreMemoryBenchmarkArtifact, x as sleepForMemoryRecovery, y as resolveMemoryCleanupTimeoutMs, z as memoryHitToSourceRecord } from "./benchmarks-CmW6iORW.js";
5
+ import { A as INDUSTRY_RAG_BENCHMARKS, B as memoryWriteResultToSourceRecord, F as respondToIndustryRagBenchmarkSmokeCase, G as retrievalRecallJudge, H as partitionRetrievalScenarios, I as isKnowledgeMemoryBenchmarkCase, K as scoreRetrievalArtifact, L as createInMemoryBenchmarkAdapter, M as buildIndustryMemoryBenchmarkSmokeCases, N as buildIndustryRagBenchmarkSmokeCases, P as respondToIndustryMemoryBenchmarkSmokeCase, R as createNoopMemoryBenchmarkAdapter, U as retrievalConfigFromSurface, V as buildRetrievalEvalDispatch, W as retrievalConfigSurface, _ as memoryRecoveryDelayMs, a as buildKnowledgeBenchmarkScenarios, b as runBoundedMemoryLifecycle, c as runKnowledgeBenchmarkSuite, d as summarizeKnowledgeBenchmarkCampaign, f as acquireAgentMemoryRunLease, g as createMemoryExecutionPool, h as DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, i as runMemoryAdapterBenchmark, j as buildFirstPartyMemoryLifecycleBenchmarkCases, k as INDUSTRY_MEMORY_BENCHMARKS, l as scoreKnowledgeBenchmarkArtifact, m as AgentMemoryLifecycleUnsafeError, n as parseKnowledgeBenchmarkJsonl, o as knowledgeBenchmarkJudge, p as AgentMemoryLifecycleTimeoutError, r as parseKnowledgeBenchmarkQrels, s as renderKnowledgeBenchmarkReportMarkdown, t as buildRetrievalBenchmarkCasesFromQrels, u as scoreMemoryBenchmarkArtifact, x as sleepForMemoryRecovery, y as resolveMemoryCleanupTimeoutMs, z as memoryHitToSourceRecord } from "./benchmarks-C8L7HJb4.js";
6
6
  import { IRS_DIMENSION_HINTS, MAX_RESPONSE_BYTES, MIN_REQUEST_GAP_MS, POLITE_USER_AGENT, __resetHttpThrottle, createCornellLiiSource, createIrsPublicationsSource, createStateSosSource, extractLinks, firstMatch, htmlToText, innerHtmlById, looksLikeBlockPage, politeFetch } from "./sources/index.js";
7
7
  import { createHash } from "node:crypto";
8
8
  import { cp, lstat, mkdir, mkdtemp, readFile, rm, stat } from "node:fs/promises";
@@ -5105,7 +5105,8 @@ async function runVerifiedResearchLoop(options) {
5105
5105
  const accepted = [];
5106
5106
  const rejectedWorkerSources = [];
5107
5107
  const existingUris = new Set(index.sources.flatMap((source) => typeof source.metadata?.originalUri === "string" ? [source.metadata.originalUri] : []));
5108
- for (const source of workerContribution.sources ?? []) {
5108
+ for (const proposedSource of workerContribution.sources ?? []) {
5109
+ const source = snapshotSourceTextInput(proposedSource);
5109
5110
  if (isDuplicate(source, existingUris, accepted)) {
5110
5111
  rejectedWorkerSources.push({
5111
5112
  source,
@@ -5235,14 +5236,17 @@ function isDuplicate(source, existingUris, accepted) {
5235
5236
  }
5236
5237
  async function registerSources(options, sources) {
5237
5238
  const records = [];
5238
- for (const source of sources) records.push(await addSourceText(options.root, source, options.sourceOptions));
5239
+ for (const candidate of sources) {
5240
+ const source = snapshotSourceTextInput(candidate);
5241
+ records.push(await addSourceText(options.root, source, options.sourceOptions));
5242
+ }
5239
5243
  return records;
5240
5244
  }
5241
5245
  async function confirmRegisteredSources(driver, sources) {
5242
5246
  if (!driver.commitSources) return;
5243
- const originalUris = sources.flatMap((source) => typeof source.metadata?.originalUri === "string" ? [source.metadata.originalUri] : []);
5244
- if (originalUris.length === 0) return;
5245
- await driver.commitSources([...new Set(originalUris)].sort());
5247
+ const textSources = sources.filter((source) => typeof source.metadata?.originalUri === "string");
5248
+ if (textSources.length === 0) return;
5249
+ await driver.commitSources(textSources);
5246
5250
  }
5247
5251
  /**
5248
5252
  * Apply a contribution's curated pages. Static `proposalText` plus a
@@ -5842,7 +5846,7 @@ function buildDriver(options, persistence, restored) {
5842
5846
  const deterministicFallback = options.deterministicFallback ?? true;
5843
5847
  const claims = new Map((restored?.claims ?? []).map((claim) => [claim.id, fromRecord(claim)]));
5844
5848
  const claimEvidence = new Map((restored?.claimEvidence ?? []).map((evidence) => [evidence.id, evidence]));
5845
- const registeredSourceUris = new Set(restored?.registeredSourceUris ?? []);
5849
+ const registeredSources = new Map((restored?.registeredSources ?? []).map((source) => [source.sourceId, source]));
5846
5850
  const questions = new Map((restored?.questions ?? []).map((question) => [question.id, question]));
5847
5851
  let rounds = restored?.rounds ?? 0;
5848
5852
  let preparedRounds = Math.max(rounds, restored?.preparedRounds ?? rounds);
@@ -5854,13 +5858,14 @@ function buildDriver(options, persistence, restored) {
5854
5858
  }
5855
5859
  function toLedger() {
5856
5860
  return {
5861
+ schemaVersion: 2,
5857
5862
  id: persistence?.ledgerId ?? "in-memory",
5858
5863
  ...goal === void 0 ? {} : { goal },
5859
5864
  updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
5860
5865
  rounds,
5861
5866
  ...preparedRounds > rounds ? { preparedRounds } : {},
5862
5867
  claimEvidence: [...claimEvidence.values()].sort((left, right) => left.id.localeCompare(right.id)),
5863
- registeredSourceUris: [...registeredSourceUris].sort(),
5868
+ registeredSources: [...registeredSources.values()].sort((left, right) => left.sourceId.localeCompare(right.sourceId)),
5864
5869
  claims: [...claims.values()].map((claim) => ({
5865
5870
  ...claim,
5866
5871
  supportingHosts: [...new Set(claim.supportingHosts)].sort(),
@@ -5894,8 +5899,8 @@ function buildDriver(options, persistence, restored) {
5894
5899
  for (const claim of merged.claims) claims.set(claim.id, fromRecord(claim));
5895
5900
  claimEvidence.clear();
5896
5901
  for (const evidence of merged.claimEvidence) claimEvidence.set(evidence.id, evidence);
5897
- registeredSourceUris.clear();
5898
- for (const sourceUri of merged.registeredSourceUris) registeredSourceUris.add(sourceUri);
5902
+ registeredSources.clear();
5903
+ for (const source of merged.registeredSources) registeredSources.set(source.sourceId, source);
5899
5904
  questions.clear();
5900
5905
  for (const question of merged.questions) questions.set(question.id, question);
5901
5906
  rounds = Math.max(rounds, merged.rounds);
@@ -5947,19 +5952,23 @@ function buildDriver(options, persistence, restored) {
5947
5952
  return tracked;
5948
5953
  }
5949
5954
  /** Persist an extraction observation without treating its source as registered. */
5950
- function recordEvidence(extracted, sourceUri, round) {
5955
+ function recordEvidence(extracted, sourceVersion, round) {
5951
5956
  const text = extracted.text.trim();
5952
5957
  const observedClaimId = claimId(text);
5953
5958
  const contradictsClaimId = extracted.contradictsExistingId === observedClaimId ? void 0 : extracted.contradictsExistingId;
5954
5959
  const evidence = {
5955
5960
  id: claimEvidenceId({
5956
5961
  claimId: observedClaimId,
5957
- sourceUri,
5962
+ sourceId: sourceVersion.sourceId,
5963
+ sourceUri: sourceVersion.uri,
5964
+ sourceContentHash: sourceVersion.contentHash,
5958
5965
  contradictsClaimId
5959
5966
  }),
5960
5967
  claimId: observedClaimId,
5961
5968
  text,
5962
- sourceUri,
5969
+ sourceId: sourceVersion.sourceId,
5970
+ sourceUri: sourceVersion.uri,
5971
+ sourceContentHash: sourceVersion.contentHash,
5963
5972
  ...contradictsClaimId === void 0 ? {} : { contradictsClaimId },
5964
5973
  firstSeenRound: round
5965
5974
  };
@@ -5975,9 +5984,9 @@ function buildDriver(options, persistence, restored) {
5975
5984
  claimEvidence.set(merged.id, merged);
5976
5985
  return merged;
5977
5986
  }
5978
- /** Materialize evidence for newly confirmed source URIs into live claims. */
5979
- function materializeEvidenceFor(sourceUris) {
5980
- const evidence = [...claimEvidence.values()].filter((item) => sourceUris.has(item.sourceUri));
5987
+ /** Materialize evidence for newly confirmed exact source versions into live claims. */
5988
+ function materializeEvidenceFor(sourceVersions) {
5989
+ const evidence = [...claimEvidence.values()].filter((item) => sourceVersions.has(sourceVersionKeyOfEvidence(item)));
5981
5990
  const texts = [];
5982
5991
  for (const item of evidence) {
5983
5992
  recordClaim({
@@ -5992,13 +6001,20 @@ function buildDriver(options, persistence, restored) {
5992
6001
  }
5993
6002
  return texts;
5994
6003
  }
5995
- async function commitSources(sourceUris) {
6004
+ async function commitSources(sources) {
6005
+ const versions = sources.map(sourceVersionOfRecord);
6006
+ const nextRegistered = new Map(registeredSources);
5996
6007
  const newlyRegistered = /* @__PURE__ */ new Set();
5997
- for (const sourceUri of sourceUris) {
5998
- if (registeredSourceUris.has(sourceUri)) continue;
5999
- registeredSourceUris.add(sourceUri);
6000
- newlyRegistered.add(sourceUri);
6008
+ for (const version of versions) {
6009
+ const key = researchSourceVersionKey(version);
6010
+ const existing = nextRegistered.get(version.sourceId);
6011
+ if (existing && researchSourceVersionKey(existing) !== key) throw new Error(`registered source '${version.sourceId}' has conflicting immutable content`);
6012
+ if (existing) continue;
6013
+ nextRegistered.set(version.sourceId, version);
6014
+ newlyRegistered.add(key);
6001
6015
  }
6016
+ registeredSources.clear();
6017
+ for (const [sourceId, version] of nextRegistered) registeredSources.set(sourceId, version);
6002
6018
  if (newlyRegistered.size > 0) markAddressed(materializeEvidenceFor(newlyRegistered));
6003
6019
  await persist();
6004
6020
  }
@@ -6071,17 +6087,25 @@ function buildDriver(options, persistence, restored) {
6071
6087
  * because such a source cannot drive the research and pollutes the KB.
6072
6088
  */
6073
6089
  async verifySource(source, ctx) {
6074
- bindGoal(ctx.goal);
6075
- const extracted = await extractClaims(source, ctx);
6090
+ const sourceSnapshot = snapshotSourceTextInput(source);
6091
+ const goalSnapshot = ctx.goal;
6092
+ const roundSnapshot = ctx.round;
6093
+ const sourceVersion = sourceVersionOfProposal(sourceSnapshot);
6094
+ bindGoal(goalSnapshot);
6095
+ const extracted = await extractClaims(sourceSnapshot, goalSnapshot);
6076
6096
  if (extracted.length === 0) return {
6077
6097
  accept: false,
6078
6098
  reason: "no extractable claim: source yields nothing to drive the research deeper"
6079
6099
  };
6080
- for (const claim of extracted) recordEvidence(claim, source.uri, ctx.round);
6100
+ for (const claim of extracted) recordEvidence(claim, sourceVersion, roundSnapshot);
6081
6101
  if (!persistence) {
6082
- registeredSourceUris.add(source.uri);
6083
- markAddressed(materializeEvidenceFor(/* @__PURE__ */ new Set([source.uri])));
6084
- } else if (registeredSourceUris.has(source.uri)) markAddressed(materializeEvidenceFor(/* @__PURE__ */ new Set([source.uri])));
6102
+ const key = researchSourceVersionKey(sourceVersion);
6103
+ registeredSources.set(sourceVersion.sourceId, sourceVersion);
6104
+ markAddressed(materializeEvidenceFor(/* @__PURE__ */ new Set([key])));
6105
+ } else {
6106
+ const registered = registeredSources.get(sourceVersion.sourceId);
6107
+ if (registered && researchSourceVersionKey(registered) === researchSourceVersionKey(sourceVersion)) markAddressed(materializeEvidenceFor(/* @__PURE__ */ new Set([researchSourceVersionKey(sourceVersion)])));
6108
+ }
6085
6109
  await persist();
6086
6110
  return { accept: true };
6087
6111
  },
@@ -6126,8 +6150,8 @@ function buildDriver(options, persistence, restored) {
6126
6150
  commitSources,
6127
6151
  toLedger
6128
6152
  };
6129
- async function extractClaims(source, ctx) {
6130
- const fromLlm = await extractClaimsWithLlm(source, ctx, claimsForExtraction());
6153
+ async function extractClaims(source, goal) {
6154
+ const fromLlm = await extractClaimsWithLlm(source, goal, claimsForExtraction());
6131
6155
  if (fromLlm.length > 0) return fromLlm.slice(0, maxClaimsPerSource);
6132
6156
  if (deterministicFallback) return deterministicClaims(source).slice(0, maxClaimsPerSource);
6133
6157
  return [];
@@ -6148,7 +6172,7 @@ function buildDriver(options, persistence, restored) {
6148
6172
  }
6149
6173
  return [...known.values()];
6150
6174
  }
6151
- async function extractClaimsWithLlm(source, ctx, ledger) {
6175
+ async function extractClaimsWithLlm(source, goal, ledger) {
6152
6176
  let router;
6153
6177
  try {
6154
6178
  router = resolveRouter();
@@ -6159,7 +6183,7 @@ function buildDriver(options, persistence, restored) {
6159
6183
  const ledgerLines = ledger.slice(0, 20).map((claim) => `- [${claim.id}] ${claim.text}`).join("\n");
6160
6184
  const system = `You extract the KEY factual claims a researcher would cite a page for, and flag CONTRADICTIONS with claims already on the ledger. A claim is one concrete, checkable assertion using the page's own terms and numbers. Return ONLY a JSON array; each item is {"claim": string, "contradicts": string|null} where contradicts is the bracketed [id] of a ledger claim this page DIRECTLY contradicts, else null. Return at most ${maxClaimsPerSource} claims. No prose.`;
6161
6185
  const user = [
6162
- `Research goal: ${ctx.goal}`,
6186
+ `Research goal: ${goal}`,
6163
6187
  `Page title: ${source.title ?? "(none)"}`,
6164
6188
  ledgerLines ? `Claims already on the ledger:\n${ledgerLines}` : "Ledger is empty.",
6165
6189
  `Page excerpt:\n${excerpt}`,
@@ -6217,6 +6241,33 @@ function buildDriver(options, persistence, restored) {
6217
6241
  return out.sort((a, b) => priority[a.kind] - priority[b.kind]);
6218
6242
  }
6219
6243
  }
6244
+ function sourceVersionOfProposal(source) {
6245
+ const contentHash = sha256(source.text);
6246
+ return {
6247
+ sourceId: textSourceId(source.uri, contentHash),
6248
+ uri: source.uri,
6249
+ contentHash
6250
+ };
6251
+ }
6252
+ function sourceVersionOfRecord(source) {
6253
+ const originalUri = source.metadata?.originalUri;
6254
+ if (typeof originalUri !== "string" || originalUri.length === 0) throw new Error(`registered source '${source.id}' has no originalUri`);
6255
+ if (!/^[a-f0-9]{64}$/.test(source.contentHash)) throw new Error(`registered source '${source.id}' contentHash is not a SHA-256 digest`);
6256
+ const expectedSourceId = textSourceId(originalUri, source.contentHash);
6257
+ if (source.id !== expectedSourceId) throw new Error(`registered source '${source.id}' does not match URI-and-content identity '${expectedSourceId}'`);
6258
+ return {
6259
+ sourceId: source.id,
6260
+ uri: originalUri,
6261
+ contentHash: source.contentHash
6262
+ };
6263
+ }
6264
+ function sourceVersionKeyOfEvidence(evidence) {
6265
+ return researchSourceVersionKey({
6266
+ sourceId: evidence.sourceId,
6267
+ uri: evidence.sourceUri,
6268
+ contentHash: evidence.sourceContentHash
6269
+ });
6270
+ }
6220
6271
  function makeQuestion(kind, text, claimIds, raisedRound) {
6221
6272
  return {
6222
6273
  kind,
@@ -6371,6 +6422,6 @@ function buildSteerText(gaps, deepQuestions, invalidationTargets, minIndependent
6371
6422
  return lines.join("\n");
6372
6423
  }
6373
6424
  //#endregion
6374
- export { AgentMemoryHitSchema, AgentMemoryKindSchema, AgentMemoryLifecycleTimeoutError, AgentMemoryLifecycleUnsafeError, AgentMemoryScopeSchema, AgentMemoryWriteInputSchema, ClaimLedgerGoalConflictError, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, DeepQuestionSchema, FileSystemKbStore, FileSystemSearchProvider, INDUSTRY_MEMORY_BENCHMARKS, INDUSTRY_RAG_BENCHMARKS, IRS_DIMENSION_HINTS, KB_CLAIM_LEDGER_DIR, KB_EVENTS_PATH, KB_INDEX_PATH, KB_STORE_DIR, KNOWLEDGE_EVENT_TYPES, KnowledgeBaseCandidateSchema, KnowledgeEventSchema, KnowledgeGraphEdgeSchema, KnowledgeGraphNodeSchema, KnowledgeImprovementCandidateRefSchema, KnowledgeImprovementEvidenceSchema, KnowledgeImprovementRunStateSchema, KnowledgeIndexSchema, KnowledgePageSchema, KnowledgeProposalParseError, MAX_RESPONSE_BYTES, MIN_REQUEST_GAP_MS, MemoryKbStore, POLITE_USER_AGENT, READINESS_SPEC_DEFAULTS, ResearchClaimEvidenceSchema, ResearchClaimLedgerSchema, ResearchClaimRecordSchema, RouterError, SCAFFOLD_PAGE_BASENAMES, SourceAnchorSchema, SourceRecordSchema, WIKILINK_REGEX, __resetHttpThrottle, acquireAgentMemoryRunLease, addSourcePath, addSourceText, agentMemorySequenceJudge, applyKnowledgeWriteBlocks, applyKnowledgeWriteBlocksFile, applyRetrievalHoldout, applySessionStickyRetrievalHoldout, assertClaimLedgerId, assertDeepQuestionIntegrity, assertResearchClaimEvidenceIntegrity, assertResearchClaimLedgerIntegrity, assertTrackedClaimIntegrity, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, buildEvalKnowledgeBundle, buildFirstPartyMemoryLifecycleBenchmarkCases, buildIndustryMemoryBenchmarkSmokeCases, buildIndustryRagBenchmarkSmokeCases, buildKnowledgeBenchmarkScenarios, buildKnowledgeGraph, buildKnowledgeIndex, buildRetrievalBenchmarkCasesFromQrels, buildRetrievalEvalDispatch, calibrateRagAnswerJudge, canonicalizeUrl, chunkMarkdown, citedClaimKey, citedClaimOf, claimEvidenceId, claimId, claimSourceHost, contentKey, createAdaptiveResearchDriver, createAgentMemoryBranch, createClaimDecorator, createClaimGroundingVerifier, createCollectionResearchDriver, createCornellLiiSource, createD1FreshnessStoreStub, createFileSystemFreshnessStore, createFileSystemSearchProvider, createGraphitiMemoryAdapter, createInMemoryBenchmarkAdapter, createIrsPublicationsSource, createKnowledgeControlLoopAdapter, createKnowledgeEvent, createLocalDiscoveryDispatcher, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, createNoopMemoryBenchmarkAdapter, createPersistentResearchDrivingDriver, createRagAnswerQualityHook, createResearchDrivingDriver, createStateSosSource, createTangleRouterClient, createVerifyingResearchDriver, createWebResearchWorker, deepQuestionId, defaultGetMemoryContext, defineReadinessSpec, detectChanges, deterministicRng, diagnoseRagAnswerFailure, emitRetrievalHoldoutBypass, emptyClaimLedger, evaluateKnowledgeBaseReadiness, explainKnowledgeTarget, extractLinks, extractWikilinks, firstMatch, forkAgentMemoryBranchSnapshot, formatFrontmatter, fromAgentCandidateKnowledgeRef, gradeCompanyAgainstText, gradeFactAgainstText, graphitiMemoryAdapterIdentity, groundClaimInText, hashKnowledgeBase, htmlToText, improveKnowledgeBase, initKnowledgeBase, innerHtmlById, inspectKnowledgeIndex, inspectPendingKnowledgeMutation, investmentThesisSet, isKernelAnchoredPath, isKnowledgeMemoryBenchmarkCase, isMissingFile, isSafeKnowledgePath, isScaffoldPath, jsonCandidateCodec, jsonObjectCandidateCodec, kbIndexToText, knowledgeBenchmarkJudge, knowledgeImprovementCandidateRef, knowledgeImprovementRunDir, knowledgeImprovementRunId, knowledgeReleaseReport, layoutFor, lensDistribution, linkClaimContradictions, lintKnowledgeIndex, listRegularFilesWithinRoot, loadKnowledgeImprovementActivationResult, loadKnowledgeImprovementEvents, loadKnowledgeImprovementState, loadKnowledgePages, loadSourceRegistry, looksLikeBlockPage, materialFactsSurfaced, materialFactsSurfacedInText, materializeRegisteredClaimEvidence, mediaTypeFor, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, mergeClaimLedgers, mergeTrackedClaims, normalizeClaimText, normalizeExternalRagScores, normalizeLinkTarget, optimizeKnowledgeBasePolicy, parseFrontmatter, parseKnowledgeBenchmarkJsonl, parseKnowledgeBenchmarkQrels, parseKnowledgeWriteBlocks, partitionRetrievalScenarios, politeFetch, promoteKnowledgeCandidate, proposeFromFinding, proposeFromFindings, ragAnswerQualityJudge, readRegularFileNoFollow, readRegularFileWithinRoot, reciprocalRankFusion, recoverPendingKnowledgeMutation, removeDurable, renameDurable, renderKnowledgeBenchmarkReportMarkdown, renderMemoryContext, resetRetrievalHoldoutRegistry, resolveMemoryCleanupTimeoutMs, respondToIndustryMemoryBenchmarkSmokeCase, respondToIndustryRagBenchmarkSmokeCase, restoreKnowledgeCandidateBaseline, retrievalConfigFromSurface, retrievalConfigSurface, retrievalHoldoutConfigHash, retrievalRecallJudge, runAgentMemoryExperiment, runAgentMemoryImprovement, runBoundedMemoryLifecycle, runDiscoveryLoop, runInvestmentThesisTask, runKnowledgeBenchmarkSuite, runKnowledgeResearchLoop, runMemoryAdapterBenchmark, runRagKnowledgeImprovementLoop, runRagOptimization, runRetrievalImprovementLoop, runSerializedKnowledgeOptimization, runVerifiedResearchLoop, scenarioContentFingerprint, scoreKnowledgeBaseIndex, scoreKnowledgeBenchmarkArtifact, scoreMemoryBenchmarkArtifact, scoreRagAnswerArtifact, scoreRetrievalArtifact, searchKnowledge, sha256, sleepForMemoryRecovery, slugify, sourceMatchesGaps, sourceRegistryPath, stableId, stripFrontmatter, summarizeKnowledgeBenchmarkCampaign, syncDirectory, textSourceAdapter, thesisReadinessSpecs, toAgentCandidateKnowledgeRef, toDeepEvalTestCases, toOffPolicyTrajectory, toRagCheckerRecords, toRagasEvaluationRows, toTruLensRecords, tokenizeQuery, totalMaterialFacts, triageSource, validateKnowledgeIndex, withCitedClaim, withKnowledgeImprovementCandidate, withKnowledgeImprovementComparison, withSafeDescendant, withSafeDirectory, writeFileDurable, writeFileDurableWithinRoot, writeJson, writeJsonDurable, writeJsonDurableWithinRoot, writeKnowledgeIndex, writeSourceRegistry };
6425
+ export { AgentMemoryHitSchema, AgentMemoryKindSchema, AgentMemoryLifecycleTimeoutError, AgentMemoryLifecycleUnsafeError, AgentMemoryScopeSchema, AgentMemoryWriteInputSchema, ClaimLedgerGoalConflictError, ClaimLedgerMigrationRequiredError, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, DeepQuestionSchema, FileSystemKbStore, FileSystemSearchProvider, INDUSTRY_MEMORY_BENCHMARKS, INDUSTRY_RAG_BENCHMARKS, IRS_DIMENSION_HINTS, KB_CLAIM_LEDGER_DIR, KB_EVENTS_PATH, KB_INDEX_PATH, KB_STORE_DIR, KNOWLEDGE_EVENT_TYPES, KnowledgeBaseCandidateSchema, KnowledgeEventSchema, KnowledgeGraphEdgeSchema, KnowledgeGraphNodeSchema, KnowledgeImprovementCandidateRefSchema, KnowledgeImprovementEvidenceSchema, KnowledgeImprovementRunStateSchema, KnowledgeIndexSchema, KnowledgePageSchema, KnowledgeProposalParseError, MAX_RESPONSE_BYTES, MIN_REQUEST_GAP_MS, MemoryKbStore, POLITE_USER_AGENT, READINESS_SPEC_DEFAULTS, ResearchClaimEvidenceSchema, ResearchClaimLedgerSchema, ResearchClaimRecordSchema, ResearchSourceVersionSchema, RouterError, SCAFFOLD_PAGE_BASENAMES, SourceAnchorSchema, SourceRecordSchema, WIKILINK_REGEX, __resetHttpThrottle, acquireAgentMemoryRunLease, addSourcePath, addSourceText, agentMemorySequenceJudge, applyKnowledgeWriteBlocks, applyKnowledgeWriteBlocksFile, applyRetrievalHoldout, applySessionStickyRetrievalHoldout, assertClaimLedgerId, assertDeepQuestionIntegrity, assertResearchClaimEvidenceIntegrity, assertResearchClaimLedgerIntegrity, assertTrackedClaimIntegrity, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, buildEvalKnowledgeBundle, buildFirstPartyMemoryLifecycleBenchmarkCases, buildIndustryMemoryBenchmarkSmokeCases, buildIndustryRagBenchmarkSmokeCases, buildKnowledgeBenchmarkScenarios, buildKnowledgeGraph, buildKnowledgeIndex, buildRetrievalBenchmarkCasesFromQrels, buildRetrievalEvalDispatch, calibrateRagAnswerJudge, canonicalizeUrl, chunkMarkdown, citedClaimKey, citedClaimOf, claimEvidenceId, claimId, claimSourceHost, contentKey, createAdaptiveResearchDriver, createAgentMemoryBranch, createClaimDecorator, createClaimGroundingVerifier, createCollectionResearchDriver, createCornellLiiSource, createD1FreshnessStoreStub, createFileSystemFreshnessStore, createFileSystemSearchProvider, createGraphitiMemoryAdapter, createInMemoryBenchmarkAdapter, createIrsPublicationsSource, createKnowledgeControlLoopAdapter, createKnowledgeEvent, createLocalDiscoveryDispatcher, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, createNoopMemoryBenchmarkAdapter, createPersistentResearchDrivingDriver, createRagAnswerQualityHook, createResearchDrivingDriver, createStateSosSource, createTangleRouterClient, createVerifyingResearchDriver, createWebResearchWorker, deepQuestionId, defaultGetMemoryContext, defineReadinessSpec, detectChanges, deterministicRng, diagnoseRagAnswerFailure, emitRetrievalHoldoutBypass, emptyClaimLedger, evaluateKnowledgeBaseReadiness, explainKnowledgeTarget, extractLinks, extractWikilinks, firstMatch, forkAgentMemoryBranchSnapshot, formatFrontmatter, fromAgentCandidateKnowledgeRef, gradeCompanyAgainstText, gradeFactAgainstText, graphitiMemoryAdapterIdentity, groundClaimInText, hashKnowledgeBase, htmlToText, improveKnowledgeBase, initKnowledgeBase, innerHtmlById, inspectKnowledgeIndex, inspectPendingKnowledgeMutation, investmentThesisSet, isKernelAnchoredPath, isKnowledgeMemoryBenchmarkCase, isMissingFile, isSafeKnowledgePath, isScaffoldPath, jsonCandidateCodec, jsonObjectCandidateCodec, kbIndexToText, knowledgeBenchmarkJudge, knowledgeImprovementCandidateRef, knowledgeImprovementRunDir, knowledgeImprovementRunId, knowledgeReleaseReport, layoutFor, lensDistribution, linkClaimContradictions, lintKnowledgeIndex, listRegularFilesWithinRoot, loadKnowledgeImprovementActivationResult, loadKnowledgeImprovementEvents, loadKnowledgeImprovementState, loadKnowledgePages, loadSourceRegistry, looksLikeBlockPage, materialFactsSurfaced, materialFactsSurfacedInText, materializeRegisteredClaimEvidence, mediaTypeFor, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, mergeClaimLedgers, mergeTrackedClaims, normalizeClaimText, normalizeExternalRagScores, normalizeLinkTarget, optimizeKnowledgeBasePolicy, parseFrontmatter, parseKnowledgeBenchmarkJsonl, parseKnowledgeBenchmarkQrels, parseKnowledgeWriteBlocks, partitionRetrievalScenarios, politeFetch, promoteKnowledgeCandidate, proposeFromFinding, proposeFromFindings, ragAnswerQualityJudge, readRegularFileNoFollow, readRegularFileWithinRoot, reciprocalRankFusion, recoverPendingKnowledgeMutation, removeDurable, renameDurable, renderKnowledgeBenchmarkReportMarkdown, renderMemoryContext, researchSourceVersionKey, resetRetrievalHoldoutRegistry, resolveMemoryCleanupTimeoutMs, respondToIndustryMemoryBenchmarkSmokeCase, respondToIndustryRagBenchmarkSmokeCase, restoreKnowledgeCandidateBaseline, retrievalConfigFromSurface, retrievalConfigSurface, retrievalHoldoutConfigHash, retrievalRecallJudge, runAgentMemoryExperiment, runAgentMemoryImprovement, runBoundedMemoryLifecycle, runDiscoveryLoop, runInvestmentThesisTask, runKnowledgeBenchmarkSuite, runKnowledgeResearchLoop, runMemoryAdapterBenchmark, runRagKnowledgeImprovementLoop, runRagOptimization, runRetrievalImprovementLoop, runSerializedKnowledgeOptimization, runVerifiedResearchLoop, scenarioContentFingerprint, scoreKnowledgeBaseIndex, scoreKnowledgeBenchmarkArtifact, scoreMemoryBenchmarkArtifact, scoreRagAnswerArtifact, scoreRetrievalArtifact, searchKnowledge, sha256, sleepForMemoryRecovery, slugify, snapshotSourceTextInput, sourceMatchesGaps, sourceRegistryPath, stableId, stripFrontmatter, summarizeKnowledgeBenchmarkCampaign, syncDirectory, textSourceAdapter, textSourceId, thesisReadinessSpecs, toAgentCandidateKnowledgeRef, toDeepEvalTestCases, toOffPolicyTrajectory, toRagCheckerRecords, toRagasEvaluationRows, toTruLensRecords, tokenizeQuery, totalMaterialFacts, triageSource, validateKnowledgeIndex, withCitedClaim, withKnowledgeImprovementCandidate, withKnowledgeImprovementComparison, withSafeDescendant, withSafeDirectory, writeFileDurable, writeFileDurableWithinRoot, writeJson, writeJsonDurable, writeJsonDurableWithinRoot, writeKnowledgeIndex, writeSourceRegistry };
6375
6426
 
6376
6427
  //# sourceMappingURL=index.js.map