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,C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AE,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,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Context Tools — signal-over-noise retrieval for MCP agents.
|
|
3
|
+
*
|
|
4
|
+
* Two tools that let any MCP client (Claude Code, Codex, Gemini CLI, Cursor)
|
|
5
|
+
* pull *curated* shared state instead of dumping the whole blackboard into
|
|
6
|
+
* its own context window:
|
|
7
|
+
*
|
|
8
|
+
* - `context_pack` — "give me everything relevant to task X in
|
|
9
|
+
* ≤ N tokens": a token-budgeted, relevance-ranked, position-aware
|
|
10
|
+
* context brief assembled by {@link ContextComposer} from the agent's
|
|
11
|
+
* scoped blackboard snapshot.
|
|
12
|
+
* - `blackboard_search` — ranked top-K search over blackboard entries.
|
|
13
|
+
* Uses a semantic ranker when one is wired (BYOE `SemanticMemory`),
|
|
14
|
+
* falling back to deterministic lexical overlap scoring otherwise —
|
|
15
|
+
* always works out of the box.
|
|
16
|
+
*
|
|
17
|
+
* Implements the same `McpToolProvider` contract as the other tool modules,
|
|
18
|
+
* so it registers directly on `McpCombinedBridge`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const contextTools = new ContextMcpTools({ blackboard });
|
|
23
|
+
* combined.register(contextTools);
|
|
24
|
+
* // MCP client: context_pack { task: "fix the parser bug", budget_tokens: 1500, agent_id: "claude-code" }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module mcp-tools-context
|
|
28
|
+
* @version 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
import type { MCPToolDefinition, BlackboardToolResult, IBlackboard } from './mcp-blackboard-tools';
|
|
31
|
+
import { ContextComposer, type SemanticSearchLike } from './context-composer';
|
|
32
|
+
/** Options for {@link ContextMcpTools}. */
|
|
33
|
+
export interface ContextMcpToolsOptions {
|
|
34
|
+
/** The blackboard to compose/search over (required) */
|
|
35
|
+
blackboard: IBlackboard;
|
|
36
|
+
/**
|
|
37
|
+
* Optional BYOE semantic memory. When provided, `blackboard_search` and
|
|
38
|
+
* `context_pack` rank by embedding similarity; otherwise both fall back
|
|
39
|
+
* to deterministic lexical scoring.
|
|
40
|
+
*/
|
|
41
|
+
memory?: SemanticSearchLike;
|
|
42
|
+
/** Optional pre-configured composer (default: `new ContextComposer()`) */
|
|
43
|
+
composer?: ContextComposer;
|
|
44
|
+
/** Default token budget for `context_pack` when the caller omits one (default 2000) */
|
|
45
|
+
defaultBudgetTokens?: number;
|
|
46
|
+
/** Hard ceiling on any requested budget (default 32000) */
|
|
47
|
+
maxBudgetTokens?: number;
|
|
48
|
+
}
|
|
49
|
+
/** MCP tool definitions for the two context tools. */
|
|
50
|
+
export declare const CONTEXT_TOOL_DEFINITIONS: MCPToolDefinition[];
|
|
51
|
+
/**
|
|
52
|
+
* `McpToolProvider` exposing `context_pack` and `blackboard_search`.
|
|
53
|
+
* Register on a `McpCombinedBridge` alongside the other tool providers.
|
|
54
|
+
*/
|
|
55
|
+
export declare class ContextMcpTools {
|
|
56
|
+
private readonly blackboard;
|
|
57
|
+
private readonly composer;
|
|
58
|
+
private readonly ranker;
|
|
59
|
+
private readonly semantic;
|
|
60
|
+
private readonly defaultBudgetTokens;
|
|
61
|
+
private readonly maxBudgetTokens;
|
|
62
|
+
constructor(options: ContextMcpToolsOptions);
|
|
63
|
+
/** Returns the MCP tool definitions provided by this module. */
|
|
64
|
+
getDefinitions(): MCPToolDefinition[];
|
|
65
|
+
/**
|
|
66
|
+
* Dispatch a tool call by name. All errors are caught and returned as
|
|
67
|
+
* `{ ok: false, error }`.
|
|
68
|
+
*/
|
|
69
|
+
call(toolName: string, args: Record<string, unknown>): Promise<BlackboardToolResult>;
|
|
70
|
+
private _pack;
|
|
71
|
+
private _search;
|
|
72
|
+
private _snapshot;
|
|
73
|
+
private _requireString;
|
|
74
|
+
/** Accept number or numeric string; clamp into [min, max]; fall back to a default. */
|
|
75
|
+
private _clampNumber;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=mcp-tools-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools-context.d.ts","sourceRoot":"","sources":["../../lib/mcp-tools-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,EAC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