Repository navigation
feat(core+cli): Workflow P4 — meta + /workflows + phase-tree (#4721) #5094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5b56c39
feat(core): Workflow P4a — extractAndStripMeta + meta on RunOutcome (…
LaZzyMan 55c23a0
test(core): close P4a adversarial-review gaps + add real-LLM E2E (#4721)
LaZzyMan 402df8f
fix(core): P4a meta-literal Promise crash + live-test typecheck + pre…
LaZzyMan c3f9d84
feat(core+cli): Workflow P4b — /workflows command + phase-tree UI + W…
LaZzyMan e9ad076
fix(core): bound rejectThenablesInMeta against cyclic meta input (#4721)
LaZzyMan 2491911
test(cli): stub isWorkflowsEnabled in BuiltinCommandLoader mock confi…
LaZzyMan 2af3536
test(core): cover P4b registry integration + orchestrator emitter (#4…
LaZzyMan b53bc4e
fix(core+cli): R7 review fixes — 6 substantive + tmux re-verified (#4…
LaZzyMan aa62afa
test(core): R7 dialog-cancel race integration test (#4721)
LaZzyMan 7b0ea82
test(cli): stub getWorkflowRunRegistry in clearCommand + useResumeCom…
LaZzyMan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { vi, describe, it, expect, beforeEach } from 'vitest'; | ||
| import { workflowsCommand } from './workflowsCommand.js'; | ||
| import { type CommandContext } from './types.js'; | ||
| import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; | ||
| import type { WorkflowTask } from '@qwen-code/qwen-code-core'; | ||
|
|
||
| function entry(overrides: Partial<WorkflowTask> = {}): WorkflowTask { | ||
| return { | ||
| id: 'wf_aaaaaaaa', | ||
| kind: 'workflow', | ||
| runId: 'wf_aaaaaaaa', | ||
| description: 'demo', | ||
| meta: null, | ||
| status: 'running', | ||
| startTime: 1_700_000_000_000, | ||
| outputFile: '', | ||
| outputOffset: 0, | ||
| notified: false, | ||
| abortController: new AbortController(), | ||
| currentPhase: null, | ||
| phases: [], | ||
| agentsDispatched: 0, | ||
| agentsCompleted: 0, | ||
| recentLogs: [], | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe('workflowsCommand', () => { | ||
| let context: CommandContext; | ||
| let listMock: ReturnType<typeof vi.fn>; | ||
| let getMock: ReturnType<typeof vi.fn>; | ||
|
|
||
| beforeEach(() => { | ||
| listMock = vi.fn().mockReturnValue([] as WorkflowTask[]); | ||
| getMock = vi.fn().mockReturnValue(undefined); | ||
| context = createMockCommandContext({ | ||
| services: { | ||
| config: { | ||
| getWorkflowRunRegistry: () => ({ | ||
| list: listMock, | ||
| get: getMock, | ||
| }), | ||
| }, | ||
| }, | ||
| executionMode: 'interactive', | ||
| } as unknown as Parameters<typeof createMockCommandContext>[0]); | ||
| }); | ||
|
|
||
| it('returns info message when there are no runs', async () => { | ||
| const result = await workflowsCommand.action!(context, ''); | ||
| expect(result).toMatchObject({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: 'No workflow runs recorded yet.', | ||
| }); | ||
| }); | ||
|
|
||
| it('lists active + recent buckets with running first', async () => { | ||
| listMock.mockReturnValue([ | ||
| entry({ | ||
| runId: 'wf_done', | ||
| status: 'completed', | ||
| endTime: 1_700_000_010_000, | ||
| }), | ||
| entry({ | ||
| runId: 'wf_running', | ||
| meta: { name: 'capitals', description: 'd' }, | ||
| status: 'running', | ||
| currentPhase: 'Plan', | ||
| phases: ['Plan'], | ||
| agentsDispatched: 2, | ||
| agentsCompleted: 1, | ||
| }), | ||
| ]); | ||
| const result = await workflowsCommand.action!(context, ''); | ||
| if (!result || result.type !== 'message') throw new Error('no result'); | ||
| expect(result.content).toContain('Workflow runs (2 total · 1 running)'); | ||
| const activeIdx = result.content.indexOf('Active'); | ||
| const recentIdx = result.content.indexOf('Recent'); | ||
| // Active section comes before Recent in the output. | ||
| expect(activeIdx).toBeGreaterThan(-1); | ||
| expect(recentIdx).toBeGreaterThan(activeIdx); | ||
| expect(result.content).toContain('wf_running'); | ||
| expect(result.content).toContain('Plan'); | ||
| expect(result.content).toContain('1/2 agents'); | ||
| expect(result.content).toContain('wf_done'); | ||
| expect(result.content).toContain('capitals'); | ||
| }); | ||
|
|
||
| it('omits the interactive tip in non_interactive / acp modes', async () => { | ||
| const ctx = createMockCommandContext({ | ||
| services: { | ||
| config: { | ||
| getWorkflowRunRegistry: () => ({ list: listMock, get: getMock }), | ||
| }, | ||
| }, | ||
| executionMode: 'non_interactive', | ||
| } as unknown as Parameters<typeof createMockCommandContext>[0]); | ||
| listMock.mockReturnValue([entry()]); | ||
| const result = await workflowsCommand.action!(ctx, ''); | ||
| if (!result || result.type !== 'message') throw new Error('no result'); | ||
| expect(result.content).not.toMatch(/Tip:/); | ||
| }); | ||
|
|
||
| it('detail view: known runId returns full per-field dump', async () => { | ||
| const detail = entry({ | ||
| runId: 'wf_target', | ||
| meta: { | ||
| name: 'demo', | ||
| description: 'd', | ||
| whenToUse: 'when stuff', | ||
| }, | ||
| status: 'completed', | ||
| phases: ['A', 'B'], | ||
| agentsDispatched: 3, | ||
| agentsCompleted: 3, | ||
| recentLogs: ['log1', 'log2'], | ||
| endTime: 1_700_000_010_000, | ||
| }); | ||
| getMock.mockImplementation((id) => | ||
| id === 'wf_target' ? detail : undefined, | ||
| ); | ||
| const result = await workflowsCommand.action!(context, 'wf_target'); | ||
| if (!result || result.type !== 'message') throw new Error('no result'); | ||
| expect(result.messageType).toBe('info'); | ||
| expect(result.content).toContain('Workflow wf_target'); | ||
| expect(result.content).toContain('name : demo'); | ||
| expect(result.content).toContain('whenToUse : when stuff'); | ||
| expect(result.content).toContain('agents : 3/3'); | ||
| expect(result.content).toContain('· A'); | ||
| expect(result.content).toContain('· B'); | ||
| expect(result.content).toContain('log1'); | ||
| expect(result.content).toContain('log2'); | ||
| }); | ||
|
|
||
| it('detail view: unknown runId returns clear error', async () => { | ||
| getMock.mockReturnValue(undefined); | ||
| const result = await workflowsCommand.action!(context, 'wf_missing'); | ||
| expect(result).toMatchObject({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: 'Unknown workflow runId: wf_missing', | ||
| }); | ||
| }); | ||
|
|
||
| it('argument is trimmed before lookup', async () => { | ||
| const target = entry({ runId: 'wf_t' }); | ||
| getMock.mockImplementation((id) => (id === 'wf_t' ? target : undefined)); | ||
| const result = await workflowsCommand.action!(context, ' wf_t '); | ||
| if (!result || result.type !== 'message') throw new Error('no result'); | ||
| expect(result.content).toContain('Workflow wf_t'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import type { WorkflowTask } from '@qwen-code/qwen-code-core'; | ||
| import type { SlashCommand } from './types.js'; | ||
| import { CommandKind } from './types.js'; | ||
| import { t } from '../../i18n/index.js'; | ||
| import { formatDuration } from '../utils/formatters.js'; | ||
|
|
||
| /** | ||
| * Format one workflow run as a one-line summary used by both the | ||
| * top-level listing and the per-run detail view. | ||
| */ | ||
| function rowLine(entry: WorkflowTask, now: number): string { | ||
| const endTime = entry.endTime ?? now; | ||
| const runtime = formatDuration(endTime - entry.startTime, { | ||
| hideTrailingZeros: true, | ||
| }); | ||
| const label = entry.meta?.name ?? entry.runId; | ||
| const phase = entry.currentPhase ? ` · ${entry.currentPhase}` : ''; | ||
| const counts = | ||
| entry.agentsDispatched > 0 | ||
| ? ` · ${entry.agentsCompleted}/${entry.agentsDispatched} agents` | ||
| : ''; | ||
| const phaseCount = | ||
| entry.phases.length > 0 | ||
| ? ` · ${entry.phases.length} ${entry.phases.length === 1 ? 'phase' : 'phases'}` | ||
| : ''; | ||
| const errorTail = | ||
| entry.status === 'failed' && entry.error | ||
| ? ` — ${entry.error.slice(0, 80)}` | ||
| : ''; | ||
| return ` ${entry.runId.padEnd(20)} ${entry.status.padEnd(10)} ${runtime.padStart(8)} ${label}${phase}${counts}${phaseCount}${errorTail}`; | ||
| } | ||
|
|
||
| function detailLines(entry: WorkflowTask, now: number): string[] { | ||
| const lines: string[] = []; | ||
| const endTime = entry.endTime ?? now; | ||
| const runtime = formatDuration(endTime - entry.startTime, { | ||
| hideTrailingZeros: true, | ||
| }); | ||
|
|
||
| lines.push(`Workflow ${entry.runId}`); | ||
| if (entry.meta?.name) { | ||
| lines.push(` name : ${entry.meta.name}`); | ||
| } | ||
| if (entry.meta?.description) { | ||
| lines.push(` description : ${entry.meta.description}`); | ||
| } | ||
| if (entry.meta?.whenToUse) { | ||
| lines.push(` whenToUse : ${entry.meta.whenToUse}`); | ||
| } | ||
| lines.push(` status : ${entry.status}`); | ||
| lines.push(` runtime : ${runtime}`); | ||
| if (entry.currentPhase) { | ||
| lines.push(` currentPhase: ${entry.currentPhase}`); | ||
| } | ||
| lines.push( | ||
| ` agents : ${entry.agentsCompleted}/${entry.agentsDispatched}`, | ||
| ); | ||
| if (entry.error) { | ||
| lines.push(` error : ${entry.error}`); | ||
|
LaZzyMan marked this conversation as resolved.
Resolved
|
||
| } | ||
| if (entry.phases.length > 0) { | ||
| lines.push(''); | ||
| lines.push(` Phases (${entry.phases.length})`); | ||
| for (const phase of entry.phases) { | ||
| lines.push(` · ${phase}`); | ||
| } | ||
| } | ||
| if (entry.recentLogs.length > 0) { | ||
| lines.push(''); | ||
| lines.push(` Logs (last ${entry.recentLogs.length})`); | ||
| for (const line of entry.recentLogs) { | ||
| lines.push(` ${line}`); | ||
| } | ||
| } | ||
| return lines; | ||
| } | ||
|
|
||
| export const workflowsCommand: SlashCommand = { | ||
| name: 'workflows', | ||
| get description() { | ||
| return t( | ||
| 'List active and completed workflow runs (text dump — interactive dialog opens via the footer pill)', | ||
| ); | ||
| }, | ||
| get argumentHint() { | ||
| return t('[runId]'); | ||
| }, | ||
| kind: CommandKind.BUILT_IN, | ||
| // Same triple-mode coverage as `/tasks`: the dialog is richer in | ||
| // interactive mode but headless / acp consumers need the text dump | ||
| // as their only inspection path. | ||
| supportedModes: ['interactive', 'non_interactive', 'acp'] as const, | ||
| action: async (context, args) => { | ||
| const { config } = context.services; | ||
| if (!config) { | ||
| return { | ||
| type: 'message' as const, | ||
| messageType: 'error' as const, | ||
| content: 'Config not available.', | ||
| }; | ||
| } | ||
| const registry = config.getWorkflowRunRegistry(); | ||
| const allEntries = registry.list(); | ||
|
|
||
| // Targeted detail view: `/workflows wf_abc123` opens the detail | ||
| // dump for that run if it exists. Reject early on unknown runId so | ||
| // the user sees a clear error instead of an empty listing. | ||
| const trimmedArgs = (args ?? '').trim(); | ||
| if (trimmedArgs.length > 0) { | ||
| const target = registry.get(trimmedArgs); | ||
| if (!target) { | ||
| return { | ||
| type: 'message' as const, | ||
| messageType: 'error' as const, | ||
| content: `Unknown workflow runId: ${trimmedArgs}`, | ||
| }; | ||
| } | ||
| return { | ||
| type: 'message' as const, | ||
| messageType: 'info' as const, | ||
| content: detailLines(target, Date.now()).join('\n'), | ||
| }; | ||
| } | ||
|
|
||
| if (allEntries.length === 0) { | ||
| return { | ||
| type: 'message' as const, | ||
| messageType: 'info' as const, | ||
| content: 'No workflow runs recorded yet.', | ||
| }; | ||
| } | ||
|
|
||
| const now = Date.now(); | ||
| // Order: running first (oldest startTime first inside the bucket so | ||
| // long-runners stay visible), then terminal by endTime DESC. Mirrors | ||
| // the dialog's two-bucket sort. | ||
| const running = allEntries | ||
| .filter((e) => e.status === 'running') | ||
| .sort((a, b) => a.startTime - b.startTime); | ||
| const terminal = allEntries | ||
| .filter((e) => e.status !== 'running') | ||
| .sort((a, b) => (b.endTime ?? 0) - (a.endTime ?? 0)); | ||
|
|
||
| const lines: string[] = []; | ||
| if (context.executionMode === 'interactive') { | ||
| lines.push( | ||
| t( | ||
| 'Tip: use `/workflows <runId>` for the per-run detail view (name, description, phase tree, recent logs).', | ||
| ), | ||
| '', | ||
| ); | ||
| } | ||
| lines.push( | ||
| `Workflow runs (${allEntries.length} total · ${running.length} running)`, | ||
| '', | ||
| ); | ||
| if (running.length > 0) { | ||
| lines.push('Active'); | ||
| for (const entry of running) lines.push(rowLine(entry, now)); | ||
| lines.push(''); | ||
| } | ||
| if (terminal.length > 0) { | ||
| lines.push('Recent'); | ||
| for (const entry of terminal) lines.push(rowLine(entry, now)); | ||
| } | ||
|
|
||
| return { | ||
| type: 'message' as const, | ||
| messageType: 'info' as const, | ||
| content: lines.join('\n'), | ||
| }; | ||
| }, | ||
|
LaZzyMan marked this conversation as resolved.
Resolved
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.