@hraness/kb 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DISCLOSURE +43 -0
- package/LICENSE +21 -0
- package/README.md +545 -0
- package/dist/agent-context.js +35 -0
- package/dist/agent-guide-audit.js +18 -0
- package/dist/attachments.js +19 -0
- package/dist/authoring.js +33 -0
- package/dist/benchmark.js +19 -0
- package/dist/capture.js +49 -0
- package/dist/cli.js +3646 -0
- package/dist/clip/acquire.js +57 -0
- package/dist/clip/args.js +21 -0
- package/dist/clip/bounded-byte-buffer.js +9 -0
- package/dist/clip/browser-profiles.js +17 -0
- package/dist/clip/bundle-reader.js +11 -0
- package/dist/clip/cli.js +27 -0
- package/dist/clip/cookies.js +21 -0
- package/dist/clip/defuddle-worker.js +84 -0
- package/dist/clip/doctor.js +32 -0
- package/dist/clip/jobs.js +784 -0
- package/dist/clip/network-proxy.js +9 -0
- package/dist/clip/network.js +28 -0
- package/dist/clip/persist.js +30 -0
- package/dist/clip/refresh.js +11 -0
- package/dist/clip/terminal.js +11 -0
- package/dist/evaluation-builder.js +12238 -0
- package/dist/evaluation-kb.js +26 -0
- package/dist/evaluation.js +35 -0
- package/dist/git.js +39 -0
- package/dist/graph.js +39 -0
- package/dist/index-01jj6rbv.js +1103 -0
- package/dist/index-06c9ctr6.js +738 -0
- package/dist/index-0kavxzqj.js +2480 -0
- package/dist/index-1gwbassd.js +743 -0
- package/dist/index-1n418kb9.js +827 -0
- package/dist/index-1vrd1rmn.js +56 -0
- package/dist/index-1xxnjn0d.js +171 -0
- package/dist/index-3rm7cz6h.js +373 -0
- package/dist/index-3v2z4f0q.js +328 -0
- package/dist/index-48pz4jpc.js +392 -0
- package/dist/index-4j3tt0c3.js +234 -0
- package/dist/index-5n05se68.js +307 -0
- package/dist/index-5vwpzb5a.js +764 -0
- package/dist/index-6g2pv9d2.js +370 -0
- package/dist/index-7fzc32gf.js +712 -0
- package/dist/index-84x0vjjp.js +432 -0
- package/dist/index-adx6khj5.js +488 -0
- package/dist/index-b88v3vtm.js +805 -0
- package/dist/index-cv6fh7z5.js +462 -0
- package/dist/index-cxfrakt7.js +1067 -0
- package/dist/index-d13v9ckt.js +150 -0
- package/dist/index-dycjbhw2.js +1943 -0
- package/dist/index-dyqwejk5.js +531 -0
- package/dist/index-e5fbsywq.js +658 -0
- package/dist/index-f984hw45.js +927 -0
- package/dist/index-gh719d91.js +63 -0
- package/dist/index-hgve9rh2.js +2046 -0
- package/dist/index-hya40gb2.js +474 -0
- package/dist/index-j4zgmzjr.js +152 -0
- package/dist/index-jsmvyyvf.js +1166 -0
- package/dist/index-kh0pwvdd.js +1974 -0
- package/dist/index-mqx4nd6v.js +119 -0
- package/dist/index-mxxxytys.js +1254 -0
- package/dist/index-n5dd7r0v.js +711 -0
- package/dist/index-npg9z1a4.js +431 -0
- package/dist/index-pj501bh1.js +140 -0
- package/dist/index-qry4vhxk.js +1041 -0
- package/dist/index-s2gw5aw9.js +199 -0
- package/dist/index-vvdj6kca.js +70 -0
- package/dist/index-w2zc0vwa.js +571 -0
- package/dist/index-x3fthpsc.js +585 -0
- package/dist/index-zr53sf63.js +44 -0
- package/dist/index-zxdy5pby.js +2728 -0
- package/dist/index-zzhgcwyt.js +966 -0
- package/dist/index.js +453 -0
- package/dist/navigation.js +13 -0
- package/dist/pdf.js +85 -0
- package/dist/percolate.js +24 -0
- package/dist/portfolio.js +77 -0
- package/dist/query.js +29 -0
- package/dist/repository-memory.js +60 -0
- package/dist/sdk.js +36 -0
- package/dist/search-rules.js +34 -0
- package/dist/search.js +22 -0
- package/dist/semantic.js +39 -0
- package/dist/source-inbox.js +17 -0
- package/dist/untrusted-content.js +32 -0
- package/dist/url-intelligence.js +74 -0
- package/dist/workflow.js +23 -0
- package/dist/workflows/decision-context.js +20 -0
- package/dist/workflows/explain-change.js +8 -0
- package/dist/workflows/index.js +28 -0
- package/dist/workflows/plan-radar.js +10 -0
- package/package.json +409 -0
- package/skills/kb/AGENTS.md +19 -0
- package/skills/kb/SKILL.md +82 -0
- package/skills/kb/agents/openai.yaml +4 -0
- package/skills/kb/references/pdf-review.md +51 -0
- package/skills/kb/references/percolate.md +144 -0
- package/skills/kb/references/plan-structure.md +105 -0
- package/skills/kb/references/plan.md +115 -0
- package/skills/kb/references/query.md +231 -0
- package/skills/kb/references/refresh.md +133 -0
- package/skills/kb/references/save-pdf.md +125 -0
- package/skills/kb/references/save-url.md +178 -0
- package/skills/kb/references/url-authentication.md +75 -0
- package/skills/kb/references/url-platforms.md +25 -0
- package/src/agent-context.ts +1241 -0
- package/src/agent-guide-audit.ts +750 -0
- package/src/attachments.ts +723 -0
- package/src/authoring.ts +1725 -0
- package/src/benchmark.ts +362 -0
- package/src/capture.ts +68 -0
- package/src/cli.ts +3660 -0
- package/src/clip/acquire.ts +1273 -0
- package/src/clip/archive-today.ts +402 -0
- package/src/clip/args.ts +423 -0
- package/src/clip/assets.ts +262 -0
- package/src/clip/bounded-byte-buffer.ts +75 -0
- package/src/clip/browser-profiles.ts +372 -0
- package/src/clip/bundle-reader.ts +608 -0
- package/src/clip/capture.ts +1054 -0
- package/src/clip/cli.ts +181 -0
- package/src/clip/cookies.ts +512 -0
- package/src/clip/doctor.ts +1110 -0
- package/src/clip/extract.ts +868 -0
- package/src/clip/jobs.ts +959 -0
- package/src/clip/lib.ts +861 -0
- package/src/clip/media.ts +1474 -0
- package/src/clip/metadata-search-tool/Cargo.lock +2498 -0
- package/src/clip/metadata-search-tool/Cargo.toml +18 -0
- package/src/clip/metadata-search-tool/runner.ts +685 -0
- package/src/clip/metadata-search-tool/src/main.rs +389 -0
- package/src/clip/metadata-search.ts +687 -0
- package/src/clip/network-proxy.ts +627 -0
- package/src/clip/network.ts +950 -0
- package/src/clip/package-root.ts +54 -0
- package/src/clip/persist.ts +1472 -0
- package/src/clip/platforms.ts +1824 -0
- package/src/clip/refresh.ts +197 -0
- package/src/clip/structured.ts +432 -0
- package/src/clip/terminal.ts +197 -0
- package/src/clip/url-intelligence.ts +581 -0
- package/src/clip/url-metadata-backfill.ts +616 -0
- package/src/clip/url-metadata-cli.ts +251 -0
- package/src/clip/url-metadata.ts +1397 -0
- package/src/evaluation-analysis-v2.ts +1440 -0
- package/src/evaluation-builder.ts +2539 -0
- package/src/evaluation-corpus-authoring.ts +2052 -0
- package/src/evaluation-evidence.ts +1147 -0
- package/src/evaluation-execution-v2.ts +426 -0
- package/src/evaluation-implementation.ts +131 -0
- package/src/evaluation-kb-closure.ts +1430 -0
- package/src/evaluation-kb-runner-v2.ts +735 -0
- package/src/evaluation-kb-v2.ts +2567 -0
- package/src/evaluation-kb.ts +1018 -0
- package/src/evaluation-measurement-v2.ts +1462 -0
- package/src/evaluation-packing-v2.ts +452 -0
- package/src/evaluation-redaction.ts +28 -0
- package/src/evaluation-v2.ts +3857 -0
- package/src/evaluation.ts +1220 -0
- package/src/git.ts +1276 -0
- package/src/graph.ts +1487 -0
- package/src/index.ts +20 -0
- package/src/init.ts +123 -0
- package/src/navigation.ts +277 -0
- package/src/note-lock.ts +529 -0
- package/src/pdf/args.ts +202 -0
- package/src/pdf/capture.ts +298 -0
- package/src/pdf/cli.ts +159 -0
- package/src/pdf/extract.ts +303 -0
- package/src/pdf/layout.ts +618 -0
- package/src/pdf/markdown.ts +154 -0
- package/src/pdf/model.ts +234 -0
- package/src/pdf/ocr.ts +190 -0
- package/src/pdf/persist.ts +314 -0
- package/src/pdf/source.ts +135 -0
- package/src/pdf/tools.ts +146 -0
- package/src/pdf.ts +92 -0
- package/src/percolate.ts +877 -0
- package/src/portfolio-audit.ts +574 -0
- package/src/portfolio-identity.ts +162 -0
- package/src/portfolio-registry.ts +473 -0
- package/src/portfolio.ts +765 -0
- package/src/query.ts +646 -0
- package/src/repository-memory.ts +1150 -0
- package/src/sdk.ts +1452 -0
- package/src/search-rules.ts +712 -0
- package/src/search.ts +710 -0
- package/src/semantic-runtime.ts +1139 -0
- package/src/semantic.ts +2480 -0
- package/src/source-inbox.ts +232 -0
- package/src/untrusted-content.ts +401 -0
- package/src/url-intelligence.ts +104 -0
- package/src/vault.ts +636 -0
- package/src/workflow.ts +653 -0
- package/src/workflows/decision-context.ts +81 -0
- package/src/workflows/explain-change.ts +73 -0
- package/src/workflows/index.ts +3 -0
- package/src/workflows/plan-radar.ts +101 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/navigation.ts
|
|
3
|
+
var MAX_NAVIGATION_INDEXED_CONNECTIONS = 1e5;
|
|
4
|
+
var MAX_NAVIGATION_RETURNED_CONNECTIONS = 1e4;
|
|
5
|
+
|
|
6
|
+
class NavigationBudgetError extends RangeError {
|
|
7
|
+
kind;
|
|
8
|
+
limit;
|
|
9
|
+
constructor(kind, limit, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "NavigationBudgetError";
|
|
12
|
+
this.kind = kind;
|
|
13
|
+
this.limit = limit;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function checkedDepth(value) {
|
|
17
|
+
const depth = value ?? 1;
|
|
18
|
+
if (!Number.isSafeInteger(depth) || depth < 1 || depth > 10) {
|
|
19
|
+
throw new RangeError("Link depth must be an integer from 1 through 10.");
|
|
20
|
+
}
|
|
21
|
+
return depth;
|
|
22
|
+
}
|
|
23
|
+
function checkedLimit(value) {
|
|
24
|
+
const limit = value ?? 50;
|
|
25
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1000) {
|
|
26
|
+
throw new RangeError("Link result limit must be an integer from 1 through 1000.");
|
|
27
|
+
}
|
|
28
|
+
return limit;
|
|
29
|
+
}
|
|
30
|
+
function connectionNode(note, connection, distance) {
|
|
31
|
+
return {
|
|
32
|
+
id: note.id,
|
|
33
|
+
path: note.path,
|
|
34
|
+
title: note.title,
|
|
35
|
+
distance,
|
|
36
|
+
inboundContextualCount: connection?.inboundContextualCount ?? 0,
|
|
37
|
+
outboundContextualCount: connection?.outboundContextualCount ?? 0,
|
|
38
|
+
inboundRelationCount: connection?.inboundRelationCount ?? 0,
|
|
39
|
+
outboundRelationCount: connection?.outboundRelationCount ?? 0
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function edgeKey(edge) {
|
|
43
|
+
return `${edge.source}\x00${edge.target}\x00${edge.line}`;
|
|
44
|
+
}
|
|
45
|
+
function relationKey(relation) {
|
|
46
|
+
return `${relation.source}\x00${relation.predicate}\x00${relation.target}`;
|
|
47
|
+
}
|
|
48
|
+
function compareTraversalCandidates(left, right) {
|
|
49
|
+
return left.source.localeCompare(right.source) || left.target.localeCompare(right.target) || left.kind.localeCompare(right.kind) || (left.kind === "relation" && right.kind === "relation" ? left.relation.predicate.localeCompare(right.relation.predicate) : 0) || left.line - right.line;
|
|
50
|
+
}
|
|
51
|
+
function addCandidate(candidates, path, candidate) {
|
|
52
|
+
const existing = candidates.get(path) ?? [];
|
|
53
|
+
existing.push(candidate);
|
|
54
|
+
candidates.set(path, existing);
|
|
55
|
+
}
|
|
56
|
+
function candidateKey(candidate) {
|
|
57
|
+
return candidate.kind === "link" ? `link\x00${edgeKey(candidate.edge)}` : `relation\x00${relationKey(candidate.relation)}`;
|
|
58
|
+
}
|
|
59
|
+
function checkedConnections(analysis) {
|
|
60
|
+
const authoredRelations = analysis.authoredRelations ?? [];
|
|
61
|
+
const connectionCount = analysis.contextualLinks.length + authoredRelations.length;
|
|
62
|
+
if (connectionCount > MAX_NAVIGATION_INDEXED_CONNECTIONS) {
|
|
63
|
+
throw new NavigationBudgetError("connection-work-limit", MAX_NAVIGATION_INDEXED_CONNECTIONS, `Link navigation exceeds the ${MAX_NAVIGATION_INDEXED_CONNECTIONS} ` + "contextual-link and authored-relation observation limit.");
|
|
64
|
+
}
|
|
65
|
+
return authoredRelations;
|
|
66
|
+
}
|
|
67
|
+
function returnedConnectionLimit(nodeLimit) {
|
|
68
|
+
return Math.min(MAX_NAVIGATION_RETURNED_CONNECTIONS, nodeLimit ** 2);
|
|
69
|
+
}
|
|
70
|
+
function navigateLinks(notes, analysis, start, options = {}) {
|
|
71
|
+
const direction = options.direction ?? "both";
|
|
72
|
+
const depth = checkedDepth(options.depth);
|
|
73
|
+
const limit = checkedLimit(options.limit);
|
|
74
|
+
const authoredRelations = checkedConnections(analysis);
|
|
75
|
+
const notesByPath = new Map(notes.map((note) => [note.path, note]));
|
|
76
|
+
const notesById = new Map(notes.map((note) => [note.id, note]));
|
|
77
|
+
const connectionsById = new Map(analysis.noteConnections.map((connection) => [connection.id, connection]));
|
|
78
|
+
const inbound = new Map;
|
|
79
|
+
const outbound = new Map;
|
|
80
|
+
for (const edge of analysis.contextualLinks) {
|
|
81
|
+
const candidate = {
|
|
82
|
+
kind: "link",
|
|
83
|
+
source: edge.source,
|
|
84
|
+
target: edge.target,
|
|
85
|
+
line: edge.line,
|
|
86
|
+
edge
|
|
87
|
+
};
|
|
88
|
+
addCandidate(inbound, edge.target, candidate);
|
|
89
|
+
addCandidate(outbound, edge.source, candidate);
|
|
90
|
+
}
|
|
91
|
+
for (const relation of authoredRelations) {
|
|
92
|
+
const source = notesById.get(relation.source)?.path;
|
|
93
|
+
const target = notesById.get(relation.target)?.path;
|
|
94
|
+
if (source === undefined || target === undefined)
|
|
95
|
+
continue;
|
|
96
|
+
const candidate = {
|
|
97
|
+
kind: "relation",
|
|
98
|
+
source,
|
|
99
|
+
target,
|
|
100
|
+
line: relation.provenance.line,
|
|
101
|
+
relation
|
|
102
|
+
};
|
|
103
|
+
addCandidate(inbound, target, candidate);
|
|
104
|
+
addCandidate(outbound, source, candidate);
|
|
105
|
+
}
|
|
106
|
+
const distanceByPath = new Map([[start.path, 0]]);
|
|
107
|
+
let frontier = [start.path];
|
|
108
|
+
let truncated = false;
|
|
109
|
+
const selectedCandidates = new Map;
|
|
110
|
+
for (let distance = 0;distance < depth && frontier.length > 0; distance += 1) {
|
|
111
|
+
const next = new Set;
|
|
112
|
+
for (const path of frontier.toSorted()) {
|
|
113
|
+
const candidates = [
|
|
114
|
+
...direction === "out" || direction === "both" ? outbound.get(path) ?? [] : [],
|
|
115
|
+
...direction === "in" || direction === "both" ? inbound.get(path) ?? [] : []
|
|
116
|
+
].toSorted(compareTraversalCandidates);
|
|
117
|
+
for (const candidate of candidates) {
|
|
118
|
+
const neighborPath = candidate.source === path ? candidate.target : candidate.source;
|
|
119
|
+
if (!notesByPath.has(neighborPath))
|
|
120
|
+
continue;
|
|
121
|
+
if (distanceByPath.has(neighborPath)) {
|
|
122
|
+
selectedCandidates.set(candidateKey(candidate), candidate);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (distanceByPath.size >= limit) {
|
|
126
|
+
truncated = true;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
selectedCandidates.set(candidateKey(candidate), candidate);
|
|
130
|
+
distanceByPath.set(neighborPath, distance + 1);
|
|
131
|
+
next.add(neighborPath);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
frontier = [...next];
|
|
135
|
+
}
|
|
136
|
+
const nodes = [...distanceByPath].map(([path, distance]) => {
|
|
137
|
+
const note = notesByPath.get(path);
|
|
138
|
+
return note === undefined ? null : connectionNode(note, connectionsById.get(note.id), distance);
|
|
139
|
+
}).filter((node) => node !== null).toSorted((left, right) => left.distance - right.distance || left.path.localeCompare(right.path));
|
|
140
|
+
const sortedCandidates = [...selectedCandidates.values()].toSorted(compareTraversalCandidates);
|
|
141
|
+
const connectionLimit = returnedConnectionLimit(limit);
|
|
142
|
+
if (sortedCandidates.length > connectionLimit)
|
|
143
|
+
truncated = true;
|
|
144
|
+
const returnedCandidates = sortedCandidates.slice(0, connectionLimit);
|
|
145
|
+
const edges = returnedCandidates.filter((candidate) => candidate.kind === "link").map(({ edge }) => edge).toSorted((left, right) => left.source.localeCompare(right.source) || left.target.localeCompare(right.target) || left.line - right.line);
|
|
146
|
+
const relations = returnedCandidates.filter((candidate) => candidate.kind === "relation").map(({ relation }) => relation).toSorted((left, right) => left.source.localeCompare(right.source) || left.predicate.localeCompare(right.predicate) || left.target.localeCompare(right.target) || left.provenance.line - right.provenance.line);
|
|
147
|
+
return { note: start.path, direction, depth, limit, truncated, nodes, edges, relations };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { MAX_NAVIGATION_INDEXED_CONNECTIONS, MAX_NAVIGATION_RETURNED_CONNECTIONS, NavigationBudgetError, navigateLinks };
|