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

Function getLastUserMessage

lib/messages/query.ts:5–20  ·  view source on GitHub ↗
(
    messages: WithParts[],
    startIndex?: number,
)

Source from the content-addressed store, hash-verified

3import { isMessageWithInfo } from "./shape"
4
5export const getLastUserMessage = (
6 messages: WithParts[],
7 startIndex?: number,
8): WithParts | null => {
9 const start = startIndex ?? messages.length - 1
10 for (let i = start; i >= 0; i--) {
11 const msg = messages[i]
12 if (!isMessageWithInfo(msg)) {
13 continue
14 }
15 if (msg.info.role === "user" && !isIgnoredUserMessage(msg)) {
16 return msg
17 }
18 }
19 return null
20}
21
22export const messageHasCompress = (message: WithParts): boolean => {
23 if (!isMessageWithInfo(message)) {

Callers 7

getCurrentParamsFunction · 0.90
checkSessionFunction · 0.90
stripStaleMetadataFunction · 0.90
filterCompressedRangesFunction · 0.90
getModelInfoFunction · 0.90
injectCompressNudgesFunction · 0.90

Calls 2

isMessageWithInfoFunction · 0.90
isIgnoredUserMessageFunction · 0.85

Tested by

no test coverage detected