@nathan-adk/dsh-rea-lazy 2.0.0 → 2.0.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/lib/core/catalog.js +61 -22
- package/lib/index.js +12 -2
- package/package.json +1 -1
package/lib/core/catalog.js
CHANGED
|
@@ -1,25 +1,64 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Family assignment: curated glob rules first, then a name-derived heuristic.
|
|
4
|
+
* Reimplemented in-house from the published algorithm description (subject-word
|
|
5
|
+
* frequency clustering): verbs and generic words are ignored; a tool joins the
|
|
6
|
+
* family of its most widely shared subject word, small groups fold into misc.
|
|
7
|
+
*/
|
|
8
|
+
const VERBS = new Set(('add analyze annotate apply batch build call capture check close collect compare correlate create current decode decompile delete demangle describe discover evaluate execute export extract fetch find get goto identify import inspect install instrument list load next observe open prev project pull push query read reconcile record recover remove resolve resume run search send set start stop trace uninstall unload unset update upload verify write').split(' '));
|
|
9
|
+
const GENERIC = new Set(('to with of and session status command console client target targets file files data info the a').split(' '));
|
|
10
|
+
|
|
11
|
+
function globToRegExp(glob) {
|
|
12
|
+
const e = glob.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*').replace(/\?/g, '.');
|
|
13
|
+
return new RegExp('^' + e + '$', 'u');
|
|
14
|
+
}
|
|
15
|
+
function words(name) {
|
|
16
|
+
return String(name).split(/[_\-.:]+|(?<=[a-z0-9])(?=[A-Z])/u).map(w => w.toLowerCase()).filter(Boolean);
|
|
17
|
+
}
|
|
18
|
+
function subjectWords(name) {
|
|
19
|
+
const s = words(name).filter(w => !VERBS.has(w) && !GENERIC.has(w));
|
|
20
|
+
return s.length ? s : [words(name)[0] || 'misc'];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Assign every tool name to a family: curated rules win, heuristic fills the rest. */
|
|
24
|
+
function assignFamilies(names, rules, minSize = 3) {
|
|
25
|
+
const family = new Map();
|
|
26
|
+
const compiled = (rules || []).map(r => ({ r, p: (r.match || []).map(globToRegExp) }));
|
|
27
|
+
const unassigned = [];
|
|
28
|
+
for (const name of names) {
|
|
29
|
+
const hit = compiled.find(({ p }) => p.some(re => re.test(name)));
|
|
30
|
+
if (hit) family.set(name, hit.r.name);
|
|
31
|
+
else unassigned.push(name);
|
|
32
|
+
}
|
|
33
|
+
const subjects = new Map(unassigned.map(n => [n, subjectWords(n)]));
|
|
34
|
+
const freq = new Map();
|
|
35
|
+
for (const ws of subjects.values()) for (const w of new Set(ws)) freq.set(w, (freq.get(w) || 0) + 1);
|
|
36
|
+
for (const name of unassigned) {
|
|
37
|
+
let best, bestCount = 0;
|
|
38
|
+
for (const w of subjects.get(name) || []) {
|
|
39
|
+
const c = freq.get(w) || 0;
|
|
40
|
+
if (c > bestCount) { best = w; bestCount = c; }
|
|
41
|
+
}
|
|
42
|
+
family.set(name, best !== undefined && (bestCount >= minSize || unassigned.length < minSize) ? best : 'misc');
|
|
43
|
+
}
|
|
44
|
+
if (unassigned.length >= minSize) {
|
|
45
|
+
const sizes = new Map();
|
|
46
|
+
for (const n of unassigned) sizes.set(family.get(n), (sizes.get(family.get(n)) || 0) + 1);
|
|
47
|
+
for (const n of unassigned) if ((sizes.get(family.get(n)) || 0) < minSize) family.set(n, 'misc');
|
|
48
|
+
}
|
|
49
|
+
return family;
|
|
50
|
+
}
|
|
51
|
+
|
|
3
52
|
function summarizeFamilies(tools, families) {
|
|
4
53
|
const fam = new Map();
|
|
5
54
|
for (const rule of families || []) fam.set(rule.name, { name: rule.name, description: rule.description || '', count: 0, examples: [] });
|
|
6
|
-
const glob = (pat, s) => {
|
|
7
|
-
const r = new RegExp('^' + String(pat).replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*') + '$');
|
|
8
|
-
return r.test(s);
|
|
9
|
-
};
|
|
10
55
|
for (const t of tools) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
if (!hit) hit = 'misc';
|
|
17
|
-
if (!fam.has(hit)) fam.set(hit, { name: hit, description: '', count: 0, examples: [] });
|
|
18
|
-
const f = fam.get(hit);
|
|
19
|
-
f.count++;
|
|
20
|
-
if (f.examples.length < 4) f.examples.push(name);
|
|
56
|
+
const f = t.family || 'misc';
|
|
57
|
+
if (!fam.has(f)) fam.set(f, { name: f, description: '', count: 0, examples: [] });
|
|
58
|
+
const g = fam.get(f); g.count++;
|
|
59
|
+
if (g.examples.length < 4) g.examples.push(t.name);
|
|
21
60
|
}
|
|
22
|
-
return [...fam.values()].filter(f => f.count > 0);
|
|
61
|
+
return [...fam.values()].filter(f => f.count > 0).sort((a, b) => b.count - a.count);
|
|
23
62
|
}
|
|
24
63
|
|
|
25
64
|
function search(tools, query, limit = 8) {
|
|
@@ -42,12 +81,12 @@ function search(tools, query, limit = 8) {
|
|
|
42
81
|
|
|
43
82
|
function renderIndex(tools, families) {
|
|
44
83
|
const fams = summarizeFamilies(tools, families);
|
|
45
|
-
const lines = ['
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
lines.push(
|
|
84
|
+
const lines = ['## REA capability catalog', '',
|
|
85
|
+
'REA tools are NOT declared as native tools; their schemas are not in context.',
|
|
86
|
+
'Find one with `capability_search`, read exact parameters with `capability_describe`, then run it with `capability_call`.',
|
|
87
|
+
'When a task matches a family below, search before concluding no tool exists.', ''];
|
|
88
|
+
for (const f of fams) lines.push(`- ${f.name} (${f.count}): ${f.examples.join(', ')}${f.count > f.examples.length ? ', …' : ''}`);
|
|
50
89
|
return lines.join('\n');
|
|
51
90
|
}
|
|
52
91
|
|
|
53
|
-
module.exports = { summarizeFamilies, search, renderIndex };
|
|
92
|
+
module.exports = { assignFamilies, summarizeFamilies, search, renderIndex, globToRegExp };
|
package/lib/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const path = require('path');
|
|
|
9
9
|
const os = require('os');
|
|
10
10
|
const { spawnSync } = require('child_process');
|
|
11
11
|
const { McpSource, cacheKey } = require('./core/mcp-source');
|
|
12
|
-
const { renderIndex } = require('./core/catalog');
|
|
12
|
+
const { renderIndex, assignFamilies } = require('./core/catalog');
|
|
13
13
|
const { createTools } = require('./core/tools');
|
|
14
14
|
const { createUpdater } = require('./core/updater');
|
|
15
15
|
|
|
@@ -71,6 +71,12 @@ async function apply(ctx, config = {}) {
|
|
|
71
71
|
};
|
|
72
72
|
const source = new McpSource(server, cachePath);
|
|
73
73
|
await source.start(); // cache hit = no spawn; miss = one discovery
|
|
74
|
+
// Enrich cached tools with families (curated rules + in-house heuristic) so the
|
|
75
|
+
// compact index shows the full family set (curated + derived, ~24 families).
|
|
76
|
+
if (source.catalog && Array.isArray(source.catalog.tools)) {
|
|
77
|
+
const fm = assignFamilies(source.catalog.tools.map(t => t.name), FAMILIES);
|
|
78
|
+
for (const t of source.catalog.tools) if (!t.family) t.family = fm.get(t.name) || 'misc';
|
|
79
|
+
}
|
|
74
80
|
ctx.effect(() => () => source.dispose(), 'dsh-rea-lazy.source');
|
|
75
81
|
|
|
76
82
|
// register three meta-tools
|
|
@@ -100,7 +106,11 @@ async function apply(ctx, config = {}) {
|
|
|
100
106
|
updater.start();
|
|
101
107
|
ctx.effect(() => () => updater.stop(), 'dsh-rea-lazy.updater');
|
|
102
108
|
|
|
103
|
-
|
|
109
|
+
// FIX: DSH forbids assigning undeclared ctx properties; declare via provide.
|
|
110
|
+
// Placed after all tool/prompt registration so an early failure cannot leave a half-loaded plugin.
|
|
111
|
+
if (ctx.provide) {
|
|
112
|
+
ctx.provide('reaRefresh', async () => { await source.discover(true); return source.toolCount; });
|
|
113
|
+
}
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
module.exports = { name: 'dsh-rea-lazy', inject: ['tools', 'systemPrompt'], apply, findRea, cacheKey };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathan-adk/dsh-rea-lazy",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Self-contained on-demand REA capability layer for DeepSeek Harness: built-in compact index + search/describe/call meta-tools + on-disk cache + on-demand spawn + daily upstream check. No third-party catalog required.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|