Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
"ignorePatterns": ["out", "dist", "**/*.d.ts", "!roo-code.d.ts"]
}
4 changes: 2 additions & 2 deletions e2e/VSCODE_INTEGRATION_TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClineAPI>
var extension: vscode.Extension<RooCodeAPI>
var panel: vscode.WebviewPanel
}
```
Expand Down
6 changes: 3 additions & 3 deletions e2e/src/suite/index.ts
Original file line number Diff line number Diff line change
@@ -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<ClineAPI> | undefined
var extension: vscode.Extension<RooCodeAPI> | undefined
var panel: vscode.WebviewPanel | undefined
}

Expand Down
2 changes: 1 addition & 1 deletion e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
22 changes: 9 additions & 13 deletions src/exports/index.ts → src/activate/createRooCodeAPI.ts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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)`,
)
Expand All @@ -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",
Expand All @@ -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
}
1 change: 1 addition & 0 deletions src/activate/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { handleUri } from "./handleUri"
export { registerCommands } from "./registerCommands"
export { registerCodeActions } from "./registerCodeActions"
export { createRooCodeAPI } from "./createRooCodeAPI"
72 changes: 34 additions & 38 deletions src/exports/README.md
Original file line number Diff line number Diff line change
@@ -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<ClineAPI>("rooveterinaryinc.roo-cline")
```typescript
const extension = vscode.extensions.getExtension<RooCodeAPI>("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.
68 changes: 55 additions & 13 deletions src/exports/cline.d.ts → src/exports/roo-code.d.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<string, unknown>
}

export interface ClineProvider {
Expand Down Expand Up @@ -82,11 +135,6 @@ export interface ClineProvider {
*/
cancelTask(): Promise<void>

/**
* Clears the current task
*/
clearTask(): Promise<void>

/**
* Gets the current state
*/
Expand All @@ -112,12 +160,6 @@ export interface ClineProvider {
*/
storeSecret(key: SecretKey, value?: string): Promise<void>

/**
* Retrieves a secret value from secure storage
* @param key The key of the secret to retrieve
*/
getSecret(key: SecretKey): Promise<string | undefined>

/**
* Resets the state
*/
Expand Down
5 changes: 2 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Loading
Loading