network-ai 5.14.0 → 5.15.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.
- package/INTEGRATION_GUIDE.md +1 -1
- package/README.md +11 -4
- package/SKILL.md +1 -1
- package/bin/mcp-server.ts +9 -0
- package/dist/bin/mcp-server.js +8 -0
- package/dist/bin/mcp-server.js.map +1 -1
- package/dist/esm/index.js +12 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/context-composer.js +332 -0
- package/dist/esm/lib/context-composer.js.map +1 -0
- package/dist/esm/lib/mcp-tools-context.js +266 -0
- package/dist/esm/lib/mcp-tools-context.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -1
- package/dist/lib/context-composer.d.ts +187 -0
- package/dist/lib/context-composer.d.ts.map +1 -0
- package/dist/lib/context-composer.js +332 -0
- package/dist/lib/context-composer.js.map +1 -0
- package/dist/lib/mcp-tools-context.d.ts +77 -0
- package/dist/lib/mcp-tools-context.d.ts.map +1 -0
- package/dist/lib/mcp-tools-context.js +266 -0
- package/dist/lib/mcp-tools-context.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Context Composer — token-budgeted, relevance-ranked context assembly.
|
|
4
|
+
*
|
|
5
|
+
* Agents have large context windows but a much smaller *effective reasoning*
|
|
6
|
+
* window: irrelevant, stale, or noisy context degrades output quality long
|
|
7
|
+
* before the hard token limit ("context rot"). This module assembles the
|
|
8
|
+
* context block for an LLM call from candidate sources (blackboard entries,
|
|
9
|
+
* project context, memory recall) under a **hard token budget**, ranked by:
|
|
10
|
+
*
|
|
11
|
+
* score = w.relevance × relevance + w.recency × recency + w.affinity × affinity
|
|
12
|
+
*
|
|
13
|
+
* - **relevance** — semantic similarity to the task via a pluggable
|
|
14
|
+
* {@link SemanticRanker} (BYOE — e.g. wrap `SemanticMemory`), with a
|
|
15
|
+
* deterministic lexical-overlap fallback when no ranker is supplied;
|
|
16
|
+
* - **recency** — exponential half-life decay on the entry timestamp
|
|
17
|
+
* (the same math `EpisodicMemory` uses);
|
|
18
|
+
* - **affinity** — scope-tag match on the key (same substring semantics as
|
|
19
|
+
* `ContextThrottler`).
|
|
20
|
+
*
|
|
21
|
+
* Pinned sources (task-critical instructions, Layer-3 project context) are
|
|
22
|
+
* always included first. Assembly is position-aware by default: the
|
|
23
|
+
* strongest items are placed at the start *and end* of the block, weakest in
|
|
24
|
+
* the middle — mitigating "lost in the middle" attention decay.
|
|
25
|
+
*
|
|
26
|
+
* The result carries full observability metadata: what was included,
|
|
27
|
+
* what was excluded and why, token usage, and budget utilization.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const composer = new ContextComposer();
|
|
32
|
+
* const sources = ContextComposer.fromSnapshot(blackboard.getScopedSnapshot('analyst'));
|
|
33
|
+
* const pack = await composer.compose(sources, {
|
|
34
|
+
* task: 'Summarize Q3 revenue anomalies',
|
|
35
|
+
* budgetTokens: 2000,
|
|
36
|
+
* scopeTags: ['analytics', 'task'],
|
|
37
|
+
* });
|
|
38
|
+
* llmPrompt = `${instructions}\n\n${pack.text}`;
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @module ContextComposer
|
|
42
|
+
* @version 1.0.0
|
|
43
|
+
*/
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.ContextComposer = void 0;
|
|
46
|
+
exports.estimateTokens = estimateTokens;
|
|
47
|
+
exports.createSemanticMemoryRanker = createSemanticMemoryRanker;
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// TOKEN ESTIMATION
|
|
50
|
+
// ============================================================================
|
|
51
|
+
/**
|
|
52
|
+
* Estimate the token count of a text without a tokenizer dependency.
|
|
53
|
+
*
|
|
54
|
+
* Uses the ~4-characters-per-token heuristic blended with a word count
|
|
55
|
+
* (English prose averages ~0.75 tokens/word; code and JSON run denser).
|
|
56
|
+
* Accurate to roughly ±15% across prose/code/JSON — sufficient for budget
|
|
57
|
+
* enforcement, not for billing.
|
|
58
|
+
*/
|
|
59
|
+
function estimateTokens(text) {
|
|
60
|
+
if (!text)
|
|
61
|
+
return 0;
|
|
62
|
+
const byChars = text.length / 4;
|
|
63
|
+
const words = text.split(/\s+/).filter(Boolean).length;
|
|
64
|
+
const byWords = words * 1.33;
|
|
65
|
+
return Math.max(1, Math.ceil((byChars + byWords) / 2));
|
|
66
|
+
}
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// INTERNAL HELPERS
|
|
69
|
+
// ============================================================================
|
|
70
|
+
/** Tokenize text into a lowercase word set for lexical overlap scoring. */
|
|
71
|
+
function wordSet(text) {
|
|
72
|
+
return new Set(text
|
|
73
|
+
.toLowerCase()
|
|
74
|
+
.split(/[^a-z0-9_]+/)
|
|
75
|
+
.filter((w) => w.length > 2));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Deterministic lexical relevance: fraction of task words present in the
|
|
79
|
+
* item (key + text). Zero-dependency fallback when no semantic ranker is
|
|
80
|
+
* configured.
|
|
81
|
+
*/
|
|
82
|
+
function lexicalRelevance(taskWords, item) {
|
|
83
|
+
if (taskWords.size === 0)
|
|
84
|
+
return 0;
|
|
85
|
+
const itemWords = wordSet(`${item.key} ${item.text}`);
|
|
86
|
+
if (itemWords.size === 0)
|
|
87
|
+
return 0;
|
|
88
|
+
let hits = 0;
|
|
89
|
+
for (const w of taskWords) {
|
|
90
|
+
if (itemWords.has(w))
|
|
91
|
+
hits++;
|
|
92
|
+
}
|
|
93
|
+
return hits / taskWords.size;
|
|
94
|
+
}
|
|
95
|
+
/** Exponential half-life recency decay (1 = now, → 0 with age). */
|
|
96
|
+
function recencyScore(timestamp, halfLifeMs, now) {
|
|
97
|
+
if (!timestamp)
|
|
98
|
+
return 0.5; // unknown age — neutral
|
|
99
|
+
const t = Date.parse(timestamp);
|
|
100
|
+
if (Number.isNaN(t))
|
|
101
|
+
return 0.5;
|
|
102
|
+
const elapsed = Math.max(0, now - t);
|
|
103
|
+
return Math.pow(0.5, elapsed / halfLifeMs);
|
|
104
|
+
}
|
|
105
|
+
/** Scope-tag affinity — ContextThrottler substring semantics on the key. */
|
|
106
|
+
function affinityScore(key, scopeTags) {
|
|
107
|
+
if (!scopeTags || scopeTags.length === 0)
|
|
108
|
+
return 0.5; // no scoping — neutral
|
|
109
|
+
const lowerKey = key.toLowerCase();
|
|
110
|
+
return scopeTags.some((tag) => lowerKey.includes(tag.toLowerCase())) ? 1 : 0;
|
|
111
|
+
}
|
|
112
|
+
/** True when the entry's TTL has already elapsed relative to its timestamp. */
|
|
113
|
+
function isStale(source, now) {
|
|
114
|
+
if (source.ttl === null || source.ttl === undefined)
|
|
115
|
+
return false;
|
|
116
|
+
if (!source.timestamp)
|
|
117
|
+
return false;
|
|
118
|
+
const t = Date.parse(source.timestamp);
|
|
119
|
+
if (Number.isNaN(t))
|
|
120
|
+
return false;
|
|
121
|
+
return now - t > source.ttl * 1000;
|
|
122
|
+
}
|
|
123
|
+
/** Render one item as a labelled context block. */
|
|
124
|
+
function renderBlock(item) {
|
|
125
|
+
const origin = item.sourceAgent ? ` (from ${item.sourceAgent})` : '';
|
|
126
|
+
return `### ${item.key}${origin}\n${item.text}`;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Serpentine layout: ranked items `[1,2,3,4,5]` become `[1,3,5,4,2]` —
|
|
130
|
+
* strongest first, second-strongest last, weakest in the middle.
|
|
131
|
+
*/
|
|
132
|
+
function positionAwareLayout(ranked) {
|
|
133
|
+
const head = [];
|
|
134
|
+
const tail = [];
|
|
135
|
+
ranked.forEach((item, i) => {
|
|
136
|
+
if (i % 2 === 0)
|
|
137
|
+
head.push(item);
|
|
138
|
+
else
|
|
139
|
+
tail.unshift(item);
|
|
140
|
+
});
|
|
141
|
+
return [...head, ...tail];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Adapt a `SemanticMemory` instance (or anything with a compatible
|
|
145
|
+
* `search()`) into a {@link SemanticRanker}. Items the memory does not know
|
|
146
|
+
* about simply fall back to lexical scoring.
|
|
147
|
+
*/
|
|
148
|
+
function createSemanticMemoryRanker(memory) {
|
|
149
|
+
return async (query, items) => {
|
|
150
|
+
const results = await memory.search(query, items.length, 0);
|
|
151
|
+
const scores = new Map();
|
|
152
|
+
for (const r of results) {
|
|
153
|
+
// Cosine similarity may be negative — clamp to 0–1.
|
|
154
|
+
scores.set(r.key, Math.max(0, Math.min(1, r.score)));
|
|
155
|
+
}
|
|
156
|
+
return scores;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
// ============================================================================
|
|
160
|
+
// CONTEXT COMPOSER
|
|
161
|
+
// ============================================================================
|
|
162
|
+
/**
|
|
163
|
+
* Assembles token-budgeted, relevance-ranked context packs from candidate
|
|
164
|
+
* sources. See the module docs for the ranking model.
|
|
165
|
+
*/
|
|
166
|
+
class ContextComposer {
|
|
167
|
+
halfLifeMs;
|
|
168
|
+
weights;
|
|
169
|
+
ranker;
|
|
170
|
+
constructor(options = {}) {
|
|
171
|
+
this.halfLifeMs = options.halfLifeMs ?? 1_800_000;
|
|
172
|
+
if (this.halfLifeMs <= 0) {
|
|
173
|
+
throw new Error('ContextComposer: halfLifeMs must be > 0');
|
|
174
|
+
}
|
|
175
|
+
const w = { relevance: 0.5, recency: 0.3, affinity: 0.2, ...(options.weights ?? {}) };
|
|
176
|
+
const sum = w.relevance + w.recency + w.affinity;
|
|
177
|
+
if (sum <= 0) {
|
|
178
|
+
throw new Error('ContextComposer: score weights must sum to a positive number');
|
|
179
|
+
}
|
|
180
|
+
this.weights = {
|
|
181
|
+
relevance: w.relevance / sum,
|
|
182
|
+
recency: w.recency / sum,
|
|
183
|
+
affinity: w.affinity / sum,
|
|
184
|
+
};
|
|
185
|
+
this.ranker = options.ranker;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Convert a blackboard snapshot (`getSnapshot()` / `getScopedSnapshot()`
|
|
189
|
+
* shape) into {@link ContextSource} candidates. Values are rendered as
|
|
190
|
+
* strings (JSON for objects) and truncated to `maxValueChars`.
|
|
191
|
+
*/
|
|
192
|
+
static fromSnapshot(snapshot, options = {}) {
|
|
193
|
+
const maxChars = options.maxValueChars ?? 4000;
|
|
194
|
+
const sources = [];
|
|
195
|
+
for (const [key, raw] of Object.entries(snapshot ?? {})) {
|
|
196
|
+
if (raw === null || raw === undefined)
|
|
197
|
+
continue;
|
|
198
|
+
let text;
|
|
199
|
+
let sourceAgent;
|
|
200
|
+
let timestamp;
|
|
201
|
+
let ttl;
|
|
202
|
+
if (typeof raw === 'object' && ('value' in raw)) {
|
|
203
|
+
const entry = raw;
|
|
204
|
+
const v = entry.value;
|
|
205
|
+
text = typeof v === 'string' ? v : JSON.stringify(v);
|
|
206
|
+
sourceAgent = entry.sourceAgent ?? entry.source_agent;
|
|
207
|
+
timestamp = entry.timestamp;
|
|
208
|
+
ttl = entry.ttl;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
text = typeof raw === 'string' ? raw : JSON.stringify(raw);
|
|
212
|
+
}
|
|
213
|
+
if (text === undefined || text === null)
|
|
214
|
+
continue;
|
|
215
|
+
sources.push({
|
|
216
|
+
key,
|
|
217
|
+
text: text.length > maxChars ? `${text.slice(0, maxChars)}…[truncated]` : text,
|
|
218
|
+
...(sourceAgent !== undefined ? { sourceAgent } : {}),
|
|
219
|
+
...(timestamp !== undefined ? { timestamp } : {}),
|
|
220
|
+
...(ttl !== undefined ? { ttl } : {}),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return sources;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Rank the candidate sources against the task and assemble the largest
|
|
227
|
+
* high-signal context block that fits the token budget.
|
|
228
|
+
*/
|
|
229
|
+
async compose(sources, options) {
|
|
230
|
+
if (!options || typeof options.task !== 'string' || options.task.trim() === '') {
|
|
231
|
+
throw new Error('ContextComposer.compose: options.task must be a non-empty string');
|
|
232
|
+
}
|
|
233
|
+
if (typeof options.budgetTokens !== 'number' || options.budgetTokens <= 0) {
|
|
234
|
+
throw new Error('ContextComposer.compose: options.budgetTokens must be > 0');
|
|
235
|
+
}
|
|
236
|
+
const now = Date.now();
|
|
237
|
+
const halfLifeMs = options.halfLifeMs ?? this.halfLifeMs;
|
|
238
|
+
const minScore = options.minScore ?? 0.05;
|
|
239
|
+
const maxItems = options.maxItems ?? 0;
|
|
240
|
+
const w = (() => {
|
|
241
|
+
if (!options.weights)
|
|
242
|
+
return this.weights;
|
|
243
|
+
const merged = { ...this.weights, ...options.weights };
|
|
244
|
+
const sum = merged.relevance + merged.recency + merged.affinity;
|
|
245
|
+
return sum > 0
|
|
246
|
+
? { relevance: merged.relevance / sum, recency: merged.recency / sum, affinity: merged.affinity / sum }
|
|
247
|
+
: this.weights;
|
|
248
|
+
})();
|
|
249
|
+
const excluded = [];
|
|
250
|
+
const pinned = [];
|
|
251
|
+
const candidates = [];
|
|
252
|
+
for (const source of sources ?? []) {
|
|
253
|
+
if (!source || typeof source.key !== 'string' || source.key === '')
|
|
254
|
+
continue;
|
|
255
|
+
if (!source.text || source.text.trim() === '') {
|
|
256
|
+
excluded.push({ key: source.key ?? '(unknown)', reason: 'empty' });
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (isStale(source, now)) {
|
|
260
|
+
excluded.push({ key: source.key, reason: 'stale' });
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
(source.pinned ? pinned : candidates).push(source);
|
|
264
|
+
}
|
|
265
|
+
// ── Relevance scores (semantic ranker with lexical fallback) ────────────
|
|
266
|
+
const taskWords = wordSet(options.task);
|
|
267
|
+
let semanticScores = new Map();
|
|
268
|
+
const ranker = options.ranker ?? this.ranker;
|
|
269
|
+
if (ranker && candidates.length > 0) {
|
|
270
|
+
try {
|
|
271
|
+
semanticScores = await ranker(options.task, candidates.map((c) => ({ key: c.key, text: c.text })));
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
semanticScores = new Map(); // ranker failure → lexical fallback for all
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// ── Score every candidate ────────────────────────────────────────────────
|
|
278
|
+
const ranked = candidates.map((c) => {
|
|
279
|
+
const relevance = semanticScores.get(c.key) ?? lexicalRelevance(taskWords, c);
|
|
280
|
+
const recency = recencyScore(c.timestamp, halfLifeMs, now);
|
|
281
|
+
const affinity = affinityScore(c.key, options.scopeTags);
|
|
282
|
+
const score = w.relevance * relevance + w.recency * recency + w.affinity * affinity;
|
|
283
|
+
return { ...c, relevance, recency, affinity, score, tokens: estimateTokens(renderBlock(c)) };
|
|
284
|
+
});
|
|
285
|
+
ranked.sort((a, b) => b.score - a.score);
|
|
286
|
+
// ── Budget-enforced selection: pinned first, then by score ──────────────
|
|
287
|
+
const included = [];
|
|
288
|
+
let usedTokens = 0;
|
|
289
|
+
for (const p of pinned) {
|
|
290
|
+
const tokens = estimateTokens(renderBlock(p));
|
|
291
|
+
if (usedTokens + tokens > options.budgetTokens) {
|
|
292
|
+
excluded.push({ key: p.key, reason: 'budget' });
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
usedTokens += tokens;
|
|
296
|
+
included.push({ ...p, relevance: 1, recency: 1, affinity: 1, score: 1, tokens });
|
|
297
|
+
}
|
|
298
|
+
for (const item of ranked) {
|
|
299
|
+
if (item.score < minScore) {
|
|
300
|
+
excluded.push({ key: item.key, reason: 'score', score: item.score });
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (maxItems > 0 && included.length >= maxItems) {
|
|
304
|
+
excluded.push({ key: item.key, reason: 'budget', score: item.score });
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (usedTokens + item.tokens > options.budgetTokens) {
|
|
308
|
+
excluded.push({ key: item.key, reason: 'budget', score: item.score });
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
usedTokens += item.tokens;
|
|
312
|
+
included.push(item);
|
|
313
|
+
}
|
|
314
|
+
// ── Assembly (pinned lead; ranked items in position-aware layout) ────────
|
|
315
|
+
const pinnedBlocks = included.filter((i) => i.pinned);
|
|
316
|
+
const rankedBlocks = included.filter((i) => !i.pinned);
|
|
317
|
+
const layout = (options.positionAware ?? true)
|
|
318
|
+
? positionAwareLayout(rankedBlocks)
|
|
319
|
+
: rankedBlocks;
|
|
320
|
+
const text = [...pinnedBlocks, ...layout].map((i) => renderBlock(i)).join('\n\n');
|
|
321
|
+
return {
|
|
322
|
+
text,
|
|
323
|
+
included,
|
|
324
|
+
excluded,
|
|
325
|
+
budgetTokens: options.budgetTokens,
|
|
326
|
+
usedTokens,
|
|
327
|
+
utilization: Math.min(1, usedTokens / options.budgetTokens),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
exports.ContextComposer = ContextComposer;
|
|
332
|
+
//# sourceMappingURL=context-composer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-composer.js","sourceRoot":"","sources":["../../../lib/context-composer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;;;AAcH,wCAMC;AAoND,gEAUC;AAhPD,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,IAAY;IACzC,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,CAAC;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IACvD,MAAM,OAAO,GAAG,KAAK,GAAG,IAAI,CAAC;IAC7B,OAAO,IAAI,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AAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;gBACtE,SAAS;YACX,CAAC;YACD,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC;YAC1B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;QAED,4EAA4E;QAC5E,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACtD,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC;YAC5C,CAAC,CAAC,mBAAmB,CAAC,YAAY,CAAC;YACnC,CAAC,CAAC,YAAY,CAAC;QAEjB,MAAM,IAAI,GAAG,CAAC,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAElF,OAAO;YACL,IAAI;YACJ,QAAQ;YACR,QAAQ;YACR,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,UAAU;YACV,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;SAC5D,CAAC;IACJ,CAAC;CACF;AApLD,0CAoLC"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP Context Tools — signal-over-noise retrieval for MCP agents.
|
|
4
|
+
*
|
|
5
|
+
* Two tools that let any MCP client (Claude Code, Codex, Gemini CLI, Cursor)
|
|
6
|
+
* pull *curated* shared state instead of dumping the whole blackboard into
|
|
7
|
+
* its own context window:
|
|
8
|
+
*
|
|
9
|
+
* - `context_pack` — "give me everything relevant to task X in
|
|
10
|
+
* ≤ N tokens": a token-budgeted, relevance-ranked, position-aware
|
|
11
|
+
* context brief assembled by {@link ContextComposer} from the agent's
|
|
12
|
+
* scoped blackboard snapshot.
|
|
13
|
+
* - `blackboard_search` — ranked top-K search over blackboard entries.
|
|
14
|
+
* Uses a semantic ranker when one is wired (BYOE `SemanticMemory`),
|
|
15
|
+
* falling back to deterministic lexical overlap scoring otherwise —
|
|
16
|
+
* always works out of the box.
|
|
17
|
+
*
|
|
18
|
+
* Implements the same `McpToolProvider` contract as the other tool modules,
|
|
19
|
+
* so it registers directly on `McpCombinedBridge`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const contextTools = new ContextMcpTools({ blackboard });
|
|
24
|
+
* combined.register(contextTools);
|
|
25
|
+
* // MCP client: context_pack { task: "fix the parser bug", budget_tokens: 1500, agent_id: "claude-code" }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @module mcp-tools-context
|
|
29
|
+
* @version 1.0.0
|
|
30
|
+
*/
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.ContextMcpTools = exports.CONTEXT_TOOL_DEFINITIONS = void 0;
|
|
33
|
+
const context_composer_1 = require("./context-composer");
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// TOOL DEFINITIONS
|
|
36
|
+
// ============================================================================
|
|
37
|
+
/** MCP tool definitions for the two context tools. */
|
|
38
|
+
exports.CONTEXT_TOOL_DEFINITIONS = [
|
|
39
|
+
{
|
|
40
|
+
name: 'context_pack',
|
|
41
|
+
description: 'Assemble a token-budgeted, relevance-ranked context brief from the shared blackboard for a given task. ' +
|
|
42
|
+
'Use this INSTEAD of blackboard_list + many blackboard_read calls: it returns only the entries most relevant ' +
|
|
43
|
+
'to your task, ranked by semantic/lexical relevance, recency (half-life decay), and namespace affinity, ' +
|
|
44
|
+
'assembled position-aware (strongest items first and last) under a hard token budget. ' +
|
|
45
|
+
'Read-only — never modifies the blackboard. Returns {ok:true, text, used_tokens, budget_tokens, utilization, ' +
|
|
46
|
+
'included:[{key,score,tokens}], excluded:[{key,reason}]}. The `text` field is ready to use as working context. ' +
|
|
47
|
+
'Entries past their TTL are excluded automatically.',
|
|
48
|
+
inputSchema: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
task: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
description: 'The task or question driving relevance ranking (e.g. "diagnose the failing payment webhook")',
|
|
54
|
+
},
|
|
55
|
+
agent_id: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
description: 'The agent requesting the pack (used for scoped access checks and audit)',
|
|
58
|
+
},
|
|
59
|
+
budget_tokens: {
|
|
60
|
+
type: 'number',
|
|
61
|
+
description: 'Hard token budget for the returned context text (default 2000)',
|
|
62
|
+
},
|
|
63
|
+
scope_tags: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
description: 'Optional comma-separated scope tags for namespace affinity (e.g. "task,analytics")',
|
|
66
|
+
},
|
|
67
|
+
max_items: {
|
|
68
|
+
type: 'number',
|
|
69
|
+
description: 'Optional hard cap on the number of included entries (0 = unlimited)',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
required: ['task', 'agent_id'],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'blackboard_search',
|
|
77
|
+
description: 'Search the shared blackboard for entries relevant to a query and return the top-K ranked matches. ' +
|
|
78
|
+
'Use this instead of blackboard_list when you need *relevant* keys rather than *all* keys — it keeps noise ' +
|
|
79
|
+
'out of your context window. Read-only. Ranks semantically when the server has an embedding provider wired, ' +
|
|
80
|
+
'otherwise by deterministic lexical overlap (response includes which mode was used). ' +
|
|
81
|
+
'Returns {ok:true, mode, results:[{key, score, snippet, sourceAgent}], count}. ' +
|
|
82
|
+
'Follow up with blackboard_read for the full value of a specific key.',
|
|
83
|
+
inputSchema: {
|
|
84
|
+
type: 'object',
|
|
85
|
+
properties: {
|
|
86
|
+
query: {
|
|
87
|
+
type: 'string',
|
|
88
|
+
description: 'Natural-language search query (e.g. "budget decisions for Q3")',
|
|
89
|
+
},
|
|
90
|
+
agent_id: {
|
|
91
|
+
type: 'string',
|
|
92
|
+
description: 'The agent performing the search (used for scoped access checks)',
|
|
93
|
+
},
|
|
94
|
+
top_k: {
|
|
95
|
+
type: 'number',
|
|
96
|
+
description: 'Maximum number of results to return (default 5, max 50)',
|
|
97
|
+
},
|
|
98
|
+
min_score: {
|
|
99
|
+
type: 'number',
|
|
100
|
+
description: 'Minimum relevance score 0-1 (default 0)',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
required: ['query', 'agent_id'],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
// ============================================================================
|
|
108
|
+
// CONTEXT MCP TOOLS
|
|
109
|
+
// ============================================================================
|
|
110
|
+
/**
|
|
111
|
+
* `McpToolProvider` exposing `context_pack` and `blackboard_search`.
|
|
112
|
+
* Register on a `McpCombinedBridge` alongside the other tool providers.
|
|
113
|
+
*/
|
|
114
|
+
class ContextMcpTools {
|
|
115
|
+
blackboard;
|
|
116
|
+
composer;
|
|
117
|
+
ranker;
|
|
118
|
+
semantic;
|
|
119
|
+
defaultBudgetTokens;
|
|
120
|
+
maxBudgetTokens;
|
|
121
|
+
constructor(options) {
|
|
122
|
+
if (!options || !options.blackboard) {
|
|
123
|
+
throw new Error('ContextMcpTools: options.blackboard is required');
|
|
124
|
+
}
|
|
125
|
+
this.blackboard = options.blackboard;
|
|
126
|
+
this.semantic = Boolean(options.memory);
|
|
127
|
+
this.ranker = options.memory ? (0, context_composer_1.createSemanticMemoryRanker)(options.memory) : undefined;
|
|
128
|
+
this.composer = options.composer
|
|
129
|
+
?? new context_composer_1.ContextComposer(this.ranker ? { ranker: this.ranker } : {});
|
|
130
|
+
this.defaultBudgetTokens = options.defaultBudgetTokens ?? 2000;
|
|
131
|
+
this.maxBudgetTokens = options.maxBudgetTokens ?? 32_000;
|
|
132
|
+
if (this.defaultBudgetTokens <= 0 || this.maxBudgetTokens <= 0) {
|
|
133
|
+
throw new Error('ContextMcpTools: token budgets must be > 0');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** Returns the MCP tool definitions provided by this module. */
|
|
137
|
+
getDefinitions() {
|
|
138
|
+
return exports.CONTEXT_TOOL_DEFINITIONS;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Dispatch a tool call by name. All errors are caught and returned as
|
|
142
|
+
* `{ ok: false, error }`.
|
|
143
|
+
*/
|
|
144
|
+
async call(toolName, args) {
|
|
145
|
+
try {
|
|
146
|
+
switch (toolName) {
|
|
147
|
+
case 'context_pack': return await this._pack(args);
|
|
148
|
+
case 'blackboard_search': return await this._search(args);
|
|
149
|
+
default:
|
|
150
|
+
return { ok: false, tool: toolName, error: `Unknown tool: "${toolName}"` };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
return {
|
|
155
|
+
ok: false,
|
|
156
|
+
tool: toolName,
|
|
157
|
+
error: err instanceof Error ? err.message : String(err),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// --------------------------------------------------------------------------
|
|
162
|
+
// Tool implementations
|
|
163
|
+
// --------------------------------------------------------------------------
|
|
164
|
+
async _pack(args) {
|
|
165
|
+
const task = this._requireString(args, 'task');
|
|
166
|
+
const agentId = this._requireString(args, 'agent_id');
|
|
167
|
+
const budget = this._clampNumber(args['budget_tokens'], this.defaultBudgetTokens, 1, this.maxBudgetTokens);
|
|
168
|
+
const maxItems = this._clampNumber(args['max_items'], 0, 0, 10_000);
|
|
169
|
+
const scopeTags = typeof args['scope_tags'] === 'string' && args['scope_tags'].trim() !== ''
|
|
170
|
+
? args['scope_tags'].split(',').map((t) => t.trim()).filter(Boolean)
|
|
171
|
+
: undefined;
|
|
172
|
+
const sources = context_composer_1.ContextComposer.fromSnapshot(this._snapshot(agentId));
|
|
173
|
+
const pack = await this.composer.compose(sources, {
|
|
174
|
+
task,
|
|
175
|
+
budgetTokens: budget,
|
|
176
|
+
...(scopeTags ? { scopeTags } : {}),
|
|
177
|
+
...(maxItems > 0 ? { maxItems } : {}),
|
|
178
|
+
});
|
|
179
|
+
return {
|
|
180
|
+
ok: true,
|
|
181
|
+
tool: 'context_pack',
|
|
182
|
+
data: {
|
|
183
|
+
text: pack.text,
|
|
184
|
+
used_tokens: pack.usedTokens,
|
|
185
|
+
budget_tokens: pack.budgetTokens,
|
|
186
|
+
utilization: Number(pack.utilization.toFixed(3)),
|
|
187
|
+
mode: this.semantic ? 'semantic' : 'lexical',
|
|
188
|
+
included: pack.included.map((i) => ({
|
|
189
|
+
key: i.key,
|
|
190
|
+
score: Number(i.score.toFixed(3)),
|
|
191
|
+
tokens: i.tokens,
|
|
192
|
+
})),
|
|
193
|
+
excluded: pack.excluded.map((e) => ({
|
|
194
|
+
key: e.key,
|
|
195
|
+
reason: e.reason,
|
|
196
|
+
...(e.score !== undefined ? { score: Number(e.score.toFixed(3)) } : {}),
|
|
197
|
+
})),
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async _search(args) {
|
|
202
|
+
const query = this._requireString(args, 'query');
|
|
203
|
+
const agentId = this._requireString(args, 'agent_id');
|
|
204
|
+
const topK = this._clampNumber(args['top_k'], 5, 1, 50);
|
|
205
|
+
const minScore = this._clampNumber(args['min_score'], 0, 0, 1);
|
|
206
|
+
const sources = context_composer_1.ContextComposer.fromSnapshot(this._snapshot(agentId));
|
|
207
|
+
// Rank purely by relevance: reuse the composer with relevance-only
|
|
208
|
+
// weights and an unbounded budget, then take the top-K.
|
|
209
|
+
const ranked = await this.composer.compose(sources, {
|
|
210
|
+
task: query,
|
|
211
|
+
budgetTokens: this.maxBudgetTokens,
|
|
212
|
+
weights: { relevance: 1, recency: 0, affinity: 0 },
|
|
213
|
+
minScore: Math.max(minScore, 0.000_001), // drop zero-relevance items
|
|
214
|
+
positionAware: false,
|
|
215
|
+
});
|
|
216
|
+
const results = ranked.included
|
|
217
|
+
.slice(0, topK)
|
|
218
|
+
.map((i) => ({
|
|
219
|
+
key: i.key,
|
|
220
|
+
score: Number(i.relevance.toFixed(3)),
|
|
221
|
+
snippet: i.text.length > 240 ? `${i.text.slice(0, 240)}…` : i.text,
|
|
222
|
+
...(i.sourceAgent ? { sourceAgent: i.sourceAgent } : {}),
|
|
223
|
+
}));
|
|
224
|
+
return {
|
|
225
|
+
ok: true,
|
|
226
|
+
tool: 'blackboard_search',
|
|
227
|
+
data: {
|
|
228
|
+
mode: this.semantic ? 'semantic' : 'lexical',
|
|
229
|
+
results,
|
|
230
|
+
count: results.length,
|
|
231
|
+
query_tokens: (0, context_composer_1.estimateTokens)(query),
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
// --------------------------------------------------------------------------
|
|
236
|
+
// Helpers
|
|
237
|
+
// --------------------------------------------------------------------------
|
|
238
|
+
_snapshot(agentId) {
|
|
239
|
+
if (this.blackboard.getScopedSnapshot) {
|
|
240
|
+
return this.blackboard.getScopedSnapshot(agentId);
|
|
241
|
+
}
|
|
242
|
+
return this.blackboard.getSnapshot();
|
|
243
|
+
}
|
|
244
|
+
_requireString(args, field) {
|
|
245
|
+
const val = args[field];
|
|
246
|
+
if (typeof val !== 'string' || val.trim() === '') {
|
|
247
|
+
throw new Error(`Missing required field "${field}" (must be a non-empty string)`);
|
|
248
|
+
}
|
|
249
|
+
return val;
|
|
250
|
+
}
|
|
251
|
+
/** Accept number or numeric string; clamp into [min, max]; fall back to a default. */
|
|
252
|
+
_clampNumber(raw, fallback, min, max) {
|
|
253
|
+
let n;
|
|
254
|
+
if (typeof raw === 'number')
|
|
255
|
+
n = raw;
|
|
256
|
+
else if (typeof raw === 'string' && raw.trim() !== '')
|
|
257
|
+
n = Number(raw);
|
|
258
|
+
else
|
|
259
|
+
return fallback;
|
|
260
|
+
if (!Number.isFinite(n))
|
|
261
|
+
return fallback;
|
|
262
|
+
return Math.min(max, Math.max(min, Math.floor(n)));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
exports.ContextMcpTools = ContextMcpTools;
|
|
266
|
+
//# sourceMappingURL=mcp-tools-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools-context.js","sourceRoot":"","sources":["../../../lib/mcp-tools-context.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AAGH,yDAO4B;AAwB5B,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E,sDAAsD;AACzC,QAAA,wBAAwB,GAAwB;IAC3D;QACE,IAAI,EAAE,cAAc;QACpB,WAAW,EACT,yGAAyG;YACzG,8GAA8G;YAC9G,yGAAyG;YACzG,uFAAuF;YACvF,8GAA8G;YAC9G,gHAAgH;YAChH,oDAAoD;QACtD,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,8FAA8F;iBAC5G;gBACD,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,yEAAyE;iBACvF;gBACD,aAAa,EAAE;oBACb,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,gEAAgE;iBAC9E;gBACD,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,oFAAoF;iBAClG;gBACD,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,qEAAqE;iBACnF;aACF;YACD,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC;SAC/B;KACF;IACD;QACE,IAAI,EAAE,mBAAmB;QACzB,WAAW,EACT,oGAAoG;YACpG,4GAA4G;YAC5G,6GAA6G;Y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AAE,OAAO,QAAQ,CAAC;QACzC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;CACF;AAjKD,0CAiKC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -218,6 +218,10 @@ export { createElicitationApprovalCallback, StdioElicitationChannel } from './li
|
|
|
218
218
|
export type { ElicitationCreateParams, ElicitationResult, ElicitationRequestSender, ElicitationRequestedSchema, ElicitationSchemaProperty, ElicitationApprovalOptions } from './lib/mcp-elicitation';
|
|
219
219
|
export { A2AServer } from './lib/a2a-server';
|
|
220
220
|
export type { A2AServerOptions, A2AServerTask, A2AServerTaskState, A2ATaskExecutor } from './lib/a2a-server';
|
|
221
|
+
export { ContextComposer, estimateTokens, createSemanticMemoryRanker } from './lib/context-composer';
|
|
222
|
+
export type { ContextSource, RankedContextItem, ComposedContext, ComposeOptions, ContextComposerOptions, ScoreWeights, SemanticRanker, SemanticSearchLike, ExclusionReason, ExcludedItem } from './lib/context-composer';
|
|
223
|
+
export { ContextMcpTools, CONTEXT_TOOL_DEFINITIONS } from './lib/mcp-tools-context';
|
|
224
|
+
export type { ContextMcpToolsOptions } from './lib/mcp-tools-context';
|
|
221
225
|
export { createAdapterTestSuite } from './lib/adapter-test-harness';
|
|
222
226
|
export type { AdapterTestSuiteConfig, AdapterTestResult, AssertFn, SectionFn } from './lib/adapter-test-harness';
|
|
223
227
|
export { SwarmTransportServer, SwarmTransportClient } from './lib/swarm-transport';
|