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

Function foldShellRunToolActivities

packages/ui/src/materialize.ts:791–842  ·  view source on GitHub ↗
(
  items: readonly ToolActivityItem[],
)

Source from the content-addressed store, hash-verified

789 * revision.
790 */
791export function foldShellRunToolActivities(
792 items: readonly ToolActivityItem[],
793): ToolActivityItem[] {
794 const ownedRefs = new Set<string>();
795 for (const item of items) {
796 if (item.toolName === "Bash" && item.result?.kind === "shell_run")
797 ownedRefs.add(item.result.ref);
798 }
799
800 const folded: ToolActivityItem[] = [];
801 const parentIndexByRef = new Map<string, number>();
802 const childResultsByRef = new Map<string, ShellRunToolResult[]>();
803
804 for (const item of items) {
805 const result = item.result?.kind === "shell_run" ? item.result : undefined;
806 if (!result || item.toolName === "Bash") {
807 if (result) parentIndexByRef.set(result.ref, folded.length);
808 folded.push(item);
809 continue;
810 }
811 if (ownedRefs.has(result.ref)) {
812 const pending = childResultsByRef.get(result.ref);
813 if (pending) pending.push(result);
814 else childResultsByRef.set(result.ref, [result]);
815 if (item.toolName === "Read" || item.toolName === "StopBackgroundTask")
816 continue;
817 }
818 folded.push(item);
819 }
820
821 for (const [ref, results] of childResultsByRef) {
822 const index = parentIndexByRef.get(ref)!;
823 const parent = folded[index]!;
824 let current =
825 parent.result?.kind === "shell_run" ? parent.result : undefined;
826 let changed = false;
827 for (const result of results) {
828 const merged = mergeShellRunStateWithDiagnostics(
829 current,
830 result,
831 "ui.fold-shell-run-child",
832 );
833 if (merged.changed) {
834 current = merged.result;
835 changed = true;
836 }
837 }
838 if (changed && current) folded[index] = { ...parent, result: current };
839 }
840
841 return folded;
842}
843
844function foldShellRunTurns(
845 turns: readonly TurnViewModel[],

Callers 3

materializeTurnsFunction · 0.85
foldShellRunTurnsFunction · 0.85

Calls 6

addMethod · 0.65
setMethod · 0.65
pushMethod · 0.65
hasMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected