JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
Fix TUI workflow log accumulation
chensheng12345bf864b4759b9
diff --git a/jiuwenswarm/channels/tui/frontend/src/app-state.ts b/jiuwenswarm/channels/tui/frontend/src/app-state.tsindex 14d3cfb068..6d2d2cb0ca 100644--- a/jiuwenswarm/channels/tui/frontend/src/app-state.ts+++ b/jiuwenswarm/channels/tui/frontend/src/app-state.ts@@ -62,7 +62,7 @@ import {getCurrentCwd,} from "./core/tui-trusted-dirs-store.js";import { loadTuiConfig } from "./core/tui-config-store.js";-import { applyWorkflowUpdate, type WorkflowRun } from "./core/workflows.js";+import { applyWorkflowUpdate, normalizeWorkflowRun, type WorkflowRun } from "./core/workflows.js";import { execFile, spawnSync } from "node:child_process";import { writeFileSync } from "node:fs";import { createConnection } from "node:net";@@ -902,9 +902,9 @@ export class CliPiAppState {workflowRuns: this.workflowRuns.map((workflow) => ({...workflow,logs: workflow.logs ? [...workflow.logs] : undefined,- phases: workflow.phases.map((phase) => ({+ phases: (workflow.phases ?? []).map((phase) => ({...phase,- agents: phase.agents.map((agent) => ({+ agents: (phase.agents ?? []).map((agent) => ({...agent,activity: agent.activity ? [...agent.activity] : undefined,})),@@ -1147,7 +1147,7 @@ export class CliPiAppState {};readonly setWorkflowRuns = (workflows: WorkflowRun[]): void => {- this.workflowRuns = workflows;+ this.workflowRuns = workflows.map((workflow) => normalizeWorkflowRun(workflow));this.emitChange();};diff --git a/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts b/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.tsindex 3ef2ef9b87..194de0f182 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts@@ -1059,17 +1059,6 @@ function handleWorkflowUpdated(return false;}- // Normalize phases and agents to ensure they are arrays- const wf = workflow as Record<string, unknown>;- if (!Array.isArray(wf.phases)) {- wf.phases = [];- }- for (const phase of wf.phases as Record<string, unknown>[]) {- if (!Array.isArray(phase.agents)) {- phase.agents = [];- }- }-delegate.applyWorkflowUpdate(workflow as unknown as WorkflowRun);return true;}diff --git a/jiuwenswarm/channels/tui/frontend/src/core/workflows.ts b/jiuwenswarm/channels/tui/frontend/src/core/workflows.tsindex 3d74d3c5d3..c83231a630 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/workflows.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/workflows.ts@@ -168,12 +168,13 @@ export function workflowStatusBannerText(status: WorkflowStatus): string | null}export function countWorkflowAgents(workflow: WorkflowRun): number {- return workflow.phases.reduce((total, phase) => total + phase.agents.length, 0);+ return (workflow.phases ?? []).reduce((total, phase) => total + (phase.agents ?? []).length, 0);}export function countCompletedWorkflowAgents(workflow: WorkflowRun): number {- return workflow.phases.reduce(- (total, phase) => total + phase.agents.filter((agent) => agent.status === "completed").length,+ return (workflow.phases ?? []).reduce(+ (total, phase) =>+ total + (phase.agents ?? []).filter((agent) => agent.status === "completed").length,0,);}@@ -185,13 +186,40 @@ export function findWorkflowAgent(): WorkflowAgentLookup | null {const workflow = workflows.find((item) => item.id === workflowId);if (!workflow) return null;- for (const phase of workflow.phases) {- const agent = phase.agents.find((item) => item.id === agentId);+ for (const phase of workflow.phases ?? []) {+ const agent = (phase.agents ?? []).find((item) => item.id === agentId);if (agent) return { workflow, phase, agent };}return null;}+export function normalizeWorkflowRun(workflow: WorkflowRun): WorkflowRun {+ return {+ ...workflow,+ logs: Array.isArray(workflow.logs)+ ? workflow.logs.filter((log): log is string => typeof log === "string")+ : undefined,+ phases: Array.isArray(workflow.phases)+ ? workflow.phases.map((phase) => ({+ ...phase,+ agents: Array.isArray(phase.agents)+ ? phase.agents.map((agent) => ({+ ...agent,+ activity: Array.isArray(agent.activity)+ ? agent.activity.filter(+ (activity): activity is WorkflowAgentActivity =>+ Boolean(+ activity && typeof activity === "object" && !Array.isArray(activity),+ ),+ )+ : undefined,+ }))+ : [],+ }))+ : [],+ };+}+function mergeWorkflowAgent(existing: WorkflowAgent | undefined,incoming: WorkflowAgent,@@ -241,7 +269,8 @@ export function mergeWorkflowRun(? incoming.logs.filter((log): log is string => typeof log === "string"): undefined;- for (const incomingPhase of incoming.phases ?? []) {+ const incomingPhases = Array.isArray(incoming.phases) ? incoming.phases : [];+ for (const incomingPhase of incomingPhases) {const index = mergedPhases.findIndex((phase) => phase.id === incomingPhase.id);const nextPhase = mergeWorkflowPhase(index === -1 ? undefined : mergedPhases[index],@@ -274,19 +303,9 @@ export function applyWorkflowUpdate(): WorkflowRun[] {const index = workflows.findIndex((workflow) => workflow.id === incoming.id);if (index === -1) {- // Normalize incoming workflow to ensure phases and agents are arrays- const normalized: WorkflowRun = {- ...incoming,- phases: Array.isArray(incoming.phases)- ? incoming.phases.map((phase) => ({- ...phase,- agents: Array.isArray(phase.agents) ? phase.agents : [],- }))- : [],- };- return [normalized, ...workflows];+ return [normalizeWorkflowRun(incoming), ...workflows];}return workflows.map((workflow, itemIndex) =>- itemIndex === index ? mergeWorkflowRun(workflow, incoming) : workflow,+ itemIndex === index ? normalizeWorkflowRun(mergeWorkflowRun(workflow, incoming)) : workflow,);}diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/components/todo-list.ts b/jiuwenswarm/channels/tui/frontend/src/ui/components/todo-list.tsindex eb8c8e0d59..38bf393dda 100644--- a/jiuwenswarm/channels/tui/frontend/src/ui/components/todo-list.ts+++ b/jiuwenswarm/channels/tui/frontend/src/ui/components/todo-list.ts@@ -33,7 +33,8 @@ function todoLabel(todo: TodoItem, animationPhase: number = 0): string {if (todo.status === "error") {return `${palette.status.error("✗")} ${text}`;}- const prefix = todo.status === "in_progress" ? spinner : "○";+ const prefix =+ todo.status === "in_progress" ? palette.status.info(spinner) : palette.status.warning("○");return `${prefix} ${text}`;}