From 97928e311101ea2f8600d65e8fc2feb1759eaaa6 Mon Sep 17 00:00:00 2001 From: Megan Mott Date: Tue, 2 Dec 2025 13:06:24 -0800 Subject: [PATCH 1/3] add new rerun command --- package-lock.json | 36 +++++++++++++++++++++++++++++--- package.json | 17 ++++++++++++++- package.nls.json | 1 + src/commands/registerCommands.ts | 2 ++ src/copilot/reRunWithCopilot.ts | 32 ++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 src/copilot/reRunWithCopilot.ts diff --git a/package-lock.json b/package-lock.json index 2a905869..36b485cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@microsoft/vscode-azext-azureauth": "^5.1.1", "@microsoft/vscode-azext-azureutils": "^4.0.0", - "@microsoft/vscode-azext-utils": "^4.0.0", + "@microsoft/vscode-azext-utils": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.0.tgz", "buffer": "^6.0.3", "form-data": "^4.0.4", "fs-extra": "^11.3.0", @@ -1017,6 +1017,36 @@ "@azure/ms-rest-azure-env": "^2.0.0" } }, + "node_modules/@microsoft/vscode-azext-azureutils/node_modules/@microsoft/vscode-azext-utils": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-utils/-/vscode-azext-utils-4.0.2.tgz", + "integrity": "sha512-RpHKn4hcDTtJpMaif0jb8ulfDEFPT/C/U3wcx93eLxgQhDVFQ5aC49KybxodNp89dVUXhNUHhu6gdNDPfXt6Pg==", + "license": "MIT", + "dependencies": { + "@microsoft/vscode-azureresources-api": "^3.0.0", + "@vscode/extension-telemetry": "^0.9.6", + "dayjs": "^1.11.2", + "escape-string-regexp": "^2.0.0", + "html-to-text": "^9.0.0", + "semver": "^7.3.7", + "vscode-tas-client": "^0.1.84" + }, + "engines": { + "vscode": "^1.105.0" + }, + "peerDependencies": { + "@azure/ms-rest-azure-env": "^2.0.0" + } + }, + "node_modules/@microsoft/vscode-azext-azureutils/node_modules/escape-string-regexp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", + "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/@microsoft/vscode-azext-dev": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-dev/-/vscode-azext-dev-3.0.1.tgz", @@ -1069,8 +1099,8 @@ }, "node_modules/@microsoft/vscode-azext-utils": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-utils/-/vscode-azext-utils-4.0.0.tgz", - "integrity": "sha512-c5e4LD8Xkir6KqAVzIF0f+u1w/QDH7b3AFgYYcWqPyYN0HVp+YCvI97zP1uqb/YzZFTYjr2NbO54xgtftsePAA==", + "resolved": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.0.tgz", + "integrity": "sha512-AWPegfYXln1f3GpApRl8DGVAtrM77Kf59mJDMrS8tK+FZBFFzmGercDaE8R0Ow5blbihZNa5tIaLO5qA1TDcPg==", "license": "MIT", "dependencies": { "@microsoft/vscode-azureresources-api": "^3.0.0", diff --git a/package.json b/package.json index db85557d..eb1ac81f 100644 --- a/package.json +++ b/package.json @@ -337,6 +337,12 @@ "category": "Azure", "icon": "$(chat-sparkle)" }, + { + "command": "azureResourceGroups.reRunWithCopilot", + "title": "%azureResourceGroups.reRunWithCopilot%", + "category": "Azure", + "icon": "$(refresh)" + }, { "command": "azureTenantsView.refresh", "title": "%azureResourceGroups.refresh%", @@ -624,6 +630,11 @@ "command": "azureResourceGroups.askAgentAboutActivityLogItem", "when": "view == azureActivityLog && viewItem =~ /activityItem/i", "group": "inline" + }, + { + "command": "azureResourceGroups.reRunWithCopilot", + "when": "view == azureActivityLog && viewItem =~ /activityItem/i", + "group": "inline" } ], "commandPalette": [ @@ -678,6 +689,10 @@ { "command": "azureResourceGroups.askAgentAboutActivityLogItem", "when": "never" + }, + { + "command": "azureResourceGroups.reRunWithCopilot", + "when": "never" } ], "azureResourceGroups.groupBy": [ @@ -946,7 +961,7 @@ "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@microsoft/vscode-azext-azureauth": "^5.1.1", "@microsoft/vscode-azext-azureutils": "^4.0.0", - "@microsoft/vscode-azext-utils": "^4.0.0", + "@microsoft/vscode-azext-utils": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.0.tgz", "buffer": "^6.0.3", "form-data": "^4.0.4", "fs-extra": "^11.3.0", diff --git a/package.nls.json b/package.nls.json index 766e8a32..70704bfe 100644 --- a/package.nls.json +++ b/package.nls.json @@ -55,6 +55,7 @@ "Do not translate '@azure'; it is syntax for addressing the Azure agent." ] }, + "azureResourceGroups.reRunWithCopilot": "Rerun Command with Copilot...", "walkthrough.askAzure.description": { "message": "Enter @azure in the GitHub Copilot Chat to start a conversation.\n @azure can help with learning about Azure, deploying resources, troubleshooting web app problems, querying Azure costs and more without having to switch to the Azure Portal.\n[Chat with @azure](command:azureResourceGroups.askAzure?%5B%22What%20kinds%20of%20things%20can%20you%20help%20me%20with?%22%5D)", "comment": [ diff --git a/src/commands/registerCommands.ts b/src/commands/registerCommands.ts index 873ae56a..05febeb4 100644 --- a/src/commands/registerCommands.ts +++ b/src/commands/registerCommands.ts @@ -10,6 +10,7 @@ import { askAgentAboutActivityLog } from '../chat/askAgentAboutActivityLog/askAg import { askAgentAboutResource } from '../chat/askAgentAboutResource'; import { askAzureInCommandPalette } from '../chat/askAzure'; import { uploadFileToCloudShell } from '../cloudConsole/uploadFileToCloudShell'; +import { reRunWithCopilot } from '../copilot/reRunWithCopilot'; import { ext } from '../extensionVariables'; import { TargetServiceRoleAssignmentItem } from '../managedIdentity/TargetServiceRoleAssignmentItem'; import { BranchDataItemWrapper } from '../tree/BranchDataItemWrapper'; @@ -134,6 +135,7 @@ export function registerCommands(): void { registerCommand("azureResourceGroups.askAgentAboutActivityLog", async (context: IActionContext, _node: ActivityItem) => await askAgentAboutActivityLog(context)); registerCommandWithTreeNodeUnwrapping("azureResourceGroups.askAgentAboutActivityLogItem", askAgentAboutActivityLog); registerCommandWithTreeNodeUnwrapping<{ id?: string }>("azureResourceGroups.askAgentAboutResource", (context, node) => askAgentAboutResource(context, node)); + registerCommand('azureResourceGroups.reRunWithCopilot', async (context: IActionContext, item: ActivityItem) => await reRunWithCopilot(context, item)); } async function handleAzExtTreeItemRefresh(context: IActionContext, node?: ResourceGroupsItem): Promise { diff --git a/src/copilot/reRunWithCopilot.ts b/src/copilot/reRunWithCopilot.ts new file mode 100644 index 00000000..adfcf65d --- /dev/null +++ b/src/copilot/reRunWithCopilot.ts @@ -0,0 +1,32 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Microsoft Corporation. All rights reserved. +* Licensed under the MIT License. See License.md in the project root for license information. +*--------------------------------------------------------------------------------------------*/ + +import { CopilotUserInput, executeCommandWithAddedContext, type IActionContext } from "@microsoft/vscode-azext-utils"; +import * as vscode from "vscode"; +import { ActivitySelectedCache } from "../chat/askAgentAboutActivityLog/ActivitySelectedCache"; +import { convertActivityTreeToSimpleObjectArray, ConvertedActivityItem } from "../chat/tools/GetAzureActivityLog/convertActivityTree"; +import { GetAzureActivityLogContext } from "../chat/tools/GetAzureActivityLog/GetAzureActivityLogContext"; +import { ActivityItem } from "../tree/activityLog/ActivityItem"; + +export async function reRunWithCopilot(context: IActionContext, item: ActivityItem): Promise { + const activitySelectedCache = ActivitySelectedCache.getInstance(); + activitySelectedCache.addActivity(item.id); + + const activityContext: GetAzureActivityLogContext = { + ...context, + activitySelectedCache: activitySelectedCache + } + + const activityItems: ConvertedActivityItem[] = await convertActivityTreeToSimpleObjectArray(activityContext); + context.ui = new CopilotUserInput(vscode, JSON.stringify(activityItems)); + + // An item will always be passed in so we will only need to look at the first item in the array + const callbackId = activityItems[0]?.callbackId; + if (callbackId) { + await executeCommandWithAddedContext(callbackId, context) + } else { + throw new Error(vscode.l10n.t('Failed to rerun with Copilot. Activity item callback ID not found.')); + } +} From 0a7414bbc68277918e75bdbc88073495971c8680 Mon Sep 17 00:00:00 2001 From: Megan Mott Date: Wed, 10 Dec 2025 14:59:21 -0800 Subject: [PATCH 2/3] pass in subscription --- package-lock.json | 38 ++++----------------------------- package.json | 2 +- src/copilot/reRunWithCopilot.ts | 12 +++++++++-- 3 files changed, 15 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index 36b485cf..5eca9709 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@microsoft/vscode-azext-azureauth": "^5.1.1", "@microsoft/vscode-azext-azureutils": "^4.0.0", - "@microsoft/vscode-azext-utils": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.0.tgz", + "@microsoft/vscode-azext-utils": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.2.tgz", "buffer": "^6.0.3", "form-data": "^4.0.4", "fs-extra": "^11.3.0", @@ -1017,36 +1017,6 @@ "@azure/ms-rest-azure-env": "^2.0.0" } }, - "node_modules/@microsoft/vscode-azext-azureutils/node_modules/@microsoft/vscode-azext-utils": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-utils/-/vscode-azext-utils-4.0.2.tgz", - "integrity": "sha512-RpHKn4hcDTtJpMaif0jb8ulfDEFPT/C/U3wcx93eLxgQhDVFQ5aC49KybxodNp89dVUXhNUHhu6gdNDPfXt6Pg==", - "license": "MIT", - "dependencies": { - "@microsoft/vscode-azureresources-api": "^3.0.0", - "@vscode/extension-telemetry": "^0.9.6", - "dayjs": "^1.11.2", - "escape-string-regexp": "^2.0.0", - "html-to-text": "^9.0.0", - "semver": "^7.3.7", - "vscode-tas-client": "^0.1.84" - }, - "engines": { - "vscode": "^1.105.0" - }, - "peerDependencies": { - "@azure/ms-rest-azure-env": "^2.0.0" - } - }, - "node_modules/@microsoft/vscode-azext-azureutils/node_modules/escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/@microsoft/vscode-azext-dev": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-dev/-/vscode-azext-dev-3.0.1.tgz", @@ -1098,9 +1068,9 @@ } }, "node_modules/@microsoft/vscode-azext-utils": { - "version": "4.0.0", - "resolved": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.0.tgz", - "integrity": "sha512-AWPegfYXln1f3GpApRl8DGVAtrM77Kf59mJDMrS8tK+FZBFFzmGercDaE8R0Ow5blbihZNa5tIaLO5qA1TDcPg==", + "version": "4.0.2", + "resolved": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.2.tgz", + "integrity": "sha512-5r7QaInfYnjc6OZDmOvFnQFee0t3cpqWs2JWGLdhsuy0K/7PT66EUZB8z10u9lpf8x1SyVGDUx894Rl1mK+qVQ==", "license": "MIT", "dependencies": { "@microsoft/vscode-azureresources-api": "^3.0.0", diff --git a/package.json b/package.json index eb1ac81f..31233df2 100644 --- a/package.json +++ b/package.json @@ -961,7 +961,7 @@ "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@microsoft/vscode-azext-azureauth": "^5.1.1", "@microsoft/vscode-azext-azureutils": "^4.0.0", - "@microsoft/vscode-azext-utils": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.0.tgz", + "@microsoft/vscode-azext-utils": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-4.0.2.tgz", "buffer": "^6.0.3", "form-data": "^4.0.4", "fs-extra": "^11.3.0", diff --git a/src/copilot/reRunWithCopilot.ts b/src/copilot/reRunWithCopilot.ts index adfcf65d..a906adf0 100644 --- a/src/copilot/reRunWithCopilot.ts +++ b/src/copilot/reRunWithCopilot.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CopilotUserInput, executeCommandWithAddedContext, type IActionContext } from "@microsoft/vscode-azext-utils"; +import { CopilotUserInput, createSubscriptionContext, executeCommandWithAddedContext, type IActionContext } from "@microsoft/vscode-azext-utils"; import * as vscode from "vscode"; import { ActivitySelectedCache } from "../chat/askAgentAboutActivityLog/ActivitySelectedCache"; import { convertActivityTreeToSimpleObjectArray, ConvertedActivityItem } from "../chat/tools/GetAzureActivityLog/convertActivityTree"; @@ -22,10 +22,18 @@ export async function reRunWithCopilot(context: IActionContext, item: ActivityIt const activityItems: ConvertedActivityItem[] = await convertActivityTreeToSimpleObjectArray(activityContext); context.ui = new CopilotUserInput(vscode, JSON.stringify(activityItems)); + // if subscription exists then add it to the context and + let wizardContext = context + const subscription = activityItems[0].activityAttributes?.subscription + if (subscription) { + const subscriptionContext = createSubscriptionContext(subscription); + wizardContext = { ...context, ...subscriptionContext }; + } + // An item will always be passed in so we will only need to look at the first item in the array const callbackId = activityItems[0]?.callbackId; if (callbackId) { - await executeCommandWithAddedContext(callbackId, context) + await executeCommandWithAddedContext(callbackId, wizardContext, undefined, undefined, subscription) } else { throw new Error(vscode.l10n.t('Failed to rerun with Copilot. Activity item callback ID not found.')); } From 885ba92fb9d435343269223136002688b1b0ecbb Mon Sep 17 00:00:00 2001 From: Megan Mott Date: Wed, 10 Dec 2025 14:59:38 -0800 Subject: [PATCH 3/3] small change --- src/copilot/reRunWithCopilot.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/copilot/reRunWithCopilot.ts b/src/copilot/reRunWithCopilot.ts index a906adf0..cd8786d9 100644 --- a/src/copilot/reRunWithCopilot.ts +++ b/src/copilot/reRunWithCopilot.ts @@ -33,6 +33,7 @@ export async function reRunWithCopilot(context: IActionContext, item: ActivityIt // An item will always be passed in so we will only need to look at the first item in the array const callbackId = activityItems[0]?.callbackId; if (callbackId) { + // todo: change this as the subscription may not always be the third thing passed in await executeCommandWithAddedContext(callbackId, wizardContext, undefined, undefined, subscription) } else { throw new Error(vscode.l10n.t('Failed to rerun with Copilot. Activity item callback ID not found.'));