muuuuse 3.3.6 → 3.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/agents.js +37 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muuuuse",
3
- "version": "3.3.6",
3
+ "version": "3.3.7",
4
4
  "description": "🔌Muuuuse arms regular terminals and relays assistant output across signed terminal links.",
5
5
  "type": "commonjs",
6
6
  "bin": {
package/src/agents.js CHANGED
@@ -735,33 +735,56 @@ function selectGeminiSessionFile(currentPath, processStartedAtMs, options = {})
735
735
  return selectSessionCandidatePath(candidates, projectHash, processStartedAtMs);
736
736
  }
737
737
 
738
- function readGeminiAnswers(filePath, lastMessageId = null, sinceMs = null) {
738
+ function parseGeminiMessage(message, options = {}) {
739
+ const flowMode = options.flowMode === true;
740
+ if (!message || message.type !== "gemini" || typeof message.content !== "string") {
741
+ return null;
742
+ }
743
+
744
+ const text = sanitizeRelayText(message.content);
745
+ if (!text) {
746
+ return null;
747
+ }
748
+
749
+ const toolCalls = Array.isArray(message.toolCalls) ? message.toolCalls : [];
750
+ const phase = toolCalls.length > 0 ? "commentary" : "final_answer";
751
+ if (phase === "commentary" && !flowMode) {
752
+ return null;
753
+ }
754
+
755
+ return {
756
+ id: message.id || hashText(JSON.stringify(message)),
757
+ text,
758
+ phase,
759
+ timestamp: message.timestamp || new Date().toISOString(),
760
+ };
761
+ }
762
+
763
+ function readGeminiAnswers(filePath, lastMessageId = null, sinceMs = null, options = {}) {
739
764
  try {
740
765
  const entry = JSON.parse(fs.readFileSync(filePath, "utf8"));
741
766
  const messages = Array.isArray(entry.messages) ? entry.messages : [];
742
- const finalMessages = messages.filter((message) => {
743
- const toolCalls = Array.isArray(message.toolCalls) ? message.toolCalls : [];
744
- return message.type === "gemini" && typeof message.content === "string" && message.content.trim() && toolCalls.length === 0;
745
- });
746
767
 
747
768
  let startIndex = 0;
748
769
  if (lastMessageId) {
749
- const previousIndex = finalMessages.findIndex((message) => message.id === lastMessageId);
750
- startIndex = previousIndex === -1 ? finalMessages.length : previousIndex + 1;
770
+ const previousIndex = messages.findIndex((message) => message?.id === lastMessageId);
771
+ startIndex = previousIndex === -1 ? 0 : previousIndex + 1;
751
772
  }
752
773
 
753
- const answers = finalMessages.slice(startIndex).map((message) => ({
754
- id: message.id || hashText(JSON.stringify(message)),
755
- text: sanitizeRelayText(message.content),
756
- phase: "final_answer",
757
- timestamp: message.timestamp || entry.lastUpdated || new Date().toISOString(),
758
- }));
774
+ const answers = messages
775
+ .slice(startIndex)
776
+ .map((message) => parseGeminiMessage(message, options))
777
+ .filter((answer) => answer !== null);
778
+
779
+ const lastSeenMessage = [...messages]
780
+ .reverse()
781
+ .find((message) => typeof message?.id === "string" && message.id.trim());
759
782
 
760
783
  return {
761
784
  answers: answers
762
785
  .filter((answer) => answer.text.length > 0)
763
786
  .filter((answer) => isAnswerNewEnough(answer, sinceMs)),
764
- lastMessageId: finalMessages.length > 0 ? finalMessages[finalMessages.length - 1].id : lastMessageId,
787
+ lastMessageId: lastSeenMessage?.id || lastMessageId,
765
788
  fileSize: getFileSize(filePath),
766
789
  };
767
790
  } catch {