MCPcopy Index your code
hub / github.com/Opencode-DCP/opencode-dynamic-context-pruning / prepareSession

Function prepareSession

lib/compress/pipeline.ts:37–79  ·  view source on GitHub ↗
(
    ctx: ToolContext,
    toolCtx: RunContext,
    title: string,
)

Source from the content-addressed store, hash-verified

35}
36
37export async function prepareSession(
38 ctx: ToolContext,
39 toolCtx: RunContext,
40 title: string,
41): Promise<PreparedSession> {
42 await refreshManualMode(ctx.state, toolCtx.sessionID, ctx.logger, ctx.config.manualMode.enabled)
43
44 if (ctx.state.manualMode && ctx.state.manualMode !== "compress-pending") {
45 throw new Error(
46 "Manual mode: compress blocked. Do not retry until `<compress triggered manually>` appears in user context.",
47 )
48 }
49
50 await toolCtx.ask({
51 permission: "compress",
52 patterns: ["*"],
53 always: ["*"],
54 metadata: {},
55 })
56
57 toolCtx.metadata({ title })
58
59 const rawMessages = await fetchSessionMessages(ctx.client, toolCtx.sessionID)
60
61 await ensureSessionInitialized(
62 ctx.client,
63 ctx.state,
64 toolCtx.sessionID,
65 ctx.logger,
66 rawMessages,
67 ctx.config.manualMode.enabled,
68 )
69
70 assignMessageRefs(ctx.state, rawMessages)
71
72 deduplicate(ctx.state, ctx.logger, ctx.config, rawMessages)
73 purgeErrors(ctx.state, ctx.logger, ctx.config, rawMessages)
74
75 return {
76 rawMessages,
77 searchContext: buildSearchContext(ctx.state, rawMessages),
78 }
79}
80
81export async function finalizeSession(
82 ctx: ToolContext,

Callers 2

executeFunction · 0.90
executeFunction · 0.90

Calls 9

refreshManualModeFunction · 0.90
fetchSessionMessagesFunction · 0.90
ensureSessionInitializedFunction · 0.90
assignMessageRefsFunction · 0.90
deduplicateFunction · 0.90
purgeErrorsFunction · 0.90
buildSearchContextFunction · 0.90
askMethod · 0.80
metadataMethod · 0.80

Tested by

no test coverage detected