feat(context): add MCP result compactor for tool output shadow path
Memind CI / Test, build, and release guards (push) Has been cancelled
Memind CI / Test, build, and release guards (push) Has been cancelled
Introduce off/shadow/active compaction for large tkmind read/research and excel report payloads with optional Redis-backed ctx_fetch handles, keeping fail-open behavior when storage is unavailable. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Local smoke for MCP result compactor (Phase 1-B).
|
||||
*/
|
||||
import {
|
||||
applyMcpCompaction,
|
||||
createMemoryCompactStore,
|
||||
fetchCompactPayload,
|
||||
resetMcpCompactStoresForTests,
|
||||
resolveMcpCompactMode,
|
||||
} from '../mcp-result-compactor.mjs';
|
||||
|
||||
resetMcpCompactStoresForTests();
|
||||
const store = createMemoryCompactStore();
|
||||
const payload = `section-${'x'.repeat(6000)}\nfooter-line`;
|
||||
|
||||
const shadow = await applyMcpCompaction(payload, {
|
||||
kind: 'tkmind_read',
|
||||
env: { MEMIND_MCP_COMPACT_MODE: 'shadow', MEMIND_MCP_COMPACT_BUDGET_CHARS: '800' },
|
||||
store,
|
||||
});
|
||||
if (shadow.text !== payload || shadow.mode !== 'shadow') {
|
||||
throw new Error(`shadow mode should keep original payload: ${JSON.stringify(shadow)}`);
|
||||
}
|
||||
|
||||
const active = await applyMcpCompaction(payload, {
|
||||
kind: 'tkmind_read',
|
||||
env: { MEMIND_MCP_COMPACT_MODE: 'active', MEMIND_MCP_COMPACT_BUDGET_CHARS: '800' },
|
||||
store,
|
||||
});
|
||||
if (!active.compacted || !active.handle) {
|
||||
throw new Error(`active mode should compact payload: ${JSON.stringify(active)}`);
|
||||
}
|
||||
const restored = await fetchCompactPayload(active.handle, { store });
|
||||
if (!restored.ok || restored.text !== payload) {
|
||||
throw new Error(`ctx_fetch restore failed: ${JSON.stringify(restored)}`);
|
||||
}
|
||||
|
||||
console.log('MCP_COMPACTOR_LOCAL_OK:', {
|
||||
mode: resolveMcpCompactMode(),
|
||||
shadowSavedRatio: shadow.stats?.savedRatio ?? 0,
|
||||
activeSavedRatio: active.stats?.savedRatio ?? 0,
|
||||
handle: active.handle,
|
||||
});
|
||||
Reference in New Issue
Block a user