From 0570fa8a4e3a40acf9f709364ebc753fa4189576 Mon Sep 17 00:00:00 2001 From: colinmcneil Date: Wed, 21 Aug 2024 17:15:19 -0400 Subject: [PATCH] Remove all `runbook` references --- CHANGELOG.md | 2 +- LICENSE.md | 2 +- README.md | 2 +- package.json | 10 ++--- src/commands/manageSavedPrompts.ts | 8 ++-- src/commands/runHotCommand.ts | 10 ++--- src/commands/runPrompt.ts | 15 +++---- src/extension.ts | 26 ++++++------ src/test/extension.test.ts | 28 ++++++------- src/utils/lsp.ts | 4 +- src/utils/preparePrompt.ts | 41 ------------------- .../{runbookFilename.ts => promptFilename.ts} | 13 +++--- src/utils/promptPicker.ts | 33 +++------------ 13 files changed, 65 insertions(+), 129 deletions(-) delete mode 100644 src/utils/preparePrompt.ts rename src/utils/{runbookFilename.ts => promptFilename.ts} (73%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f468b946..52574c85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -All notable changes to the "make-runbook" extension will be documented in this file. +All notable changes to the "labs-ai-tools-vscode" extension will be documented in this file. Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. diff --git a/LICENSE.md b/LICENSE.md index e1f72bf8..e81222d9 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Visual Studio Code Extension for Docker Runbooks +Visual Studio Code Extension for Docker Prompts Copyright (c) Docker Inc diff --git a/README.md b/README.md index 7c9c120f..df7b1ec6 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## Getting started Docker internal users: You must be opted-out of mandatory sign-in. -1. Install latest VSIX file https://github.com/docker/labs-make-runbook/releases +1. Install latest VSIX file https://github.com/docker/labs-ai-tools-vscode/releases 2. Open your workspace 3. Execute command `>Set OpenAI API key...` and enter your OpenAI secret key. 4. Execute command `>save-prompt` and enter your prompt URL/ref. diff --git a/package.json b/package.json index 586536b4..4900a6b3 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "publisher": "docker", "repository": { "type": "git", - "url": "https://github.com/docker/docker-make-runbook.git" + "url": "https://github.com/docker/docker-labs-ai-tools-vscode.git" }, "engines": { "vscode": "^1.88.0" @@ -39,11 +39,11 @@ "title": "Run a prompt" }, { - "command": "docker.make-runbook.run-commands", - "title": "Check runbook commands" + "command": "docker.labs-ai-tools-vscode.run-commands", + "title": "Run markdown commands" }, { - "command": "docker.make-runbook.set-openai-api-key", + "command": "docker.labs-ai-tools-vscode.set-openai-api-key", "title": "Set OpenAI API key for Docker AI prompts" }, { @@ -82,4 +82,4 @@ "vscode-languageclient": "^8.1.0" }, "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" -} +} \ No newline at end of file diff --git a/src/commands/manageSavedPrompts.ts b/src/commands/manageSavedPrompts.ts index aaa17b2a..c9f9a2e0 100644 --- a/src/commands/manageSavedPrompts.ts +++ b/src/commands/manageSavedPrompts.ts @@ -10,7 +10,7 @@ export const savePrompt = async (prompt: string) => { return vscode.window.showErrorMessage("No prompt selected"); } - const promptImage = vscode.workspace.getConfiguration('docker.make-runbook').get('prompt-image') as string; + const promptImage = vscode.workspace.getConfiguration('docker.labs-ai-tools-vscode').get('prompt-image') as string; const args = [ "run", "--rm", @@ -28,12 +28,12 @@ export const savePrompt = async (prompt: string) => { } else { vscode.window.showInformationMessage(`Saved ${prompt}`); - vscode.commands.executeCommand("docker.make-runbook.generate"); + vscode.commands.executeCommand("docker.labs-ai-tools-vscode.generate"); } }; export const deletePrompt = (prompt: string) => { - const promptImage = vscode.workspace.getConfiguration('docker.make-runbook').get('prompt-image') as string; + const promptImage = vscode.workspace.getConfiguration('docker.labs-ai-tools-vscode').get('prompt-image') as string; const args = [ "run", "--rm", @@ -51,6 +51,6 @@ export const deletePrompt = (prompt: string) => { } else { vscode.window.showInformationMessage(`Deleted ${prompt}`); - vscode.commands.executeCommand("docker.make-runbook.generate"); + vscode.commands.executeCommand("docker.labs-ai-tools-vscode.generate"); } }; \ No newline at end of file diff --git a/src/commands/runHotCommand.ts b/src/commands/runHotCommand.ts index 24075b06..411648d3 100644 --- a/src/commands/runHotCommand.ts +++ b/src/commands/runHotCommand.ts @@ -12,15 +12,15 @@ const groupCommands = (blocks: (typeof workspaceCommands)[string]) => blocks.red export const runHotCommand = async () => { const quickPicks = []; if (Object.keys(workspaceCommands).length === 0) { - return vscode.window.showErrorMessage('No runbooks found in workspace'); + return vscode.window.showErrorMessage('No commands found in workspace'); } - for (const [runbookFSPath, blocks] of Object.entries(workspaceCommands)) { + for (const [promptOutFSPath, blocks] of Object.entries(workspaceCommands)) { quickPicks.push({ - label: runbookFSPath, + label: promptOutFSPath, description: ``, detail: ``, kind: vscode.QuickPickItemKind.Separator, - workspace: runbookFSPath, + workspace: promptOutFSPath, }); const groupedBlocks = groupCommands(blocks); @@ -28,7 +28,7 @@ export const runHotCommand = async () => { quickPicks.push(...Object.entries(groupedBlocks).map(([command, script]) => ({ label: command, detail: script, - workspace: runbookFSPath, + workspace: promptOutFSPath, }))); }; diff --git a/src/commands/runPrompt.ts b/src/commands/runPrompt.ts index a69ed490..96f10b78 100644 --- a/src/commands/runPrompt.ts +++ b/src/commands/runPrompt.ts @@ -1,13 +1,10 @@ import { spawnSync, } from "child_process"; -import { TextEncoder } from "util"; import * as vscode from "vscode"; -import OpenAI from 'openai'; -import { prepareProjectPrompt } from "../utils/preparePrompt"; import { verifyHasOpenAIKey } from "../extension"; import { showPromptPicker } from "../utils/promptPicker"; -import { prepareRunbookFile } from "../utils/runbookFilename"; +import { preparePromptFile } from "../utils/promptFilename"; const START_DOCKER_COMMAND = { 'win32': 'Start-Process -NoNewWindow -Wait -FilePath "C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"', @@ -17,7 +14,7 @@ const START_DOCKER_COMMAND = { const DEFAULT_USER = "local-user"; -export const generateRunbook = (secrets: vscode.SecretStorage) => vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, async progress => { +export const runPrompt = (secrets: vscode.SecretStorage) => vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, async progress => { // Coerce the error to have an exit code type DockerSpawnError = Error & { code: number }; @@ -51,7 +48,7 @@ export const generateRunbook = (secrets: vscode.SecretStorage) => vscode.window. vscode.env.openExternal(vscode.Uri.parse("https://www.docker.com/products/docker-desktop")); return; case "Try again": - return vscode.commands.executeCommand("docker.make-runbook.generate"); + return vscode.commands.executeCommand("docker.labs-ai-tools-vscode.generate"); } }); } @@ -88,7 +85,7 @@ export const generateRunbook = (secrets: vscode.SecretStorage) => vscode.window. let apiKey = await secrets.get("openAIKey"); - const { editor, doc } = (await prepareRunbookFile(workspaceFolder, promptOption.id) || {}); + const { editor, doc } = (await preparePromptFile(workspaceFolder, promptOption.id) || {}); if (!editor || !doc) { return; @@ -98,11 +95,11 @@ export const generateRunbook = (secrets: vscode.SecretStorage) => vscode.window. try { progress.report({ increment: 5, message: "Running..." }); - + // TODO: Run the prompt await doc.save(); } catch (e: unknown) { e = e as Error; - void vscode.window.showErrorMessage("Error generating runbook"); + void vscode.window.showErrorMessage("Error running prompt"); await editor.edit((edit) => { edit.insert( new vscode.Position(editor.document.lineCount, 0), diff --git a/src/extension.ts b/src/extension.ts index 99331ba4..7e30b875 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import { generateRunbook } from './commands/generateRunbook'; +import { runPrompt } from './commands/runPrompt'; import { runHotCommand } from './commands/runHotCommand'; import { setOpenAIKey } from './commands/setOpenAIKey'; @@ -15,7 +15,7 @@ export const workspaceCommands = {} as { }[] }; -export const extensionId = 'docker.make-runbook'; +export const extensionId = 'docker.labs-ai-tools-vscode'; export const packageJSON = vscode.extensions.getExtension(extensionId)?.packageJSON; @@ -32,7 +32,7 @@ export const verifyHasOpenAIKey = async (secrets: vscode.SecretStorage, didRunAu await setOpenAIKey(secrets, true); } else if (res === 'Use Ollama') { - await vscode.workspace.getConfiguration('docker.make-runbook').update('openai-base', 'Ollama'); + await vscode.workspace.getConfiguration('docker.labs-ai-tools-vscode').update('openai-base', 'Ollama'); } else { return false; @@ -43,7 +43,7 @@ export const verifyHasOpenAIKey = async (secrets: vscode.SecretStorage, didRunAu export async function activate(context: vscode.ExtensionContext) { - let setOpenAIKeyCommand = vscode.commands.registerCommand('docker.make-runbook.set-openai-api-key', () => { + let setOpenAIKeyCommand = vscode.commands.registerCommand('docker.labs-ai-tools-vscode.set-openai-api-key', () => { setOpenAIKey(context.secrets); }); @@ -51,23 +51,23 @@ export async function activate(context: vscode.ExtensionContext) { spawnSync('docker', ['pull', "vonwig/prompts:latest"]); - let makeRunbook = vscode.commands.registerCommand('docker.make-runbook.generate', () => generateRunbook(context.secrets)); + let runPromptCommand = vscode.commands.registerCommand('docker.labs-ai-tools-vscode.generate', () => runPrompt(context.secrets)); - context.subscriptions.push(makeRunbook); + context.subscriptions.push(runPromptCommand); - let runBoundCommands = vscode.commands.registerCommand('docker.make-runbook.run', runHotCommand); + let runBoundCommands = vscode.commands.registerCommand('docker.labs-ai-tools-vscode.run', runHotCommand); context.subscriptions.push(runBoundCommands); - let savePromptCommand = vscode.commands.registerCommand('docker.make-runbook.save-prompt', savePrompt); + let savePromptCommand = vscode.commands.registerCommand('docker.labs-ai-tools-vscode.save-prompt', savePrompt); context.subscriptions.push(savePromptCommand); - let deletePromptCommand = vscode.commands.registerCommand('docker.make-runbook.delete-prompt', deletePrompt); + let deletePromptCommand = vscode.commands.registerCommand('docker.labs-ai-tools-vscode.delete-prompt', deletePrompt); context.subscriptions.push(deletePromptCommand); - if (vscode.workspace.getConfiguration('docker.make-runbook').get('openai-base') === 'OpenAI') { + if (vscode.workspace.getConfiguration('docker.labs-ai-tools-vscode').get('openai-base') === 'OpenAI') { void verifyHasOpenAIKey(context.secrets); } @@ -79,13 +79,13 @@ export async function activate(context: vscode.ExtensionContext) { }) => { const blocks = args.blocks; - const runbookURI = vscode.Uri.parse(args.uri); + const PromptRespURI = vscode.Uri.parse(args.uri); - workspaceCommands[runbookURI.fsPath] = blocks; + workspaceCommands[PromptRespURI.fsPath] = blocks; }); nativeClient.onNotification("$terminal/run", async (args: { content: string }) => { - const terminal = vscode.window.createTerminal("Docker Runbook"); + const terminal = vscode.window.createTerminal("Markdown Blocks"); terminal.sendText(args.content); terminal.show(); diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 152764ed..0442431d 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -3,7 +3,7 @@ import * as assert from 'assert'; // You can import and use all API from the 'vscode' module // as well as import your extension to test it import * as vscode from 'vscode'; -import { generateFriendlyPromptName } from '../utils/runbookFilename'; +import { generateFriendlyPromptName } from '../utils/promptFilename'; import { parseGitHubRef, parseGitHubURL } from '../utils/promptPicker'; // import * as myExtension from '../../extension'; @@ -16,19 +16,19 @@ suite('Extension Test Suite', () => { }); test('generateFriendlyPromptName', () => { - assert.strictEqual(generateFriendlyPromptName("github:docker/labs-make-runbook?ref=main&path=prompts/git_smoosh"), "gh-docker-labs-make-runbook-prompts-git_smoosh"); + assert.strictEqual(generateFriendlyPromptName("github:docker/labs-ai-tools-vscode?ref=main&path=prompts/git_smoosh"), "gh-docker-labs-ai-tools-vscode-prompts-git_smoosh"); assert.strictEqual(generateFriendlyPromptName("npm"), "npm"); }); test('parseRefs', () => { const urls = [ - "https://github.com/docker/labs-make-runbook/tree/main/prompts/docker", - "https://github.com/docker/labs-make-runbook/tree/main/prompts/npm_setup", + "https://github.com/docker/labs-ai-tools-vscode/tree/main/prompts/docker", + "https://github.com/docker/labs-ai-tools-vscode/tree/main/prompts/npm_setup", ]; const refs = [ - "github:docker/labs-make-runbook?ref=main&path=prompts/docker", - "github:docker/labs-make-runbook?ref=main&path=prompts/npm_setup", + "github:docker/labs-ai-tools-vscode?ref=main&path=prompts/docker", + "github:docker/labs-ai-tools-vscode?ref=main&path=prompts/npm_setup", ]; urls.forEach((url, i) => { @@ -36,7 +36,7 @@ suite('Extension Test Suite', () => { const parsed = parseGitHubURL(url)!; assert.notStrictEqual(parsed, undefined); assert.strictEqual(parsed.owner, "docker"); - assert.strictEqual(parsed.repo, "labs-make-runbook"); + assert.strictEqual(parsed.repo, "labs-ai-tools-vscode"); assert.strictEqual(parsed.ref, "main"); assert.strictEqual(parsed.args.path.length > 0, true); assert.strictEqual(parsed.toRef(), ref); @@ -47,7 +47,7 @@ suite('Extension Test Suite', () => { const parsed = parseGitHubRef(ref)!; assert.notStrictEqual(parsed, undefined); assert.strictEqual(parsed.owner, "docker"); - assert.strictEqual(parsed.repo, "labs-make-runbook"); + assert.strictEqual(parsed.repo, "labs-ai-tools-vscode"); assert.strictEqual(parsed.ref, "main"); assert.strictEqual(parsed.args.path.length > 0, true); assert.strictEqual(parsed.toURL(), url); @@ -56,15 +56,15 @@ suite('Extension Test Suite', () => { test('refToRefString', () => { const urls = [ - "https://github.com/docker/labs-make-runbook/tree/main/prompts/docker", - "https://github.com/docker/labs-make-runbook/tree/main/prompts/npm_setup", - "https://github.com/docker/labs-make-runbook/tree/main/", + "https://github.com/docker/labs-ai-tools-vscode/tree/main/prompts/docker", + "https://github.com/docker/labs-ai-tools-vscode/tree/main/prompts/npm_setup", + "https://github.com/docker/labs-ai-tools-vscode/tree/main/", ]; const refs = [ - "github:docker/labs-make-runbook?ref=main&path=prompts/docker", - "github:docker/labs-make-runbook?ref=main&path=prompts/npm_setup", - "github:docker/labs-make-runbook?ref=main", + "github:docker/labs-ai-tools-vscode?ref=main&path=prompts/docker", + "github:docker/labs-ai-tools-vscode?ref=main&path=prompts/npm_setup", + "github:docker/labs-ai-tools-vscode?ref=main", ]; urls.forEach((url, i) => { diff --git a/src/utils/lsp.ts b/src/utils/lsp.ts index ab7d9b4d..7331f6a1 100644 --- a/src/utils/lsp.ts +++ b/src/utils/lsp.ts @@ -23,12 +23,12 @@ const dockerrunner = { "-l", 'com.docker.lsp=true', "-l", - 'com.docker.lsp.extension=labs-make-runbook', + 'com.docker.lsp.extension=labs-ai-tools-vscode', "docker/lsp", "--workspace", "/docker", "--profile", - "labs-make-runbook", + "labs-ai-tools-vscode", ], }; diff --git a/src/utils/preparePrompt.ts b/src/utils/preparePrompt.ts deleted file mode 100644 index 4c13bf7f..00000000 --- a/src/utils/preparePrompt.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { spawnSync } from "child_process"; -import * as vscode from "vscode"; - -type PromptTypes = [{ title: string, type: string; saved: boolean }]; - -export const getPromptTypes = function (): PromptTypes { - // github:docker/labs-make-runbook?ref=main&path=prompts/git_smoosh - const promptImage = vscode.workspace.getConfiguration('docker.make-runbook').get('prompt-image') as string; - if (promptImage === "vonwig/prompts" || promptImage === "vonwig/prompts:latest") { - spawnSync('docker', ['pull', "vonwig/prompts"]); - } - const result = spawnSync('docker', ['run', "--mount", "type=volume,source=docker-prompts,target=/prompts", promptImage, "prompts"]); - try { - return JSON.parse(result.stdout.toString()); - } - catch (e) { - throw new Error(`Expected JSON from ${promptImage}, got STDOUT: ${result.stdout.toString()} STDERR: ${result.stderr.toString()} ERR: ${(result.error || "N/A").toString()}`); - } - -}; - -export const prepareProjectPrompt = (projectRoot: vscode.WorkspaceFolder, promptType: string) => { - - const platform = process.platform; - - const promptImage = vscode.workspace.getConfiguration('docker.make-runbook').get('prompt-image') as string; - - const promptImageArgs = ['run', '--rm', "-v", "/var/run/docker.sock:/var/run/docker.sock", "--mount", "type=volume,source=docker-prompts,target=/prompts", promptImage, projectRoot.uri.fsPath, vscode.env.machineId, platform, promptType]; - - const result = spawnSync('docker', promptImageArgs); - - if (result.error) { - throw result.error; - } - try { - return JSON.parse(result.stdout.toString()); - } - catch (e) { - throw new Error(`Expected JSON from ${promptImage}, got STDOUT: ${result.stdout.toString()} STDERR: ${result.stderr.toString()} ERR: ${(result.error || "N/A").toString()}`); - } -}; diff --git a/src/utils/runbookFilename.ts b/src/utils/promptFilename.ts similarity index 73% rename from src/utils/runbookFilename.ts rename to src/utils/promptFilename.ts index 3775237e..323e12f7 100644 --- a/src/utils/runbookFilename.ts +++ b/src/utils/promptFilename.ts @@ -12,7 +12,7 @@ export const generateFriendlyPromptName = (promptType: string) => { return friendlyPromptName; }; -export const prepareRunbookFile = async (workspaceFolder: vscode.WorkspaceFolder, promptType: string) => { +export const preparePromptFile = async (workspaceFolder: vscode.WorkspaceFolder, promptType: string) => { const friendlyPromptName = generateFriendlyPromptName(promptType); @@ -22,22 +22,25 @@ export const prepareRunbookFile = async (workspaceFolder: vscode.WorkspaceFolder try { await vscode.workspace.fs.stat(uri); - const option = await vscode.window.showQuickPick([{ label: "Do nothing" }, { label: "Overwrite", detail: `Will delete ${uri.fsPath}` }], { - title: "Runbook already exists", + const option = await vscode.window.showQuickPick([{ label: "Append" }, { label: "Overwrite", detail: `Will delete ${uri.fsPath}` }, { label: "Cancel" }], { + title: "Output for this prompt already exists", ignoreFocusOut: true, }); - if (!option || option.label === "Do nothing") { + if (!option || option.label === "Cancel") { return; } if (option.label === "Overwrite") { await vscode.workspace.fs.delete(uri); } + else { + await vscode.workspace.fs.writeFile(uri, new TextEncoder().encode("")); + } } catch (e) { // File does not exist } - await vscode.workspace.fs.writeFile(uri, new TextEncoder().encode("")); + const doc = await vscode.workspace.openTextDocument(uri); diff --git a/src/utils/promptPicker.ts b/src/utils/promptPicker.ts index 01dcd438..6de9cb5c 100644 --- a/src/utils/promptPicker.ts +++ b/src/utils/promptPicker.ts @@ -1,8 +1,7 @@ import { QuickPickItem, QuickPickItemKind, ThemeIcon, commands, window, workspace } from "vscode"; -import { getPromptTypes } from "./preparePrompt"; // https://github.com/owner/repo/tree/ref/path -// https://github.com/docker/labs-make-runbook/tree/main/prompts/docker +// https://github.com/docker/labs-ai-tools-vscode/tree/main/prompts/docker const GitHubURLPattern = /https:\/\/github.com\/(.*)\/(.*)\/tree\/(.*)/; // github:owner/repo?ref=main&path=prompts/dir const GitHubRefPattern = /github:(.*)\/(.*)\?ref=(.*)/; @@ -80,22 +79,6 @@ export interface PromptTypeOption extends QuickPickItem { export const showPromptPicker = (skipBuiltins = false) => new Promise((resolve) => { let promptTypeItems: PromptTypeOption[] = []; - if (!skipBuiltins) { - const promptTypes = getPromptTypes(); - promptTypeItems = promptTypes.map(f => ( - { - label: f.title, - detail: `Generate runbook to use ${f.type} in this project`, - id: f.type, - description: "Built-in", - buttons: f.saved ? [{ - iconPath: new ThemeIcon('trash'), - tooltip: 'Delete saved command' - }] : undefined, - saved: f.saved - } - )); - } const getDefaultItems = () => { const defaultItems = [ { @@ -104,12 +87,6 @@ export const showPromptPicker = (skipBuiltins = false) => id: "separator" } as PromptTypeOption, ...promptTypeItems.filter(i => i.saved), - { - kind: QuickPickItemKind.Separator, - label: "Built-In", - id: "separator" - } as PromptTypeOption, - ...promptTypeItems.filter(i => !i.saved) ]; return defaultItems; @@ -117,7 +94,7 @@ export const showPromptPicker = (skipBuiltins = false) => const quickPick = window.createQuickPick(); quickPick.items = getDefaultItems(); - quickPick.title = "Select runbook type"; + quickPick.title = "Select prompt"; quickPick.ignoreFocusOut = true; quickPick.onDidChangeValue((val) => { const githubRefMatch = val.match(GitHubRefPattern); @@ -137,7 +114,7 @@ export const showPromptPicker = (skipBuiltins = false) => }] }]; } - //https://github.com/docker/labs-make-runbook/tree/main/prompts/npm_setup + //https://github.com/docker/labs-ai-tools-vscode/tree/main/prompts/npm_setup else if (githubURLMatch) { const ref = parseGitHubURL(val)!; quickPick.items = [{ @@ -178,11 +155,11 @@ export const showPromptPicker = (skipBuiltins = false) => quickPick.onDidTriggerItemButton(async ({ item }) => { if (item.id) { if (item.saved) { - await commands.executeCommand("docker.make-runbook.delete-prompt", item.id); + await commands.executeCommand("docker.labs-ai-tools-vscode.delete-prompt", item.id); quickPick.items = getDefaultItems(); } else { - await commands.executeCommand("docker.make-runbook.save-prompt", item.id); + await commands.executeCommand("docker.labs-ai-tools-vscode.save-prompt", item.id); quickPick.items = getDefaultItems(); }