(
ctx: ToolContext,
toolCtx: RunContext,
title: string,
)
| 35 | } |
| 36 | |
| 37 | export 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 | |
| 81 | export async function finalizeSession( |
| 82 | ctx: ToolContext, |
no test coverage detected