MCPcopy Index your code
hub / github.com/Noumena-Network/code / computeDiffStatsBetweenMessages

Function computeDiffStatsBetweenMessages

src/components/MessageSelector.tsx:723–767  ·  view source on GitHub ↗

* Computes the diff stats for all the file edits in-between two messages.

(messages: Message[], fromMessageId: UUID, toMessageId: UUID | undefined)

Source from the content-addressed store, hash-verified

721 * Computes the diff stats for all the file edits in-between two messages.
722 */
723function computeDiffStatsBetweenMessages(messages: Message[], fromMessageId: UUID, toMessageId: UUID | undefined): DiffStats | undefined {
724 const startIndex = messages.findIndex(msg => msg.uuid === fromMessageId);
725 if (startIndex === -1) {
726 return undefined;
727 }
728 let endIndex = toMessageId ? messages.findIndex(msg => msg.uuid === toMessageId) : messages.length;
729 if (endIndex === -1) {
730 endIndex = messages.length;
731 }
732 const filesChanged: string[] = [];
733 let insertions = 0;
734 let deletions = 0;
735 for (let i = startIndex + 1; i < endIndex; i++) {
736 const msg = messages[i];
737 if (!msg || !isToolUseResultMessage(msg)) {
738 continue;
739 }
740 const result = msg.toolUseResult as FileEditOutput | FileWriteToolOutput;
741 if (!result || !result.filePath || !result.structuredPatch) {
742 continue;
743 }
744 if (!filesChanged.includes(result.filePath)) {
745 filesChanged.push(result.filePath);
746 }
747 try {
748 if ('type' in result && result.type === 'create') {
749 insertions += result.content.split(/\r?\n/).length;
750 } else {
751 for (const hunk of result.structuredPatch) {
752 const additions = count(hunk.lines, line => line.startsWith('+'));
753 const removals = count(hunk.lines, line => line.startsWith('-'));
754 insertions += additions;
755 deletions += removals;
756 }
757 }
758 } catch {
759 continue;
760 }
761 }
762 return {
763 filesChanged,
764 insertions,
765 deletions
766 };
767}
768export function selectableUserMessagesFilter(message: Message): message is UserMessage {
769 if (message.type !== 'user') {
770 return false;

Callers 1

loadFileHistoryMetadataFunction · 0.85

Calls 2

isToolUseResultMessageFunction · 0.85
countFunction · 0.85

Tested by

no test coverage detected