b208c4d2bd
Memind CI / Test, build, and release guards (push) Failing after 3m47s
Add CONTEXT_RUNTIME_ACTIVE_ENV bundle and zero-LLM active probe covering MCP compact, zvec, and headroom proxy readiness while keeping memory injection on shadow. Co-authored-by: Cursor <cursoragent@cursor.com>
145 lines
5.1 KiB
JavaScript
145 lines
5.1 KiB
JavaScript
import { buildHeadroomRunObservation, resolveHeadroomMode } from './memind-headroom-policy.mjs';
|
|
import {
|
|
buildContextBudgetResolvedEvent,
|
|
planContextBudget,
|
|
resolveContextBudgetMode,
|
|
} from './context-budget.mjs';
|
|
import { resolveMcpCompactMode } from './mcp-result-compactor.mjs';
|
|
import {
|
|
buildRecallFusionResolvedEvent,
|
|
fuseRecallCandidates,
|
|
resolveRecallFusionMode,
|
|
} from './recall-fusion.mjs';
|
|
import { resolveZvecWorkspaceMode } from './memind-zvec-workspace.mjs';
|
|
|
|
/** Recommended local shadow profile (observe-only, no behavior change). */
|
|
export const CONTEXT_RUNTIME_SHADOW_ENV = Object.freeze({
|
|
MEMIND_HEADROOM_MODE: 'shadow',
|
|
MEMIND_CONTEXT_BUDGET_MODE: 'shadow',
|
|
MEMIND_RECALL_FUSION_MODE: 'shadow',
|
|
MEMIND_MCP_COMPACT_MODE: 'shadow',
|
|
MEMIND_ZVEC_WORKSPACE_MODE: 'shadow',
|
|
});
|
|
|
|
/** Local active bundle (MCP/ budget / recall / zvec / headroom). Injection stays shadow separately. */
|
|
export const CONTEXT_RUNTIME_ACTIVE_ENV = Object.freeze({
|
|
MEMIND_HEADROOM_MODE: 'active',
|
|
MEMIND_CONTEXT_BUDGET_MODE: 'active',
|
|
MEMIND_RECALL_FUSION_MODE: 'active',
|
|
MEMIND_MCP_COMPACT_MODE: 'active',
|
|
MEMIND_ZVEC_WORKSPACE_MODE: 'active',
|
|
HEADROOM_OUTPUT_SHAPER: '0',
|
|
});
|
|
|
|
export function describeContextRuntimeProfile(env = process.env) {
|
|
return {
|
|
headroom: resolveHeadroomMode(env),
|
|
contextBudget: resolveContextBudgetMode(env),
|
|
recallFusion: resolveRecallFusionMode(env),
|
|
mcpCompact: resolveMcpCompactMode(env),
|
|
zvecWorkspace: resolveZvecWorkspaceMode(env),
|
|
};
|
|
}
|
|
|
|
export function isContextRuntimeShadowProfile(env = process.env) {
|
|
const profile = describeContextRuntimeProfile(env);
|
|
return Object.values(profile).every((mode) => mode === 'off' || mode === 'shadow');
|
|
}
|
|
|
|
export function isAnyContextRuntimeObservabilityEnabled(env = process.env) {
|
|
const profile = describeContextRuntimeProfile(env);
|
|
return Object.values(profile).some((mode) => mode !== 'off');
|
|
}
|
|
|
|
/**
|
|
* Offline simulation of gateway shadow events (no LLM / no DB).
|
|
* Mirrors agent-run-gateway appendEvent payloads for local evidence review.
|
|
*/
|
|
export function simulateContextRuntimeShadowEvents({
|
|
skillId = 'web',
|
|
userMessage = {
|
|
role: 'user',
|
|
content: [{ type: 'text', text: '帮我查一下 Memind context runtime 设计' }],
|
|
metadata: { displayText: '帮我查一下 Memind context runtime 设计' },
|
|
},
|
|
routing = {
|
|
route: 'agent_orchestration',
|
|
suggestedSkill: 'web',
|
|
reason: 'offline-shadow-simulation',
|
|
},
|
|
memoryContext = {
|
|
mode: 'shadow',
|
|
injectionEnabled: true,
|
|
memories: [
|
|
{ label: '偏好', text: '用户偏好:喜欢简洁回答' },
|
|
{ label: '偏好副本', text: '用户偏好:喜欢简洁回答' },
|
|
{ label: '项目', text: '正在推进 Context Runtime 融合' },
|
|
],
|
|
},
|
|
env = { ...CONTEXT_RUNTIME_SHADOW_ENV },
|
|
} = {}) {
|
|
const events = {};
|
|
const resolvedSkill = routing?.suggestedSkill ?? routing?.suggested_skill ?? skillId;
|
|
|
|
if (resolveHeadroomMode(env) !== 'off') {
|
|
events.headroom_context_observed = buildHeadroomRunObservation({
|
|
skillId: resolvedSkill,
|
|
env,
|
|
});
|
|
}
|
|
|
|
if (resolveRecallFusionMode(env) !== 'off') {
|
|
const fusion = fuseRecallCandidates({
|
|
personalMemories: memoryContext?.memories ?? [],
|
|
episodicMemories: [],
|
|
temporalItems: [],
|
|
query: userMessage.metadata?.displayText ?? 'context runtime',
|
|
limit: 3,
|
|
env,
|
|
});
|
|
events.recall_fusion_resolved = buildRecallFusionResolvedEvent(fusion);
|
|
}
|
|
|
|
if (resolveContextBudgetMode(env) !== 'off') {
|
|
const displayText = userMessage.metadata?.displayText
|
|
?? userMessage.content?.find?.((item) => item?.type === 'text')?.text
|
|
?? '';
|
|
const budgetPlan = planContextBudget({
|
|
userTask: displayText,
|
|
skillPrompt: `[skill:${resolvedSkill}] 使用 web 搜索补充事实`,
|
|
memories: memoryContext?.injectionEnabled ? memoryContext.memories : [],
|
|
temporalText: '最近一周无日程冲突',
|
|
harnessEntries: [{ title: 'TKMind 用户偏好画像', content: '用户偏好:喜欢简洁回答' }],
|
|
}, { env });
|
|
events.context_budget_resolved = buildContextBudgetResolvedEvent(budgetPlan);
|
|
}
|
|
|
|
return {
|
|
profile: describeContextRuntimeProfile(env),
|
|
events,
|
|
};
|
|
}
|
|
|
|
export function validateContextRuntimeShadowEvents(simulation) {
|
|
const issues = [];
|
|
const { profile, events } = simulation ?? {};
|
|
if (!profile || !events) {
|
|
return { ok: false, issues: ['simulation missing profile or events'] };
|
|
}
|
|
|
|
if (profile.headroom !== 'off' && !events.headroom_context_observed) {
|
|
issues.push('headroom mode enabled but headroom_context_observed missing');
|
|
}
|
|
if (profile.contextBudget !== 'off' && !events.context_budget_resolved) {
|
|
issues.push('context budget mode enabled but context_budget_resolved missing');
|
|
}
|
|
if (profile.recallFusion !== 'off' && !events.recall_fusion_resolved) {
|
|
issues.push('recall fusion mode enabled but recall_fusion_resolved missing');
|
|
}
|
|
if (events.context_budget_resolved?.mode === 'shadow' && !events.context_budget_resolved?.duplicateCount) {
|
|
issues.push('expected shadow budget simulation to report duplicate fingerprints');
|
|
}
|
|
|
|
return { ok: issues.length === 0, issues };
|
|
}
|