@tangle-network/agent-knowledge 17.0.1 → 17.1.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.
@@ -1,5 +1,5 @@
1
1
  import { i as textSourceId, n as slugify, r as stableId, t as sha256 } from "./ids-Bevz_pXV.js";
2
- import { r as searchKnowledge } from "./search-Cw6eYfSd.js";
2
+ import { r as searchKnowledge } from "./search-Cbyj2shJ.js";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm } from "node:fs/promises";
5
5
  import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
@@ -2027,15 +2027,29 @@ var KnowledgeCitationAuditError = class extends Error {
2027
2027
  this.report = report;
2028
2028
  }
2029
2029
  };
2030
+ const ENCODED_REFERENCE_PREFIX = "knowledge-ref:v1:";
2030
2031
  /**
2031
2032
  * Parse the persisted citation form.
2032
2033
  *
2033
2034
  * `page-id` is unqualified. `here::page-id`, `shared::page-id`, and
2034
2035
  * `inherited:<runId>::page-id` bind an intentional duplicate to one origin.
2036
+ * Ambiguous names use `knowledge-ref:v1:` plus a URI-encoded JSON [origin, pageId]
2037
+ * tuple (null origin means unqualified). Always use the formatter to mint handles.
2038
+ * Legacy percent sequences are literal; old records are not silently reinterpreted.
2035
2039
  */
2036
2040
  function parseKnowledgeCitationReference(value) {
2037
2041
  if (typeof value !== "string" || value.trim().length === 0) throw new TypeError("persisted knowledge citation must be a non-empty string");
2038
2042
  const normalized = value.trim();
2043
+ if (normalized.startsWith(ENCODED_REFERENCE_PREFIX)) try {
2044
+ const tuple = JSON.parse(decodeURIComponent(normalized.slice(17)));
2045
+ if (!Array.isArray(tuple) || tuple.length !== 2) throw new TypeError("encoded citation must contain an origin/page tuple");
2046
+ return normalizeReference({
2047
+ pageId: tuple[1],
2048
+ ...tuple[0] === null ? {} : { origin: tuple[0] }
2049
+ });
2050
+ } catch (cause) {
2051
+ throw new TypeError("invalid encoded knowledge citation", { cause });
2052
+ }
2039
2053
  const separator = normalized.indexOf("::");
2040
2054
  if (separator < 0) return Object.freeze({ pageId: normalized });
2041
2055
  const possibleOrigin = normalized.slice(0, separator);
@@ -2049,7 +2063,14 @@ function parseKnowledgeCitationReference(value) {
2049
2063
  /** Serialize one reference into the canonical frontmatter representation. */
2050
2064
  function formatKnowledgeCitationReference(reference) {
2051
2065
  const normalized = normalizeReference(reference);
2052
- return normalized.origin === void 0 ? normalized.pageId : `${normalized.origin}::${normalized.pageId}`;
2066
+ const legacy = normalized.origin === void 0 ? normalized.pageId : `${normalized.origin}::${normalized.pageId}`;
2067
+ try {
2068
+ const parsed = parseKnowledgeCitationReference(legacy);
2069
+ if (parsed.pageId === normalized.pageId && parsed.origin === normalized.origin) return legacy;
2070
+ } catch (error) {
2071
+ if (!(error instanceof TypeError)) throw error;
2072
+ }
2073
+ return `${ENCODED_REFERENCE_PREFIX}${encodeURIComponent(JSON.stringify([normalized.origin ?? null, normalized.pageId]))}`;
2053
2074
  }
2054
2075
  /** Resolve one reference against an already materialized visibility chain. */
2055
2076
  function resolveKnowledgeCitation(visiblePages, reference) {
@@ -3903,11 +3924,13 @@ function parseKnowledgeWriteBlocks(text, allowedPrefixes = ["knowledge/"]) {
3903
3924
  i++;
3904
3925
  break;
3905
3926
  }
3927
+ if (fenceMarker === null && OPENER_LINE.test(line)) break;
3906
3928
  contentLines.push(line);
3907
3929
  i++;
3908
3930
  }
3909
3931
  if (!closed) {
3910
- warnings.push(`FILE block "${path || "(empty)"}" was not closed before end of stream.`);
3932
+ const boundary = i < lines.length ? "next FILE block" : "end of stream";
3933
+ warnings.push(`FILE block "${path || "(empty)"}" was not closed before ${boundary}. Expected ---END FILE--- on its own line.`);
3911
3934
  continue;
3912
3935
  }
3913
3936
  if (!isSafeKnowledgePath(path, allowedPrefixes)) {
@@ -4051,4 +4074,4 @@ function explainKnowledgeTarget(index, target) {
4051
4074
  //#endregion
4052
4075
  export { formatKnowledgeCitationReference as $, inspectPendingKnowledgeMutation as $t, addSourceText as A, writeJsonDurableWithinRoot as An, ResearchSourceVersionSchema as At, KB_STORE_DIR as B, claimId as Bt, gradeClaims as C, renameDurable as Cn, KnowledgePageSchema as Ct, buildKnowledgeIndex as D, writeFileDurable as Dn, ResearchClaimEvidenceSchema as Dt, verifyGradeableEvidence as E, withSafeDirectory as En, KnowledgeRelationSchema as Et, ClaimLedgerMigrationRequiredError as F, assertDeepQuestionIntegrity as Ft, KnowledgeCitationAuditError as G, materializeRegisteredClaimEvidence as Gt, assertClaimLedgerId as H, deepQuestionId as Ht, FileSystemKbStore as I, assertResearchClaimEvidenceIntegrity as It, assertKnowledgeCitationAudit as J, normalizeClaimText as Jt, KnowledgeCitationResolutionError as K, mergeClaimLedgers as Kt, KB_CLAIM_LEDGER_DIR as L, assertResearchClaimLedgerIntegrity as Lt, snapshotSourceTextInput as M, textSourceAdapter as Mn, SourceRecordSchema as Mt, sourceRegistryPath as N, KNOWLEDGE_EVENT_TYPES as Nt, writeKnowledgeIndex as O, writeFileDurableWithinRoot as On, ResearchClaimLedgerSchema as Ot, writeSourceRegistry as P, ClaimLedgerGoalConflictError as Pt, auditKnowledgeCitations as Q, acquireDurableFileLock as Qt, KB_EVENTS_PATH as R, assertTrackedClaimIntegrity as Rt, claimCheckKey as S, removeDurable as Sn, KnowledgePageInvalidationSchema as St, verdictFor as T, withSafeDescendant as Tn, KnowledgeRelationNodeSchema as Tt, buildKnowledgeGraph as U, emptyClaimLedger as Ut, MemoryKbStore as V, claimSourceHost as Vt, knowledgePageRelations as W, linkClaimContradictions as Wt, assertRunScopedCitationsResolved as X, formatFrontmatter as Xt, assertKnowledgeCitationsResolved as Y, researchSourceVersionKey as Yt, auditCurrentRunCitations as Z, parseFrontmatter as Zt, lintKnowledgeIndex as _, isMissingFile as _n, KnowledgeBaseCandidateSchema as _t, applyKnowledgeWriteBlocksFile as a, applyKnowledgeFileTransaction as an, SCAFFOLD_PAGE_BASENAMES as at, UncheckableClaimError as b, readRegularFileWithinRoot as bn, KnowledgeGraphNodeSchema as bt, KnowledgeDuplicateIntakeError as c, finishKnowledgeFileTransaction as cn, isScaffoldPath as ct, createFileRunLineageAuthority as d, rollbackKnowledgeFileTransaction as dn, loadKnowledgePages as dt, isKnowledgeMutationHeld as en, parseKnowledgeCitationReference as et, createRunScopedStores as f, DEFAULT_PAGES_DIRECTORY as fn, writeJson as ft, validateKnowledgeIndex as g, isKernelAnchoredPath as gn, DeepQuestionSchema as gt, normalizePageText as h, canonicalRelativeWithinRoot as hn, normalizeLinkTarget as ht, applyKnowledgeWriteBlocks as i, withKnowledgeRead as in, resolveRunScopedCitations as it, loadSourceRegistry as j, mediaTypeFor$1 as jn, SourceAnchorSchema as jt, addSourcePath as k, writeJsonDurable as kn, ResearchClaimRecordSchema as kt, assertKnowledgeWriteIntake as l, knowledgeFileTransactionPlanHash as ln, knowledgePageFromMarkdown as lt, detectNearDuplicatePages as m, canonicalPathsEqual as mn, extractWikilinks as mt, inspectKnowledgeIndex as n, runInKnowledgeMutationScope as nn, resolveKnowledgeCitations as nt, isSafeKnowledgePath as o, assertKnowledgeMutationPath as on, initKnowledgeBase as ot, originatedPages as p, normalizePagesDirectory as pn, WIKILINK_REGEX as pt, assertCurrentRunCitationsResolved as q, mergeTrackedClaims as qt, stringMetadata as r, withKnowledgeMutation as rn, resolveRunScopedCitation as rt, parseKnowledgeWriteBlocks as s, commitKnowledgeFileMutations as sn, isKnowledgePagePath as st, explainKnowledgeTarget as t, recoverPendingKnowledgeMutation as tn, resolveKnowledgeCitation as tt, RUN_LINEAGE_BASENAME as u, prepareKnowledgeFileTransaction as un, layoutFor as ut, CHECKABLE_RUNG_THRESHOLD as v, listRegularFilesWithinRoot as vn, KnowledgeEventSchema as vt, gradeFor as w, syncDirectory as wn, KnowledgeRelationGraphSchema as wt, assertGradeableEvidence as x, relativeWithinRoot as xn, KnowledgeIndexSchema as xt, DEADLINE_EXIT_CODE as y, readRegularFileNoFollow as yn, KnowledgeGraphEdgeSchema as yt, KB_INDEX_PATH as z, claimEvidenceId as zt };
4053
4076
 
4054
- //# sourceMappingURL=inspect-Dn7xCZLn.js.map
4077
+ //# sourceMappingURL=inspect-DrJnvx5Z.js.map