MCPcopy Create free account
hub / github.com/apache/maka / reconcileToolsWithStoredMessages

Function reconcileToolsWithStoredMessages

packages/cli/src/pi-transcript.ts:344–389  ·  view source on GitHub ↗
(
  state: MakaPiTranscriptState,
  turnId: string,
  messages: readonly StoredMessage[],
)

Source from the content-addressed store, hash-verified

342 * live events without applying session-switch reset semantics.
343 */
344export function reconcileToolsWithStoredMessages(
345 state: MakaPiTranscriptState,
346 turnId: string,
347 messages: readonly StoredMessage[],
348): boolean {
349 const turnMessages = messages.filter((message) => message.turnId === turnId);
350 const durableTools = new Map(
351 foldStoredShellRunChildren(
352 materializeSession(turnMessages).items.flatMap(chatItemToTranscriptEntries),
353 )
354 .filter(
355 (entry): entry is Extract<MakaPiTranscriptEntry, { kind: 'tool' }> => entry.kind === 'tool',
356 )
357 .map((entry) => [entry.toolUseId, entry]),
358 );
359 let changed = false;
360 const reconciled: MakaPiTranscriptEntry[] = [];
361 for (const entry of state.entries) {
362 if (entry.kind !== 'tool' || entry.turnId !== turnId) {
363 reconciled.push(entry);
364 continue;
365 }
366 const durable = durableTools.get(entry.toolUseId);
367 if (!durable) {
368 if (!entryInLiveViewport(state, entry)) {
369 entry.hidden = true;
370 reconciled.push(entry);
371 }
372 changed = true;
373 continue;
374 }
375 entry.toolName = durable.toolName;
376 entry.title = durable.title;
377 entry.input = structuredClone(durable.input);
378 entry.result = durable.result ? structuredClone(durable.result) : undefined;
379 entry.output = durable.output;
380 entry.durationMs = durable.durationMs;
381 entry.status = durable.status;
382 entry.hidden = durable.hidden;
383 entry.resultVersion += 1;
384 changed = true;
385 reconciled.push(entry);
386 }
387 state.entries = reconciled;
388 return changed;
389}
390
391/**
392 * True when the entry will render inside the live viewport, or has not been

Callers 2

runMakaPiTuiFunction · 0.85

Calls 5

materializeSessionFunction · 0.90
entryInLiveViewportFunction · 0.85
pushMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected