src/shared/context/README.md
Pure function context builder for AI message preparation. Production context builder used by orchestration layer.
import { buildContext } from '@shared/context'
import type { AttachmentResolver, ContextBuilderOptions } from '@shared/context'
Production context builder - Pure function that prepares messages for AI generation.
Used directly by orchestration.ts and wrapped by genMessageContext() in the session module.
async function buildContext(
messages: Message[],
options: ContextBuilderOptions
): Promise<Message[]>
Processing pipeline:
generating: true)Usage pattern:
import { buildContext, createAttachmentResolver } from '@shared/context'
const resolver = createAttachmentResolver()
const contextMessages = await buildContext(messages, {
attachmentResolver: resolver,
maxContextMessageCount: 50,
})
Platform abstraction for reading attachments. Implemented by renderer.
interface AttachmentResolver {
read(id: string): Promise<string | null>
}
interface ContextBuilderOptions {
attachmentResolver: AttachmentResolver
maxContextMessageCount?: number
compactionPoints?: CompactionPoint[]
keepToolCallRounds?: number
modelSupportToolUseForFile?: boolean
}
Options:
attachmentResolver - Required. Platform abstraction for accessing attachmentsmaxContextMessageCount - Optional. Limits context to the most recent N messagescompactionPoints - Optional. History compression points for context optimizationkeepToolCallRounds - Optional. Number of recent tool call rounds to preserve (default: 2)modelSupportToolUseForFile - Optional. Whether model supports tool use for file reading (default: false)buildContext() is the only context builder in productiongenMessageContext() in session module wraps buildContext() with session-specific logic