diff --git a/.eslintrc.json b/.eslintrc.json index bae7854a6ea..e967b58a03f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -19,5 +19,5 @@ "no-throw-literal": "warn", "semi": "off" }, - "ignorePatterns": ["out", "dist", "**/*.d.ts"] + "ignorePatterns": ["out", "dist", "**/*.d.ts", "!roo-code.d.ts"] } diff --git a/e2e/VSCODE_INTEGRATION_TESTS.md b/e2e/VSCODE_INTEGRATION_TESTS.md index 25f54492de0..a36b2403811 100644 --- a/e2e/VSCODE_INTEGRATION_TESTS.md +++ b/e2e/VSCODE_INTEGRATION_TESTS.md @@ -58,9 +58,9 @@ The following global objects are available in tests: ```typescript declare global { - var api: ClineAPI + var api: RooCodeAPI var provider: ClineProvider - var extension: vscode.Extension + var extension: vscode.Extension var panel: vscode.WebviewPanel } ``` diff --git a/e2e/src/suite/index.ts b/e2e/src/suite/index.ts index a9540d96004..19e00aa40c2 100644 --- a/e2e/src/suite/index.ts +++ b/e2e/src/suite/index.ts @@ -1,13 +1,13 @@ import * as path from "path" import Mocha from "mocha" import { glob } from "glob" -import { ClineAPI, ClineProvider } from "../../../src/exports/cline" +import { RooCodeAPI, ClineProvider } from "../../../src/exports/roo-code" import * as vscode from "vscode" declare global { - var api: ClineAPI + var api: RooCodeAPI var provider: ClineProvider - var extension: vscode.Extension | undefined + var extension: vscode.Extension | undefined var panel: vscode.WebviewPanel | undefined } diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json index 792acb14a0d..4439b32b39b 100644 --- a/e2e/tsconfig.json +++ b/e2e/tsconfig.json @@ -11,6 +11,6 @@ "useUnknownInCatchVariables": false, "outDir": "out" }, - "include": ["src", "../src/exports/cline.d.ts"], + "include": ["src", "../src/exports/roo-code.d.ts"], "exclude": [".vscode-test", "**/node_modules/**", "out"] } diff --git a/src/exports/index.ts b/src/activate/createRooCodeAPI.ts similarity index 79% rename from src/exports/index.ts rename to src/activate/createRooCodeAPI.ts index e4b17da4844..18c696a8fde 100644 --- a/src/exports/index.ts +++ b/src/activate/createRooCodeAPI.ts @@ -1,9 +1,11 @@ import * as vscode from "vscode" + import { ClineProvider } from "../core/webview/ClineProvider" -import { ClineAPI } from "./cline" -export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvider: ClineProvider): ClineAPI { - const api: ClineAPI = { +import { RooCodeAPI } from "../exports/roo-code" + +export function createRooCodeAPI(outputChannel: vscode.OutputChannel, sidebarProvider: ClineProvider): RooCodeAPI { + return { setCustomInstructions: async (value: string) => { await sidebarProvider.updateCustomInstructions(value) outputChannel.appendLine("Custom instructions set") @@ -24,6 +26,7 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi text: task, images: images, }) + outputChannel.appendLine( `Task started with message: ${task ? `"${task}"` : "undefined"} and ${images?.length || 0} image(s)`, ) @@ -33,6 +36,7 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi outputChannel.appendLine( `Sending message: ${message ? `"${message}"` : "undefined"} with ${images?.length || 0} image(s)`, ) + await sidebarProvider.postMessageToWebview({ type: "invoke", invoke: "sendMessage", @@ -43,22 +47,14 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi pressPrimaryButton: async () => { outputChannel.appendLine("Pressing primary button") - await sidebarProvider.postMessageToWebview({ - type: "invoke", - invoke: "primaryButtonClick", - }) + await sidebarProvider.postMessageToWebview({ type: "invoke", invoke: "primaryButtonClick" }) }, pressSecondaryButton: async () => { outputChannel.appendLine("Pressing secondary button") - await sidebarProvider.postMessageToWebview({ - type: "invoke", - invoke: "secondaryButtonClick", - }) + await sidebarProvider.postMessageToWebview({ type: "invoke", invoke: "secondaryButtonClick" }) }, sidebarProvider: sidebarProvider, } - - return api } diff --git a/src/activate/index.ts b/src/activate/index.ts index 76eebd185e5..8b3d91cdcbb 100644 --- a/src/activate/index.ts +++ b/src/activate/index.ts @@ -1,3 +1,4 @@ export { handleUri } from "./handleUri" export { registerCommands } from "./registerCommands" export { registerCodeActions } from "./registerCodeActions" +export { createRooCodeAPI } from "./createRooCodeAPI" diff --git a/src/exports/README.md b/src/exports/README.md index 03b8983b7ed..0554580836c 100644 --- a/src/exports/README.md +++ b/src/exports/README.md @@ -1,55 +1,51 @@ -# Cline API +# Roo Code API -The Cline extension exposes an API that can be used by other extensions. To use this API in your extension: +The Roo Code extension exposes an API that can be used by other extensions. To use this API in your extension: -1. Copy `src/extension-api/cline.d.ts` to your extension's source directory. -2. Include `cline.d.ts` in your extension's compilation. +1. Copy `src/extension-api/roo-code.d.ts` to your extension's source directory. +2. Include `roo-code.d.ts` in your extension's compilation. 3. Get access to the API with the following code: - ```ts - const clineExtension = vscode.extensions.getExtension("rooveterinaryinc.roo-cline") +```typescript +const extension = vscode.extensions.getExtension("rooveterinaryinc.roo-cline") - if (!clineExtension?.isActive) { - throw new Error("Cline extension is not activated") - } +if (!extension?.isActive) { + throw new Error("Extension is not activated") +} - const cline = clineExtension.exports +const api = extension.exports - if (cline) { - // Now you can use the API +if (!api) { + throw new Error("API is not available") +} - // Set custom instructions - await cline.setCustomInstructions("Talk like a pirate") +// Set custom instructions. +await api.setCustomInstructions("Talk like a pirate") - // Get custom instructions - const instructions = await cline.getCustomInstructions() - console.log("Current custom instructions:", instructions) +// Get custom instructions. +const instructions = await api.getCustomInstructions() +console.log("Current custom instructions:", instructions) - // Start a new task with an initial message - await cline.startNewTask("Hello, Cline! Let's make a new project...") +// Start a new task with an initial message. +await api.startNewTask("Hello, Roo Code API! Let's make a new project...") - // Start a new task with an initial message and images - await cline.startNewTask("Use this design language", ["data:image/webp;base64,..."]) +// Start a new task with an initial message and images. +await api.startNewTask("Use this design language", ["data:image/webp;base64,..."]) - // Send a message to the current task - await cline.sendMessage("Can you fix the @problems?") +// Send a message to the current task. +await api.sendMessage("Can you fix the @problems?") - // Simulate pressing the primary button in the chat interface (e.g. 'Save' or 'Proceed While Running') - await cline.pressPrimaryButton() +// Simulate pressing the primary button in the chat interface (e.g. 'Save' or 'Proceed While Running'). +await api.pressPrimaryButton() - // Simulate pressing the secondary button in the chat interface (e.g. 'Reject') - await cline.pressSecondaryButton() - } else { - console.error("Cline API is not available") - } - ``` +// Simulate pressing the secondary button in the chat interface (e.g. 'Reject'). +await api.pressSecondaryButton() +``` - **Note:** To ensure that the `rooveterinaryinc.roo-cline` extension is activated before your extension, add it to the `extensionDependencies` in your `package.json`: +**NOTE:** To ensure that the `rooveterinaryinc.roo-cline` extension is activated before your extension, add it to the `extensionDependencies` in your `package.json`: - ```json - "extensionDependencies": [ - "rooveterinaryinc.roo-cline" - ] - ``` +```json +"extensionDependencies": ["rooveterinaryinc.roo-cline"] +``` -For detailed information on the available methods and their usage, refer to the `cline.d.ts` file. +For detailed information on the available methods and their usage, refer to the `roo-code.d.ts` file. diff --git a/src/exports/cline.d.ts b/src/exports/roo-code.d.ts similarity index 73% rename from src/exports/cline.d.ts rename to src/exports/roo-code.d.ts index e529947b6b4..2004b31e8ba 100644 --- a/src/exports/cline.d.ts +++ b/src/exports/roo-code.d.ts @@ -1,4 +1,4 @@ -export interface ClineAPI { +export interface RooCodeAPI { /** * Sets the custom instructions in the global storage. * @param value The custom instructions to be saved. @@ -38,7 +38,60 @@ export interface ClineAPI { /** * The sidebar provider instance. */ - sidebarProvider: ClineSidebarProvider + sidebarProvider: ClineProvider +} + +export type ClineAsk = + | "followup" + | "command" + | "command_output" + | "completion_result" + | "tool" + | "api_req_failed" + | "resume_task" + | "resume_completed_task" + | "mistake_limit_reached" + | "browser_action_launch" + | "use_mcp_server" + | "finishTask" + +export type ClineSay = + | "task" + | "error" + | "api_req_started" + | "api_req_finished" + | "api_req_retried" + | "api_req_retry_delayed" + | "api_req_deleted" + | "text" + | "reasoning" + | "completion_result" + | "user_feedback" + | "user_feedback_diff" + | "command_output" + | "tool" + | "shell_integration_warning" + | "browser_action" + | "browser_action_result" + | "command" + | "mcp_server_request_started" + | "mcp_server_response" + | "new_task_started" + | "new_task" + | "checkpoint_saved" + | "rooignore_error" + +export interface ClineMessage { + ts: number + type: "ask" | "say" + ask?: ClineAsk + say?: ClineSay + text?: string + images?: string[] + partial?: boolean + reasoning?: string + conversationHistoryIndex?: number + checkpoint?: Record } export interface ClineProvider { @@ -82,11 +135,6 @@ export interface ClineProvider { */ cancelTask(): Promise - /** - * Clears the current task - */ - clearTask(): Promise - /** * Gets the current state */ @@ -112,12 +160,6 @@ export interface ClineProvider { */ storeSecret(key: SecretKey, value?: string): Promise - /** - * Retrieves a secret value from secure storage - * @param key The key of the secret to retrieve - */ - getSecret(key: SecretKey): Promise - /** * Resets the state */ diff --git a/src/extension.ts b/src/extension.ts index c85d61053f9..e3f99779999 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -13,14 +13,13 @@ try { import "./utils/path" // Necessary to have access to String.prototype.toPosix. -import { createClineAPI } from "./exports" import { ClineProvider } from "./core/webview/ClineProvider" import { CodeActionProvider } from "./core/CodeActionProvider" import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider" import { McpServerManager } from "./services/mcp/McpServerManager" import { telemetryService } from "./services/telemetry/TelemetryService" -import { handleUri, registerCommands, registerCodeActions } from "./activate" +import { handleUri, registerCommands, registerCodeActions, createRooCodeAPI } from "./activate" /** * Built using https://github.com/microsoft/vscode-webview-ui-toolkit @@ -99,7 +98,7 @@ export function activate(context: vscode.ExtensionContext) { registerCodeActions(context) - return createClineAPI(outputChannel, sidebarProvider) + return createRooCodeAPI(outputChannel, sidebarProvider) } // This method is called when your extension is deactivated. diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 6cc176d6bd1..33c485adffd 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -1,5 +1,3 @@ -// type that represents json data that is sent from extension to webview, called ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or 'settingsButtonClicked' or 'hello' - import { ApiConfiguration, ApiProvider, ModelInfo } from "./api" import { HistoryItem } from "./HistoryItem" import { McpServer } from "./mcp" @@ -9,6 +7,7 @@ import { CustomSupportPrompts } from "./support-prompt" import { ExperimentId } from "./experiments" import { CheckpointStorage } from "./checkpoints" import { TelemetrySetting } from "./TelemetrySetting" +import { ClineMessage, ClineAsk, ClineSay } from "../exports/roo-code" export interface LanguageModelChatSelector { vendor?: string @@ -17,7 +16,9 @@ export interface LanguageModelChatSelector { id?: string } -// webview will hold state +// Represents JSON data that is sent from extension to webview, called +// ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or +// 'settingsButtonClicked' or 'hello'. Webview will hold state. export interface ExtensionMessage { type: | "action" @@ -151,58 +152,7 @@ export interface ExtensionState { showRooIgnoredFiles: boolean // Whether to show .rooignore'd files in listings } -export interface ClineMessage { - ts: number - type: "ask" | "say" - ask?: ClineAsk - say?: ClineSay - text?: string - images?: string[] - partial?: boolean - reasoning?: string - conversationHistoryIndex?: number - checkpoint?: Record -} - -export type ClineAsk = - | "followup" - | "command" - | "command_output" - | "completion_result" - | "tool" - | "api_req_failed" - | "resume_task" - | "resume_completed_task" - | "mistake_limit_reached" - | "browser_action_launch" - | "use_mcp_server" - | "finishTask" - -export type ClineSay = - | "task" - | "error" - | "api_req_started" - | "api_req_finished" - | "api_req_retried" - | "api_req_retry_delayed" - | "api_req_deleted" - | "text" - | "reasoning" - | "completion_result" - | "user_feedback" - | "user_feedback_diff" - | "command_output" - | "tool" - | "shell_integration_warning" - | "browser_action" - | "browser_action_result" - | "command" - | "mcp_server_request_started" - | "mcp_server_response" - | "new_task_started" - | "new_task" - | "checkpoint_saved" - | "rooignore_error" +export type { ClineMessage, ClineAsk, ClineSay } export interface ClineSayTool { tool: @@ -226,8 +176,9 @@ export interface ClineSayTool { reason?: string } -// must keep in sync with system prompt +// Must keep in sync with system prompt. export const browserActions = ["launch", "click", "type", "scroll_down", "scroll_up", "close"] as const + export type BrowserAction = (typeof browserActions)[number] export interface ClineSayBrowserAction { @@ -262,7 +213,6 @@ export interface ClineApiReqInfo { streamingFailedMessage?: string } -// Human relay related message types export interface ShowHumanRelayDialogMessage { type: "showHumanRelayDialog" requestId: string