MCPcopy Create free account
hub / github.com/freecodexyz/free-code / peek

Function peek

src/utils/messageQueueManager.ts:219–238  ·  view source on GitHub ↗
(
  filter?: (cmd: QueuedCommand) => boolean,
)

Source from the content-addressed store, hash-verified

217 * Accepts an optional `filter` — only commands passing the predicate are considered.
218 */
219export function peek(
220 filter?: (cmd: QueuedCommand) => boolean,
221): QueuedCommand | undefined {
222 if (commandQueue.length === 0) {
223 return undefined
224 }
225 let bestIdx = -1
226 let bestPriority = Infinity
227 for (let i = 0; i < commandQueue.length; i++) {
228 const cmd = commandQueue[i]!
229 if (filter && !filter(cmd)) continue
230 const priority = PRIORITY_ORDER[cmd.priority ?? 'next']
231 if (priority < bestPriority) {
232 bestIdx = i
233 bestPriority = priority
234 }
235 }
236 if (bestIdx === -1) return undefined
237 return commandQueue[bestIdx]
238}
239
240/**
241 * Remove and return all commands matching a predicate, preserving priority order.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected