feat: workflow run visibility — live agent tree, script view, per-agent transcripts #3650
Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 11 commits into
main fromfeat/workflow-run-visibilityopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/mobile/src/lib/threadActivity.ts line 288Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -237,3 +237,7 @@237237 for (const activity of ordered) {238238 if (activity.kind === "tool.started") continue;239239 if (activity.kind === "task.started") continue;240+ // Workflow snapshot/meta activities back the desktop workflow card; on241+ // mobile they would render as ever-mutating raw rows, so skip them.242+ if (activity.kind === "task.workflow-updated") continue;243+ if (activity.kind === "task.workflow-meta") continue;@@ -0,0 +429,21 @@429+ : "completed";430+ const detail = asString(payload.detail);431+ if (detail !== undefined) {432+ run.completionSummary = detail;433+ }434+ break;435+ }436+ default:437+ break;438+ }439+ }440+441+ // A workflow cannot outlive its provider session: when the session is gone442+ // and no task_notification ever arrived (crash, interrupt, app restart),443+ // surface the run as stopped instead of running forever.444+ const sessionActive = options?.sessionActive ?? true;445+ return [...runs.values()]446+ .map(({ hasStartedActivity: _hasStartedActivity, ...run }) => run)447+ .map((run) =>448+ run.status === "running" && !sessionActive ? { ...run, status: "stopped" as const } : run,449+ )apps/web/src/components/ChatView.tsx line 1737OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1727,3 +1730,8 @@17271730 const phase = derivePhase(activeThread?.session ?? null);17281731 const threadActivities = activeThread?.activities ?? EMPTY_ACTIVITIES;17291732 const workLogEntries = useMemo(() => deriveWorkLogEntries(threadActivities), [threadActivities]);1733+ const workflowSessionActive =1734+ activeThread?.session !== null &&1735+ activeThread?.session !== undefined &&1736+ activeThread.session.status !== "stopped" &&1737+ activeThread.session.status !== "error";apps/web/src/components/workflow/WorkflowPanel.tsx line 495Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +417,21 @@417+ if (control.cancelled || nextLineRef.current === before) {418+ break;419+ }420+ }421+ };422+ void drain();423+ return () => {424+ control.cancelled = true;425+ };426+ }, [loadMore]);427+428+ // Keep polling for new lines while the run is live.429+ useEffect(() => {430+ if (runStatus !== "running") {431+ return;432+ }433+ const id = setInterval(() => {434+ void loadMore();435+ }, 2000);436+ return () => clearInterval(id);437+ }, [loadMore, runStatus]);@@ -0,0 +430,21 @@430+ const detail = asString(payload.detail);431+ if (detail !== undefined) {432+ run.completionSummary = detail;433+ }434+ break;435+ }436+ default:437+ break;438+ }439+ }440+441+ // A workflow cannot outlive its provider session: when the session is gone442+ // and no task_notification ever arrived (crash, interrupt, app restart),443+ // surface the run as stopped instead of running forever.444+ const sessionActive = options?.sessionActive ?? true;445+ return [...runs.values()]446+ .map(({ hasStartedActivity: _hasStartedActivity, ...run }) => run)447+ .map((run) =>448+ run.status === "running" && !sessionActive ? { ...run, status: "stopped" as const } : run,449+ )450+ .toSorted((a, b) => a.createdAt.localeCompare(b.createdAt) || a.taskId.localeCompare(b.taskId));
- apps/server/src/provider/Layers/ClaudeAdapter.ts line 834OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -716,0 +814,21 @@814+ ? { error: workflowClippedString(entry.error, MAX_WORKFLOW_PREVIEW_CHARS) }815+ : {}),816+ };817+}818+819+/**820+ * Normalize the Claude Agent SDK's `workflow_progress` snapshot.821+ *822+ * The field is deliberate wire surface (the CLI's own /workflows view renders823+ * it) but is absent from the published SDK types, so every read is defensive:824+ * malformed entries and unknown entry types are dropped, previews are825+ * clipped, and entry counts are capped before the snapshot enters the826+ * runtime-event contract.827+ */828+function normalizeWorkflowProgress(829+ value: unknown,830+): ReadonlyArray<WorkflowProgressEntry> | undefined {831+ if (!Array.isArray(value) || value.length === 0) {832+ return undefined;833+ }834+ const agents: Array<WorkflowAgentProgressEntry> = [];apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts line 172Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -162,3 +163,8 @@162163 return maxTurnCount;163164 }164165166+/**167+ * Stable per-task activity ids: workflow snapshot/meta activities are168+ * upserted (one projection row per run), not appended per progress tick.169+ */170+function workflowActivityId(threadId: ThreadId, taskId: string): EventId {apps/web/src/components/workflow/WorkflowPanel.tsx line 226OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +206,21 @@206+ return (207+ <a208+ href={sessionUrl}209+ target="_blank"210+ rel="noopener noreferrer"211+ className="flex items-center gap-1.5 rounded-md px-0.5 py-1 text-[12px] text-foreground/82 leading-5 hover:bg-accent/20 hover:text-foreground"212+ >213+ <ExternalLinkIcon className="size-3.5 shrink-0 text-muted-foreground" />214+ Running in the cloud — open session215+ </a>216+ );217+ }218+219+ if (run.phases.length === 0) {220+ return <MutedBody text="No agents yet" />;221+ }222+223+ return (224+ <div className="space-y-px">225+ {run.phases.map((phase) => (226+ <div key={phase.index}>apps/web/src/components/workflow/workflowUi.tsx line 161OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +141,21 @@141+ className={cn(142+ "shrink-0 truncate font-medium",143+ agent.status === "error" ? "text-destructive" : "text-foreground/82",144+ )}145+ >146+ {agentDisplayLabel(agent)}147+ </span>148+ <AgentMetaBadges agent={agent} />149+ {preview !== undefined && (150+ <span className="min-w-0 flex-1 truncate text-muted-foreground/70">{preview}</span>151+ )}152+ </div>153+ );154+}155+156+// ---------------------------------------------------------------------------157+// Phase header + rollup helpers158+// ---------------------------------------------------------------------------159+160+export function phaseDoneCount(phase: WorkflowRunPhase): number {161+ return phase.agents.filter((agent) => agent.status === "done").length;packages/client-runtime/src/state/workflow.ts lines 24 to 32Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +8,21 @@8+ * Workflow-run inspection atoms (Claude Agent SDK workflow artifacts).9+ *10+ * `readScript` and `readJournal` are cached queries — the script never11+ * changes for a given path within a run, and journal reads are refreshed by12+ * re-query. `readAgentTranscript` is an imperative command because the13+ * caller drives cursor-paged polling while a transcript pane is open.14+ */15+export function createWorkflowEnvironmentAtoms<R, E>(16+ runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,17+) {18+ return {19+ readScript: createEnvironmentRpcQueryAtomFamily(runtime, {20+ label: "environment-data:workflow:read-script",21+ tag: WS_METHODS.workflowReadScript,22+ staleTimeMs: 30_000,23+ }),24+ readJournal: createEnvironmentRpcQueryAtomFamily(runtime, {25+ label: "environment-data:workflow:read-journal",26+ tag: WS_METHODS.workflowReadJournal,27+ staleTimeMs: 5_000,28+ }),apps/web/src/workflow-logic.ts line 309OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +289,21 @@289+ }290+ if (291+ activity.kind === "task.workflow-updated" ||292+ activity.kind === "task.workflow-meta" ||293+ (activity.kind === "task.started" &&294+ payload !== undefined &&295+ isWorkflowTaskStartedPayload(payload))296+ ) {297+ taskIds.add(taskId);298+ }299+ }300+ return taskIds;301+}302+303+export function deriveWorkflowRuns(304+ activities: ReadonlyArray<OrchestrationThreadActivity>,305+ options?: { readonly sessionActive?: boolean | undefined },306+): WorkflowRun[] {307+ const ordered = [...activities].toSorted(308+ (a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id),309+ );@@ -0,0 +68,21 @@68+export const WorkflowProgressEntry = Schema.Union([69+ WorkflowAgentProgressEntry,70+ WorkflowPhaseProgressEntry,71+ WorkflowLogProgressEntry,72+]);73+export type WorkflowProgressEntry = typeof WorkflowProgressEntry.Type;74+75+/**76+ * Handles returned by the Workflow tool result. `transcriptDir` and77+ * `scriptPath` are server-local paths — clients echo them back to the78+ * workflow inspection RPCs, which re-validate them structurally before79+ * touching disk. `sessionUrl` replaces the local handles for remote runs.80+ */81+export const WorkflowRunHandles = Schema.Struct({82+ taskId: TrimmedNonEmptyString,83+ runId: Schema.optional(TrimmedNonEmptyString),84+ workflowName: Schema.optional(TrimmedNonEmptyString),85+ taskType: Schema.optional(TrimmedNonEmptyString),86+ scriptPath: Schema.optional(TrimmedNonEmptyString),87+ transcriptDir: Schema.optional(TrimmedNonEmptyString),88+ sessionUrl: Schema.optional(TrimmedNonEmptyString),
- apps/mobile/src/lib/threadActivity.ts line 295Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -232,8 +273,21 @@232273 function deriveWorkLogEntries(233274 activities: ReadonlyArray<OrchestrationThreadActivity>,234275 ): DerivedWorkLogEntry[] {235276 const ordered = Arr.sort(activities, activityOrder);277+ const workflowTaskIds = collectWorkflowTaskIds(activities);236278 const entries: DerivedWorkLogEntry[] = [];237279 for (const activity of ordered) {238280 if (activity.kind === "tool.started") continue;239281 if (activity.kind === "task.started") continue;282+ // Workflow snapshot/meta activities back the desktop workflow card; on283+ // mobile they would render as ever-mutating raw rows, so skip them —284+ // along with the per-tick task rows the workflow owns.285+ if (activity.kind === "task.workflow-updated") continue;286+ if (activity.kind === "task.workflow-meta") continue;287+ if (288+ (activity.kind === "task.progress" || activity.kind === "task.completed") &&289+ workflowTaskIds.size > 0 &&290+ activityBelongsToWorkflow(activity, workflowTaskIds)291+ ) {292+ continue;293+ }
- apps/server/src/workflow/WorkflowInspectionService.ts lines 159 to 166Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +143,21 @@143+ const readScript = Effect.fn("WorkflowInspectionService.readScript")(function* (144+ input: WorkflowReadScriptInput,145+ ) {146+ const operation = "WorkflowInspectionService.readScript";147+ if (!input.scriptPath.endsWith(".js") && !input.scriptPath.endsWith(".mjs")) {148+ return yield* new WorkflowInspectionError({149+ operation,150+ reason: "invalid-path",151+ detail: "Script path must end with .js or .mjs.",152+ });153+ }154+155+ const realPath = yield* resolveContained(operation, input.scriptPath);156+ const source = yield* fs.readFileString(realPath).pipe(157+ Effect.mapError(158+ (cause) =>159+ new WorkflowInspectionError({160+ operation,161+ reason: isNotFoundPlatformError(cause) ? "not-found" : "read-failed",162+ detail: "Failed to read the workflow script.",163+ }),packages/contracts/src/workflow.ts lines 100 to 107Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +79,21 @@79+ * touching disk. `sessionUrl` replaces the local handles for remote runs.80+ */81+export const WorkflowRunHandles = Schema.Struct({82+ taskId: TrimmedNonEmptyString,83+ runId: Schema.optional(TrimmedNonEmptyString),84+ workflowName: Schema.optional(TrimmedNonEmptyString),85+ taskType: Schema.optional(TrimmedNonEmptyString),86+ scriptPath: Schema.optional(TrimmedNonEmptyString),87+ transcriptDir: Schema.optional(TrimmedNonEmptyString),88+ sessionUrl: Schema.optional(TrimmedNonEmptyString),89+ warning: Schema.optional(TrimmedNonEmptyString),90+});91+export type WorkflowRunHandles = typeof WorkflowRunHandles.Type;92+93+export class WorkflowInspectionError extends Schema.TaggedErrorClass<WorkflowInspectionError>()(94+ "WorkflowInspectionError",95+ {96+ operation: Schema.String,97+ reason: Schema.Literals(["invalid-path", "not-found", "read-failed", "unsupported"]),98+ detail: Schema.String,99+ },
- @@ -0,0 +311,21 @@311+ "task.workflow-updated": 1,312+ "task.completed": 2,313+};314+315+function compareWorkflowActivityOrder(316+ a: OrchestrationThreadActivity,317+ b: OrchestrationThreadActivity,318+): number {319+ if (a.sequence !== undefined && b.sequence !== undefined && a.sequence !== b.sequence) {320+ return a.sequence - b.sequence;321+ }322+ const byTime = a.createdAt.localeCompare(b.createdAt);323+ if (byTime !== 0) {324+ return byTime;325+ }326+ const byRank = (WORKFLOW_ACTIVITY_RANK[a.kind] ?? 1) - (WORKFLOW_ACTIVITY_RANK[b.kind] ?? 1);327+ if (byRank !== 0) {328+ return byRank;329+ }330+ return a.id.localeCompare(b.id);331+}
- apps/web/src/components/workflow/WorkflowPanel.tsx line 344Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +324,21 @@324+325+function clipTranscriptText(text: string, limit: number): string {326+ const trimmed = text.trim();327+ return trimmed.length > limit ? `${trimmed.slice(0, limit)}\u2026` : trimmed;328+}329+330+function toolInputPreview(input: unknown): string | undefined {331+ if (typeof input !== "object" || input === null) {332+ return undefined;333+ }334+ const record = input as Record<string, unknown>;335+ // The most informative single field per common tool, else the first string.336+ const preferred = record.command ?? record.file_path ?? record.pattern ?? record.prompt;337+ const value =338+ typeof preferred === "string"339+ ? preferred340+ : Object.values(record).find((entry): entry is string => typeof entry === "string");341+ return value !== undefined ? clipTranscriptText(value, TRANSCRIPT_TOOL_PREVIEW_CHARS) : undefined;342+}343+344+/**
- apps/web/src/components/workflow/WorkflowPanel.tsx line 508Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +481,21 @@481+ void loadMore();482+ return;483+ }484+ const id = setInterval(() => {485+ void loadMore();486+ }, 2000);487+ return () => clearInterval(id);488+ }, [loadMore, runStatus]);489+490+ return (491+ <div492+ className="mt-1 ml-4 max-h-72 overflow-y-auto rounded-md border border-border/60 bg-muted/30 p-1.5 font-mono text-[11px] leading-4"493+ onClick={stopPropagation}494+ >495+ {transcriptEntries.length === 0 ? (496+ failed ? (497+ <p className="text-destructive/80">Failed to load transcript.</p>498+ ) : loading ? (499+ <p className="text-muted-foreground/60">Loading transcript…</p>500+ ) : (501+ <p className="text-muted-foreground/60">No assistant output yet.</p>
- apps/web/src/components/workflow/workflowUi.tsx line 169OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +149,21 @@149+}: {150+ agent: WorkflowRunAgent;151+ leading?: ReactNode;152+}): ReactElement {153+ const stats = agentStatsLabel(agent);154+ const errorText = agent.status === "error" ? agent.error : undefined;155+ return (156+ <div className="flex min-w-0 items-center gap-1.5 text-[12px] leading-5">157+ {leading}158+ <AgentStatusDot status={agent.status} />159+ <span160+ className={cn(161+ "shrink-0 truncate font-medium",162+ agent.status === "error" ? "text-destructive" : "text-foreground/82",163+ )}164+ >165+ {agentDisplayLabel(agent)}166+ </span>167+ <AgentMetaBadges agent={agent} />168+ {errorText !== undefined ? (169+ <span className="min-w-0 flex-1 truncate text-destructive/70">{errorText}</span>
t3dotgg(GitHub profile, opens in a new tab) changed the title
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
a40b1552-71a6-4a3a-b6c4-4dbe39c051c4You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.