From 5fc3740443ac326d851943a6e00ec6f78e06e3de Mon Sep 17 00:00:00 2001 From: Shreyansh Gupta Date: Mon, 23 Nov 2026 11:55:56 +0530 Subject: [PATCH 1/4] Combine conversion task creation and execution into one Convert step The Home page had separate "Create Conversion Tasks" and "Execute Conversion Tasks" steps, and the Conversion view needed "Plan Conversion" before "Execute All". Convert now creates the task plan and executes the required tasks in the same agent session. - Home page shows one Convert step ("Creating tasks" / "Executing tasks" while running); flows that already have tasks resume execution. - generateConversionForFlow accepts { executeAfterPlan } and sends a combined prompt; migration_conversion_storeTaskPlan then starts Execute All and tells the agent to continue without waiting for the user. - The Conversion view's first action is Convert; Regenerate Tasks stays plan-only and Execute All remains available for resuming. - Clear the stale executing state when Execute All has nothing to run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 2 +- resources/agents/migration-converter.md | 2 + src/commands/CommandRegistry.ts | 32 ++- src/constants/ChatPrompts.ts | 43 +++- src/constants/UserMessages.ts | 12 +- src/copilot/MigrationLMTools.ts | 21 +- src/services/AgentFileProvisioner.ts | 2 +- src/stages/conversion/ConversionService.ts | 44 ++++ src/test/unit/conversion.test.ts | 82 +++++++ .../conversion/ConversionWebviewPanel.ts | 15 +- src/views/discovery/SourceFlowVisualizer.ts | 213 ++++++++++-------- 11 files changed, 353 insertions(+), 115 deletions(-) diff --git a/README.md b/README.md index 5171061..f793947 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Discovery → Planning → Conversion → Validation → Deployment | --- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 1 | **Discovery** | Find and catalog all integration artifacts from the source platform. Auto-detects platform, scans files, builds artifact inventory and dependency graph. | | 2 | **Planning** | Analyze complexity, plan the migration roadmap, and map source patterns to Logic Apps patterns. Generates per-flow migration plans with action mappings, gap analysis, and effort estimates. | -| 3 | **Conversion** | Transform source artifacts into Logic Apps Standard workflows, connections, and supporting files. Executes task plans generated during planning. | +| 3 | **Conversion** | Transform source artifacts into Logic Apps Standard workflows, connections, and supporting files. A single **Convert** step creates the conversion task plan and executes its tasks. | | 4 | **Validation** | Test generated workflows and validate behavior against source specifications. | | 5 | **Deployment** | Deploy generated Logic Apps artifacts to Azure. | diff --git a/resources/agents/migration-converter.md b/resources/agents/migration-converter.md index 4d29605..377e4e7 100644 --- a/resources/agents/migration-converter.md +++ b/resources/agents/migration-converter.md @@ -67,6 +67,8 @@ Follow skill `conversion-task-plan-rules` exactly to determine and order all tas Include the relevant design decisions, source references, and implementation requirements in each task's execution prompt so isolated task execution follows the same plan. +When the request asks you to convert the flow end to end (the Convert step), continue straight into STEP 3 after the plan is stored — do not wait for the user. When it asks only for the task plan, stop after storing it. + ### STEP 3 — Execute Tasks For each task in dependency order: diff --git a/src/commands/CommandRegistry.ts b/src/commands/CommandRegistry.ts index ad18bd7..1a31ff9 100644 --- a/src/commands/CommandRegistry.ts +++ b/src/commands/CommandRegistry.ts @@ -1036,9 +1036,14 @@ export class CommandRegistry implements vscode.Disposable { /** * Handle generating conversion tasks for a specific flow. * Opens the @migration-converter agent chat to analyse the planning - * results and produce an ordered conversion task plan. + * results and produce an ordered conversion task plan. With + * `executeAfterPlan` (the single Convert step), the agent then executes the + * required tasks in the same session instead of waiting for Execute All. */ - private async handleGenerateConversionForFlow(flowId?: string): Promise { + private async handleGenerateConversionForFlow( + flowId?: string, + options?: { executeAfterPlan?: boolean } + ): Promise { const logger = LoggingService.getInstance(); if (!flowId) { @@ -1057,9 +1062,19 @@ export class CommandRegistry implements vscode.Disposable { const flow = conversionService.getFlows().find((f) => f.id === flowId); const flowName = flow?.name || flowId; + // The latest request decides whether the stored plan starts executing, so + // regenerating tasks never auto-executes because of an abandoned Convert run. + const executeAfterPlan = options?.executeAfterPlan === true; + if (executeAfterPlan) { + conversionService.requestExecuteAfterPlan(flowId); + } else { + conversionService.cancelExecuteAfterPlan(flowId); + } + TelemetryService.getInstance().logStep('conversion.tasklist.started', { flowId, flowName, + executeAfterPlan, }); // Ensure the @migration-converter agent file is provisioned @@ -1077,7 +1092,11 @@ export class CommandRegistry implements vscode.Disposable { } // Show user feedback - vscode.window.showInformationMessage(UserPrompts.analysingConversionTasks(flowName)); + vscode.window.showInformationMessage( + executeAfterPlan + ? UserPrompts.convertingFlow(flowName) + : UserPrompts.analysingConversionTasks(flowName) + ); // Read Azure settings from VS Code configuration const azureConfig = vscode.workspace.getConfiguration('logicAppsMigrationAgent.azure'); @@ -1109,10 +1128,14 @@ export class CommandRegistry implements vscode.Disposable { outputProjectRoot, outputLogicAppName, outputLogicAppRoot, + executeAfterPlan, }), }); logger.debug('[Conversion] Agent chat opened successfully'); } catch (err) { + conversionService.cancelExecuteAfterPlan(flowId); + SourceFlowVisualizer.convertingGroupIds.delete(flowId); + SourceFlowVisualizer.refreshFlowGroupSelectorIfOpen(); logger.error( `[Conversion] Failed to open agent chat: ${err instanceof Error ? err.message : String(err)}` ); @@ -1307,6 +1330,8 @@ export class CommandRegistry implements vscode.Disposable { const taskPlan = conversionService.getTaskPlan(flowId); if (!taskPlan) { + SourceFlowVisualizer.executingGroupIds.delete(flowId); + SourceFlowVisualizer.refreshFlowGroupSelectorIfOpen(); vscode.window.showWarningMessage(UserPrompts.NO_TASK_PLAN_FOUND); return; } @@ -1345,6 +1370,7 @@ export class CommandRegistry implements vscode.Disposable { (t.optional && t.status === 'pending') ); await conversionService.setExecuteAllActive(flowId, false); + SourceFlowVisualizer.executingGroupIds.delete(flowId); SourceFlowVisualizer.refreshFlowGroupSelectorIfOpen(); if (allDone) { vscode.window.showInformationMessage(UserPrompts.ALL_TASKS_COMPLETE); diff --git a/src/constants/ChatPrompts.ts b/src/constants/ChatPrompts.ts index 7f6153a..a197925 100644 --- a/src/constants/ChatPrompts.ts +++ b/src/constants/ChatPrompts.ts @@ -47,6 +47,8 @@ interface ConversionForFlowParams { outputProjectRoot: string; outputLogicAppName: string; outputLogicAppRoot: string; + /** Convert step: continue straight into executing the required tasks after storing the plan */ + executeAfterPlan?: boolean; } interface ExecuteSingleTaskParams { @@ -171,8 +173,25 @@ export class ChatPrompts { const subscriptionSuffix = params.azureSubscriptionId ? `, SubscriptionId="${params.azureSubscriptionId}"` : ''; + const header = params.executeAfterPlan + ? `@migration-converter Convert the flow "${params.flowName}" (flowId: "${params.flowId}") end to end: create the conversion task plan, then execute its required tasks.\n` + : `@migration-converter Convert the flow "${params.flowName}" (flowId: "${params.flowId}").\n`; + const scaffoldRequirement = params.executeAfterPlan + ? ChatPrompts.scaffoldExtra( + params.outputProjectName, + params.outputLogicAppName, + params.outputProjectRoot, + params.outputLogicAppRoot + ) + : ''; + const executionSteps = params.executeAfterPlan + ? '4. Do NOT wait for the user: execute the required tasks in order. For each task, read the skills and source artifacts it needs, execute it per its executionPrompt, then call migration_conversion_storeTaskOutput with flowId, taskId, summary, and generatedFiles.\n' + + '5. After ALL required tasks complete, call migration_conversion_finalize.\n' + + 'Do NOT execute optional tasks (like local-blackbox-test or cloud-deploy-test) — the user runs them from the Conversion view.\n' + + 'PLAN ADHERENCE: Do not deviate from the planned design. If a fix requires design changes, STOP and report.\n' + : ''; return ( - `@migration-converter Convert the flow "${params.flowName}" (flowId: "${params.flowId}").\n` + + header + AUTONOMOUS_MODE_SHORT + 'PLANNING HANDOFF: Read finalized preferences and brief from migration_conversion_getPlanningResults. Preserve the selected host, broker, modernization scope, and authentication constraints in every task executionPrompt. Do not substitute defaults or use Azure Workflow Service Plan deployment instructions for hybrid.\n' + SKILL_AUTHORITY + @@ -192,10 +211,12 @@ export class ChatPrompts { `OUTPUT PATHS: Workspace root="${params.outputProjectRoot}/", Logic App="${params.outputLogicAppRoot}/", ` + `Workspace file="${params.outputProjectRoot}/${params.outputProjectName}.code-workspace".\n` + `Scaffold params: workspaceName="${params.outputProjectName}", logicAppName="${params.outputLogicAppName}".\n` + + scaffoldRequirement + '\nPROCEDURE:\n' + '1. Call migration_conversion_getPlanningResults to get the finalized plan.\n' + '2. Determine ALL conversion tasks per skill `conversion-task-plan-rules`.\n' + '3. Call migration_conversion_storeTaskPlan with flowId, summary, and task list.\n' + + executionSteps + 'Task IDs MUST be descriptive (not "task-1") — see skill for rules.' ); } @@ -378,4 +399,24 @@ export class ChatPrompts { } return '\nThis is the LAST task. After calling migration_conversion_storeTaskOutput, call migration_conversion_finalize to complete the flow.\n'; } + + // ======================================================================== + // Convert step: continue from the stored task plan into execution + // (returned by migration_conversion_storeTaskPlan) + // ======================================================================== + + static executeAfterPlanInstruction( + requiredTaskIds: string[], + optionalTaskIds: string[] + ): string { + const optionalNote = + optionalTaskIds.length > 0 + ? ` Do NOT execute the optional tasks (${optionalTaskIds.join(', ')}) — the user runs them from the Conversion view.` + : ''; + return ( + `Task plan stored. Do NOT stop or wait for the user: execute the ${requiredTaskIds.length} required tasks now, in this order: ${requiredTaskIds.join(', ')}. ` + + `Start with "${requiredTaskIds[0]}" (already marked in progress). After each task, call migration_conversion_storeTaskOutput, then move to the next task. ` + + `When all required tasks are complete, call migration_conversion_finalize.${optionalNote}` + ); + } } diff --git a/src/constants/UserMessages.ts b/src/constants/UserMessages.ts index 9858475..8888940 100644 --- a/src/constants/UserMessages.ts +++ b/src/constants/UserMessages.ts @@ -221,6 +221,13 @@ export class UserPrompts { ); } + static convertingFlow(flowName: string): string { + return format( + 'Converting "{0}" in a new Agent chat session: creating and executing the conversion tasks...', + flowName + ); + } + static failedToOpenAgentChatConversion(errorMsg: string): string { return format('Failed to open agent chat for conversion. {0}', errorMsg); } @@ -230,7 +237,7 @@ export class UserPrompts { // ======================================================================== static readonly NO_FLOW_OR_TASK_SPECIFIED = 'No flow or task specified.'; - static readonly NO_TASK_PLAN_FOUND = 'No task plan found. Run "Plan Conversion" first.'; + static readonly NO_TASK_PLAN_FOUND = 'No task plan found. Run "Convert" first.'; static taskNotFound(taskId: string): string { return format('Task "{0}" not found in the task plan.', taskId); @@ -539,8 +546,7 @@ export class UserPrompts { return format('Failed to Execute All tasks: {0}', error); } - static readonly NO_CONVERSION_TASK_PLAN = - 'No conversion task plan found. Run "Plan Conversion" first.'; + static readonly NO_CONVERSION_TASK_PLAN = 'No conversion task plan found. Run "Convert" first.'; static readonly NO_WORKSPACE_FOLDER = 'No workspace folder found.'; static projectFolderNotFound(projectPath: string): string { diff --git a/src/copilot/MigrationLMTools.ts b/src/copilot/MigrationLMTools.ts index 4a86034..79a5583 100644 --- a/src/copilot/MigrationLMTools.ts +++ b/src/copilot/MigrationLMTools.ts @@ -35,6 +35,7 @@ import { validateWorkflowDefinition } from '../workflowSchema'; import { ConversionService } from '../stages/conversion/ConversionService'; import { ConversionFileService } from '../stages/conversion/ConversionFileService'; import { MermaidValidationService } from '../services/MermaidValidationService'; +import { ChatPrompts } from '../constants/ChatPrompts'; import type { ConversionTask, ConversionTaskOutput, ConversionTaskPlan } from '../stages/conversion/types'; import { PlanningPreflightTool } from './PlanningPreflightTool'; import { PlanningBrief, validatePlanningBrief } from '../stages/planning/PlanningDecisions'; @@ -4365,6 +4366,16 @@ class ConversionStoreTaskPlanTool implements vscode.LanguageModelTool ({ id: t.id, name: t.name, order: t.order })), - message: `Conversion task plan stored with ${tasks.length} tasks. The tasks are now visible in the Conversion webview. You can proceed to execute tasks when the user asks.`, + message: executionTasks + ? ChatPrompts.executeAfterPlanInstruction( + executionTasks.map((t) => t.id), + conversionTasks.filter((t) => t.optional).map((t) => t.id) + ) + : `Conversion task plan stored with ${tasks.length} tasks. The tasks are now visible in the Conversion webview. You can proceed to execute tasks when the user asks.`, }) ), ]); diff --git a/src/services/AgentFileProvisioner.ts b/src/services/AgentFileProvisioner.ts index 2b1639f..1ab0c05 100644 --- a/src/services/AgentFileProvisioner.ts +++ b/src/services/AgentFileProvisioner.ts @@ -38,7 +38,7 @@ const ANALYSER_VERSION_TAG = ``; -const CONVERTER_AGENT_VERSION = '2.21.0'; +const CONVERTER_AGENT_VERSION = '2.22.0'; const CONVERTER_VERSION_TAG = ``; // ============================================================================= diff --git a/src/stages/conversion/ConversionService.ts b/src/stages/conversion/ConversionService.ts index 5f2c53b..05077ec 100644 --- a/src/stages/conversion/ConversionService.ts +++ b/src/stages/conversion/ConversionService.ts @@ -65,6 +65,7 @@ export class ConversionService implements vscode.Disposable { // Conversion state private state: ConversionStageState | undefined; private readonly executeAllActiveFlows = new Set(); + private readonly executeAfterPlanFlows = new Set(); private constructor() { this.disposables.push(this._onStateChange); @@ -368,12 +369,53 @@ export class ConversionService implements vscode.Disposable { return this.executeAllActiveFlows.has(flowId); } + /** + * Ask the next stored task plan for a flow to start executing its required + * tasks immediately, so creating and executing the tasks is one Convert step. + */ + public requestExecuteAfterPlan(flowId: string): void { + this.executeAfterPlanFlows.add(flowId); + } + + /** + * Withdraw a pending execute-after-plan request for a flow. + */ + public cancelExecuteAfterPlan(flowId: string): void { + this.executeAfterPlanFlows.delete(flowId); + } + + /** + * Start Execute All for a freshly stored task plan when the Convert step + * requested it. Marks the first required task in progress and returns the + * required tasks in execution order, or undefined when execution was not + * requested or nothing is left to run. + */ + public async startExecuteAfterPlan(flowId: string): Promise { + if (!this.executeAfterPlanFlows.delete(flowId)) { + return undefined; + } + + const requiredTasks = (this.getTaskPlan(flowId)?.tasks ?? []) + .filter( + (task) => !task.optional && task.status !== 'completed' && task.status !== 'skipped' + ) + .sort((a, b) => a.order - b.order); + if (requiredTasks.length === 0) { + return undefined; + } + + await this.setExecuteAllActive(flowId, true); + await this.updateTask(flowId, requiredTasks[0].id, { status: 'in-progress' }); + return requiredTasks; + } + /** * Stop a stuck execution for a flow. Resets any in-progress tasks back to * pending and clears Execute All orchestration state. Used when the agent * chat was stopped mid-run, leaving the UI stuck showing "Executing...". */ public async stopExecution(flowId: string): Promise { + this.executeAfterPlanFlows.delete(flowId); if (!this.state) { return; } @@ -414,6 +456,7 @@ export class ConversionService implements vscode.Disposable { */ public async reset(): Promise { this.state = undefined; + this.executeAfterPlanFlows.clear(); const storage = StorageService.getInstance(); await storage.setWorkspace(StorageKeys.CONVERSION_STATE, undefined); this.logger.debug('Conversion state reset'); @@ -523,6 +566,7 @@ export class ConversionService implements vscode.Disposable { d.dispose(); } this.executeAllActiveFlows.clear(); + this.executeAfterPlanFlows.clear(); ConversionService.instance = undefined; } } diff --git a/src/test/unit/conversion.test.ts b/src/test/unit/conversion.test.ts index 1360264..6507819 100644 --- a/src/test/unit/conversion.test.ts +++ b/src/test/unit/conversion.test.ts @@ -1,12 +1,14 @@ import * as assert from 'assert/strict'; import { cachedPlan, + conversionPlan, createWorkspace, disposeWorkspace, generatedAt, prepareConversion, preparePlanning, } from '../helpers/biztalk'; +import { ChatPrompts } from '../../constants/ChatPrompts'; import { ConversionService } from '../../stages/conversion/ConversionService'; import { ConversionFileService } from '../../stages/conversion/ConversionFileService'; import { PlanningCacheService } from '../../stages/planning/PlanningCacheService'; @@ -147,6 +149,39 @@ describe('BizTalk Conversion stage', () => { assert.equal(restored.getTaskPlan(flow.id)?.tasks[1].status, 'in-progress'); }); + it('starts executing the required tasks as soon as the Convert step stores the plan', async () => { + const flow = await prepareConversion(); + const conversion = ConversionService.getInstance(); + assert.equal(await conversion.startExecuteAfterPlan(flow.id), undefined); + assert.equal(conversion.isExecuteAllActive(flow.id), false); + + conversion.requestExecuteAfterPlan(flow.id); + await conversion.storeTaskPlan(flow.id, conversionPlan(flow)); + const tasks = await conversion.startExecuteAfterPlan(flow.id); + assert.deepEqual( + tasks?.map((task) => task.id), + ['convert-schemas-and-map', 'generate-workflow', 'test-workflows'] + ); + assert.equal(conversion.isExecuteAllActive(flow.id), true); + assert.equal(conversion.getFlows()[0].status, 'in-progress'); + assert.deepEqual( + conversion.getTaskPlan(flow.id)?.tasks.map((task) => task.status), + ['in-progress', 'pending', 'pending', 'pending'] + ); + assert.equal(await conversion.startExecuteAfterPlan(flow.id), undefined); + }); + + it('drops a pending Convert request when execution is stopped', async () => { + const flow = await prepareConversion(); + const conversion = ConversionService.getInstance(); + conversion.requestExecuteAfterPlan(flow.id); + await conversion.stopExecution(flow.id); + await conversion.storeTaskPlan(flow.id, conversionPlan(flow)); + assert.equal(await conversion.startExecuteAfterPlan(flow.id), undefined); + assert.equal(conversion.isExecuteAllActive(flow.id), false); + assert.equal(conversion.getFlows()[0].status, 'tasks-ready'); + }); + it('reset removes conversion state without changing the approved planning inputs', async () => { const flow = await prepareConversion(); const conversion = ConversionService.getInstance(); @@ -161,3 +196,50 @@ describe('BizTalk Conversion stage', () => { assert.equal(flows[0].status, 'not-started'); }); }); + +describe('Convert step prompts', () => { + const params = { + flowName: 'Purchase order to invoice', + flowId: 'po-to-invoice', + azureResourceGroup: 'rg-test', + azureLocation: 'eastus', + azureSubscriptionId: '', + outputProjectName: 'Purchase-order-to-invoice', + outputProjectRoot: 'out/Purchase-order-to-invoice', + outputLogicAppName: 'Purchase-order-to-invoice-logicapp', + outputLogicAppRoot: 'out/Purchase-order-to-invoice/Purchase-order-to-invoice-logicapp', + }; + + it('asks only for the task plan when tasks are regenerated', () => { + const prompt = ChatPrompts.conversionForFlow(params); + assert.match(prompt, /3\. Call migration_conversion_storeTaskPlan/); + assert.doesNotMatch( + prompt, + /migration_conversion_storeTaskOutput|migration_conversion_finalize/ + ); + }); + + it('continues from the stored plan into executing the required tasks', () => { + const prompt = ChatPrompts.conversionForFlow({ ...params, executeAfterPlan: true }); + assert.match( + prompt, + /3\. Call migration_conversion_storeTaskPlan[^\n]*\n4\. [^\n]*migration_conversion_storeTaskOutput[^\n]*\n5\. [^\n]*migration_conversion_finalize/ + ); + assert.match(prompt, /Do NOT execute optional tasks/); + assert.match(prompt, /SCAFFOLD REQUIREMENT/); + }); + + it('lists the required tasks the agent runs after storing the plan', () => { + const message = ChatPrompts.executeAfterPlanInstruction( + ['convert-schemas-and-map', 'generate-workflow', 'test-workflows'], + ['cloud-deploy-test'] + ); + assert.match( + message, + /in this order: convert-schemas-and-map, generate-workflow, test-workflows\./ + ); + assert.match(message, /Start with "convert-schemas-and-map"/); + assert.match(message, /migration_conversion_finalize/); + assert.match(message, /optional tasks \(cloud-deploy-test\)/); + }); +}); diff --git a/src/views/conversion/ConversionWebviewPanel.ts b/src/views/conversion/ConversionWebviewPanel.ts index ed51813..2d4947b 100644 --- a/src/views/conversion/ConversionWebviewPanel.ts +++ b/src/views/conversion/ConversionWebviewPanel.ts @@ -159,8 +159,13 @@ export class ConversionWebviewPanel implements vscode.Disposable { this.update(); } this.logger.debug(`Conversion started for flow: ${flowId}`); + // Convert creates the task plan and executes it in one agent session vscode.commands - .executeCommand('logicAppsMigrationAgent.generateConversionForFlow', flowId) + .executeCommand( + 'logicAppsMigrationAgent.generateConversionForFlow', + flowId, + { executeAfterPlan: true } + ) .then( () => this.logger.debug( @@ -1003,7 +1008,7 @@ export class ConversionWebviewPanel implements vscode.Disposable { private getFlowActionButton(flow: ConversionFlow): string { switch (flow.status) { case 'not-started': - return ``; + return ``; case 'thinking': return ``; case 'tasks-ready': @@ -1218,11 +1223,11 @@ export class ConversionWebviewPanel implements vscode.Disposable { return `
-

Ready to Execute

-

Click "Plan Conversion" to have the converter agent analyse the planning results and determine the ordered conversion tasks for this flow.

+

Ready to Convert

+

Click "Convert" to have the converter agent create the ordered conversion tasks for this flow from the planning results and execute them.


`; } diff --git a/src/views/discovery/SourceFlowVisualizer.ts b/src/views/discovery/SourceFlowVisualizer.ts index 2dcad80..52f4166 100644 --- a/src/views/discovery/SourceFlowVisualizer.ts +++ b/src/views/discovery/SourceFlowVisualizer.ts @@ -44,9 +44,9 @@ export class SourceFlowVisualizer implements vscode.Disposable { public static generatingGroupIds = new Set(); // Track which flow group IDs are currently being planned public static planningGroupIds = new Set(); - // Track which flow group IDs are currently being converted + // Track which flow group IDs are creating conversion tasks (first phase of Convert) public static convertingGroupIds = new Set(); - // Track which flow group IDs are currently executing conversion tasks + // Track which flow group IDs are executing conversion tasks (second phase of Convert) public static executingGroupIds = new Set(); // Track per-flow analysis panels (reuse on re-click instead of creating duplicates) private static analysisPanels = new Map(); @@ -56,7 +56,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { return this.isInitialGenerating || this.generatingGroupIds.size > 0; } - /** True if ANY LLM operation (analyse/plan/create/execute) is running on ANY flow */ + /** True if ANY LLM operation (analyse/plan/convert) is running on ANY flow */ public static get isAnyFlowBusy(): boolean { return ( this.generatingGroupIds.size > 0 || @@ -295,38 +295,22 @@ export class SourceFlowVisualizer implements vscode.Disposable { planBtn = ``; } - // ── Create button ── - let createBtn: string; + // ── Convert button (creates the conversion tasks, then executes them) ── + let convertBtn: string; if (!isPlanned) { - createBtn = - ''; - } else if (isConverting) { - createBtn = - ''; - } else if (isTasksCreated) { - createBtn = ``; - } else if (isBlockedByOtherFlow) { - createBtn = - ''; - } else { - createBtn = ``; - } - - // ── Execute button ── - let executeBtn: string; - if (!isTasksCreated) { - executeBtn = - ''; - } else if (isExecuting) { - executeBtn = - ''; + convertBtn = + ''; + } else if (isConverting || isExecuting) { + convertBtn = ``; } else if (isConverted) { - executeBtn = ``; + convertBtn = ``; } else if (isBlockedByOtherFlow) { - executeBtn = - ''; + convertBtn = + ''; + } else if (isTasksCreated) { + convertBtn = ``; } else { - executeBtn = ``; + convertBtn = ``; } // ── Open in VS Code button ── @@ -338,7 +322,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { if (isConverted) { openBtn = ``; } else { - openBtn = ``; + openBtn = ``; } // Step connector arrows @@ -352,7 +336,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { title="Reset all progress for this flow and start over">↺ Start Over` : ''; - // Stop button — shown while any process (analyse/plan/create/execute) runs on this flow + // Stop button — shown while any process (analyse/plan/convert) runs on this flow const stopBtn = isThisFlowBusy ? `` : ''; @@ -369,7 +353,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { ${escapeHtml(g.category)}
- ${analyseBtn}${stepArrow}${planBtn}${stepArrow}${createBtn}${stepArrow}${executeBtn}${stepArrow}${openBtn} + ${analyseBtn}${stepArrow}${planBtn}${stepArrow}${convertBtn}${stepArrow}${openBtn}
`; }) @@ -664,9 +648,6 @@ export class SourceFlowVisualizer implements vscode.Disposable { function viewConversion(flowId) { vscode.postMessage({ command: 'viewConversionFromSelector', data: flowId }); } - function executeFlow(flowId) { - vscode.postMessage({ command: 'executeFlowFromSelector', data: flowId }); - } function stopFlow(flowId) { vscode.postMessage({ command: 'stopFlowFromSelector', data: flowId }); } @@ -1385,56 +1366,32 @@ export class SourceFlowVisualizer implements vscode.Disposable { } case 'convertFlowFromSelector': { - // User clicked Convert button — mark as converting and start agent chat + // Single Convert step: create the conversion tasks and execute them in one + // agent session, or resume the tasks this flow already has. const flowId = message.data as string; this.logger.debug(`[FlowViz] User requested conversion for flow: ${flowId}`); - - // Mark as converting and refresh UI to show Converting... state - SourceFlowVisualizer.convertingGroupIds.add(flowId); - SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); - - // Use setTimeout to let the UI refresh before starting async work - setTimeout(() => { - void (async () => { - try { - // Open conversion planning agent chat for this flow - await vscode.commands.executeCommand( - 'logicAppsMigrationAgent.generateConversionForFlow', - flowId - ); - } catch (err) { - SourceFlowVisualizer.convertingGroupIds.delete(flowId); - SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); - vscode.window.showErrorMessage( - UserPrompts.failedToStartConversionVisualizer( - err instanceof Error ? err.message : String(err) - ) - ); - } - })(); - }, 100); - break; - } - - case 'viewConversionFromSelector': { - // User clicked "✓ Converted" — open Conversion webview for this flow - const flowId = message.data as string; - this.logger.debug(`[FlowViz] User viewing conversion for flow: ${flowId}`); void (async () => { try { - // Ensure conversion service is initialized (loads persisted state from disk) - const { ConversionService } = await import('../../stages/conversion'); - const conversionService = ConversionService.getInstance(); - await conversionService.initialize(); - if (conversionService.getFlows().length === 0) { - conversionService.buildFlowsFromPlanning(); + const { DiscoveryCacheService } = + await import('../../stages/discovery/DiscoveryCacheService'); + const tasksCreated = !!DiscoveryCacheService.getInstance() + .getFlowGroups() + ?.groups.find((g) => g.id === flowId)?.tasksCreated; + let hasTaskPlan = false; + if (tasksCreated) { + const { ConversionService } = await import('../../stages/conversion'); + const conversionService = ConversionService.getInstance(); + await conversionService.initialize(); + hasTaskPlan = !!conversionService.getTaskPlan(flowId); + } + if (hasTaskPlan) { + this.executeConversionTasks(flowId); + } else { + this.createAndExecuteConversionTasks(flowId); } - await conversionService.selectFlow(flowId); - const { ConversionWebviewPanel } = await import('../conversion'); - ConversionWebviewPanel.createOrShow(this.extensionUri); } catch (err) { vscode.window.showErrorMessage( - UserPrompts.failedToOpenConversion( + UserPrompts.failedToStartConversionVisualizer( err instanceof Error ? err.message : String(err) ) ); @@ -1443,18 +1400,13 @@ export class SourceFlowVisualizer implements vscode.Disposable { break; } - case 'executeFlowFromSelector': { - // User clicked Execute button — mark as executing, open Conversion webview, trigger Execute All + case 'viewConversionFromSelector': { + // User clicked "✓ Converted" — open Conversion webview for this flow const flowId = message.data as string; - this.logger.debug(`[FlowViz] User requested execute all for flow: ${flowId}`); - - // Mark as executing and refresh UI - SourceFlowVisualizer.executingGroupIds.add(flowId); - SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); - + this.logger.debug(`[FlowViz] User viewing conversion for flow: ${flowId}`); void (async () => { try { - // Ensure conversion service is initialized and has the flow + // Ensure conversion service is initialized (loads persisted state from disk) const { ConversionService } = await import('../../stages/conversion'); const conversionService = ConversionService.getInstance(); await conversionService.initialize(); @@ -1462,21 +1414,11 @@ export class SourceFlowVisualizer implements vscode.Disposable { conversionService.buildFlowsFromPlanning(); } await conversionService.selectFlow(flowId); - - // Open conversion webview const { ConversionWebviewPanel } = await import('../conversion'); ConversionWebviewPanel.createOrShow(this.extensionUri); - - // Trigger Execute All after a short delay to let the webview render - setTimeout(() => { - void vscode.commands.executeCommand( - 'logicAppsMigrationAgent.executeAllConversionTasks', - flowId - ); - }, 500); } catch (err) { vscode.window.showErrorMessage( - UserPrompts.failedToExecute( + UserPrompts.failedToOpenConversion( err instanceof Error ? err.message : String(err) ) ); @@ -1775,6 +1717,77 @@ export class SourceFlowVisualizer implements vscode.Disposable { } } + /** + * Convert step for a flow without tasks: create the conversion tasks and let + * the agent execute them in the same chat session. + */ + private createAndExecuteConversionTasks(flowId: string): void { + // Mark as converting and refresh UI to show the Creating tasks state + SourceFlowVisualizer.convertingGroupIds.add(flowId); + SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); + + // Use setTimeout to let the UI refresh before starting async work + setTimeout(() => { + void (async () => { + try { + await vscode.commands.executeCommand( + 'logicAppsMigrationAgent.generateConversionForFlow', + flowId, + { executeAfterPlan: true } + ); + } catch (err) { + SourceFlowVisualizer.convertingGroupIds.delete(flowId); + SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); + vscode.window.showErrorMessage( + UserPrompts.failedToStartConversionVisualizer( + err instanceof Error ? err.message : String(err) + ) + ); + } + })(); + }, 100); + } + + /** + * Convert step for a flow that already has tasks (e.g. an interrupted run): + * open the Conversion view and execute the remaining tasks. + */ + private executeConversionTasks(flowId: string): void { + SourceFlowVisualizer.executingGroupIds.add(flowId); + SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); + + void (async () => { + try { + // Ensure conversion service is initialized and has the flow + const { ConversionService } = await import('../../stages/conversion'); + const conversionService = ConversionService.getInstance(); + await conversionService.initialize(); + if (conversionService.getFlows().length === 0) { + conversionService.buildFlowsFromPlanning(); + } + await conversionService.selectFlow(flowId); + + // Open conversion webview + const { ConversionWebviewPanel } = await import('../conversion'); + ConversionWebviewPanel.createOrShow(this.extensionUri); + + // Trigger Execute All after a short delay to let the webview render + setTimeout(() => { + void vscode.commands.executeCommand( + 'logicAppsMigrationAgent.executeAllConversionTasks', + flowId + ); + }, 500); + } catch (err) { + SourceFlowVisualizer.executingGroupIds.delete(flowId); + SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); + vscode.window.showErrorMessage( + UserPrompts.failedToExecute(err instanceof Error ? err.message : String(err)) + ); + } + })(); + } + /** * Each group gets its own NEW chat session, so multiple groups can generate concurrently. */ From 697afa8004070cdb4e90a3e8a2a94770145178fb Mon Sep 17 00:00:00 2001 From: Shreyansh Gupta Date: Mon, 23 Nov 2026 12:15:20 +0530 Subject: [PATCH 2/4] Keep conversion as one Home step that creates tasks, then opens them Rework the previous change to match the intended flow. The Home flow card now has a single conversion step instead of separate Create and Execute steps: - Create: the agent creates the conversion tasks; the task list then opens so each task (or Execute All) is executed from there. - Execute: once tasks exist, the same step opens the task list. - Converted: shown when all required tasks are done. The agent no longer runs every task on its own right after creating them, so the executeAfterPlan prompt, service flag, storeTaskPlan handoff and the related doc and version changes are reverted. The step is rendered by a small helper with unit tests, and the unused Execute message handler and UserPrompts.failedToExecute are removed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 2 +- resources/agents/migration-converter.md | 2 - src/commands/CommandRegistry.ts | 32 +--- src/constants/ChatPrompts.ts | 43 +---- src/constants/UserMessages.ts | 16 +- src/copilot/MigrationLMTools.ts | 21 +-- src/services/AgentFileProvisioner.ts | 2 +- src/stages/conversion/ConversionService.ts | 44 ----- src/test/unit/conversion-step-button.test.ts | 75 ++++++++ src/test/unit/conversion.test.ts | 82 --------- .../conversion/ConversionWebviewPanel.ts | 15 +- src/views/discovery/ConversionStepButton.ts | 80 +++++++++ src/views/discovery/SourceFlowVisualizer.ts | 164 +++++------------- 13 files changed, 212 insertions(+), 366 deletions(-) create mode 100644 src/test/unit/conversion-step-button.test.ts create mode 100644 src/views/discovery/ConversionStepButton.ts diff --git a/README.md b/README.md index f793947..5171061 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Discovery → Planning → Conversion → Validation → Deployment | --- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 1 | **Discovery** | Find and catalog all integration artifacts from the source platform. Auto-detects platform, scans files, builds artifact inventory and dependency graph. | | 2 | **Planning** | Analyze complexity, plan the migration roadmap, and map source patterns to Logic Apps patterns. Generates per-flow migration plans with action mappings, gap analysis, and effort estimates. | -| 3 | **Conversion** | Transform source artifacts into Logic Apps Standard workflows, connections, and supporting files. A single **Convert** step creates the conversion task plan and executes its tasks. | +| 3 | **Conversion** | Transform source artifacts into Logic Apps Standard workflows, connections, and supporting files. Executes task plans generated during planning. | | 4 | **Validation** | Test generated workflows and validate behavior against source specifications. | | 5 | **Deployment** | Deploy generated Logic Apps artifacts to Azure. | diff --git a/resources/agents/migration-converter.md b/resources/agents/migration-converter.md index 377e4e7..4d29605 100644 --- a/resources/agents/migration-converter.md +++ b/resources/agents/migration-converter.md @@ -67,8 +67,6 @@ Follow skill `conversion-task-plan-rules` exactly to determine and order all tas Include the relevant design decisions, source references, and implementation requirements in each task's execution prompt so isolated task execution follows the same plan. -When the request asks you to convert the flow end to end (the Convert step), continue straight into STEP 3 after the plan is stored — do not wait for the user. When it asks only for the task plan, stop after storing it. - ### STEP 3 — Execute Tasks For each task in dependency order: diff --git a/src/commands/CommandRegistry.ts b/src/commands/CommandRegistry.ts index 1a31ff9..ad18bd7 100644 --- a/src/commands/CommandRegistry.ts +++ b/src/commands/CommandRegistry.ts @@ -1036,14 +1036,9 @@ export class CommandRegistry implements vscode.Disposable { /** * Handle generating conversion tasks for a specific flow. * Opens the @migration-converter agent chat to analyse the planning - * results and produce an ordered conversion task plan. With - * `executeAfterPlan` (the single Convert step), the agent then executes the - * required tasks in the same session instead of waiting for Execute All. + * results and produce an ordered conversion task plan. */ - private async handleGenerateConversionForFlow( - flowId?: string, - options?: { executeAfterPlan?: boolean } - ): Promise { + private async handleGenerateConversionForFlow(flowId?: string): Promise { const logger = LoggingService.getInstance(); if (!flowId) { @@ -1062,19 +1057,9 @@ export class CommandRegistry implements vscode.Disposable { const flow = conversionService.getFlows().find((f) => f.id === flowId); const flowName = flow?.name || flowId; - // The latest request decides whether the stored plan starts executing, so - // regenerating tasks never auto-executes because of an abandoned Convert run. - const executeAfterPlan = options?.executeAfterPlan === true; - if (executeAfterPlan) { - conversionService.requestExecuteAfterPlan(flowId); - } else { - conversionService.cancelExecuteAfterPlan(flowId); - } - TelemetryService.getInstance().logStep('conversion.tasklist.started', { flowId, flowName, - executeAfterPlan, }); // Ensure the @migration-converter agent file is provisioned @@ -1092,11 +1077,7 @@ export class CommandRegistry implements vscode.Disposable { } // Show user feedback - vscode.window.showInformationMessage( - executeAfterPlan - ? UserPrompts.convertingFlow(flowName) - : UserPrompts.analysingConversionTasks(flowName) - ); + vscode.window.showInformationMessage(UserPrompts.analysingConversionTasks(flowName)); // Read Azure settings from VS Code configuration const azureConfig = vscode.workspace.getConfiguration('logicAppsMigrationAgent.azure'); @@ -1128,14 +1109,10 @@ export class CommandRegistry implements vscode.Disposable { outputProjectRoot, outputLogicAppName, outputLogicAppRoot, - executeAfterPlan, }), }); logger.debug('[Conversion] Agent chat opened successfully'); } catch (err) { - conversionService.cancelExecuteAfterPlan(flowId); - SourceFlowVisualizer.convertingGroupIds.delete(flowId); - SourceFlowVisualizer.refreshFlowGroupSelectorIfOpen(); logger.error( `[Conversion] Failed to open agent chat: ${err instanceof Error ? err.message : String(err)}` ); @@ -1330,8 +1307,6 @@ export class CommandRegistry implements vscode.Disposable { const taskPlan = conversionService.getTaskPlan(flowId); if (!taskPlan) { - SourceFlowVisualizer.executingGroupIds.delete(flowId); - SourceFlowVisualizer.refreshFlowGroupSelectorIfOpen(); vscode.window.showWarningMessage(UserPrompts.NO_TASK_PLAN_FOUND); return; } @@ -1370,7 +1345,6 @@ export class CommandRegistry implements vscode.Disposable { (t.optional && t.status === 'pending') ); await conversionService.setExecuteAllActive(flowId, false); - SourceFlowVisualizer.executingGroupIds.delete(flowId); SourceFlowVisualizer.refreshFlowGroupSelectorIfOpen(); if (allDone) { vscode.window.showInformationMessage(UserPrompts.ALL_TASKS_COMPLETE); diff --git a/src/constants/ChatPrompts.ts b/src/constants/ChatPrompts.ts index a197925..7f6153a 100644 --- a/src/constants/ChatPrompts.ts +++ b/src/constants/ChatPrompts.ts @@ -47,8 +47,6 @@ interface ConversionForFlowParams { outputProjectRoot: string; outputLogicAppName: string; outputLogicAppRoot: string; - /** Convert step: continue straight into executing the required tasks after storing the plan */ - executeAfterPlan?: boolean; } interface ExecuteSingleTaskParams { @@ -173,25 +171,8 @@ export class ChatPrompts { const subscriptionSuffix = params.azureSubscriptionId ? `, SubscriptionId="${params.azureSubscriptionId}"` : ''; - const header = params.executeAfterPlan - ? `@migration-converter Convert the flow "${params.flowName}" (flowId: "${params.flowId}") end to end: create the conversion task plan, then execute its required tasks.\n` - : `@migration-converter Convert the flow "${params.flowName}" (flowId: "${params.flowId}").\n`; - const scaffoldRequirement = params.executeAfterPlan - ? ChatPrompts.scaffoldExtra( - params.outputProjectName, - params.outputLogicAppName, - params.outputProjectRoot, - params.outputLogicAppRoot - ) - : ''; - const executionSteps = params.executeAfterPlan - ? '4. Do NOT wait for the user: execute the required tasks in order. For each task, read the skills and source artifacts it needs, execute it per its executionPrompt, then call migration_conversion_storeTaskOutput with flowId, taskId, summary, and generatedFiles.\n' + - '5. After ALL required tasks complete, call migration_conversion_finalize.\n' + - 'Do NOT execute optional tasks (like local-blackbox-test or cloud-deploy-test) — the user runs them from the Conversion view.\n' + - 'PLAN ADHERENCE: Do not deviate from the planned design. If a fix requires design changes, STOP and report.\n' - : ''; return ( - header + + `@migration-converter Convert the flow "${params.flowName}" (flowId: "${params.flowId}").\n` + AUTONOMOUS_MODE_SHORT + 'PLANNING HANDOFF: Read finalized preferences and brief from migration_conversion_getPlanningResults. Preserve the selected host, broker, modernization scope, and authentication constraints in every task executionPrompt. Do not substitute defaults or use Azure Workflow Service Plan deployment instructions for hybrid.\n' + SKILL_AUTHORITY + @@ -211,12 +192,10 @@ export class ChatPrompts { `OUTPUT PATHS: Workspace root="${params.outputProjectRoot}/", Logic App="${params.outputLogicAppRoot}/", ` + `Workspace file="${params.outputProjectRoot}/${params.outputProjectName}.code-workspace".\n` + `Scaffold params: workspaceName="${params.outputProjectName}", logicAppName="${params.outputLogicAppName}".\n` + - scaffoldRequirement + '\nPROCEDURE:\n' + '1. Call migration_conversion_getPlanningResults to get the finalized plan.\n' + '2. Determine ALL conversion tasks per skill `conversion-task-plan-rules`.\n' + '3. Call migration_conversion_storeTaskPlan with flowId, summary, and task list.\n' + - executionSteps + 'Task IDs MUST be descriptive (not "task-1") — see skill for rules.' ); } @@ -399,24 +378,4 @@ export class ChatPrompts { } return '\nThis is the LAST task. After calling migration_conversion_storeTaskOutput, call migration_conversion_finalize to complete the flow.\n'; } - - // ======================================================================== - // Convert step: continue from the stored task plan into execution - // (returned by migration_conversion_storeTaskPlan) - // ======================================================================== - - static executeAfterPlanInstruction( - requiredTaskIds: string[], - optionalTaskIds: string[] - ): string { - const optionalNote = - optionalTaskIds.length > 0 - ? ` Do NOT execute the optional tasks (${optionalTaskIds.join(', ')}) — the user runs them from the Conversion view.` - : ''; - return ( - `Task plan stored. Do NOT stop or wait for the user: execute the ${requiredTaskIds.length} required tasks now, in this order: ${requiredTaskIds.join(', ')}. ` + - `Start with "${requiredTaskIds[0]}" (already marked in progress). After each task, call migration_conversion_storeTaskOutput, then move to the next task. ` + - `When all required tasks are complete, call migration_conversion_finalize.${optionalNote}` - ); - } } diff --git a/src/constants/UserMessages.ts b/src/constants/UserMessages.ts index 8888940..d6a5707 100644 --- a/src/constants/UserMessages.ts +++ b/src/constants/UserMessages.ts @@ -221,13 +221,6 @@ export class UserPrompts { ); } - static convertingFlow(flowName: string): string { - return format( - 'Converting "{0}" in a new Agent chat session: creating and executing the conversion tasks...', - flowName - ); - } - static failedToOpenAgentChatConversion(errorMsg: string): string { return format('Failed to open agent chat for conversion. {0}', errorMsg); } @@ -237,7 +230,7 @@ export class UserPrompts { // ======================================================================== static readonly NO_FLOW_OR_TASK_SPECIFIED = 'No flow or task specified.'; - static readonly NO_TASK_PLAN_FOUND = 'No task plan found. Run "Convert" first.'; + static readonly NO_TASK_PLAN_FOUND = 'No task plan found. Run "Plan Conversion" first.'; static taskNotFound(taskId: string): string { return format('Task "{0}" not found in the task plan.', taskId); @@ -480,10 +473,6 @@ export class UserPrompts { return format('Failed to open conversion: {0}', errorMsg); } - static failedToExecute(errorMsg: string): string { - return format('Failed to execute: {0}', errorMsg); - } - static readonly NO_PROJECT_FOLDER = 'No project folder found.'; static readonly NO_CODE_WORKSPACE_FILE = 'No .code-workspace file found. Run Execute first to generate the project.'; @@ -546,7 +535,8 @@ export class UserPrompts { return format('Failed to Execute All tasks: {0}', error); } - static readonly NO_CONVERSION_TASK_PLAN = 'No conversion task plan found. Run "Convert" first.'; + static readonly NO_CONVERSION_TASK_PLAN = + 'No conversion task plan found. Run "Plan Conversion" first.'; static readonly NO_WORKSPACE_FOLDER = 'No workspace folder found.'; static projectFolderNotFound(projectPath: string): string { diff --git a/src/copilot/MigrationLMTools.ts b/src/copilot/MigrationLMTools.ts index 79a5583..4a86034 100644 --- a/src/copilot/MigrationLMTools.ts +++ b/src/copilot/MigrationLMTools.ts @@ -35,7 +35,6 @@ import { validateWorkflowDefinition } from '../workflowSchema'; import { ConversionService } from '../stages/conversion/ConversionService'; import { ConversionFileService } from '../stages/conversion/ConversionFileService'; import { MermaidValidationService } from '../services/MermaidValidationService'; -import { ChatPrompts } from '../constants/ChatPrompts'; import type { ConversionTask, ConversionTaskOutput, ConversionTaskPlan } from '../stages/conversion/types'; import { PlanningPreflightTool } from './PlanningPreflightTool'; import { PlanningBrief, validatePlanningBrief } from '../stages/planning/PlanningDecisions'; @@ -4366,16 +4365,6 @@ class ConversionStoreTaskPlanTool implements vscode.LanguageModelTool ({ id: t.id, name: t.name, order: t.order })), - message: executionTasks - ? ChatPrompts.executeAfterPlanInstruction( - executionTasks.map((t) => t.id), - conversionTasks.filter((t) => t.optional).map((t) => t.id) - ) - : `Conversion task plan stored with ${tasks.length} tasks. The tasks are now visible in the Conversion webview. You can proceed to execute tasks when the user asks.`, + message: `Conversion task plan stored with ${tasks.length} tasks. The tasks are now visible in the Conversion webview. You can proceed to execute tasks when the user asks.`, }) ), ]); diff --git a/src/services/AgentFileProvisioner.ts b/src/services/AgentFileProvisioner.ts index 1ab0c05..2b1639f 100644 --- a/src/services/AgentFileProvisioner.ts +++ b/src/services/AgentFileProvisioner.ts @@ -38,7 +38,7 @@ const ANALYSER_VERSION_TAG = ``; -const CONVERTER_AGENT_VERSION = '2.22.0'; +const CONVERTER_AGENT_VERSION = '2.21.0'; const CONVERTER_VERSION_TAG = ``; // ============================================================================= diff --git a/src/stages/conversion/ConversionService.ts b/src/stages/conversion/ConversionService.ts index 05077ec..5f2c53b 100644 --- a/src/stages/conversion/ConversionService.ts +++ b/src/stages/conversion/ConversionService.ts @@ -65,7 +65,6 @@ export class ConversionService implements vscode.Disposable { // Conversion state private state: ConversionStageState | undefined; private readonly executeAllActiveFlows = new Set(); - private readonly executeAfterPlanFlows = new Set(); private constructor() { this.disposables.push(this._onStateChange); @@ -369,53 +368,12 @@ export class ConversionService implements vscode.Disposable { return this.executeAllActiveFlows.has(flowId); } - /** - * Ask the next stored task plan for a flow to start executing its required - * tasks immediately, so creating and executing the tasks is one Convert step. - */ - public requestExecuteAfterPlan(flowId: string): void { - this.executeAfterPlanFlows.add(flowId); - } - - /** - * Withdraw a pending execute-after-plan request for a flow. - */ - public cancelExecuteAfterPlan(flowId: string): void { - this.executeAfterPlanFlows.delete(flowId); - } - - /** - * Start Execute All for a freshly stored task plan when the Convert step - * requested it. Marks the first required task in progress and returns the - * required tasks in execution order, or undefined when execution was not - * requested or nothing is left to run. - */ - public async startExecuteAfterPlan(flowId: string): Promise { - if (!this.executeAfterPlanFlows.delete(flowId)) { - return undefined; - } - - const requiredTasks = (this.getTaskPlan(flowId)?.tasks ?? []) - .filter( - (task) => !task.optional && task.status !== 'completed' && task.status !== 'skipped' - ) - .sort((a, b) => a.order - b.order); - if (requiredTasks.length === 0) { - return undefined; - } - - await this.setExecuteAllActive(flowId, true); - await this.updateTask(flowId, requiredTasks[0].id, { status: 'in-progress' }); - return requiredTasks; - } - /** * Stop a stuck execution for a flow. Resets any in-progress tasks back to * pending and clears Execute All orchestration state. Used when the agent * chat was stopped mid-run, leaving the UI stuck showing "Executing...". */ public async stopExecution(flowId: string): Promise { - this.executeAfterPlanFlows.delete(flowId); if (!this.state) { return; } @@ -456,7 +414,6 @@ export class ConversionService implements vscode.Disposable { */ public async reset(): Promise { this.state = undefined; - this.executeAfterPlanFlows.clear(); const storage = StorageService.getInstance(); await storage.setWorkspace(StorageKeys.CONVERSION_STATE, undefined); this.logger.debug('Conversion state reset'); @@ -566,7 +523,6 @@ export class ConversionService implements vscode.Disposable { d.dispose(); } this.executeAllActiveFlows.clear(); - this.executeAfterPlanFlows.clear(); ConversionService.instance = undefined; } } diff --git a/src/test/unit/conversion-step-button.test.ts b/src/test/unit/conversion-step-button.test.ts new file mode 100644 index 0000000..e8fe62d --- /dev/null +++ b/src/test/unit/conversion-step-button.test.ts @@ -0,0 +1,75 @@ +import * as assert from 'assert/strict'; +import { + ConversionStepState, + renderConversionStepButton, +} from '../../views/discovery/ConversionStepButton'; + +const planned: ConversionStepState = { + flowId: 'order-flow', + isPlanned: true, + isTasksCreated: false, + isConverted: false, + isCreatingTasks: false, + isExecuting: false, + isBlockedByOtherFlow: false, +}; + +function step(overrides: Partial): { + label: string; + action?: string; + disabled: boolean; +} { + const html = renderConversionStepButton({ ...planned, ...overrides }); + return { + label: /([^<]*)<\/strong>/.exec(html)?.[1] ?? '', + action: /onclick="event\.stopPropagation\(\); (\w+)\('order-flow'\)"/.exec(html)?.[1], + disabled: /\sdisabled[\s>]/.test(html), + }; +} + +describe('Home conversion step', () => { + it('creates the conversion tasks once the flow is planned', () => { + assert.deepEqual(step({ isPlanned: false }), { + label: 'Create', + action: undefined, + disabled: true, + }); + assert.deepEqual(step({}), { label: 'Create', action: 'convertFlow', disabled: false }); + assert.deepEqual(step({ isCreatingTasks: true }), { + label: 'Creating...', + action: undefined, + disabled: true, + }); + }); + + it('opens the created tasks so they are executed from the task list', () => { + assert.deepEqual(step({ isTasksCreated: true }), { + label: 'Execute', + action: 'viewConversion', + disabled: false, + }); + assert.deepEqual(step({ isTasksCreated: true, isExecuting: true }), { + label: 'Executing...', + action: undefined, + disabled: true, + }); + assert.deepEqual(step({ isTasksCreated: true, isConverted: true }), { + label: '✓ Converted', + action: 'viewConversion', + disabled: false, + }); + }); + + it('only blocks creating tasks while another flow is busy', () => { + assert.deepEqual(step({ isBlockedByOtherFlow: true }), { + label: 'Create', + action: undefined, + disabled: true, + }); + assert.deepEqual(step({ isBlockedByOtherFlow: true, isTasksCreated: true }), { + label: 'Execute', + action: 'viewConversion', + disabled: false, + }); + }); +}); diff --git a/src/test/unit/conversion.test.ts b/src/test/unit/conversion.test.ts index 6507819..1360264 100644 --- a/src/test/unit/conversion.test.ts +++ b/src/test/unit/conversion.test.ts @@ -1,14 +1,12 @@ import * as assert from 'assert/strict'; import { cachedPlan, - conversionPlan, createWorkspace, disposeWorkspace, generatedAt, prepareConversion, preparePlanning, } from '../helpers/biztalk'; -import { ChatPrompts } from '../../constants/ChatPrompts'; import { ConversionService } from '../../stages/conversion/ConversionService'; import { ConversionFileService } from '../../stages/conversion/ConversionFileService'; import { PlanningCacheService } from '../../stages/planning/PlanningCacheService'; @@ -149,39 +147,6 @@ describe('BizTalk Conversion stage', () => { assert.equal(restored.getTaskPlan(flow.id)?.tasks[1].status, 'in-progress'); }); - it('starts executing the required tasks as soon as the Convert step stores the plan', async () => { - const flow = await prepareConversion(); - const conversion = ConversionService.getInstance(); - assert.equal(await conversion.startExecuteAfterPlan(flow.id), undefined); - assert.equal(conversion.isExecuteAllActive(flow.id), false); - - conversion.requestExecuteAfterPlan(flow.id); - await conversion.storeTaskPlan(flow.id, conversionPlan(flow)); - const tasks = await conversion.startExecuteAfterPlan(flow.id); - assert.deepEqual( - tasks?.map((task) => task.id), - ['convert-schemas-and-map', 'generate-workflow', 'test-workflows'] - ); - assert.equal(conversion.isExecuteAllActive(flow.id), true); - assert.equal(conversion.getFlows()[0].status, 'in-progress'); - assert.deepEqual( - conversion.getTaskPlan(flow.id)?.tasks.map((task) => task.status), - ['in-progress', 'pending', 'pending', 'pending'] - ); - assert.equal(await conversion.startExecuteAfterPlan(flow.id), undefined); - }); - - it('drops a pending Convert request when execution is stopped', async () => { - const flow = await prepareConversion(); - const conversion = ConversionService.getInstance(); - conversion.requestExecuteAfterPlan(flow.id); - await conversion.stopExecution(flow.id); - await conversion.storeTaskPlan(flow.id, conversionPlan(flow)); - assert.equal(await conversion.startExecuteAfterPlan(flow.id), undefined); - assert.equal(conversion.isExecuteAllActive(flow.id), false); - assert.equal(conversion.getFlows()[0].status, 'tasks-ready'); - }); - it('reset removes conversion state without changing the approved planning inputs', async () => { const flow = await prepareConversion(); const conversion = ConversionService.getInstance(); @@ -196,50 +161,3 @@ describe('BizTalk Conversion stage', () => { assert.equal(flows[0].status, 'not-started'); }); }); - -describe('Convert step prompts', () => { - const params = { - flowName: 'Purchase order to invoice', - flowId: 'po-to-invoice', - azureResourceGroup: 'rg-test', - azureLocation: 'eastus', - azureSubscriptionId: '', - outputProjectName: 'Purchase-order-to-invoice', - outputProjectRoot: 'out/Purchase-order-to-invoice', - outputLogicAppName: 'Purchase-order-to-invoice-logicapp', - outputLogicAppRoot: 'out/Purchase-order-to-invoice/Purchase-order-to-invoice-logicapp', - }; - - it('asks only for the task plan when tasks are regenerated', () => { - const prompt = ChatPrompts.conversionForFlow(params); - assert.match(prompt, /3\. Call migration_conversion_storeTaskPlan/); - assert.doesNotMatch( - prompt, - /migration_conversion_storeTaskOutput|migration_conversion_finalize/ - ); - }); - - it('continues from the stored plan into executing the required tasks', () => { - const prompt = ChatPrompts.conversionForFlow({ ...params, executeAfterPlan: true }); - assert.match( - prompt, - /3\. Call migration_conversion_storeTaskPlan[^\n]*\n4\. [^\n]*migration_conversion_storeTaskOutput[^\n]*\n5\. [^\n]*migration_conversion_finalize/ - ); - assert.match(prompt, /Do NOT execute optional tasks/); - assert.match(prompt, /SCAFFOLD REQUIREMENT/); - }); - - it('lists the required tasks the agent runs after storing the plan', () => { - const message = ChatPrompts.executeAfterPlanInstruction( - ['convert-schemas-and-map', 'generate-workflow', 'test-workflows'], - ['cloud-deploy-test'] - ); - assert.match( - message, - /in this order: convert-schemas-and-map, generate-workflow, test-workflows\./ - ); - assert.match(message, /Start with "convert-schemas-and-map"/); - assert.match(message, /migration_conversion_finalize/); - assert.match(message, /optional tasks \(cloud-deploy-test\)/); - }); -}); diff --git a/src/views/conversion/ConversionWebviewPanel.ts b/src/views/conversion/ConversionWebviewPanel.ts index 2d4947b..ed51813 100644 --- a/src/views/conversion/ConversionWebviewPanel.ts +++ b/src/views/conversion/ConversionWebviewPanel.ts @@ -159,13 +159,8 @@ export class ConversionWebviewPanel implements vscode.Disposable { this.update(); } this.logger.debug(`Conversion started for flow: ${flowId}`); - // Convert creates the task plan and executes it in one agent session vscode.commands - .executeCommand( - 'logicAppsMigrationAgent.generateConversionForFlow', - flowId, - { executeAfterPlan: true } - ) + .executeCommand('logicAppsMigrationAgent.generateConversionForFlow', flowId) .then( () => this.logger.debug( @@ -1008,7 +1003,7 @@ export class ConversionWebviewPanel implements vscode.Disposable { private getFlowActionButton(flow: ConversionFlow): string { switch (flow.status) { case 'not-started': - return ``; + return ``; case 'thinking': return ``; case 'tasks-ready': @@ -1223,11 +1218,11 @@ export class ConversionWebviewPanel implements vscode.Disposable { return `
-

Ready to Convert

-

Click "Convert" to have the converter agent create the ordered conversion tasks for this flow from the planning results and execute them.

+

Ready to Execute

+

Click "Plan Conversion" to have the converter agent analyse the planning results and determine the ordered conversion tasks for this flow.


`; } diff --git a/src/views/discovery/ConversionStepButton.ts b/src/views/discovery/ConversionStepButton.ts new file mode 100644 index 0000000..ab43b7e --- /dev/null +++ b/src/views/discovery/ConversionStepButton.ts @@ -0,0 +1,80 @@ +/** + * Conversion step on the Home flow cards. + * + * A single step covers conversion: it creates the conversion tasks, then opens + * the task list where each task (or Execute All) is executed. + * + * @module views/discovery/ConversionStepButton + */ + +export interface ConversionStepState { + readonly flowId: string; + readonly isPlanned: boolean; + readonly isTasksCreated: boolean; + readonly isConverted: boolean; + readonly isCreatingTasks: boolean; + readonly isExecuting: boolean; + readonly isBlockedByOtherFlow: boolean; +} + +function stepLabel(text: string): string { + return `${text}Conversion Tasks`; +} + +function disabledStep(text: string, title?: string): string { + const titleAttr = title ? ` title="${title}"` : ''; + return ``; +} + +function actionStep( + text: string, + style: 'btn-primary' | 'btn-done', + action: 'convertFlow' | 'viewConversion', + flowId: string, + title: string +): string { + return ``; +} + +/** + * Render the conversion step: Create the tasks, then Execute them from the task list. + */ +export function renderConversionStepButton(state: ConversionStepState): string { + if (!state.isPlanned) { + return disabledStep('Create', 'Plan first'); + } + if (state.isCreatingTasks) { + return disabledStep('Creating...'); + } + if (state.isExecuting) { + return disabledStep('Executing...'); + } + if (state.isConverted) { + return actionStep( + '✓ Converted', + 'btn-done', + 'viewConversion', + state.flowId, + 'View conversion tasks' + ); + } + if (state.isTasksCreated) { + return actionStep( + 'Execute', + 'btn-primary', + 'viewConversion', + state.flowId, + 'Open the conversion tasks to execute them' + ); + } + if (state.isBlockedByOtherFlow) { + return disabledStep('Create', 'Another flow is in progress'); + } + return actionStep( + 'Create', + 'btn-primary', + 'convertFlow', + state.flowId, + 'Create the conversion tasks' + ); +} diff --git a/src/views/discovery/SourceFlowVisualizer.ts b/src/views/discovery/SourceFlowVisualizer.ts index 52f4166..bfbdd84 100644 --- a/src/views/discovery/SourceFlowVisualizer.ts +++ b/src/views/discovery/SourceFlowVisualizer.ts @@ -23,6 +23,7 @@ import { GeneratedFlowResult, FlowGroupsResult } from '../../services/LLMFlowGen import { UserPrompts } from '../../constants/UserMessages'; import { ChatPrompts } from '../../constants/ChatPrompts'; import { ConfigurationService } from '../../services/ConfigurationService'; +import { renderConversionStepButton } from './ConversionStepButton'; // ============================================================================= // Source Flow Visualizer @@ -44,9 +45,9 @@ export class SourceFlowVisualizer implements vscode.Disposable { public static generatingGroupIds = new Set(); // Track which flow group IDs are currently being planned public static planningGroupIds = new Set(); - // Track which flow group IDs are creating conversion tasks (first phase of Convert) + // Track which flow group IDs are currently being converted public static convertingGroupIds = new Set(); - // Track which flow group IDs are executing conversion tasks (second phase of Convert) + // Track which flow group IDs are currently executing conversion tasks public static executingGroupIds = new Set(); // Track per-flow analysis panels (reuse on re-click instead of creating duplicates) private static analysisPanels = new Map(); @@ -56,7 +57,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { return this.isInitialGenerating || this.generatingGroupIds.size > 0; } - /** True if ANY LLM operation (analyse/plan/convert) is running on ANY flow */ + /** True if ANY LLM operation (analyse/plan/create/execute) is running on ANY flow */ public static get isAnyFlowBusy(): boolean { return ( this.generatingGroupIds.size > 0 || @@ -295,23 +296,16 @@ export class SourceFlowVisualizer implements vscode.Disposable { planBtn = ``; } - // ── Convert button (creates the conversion tasks, then executes them) ── - let convertBtn: string; - if (!isPlanned) { - convertBtn = - ''; - } else if (isConverting || isExecuting) { - convertBtn = ``; - } else if (isConverted) { - convertBtn = ``; - } else if (isBlockedByOtherFlow) { - convertBtn = - ''; - } else if (isTasksCreated) { - convertBtn = ``; - } else { - convertBtn = ``; - } + // ── Conversion step: create the tasks, then open them to execute ── + const conversionBtn = renderConversionStepButton({ + flowId: g.id, + isPlanned, + isTasksCreated, + isConverted, + isCreatingTasks: isConverting, + isExecuting, + isBlockedByOtherFlow, + }); // ── Open in VS Code button ── let openBtn: string; @@ -322,7 +316,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { if (isConverted) { openBtn = ``; } else { - openBtn = ``; + openBtn = ``; } // Step connector arrows @@ -336,7 +330,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { title="Reset all progress for this flow and start over">↺ Start Over` : ''; - // Stop button — shown while any process (analyse/plan/convert) runs on this flow + // Stop button — shown while any process (analyse/plan/create/execute) runs on this flow const stopBtn = isThisFlowBusy ? `` : ''; @@ -353,7 +347,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { ${escapeHtml(g.category)}
- ${analyseBtn}${stepArrow}${planBtn}${stepArrow}${convertBtn}${stepArrow}${openBtn} + ${analyseBtn}${stepArrow}${planBtn}${stepArrow}${conversionBtn}${stepArrow}${openBtn}
`; }) @@ -1366,37 +1360,34 @@ export class SourceFlowVisualizer implements vscode.Disposable { } case 'convertFlowFromSelector': { - // Single Convert step: create the conversion tasks and execute them in one - // agent session, or resume the tasks this flow already has. + // User clicked Convert button — mark as converting and start agent chat const flowId = message.data as string; this.logger.debug(`[FlowViz] User requested conversion for flow: ${flowId}`); - void (async () => { - try { - const { DiscoveryCacheService } = - await import('../../stages/discovery/DiscoveryCacheService'); - const tasksCreated = !!DiscoveryCacheService.getInstance() - .getFlowGroups() - ?.groups.find((g) => g.id === flowId)?.tasksCreated; - let hasTaskPlan = false; - if (tasksCreated) { - const { ConversionService } = await import('../../stages/conversion'); - const conversionService = ConversionService.getInstance(); - await conversionService.initialize(); - hasTaskPlan = !!conversionService.getTaskPlan(flowId); - } - if (hasTaskPlan) { - this.executeConversionTasks(flowId); - } else { - this.createAndExecuteConversionTasks(flowId); + + // Mark as converting and refresh UI to show Converting... state + SourceFlowVisualizer.convertingGroupIds.add(flowId); + SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); + + // Use setTimeout to let the UI refresh before starting async work + setTimeout(() => { + void (async () => { + try { + // Open conversion planning agent chat for this flow + await vscode.commands.executeCommand( + 'logicAppsMigrationAgent.generateConversionForFlow', + flowId + ); + } catch (err) { + SourceFlowVisualizer.convertingGroupIds.delete(flowId); + SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); + vscode.window.showErrorMessage( + UserPrompts.failedToStartConversionVisualizer( + err instanceof Error ? err.message : String(err) + ) + ); } - } catch (err) { - vscode.window.showErrorMessage( - UserPrompts.failedToStartConversionVisualizer( - err instanceof Error ? err.message : String(err) - ) - ); - } - })(); + })(); + }, 100); break; } @@ -1717,77 +1708,6 @@ export class SourceFlowVisualizer implements vscode.Disposable { } } - /** - * Convert step for a flow without tasks: create the conversion tasks and let - * the agent execute them in the same chat session. - */ - private createAndExecuteConversionTasks(flowId: string): void { - // Mark as converting and refresh UI to show the Creating tasks state - SourceFlowVisualizer.convertingGroupIds.add(flowId); - SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); - - // Use setTimeout to let the UI refresh before starting async work - setTimeout(() => { - void (async () => { - try { - await vscode.commands.executeCommand( - 'logicAppsMigrationAgent.generateConversionForFlow', - flowId, - { executeAfterPlan: true } - ); - } catch (err) { - SourceFlowVisualizer.convertingGroupIds.delete(flowId); - SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); - vscode.window.showErrorMessage( - UserPrompts.failedToStartConversionVisualizer( - err instanceof Error ? err.message : String(err) - ) - ); - } - })(); - }, 100); - } - - /** - * Convert step for a flow that already has tasks (e.g. an interrupted run): - * open the Conversion view and execute the remaining tasks. - */ - private executeConversionTasks(flowId: string): void { - SourceFlowVisualizer.executingGroupIds.add(flowId); - SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); - - void (async () => { - try { - // Ensure conversion service is initialized and has the flow - const { ConversionService } = await import('../../stages/conversion'); - const conversionService = ConversionService.getInstance(); - await conversionService.initialize(); - if (conversionService.getFlows().length === 0) { - conversionService.buildFlowsFromPlanning(); - } - await conversionService.selectFlow(flowId); - - // Open conversion webview - const { ConversionWebviewPanel } = await import('../conversion'); - ConversionWebviewPanel.createOrShow(this.extensionUri); - - // Trigger Execute All after a short delay to let the webview render - setTimeout(() => { - void vscode.commands.executeCommand( - 'logicAppsMigrationAgent.executeAllConversionTasks', - flowId - ); - }, 500); - } catch (err) { - SourceFlowVisualizer.executingGroupIds.delete(flowId); - SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); - vscode.window.showErrorMessage( - UserPrompts.failedToExecute(err instanceof Error ? err.message : String(err)) - ); - } - })(); - } - /** * Each group gets its own NEW chat session, so multiple groups can generate concurrently. */ From 13f0b91eeccca39dc908fe9f3674519bf4895ba6 Mon Sep 17 00:00:00 2001 From: Shreyansh Gupta Date: Mon, 23 Nov 2026 14:34:38 +0530 Subject: [PATCH 3/4] Name the Home conversion step Execute The combined Home step still read "Create" before tasks existed. It is now named Execute in every state, like Analyse -> Analysed and Plan -> Planned: - Execute: generates the conversion tasks (or opens them once they exist) so they are executed from the task list. - Executing...: while tasks are generated or executed. - Executed: when all required tasks are done. A unit test checks every state combination so the step never shows "Create" in its label or tooltip. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/test/unit/conversion-step-button.test.ts | 41 +++++++++++++++----- src/views/discovery/ConversionStepButton.ts | 25 ++++++------ src/views/discovery/SourceFlowVisualizer.ts | 9 +++-- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/test/unit/conversion-step-button.test.ts b/src/test/unit/conversion-step-button.test.ts index e8fe62d..8002117 100644 --- a/src/test/unit/conversion-step-button.test.ts +++ b/src/test/unit/conversion-step-button.test.ts @@ -27,22 +27,22 @@ function step(overrides: Partial): { }; } -describe('Home conversion step', () => { - it('creates the conversion tasks once the flow is planned', () => { +describe('Home Execute step', () => { + it('is named Execute and generates the conversion tasks once the flow is planned', () => { assert.deepEqual(step({ isPlanned: false }), { - label: 'Create', + label: 'Execute', action: undefined, disabled: true, }); - assert.deepEqual(step({}), { label: 'Create', action: 'convertFlow', disabled: false }); + assert.deepEqual(step({}), { label: 'Execute', action: 'convertFlow', disabled: false }); assert.deepEqual(step({ isCreatingTasks: true }), { - label: 'Creating...', + label: 'Executing...', action: undefined, disabled: true, }); }); - it('opens the created tasks so they are executed from the task list', () => { + it('opens the generated tasks so they are executed from the task list', () => { assert.deepEqual(step({ isTasksCreated: true }), { label: 'Execute', action: 'viewConversion', @@ -54,15 +54,15 @@ describe('Home conversion step', () => { disabled: true, }); assert.deepEqual(step({ isTasksCreated: true, isConverted: true }), { - label: '✓ Converted', + label: '✓ Executed', action: 'viewConversion', disabled: false, }); }); - it('only blocks creating tasks while another flow is busy', () => { + it('only blocks starting a flow while another flow is busy', () => { assert.deepEqual(step({ isBlockedByOtherFlow: true }), { - label: 'Create', + label: 'Execute', action: undefined, disabled: true, }); @@ -72,4 +72,27 @@ describe('Home conversion step', () => { disabled: false, }); }); + + it('never shows Create in any state', () => { + const flags = [ + 'isPlanned', + 'isTasksCreated', + 'isConverted', + 'isCreatingTasks', + 'isExecuting', + 'isBlockedByOtherFlow', + ] as const; + for (let mask = 0; mask < 2 ** flags.length; mask++) { + const overrides: Partial> = {}; + flags.forEach((flag, i) => { + overrides[flag] = Math.floor(mask / 2 ** i) % 2 === 1; + }); + const html = renderConversionStepButton({ ...planned, ...overrides }); + assert.doesNotMatch(html, /creat/i, JSON.stringify(overrides)); + assert.ok( + ['Execute', 'Executing...', '✓ Executed'].includes(step(overrides).label), + JSON.stringify(overrides) + ); + } + }); }); diff --git a/src/views/discovery/ConversionStepButton.ts b/src/views/discovery/ConversionStepButton.ts index ab43b7e..82e7a47 100644 --- a/src/views/discovery/ConversionStepButton.ts +++ b/src/views/discovery/ConversionStepButton.ts @@ -1,8 +1,9 @@ /** - * Conversion step on the Home flow cards. + * Execute step on the Home flow cards. * - * A single step covers conversion: it creates the conversion tasks, then opens - * the task list where each task (or Execute All) is executed. + * A single Execute step covers conversion: on a planned flow it generates the + * conversion tasks and opens the task list, where each task (or Execute All) + * is executed. * * @module views/discovery/ConversionStepButton */ @@ -37,21 +38,19 @@ function actionStep( } /** - * Render the conversion step: Create the tasks, then Execute them from the task list. + * Render the Execute step. It keeps the Execute name in every state, like + * Analyse → ✓ Analysed and Plan → ✓ Planned. */ export function renderConversionStepButton(state: ConversionStepState): string { if (!state.isPlanned) { - return disabledStep('Create', 'Plan first'); + return disabledStep('Execute', 'Plan first'); } - if (state.isCreatingTasks) { - return disabledStep('Creating...'); - } - if (state.isExecuting) { + if (state.isCreatingTasks || state.isExecuting) { return disabledStep('Executing...'); } if (state.isConverted) { return actionStep( - '✓ Converted', + '✓ Executed', 'btn-done', 'viewConversion', state.flowId, @@ -68,13 +67,13 @@ export function renderConversionStepButton(state: ConversionStepState): string { ); } if (state.isBlockedByOtherFlow) { - return disabledStep('Create', 'Another flow is in progress'); + return disabledStep('Execute', 'Another flow is in progress'); } return actionStep( - 'Create', + 'Execute', 'btn-primary', 'convertFlow', state.flowId, - 'Create the conversion tasks' + 'Generate the conversion tasks, then execute them from the task list' ); } diff --git a/src/views/discovery/SourceFlowVisualizer.ts b/src/views/discovery/SourceFlowVisualizer.ts index bfbdd84..7a750fd 100644 --- a/src/views/discovery/SourceFlowVisualizer.ts +++ b/src/views/discovery/SourceFlowVisualizer.ts @@ -296,7 +296,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { planBtn = ``; } - // ── Conversion step: create the tasks, then open them to execute ── + // ── Execute step: generate the conversion tasks, then open them to execute ── const conversionBtn = renderConversionStepButton({ flowId: g.id, isPlanned, @@ -1360,11 +1360,12 @@ export class SourceFlowVisualizer implements vscode.Disposable { } case 'convertFlowFromSelector': { - // User clicked Convert button — mark as converting and start agent chat + // User clicked Execute on a flow without tasks — generate them; the task + // list opens once the agent stores them const flowId = message.data as string; this.logger.debug(`[FlowViz] User requested conversion for flow: ${flowId}`); - // Mark as converting and refresh UI to show Converting... state + // Mark as converting and refresh UI to show the Executing... state SourceFlowVisualizer.convertingGroupIds.add(flowId); SourceFlowVisualizer.showFlowGroupSelector(this.extensionUri); @@ -1392,7 +1393,7 @@ export class SourceFlowVisualizer implements vscode.Disposable { } case 'viewConversionFromSelector': { - // User clicked "✓ Converted" — open Conversion webview for this flow + // User clicked Execute / ✓ Executed on a flow with tasks — open the task list const flowId = message.data as string; this.logger.debug(`[FlowViz] User viewing conversion for flow: ${flowId}`); void (async () => { From 226c0b80174b3a7b983dfaed58aa2c686be29e0a Mon Sep 17 00:00:00 2001 From: Shreyansh Gupta Date: Mon, 23 Nov 2026 18:04:14 +0530 Subject: [PATCH 4/4] Finalize the flow when its last required conversion task completes Open in VS Code (and the Home step's Executed state) only enabled after migration_conversion_finalize, which nothing calls when tasks are executed one at a time from the task list, so the button stayed disabled until VS Code was reloaded. migration_conversion_storeTaskOutput now finalizes the flow once every required task is completed or skipped: it marks the flow converted, refreshes Home and stamps the workflow MigrationMetadata, reusing the finalize tool's logic. Optional tasks may still be pending, and calling migration_conversion_finalize afterwards changes nothing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/copilot/MigrationLMTools.ts | 96 ++++++++++++++-------- src/stages/conversion/ConversionService.ts | 14 ++++ src/test/unit/conversion.test.ts | 21 +++++ 3 files changed, 97 insertions(+), 34 deletions(-) diff --git a/src/copilot/MigrationLMTools.ts b/src/copilot/MigrationLMTools.ts index 4a86034..048cfe8 100644 --- a/src/copilot/MigrationLMTools.ts +++ b/src/copilot/MigrationLMTools.ts @@ -4897,8 +4897,17 @@ class ConversionStoreTaskOutputTool implements vscode.LanguageModelTool t.id === taskId); const actualStatus = updatedTask?.status || 'completed'; + // Finalize once the last required task is stored, so the flow shows as converted + // ("Open in VS Code" enables) even when tasks are executed one at a time and the + // agent never calls migration_conversion_finalize. + let flowFinalized = false; + if (taskPlan2 && conversionService.areRequiredTasksComplete(flowId)) { + await completeFlowConversion(flowId, taskPlan2, logger); + flowFinalized = true; + } + logger.debug( - `[LMTool] migration_conversion_storeTaskOutput: stored output for task "${taskId}" in flow "${flowId}" (status: ${actualStatus})` + `[LMTool] migration_conversion_storeTaskOutput: stored output for task "${taskId}" in flow "${flowId}" (status: ${actualStatus}${flowFinalized ? ', flow finalized' : ''})` ); TelemetryService.getInstance().logStep('conversion.task.completed', { flowId, @@ -4915,7 +4924,11 @@ class ConversionStoreTaskOutputTool implements vscode.LanguageModelTool { + // Deterministically stamp MigrationMetadata into every generated workflow.json. + // Machine-generated data — no agent involvement, no rejection/retry loop. + const stampedCount = await applyWorkflowMigrationMetadata(plan, logger); + + // Mark the flow as completed + const flow = ConversionService.getInstance() + .getFlows() + .find((f) => f.id === flowId); + if (flow) { + flow.status = 'completed'; + } + + // Mark flow as fully converted in DiscoveryCacheService + try { + const { DiscoveryCacheService } = await import('../stages/discovery/DiscoveryCacheService'); + await DiscoveryCacheService.getInstance().markFlowConverted(flowId); + } catch { + // Non-critical + } + + // Clear executing flag and refresh flow group selector + try { + const { SourceFlowVisualizer } = await import('../views/discovery/SourceFlowVisualizer'); + SourceFlowVisualizer.executingGroupIds.delete(flowId); + if (SourceFlowVisualizer.currentPanel) { + SourceFlowVisualizer.showFlowGroupSelector( + SourceFlowVisualizer.currentPanel.extensionUri + ); + } + } catch { + // Non-critical + } + + return stampedCount; +} + class ConversionFinalizeTool implements vscode.LanguageModelTool { async invoke( options: vscode.LanguageModelToolInvocationOptions, @@ -5110,38 +5169,7 @@ class ConversionFinalizeTool implements vscode.LanguageModelTool f.id === flowId); - if (flow) { - flow.status = 'completed'; - } - - // Mark flow as fully converted in DiscoveryCacheService - try { - const { DiscoveryCacheService } = - await import('../stages/discovery/DiscoveryCacheService'); - await DiscoveryCacheService.getInstance().markFlowConverted(flowId); - } catch { - // Non-critical - } - - // Clear executing flag and refresh flow group selector - try { - const { SourceFlowVisualizer } = - await import('../views/discovery/SourceFlowVisualizer'); - SourceFlowVisualizer.executingGroupIds.delete(flowId); - if (SourceFlowVisualizer.currentPanel) { - SourceFlowVisualizer.showFlowGroupSelector( - SourceFlowVisualizer.currentPanel.extensionUri - ); - } - } catch { - // Non-critical - } + const stampedCount = await completeFlowConversion(flowId, plan, logger); // Open conversion webview void vscode.commands.executeCommand('logicAppsMigrationAgent.openConversionView'); diff --git a/src/stages/conversion/ConversionService.ts b/src/stages/conversion/ConversionService.ts index 5f2c53b..68a4b7c 100644 --- a/src/stages/conversion/ConversionService.ts +++ b/src/stages/conversion/ConversionService.ts @@ -325,6 +325,20 @@ export class ConversionService implements vscode.Disposable { return this.state?.taskPlans[flowId]; } + /** + * Whether every required (non-optional) task in the flow's plan is completed + * or skipped, so the flow's conversion can be finalized. + */ + public areRequiredTasksComplete(flowId: string): boolean { + const tasks = this.getTaskPlan(flowId)?.tasks ?? []; + return ( + tasks.length > 0 && + tasks.every( + (task) => task.optional || task.status === 'completed' || task.status === 'skipped' + ) + ); + } + /** * Set Execute All orchestration mode for a flow. */ diff --git a/src/test/unit/conversion.test.ts b/src/test/unit/conversion.test.ts index 1360264..bd92268 100644 --- a/src/test/unit/conversion.test.ts +++ b/src/test/unit/conversion.test.ts @@ -115,6 +115,27 @@ describe('BizTalk Conversion stage', () => { assert.deepEqual(completedFlows, [flow.id]); }); + it('is ready to finalize once every required task is done, even with optional tasks pending', async () => { + const flow = await prepareConversion(); + const conversion = ConversionService.getInstance(); + assert.equal(conversion.areRequiredTasksComplete(flow.id), false); + await conversion.storeTaskOutput(flow.id, 'convert-schemas-and-map', { + completedAt: generatedAt, + summary: 'convert-schemas-and-map completed.', + }); + await conversion.updateTask(flow.id, 'generate-workflow', { status: 'failed' }); + assert.equal(conversion.areRequiredTasksComplete(flow.id), false); + for (const taskId of ['generate-workflow', 'test-workflows']) { + await conversion.storeTaskOutput(flow.id, taskId, { + completedAt: generatedAt, + summary: `${taskId} completed.`, + }); + } + assert.equal(conversion.getTaskPlan(flow.id)?.tasks[3].status, 'pending'); + assert.equal(conversion.areRequiredTasksComplete(flow.id), true); + assert.equal(conversion.areRequiredTasksComplete('flow-without-tasks'), false); + }); + it('stops interrupted execution without losing previously completed tasks', async () => { const flow = await prepareConversion(); const conversion = ConversionService.getInstance();