@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,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove terminal control protocols from untrusted text while retaining prose.
|
|
3
|
+
* Newlines remain structural and tabs are normalized to spaces; use the line
|
|
4
|
+
* variant when an untrusted value must not create an additional output line.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const ESCAPE = 0x1b;
|
|
8
|
+
const BELL = 0x07;
|
|
9
|
+
const STRING_TERMINATOR = 0x9c;
|
|
10
|
+
const MAX_PENDING_LENGTH = 64 * 1024;
|
|
11
|
+
const MAX_PENDING_SEGMENTS = 4_096;
|
|
12
|
+
const CONTEXT_FREE_TERMINAL_CONTROLS = new RegExp(
|
|
13
|
+
String.raw`[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]`,
|
|
14
|
+
"g",
|
|
15
|
+
);
|
|
16
|
+
const CONTEXT_SENSITIVE_TERMINAL_CONTROLS = new RegExp(
|
|
17
|
+
String.raw`[\u0009\u000d\u001b\u0090\u0098\u009b\u009d-\u009f\u2028\u2029]`,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
type ChunkBuilder = {
|
|
21
|
+
readonly append: (value: string) => void;
|
|
22
|
+
readonly finish: () => string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function chunkBuilder(): ChunkBuilder {
|
|
26
|
+
const chunks: string[] = [];
|
|
27
|
+
let pending: string[] = [];
|
|
28
|
+
let pendingLength = 0;
|
|
29
|
+
|
|
30
|
+
const flush = (): void => {
|
|
31
|
+
if (pending.length === 0) return;
|
|
32
|
+
chunks.push(pending.join(""));
|
|
33
|
+
pending = [];
|
|
34
|
+
pendingLength = 0;
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
append: (value) => {
|
|
38
|
+
if (value === "") return;
|
|
39
|
+
if (value.length >= MAX_PENDING_LENGTH) {
|
|
40
|
+
flush();
|
|
41
|
+
chunks.push(value);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
pending.push(value);
|
|
45
|
+
pendingLength += value.length;
|
|
46
|
+
if (pendingLength >= MAX_PENDING_LENGTH || pending.length >= MAX_PENDING_SEGMENTS) flush();
|
|
47
|
+
},
|
|
48
|
+
finish: () => {
|
|
49
|
+
flush();
|
|
50
|
+
if (chunks.length === 0) return "";
|
|
51
|
+
if (chunks.length === 1) return chunks[0] ?? "";
|
|
52
|
+
return chunks.join("");
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isEscapeStringIntroducer(code: number): boolean {
|
|
58
|
+
return code === 0x50 || code === 0x58 || code === 0x5d || code === 0x5e || code === 0x5f;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isC1StringIntroducer(code: number): boolean {
|
|
62
|
+
return code === 0x90 || code === 0x98 || code === 0x9d || code === 0x9e || code === 0x9f;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function controlStringEnd(value: string, start: number): number {
|
|
66
|
+
for (let cursor = start; cursor < value.length; cursor += 1) {
|
|
67
|
+
const code = value.charCodeAt(cursor);
|
|
68
|
+
if (code === BELL || code === STRING_TERMINATOR) return cursor + 1;
|
|
69
|
+
if (code === ESCAPE && value.charCodeAt(cursor + 1) === 0x5c) return cursor + 2;
|
|
70
|
+
}
|
|
71
|
+
// An unterminated OSC/DCS payload remains terminal state, so discard its tail.
|
|
72
|
+
return value.length;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function controlSequenceEnd(value: string, start: number): number {
|
|
76
|
+
for (let cursor = start; cursor < value.length; cursor += 1) {
|
|
77
|
+
const code = value.charCodeAt(cursor);
|
|
78
|
+
if (code >= 0x40 && code <= 0x7e) return cursor + 1;
|
|
79
|
+
}
|
|
80
|
+
return value.length;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function escapeSequenceEnd(value: string, start: number): number {
|
|
84
|
+
const introducer = value.charCodeAt(start + 1);
|
|
85
|
+
if (Number.isNaN(introducer)) return start + 1;
|
|
86
|
+
if (introducer === 0x5b) return controlSequenceEnd(value, start + 2); // CSI
|
|
87
|
+
if (isEscapeStringIntroducer(introducer)) {
|
|
88
|
+
return controlStringEnd(value, start + 2); // DCS, SOS, OSC, PM, APC
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let cursor = start + 1;
|
|
92
|
+
while (cursor < value.length) {
|
|
93
|
+
const code = value.charCodeAt(cursor);
|
|
94
|
+
if (code >= 0x20 && code <= 0x2f) {
|
|
95
|
+
cursor += 1;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
return code >= 0x30 && code <= 0x7e ? cursor + 1 : start + 1;
|
|
99
|
+
}
|
|
100
|
+
return value.length;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isBidiFormatControl(code: number): boolean {
|
|
104
|
+
return code === 0x061c
|
|
105
|
+
|| code === 0x200e
|
|
106
|
+
|| code === 0x200f
|
|
107
|
+
|| (code >= 0x202a && code <= 0x202e)
|
|
108
|
+
|| (code >= 0x2066 && code <= 0x2069);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** True when text still contains a terminal control other than structural LF. */
|
|
112
|
+
export function hasUnsafeTerminalCharacters(value: string): boolean {
|
|
113
|
+
for (const character of value) {
|
|
114
|
+
const code = character.codePointAt(0) ?? 0;
|
|
115
|
+
if (code <= 0x09
|
|
116
|
+
|| (code >= 0x0b && code <= 0x1f)
|
|
117
|
+
|| (code >= 0x7f && code <= 0x9f)
|
|
118
|
+
|| isBidiFormatControl(code)) return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Strip ANSI/OSC payloads, C0/C1 controls, DEL, and bidi formatting controls. */
|
|
124
|
+
export function sanitizeTerminalText(value: string): string {
|
|
125
|
+
// Let the string engine remove context-free controls in one bounded pass.
|
|
126
|
+
// Escape strings, CSI, normalized whitespace, and line separators still use
|
|
127
|
+
// the state machine below because their replacement depends on neighbors.
|
|
128
|
+
if (!CONTEXT_SENSITIVE_TERMINAL_CONTROLS.test(value)) {
|
|
129
|
+
return value.replace(CONTEXT_FREE_TERMINAL_CONTROLS, "");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let builder: ChunkBuilder | null = null;
|
|
133
|
+
let unchangedStart = 0;
|
|
134
|
+
const replace = (start: number, end: number, replacement = ""): void => {
|
|
135
|
+
builder ??= chunkBuilder();
|
|
136
|
+
builder.append(value.slice(unchangedStart, start));
|
|
137
|
+
builder.append(replacement);
|
|
138
|
+
unchangedStart = end;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
for (let cursor = 0; cursor < value.length;) {
|
|
142
|
+
const code = value.charCodeAt(cursor);
|
|
143
|
+
if (code === ESCAPE) {
|
|
144
|
+
const end = escapeSequenceEnd(value, cursor);
|
|
145
|
+
replace(cursor, end);
|
|
146
|
+
cursor = end;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (code === 0x9b) {
|
|
150
|
+
const end = controlSequenceEnd(value, cursor + 1);
|
|
151
|
+
replace(cursor, end);
|
|
152
|
+
cursor = end;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (isC1StringIntroducer(code)) {
|
|
156
|
+
const end = controlStringEnd(value, cursor + 1);
|
|
157
|
+
replace(cursor, end);
|
|
158
|
+
cursor = end;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (code === 0x0d) {
|
|
162
|
+
const end = value.charCodeAt(cursor + 1) === 0x0a ? cursor + 2 : cursor + 1;
|
|
163
|
+
replace(cursor, end, "\n");
|
|
164
|
+
cursor = end;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (code === 0x0a) {
|
|
168
|
+
cursor += 1;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (code === 0x2028 || code === 0x2029) {
|
|
172
|
+
replace(cursor, cursor + 1, "\n");
|
|
173
|
+
cursor += 1;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (code === 0x09) {
|
|
177
|
+
replace(cursor, cursor + 1, " ");
|
|
178
|
+
cursor += 1;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (code <= 0x1f || (code >= 0x7f && code <= 0x9f) || isBidiFormatControl(code)) {
|
|
182
|
+
replace(cursor, cursor + 1);
|
|
183
|
+
cursor += 1;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
cursor += 1;
|
|
187
|
+
}
|
|
188
|
+
const completedBuilder = builder as ChunkBuilder | null;
|
|
189
|
+
if (completedBuilder === null) return value;
|
|
190
|
+
completedBuilder.append(value.slice(unchangedStart));
|
|
191
|
+
return completedBuilder.finish();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Sanitize one terminal field and prevent it from forging adjacent lines. */
|
|
195
|
+
export function sanitizeTerminalLine(value: string): string {
|
|
196
|
+
return sanitizeTerminalText(value).replace(/\n/g, " ");
|
|
197
|
+
}
|