@mfdaves/okf-mcp 0.9.1 → 0.12.0-rc.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/CHANGELOG.md +69 -0
- package/README.md +172 -17
- package/bin/okf-mcp.js +6 -1
- package/okf/okf-mcp/policies/authoring-safety.md +11 -1
- package/package.json +17 -5
- package/server.json +2 -2
- package/src/assets.js +165 -73
- package/src/authoring/candidates.js +391 -0
- package/src/authoring/git-preflight.js +225 -0
- package/src/authoring/git-publish.js +776 -0
- package/src/authoring/live.js +789 -0
- package/src/authoring/paths.js +112 -0
- package/src/authoring/policy-hook.js +221 -0
- package/src/authoring/proposal-policy.js +137 -0
- package/src/authoring/receipts.js +329 -0
- package/src/authoring/render.js +38 -0
- package/src/authoring/shared.js +75 -0
- package/src/authoring/staging.js +216 -0
- package/src/authoring.js +386 -287
- package/src/cache/files.js +147 -0
- package/src/cache/lock.js +201 -0
- package/src/cache/paths.js +197 -0
- package/src/cache/store.js +703 -0
- package/src/catalog-text.js +19 -0
- package/src/cli.js +184 -151
- package/src/computation.js +99 -61
- package/src/context/assemble.js +567 -0
- package/src/context/cli-options.js +88 -0
- package/src/context/score.js +234 -0
- package/src/context/sections.js +274 -0
- package/src/embed/interface.js +160 -0
- package/src/embed/openai.js +715 -0
- package/src/embed/prepare.js +182 -0
- package/src/embed/units.js +96 -0
- package/src/git-source.js +112 -52
- package/src/graph.js +95 -37
- package/src/http-server.js +36 -17
- package/src/index.js +15 -0
- package/src/indexer/assemble.js +566 -0
- package/src/indexer/build.js +290 -0
- package/src/indexer/cache.js +81 -0
- package/src/indexer/edges.js +430 -0
- package/src/indexer/index.js +44 -0
- package/src/indexer/paths.js +178 -0
- package/src/indexer/resolve.js +282 -0
- package/src/indexer/update.js +720 -0
- package/src/indexer.js +3 -1068
- package/src/live-authoring.js +4 -2329
- package/src/markdown.js +21 -16
- package/src/mcp/registry.js +328 -0
- package/src/mcp/resources.js +45 -0
- package/src/mcp/server.js +472 -0
- package/src/mcp/tools/catalog.js +244 -0
- package/src/mcp/tools/computation.js +83 -0
- package/src/mcp/tools/context.js +133 -0
- package/src/mcp/tools/graph.js +167 -0
- package/src/mcp/tools/live-authoring.js +316 -0
- package/src/mcp/tools/migration.js +86 -0
- package/src/mcp/tools/producers.js +79 -0
- package/src/mcp/tools/proposals.js +213 -0
- package/src/mcp/tools/provenance.js +87 -0
- package/src/mcp/tools/remote.js +79 -0
- package/src/mcp/tools/search.js +242 -0
- package/src/mcp-server.js +3 -1611
- package/src/migration.js +431 -253
- package/src/parser.js +245 -130
- package/src/plugins.js +71 -48
- package/src/policy/write-policy.js +713 -0
- package/src/producer-publisher.js +195 -77
- package/src/producers.js +265 -101
- package/src/project.js +277 -93
- package/src/remote.js +96 -61
- package/src/search/cli-options.js +107 -0
- package/src/search/confidence.js +61 -0
- package/src/search/dense.js +304 -0
- package/src/search/embedding-cli.js +57 -0
- package/src/search/embedding-config.js +217 -0
- package/src/search/fusion.js +249 -0
- package/src/search/hybrid.js +526 -0
- package/src/search/languages.js +200 -0
- package/src/search/lexical.js +695 -0
- package/src/search/query.js +620 -0
- package/src/search/stem/among.js +43 -0
- package/src/search/stem/base-stemmer.js +311 -0
- package/src/search/stem/en-regions.js +456 -0
- package/src/search/stem/en-suffixes.js +664 -0
- package/src/search/stem/en-tables.js +176 -0
- package/src/search/stem/en.js +238 -0
- package/src/search/stem/it-regions.js +459 -0
- package/src/search/stem/it-suffixes.js +471 -0
- package/src/search/stem/it-tables.js +257 -0
- package/src/search/stem/it.js +155 -0
- package/src/search-index.js +2 -81
- package/src/search.js +2 -252
- package/src/store.js +134 -81
- package/src/v02.js +301 -105
- package/src/validation.js +24 -20
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) AXA Group Operations Spain S.A.
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
* a copy of this software and associated documentation files (the
|
|
6
|
+
* "Software"), to deal in the Software without restriction, including
|
|
7
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
* the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be
|
|
13
|
+
* included in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
// Provenance: derived from @nlpjs/core 4.26.1, src/base-stemmer.js (MIT,
|
|
25
|
+
// header above). The Snowball runtime (cursor, groupings, among tables,
|
|
26
|
+
// slicing) is kept verbatim in behaviour; removed: the dependency-injection
|
|
27
|
+
// container, tokenizer and stop-word lookups, the before/after dictionaries,
|
|
28
|
+
// and `stemWords`/`stem`/`tokenizeAndStem`. The per-word cache is bounded
|
|
29
|
+
// (plan WP1); upstream grows it without limit. `test/stem-parity.test.js`
|
|
30
|
+
// asserts zero disagreements with the pinned upstream packages.
|
|
31
|
+
"use strict";
|
|
32
|
+
|
|
33
|
+
// Distinct words cached per stemmer; beyond this the oldest entries are
|
|
34
|
+
// evicted first. A 20k-concept bilingual catalog stays well under it.
|
|
35
|
+
const STEM_CACHE_LIMIT = 50000;
|
|
36
|
+
|
|
37
|
+
class BaseStemmer {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.cache = new Map();
|
|
40
|
+
this.setCurrent("");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setCurrent(value) {
|
|
44
|
+
this.current = value;
|
|
45
|
+
this.cursor = 0;
|
|
46
|
+
this.limit = this.current.length;
|
|
47
|
+
this.limit_backward = 0;
|
|
48
|
+
this.bra = this.cursor;
|
|
49
|
+
this.ket = this.limit;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getCurrent() {
|
|
53
|
+
return this.current;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// True when character offset `ch` is outside the bit-set grouping `s`.
|
|
57
|
+
bc(s, ch) {
|
|
58
|
+
return (s[ch >>> 3] & (0x1 << (ch & 0x7))) === 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
in_grouping(s, min, max) {
|
|
62
|
+
if (this.cursor >= this.limit) return false;
|
|
63
|
+
let ch = this.current.charCodeAt(this.cursor);
|
|
64
|
+
if (ch > max || ch < min) return false;
|
|
65
|
+
ch -= min;
|
|
66
|
+
if (this.bc(s, ch)) return false;
|
|
67
|
+
this.cursor++;
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
in_grouping_b(s, min, max) {
|
|
72
|
+
if (this.cursor <= this.limit_backward) return false;
|
|
73
|
+
let ch = this.current.charCodeAt(this.cursor - 1);
|
|
74
|
+
if (ch > max || ch < min) return false;
|
|
75
|
+
ch -= min;
|
|
76
|
+
if (this.bc(s, ch)) return false;
|
|
77
|
+
this.cursor--;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
out_grouping(s, min, max) {
|
|
82
|
+
if (this.cursor >= this.limit) return false;
|
|
83
|
+
let ch = this.current.charCodeAt(this.cursor);
|
|
84
|
+
if (ch > max || ch < min) {
|
|
85
|
+
this.cursor++;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
ch -= min;
|
|
89
|
+
if (this.bc(s, ch)) {
|
|
90
|
+
this.cursor++;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
out_grouping_b(s, min, max) {
|
|
97
|
+
if (this.cursor <= this.limit_backward) return false;
|
|
98
|
+
let ch = this.current.charCodeAt(this.cursor - 1);
|
|
99
|
+
if (ch > max || ch < min) {
|
|
100
|
+
this.cursor--;
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
ch -= min;
|
|
104
|
+
if (this.bc(s, ch)) {
|
|
105
|
+
this.cursor--;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Upstream accepts (size, string) or (string); the generated stemmers only
|
|
112
|
+
// pass the string.
|
|
113
|
+
eq_s(sizeOrString, maybeString) {
|
|
114
|
+
const s = typeof sizeOrString === "string" ? sizeOrString : maybeString;
|
|
115
|
+
const size = typeof sizeOrString === "string" ? s.length : sizeOrString;
|
|
116
|
+
if (
|
|
117
|
+
this.limit - this.cursor < size ||
|
|
118
|
+
this.current.slice(this.cursor, this.cursor + size) !== s
|
|
119
|
+
) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
this.cursor += size;
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
eq_s_b(sizeOrString, maybeString) {
|
|
127
|
+
const s = typeof sizeOrString === "string" ? sizeOrString : maybeString;
|
|
128
|
+
const size = typeof sizeOrString === "string" ? s.length : sizeOrString;
|
|
129
|
+
if (
|
|
130
|
+
this.cursor - this.limit_backward < size ||
|
|
131
|
+
this.current.slice(this.cursor - size, this.cursor) !== s
|
|
132
|
+
) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
this.cursor -= size;
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
find_among(v, v_size) {
|
|
140
|
+
let i = 0;
|
|
141
|
+
let j = v_size || v.length;
|
|
142
|
+
const c = this.cursor;
|
|
143
|
+
const l = this.limit;
|
|
144
|
+
let common_i = 0;
|
|
145
|
+
let common_j = 0;
|
|
146
|
+
let first_key_inspected = false;
|
|
147
|
+
|
|
148
|
+
while (true) {
|
|
149
|
+
const k = i + ((j - i) >>> 1);
|
|
150
|
+
let diff = 0;
|
|
151
|
+
let common = common_i < common_j ? common_i : common_j;
|
|
152
|
+
const w = v[k];
|
|
153
|
+
for (let i2 = common; i2 < w.s_size; i2++) {
|
|
154
|
+
if (c + common === l) {
|
|
155
|
+
diff = -1;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
diff = this.current.charCodeAt(c + common) - w.s.charCodeAt(i2);
|
|
159
|
+
if (diff !== 0) break;
|
|
160
|
+
common++;
|
|
161
|
+
}
|
|
162
|
+
if (diff < 0) {
|
|
163
|
+
j = k;
|
|
164
|
+
common_j = common;
|
|
165
|
+
} else {
|
|
166
|
+
i = k;
|
|
167
|
+
common_i = common;
|
|
168
|
+
}
|
|
169
|
+
if (j - i <= 1) {
|
|
170
|
+
if (i > 0) break;
|
|
171
|
+
if (j === i) break;
|
|
172
|
+
// One more round so that v[0] is inspected as well.
|
|
173
|
+
if (first_key_inspected) break;
|
|
174
|
+
first_key_inspected = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
while (true) {
|
|
178
|
+
const w = v[i];
|
|
179
|
+
if (common_i >= w.s_size) {
|
|
180
|
+
this.cursor = c + w.s_size;
|
|
181
|
+
if (w.method === undefined || w.method === null) {
|
|
182
|
+
return w.result;
|
|
183
|
+
}
|
|
184
|
+
const res = w.method(w.instance);
|
|
185
|
+
this.cursor = c + w.s_size;
|
|
186
|
+
if (res) {
|
|
187
|
+
return w.result;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
i = w.substring_i;
|
|
191
|
+
if (i < 0) return 0;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Backwards variant of find_among; the same comments apply.
|
|
196
|
+
find_among_b(v, v_size) {
|
|
197
|
+
let i = 0;
|
|
198
|
+
let j = v_size || v.length;
|
|
199
|
+
const c = this.cursor;
|
|
200
|
+
const lb = this.limit_backward;
|
|
201
|
+
let common_i = 0;
|
|
202
|
+
let common_j = 0;
|
|
203
|
+
let first_key_inspected = false;
|
|
204
|
+
|
|
205
|
+
while (true) {
|
|
206
|
+
const k = i + ((j - i) >> 1);
|
|
207
|
+
let diff = 0;
|
|
208
|
+
let common = common_i < common_j ? common_i : common_j;
|
|
209
|
+
const w = v[k];
|
|
210
|
+
for (let i2 = w.s_size - 1 - common; i2 >= 0; i2--) {
|
|
211
|
+
if (c - common === lb) {
|
|
212
|
+
diff = -1;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
diff = this.current.charCodeAt(c - 1 - common) - w.s.charCodeAt(i2);
|
|
216
|
+
if (diff !== 0) break;
|
|
217
|
+
common++;
|
|
218
|
+
}
|
|
219
|
+
if (diff < 0) {
|
|
220
|
+
j = k;
|
|
221
|
+
common_j = common;
|
|
222
|
+
} else {
|
|
223
|
+
i = k;
|
|
224
|
+
common_i = common;
|
|
225
|
+
}
|
|
226
|
+
if (j - i <= 1) {
|
|
227
|
+
if (i > 0) break;
|
|
228
|
+
if (j === i) break;
|
|
229
|
+
if (first_key_inspected) break;
|
|
230
|
+
first_key_inspected = true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
while (true) {
|
|
234
|
+
const w = v[i];
|
|
235
|
+
if (common_i >= w.s_size) {
|
|
236
|
+
this.cursor = c - w.s_size;
|
|
237
|
+
if (w.method === undefined || w.method === null) return w.result;
|
|
238
|
+
const res = w.method(this);
|
|
239
|
+
this.cursor = c - w.s_size;
|
|
240
|
+
if (res) return w.result;
|
|
241
|
+
}
|
|
242
|
+
i = w.substring_i;
|
|
243
|
+
if (i < 0) return 0;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Replace the characters between c_bra and c_ket with s.
|
|
248
|
+
replace_s(c_bra, c_ket, s) {
|
|
249
|
+
const adjustment = s.length - (c_ket - c_bra);
|
|
250
|
+
this.current = this.current.slice(0, c_bra) + s + this.current.slice(c_ket);
|
|
251
|
+
this.limit += adjustment;
|
|
252
|
+
if (this.cursor >= c_ket) this.cursor += adjustment;
|
|
253
|
+
else if (this.cursor > c_bra) this.cursor = c_bra;
|
|
254
|
+
return adjustment;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
slice_check() {
|
|
258
|
+
return !(
|
|
259
|
+
this.bra < 0 ||
|
|
260
|
+
this.bra > this.ket ||
|
|
261
|
+
this.ket > this.limit ||
|
|
262
|
+
this.limit > this.current.length
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
slice_from(s) {
|
|
267
|
+
if (this.slice_check()) {
|
|
268
|
+
this.replace_s(this.bra, this.ket, s);
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
slice_del() {
|
|
275
|
+
return this.slice_from("");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
insert(c_bra, c_ket, s) {
|
|
279
|
+
const adjustment = this.replace_s(c_bra, c_ket, s);
|
|
280
|
+
if (c_bra <= this.bra) this.bra += adjustment;
|
|
281
|
+
if (c_bra <= this.ket) this.ket += adjustment;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
slice_to() {
|
|
285
|
+
return this.slice_check() ? this.current.slice(this.bra, this.ket) : "";
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Subclasses implement the Snowball algorithm over `this.current`.
|
|
289
|
+
innerStem() {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
stemWord(word) {
|
|
294
|
+
const cached = this.cache.get(word);
|
|
295
|
+
if (cached !== undefined) {
|
|
296
|
+
return cached;
|
|
297
|
+
}
|
|
298
|
+
this.setCurrent(word);
|
|
299
|
+
this.innerStem();
|
|
300
|
+
const result = this.getCurrent();
|
|
301
|
+
if (this.cache.size >= STEM_CACHE_LIMIT) {
|
|
302
|
+
this.cache.delete(this.cache.keys().next().value);
|
|
303
|
+
}
|
|
304
|
+
this.cache.set(word, result);
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
BaseStemmer.STEM_CACHE_LIMIT = STEM_CACHE_LIMIT;
|
|
310
|
+
|
|
311
|
+
module.exports = BaseStemmer;
|