Function: assembleForkContext()
Makaio Framework / services-core / assembleForkContext
Function: assembleForkContext()
Section titled “Function: assembleForkContext()”assembleForkContext(
bus,session,sessionId,originalContext?,isNewTurn?):Promise<{extractedContext?:unknown;hasCompression?:boolean;hasConnectorSwap?:boolean;hasNewTransforms?:boolean;isFirstTurn?:boolean;messageHistory?:object[];turnContext?:Record<string,JsonValue>; } |undefined>
Defined in: ../../../packages/services/core/src/session/context/assemble-fork-context.ts:25
Assemble fork context for a session’s first turn.
For fork sessions on their first turn, this:
- Detects if this is a fork session (has parentSessionId)
- Checks if this is the first turn (via isNewTurn flag + storage query)
- Calls getFullConversation() to get projected context with transforms
- Converts SessionMessage[] to Message[] format
- Returns enriched SessionContext with messageHistory
If not a fork first turn, returns the original sessionContext unchanged.
Parameters
Section titled “Parameters”Bus instance for RPC calls
session
Section titled “session”Session to check for fork context
sessionId
Section titled “sessionId”string
Session ID
originalContext?
Section titled “originalContext?”Original sessionContext from payload
extractedContext?
Section titled “extractedContext?”unknown = ...
Structured context from compression (if hasCompression=true).
hasCompression?
Section titled “hasCompression?”boolean = ...
Whether compression is active (extractedContext present). If true, Agent should use fresh mode with compressed context.
hasConnectorSwap?
Section titled “hasConnectorSwap?”boolean = ...
Whether a connector swap occurred before this message (e.g., cwd/model change). If true, native resume is infeasible and adapters should use fresh mode.
hasNewTransforms?
Section titled “hasNewTransforms?”boolean = ...
Whether transforms have been applied since last turn. If true, Agent should use fresh mode (history changed).
isFirstTurn?
Section titled “isFirstTurn?”boolean = ...
Whether this is the first turn in the session. If true, no native history exists yet.
messageHistory?
Section titled “messageHistory?”object[] = ...
Curated message history assembled via getFullConversation(). Only used if Agent decides to inject (fresh mode).
turnContext?
Section titled “turnContext?”Record<string, JsonValue> = ...
Turn-scoped context assembled by PreUserMessage hooks and the orchestrator. Keys are plugin-defined (e.g., ‘skillCatalog’, ‘skills’, ‘predictedTools’). Adapters consume this to prepend context blocks.
Constrained to JSON-safe types to ensure serialization succeeds.
ADAPTER CONTRACT: Every adapter MUST materialize turnContext into the LLM-facing message using serializeTurnContext().
isNewTurn?
Section titled “isNewTurn?”boolean
Whether this is a new turn (avoids race with just-created turn record)
Returns
Section titled “Returns”Promise<{ extractedContext?: unknown; hasCompression?: boolean; hasConnectorSwap?: boolean; hasNewTransforms?: boolean; isFirstTurn?: boolean; messageHistory?: object[]; turnContext?: Record<string, JsonValue>; } | undefined>
Enriched or original SessionContext