MCPcopy
hub / github.com/Doorman11991/smallcode / buildDynamicContext

Function buildDynamicContext

bin/smallcode.js:1986–2006  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

1984// when SMALLCODE_CACHE_SPLIT=true. Returns '' when there's no dynamic content
1985// or when cache-split is disabled.
1986function buildDynamicContext(messages) {
1987 if (process.env.SMALLCODE_CACHE_SPLIT === 'false') return ''; // default: enabled
1988 const parts = [
1989 // Memory + knowledge are query-dependent → move to user message (dynamic)
1990 getMemoryContext(messages),
1991 getSkillContext(messages),
1992 getKnowledgeContext(messages),
1993 getRagContext(messages),
1994 // Note: getPluginPrompts() stays in the system prompt — plugin instructions
1995 // are authoritative and should come from the system role.
1996 // Note: getActivePlanContext() stays in the system prompt — the model needs
1997 // to trust plan step instructions; user-role is ignored for directives.
1998 // Note: getTestRunnerContext() stays in the system prompt — it's stable and
1999 // benefits from caching alongside the static base.
2000 ].filter(p => p && p.length > 0);
2001 if (parts.length === 0) return '';
2002 // Strip ANSI from the dynamic block — same reason we strip from messages:
2003 // memory/knowledge entries can contain ANSI color codes from prior tool output.
2004 const raw = `<sc:context>\n${parts.join('')}\n</sc:context>\n\n`;
2005 return raw.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '').replace(/\x1b\][^\x07]*\x07/g, '');
2006}
2007
2008// Test runner context (Feature 10): inject the detected test command once
2009// so the model knows how to run tests without 3 discovery tool calls.

Callers 1

chatCompletionFunction · 0.85

Calls 4

getKnowledgeContextFunction · 0.85
getRagContextFunction · 0.85
getMemoryContextFunction · 0.70
getSkillContextFunction · 0.70

Tested by

no test coverage detected