@tangle-network/agent-knowledge 14.0.3 → 15.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.
- package/CHANGELOG.md +10 -0
- package/README.md +19 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +28 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +193 -116
- package/dist/index.js.map +1 -1
- package/dist/{inspect-DCpUoPVb.js → inspect-DMZXOQYl.js} +12 -9
- package/dist/inspect-DMZXOQYl.js.map +1 -0
- package/docs/architecture.md +11 -0
- package/docs/knowledge-use-receipts.md +10 -0
- package/package.json +2 -2
- package/dist/inspect-DCpUoPVb.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as formatKnowledgeCitationReference, $t as inspectPendingKnowledgeMutation, A as addSourceText, An as writeJsonDurableWithinRoot, At as ResearchSourceVersionSchema, B as KB_STORE_DIR, Bt as claimId, C as gradeClaims, Cn as renameDurable, Ct as KnowledgePageSchema, D as buildKnowledgeIndex, Dn as writeFileDurable, Dt as ResearchClaimEvidenceSchema, E as verifyGradeableEvidence, En as withSafeDirectory, Et as KnowledgeRelationSchema, F as ClaimLedgerMigrationRequiredError, Ft as assertDeepQuestionIntegrity, G as KnowledgeCitationAuditError, Gt as materializeRegisteredClaimEvidence, H as assertClaimLedgerId, Ht as deepQuestionId, I as FileSystemKbStore, It as assertResearchClaimEvidenceIntegrity, J as assertKnowledgeCitationAudit, Jt as normalizeClaimText, K as KnowledgeCitationResolutionError, Kt as mergeClaimLedgers, L as KB_CLAIM_LEDGER_DIR, Lt as assertResearchClaimLedgerIntegrity, M as snapshotSourceTextInput, Mn as textSourceAdapter, Mt as SourceRecordSchema, N as sourceRegistryPath, Nt as KNOWLEDGE_EVENT_TYPES, O as writeKnowledgeIndex, On as writeFileDurableWithinRoot, Ot as ResearchClaimLedgerSchema, P as writeSourceRegistry, Pt as ClaimLedgerGoalConflictError, Q as auditKnowledgeCitations, Qt as acquireDurableFileLock, R as KB_EVENTS_PATH, Rt as assertTrackedClaimIntegrity, S as claimCheckKey, Sn as removeDurable, St as KnowledgePageInvalidationSchema, T as verdictFor, Tn as withSafeDescendant, Tt as KnowledgeRelationNodeSchema, U as buildKnowledgeGraph, Ut as emptyClaimLedger, V as MemoryKbStore, Vt as claimSourceHost, W as knowledgePageRelations, Wt as linkClaimContradictions, X as assertRunScopedCitationsResolved, Xt as formatFrontmatter, Y as assertKnowledgeCitationsResolved, Yt as researchSourceVersionKey, Z as auditCurrentRunCitations, Zt as parseFrontmatter, _ as lintKnowledgeIndex, _n as isMissingFile, _t as KnowledgeBaseCandidateSchema, a as applyKnowledgeWriteBlocksFile, an as applyKnowledgeFileTransaction, at as SCAFFOLD_PAGE_BASENAMES, b as UncheckableClaimError, bn as readRegularFileWithinRoot, bt as KnowledgeGraphNodeSchema, c as KnowledgeDuplicateIntakeError, cn as finishKnowledgeFileTransaction, ct as isScaffoldPath, d as createFileRunLineageAuthority, dn as rollbackKnowledgeFileTransaction, dt as loadKnowledgePages, en as isKnowledgeMutationHeld, et as parseKnowledgeCitationReference, f as createRunScopedStores, fn as DEFAULT_PAGES_DIRECTORY, ft as writeJson, g as validateKnowledgeIndex, gn as isKernelAnchoredPath, gt as DeepQuestionSchema, h as normalizePageText, hn as canonicalRelativeWithinRoot, ht as normalizeLinkTarget, i as applyKnowledgeWriteBlocks, in as withKnowledgeRead, it as resolveRunScopedCitations, j as loadSourceRegistry, jn as mediaTypeFor, jt as SourceAnchorSchema, k as addSourcePath, kn as writeJsonDurable, kt as ResearchClaimRecordSchema, l as assertKnowledgeWriteIntake, ln as knowledgeFileTransactionPlanHash, lt as knowledgePageFromMarkdown, m as detectNearDuplicatePages, mn as canonicalPathsEqual, mt as extractWikilinks, n as inspectKnowledgeIndex, nn as runInKnowledgeMutationScope, nt as resolveKnowledgeCitations, o as isSafeKnowledgePath, on as assertKnowledgeMutationPath, ot as initKnowledgeBase, p as originatedPages, pn as normalizePagesDirectory, pt as WIKILINK_REGEX, q as assertCurrentRunCitationsResolved, qt as mergeTrackedClaims, r as stringMetadata, rn as withKnowledgeMutation, rt as resolveRunScopedCitation, s as parseKnowledgeWriteBlocks, sn as commitKnowledgeFileMutations, st as isKnowledgePagePath, t as explainKnowledgeTarget, tn as recoverPendingKnowledgeMutation, tt as resolveKnowledgeCitation, u as RUN_LINEAGE_BASENAME, un as prepareKnowledgeFileTransaction, ut as layoutFor, v as CHECKABLE_RUNG_THRESHOLD, vn as listRegularFilesWithinRoot, vt as KnowledgeEventSchema, w as gradeFor, wn as syncDirectory, wt as KnowledgeRelationGraphSchema, x as assertGradeableEvidence, xn as relativeWithinRoot, xt as KnowledgeIndexSchema, y as DEADLINE_EXIT_CODE, yn as readRegularFileNoFollow, yt as KnowledgeGraphEdgeSchema, z as KB_INDEX_PATH, zt as claimEvidenceId } from "./inspect-
|
|
1
|
+
import { $ as formatKnowledgeCitationReference, $t as inspectPendingKnowledgeMutation, A as addSourceText, An as writeJsonDurableWithinRoot, At as ResearchSourceVersionSchema, B as KB_STORE_DIR, Bt as claimId, C as gradeClaims, Cn as renameDurable, Ct as KnowledgePageSchema, D as buildKnowledgeIndex, Dn as writeFileDurable, Dt as ResearchClaimEvidenceSchema, E as verifyGradeableEvidence, En as withSafeDirectory, Et as KnowledgeRelationSchema, F as ClaimLedgerMigrationRequiredError, Ft as assertDeepQuestionIntegrity, G as KnowledgeCitationAuditError, Gt as materializeRegisteredClaimEvidence, H as assertClaimLedgerId, Ht as deepQuestionId, I as FileSystemKbStore, It as assertResearchClaimEvidenceIntegrity, J as assertKnowledgeCitationAudit, Jt as normalizeClaimText, K as KnowledgeCitationResolutionError, Kt as mergeClaimLedgers, L as KB_CLAIM_LEDGER_DIR, Lt as assertResearchClaimLedgerIntegrity, M as snapshotSourceTextInput, Mn as textSourceAdapter, Mt as SourceRecordSchema, N as sourceRegistryPath, Nt as KNOWLEDGE_EVENT_TYPES, O as writeKnowledgeIndex, On as writeFileDurableWithinRoot, Ot as ResearchClaimLedgerSchema, P as writeSourceRegistry, Pt as ClaimLedgerGoalConflictError, Q as auditKnowledgeCitations, Qt as acquireDurableFileLock, R as KB_EVENTS_PATH, Rt as assertTrackedClaimIntegrity, S as claimCheckKey, Sn as removeDurable, St as KnowledgePageInvalidationSchema, T as verdictFor, Tn as withSafeDescendant, Tt as KnowledgeRelationNodeSchema, U as buildKnowledgeGraph, Ut as emptyClaimLedger, V as MemoryKbStore, Vt as claimSourceHost, W as knowledgePageRelations, Wt as linkClaimContradictions, X as assertRunScopedCitationsResolved, Xt as formatFrontmatter, Y as assertKnowledgeCitationsResolved, Yt as researchSourceVersionKey, Z as auditCurrentRunCitations, Zt as parseFrontmatter, _ as lintKnowledgeIndex, _n as isMissingFile, _t as KnowledgeBaseCandidateSchema, a as applyKnowledgeWriteBlocksFile, an as applyKnowledgeFileTransaction, at as SCAFFOLD_PAGE_BASENAMES, b as UncheckableClaimError, bn as readRegularFileWithinRoot, bt as KnowledgeGraphNodeSchema, c as KnowledgeDuplicateIntakeError, cn as finishKnowledgeFileTransaction, ct as isScaffoldPath, d as createFileRunLineageAuthority, dn as rollbackKnowledgeFileTransaction, dt as loadKnowledgePages, en as isKnowledgeMutationHeld, et as parseKnowledgeCitationReference, f as createRunScopedStores, fn as DEFAULT_PAGES_DIRECTORY, ft as writeJson, g as validateKnowledgeIndex, gn as isKernelAnchoredPath, gt as DeepQuestionSchema, h as normalizePageText, hn as canonicalRelativeWithinRoot, ht as normalizeLinkTarget, i as applyKnowledgeWriteBlocks, in as withKnowledgeRead, it as resolveRunScopedCitations, j as loadSourceRegistry, jn as mediaTypeFor, jt as SourceAnchorSchema, k as addSourcePath, kn as writeJsonDurable, kt as ResearchClaimRecordSchema, l as assertKnowledgeWriteIntake, ln as knowledgeFileTransactionPlanHash, lt as knowledgePageFromMarkdown, m as detectNearDuplicatePages, mn as canonicalPathsEqual, mt as extractWikilinks, n as inspectKnowledgeIndex, nn as runInKnowledgeMutationScope, nt as resolveKnowledgeCitations, o as isSafeKnowledgePath, on as assertKnowledgeMutationPath, ot as initKnowledgeBase, p as originatedPages, pn as normalizePagesDirectory, pt as WIKILINK_REGEX, q as assertCurrentRunCitationsResolved, qt as mergeTrackedClaims, r as stringMetadata, rn as withKnowledgeMutation, rt as resolveRunScopedCitation, s as parseKnowledgeWriteBlocks, sn as commitKnowledgeFileMutations, st as isKnowledgePagePath, t as explainKnowledgeTarget, tn as recoverPendingKnowledgeMutation, tt as resolveKnowledgeCitation, u as RUN_LINEAGE_BASENAME, un as prepareKnowledgeFileTransaction, ut as layoutFor, v as CHECKABLE_RUNG_THRESHOLD, vn as listRegularFilesWithinRoot, vt as KnowledgeEventSchema, w as gradeFor, wn as syncDirectory, wt as KnowledgeRelationGraphSchema, x as assertGradeableEvidence, xn as relativeWithinRoot, xt as KnowledgeIndexSchema, y as DEADLINE_EXIT_CODE, yn as readRegularFileNoFollow, yt as KnowledgeGraphEdgeSchema, z as KB_INDEX_PATH, zt as claimEvidenceId } from "./inspect-DMZXOQYl.js";
|
|
2
2
|
import { i as textSourceId, n as slugify, r as stableId, t as sha256 } from "./ids-Bevz_pXV.js";
|
|
3
3
|
import { A as runSerializedKnowledgeOptimization, C as deterministicRng, D as toOffPolicyTrajectory, E as retrievalHoldoutConfigHash, M as assertImmutableRef, O as jsonCandidateCodec, S as applySessionStickyRetrievalHoldout, T as resetRetrievalHoldoutRegistry, _ as createAgentMemoryBranch, a as createNeo4jAgentMemoryAdapter, b as renderMemoryContext, c as runAgentMemoryImprovement, d as compareAgentMemoryLearning, f as runAgentMemoryLearningExperiment, g as buildAgentMemorySequencesFromBenchmarkCases, h as buildAgentMemorySequenceScenarios, i as AgentMemoryWriteInputSchema, j as scenarioContentFingerprint, k as jsonObjectCandidateCodec, l as createGraphitiMemoryAdapter, m as agentMemorySequenceJudge, n as AgentMemoryKindSchema, o as createMem0MemoryAdapter, p as runAgentMemoryExperiment, r as AgentMemoryScopeSchema, s as mem0MemoryAdapterIdentity, t as AgentMemoryHitSchema, u as graphitiMemoryAdapterIdentity, v as forkAgentMemoryBranchSnapshot, w as emitRetrievalHoldoutBypass, x as applyRetrievalHoldout, y as defaultGetMemoryContext } from "./memory-BxwOtvd7.js";
|
|
4
4
|
import { C as sleepForMemoryRecovery, F as buildIndustryRagBenchmarkSmokeCases, G as buildRetrievalEvalDispatch, H as createNoopMemoryBenchmarkAdapter, I as respondToIndustryMemoryBenchmarkSmokeCase, J as retrievalConfigSurface, K as partitionRetrievalScenarios, L as respondToIndustryRagBenchmarkSmokeCase, M as INDUSTRY_RAG_BENCHMARKS, N as buildFirstPartyMemoryLifecycleBenchmarkCases, P as buildIndustryMemoryBenchmarkSmokeCases, R as isKnowledgeMemoryBenchmarkCase, S as runBoundedMemoryLifecycle, U as memoryHitToSourceRecord, V as createInMemoryBenchmarkAdapter, W as memoryWriteResultToSourceRecord, X as scoreRetrievalArtifact, Y as retrievalRecallJudge, Z as mean, a as buildKnowledgeBenchmarkScenarios, b as memoryRecoveryDelayMs, c as runKnowledgeBenchmarkSuite, d as summarizeKnowledgeBenchmarkCampaign, f as acquireAgentMemoryRunLease, h as DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, i as runMemoryAdapterBenchmark, j as INDUSTRY_MEMORY_BENCHMARKS, l as scoreKnowledgeBenchmarkArtifact, m as AgentMemoryLifecycleUnsafeError, n as parseKnowledgeBenchmarkJsonl, o as knowledgeBenchmarkJudge, p as AgentMemoryLifecycleTimeoutError, q as retrievalConfigFromSurface, r as parseKnowledgeBenchmarkQrels, s as renderKnowledgeBenchmarkReportMarkdown, t as buildRetrievalBenchmarkCasesFromQrels, u as scoreMemoryBenchmarkArtifact, x as resolveMemoryCleanupTimeoutMs, y as createMemoryExecutionPool } from "./benchmarks-BbPJdmHe.js";
|
|
@@ -6,13 +6,14 @@ import { a as buildKnowledgeLexicalIndex, c as tokenizeText, i as searchKnowledg
|
|
|
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";
|
|
9
|
-
import { dirname, join
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
10
|
import { agentImprovementActivationResultSchema, agentImprovementActivationSchema, canonicalCandidateBytes, canonicalCandidateDigest, canonicalCandidateJson, omitTopLevelDigest, sha256Bytes, sha256DigestSchema } from "@tangle-network/agent-interface";
|
|
11
11
|
import { acquisitionPlansForKnowledgeGaps, blockingKnowledgeEval, canonicalJson, contentHash, evaluateReleaseConfidence, objectiveEval, scoreKnowledgeReadiness, userQuestionsForKnowledgeGaps, validateRunRecord } from "@tangle-network/agent-eval";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { surfaceHash } from "@tangle-network/agent-eval/campaign";
|
|
14
14
|
import { tmpdir } from "node:os";
|
|
15
15
|
import { isDeepStrictEqual } from "node:util";
|
|
16
|
+
import { pathToFileURL } from "node:url";
|
|
16
17
|
//#region src/web-research-worker.ts
|
|
17
18
|
/**
|
|
18
19
|
* Real web-research worker + verifying driver for `runVerifiedResearchLoop`.
|
|
@@ -685,6 +686,20 @@ function createAdaptiveResearchDriver(options = {}) {
|
|
|
685
686
|
};
|
|
686
687
|
}
|
|
687
688
|
//#endregion
|
|
689
|
+
//#region src/knowledge-state-scope.ts
|
|
690
|
+
const knowledgeStateScopeSchema = z.object({
|
|
691
|
+
pagesDirectory: z.string().transform((value) => normalizePagesDirectory(value)).optional(),
|
|
692
|
+
researchState: z.boolean().optional()
|
|
693
|
+
}).strict();
|
|
694
|
+
function normalizeKnowledgeStateScope(scope = {}) {
|
|
695
|
+
const parsed = knowledgeStateScopeSchema.parse(scope);
|
|
696
|
+
return {
|
|
697
|
+
pagesDirectory: normalizePagesDirectory(parsed.pagesDirectory),
|
|
698
|
+
researchState: parsed.researchState ?? false
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
const KNOWLEDGE_RESEARCH_STATE_PATHS = [".agent-knowledge/claim-ledgers", ".agent-knowledge/events.json"];
|
|
702
|
+
//#endregion
|
|
688
703
|
//#region src/kb-improvement/contracts.ts
|
|
689
704
|
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/);
|
|
690
705
|
const immutableRefSchema = z.string().regex(/^(?:sha256:[a-f0-9]{64}|git:[a-f0-9]{40})$/);
|
|
@@ -770,6 +785,7 @@ const candidateRecordSchema = z.object({
|
|
|
770
785
|
updatedAt: z.iso.datetime()
|
|
771
786
|
}).strict();
|
|
772
787
|
const KnowledgeImprovementRunStateSchema = z.object({
|
|
788
|
+
stateScope: knowledgeStateScopeSchema.optional(),
|
|
773
789
|
runId: runIdSchema,
|
|
774
790
|
root: z.string().min(1),
|
|
775
791
|
goal: z.string().min(1),
|
|
@@ -2263,7 +2279,7 @@ function createKnowledgeControlLoopAdapter(options) {
|
|
|
2263
2279
|
await initKnowledgeBase(options.root);
|
|
2264
2280
|
initialized = true;
|
|
2265
2281
|
}
|
|
2266
|
-
const index = await buildKnowledgeIndex(options.root);
|
|
2282
|
+
const index = await buildKnowledgeIndex(options.root, options);
|
|
2267
2283
|
const validation = validateKnowledgeIndex(index, { strict: options.strict });
|
|
2268
2284
|
const lintFindings = lintKnowledgeIndex(index);
|
|
2269
2285
|
const readiness = readinessFor(options, index);
|
|
@@ -2316,7 +2332,7 @@ async function runKnowledgeResearchLoop(options) {
|
|
|
2316
2332
|
const maxIterations = Math.max(1, options.maxIterations ?? 3);
|
|
2317
2333
|
await initKnowledgeBase(options.root);
|
|
2318
2334
|
const steps = [];
|
|
2319
|
-
let index = await buildKnowledgeIndex(options.root);
|
|
2335
|
+
let index = await buildKnowledgeIndex(options.root, options);
|
|
2320
2336
|
let validation = validateKnowledgeIndex(index, { strict: options.strict });
|
|
2321
2337
|
let lintFindings = lintKnowledgeIndex(index);
|
|
2322
2338
|
let readiness = readinessFor(options, index);
|
|
@@ -2336,7 +2352,7 @@ async function runKnowledgeResearchLoop(options) {
|
|
|
2336
2352
|
});
|
|
2337
2353
|
done = Boolean(decision.done);
|
|
2338
2354
|
const step = await applyKnowledgeResearchDecision(options, decision, iteration);
|
|
2339
|
-
index = await buildKnowledgeIndex(options.root);
|
|
2355
|
+
index = await buildKnowledgeIndex(options.root, options);
|
|
2340
2356
|
validation = step.validation;
|
|
2341
2357
|
lintFindings = step.lintFindings;
|
|
2342
2358
|
readiness = step.readiness;
|
|
@@ -2361,8 +2377,8 @@ async function applyKnowledgeResearchDecision(options, decision, iteration = 1)
|
|
|
2361
2377
|
const addedSources = [];
|
|
2362
2378
|
for (const sourcePath of decision.sourcePaths ?? []) addedSources.push(...await addSourcePath(options.root, sourcePath, options.sourceOptions));
|
|
2363
2379
|
for (const sourceText of decision.sourceTexts ?? []) addedSources.push(await addSourceText(options.root, sourceText, options.sourceOptions));
|
|
2364
|
-
const applied = decision.proposalText ? await applyKnowledgeWriteBlocks(options.root, decision.proposalText) : void 0;
|
|
2365
|
-
const index = await buildKnowledgeIndex(options.root);
|
|
2380
|
+
const applied = decision.proposalText ? await applyKnowledgeWriteBlocks(options.root, decision.proposalText, { pagesDirectory: options.pagesDirectory }) : void 0;
|
|
2381
|
+
const index = await buildKnowledgeIndex(options.root, options);
|
|
2366
2382
|
const validation = validateKnowledgeIndex(index, { strict: options.strict });
|
|
2367
2383
|
const lintFindings = lintKnowledgeIndex(index);
|
|
2368
2384
|
const readiness = readinessFor(options, index);
|
|
@@ -2735,6 +2751,7 @@ async function withKnowledgeImprovementComparison(options, use) {
|
|
|
2735
2751
|
const state = await loadKnowledgeImprovementStateFromRun(options.root, reference.runId, runDir);
|
|
2736
2752
|
return withMeasuredCandidateSnapshot(options.root, runDir, state, reference, (resolved) => withBaselineSnapshot(runDir, reference.baseHash, (baselineRoot) => withIsolatedKnowledgeCopy(baselineRoot, reference.baseHash, "baseline", (baseline) => withIsolatedKnowledgeCopy(resolved.root, reference.candidateHash, "candidate", (candidate) => use(Object.freeze({
|
|
2737
2753
|
reference,
|
|
2754
|
+
stateScope: Object.freeze(normalizeKnowledgeStateScope(state.stateScope)),
|
|
2738
2755
|
evaluation: immutableJsonValue(structuredClone(resolved.evidence.evaluation)),
|
|
2739
2756
|
baseline: Object.freeze({
|
|
2740
2757
|
root: baseline,
|
|
@@ -2744,7 +2761,7 @@ async function withKnowledgeImprovementComparison(options, use) {
|
|
|
2744
2761
|
root: candidate,
|
|
2745
2762
|
hash: reference.candidateHash
|
|
2746
2763
|
})
|
|
2747
|
-
}))))));
|
|
2764
|
+
})), state.stateScope), state.stateScope), state.stateScope));
|
|
2748
2765
|
});
|
|
2749
2766
|
}
|
|
2750
2767
|
/** Use the frozen candidate side of one measured comparison. */
|
|
@@ -2756,8 +2773,9 @@ async function withKnowledgeImprovementCandidate(options, use) {
|
|
|
2756
2773
|
return withMeasuredCandidateSnapshot(options.root, runDir, state, candidateRef, (resolved) => withIsolatedKnowledgeCopy(resolved.root, candidateRef.candidateHash, "candidate", (root) => use(Object.freeze({
|
|
2757
2774
|
root,
|
|
2758
2775
|
candidate: candidateRef,
|
|
2776
|
+
stateScope: Object.freeze(normalizeKnowledgeStateScope(state.stateScope)),
|
|
2759
2777
|
evaluation: immutableJsonValue(structuredClone(resolved.evidence.evaluation))
|
|
2760
|
-
}))));
|
|
2778
|
+
})), state.stateScope));
|
|
2761
2779
|
});
|
|
2762
2780
|
}
|
|
2763
2781
|
function candidateRefFor(runId, state, candidate) {
|
|
@@ -2786,24 +2804,24 @@ async function withMeasuredCandidateSnapshot(liveRoot, runDir, state, candidateR
|
|
|
2786
2804
|
if (canonicalJson(candidateRefFor(candidateRef.runId, state, candidate)) !== canonicalJson(candidateRef)) throw new Error("knowledge candidate approval does not match the measured candidate");
|
|
2787
2805
|
const evidence = await assertCandidateEvidence(runDir, candidateRef, state.implementationRef);
|
|
2788
2806
|
return withSafeDirectory(runDir, join("candidates", candidate.candidateId, "snapshots", candidateRef.candidateHash), false, async (root) => {
|
|
2789
|
-
if (await hashKnowledgeBase(root) !== candidateRef.candidateHash) throw new Error("knowledge candidate snapshot changed after approval");
|
|
2807
|
+
if (await hashKnowledgeBase(root, state.stateScope) !== candidateRef.candidateHash) throw new Error("knowledge candidate snapshot changed after approval");
|
|
2790
2808
|
const result = await use({
|
|
2791
2809
|
root,
|
|
2792
2810
|
candidate,
|
|
2793
2811
|
evidence
|
|
2794
2812
|
});
|
|
2795
|
-
if (await hashKnowledgeBase(root) !== candidateRef.candidateHash) throw new Error("knowledge candidate snapshot changed during use");
|
|
2813
|
+
if (await hashKnowledgeBase(root, state.stateScope) !== candidateRef.candidateHash) throw new Error("knowledge candidate snapshot changed during use");
|
|
2796
2814
|
return result;
|
|
2797
2815
|
});
|
|
2798
2816
|
}
|
|
2799
|
-
async function withIsolatedKnowledgeCopy(sourceRoot, expectedHash, target, use) {
|
|
2817
|
+
async function withIsolatedKnowledgeCopy(sourceRoot, expectedHash, target, use, scope) {
|
|
2800
2818
|
const isolationRoot = await mkdtemp(join(tmpdir(), "agent-knowledge-snapshot-"));
|
|
2801
2819
|
const snapshotRoot = join(isolationRoot, "snapshot");
|
|
2802
2820
|
try {
|
|
2803
|
-
await copyKnowledgeWorkspace(sourceRoot, snapshotRoot);
|
|
2804
|
-
if (await hashKnowledgeBase(snapshotRoot) !== expectedHash) throw new Error(`isolated knowledge ${target} does not match its measured content`);
|
|
2821
|
+
await copyKnowledgeWorkspace(sourceRoot, snapshotRoot, scope);
|
|
2822
|
+
if (await hashKnowledgeBase(snapshotRoot, scope) !== expectedHash) throw new Error(`isolated knowledge ${target} does not match its measured content`);
|
|
2805
2823
|
const result = await use(snapshotRoot);
|
|
2806
|
-
if (await hashKnowledgeBase(snapshotRoot) !== expectedHash) throw new Error(`knowledge ${target} snapshot changed during use`);
|
|
2824
|
+
if (await hashKnowledgeBase(snapshotRoot, scope) !== expectedHash) throw new Error(`knowledge ${target} snapshot changed during use`);
|
|
2807
2825
|
return result;
|
|
2808
2826
|
} finally {
|
|
2809
2827
|
await rm(isolationRoot, {
|
|
@@ -2828,7 +2846,7 @@ async function assertStateIdentity(root, candidateRef, state) {
|
|
|
2828
2846
|
async function createCandidateWorkspace(runDir, state, root, now) {
|
|
2829
2847
|
const iteration = state.candidates.length + 1;
|
|
2830
2848
|
const candidateId = stableId("kcand", `${state.runId}:${iteration}:${now().toISOString()}`);
|
|
2831
|
-
await copyKnowledgeWorkspace(root, candidateWorkspacePath(runDir, candidateId));
|
|
2849
|
+
await copyKnowledgeWorkspace(root, candidateWorkspacePath(runDir, candidateId), state.stateScope);
|
|
2832
2850
|
const createdAt = now().toISOString();
|
|
2833
2851
|
return {
|
|
2834
2852
|
iteration,
|
|
@@ -2845,10 +2863,10 @@ function candidateWorkspacePath(runDir, candidateId) {
|
|
|
2845
2863
|
function baselineSnapshotPath(runDir) {
|
|
2846
2864
|
return join(runDir, "baseline");
|
|
2847
2865
|
}
|
|
2848
|
-
async function createBaselineSnapshot(runDir, root, expectedHash) {
|
|
2866
|
+
async function createBaselineSnapshot(runDir, root, expectedHash, scope) {
|
|
2849
2867
|
const target = baselineSnapshotPath(runDir);
|
|
2850
2868
|
try {
|
|
2851
|
-
await assertBaselineSnapshot(runDir, expectedHash);
|
|
2869
|
+
await assertBaselineSnapshot(runDir, expectedHash, scope);
|
|
2852
2870
|
return;
|
|
2853
2871
|
} catch (error) {
|
|
2854
2872
|
if (!isMissingFile(error)) throw error;
|
|
@@ -2856,8 +2874,8 @@ async function createBaselineSnapshot(runDir, root, expectedHash) {
|
|
|
2856
2874
|
const preparation = await mkdtemp(join(runDir, "baseline-prepare-"));
|
|
2857
2875
|
let activated = false;
|
|
2858
2876
|
try {
|
|
2859
|
-
await copyKnowledgeWorkspace(root, preparation);
|
|
2860
|
-
const actualHash = await hashKnowledgeBase(preparation);
|
|
2877
|
+
await copyKnowledgeWorkspace(root, preparation, scope);
|
|
2878
|
+
const actualHash = await hashKnowledgeBase(preparation, scope);
|
|
2861
2879
|
if (actualHash !== expectedHash) throw new Error(`knowledge base changed while baseline was frozen: expected ${expectedHash}, got ${actualHash}`);
|
|
2862
2880
|
await renameDurable(preparation, target);
|
|
2863
2881
|
activated = true;
|
|
@@ -2868,35 +2886,35 @@ async function createBaselineSnapshot(runDir, root, expectedHash) {
|
|
|
2868
2886
|
});
|
|
2869
2887
|
}
|
|
2870
2888
|
}
|
|
2871
|
-
async function ensureBaselineSnapshot(runDir, root, expectedHash) {
|
|
2889
|
+
async function ensureBaselineSnapshot(runDir, root, expectedHash, scope) {
|
|
2872
2890
|
try {
|
|
2873
|
-
await assertBaselineSnapshot(runDir, expectedHash);
|
|
2891
|
+
await assertBaselineSnapshot(runDir, expectedHash, scope);
|
|
2874
2892
|
} catch (error) {
|
|
2875
2893
|
if (!isMissingFile(error)) throw error;
|
|
2876
|
-
if (await hashKnowledgeBase(root) !== expectedHash) throw new Error("knowledge improvement baseline snapshot is missing and cannot be reconstructed");
|
|
2877
|
-
await createBaselineSnapshot(runDir, root, expectedHash);
|
|
2894
|
+
if (await hashKnowledgeBase(root, scope) !== expectedHash) throw new Error("knowledge improvement baseline snapshot is missing and cannot be reconstructed");
|
|
2895
|
+
await createBaselineSnapshot(runDir, root, expectedHash, scope);
|
|
2878
2896
|
}
|
|
2879
2897
|
}
|
|
2880
|
-
async function assertBaselineSnapshot(runDir, expectedHash) {
|
|
2881
|
-
await withBaselineSnapshot(runDir, expectedHash, () => void 0);
|
|
2898
|
+
async function assertBaselineSnapshot(runDir, expectedHash, scope) {
|
|
2899
|
+
await withBaselineSnapshot(runDir, expectedHash, () => void 0, scope);
|
|
2882
2900
|
}
|
|
2883
|
-
async function withBaselineSnapshot(runDir, expectedHash, use) {
|
|
2901
|
+
async function withBaselineSnapshot(runDir, expectedHash, use, scope) {
|
|
2884
2902
|
return withSafeDirectory(runDir, "baseline", false, async (baselineRoot) => {
|
|
2885
|
-
const actualHash = await hashKnowledgeBase(baselineRoot);
|
|
2903
|
+
const actualHash = await hashKnowledgeBase(baselineRoot, scope);
|
|
2886
2904
|
if (actualHash !== expectedHash) throw new Error(`knowledge improvement baseline changed: expected ${expectedHash}, got ${actualHash}`);
|
|
2887
2905
|
return use(baselineRoot);
|
|
2888
2906
|
});
|
|
2889
2907
|
}
|
|
2890
|
-
async function withFrozenCandidateWorkspace(runDir, candidate, candidateRoot, use) {
|
|
2908
|
+
async function withFrozenCandidateWorkspace(runDir, candidate, candidateRoot, use, scope) {
|
|
2891
2909
|
return withSafeDirectory(runDir, join("candidates", safePathSegmentSchema.parse(candidate.candidateId), "snapshots"), true, async (snapshotsDir) => {
|
|
2892
2910
|
const preparation = await mkdtemp(join(snapshotsDir, "prepare-"));
|
|
2893
2911
|
let activated = false;
|
|
2894
2912
|
try {
|
|
2895
|
-
await copyKnowledgeWorkspace(candidateRoot, preparation);
|
|
2896
|
-
const hash = await hashKnowledgeBase(preparation);
|
|
2913
|
+
await copyKnowledgeWorkspace(candidateRoot, preparation, scope);
|
|
2914
|
+
const hash = await hashKnowledgeBase(preparation, scope);
|
|
2897
2915
|
try {
|
|
2898
2916
|
const result = await withSafeDirectory(snapshotsDir, hash, false, async (existing) => {
|
|
2899
|
-
if (await hashKnowledgeBase(existing) !== hash) throw new Error("knowledge candidate snapshot does not match its content identity");
|
|
2917
|
+
if (await hashKnowledgeBase(existing, scope) !== hash) throw new Error("knowledge candidate snapshot does not match its content identity");
|
|
2900
2918
|
return use({
|
|
2901
2919
|
root: existing,
|
|
2902
2920
|
hash
|
|
@@ -2930,17 +2948,27 @@ function clearCandidateMeasurement(candidate) {
|
|
|
2930
2948
|
delete candidate.evidenceHash;
|
|
2931
2949
|
delete candidate.promotionPlanHash;
|
|
2932
2950
|
}
|
|
2933
|
-
async function copyKnowledgeWorkspace(sourceRoot, targetRoot) {
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2951
|
+
async function copyKnowledgeWorkspace(sourceRoot, targetRoot, scope) {
|
|
2952
|
+
const normalized = normalizeKnowledgeStateScope(scope);
|
|
2953
|
+
await withKnowledgeRead(sourceRoot, async () => {
|
|
2954
|
+
await rm(targetRoot, {
|
|
2955
|
+
recursive: true,
|
|
2956
|
+
force: true
|
|
2957
|
+
});
|
|
2958
|
+
await mkdir(join(targetRoot, normalized.pagesDirectory), { recursive: true });
|
|
2959
|
+
await mkdir(join(targetRoot, "raw", "sources"), { recursive: true });
|
|
2960
|
+
for (const path of knowledgeScopePaths(normalized)) await copyIfExists(join(sourceRoot, path), join(targetRoot, path));
|
|
2937
2961
|
});
|
|
2938
|
-
await
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2962
|
+
await writeKnowledgeIndex(targetRoot, { pagesDirectory: normalized.pagesDirectory });
|
|
2963
|
+
}
|
|
2964
|
+
function knowledgeScopePaths(scope) {
|
|
2965
|
+
const normalized = normalizeKnowledgeStateScope(scope);
|
|
2966
|
+
return [
|
|
2967
|
+
normalized.pagesDirectory,
|
|
2968
|
+
"raw",
|
|
2969
|
+
".agent-knowledge/sources.json",
|
|
2970
|
+
...normalized.researchState ? KNOWLEDGE_RESEARCH_STATE_PATHS : []
|
|
2971
|
+
];
|
|
2944
2972
|
}
|
|
2945
2973
|
async function copyIfExists(source, target) {
|
|
2946
2974
|
let sourceStat;
|
|
@@ -2957,28 +2985,29 @@ async function copyIfExists(source, target) {
|
|
|
2957
2985
|
dereference: false
|
|
2958
2986
|
});
|
|
2959
2987
|
}
|
|
2960
|
-
async function hashKnowledgeBase(root) {
|
|
2961
|
-
return withKnowledgeRead(root, () => hashKnowledgeBaseUnlocked(root));
|
|
2988
|
+
async function hashKnowledgeBase(root, scope) {
|
|
2989
|
+
return withKnowledgeRead(root, () => hashKnowledgeBaseUnlocked(root, scope));
|
|
2962
2990
|
}
|
|
2963
|
-
async function hashKnowledgeBaseUnlocked(root) {
|
|
2964
|
-
const
|
|
2965
|
-
|
|
2991
|
+
async function hashKnowledgeBaseUnlocked(root, scope) {
|
|
2992
|
+
const normalized = normalizeKnowledgeStateScope(scope);
|
|
2993
|
+
const files = (await knowledgeHashEntries(root, normalized)).map(({ path, hash, mode }) => ({
|
|
2966
2994
|
path,
|
|
2967
2995
|
hash,
|
|
2968
2996
|
mode
|
|
2969
|
-
}))
|
|
2997
|
+
}));
|
|
2998
|
+
return sha256(JSON.stringify(normalized.pagesDirectory === "knowledge" && !normalized.researchState ? files : {
|
|
2999
|
+
scope: normalized,
|
|
3000
|
+
files
|
|
3001
|
+
}));
|
|
2970
3002
|
}
|
|
2971
|
-
async function knowledgeHashEntries(root) {
|
|
3003
|
+
async function knowledgeHashEntries(root, scope) {
|
|
2972
3004
|
const entries = [];
|
|
2973
|
-
for (const
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
try {
|
|
2980
|
-
const file = await readRegularFileWithinRoot(root, sourceRegistry);
|
|
2981
|
-
entries.push(knowledgeFileIdentity(sourceRegistry, file.bytes, file.mode));
|
|
3005
|
+
for (const path of knowledgeScopePaths(scope ?? {})) try {
|
|
3006
|
+
const files = path === ".agent-knowledge/sources.json" || path === ".agent-knowledge/events.json" ? [{
|
|
3007
|
+
...await readRegularFileWithinRoot(root, path),
|
|
3008
|
+
path
|
|
3009
|
+
}] : await listRegularFilesWithinRoot(root, path);
|
|
3010
|
+
for (const file of files) entries.push(knowledgeFileIdentity(file.path, file.bytes, file.mode));
|
|
2982
3011
|
} catch (error) {
|
|
2983
3012
|
if (!isMissingFile(error)) throw error;
|
|
2984
3013
|
}
|
|
@@ -3054,7 +3083,7 @@ async function applyKnowledgeCandidateTarget(input, target) {
|
|
|
3054
3083
|
if (existingActivation) {
|
|
3055
3084
|
if (recovery?.direction === "rollback") throw new Error("stored knowledge activation result conflicts with a pending rollback");
|
|
3056
3085
|
if (recovery) {
|
|
3057
|
-
if (await hashKnowledgeBase(input.root) !== existingActivation.mutation.afterHash) throw new Error("stored knowledge activation result does not match the recovered files");
|
|
3086
|
+
if (await hashKnowledgeBase(input.root, state.stateScope) !== existingActivation.mutation.afterHash) throw new Error("stored knowledge activation result does not match the recovered files");
|
|
3058
3087
|
await finishKnowledgeFileTransaction({
|
|
3059
3088
|
root: input.root,
|
|
3060
3089
|
transactionRoot,
|
|
@@ -3079,7 +3108,7 @@ async function applyKnowledgeCandidateTarget(input, target) {
|
|
|
3079
3108
|
});
|
|
3080
3109
|
const recovered = recovery?.direction === "apply" ? recovery : void 0;
|
|
3081
3110
|
let pending = input.activation && recovered ? recovered.transaction : null;
|
|
3082
|
-
const currentHash = await hashKnowledgeBase(input.root);
|
|
3111
|
+
const currentHash = await hashKnowledgeBase(input.root, state.stateScope);
|
|
3083
3112
|
let transactionId = recovered?.transactionId ?? null;
|
|
3084
3113
|
if (recovered && currentHash !== desiredHash) throw new Error(`recovered knowledge ${action} does not match the approved target`);
|
|
3085
3114
|
if (state.status === "promoted" && state.promotedCandidateId !== candidate.candidateId) throw new Error(`knowledge run already promoted '${state.promotedCandidateId ?? "unknown"}'`);
|
|
@@ -3106,22 +3135,23 @@ async function applyKnowledgeCandidateTarget(input, target) {
|
|
|
3106
3135
|
pending = await withMeasuredCandidateSnapshot(input.root, runDir, state, candidateRef, (resolved) => withBaselineSnapshot(runDir, state.baseHash, async (baselineRoot) => {
|
|
3107
3136
|
const sourceRoot = target === "candidate" ? baselineRoot : resolved.root;
|
|
3108
3137
|
const targetRoot = target === "candidate" ? resolved.root : baselineRoot;
|
|
3109
|
-
const plan = await knowledgeFilePlanEntries(sourceRoot, targetRoot);
|
|
3110
|
-
assertCandidateTransitionPlan(plan, candidateRef, target);
|
|
3138
|
+
const plan = await knowledgeFilePlanEntries(sourceRoot, targetRoot, state.stateScope);
|
|
3139
|
+
assertCandidateTransitionPlan(plan, candidateRef, target, state.stateScope);
|
|
3111
3140
|
return prepareKnowledgeFileTransaction({
|
|
3112
3141
|
root: input.root,
|
|
3113
3142
|
transactionRoot,
|
|
3114
3143
|
purpose,
|
|
3144
|
+
...normalizeKnowledgeStateScope(state.stateScope),
|
|
3115
3145
|
recoveryOwner,
|
|
3116
3146
|
mutations: await knowledgePlanMutations(targetRoot, plan),
|
|
3117
3147
|
includeUnchanged: true,
|
|
3118
3148
|
now: input.now
|
|
3119
3149
|
});
|
|
3120
|
-
}));
|
|
3150
|
+
}, state.stateScope));
|
|
3121
3151
|
if (!pending) throw new Error(`knowledge ${action} plan unexpectedly contained no file changes`);
|
|
3122
3152
|
transactionId = pending.transactionId;
|
|
3123
3153
|
try {
|
|
3124
|
-
assertCandidateTransitionTransaction(pending, candidateRef, target);
|
|
3154
|
+
assertCandidateTransitionTransaction(pending, candidateRef, target, state.stateScope);
|
|
3125
3155
|
} catch (error) {
|
|
3126
3156
|
try {
|
|
3127
3157
|
await rollbackKnowledgeFileTransaction({
|
|
@@ -3150,8 +3180,8 @@ async function applyKnowledgeCandidateTarget(input, target) {
|
|
|
3150
3180
|
beforeCommit: assertOwned
|
|
3151
3181
|
});
|
|
3152
3182
|
assertOwned();
|
|
3153
|
-
if (await hashKnowledgeBase(input.root) !== desiredHash) throw new Error(`knowledge ${action} content does not match the approved target`);
|
|
3154
|
-
await writeKnowledgeIndex(input.root);
|
|
3183
|
+
if (await hashKnowledgeBase(input.root, state.stateScope) !== desiredHash) throw new Error(`knowledge ${action} content does not match the approved target`);
|
|
3184
|
+
await writeKnowledgeIndex(input.root, state.stateScope);
|
|
3155
3185
|
} catch (error) {
|
|
3156
3186
|
if (!pending) throw error;
|
|
3157
3187
|
if (recovered && input.activation) throw error;
|
|
@@ -3173,7 +3203,7 @@ async function applyKnowledgeCandidateTarget(input, target) {
|
|
|
3173
3203
|
transaction: pending,
|
|
3174
3204
|
assertOwned
|
|
3175
3205
|
});
|
|
3176
|
-
await writeKnowledgeIndex(input.root);
|
|
3206
|
+
await writeKnowledgeIndex(input.root, state.stateScope);
|
|
3177
3207
|
} catch (rollbackError) {
|
|
3178
3208
|
throw new AggregateError([error, rollbackError], `knowledge ${action} failed and could not restore the previous files`);
|
|
3179
3209
|
}
|
|
@@ -3188,7 +3218,7 @@ async function applyKnowledgeCandidateTarget(input, target) {
|
|
|
3188
3218
|
state.updatedAt = input.now().toISOString();
|
|
3189
3219
|
await saveState(runDir, state, input.onState);
|
|
3190
3220
|
await ensureCandidateTransitionEvent(runDir, candidateRef, target);
|
|
3191
|
-
let finalHash = await hashKnowledgeBase(input.root);
|
|
3221
|
+
let finalHash = await hashKnowledgeBase(input.root, state.stateScope);
|
|
3192
3222
|
if (finalHash !== desiredHash) throw new Error(`knowledge ${action} changed before its result was returned`);
|
|
3193
3223
|
const mutation = Object.freeze({
|
|
3194
3224
|
target,
|
|
@@ -3199,14 +3229,14 @@ async function applyKnowledgeCandidateTarget(input, target) {
|
|
|
3199
3229
|
recovered: recovered !== void 0
|
|
3200
3230
|
});
|
|
3201
3231
|
const activationResult = input.activation ? await persistKnowledgeActivationResult(runDir, candidateRef, input.activation, target, mutation) : void 0;
|
|
3202
|
-
if (await hashKnowledgeBase(input.root) !== finalHash) throw new Error(`knowledge ${action} changed while its result was persisted`);
|
|
3232
|
+
if (await hashKnowledgeBase(input.root, state.stateScope) !== finalHash) throw new Error(`knowledge ${action} changed while its result was persisted`);
|
|
3203
3233
|
if (pending) await finishKnowledgeFileTransaction({
|
|
3204
3234
|
root: input.root,
|
|
3205
3235
|
transactionRoot,
|
|
3206
3236
|
transaction: pending,
|
|
3207
3237
|
assertOwned
|
|
3208
3238
|
});
|
|
3209
|
-
finalHash = await hashKnowledgeBase(input.root);
|
|
3239
|
+
finalHash = await hashKnowledgeBase(input.root, state.stateScope);
|
|
3210
3240
|
if (finalHash !== desiredHash) throw new Error(`knowledge ${action} changed before its result was returned`);
|
|
3211
3241
|
return candidateTransitionResult(input, candidate, target === "candidate", false, mutation, activationResult);
|
|
3212
3242
|
}, {
|
|
@@ -3214,7 +3244,7 @@ async function applyKnowledgeCandidateTarget(input, target) {
|
|
|
3214
3244
|
resumeTransaction: {
|
|
3215
3245
|
purpose,
|
|
3216
3246
|
recoveryOwner,
|
|
3217
|
-
validate: (transaction) => assertCandidateTransitionTransaction(transaction, candidateRef, target),
|
|
3247
|
+
validate: (transaction) => assertCandidateTransitionTransaction(transaction, candidateRef, target, state.stateScope),
|
|
3218
3248
|
deferFinish: input.activation !== void 0
|
|
3219
3249
|
}
|
|
3220
3250
|
});
|
|
@@ -3262,12 +3292,12 @@ function knowledgeCandidateTransitionPurpose(candidate, implementationRef, targe
|
|
|
3262
3292
|
implementationRef
|
|
3263
3293
|
})}`;
|
|
3264
3294
|
}
|
|
3265
|
-
async function knowledgeFilePlanEntries(sourceRoot, targetRoot) {
|
|
3266
|
-
const [before, after] = await Promise.all([knowledgeHashEntries(sourceRoot), knowledgeHashEntries(targetRoot)]);
|
|
3295
|
+
async function knowledgeFilePlanEntries(sourceRoot, targetRoot, scope) {
|
|
3296
|
+
const [before, after] = await Promise.all([knowledgeHashEntries(sourceRoot, scope), knowledgeHashEntries(targetRoot, scope)]);
|
|
3267
3297
|
const beforeByPath = new Map(before.map((entry) => [entry.path, entry]));
|
|
3268
3298
|
const afterByPath = new Map(after.map((entry) => [entry.path, entry]));
|
|
3269
3299
|
return [.../* @__PURE__ */ new Set([...before.map((entry) => entry.path), ...after.map((entry) => entry.path)])].sort((left, right) => left.localeCompare(right)).map((path) => {
|
|
3270
|
-
assertKnowledgeMutationPath(path,
|
|
3300
|
+
assertKnowledgeMutationPath(path, normalizeKnowledgeStateScope(scope).pagesDirectory, scope?.researchState);
|
|
3271
3301
|
const beforeEntry = beforeByPath.get(path);
|
|
3272
3302
|
const afterEntry = afterByPath.get(path);
|
|
3273
3303
|
return {
|
|
@@ -3294,12 +3324,12 @@ async function knowledgePlanMutations(targetRoot, plan) {
|
|
|
3294
3324
|
};
|
|
3295
3325
|
}));
|
|
3296
3326
|
}
|
|
3297
|
-
function assertCandidateTransitionPlan(plan, candidate, target) {
|
|
3298
|
-
const actualPlanHash = knowledgeFileTransactionPlanHash(target === "candidate" ? plan : reverseKnowledgeFilePlan(plan),
|
|
3327
|
+
function assertCandidateTransitionPlan(plan, candidate, target, scope) {
|
|
3328
|
+
const actualPlanHash = knowledgeFileTransactionPlanHash(target === "candidate" ? plan : reverseKnowledgeFilePlan(plan), normalizeKnowledgeStateScope(scope).pagesDirectory, scope?.researchState);
|
|
3299
3329
|
if (actualPlanHash !== candidate.promotionPlanHash) throw new Error(`knowledge candidate plan changed after approval: expected ${candidate.promotionPlanHash}, got ${actualPlanHash}`);
|
|
3300
3330
|
}
|
|
3301
|
-
function assertCandidateTransitionTransaction(transaction, candidate, target) {
|
|
3302
|
-
assertCandidateTransitionPlan(transaction.entries, candidate, target);
|
|
3331
|
+
function assertCandidateTransitionTransaction(transaction, candidate, target, scope) {
|
|
3332
|
+
assertCandidateTransitionPlan(transaction.entries, candidate, target, scope);
|
|
3303
3333
|
}
|
|
3304
3334
|
function reverseKnowledgeFilePlan(plan) {
|
|
3305
3335
|
return plan.map((entry) => ({
|
|
@@ -3335,6 +3365,7 @@ async function hasCandidateTransitionEvent(runDir, candidateRef, target) {
|
|
|
3335
3365
|
//#region src/kb-improvement/evaluation.ts
|
|
3336
3366
|
function assertKnowledgeImprovementOptions(options) {
|
|
3337
3367
|
assertImmutableRef(options.implementationRef, "knowledge improvement implementationRef");
|
|
3368
|
+
normalizeKnowledgeStateScope(options.stateScope);
|
|
3338
3369
|
for (const phase of options.requiredPhases ?? []) if (options.enabledPhases && !options.enabledPhases.includes(phase)) throw new Error(`required phase ${phase} is not enabled`);
|
|
3339
3370
|
if (options.answerQualityCostCeiling !== void 0 && (!Number.isFinite(options.answerQualityCostCeiling) || options.answerQualityCostCeiling < 0)) throw new Error("knowledge improvement answerQualityCostCeiling must be a non-negative finite number");
|
|
3340
3371
|
if (options.ragOptimization) assertImmutableRef(options.ragOptimization.executionRef, "knowledge improvement RAG executionRef");
|
|
@@ -3344,7 +3375,7 @@ function assertKnowledgeImprovementOptions(options) {
|
|
|
3344
3375
|
}
|
|
3345
3376
|
async function measureCandidate(runId, runDir, state, candidate, options, now) {
|
|
3346
3377
|
return withCandidateWorkspace(runDir, candidate, async (candidateRoot) => {
|
|
3347
|
-
const currentCandidateHash = await hashKnowledgeBase(candidateRoot);
|
|
3378
|
+
const currentCandidateHash = await hashKnowledgeBase(candidateRoot, options.stateScope);
|
|
3348
3379
|
if (candidate.status === "candidate-ready" && candidate.candidateHash === currentCandidateHash && candidate.evidenceHash !== void 0 && candidate.promotionPlanHash !== void 0) {
|
|
3349
3380
|
const evidence = await assertCandidateEvidence(runDir, candidateRefFor(runId, state, candidate), state.implementationRef);
|
|
3350
3381
|
return {
|
|
@@ -3379,7 +3410,7 @@ async function measureCandidate(runId, runDir, state, candidate, options, now) {
|
|
|
3379
3410
|
...lifecycle ? { lifecycle } : {},
|
|
3380
3411
|
finalEvaluated: true
|
|
3381
3412
|
};
|
|
3382
|
-
});
|
|
3413
|
+
}, options.stateScope);
|
|
3383
3414
|
});
|
|
3384
3415
|
}
|
|
3385
3416
|
async function runCandidateUpdateLifecycle(runId, candidate, candidateRoot, options, now) {
|
|
@@ -3398,7 +3429,7 @@ async function runCandidateUpdateLifecycle(runId, candidate, candidateRoot, opti
|
|
|
3398
3429
|
}
|
|
3399
3430
|
async function runCandidateEvaluationLifecycle(runId, runDir, candidate, candidateRoot, candidateHash, lifecycle, options, now) {
|
|
3400
3431
|
if (!shouldRunEvaluationStage(options)) return void 0;
|
|
3401
|
-
const candidateIndex = await buildKnowledgeIndex(candidateRoot);
|
|
3432
|
+
const candidateIndex = await buildKnowledgeIndex(candidateRoot, options.stateScope);
|
|
3402
3433
|
return withBaselineSnapshot(runDir, candidate.baseHash, (baselineRoot) => runRagKnowledgeImprovementPhases({
|
|
3403
3434
|
goal: options.goal,
|
|
3404
3435
|
optimization: options.ragOptimization ? {
|
|
@@ -3430,7 +3461,7 @@ async function runCandidateEvaluationLifecycle(runId, runDir, candidate, candida
|
|
|
3430
3461
|
requiredPhases: selectedStageRequiredPhases(options, EVALUATION_PHASES),
|
|
3431
3462
|
signal: options.signal,
|
|
3432
3463
|
now
|
|
3433
|
-
}, lifecycle));
|
|
3464
|
+
}, lifecycle), options.stateScope);
|
|
3434
3465
|
}
|
|
3435
3466
|
function candidateExecutionRef(executionRef, candidateHash) {
|
|
3436
3467
|
return `sha256:${sha256(`${executionRef}\n${candidateHash}`)}`;
|
|
@@ -3442,6 +3473,7 @@ function candidateKnowledgeResearchOptions(candidateRoot, options) {
|
|
|
3442
3473
|
return {
|
|
3443
3474
|
...rest,
|
|
3444
3475
|
root: candidateRoot,
|
|
3476
|
+
pagesDirectory: normalizeKnowledgeStateScope(options.stateScope).pagesDirectory,
|
|
3445
3477
|
step,
|
|
3446
3478
|
maxIterations: rest.maxIterations ?? (step ? options.candidateResearchIterations ?? 3 : void 0),
|
|
3447
3479
|
strict: rest.strict ?? options.strict,
|
|
@@ -3481,7 +3513,7 @@ function selectedStageRequiredPhases(options, stagePhases) {
|
|
|
3481
3513
|
}
|
|
3482
3514
|
async function evaluateCandidate(runDir, state, candidate, snapshot, lifecycle, options, now, useConfiguredEvaluator) {
|
|
3483
3515
|
return withBaselineSnapshot(runDir, state.baseHash, async (baselineRoot) => {
|
|
3484
|
-
const [baselineIndex, candidateIndex] = await Promise.all([buildKnowledgeIndex(baselineRoot), buildKnowledgeIndex(snapshot.root)]);
|
|
3516
|
+
const [baselineIndex, candidateIndex] = await Promise.all([buildKnowledgeIndex(baselineRoot, options.stateScope), buildKnowledgeIndex(snapshot.root, options.stateScope)]);
|
|
3485
3517
|
const validation = validateKnowledgeIndex(candidateIndex, { strict: options.strict });
|
|
3486
3518
|
const readiness = readinessFor(options, candidateIndex);
|
|
3487
3519
|
const kbQuality = scoreKnowledgeBaseIndex(candidateIndex, {
|
|
@@ -3506,10 +3538,10 @@ async function evaluateCandidate(runDir, state, candidate, snapshot, lifecycle,
|
|
|
3506
3538
|
lifecycle,
|
|
3507
3539
|
signal: options.signal
|
|
3508
3540
|
}) : void 0) ?? defaultKnowledgeImprovementMetric(validation, readiness, options.readinessSpecs, kbQuality, lifecycle))), lifecycle, options.answerQualityCostCeiling);
|
|
3509
|
-
const measuredHash = await hashKnowledgeBase(snapshot.root);
|
|
3541
|
+
const measuredHash = await hashKnowledgeBase(snapshot.root, options.stateScope);
|
|
3510
3542
|
if (measuredHash !== candidateHash) throw new Error(`knowledge candidate changed during evaluation: expected ${candidateHash}, got ${measuredHash}`);
|
|
3511
3543
|
candidate.candidateHash = candidateHash;
|
|
3512
|
-
candidate.promotionPlanHash = knowledgeFileTransactionPlanHash(await knowledgeFilePlanEntries(baselineRoot, snapshot.root),
|
|
3544
|
+
candidate.promotionPlanHash = knowledgeFileTransactionPlanHash(await knowledgeFilePlanEntries(baselineRoot, snapshot.root, options.stateScope), normalizeKnowledgeStateScope(options.stateScope).pagesDirectory, options.stateScope?.researchState);
|
|
3513
3545
|
const evidence = KnowledgeImprovementEvidenceSchema.parse(JSON.parse(JSON.stringify({
|
|
3514
3546
|
kind: "knowledge-improvement-evidence",
|
|
3515
3547
|
runId: state.runId,
|
|
@@ -3540,7 +3572,7 @@ async function evaluateCandidate(runDir, state, candidate, snapshot, lifecycle,
|
|
|
3540
3572
|
candidate,
|
|
3541
3573
|
evaluation
|
|
3542
3574
|
};
|
|
3543
|
-
});
|
|
3575
|
+
}, options.stateScope);
|
|
3544
3576
|
}
|
|
3545
3577
|
function defaultKnowledgeImprovementMetric(validation, readiness, readinessSpecs, kbQuality, lifecycle) {
|
|
3546
3578
|
const blockingMissing = readiness?.report.blockingMissingRequirements.length ?? 0;
|
|
@@ -3590,6 +3622,10 @@ function normalizeMetric(metric) {
|
|
|
3590
3622
|
//#region src/kb-improvement/run.ts
|
|
3591
3623
|
async function improveKnowledgeBase(options) {
|
|
3592
3624
|
assertExactCandidatePlatform();
|
|
3625
|
+
options = {
|
|
3626
|
+
...options,
|
|
3627
|
+
...options.stateScope === void 0 ? {} : { stateScope: Object.freeze(normalizeKnowledgeStateScope(options.stateScope)) }
|
|
3628
|
+
};
|
|
3593
3629
|
assertKnowledgeImprovementOptions(options);
|
|
3594
3630
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
3595
3631
|
const runId = runIdSchema.parse(options.runId ?? knowledgeImprovementRunId(options.root, options.goal));
|
|
@@ -3607,13 +3643,14 @@ async function improveKnowledgeBaseInRun(options, runId, runDir, now) {
|
|
|
3607
3643
|
throw error;
|
|
3608
3644
|
});
|
|
3609
3645
|
if (!state) {
|
|
3610
|
-
const baseHash = await hashKnowledgeBase(options.root);
|
|
3611
|
-
await createBaselineSnapshot(runDir, options.root, baseHash);
|
|
3646
|
+
const baseHash = await hashKnowledgeBase(options.root, options.stateScope);
|
|
3647
|
+
await createBaselineSnapshot(runDir, options.root, baseHash, options.stateScope);
|
|
3612
3648
|
state = {
|
|
3613
3649
|
runId,
|
|
3614
3650
|
root: options.root,
|
|
3615
3651
|
goal: options.goal,
|
|
3616
3652
|
implementationRef: options.implementationRef,
|
|
3653
|
+
...options.stateScope === void 0 ? {} : { stateScope: normalizeKnowledgeStateScope(options.stateScope) },
|
|
3617
3654
|
status: "running",
|
|
3618
3655
|
baseHash,
|
|
3619
3656
|
createdAt: now().toISOString(),
|
|
@@ -3628,6 +3665,7 @@ async function improveKnowledgeBaseInRun(options, runId, runDir, now) {
|
|
|
3628
3665
|
baseHash
|
|
3629
3666
|
});
|
|
3630
3667
|
}
|
|
3668
|
+
if (canonicalJson(normalizeKnowledgeStateScope(state.stateScope)) !== canonicalJson(normalizeKnowledgeStateScope(options.stateScope))) throw new Error("knowledge improvement state does not match the requested stateScope");
|
|
3631
3669
|
if (state.goal !== options.goal) throw new Error("knowledge improvement state does not match the requested goal");
|
|
3632
3670
|
if (state.implementationRef !== options.implementationRef) throw new Error("knowledge improvement state does not match the requested implementationRef");
|
|
3633
3671
|
const promotedCandidateId = state.promotedCandidateId;
|
|
@@ -3637,7 +3675,7 @@ async function improveKnowledgeBaseInRun(options, runId, runDir, now) {
|
|
|
3637
3675
|
const promoted = promotedCandidate;
|
|
3638
3676
|
const promotedState = state;
|
|
3639
3677
|
return withKnowledgeMutation(options.root, async () => {
|
|
3640
|
-
const currentHash = await hashKnowledgeBase(options.root);
|
|
3678
|
+
const currentHash = await hashKnowledgeBase(options.root, options.stateScope);
|
|
3641
3679
|
if (currentHash !== promoted.candidateHash) throw new Error(`promoted knowledge base changed: expected ${promoted.candidateHash}, got ${currentHash}`);
|
|
3642
3680
|
const evidence = await assertCandidateEvidence(runDir, candidateRefFor(runId, promotedState, promoted), promotedState.implementationRef);
|
|
3643
3681
|
return {
|
|
@@ -3651,7 +3689,7 @@ async function improveKnowledgeBaseInRun(options, runId, runDir, now) {
|
|
|
3651
3689
|
});
|
|
3652
3690
|
}
|
|
3653
3691
|
await withKnowledgeMutation(options.root, () => void 0);
|
|
3654
|
-
await ensureBaselineSnapshot(runDir, options.root, state.baseHash);
|
|
3692
|
+
await ensureBaselineSnapshot(runDir, options.root, state.baseHash, state.stateScope);
|
|
3655
3693
|
if (state.status === "blocked") return {
|
|
3656
3694
|
runId,
|
|
3657
3695
|
state,
|
|
@@ -3675,7 +3713,7 @@ async function improveKnowledgeBaseInRun(options, runId, runDir, now) {
|
|
|
3675
3713
|
};
|
|
3676
3714
|
}
|
|
3677
3715
|
if (!candidate) {
|
|
3678
|
-
const currentHash = await hashKnowledgeBase(options.root);
|
|
3716
|
+
const currentHash = await hashKnowledgeBase(options.root, options.stateScope);
|
|
3679
3717
|
if (currentHash !== state.baseHash) {
|
|
3680
3718
|
state = await blockRun(runDir, state, `base changed before candidate creation: expected ${state.baseHash}, got ${currentHash}`, options.onState, now);
|
|
3681
3719
|
return {
|
|
@@ -3686,7 +3724,7 @@ async function improveKnowledgeBaseInRun(options, runId, runDir, now) {
|
|
|
3686
3724
|
};
|
|
3687
3725
|
}
|
|
3688
3726
|
const activeState = state;
|
|
3689
|
-
candidate = await withBaselineSnapshot(runDir, activeState.baseHash, (baselineRoot) => createCandidateWorkspace(runDir, activeState, baselineRoot, now));
|
|
3727
|
+
candidate = await withBaselineSnapshot(runDir, activeState.baseHash, (baselineRoot) => createCandidateWorkspace(runDir, activeState, baselineRoot, now), state.stateScope);
|
|
3690
3728
|
state.candidates.push(candidate);
|
|
3691
3729
|
state.status = "running";
|
|
3692
3730
|
state.updatedAt = now().toISOString();
|
|
@@ -3769,7 +3807,7 @@ async function optimizeKnowledgeBasePolicy(options) {
|
|
|
3769
3807
|
if (typeof goal !== "string" || !goal.trim()) throw new Error("optimizeKnowledgeBasePolicy goal must be non-empty");
|
|
3770
3808
|
assertImmutableRef(policyApplicationRef, "optimizeKnowledgeBasePolicy policyApplicationRef");
|
|
3771
3809
|
if (candidateRunLabel !== void 0 && (typeof candidateRunLabel !== "string" || !candidateRunLabel.trim())) throw new Error("optimizeKnowledgeBasePolicy candidateRunLabel must be non-empty");
|
|
3772
|
-
const baseHash = await hashKnowledgeBase(root);
|
|
3810
|
+
const baseHash = await hashKnowledgeBase(root, candidate?.stateScope);
|
|
3773
3811
|
const optimization = await runSerializedKnowledgeOptimization({
|
|
3774
3812
|
...optimizationOptions,
|
|
3775
3813
|
executionRef: policyApplicationRef,
|
|
@@ -3780,7 +3818,7 @@ async function optimizeKnowledgeBasePolicy(options) {
|
|
|
3780
3818
|
finalScenarios
|
|
3781
3819
|
});
|
|
3782
3820
|
const winner = optimization.winner;
|
|
3783
|
-
const currentBaseHash = await hashKnowledgeBase(root);
|
|
3821
|
+
const currentBaseHash = await hashKnowledgeBase(root, candidate?.stateScope);
|
|
3784
3822
|
if (currentBaseHash !== baseHash) throw new Error(`knowledge base changed during policy optimization: expected ${baseHash}, got ${currentBaseHash}`);
|
|
3785
3823
|
const runId = stableId("kbpolicy", `${candidateRunLabel ?? "default"}:${goal}:${optimization.methodName}:${winner.surfaceHash}:${policyApplicationRef}:${baseHash}`);
|
|
3786
3824
|
return {
|
|
@@ -3818,10 +3856,13 @@ async function optimizeKnowledgeBasePolicy(options) {
|
|
|
3818
3856
|
}
|
|
3819
3857
|
//#endregion
|
|
3820
3858
|
//#region src/kb-improvement/selected-candidate.ts
|
|
3821
|
-
const DERIVED_KNOWLEDGE_PATHS = /* @__PURE__ */ new Set([`${KB_IMPROVEMENT_PAGES_DIRECTORY}/index.md`]);
|
|
3822
3859
|
const selectionPathSchema = z.string().min(1).transform((path, context) => {
|
|
3823
3860
|
try {
|
|
3824
|
-
|
|
3861
|
+
try {
|
|
3862
|
+
return assertKnowledgeMutationPath(path, KB_IMPROVEMENT_PAGES_DIRECTORY, true);
|
|
3863
|
+
} catch {
|
|
3864
|
+
return normalizePagesDirectory(path);
|
|
3865
|
+
}
|
|
3825
3866
|
} catch (error) {
|
|
3826
3867
|
context.addIssue({
|
|
3827
3868
|
code: "custom",
|
|
@@ -3881,11 +3922,13 @@ async function improveSelectedKnowledgeCandidate(options) {
|
|
|
3881
3922
|
root: options.root,
|
|
3882
3923
|
candidate: sourceCandidate
|
|
3883
3924
|
}, async (source) => {
|
|
3884
|
-
const
|
|
3885
|
-
|
|
3925
|
+
const scope = normalizeKnowledgeStateScope(source.stateScope);
|
|
3926
|
+
if (options.stateScope !== void 0 && canonicalJson(normalizeKnowledgeStateScope(options.stateScope)) !== canonicalJson(scope)) throw new Error("selected knowledge candidate stateScope differs from its source");
|
|
3927
|
+
const sourcePlan = await knowledgeFilePlanEntries(source.baseline.root, source.candidate.root, scope);
|
|
3928
|
+
const sourcePlanHash = knowledgeFileTransactionPlanHash(sourcePlan, scope.pagesDirectory, scope.researchState);
|
|
3886
3929
|
if (sourcePlanHash !== sourceCandidate.promotionPlanHash) throw new Error("source knowledge candidate plan no longer matches its measured identity");
|
|
3887
|
-
const changedSourcePlan = sourcePlan.filter(planEntryChanged).filter(notDerivedPath);
|
|
3888
|
-
const selectedPaths = normalizeSelectedPaths(options.selectedPaths, changedSourcePlan);
|
|
3930
|
+
const changedSourcePlan = sourcePlan.filter(planEntryChanged).filter((entry) => notDerivedPath(entry, scope));
|
|
3931
|
+
const selectedPaths = normalizeSelectedPaths(options.selectedPaths, changedSourcePlan, scope);
|
|
3889
3932
|
const selectionDigest = contentHash(immutableJson({
|
|
3890
3933
|
kind: "measured-knowledge-change-selection",
|
|
3891
3934
|
version: 1,
|
|
@@ -3911,11 +3954,12 @@ async function improveSelectedKnowledgeCandidate(options) {
|
|
|
3911
3954
|
if (!entry) throw new Error(`selected knowledge path disappeared: ${path}`);
|
|
3912
3955
|
return entry;
|
|
3913
3956
|
});
|
|
3914
|
-
const selectionMutationPlanHash = knowledgeFileTransactionPlanHash(selectedEntries,
|
|
3957
|
+
const selectionMutationPlanHash = knowledgeFileTransactionPlanHash(selectedEntries, scope.pagesDirectory, scope.researchState);
|
|
3915
3958
|
let lifecycleSelection;
|
|
3916
3959
|
const result = await improveKnowledgeBase({
|
|
3917
3960
|
...improvementOptions(options),
|
|
3918
3961
|
root: options.root,
|
|
3962
|
+
stateScope: scope,
|
|
3919
3963
|
goal: options.goal,
|
|
3920
3964
|
implementationRef: derivedImplementationRef,
|
|
3921
3965
|
runId,
|
|
@@ -3931,6 +3975,7 @@ async function improveSelectedKnowledgeCandidate(options) {
|
|
|
3931
3975
|
root: input.candidateRoot,
|
|
3932
3976
|
transactionRoot: lock.transactionRoot,
|
|
3933
3977
|
purpose,
|
|
3978
|
+
...scope,
|
|
3934
3979
|
recoveryOwner,
|
|
3935
3980
|
mutations: await selectionMutations(source.candidate.root, selectedEntries),
|
|
3936
3981
|
now: options.now
|
|
@@ -3951,17 +3996,17 @@ async function improveSelectedKnowledgeCandidate(options) {
|
|
|
3951
3996
|
});
|
|
3952
3997
|
}
|
|
3953
3998
|
}
|
|
3954
|
-
await writeKnowledgeIndex(input.candidateRoot);
|
|
3999
|
+
await writeKnowledgeIndex(input.candidateRoot, scope);
|
|
3955
4000
|
lock.assertOwned();
|
|
3956
4001
|
}, { resumeTransaction: {
|
|
3957
4002
|
purpose,
|
|
3958
4003
|
recoveryOwner,
|
|
3959
4004
|
validate: (transaction) => assertSelectionTransaction(transaction, selectionMutationPlanHash)
|
|
3960
4005
|
} });
|
|
3961
|
-
const selectedPlan = await knowledgeFilePlanEntries(source.baseline.root, input.candidateRoot);
|
|
3962
|
-
assertExactSelectedChanges(selectedPlan, selectedPaths);
|
|
3963
|
-
const selectedPlanHash = knowledgeFileTransactionPlanHash(selectedPlan,
|
|
3964
|
-
const selectedCandidateHash = await hashKnowledgeBase(input.candidateRoot);
|
|
4006
|
+
const selectedPlan = await knowledgeFilePlanEntries(source.baseline.root, input.candidateRoot, scope);
|
|
4007
|
+
assertExactSelectedChanges(selectedPlan, selectedPaths, scope);
|
|
4008
|
+
const selectedPlanHash = knowledgeFileTransactionPlanHash(selectedPlan, scope.pagesDirectory, scope.researchState);
|
|
4009
|
+
const selectedCandidateHash = await hashKnowledgeBase(input.candidateRoot, scope);
|
|
3965
4010
|
lifecycleSelection = measuredSelectionLifecycleSchema.parse({
|
|
3966
4011
|
kind: "measured-knowledge-change-selection",
|
|
3967
4012
|
version: 1,
|
|
@@ -4021,13 +4066,13 @@ function normalizeEvaluationPhases(phases, field) {
|
|
|
4021
4066
|
for (const phase of unique) if (phase === "knowledge-acquisition" || phase === "knowledge-update") throw new Error(`${field} cannot contain the selection-owned phase '${phase}'`);
|
|
4022
4067
|
return unique;
|
|
4023
4068
|
}
|
|
4024
|
-
function normalizeSelectedPaths(paths, changedPlan) {
|
|
4069
|
+
function normalizeSelectedPaths(paths, changedPlan, scope) {
|
|
4025
4070
|
const available = new Set(changedPlan.map((entry) => entry.path));
|
|
4026
4071
|
const selected = [];
|
|
4027
4072
|
const seen = /* @__PURE__ */ new Set();
|
|
4028
4073
|
for (const input of paths) {
|
|
4029
|
-
const path = selectionPathSchema.parse(input);
|
|
4030
|
-
if (
|
|
4074
|
+
const path = assertKnowledgeMutationPath(selectionPathSchema.parse(input), normalizeKnowledgeStateScope(scope).pagesDirectory, scope.researchState);
|
|
4075
|
+
if (!notDerivedPath({ path }, scope)) throw new Error(`derived knowledge path cannot be selected directly: ${path}`);
|
|
4031
4076
|
if (seen.has(path)) throw new Error(`selected knowledge path is repeated: ${path}`);
|
|
4032
4077
|
if (!available.has(path)) throw new Error(`selected knowledge path is not a changed source-candidate file: ${path}`);
|
|
4033
4078
|
seen.add(path);
|
|
@@ -4038,8 +4083,8 @@ function normalizeSelectedPaths(paths, changedPlan) {
|
|
|
4038
4083
|
function planEntryChanged(entry) {
|
|
4039
4084
|
return entry.beforeHash !== entry.afterHash || entry.beforeHash !== null && entry.afterHash !== null && entry.beforeMode !== entry.afterMode;
|
|
4040
4085
|
}
|
|
4041
|
-
function notDerivedPath(entry) {
|
|
4042
|
-
return
|
|
4086
|
+
function notDerivedPath(entry, scope) {
|
|
4087
|
+
return entry.path !== `${normalizeKnowledgeStateScope(scope).pagesDirectory}/index.md`;
|
|
4043
4088
|
}
|
|
4044
4089
|
async function selectionMutations(sourceCandidateRoot, entries) {
|
|
4045
4090
|
return Promise.all(entries.map(async (entry) => {
|
|
@@ -4057,10 +4102,10 @@ async function selectionMutations(sourceCandidateRoot, entries) {
|
|
|
4057
4102
|
}));
|
|
4058
4103
|
}
|
|
4059
4104
|
function assertSelectionTransaction(transaction, expectedPlanHash) {
|
|
4060
|
-
if (knowledgeFileTransactionPlanHash(transaction.entries,
|
|
4105
|
+
if (knowledgeFileTransactionPlanHash(transaction.entries, normalizePagesDirectory(transaction.pagesDirectory), transaction.researchState) !== expectedPlanHash) throw new Error("selected knowledge transaction does not match its approved path set");
|
|
4061
4106
|
}
|
|
4062
|
-
function assertExactSelectedChanges(plan, selectedPaths) {
|
|
4063
|
-
const actual = plan.filter(planEntryChanged).filter(notDerivedPath).map((entry) => entry.path).sort((left, right) => left.localeCompare(right));
|
|
4107
|
+
function assertExactSelectedChanges(plan, selectedPaths, scope) {
|
|
4108
|
+
const actual = plan.filter(planEntryChanged).filter((entry) => notDerivedPath(entry, scope)).map((entry) => entry.path).sort((left, right) => left.localeCompare(right));
|
|
4064
4109
|
if (canonicalJson(actual) !== canonicalJson(selectedPaths)) throw new Error(`selected knowledge candidate changed the wrong files: expected ${selectedPaths.join(", ") || "(none)"}, got ${actual.join(", ") || "(none)"}`);
|
|
4065
4110
|
}
|
|
4066
4111
|
async function persistSelectionReceipt(root, receipt) {
|
|
@@ -6582,6 +6627,17 @@ function isoTimestamp(value, label) {
|
|
|
6582
6627
|
}
|
|
6583
6628
|
//#endregion
|
|
6584
6629
|
//#region src/knowledge-tools.ts
|
|
6630
|
+
/**
|
|
6631
|
+
* Provider-neutral knowledge tools.
|
|
6632
|
+
*
|
|
6633
|
+
* Knowledge owns what each tool does; a runtime only transports the definitions
|
|
6634
|
+
* and the calls. The shape is `ToolDefinition` from `@tangle-network/agent-interface`,
|
|
6635
|
+
* so no provider vocabulary reaches this package and no knowledge behavior
|
|
6636
|
+
* reaches a provider adapter.
|
|
6637
|
+
*
|
|
6638
|
+
* Every search mints a retrieval receipt. Configured receipt capture also
|
|
6639
|
+
* persists the exact visibility snapshot before delivering the receipt.
|
|
6640
|
+
*/
|
|
6585
6641
|
const searchInput = z.object({
|
|
6586
6642
|
question: z.string().min(1),
|
|
6587
6643
|
limit: z.int().min(1).max(50).optional()
|
|
@@ -6606,6 +6662,8 @@ function createKnowledgeTools(options) {
|
|
|
6606
6662
|
...options.brief,
|
|
6607
6663
|
...input.limit === void 0 ? {} : { limit: input.limit }
|
|
6608
6664
|
});
|
|
6665
|
+
const visibility = createKnowledgeVisibilitySnapshot(chain);
|
|
6666
|
+
const visibilityArtifact = options.recordRetrieval ? await persistVisibility(stores.storePath(runId), visibility) : void 0;
|
|
6609
6667
|
const receipt = createKnowledgeRetrievalReceipt({
|
|
6610
6668
|
runId,
|
|
6611
6669
|
...options.actorId === void 0 ? {} : { actorId: options.actorId },
|
|
@@ -6615,7 +6673,8 @@ function createKnowledgeTools(options) {
|
|
|
6615
6673
|
version: options.retrieverVersion,
|
|
6616
6674
|
configDigest: brief.retrieverConfigDigest
|
|
6617
6675
|
},
|
|
6618
|
-
visibility
|
|
6676
|
+
visibility,
|
|
6677
|
+
...visibilityArtifact ? { visibilityArtifact } : {},
|
|
6619
6678
|
results: brief.results,
|
|
6620
6679
|
createdAt: options.now?.()
|
|
6621
6680
|
});
|
|
@@ -6680,6 +6739,24 @@ function tool(name, description, inputSchema, handler) {
|
|
|
6680
6739
|
handler: (input) => handler(inputSchema.parse(input))
|
|
6681
6740
|
};
|
|
6682
6741
|
}
|
|
6742
|
+
/** Snapshot artifacts are immutable evidence, separate from authoritative KB state. */
|
|
6743
|
+
async function persistVisibility(root, snapshot) {
|
|
6744
|
+
const bytes = encodeKnowledgeVisibilitySnapshot(snapshot);
|
|
6745
|
+
const path = `.agent-knowledge/retrieval-visibility/${snapshot.snapshotDigest.replace("sha256:", "")}.json`;
|
|
6746
|
+
await withKnowledgeMutation(root, async () => {
|
|
6747
|
+
try {
|
|
6748
|
+
const existing = await readRegularFileWithinRoot(root, path);
|
|
6749
|
+
if (!Buffer.from(existing.bytes).equals(Buffer.from(bytes))) throw new Error("stored knowledge visibility artifact does not match its content identity");
|
|
6750
|
+
} catch (error) {
|
|
6751
|
+
if (!isMissingFile(error)) throw error;
|
|
6752
|
+
await writeFileDurableWithinRoot(root, path, Buffer.from(bytes));
|
|
6753
|
+
}
|
|
6754
|
+
});
|
|
6755
|
+
return knowledgeVisibilityArtifactRef({
|
|
6756
|
+
uri: pathToFileURL(join(root, path)).href,
|
|
6757
|
+
bytes
|
|
6758
|
+
});
|
|
6759
|
+
}
|
|
6683
6760
|
//#endregion
|
|
6684
6761
|
//#region src/promotion.ts
|
|
6685
6762
|
/**
|
|
@@ -8047,6 +8124,6 @@ function buildSteerText(gaps, deepQuestions, invalidationTargets, minIndependent
|
|
|
8047
8124
|
return lines.join("\n");
|
|
8048
8125
|
}
|
|
8049
8126
|
//#endregion
|
|
8050
|
-
export { AgentMemoryHitSchema, AgentMemoryKindSchema, AgentMemoryLifecycleTimeoutError, AgentMemoryLifecycleUnsafeError, AgentMemoryScopeSchema, AgentMemoryWriteInputSchema, CHECKABLE_RUNG_THRESHOLD, CITES_INVALIDATED_FIELD, ClaimLedgerGoalConflictError, ClaimLedgerMigrationRequiredError, DEADLINE_EXIT_CODE, DEFAULT_KNOWLEDGE_BRIEF_LIMIT, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, DEFAULT_PAGES_DIRECTORY, 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, KNOWLEDGE_PROMOTIONS_DIRECTORY, KNOWLEDGE_PROMOTION_DIGEST_ALGORITHM, KNOWLEDGE_PROMOTION_SCHEMA_VERSION, KNOWLEDGE_RECEIPT_DIGEST_ALGORITHM, KNOWLEDGE_SEARCH_RETRIEVER_ID, KNOWLEDGE_USE_RECEIPT_SCHEMA_VERSION, KnowledgeBaseCandidateSchema, KnowledgeCitationAuditError, KnowledgeCitationResolutionError, KnowledgeDuplicateIntakeError, KnowledgeEventSchema, KnowledgeGraphEdgeSchema, KnowledgeGraphNodeSchema, KnowledgeImprovementCandidateRefSchema, KnowledgeImprovementEvidenceSchema, KnowledgeImprovementRunStateSchema, KnowledgeIndexSchema, KnowledgePageInvalidationSchema, KnowledgePageSchema, KnowledgePromotionError, KnowledgeProposalParseError, KnowledgeRelationGraphError, KnowledgeRelationGraphSchema, KnowledgeRelationNodeSchema, KnowledgeRelationSchema, KnowledgeVisibilityUnavailableError, MAX_RESPONSE_BYTES, MIN_REQUEST_GAP_MS, MemoryKbStore, POLITE_USER_AGENT, READINESS_SPEC_DEFAULTS, RUN_LINEAGE_BASENAME, ResearchClaimEvidenceSchema, ResearchClaimLedgerSchema, ResearchClaimRecordSchema, ResearchSourceVersionSchema, RouterError, SCAFFOLD_PAGE_BASENAMES, SourceAnchorSchema, SourceRecordSchema, UncheckableClaimError, WIKILINK_REGEX, __resetHttpThrottle, acquireAgentMemoryRunLease, addSourcePath, addSourceText, agentMemorySequenceJudge, applyKnowledgeWriteBlocks, applyKnowledgeWriteBlocksFile, applyRetrievalHoldout, applySessionStickyRetrievalHoldout, assertClaimLedgerId, assertCurrentRunCitationsResolved, assertDeepQuestionIntegrity, assertGradeableEvidence, assertKnowledgeCitationAudit, assertKnowledgeCitationsResolved, assertKnowledgeRetrievalMatchesVisibility, assertKnowledgeRetrievalMatchesVisibilityArtifact, assertKnowledgeWriteIntake, assertResearchClaimEvidenceIntegrity, assertResearchClaimLedgerIntegrity, assertRunScopedCitationsResolved, assertTrackedClaimIntegrity, auditCurrentRunCitations, auditKnowledgeCitations, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, buildEvalKnowledgeBundle, buildFirstPartyMemoryLifecycleBenchmarkCases, buildIndustryMemoryBenchmarkSmokeCases, buildIndustryRagBenchmarkSmokeCases, buildKnowledgeBenchmarkScenarios, buildKnowledgeBrief, buildKnowledgeGraph, buildKnowledgeIndex, buildKnowledgeLexicalIndex, buildKnowledgeRelationGraph, buildRetrievalBenchmarkCasesFromQrels, buildRetrievalEvalDispatch, calibrateRagAnswerJudge, canonicalPathsEqual, canonicalRelativeWithinRoot, canonicalizeUrl, chunkMarkdown, citedClaimKey, citedClaimOf, claimCheckKey, claimEvidenceId, claimId, claimSourceHost, compareAgentMemoryLearning, contentKey, createAdaptiveResearchDriver, createAgentMemoryBranch, createClaimDecorator, createClaimGroundingVerifier, createCollectionResearchDriver, createCornellLiiSource, createD1FreshnessStoreStub, createFileRunLineageAuthority, createFileSystemFreshnessStore, createFileSystemSearchProvider, createGraphitiMemoryAdapter, createInMemoryBenchmarkAdapter, createIrsPublicationsSource, createKnowledgeControlLoopAdapter, createKnowledgeEvent, createKnowledgeRetrievalDisposition, createKnowledgeRetrievalReceipt, createKnowledgeTools, createKnowledgeUseReceipt, createKnowledgeVisibilitySnapshot, createLocalDiscoveryDispatcher, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, createNoopMemoryBenchmarkAdapter, createPersistentResearchDrivingDriver, createRagAnswerQualityHook, createResearchDrivingDriver, createRunScopedStores, createStateSosSource, createTangleRouterClient, createVerifyingResearchDriver, createWebResearchWorker, decodeKnowledgeVisibilitySnapshot, deepQuestionId, defaultGetMemoryContext, defineReadinessSpec, detectChanges, detectNearDuplicatePages, deterministicRng, diagnoseRagAnswerFailure, emitRetrievalHoldoutBypass, emptyClaimLedger, encodeKnowledgeVisibilitySnapshot, evaluateKnowledgeBaseReadiness, explainKnowledgeTarget, extractLinks, extractWikilinks, firstMatch, forkAgentMemoryBranchSnapshot, formatFrontmatter, formatKnowledgeCitationReference, formatKnowledgeInvalidationProposal, fromAgentCandidateKnowledgeRef, gradeClaims, gradeCompanyAgainstText, gradeFactAgainstText, gradeFor, graphitiMemoryAdapterIdentity, groundClaimInText, hashKnowledgeBase, htmlToText, improveKnowledgeBase, improveSelectedKnowledgeCandidate, initKnowledgeBase, innerHtmlById, inspectKnowledgeIndex, inspectPendingKnowledgeMutation, investmentThesisSet, isKernelAnchoredPath, isKnowledgeMemoryBenchmarkCase, isKnowledgeMutationHeld, isKnowledgePagePath, isMissingFile, isReachable, isSafeKnowledgePath, isScaffoldPath, jsonCandidateCodec, jsonObjectCandidateCodec, kbIndexToText, knowledgeBenchmarkJudge, knowledgeCitationAuditFindings, knowledgeImprovementCandidateRef, knowledgeImprovementRunDir, knowledgeImprovementRunId, knowledgePageDigest, knowledgePageFromMarkdown, knowledgePageRelations, knowledgeReleaseReport, knowledgeVisibilityArtifactRef, layoutFor, lensDistribution, linkClaimContradictions, lintCurrentRunCitations, lintKnowledgeIndex, listRegularFilesWithinRoot, loadKnowledgeImprovementActivationResult, loadKnowledgeImprovementEvents, loadKnowledgeImprovementState, loadKnowledgePages, loadKnowledgePromotionRecord, loadSourceRegistry, looksLikeBlockPage, materialFactsSurfaced, materialFactsSurfacedInText, materializeRegisteredClaimEvidence, mediaTypeFor, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, mergeClaimLedgers, mergeTrackedClaims, neighbors, normalizeClaimText, normalizeExternalRagScores, normalizeLinkTarget, normalizePageText, normalizePagesDirectory, optimizeKnowledgeBasePolicy, originatedPages, parseFrontmatter, parseKnowledgeBenchmarkJsonl, parseKnowledgeBenchmarkQrels, parseKnowledgeCitationReference, parseKnowledgeWriteBlocks, partitionRetrievalScenarios, planInvalidationPropagation, politeFetch, promoteKnowledgeCandidate, promoteRunScopedPages, proposeFromFinding, proposeFromFindings, ragAnswerQualityJudge, readRegularFileNoFollow, readRegularFileWithinRoot, reciprocalRankFusion, recoverPendingKnowledgeMutation, relativeWithinRoot, removeDurable, renameDurable, renderKnowledgeBenchmarkReportMarkdown, renderMemoryContext, researchSourceVersionKey, resetRetrievalHoldoutRegistry, resolveKnowledgeCitation, resolveKnowledgeCitations, resolveMemoryCleanupTimeoutMs, resolveRunScopedCitation, resolveRunScopedCitations, respondToIndustryMemoryBenchmarkSmokeCase, respondToIndustryRagBenchmarkSmokeCase, restoreKnowledgeCandidateBaseline, retrievalConfigFromSurface, retrievalConfigSurface, retrievalHoldoutConfigHash, retrievalRecallJudge, runAgentMemoryExperiment, runAgentMemoryImprovement, runAgentMemoryLearningExperiment, runBoundedMemoryLifecycle, runDiscoveryLoop, runInKnowledgeMutationScope, runInvestmentThesisTask, runKnowledgeBenchmarkSuite, runKnowledgeResearchLoop, runMemoryAdapterBenchmark, runRagKnowledgeImprovementLoop, runRagOptimization, runRetrievalImprovementLoop, runSerializedKnowledgeOptimization, runVerifiedResearchLoop, scenarioContentFingerprint, scoreBm25, scoreKnowledgeBaseIndex, scoreKnowledgeBenchmarkArtifact, scoreMemoryBenchmarkArtifact, scoreRagAnswerArtifact, scoreRetrievalArtifact, searchKnowledge, searchKnowledgePages, sha256, sleepForMemoryRecovery, slugify, snapshotSourceTextInput, sourceMatchesGaps, sourceRegistryPath, stableId, stripFrontmatter, summarizeKnowledgeBenchmarkCampaign, syncDirectory, textSourceAdapter, textSourceId, thesisReadinessSpecs, toAgentCandidateKnowledgeRef, toDeepEvalTestCases, toOffPolicyTrajectory, toRagCheckerRecords, toRagasEvaluationRows, toTruLensRecords, tokenizeQuery, tokenizeText, totalMaterialFacts, triageSource, validateKnowledgeIndex, verdictFor, verifyGradeableEvidence, verifyKnowledgeRetrievalDisposition, verifyKnowledgeRetrievalReceipt, verifyKnowledgeUseReceipt, verifyKnowledgeVisibilitySnapshot, walk, withCitedClaim, withKnowledgeImprovementCandidate, withKnowledgeImprovementComparison, withKnowledgeMutation, withKnowledgeRead, withSafeDescendant, withSafeDirectory, writeFileDurable, writeFileDurableWithinRoot, writeJson, writeJsonDurable, writeJsonDurableWithinRoot, writeKnowledgeIndex, writeSourceRegistry };
|
|
8127
|
+
export { AgentMemoryHitSchema, AgentMemoryKindSchema, AgentMemoryLifecycleTimeoutError, AgentMemoryLifecycleUnsafeError, AgentMemoryScopeSchema, AgentMemoryWriteInputSchema, CHECKABLE_RUNG_THRESHOLD, CITES_INVALIDATED_FIELD, ClaimLedgerGoalConflictError, ClaimLedgerMigrationRequiredError, DEADLINE_EXIT_CODE, DEFAULT_KNOWLEDGE_BRIEF_LIMIT, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, DEFAULT_PAGES_DIRECTORY, 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, KNOWLEDGE_PROMOTIONS_DIRECTORY, KNOWLEDGE_PROMOTION_DIGEST_ALGORITHM, KNOWLEDGE_PROMOTION_SCHEMA_VERSION, KNOWLEDGE_RECEIPT_DIGEST_ALGORITHM, KNOWLEDGE_SEARCH_RETRIEVER_ID, KNOWLEDGE_USE_RECEIPT_SCHEMA_VERSION, KnowledgeBaseCandidateSchema, KnowledgeCitationAuditError, KnowledgeCitationResolutionError, KnowledgeDuplicateIntakeError, KnowledgeEventSchema, KnowledgeGraphEdgeSchema, KnowledgeGraphNodeSchema, KnowledgeImprovementCandidateRefSchema, KnowledgeImprovementEvidenceSchema, KnowledgeImprovementRunStateSchema, KnowledgeIndexSchema, KnowledgePageInvalidationSchema, KnowledgePageSchema, KnowledgePromotionError, KnowledgeProposalParseError, KnowledgeRelationGraphError, KnowledgeRelationGraphSchema, KnowledgeRelationNodeSchema, KnowledgeRelationSchema, KnowledgeVisibilityUnavailableError, MAX_RESPONSE_BYTES, MIN_REQUEST_GAP_MS, MemoryKbStore, POLITE_USER_AGENT, READINESS_SPEC_DEFAULTS, RUN_LINEAGE_BASENAME, ResearchClaimEvidenceSchema, ResearchClaimLedgerSchema, ResearchClaimRecordSchema, ResearchSourceVersionSchema, RouterError, SCAFFOLD_PAGE_BASENAMES, SourceAnchorSchema, SourceRecordSchema, UncheckableClaimError, WIKILINK_REGEX, __resetHttpThrottle, acquireAgentMemoryRunLease, addSourcePath, addSourceText, agentMemorySequenceJudge, applyKnowledgeWriteBlocks, applyKnowledgeWriteBlocksFile, applyRetrievalHoldout, applySessionStickyRetrievalHoldout, assertClaimLedgerId, assertCurrentRunCitationsResolved, assertDeepQuestionIntegrity, assertGradeableEvidence, assertKnowledgeCitationAudit, assertKnowledgeCitationsResolved, assertKnowledgeRetrievalMatchesVisibility, assertKnowledgeRetrievalMatchesVisibilityArtifact, assertKnowledgeWriteIntake, assertResearchClaimEvidenceIntegrity, assertResearchClaimLedgerIntegrity, assertRunScopedCitationsResolved, assertTrackedClaimIntegrity, auditCurrentRunCitations, auditKnowledgeCitations, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, buildEvalKnowledgeBundle, buildFirstPartyMemoryLifecycleBenchmarkCases, buildIndustryMemoryBenchmarkSmokeCases, buildIndustryRagBenchmarkSmokeCases, buildKnowledgeBenchmarkScenarios, buildKnowledgeBrief, buildKnowledgeGraph, buildKnowledgeIndex, buildKnowledgeLexicalIndex, buildKnowledgeRelationGraph, buildRetrievalBenchmarkCasesFromQrels, buildRetrievalEvalDispatch, calibrateRagAnswerJudge, canonicalPathsEqual, canonicalRelativeWithinRoot, canonicalizeUrl, chunkMarkdown, citedClaimKey, citedClaimOf, claimCheckKey, claimEvidenceId, claimId, claimSourceHost, compareAgentMemoryLearning, contentKey, createAdaptiveResearchDriver, createAgentMemoryBranch, createClaimDecorator, createClaimGroundingVerifier, createCollectionResearchDriver, createCornellLiiSource, createD1FreshnessStoreStub, createFileRunLineageAuthority, createFileSystemFreshnessStore, createFileSystemSearchProvider, createGraphitiMemoryAdapter, createInMemoryBenchmarkAdapter, createIrsPublicationsSource, createKnowledgeControlLoopAdapter, createKnowledgeEvent, createKnowledgeRetrievalDisposition, createKnowledgeRetrievalReceipt, createKnowledgeTools, createKnowledgeUseReceipt, createKnowledgeVisibilitySnapshot, createLocalDiscoveryDispatcher, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, createNoopMemoryBenchmarkAdapter, createPersistentResearchDrivingDriver, createRagAnswerQualityHook, createResearchDrivingDriver, createRunScopedStores, createStateSosSource, createTangleRouterClient, createVerifyingResearchDriver, createWebResearchWorker, decodeKnowledgeVisibilitySnapshot, deepQuestionId, defaultGetMemoryContext, defineReadinessSpec, detectChanges, detectNearDuplicatePages, deterministicRng, diagnoseRagAnswerFailure, emitRetrievalHoldoutBypass, emptyClaimLedger, encodeKnowledgeVisibilitySnapshot, evaluateKnowledgeBaseReadiness, explainKnowledgeTarget, extractLinks, extractWikilinks, firstMatch, forkAgentMemoryBranchSnapshot, formatFrontmatter, formatKnowledgeCitationReference, formatKnowledgeInvalidationProposal, fromAgentCandidateKnowledgeRef, gradeClaims, gradeCompanyAgainstText, gradeFactAgainstText, gradeFor, graphitiMemoryAdapterIdentity, groundClaimInText, hashKnowledgeBase, htmlToText, improveKnowledgeBase, improveSelectedKnowledgeCandidate, initKnowledgeBase, innerHtmlById, inspectKnowledgeIndex, inspectPendingKnowledgeMutation, investmentThesisSet, isKernelAnchoredPath, isKnowledgeMemoryBenchmarkCase, isKnowledgeMutationHeld, isKnowledgePagePath, isMissingFile, isReachable, isSafeKnowledgePath, isScaffoldPath, jsonCandidateCodec, jsonObjectCandidateCodec, kbIndexToText, knowledgeBenchmarkJudge, knowledgeCitationAuditFindings, knowledgeImprovementCandidateRef, knowledgeImprovementRunDir, knowledgeImprovementRunId, knowledgePageDigest, knowledgePageFromMarkdown, knowledgePageRelations, knowledgeReleaseReport, knowledgeVisibilityArtifactRef, layoutFor, lensDistribution, linkClaimContradictions, lintCurrentRunCitations, lintKnowledgeIndex, listRegularFilesWithinRoot, loadKnowledgeImprovementActivationResult, loadKnowledgeImprovementEvents, loadKnowledgeImprovementState, loadKnowledgePages, loadKnowledgePromotionRecord, loadSourceRegistry, looksLikeBlockPage, materialFactsSurfaced, materialFactsSurfacedInText, materializeRegisteredClaimEvidence, mediaTypeFor, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, mergeClaimLedgers, mergeTrackedClaims, neighbors, normalizeClaimText, normalizeExternalRagScores, normalizeKnowledgeStateScope, normalizeLinkTarget, normalizePageText, normalizePagesDirectory, optimizeKnowledgeBasePolicy, originatedPages, parseFrontmatter, parseKnowledgeBenchmarkJsonl, parseKnowledgeBenchmarkQrels, parseKnowledgeCitationReference, parseKnowledgeWriteBlocks, partitionRetrievalScenarios, planInvalidationPropagation, politeFetch, promoteKnowledgeCandidate, promoteRunScopedPages, proposeFromFinding, proposeFromFindings, ragAnswerQualityJudge, readRegularFileNoFollow, readRegularFileWithinRoot, reciprocalRankFusion, recoverPendingKnowledgeMutation, relativeWithinRoot, removeDurable, renameDurable, renderKnowledgeBenchmarkReportMarkdown, renderMemoryContext, researchSourceVersionKey, resetRetrievalHoldoutRegistry, resolveKnowledgeCitation, resolveKnowledgeCitations, resolveMemoryCleanupTimeoutMs, resolveRunScopedCitation, resolveRunScopedCitations, respondToIndustryMemoryBenchmarkSmokeCase, respondToIndustryRagBenchmarkSmokeCase, restoreKnowledgeCandidateBaseline, retrievalConfigFromSurface, retrievalConfigSurface, retrievalHoldoutConfigHash, retrievalRecallJudge, runAgentMemoryExperiment, runAgentMemoryImprovement, runAgentMemoryLearningExperiment, runBoundedMemoryLifecycle, runDiscoveryLoop, runInKnowledgeMutationScope, runInvestmentThesisTask, runKnowledgeBenchmarkSuite, runKnowledgeResearchLoop, runMemoryAdapterBenchmark, runRagKnowledgeImprovementLoop, runRagOptimization, runRetrievalImprovementLoop, runSerializedKnowledgeOptimization, runVerifiedResearchLoop, scenarioContentFingerprint, scoreBm25, scoreKnowledgeBaseIndex, scoreKnowledgeBenchmarkArtifact, scoreMemoryBenchmarkArtifact, scoreRagAnswerArtifact, scoreRetrievalArtifact, searchKnowledge, searchKnowledgePages, sha256, sleepForMemoryRecovery, slugify, snapshotSourceTextInput, sourceMatchesGaps, sourceRegistryPath, stableId, stripFrontmatter, summarizeKnowledgeBenchmarkCampaign, syncDirectory, textSourceAdapter, textSourceId, thesisReadinessSpecs, toAgentCandidateKnowledgeRef, toDeepEvalTestCases, toOffPolicyTrajectory, toRagCheckerRecords, toRagasEvaluationRows, toTruLensRecords, tokenizeQuery, tokenizeText, totalMaterialFacts, triageSource, validateKnowledgeIndex, verdictFor, verifyGradeableEvidence, verifyKnowledgeRetrievalDisposition, verifyKnowledgeRetrievalReceipt, verifyKnowledgeUseReceipt, verifyKnowledgeVisibilitySnapshot, walk, withCitedClaim, withKnowledgeImprovementCandidate, withKnowledgeImprovementComparison, withKnowledgeMutation, withKnowledgeRead, withSafeDescendant, withSafeDirectory, writeFileDurable, writeFileDurableWithinRoot, writeJson, writeJsonDurable, writeJsonDurableWithinRoot, writeKnowledgeIndex, writeSourceRegistry };
|
|
8051
8128
|
|
|
8052
8129
|
//# sourceMappingURL=index.js.map
|