Skip to content

Commit fe820e6

Browse files
committed
Data Engineer mode (rebased on 3.9.2)
1 parent c7562a6 commit fe820e6

29 files changed

+1816
-5
lines changed

src/core/Cline.ts

Lines changed: 415 additions & 0 deletions
Large diffs are not rendered by default.

src/core/assistant-message/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export const toolUseNames = [
2525
"attempt_completion",
2626
"switch_mode",
2727
"new_task",
28+
"notebook_read",
29+
"notebook_edit",
30+
"notebook_execute",
2831
] as const
2932

3033
// Converts array of tool call names into a union type ("execute_command" | "read_file" | ...)
@@ -58,6 +61,12 @@ export const toolParamNames = [
5861
"message",
5962
"cwd",
6063
"follow_up",
64+
"cell_index",
65+
"cell_type",
66+
"cell_content",
67+
"language_id",
68+
"start_index",
69+
"end_index",
6170
] as const
6271

6372
export type ToolParamName = (typeof toolParamNames)[number]
@@ -140,3 +149,23 @@ export interface NewTaskToolUse extends ToolUse {
140149
name: "new_task"
141150
params: Partial<Pick<Record<ToolParamName, string>, "mode" | "message">>
142151
}
152+
153+
export interface NotebookReadToolUse extends ToolUse {
154+
name: "notebook_read"
155+
params: Partial<Pick<Record<ToolParamName, string>, "action">>
156+
}
157+
158+
export interface NotebookEditToolUse extends ToolUse {
159+
name: "notebook_edit"
160+
params: Partial<
161+
Pick<
162+
Record<ToolParamName, string>,
163+
"action" | "cell_index" | "start_index" | "end_index" | "cell_content" | "cell_type" | "language_id"
164+
>
165+
>
166+
}
167+
168+
export interface NotebookExecuteToolUse extends ToolUse {
169+
name: "notebook_execute"
170+
params: Partial<Pick<Record<ToolParamName, string>, "action" | "start_index" | "end_index">>
171+
}

src/core/prompts/tools/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { getUseMcpToolDescription } from "./use-mcp-tool"
1313
import { getAccessMcpResourceDescription } from "./access-mcp-resource"
1414
import { getSwitchModeDescription } from "./switch-mode"
1515
import { getNewTaskDescription } from "./new-task"
16+
import { getNotebookReadToolDescription } from "./notebook-read"
17+
import { getNotebookEditToolDescription } from "./notebook-edit"
18+
import { getNotebookExecuteToolDescription } from "./notebook-execute"
1619
import { DiffStrategy } from "../../diff/DiffStrategy"
1720
import { McpHub } from "../../../services/mcp/McpHub"
1821
import { Mode, ModeConfig, getModeConfig, isToolAllowedForMode, getGroupName } from "../../../shared/modes"
@@ -36,6 +39,9 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined>
3639
new_task: (args) => getNewTaskDescription(args),
3740
insert_content: (args) => getInsertContentDescription(args),
3841
search_and_replace: (args) => getSearchAndReplaceDescription(args),
42+
notebook_read: (args) => getNotebookReadToolDescription(args),
43+
notebook_edit: (args) => getNotebookEditToolDescription(args),
44+
notebook_execute: (args) => getNotebookExecuteToolDescription(args),
3945
apply_diff: (args) =>
4046
args.diffStrategy ? args.diffStrategy.getToolDescription({ cwd: args.cwd, toolOptions: args.toolOptions }) : "",
4147
}
@@ -109,4 +115,7 @@ export {
109115
getSwitchModeDescription,
110116
getInsertContentDescription,
111117
getSearchAndReplaceDescription,
118+
getNotebookReadToolDescription,
119+
getNotebookEditToolDescription,
120+
getNotebookExecuteToolDescription,
112121
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { ToolArgs } from "./types"
2+
3+
export function getNotebookEditToolDescription(args: ToolArgs): string {
4+
return `## notebook_edit
5+
Description: Edit the active notebook in the editor. This tool allows you to insert new cells or replace existing cells. Note that new/modified code cells will be executed immediately, by default, unless the <noexec/> parameter presents.
6+
Parameters:
7+
- action: (required) The action to perform. Valid values are:
8+
- "insert_cells": Insert a new cell into the notebook
9+
- "modify_cell_content": Modify the content of an existing cell in the notebook (note: this will clear any existing outputs)
10+
- "replace_cells": Replace a range of cells with a new cell (note: this will clear any existing outputs)
11+
- cell_index: (required for modify_cell_content, optional for insert_cells) The index of the cell to modify (0-based), or for insert_cells the position to insert at (defaults to end of notebook)
12+
- start_index: (required for replace_cells) The starting index of the range to replace (0-based, inclusive)
13+
- end_index: (required for replace_cells) The ending index of the range to replace (0-based, exclusive)
14+
- cell_type: (optional for insert_cells and replace_cells) The type of cell, either "code" or "markdown"
15+
- language_id: (optional for insert_cells and replace_cells) The language of the cell (e.g., "python", "javascript")
16+
- cell_content: (required for all actions) The content of the cell
17+
- noexec: (optional) Can be used as a flag <noexec/> or with explicit value <noexec>true</noexec> to prevent automatic execution of new/modified code cells.
18+
Usage:
19+
<notebook_edit>
20+
<action>action name here</action>
21+
<cell_index>index value here (if required)</cell_index>
22+
<start_index>start index here (if required)</start_index>
23+
<end_index>end index here (if required)</end_index>
24+
<cell_type>cell type here (if required)</cell_type>
25+
<language_id>language here (if required)</language_id>
26+
<cell_content>cell content here</cell_content>
27+
<noexec/>
28+
</notebook_edit>
29+
30+
Example 1: Insert a new Python code cell
31+
<notebook_edit>
32+
<action>insert_cells</action>
33+
<cell_index>0</cell_index>
34+
<cell_type>code</cell_type>
35+
<language_id>python</language_id>
36+
<cell_content>import pandas as pd
37+
import numpy as np
38+
df = pd.read_csv('data.csv')
39+
df.head()</cell_content>
40+
</notebook_edit>
41+
42+
Example 2: Insert a new markdown cell
43+
<notebook_edit>
44+
<action>insert_cells</action>
45+
<cell_type>markdown</cell_type>
46+
<cell_content># Data Analysis
47+
This notebook contains the analysis of our dataset with the following steps:
48+
1. Data loading and cleaning
49+
2. Exploratory data analysis
50+
3. Statistical testing
51+
4. Visualization</cell_content>
52+
</notebook_edit>
53+
54+
Example 3: Modify an existing cell without execution
55+
<notebook_edit>
56+
<action>modify_cell_content</action>
57+
<cell_index>2</cell_index>
58+
<noexec/>
59+
<cell_content>import matplotlib.pyplot as plt
60+
plt.figure(figsize=(10, 6))
61+
plt.plot(df['x'], df['y'])
62+
plt.title('Data Visualization')
63+
plt.xlabel('X Axis')
64+
plt.ylabel('Y Axis')
65+
plt.show()</cell_content>
66+
</notebook_edit>
67+
68+
Example 4: Replace a range of cells with a new cell
69+
<notebook_edit>
70+
<action>replace_cells</action>
71+
<start_index>2</start_index>
72+
<end_index>4</end_index>
73+
<cell_type>code</cell_type>
74+
<language_id>python</language_id>
75+
<cell_content>import matplotlib.pyplot as plt
76+
import seaborn as sns
77+
78+
plt.figure(figsize=(10, 6))
79+
sns.scatterplot(x='x', y='y', data=df)
80+
plt.title('Scatter Plot')
81+
plt.show()</cell_content>
82+
</notebook_edit>
83+
84+
IMPORTANT: For insert_cells and replace_cells, each cell_content tag creates a new cell. The cell_type and language_id tags must come BEFORE the cell_content tag they apply to. The last cell_type before a cell_content will be used as that cell's type, and the last language_id before a cell_content will be used as that cell's language.`
85+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ToolArgs } from "./types"
2+
3+
export function getNotebookExecuteToolDescription(args: ToolArgs): string {
4+
return `## notebook_execute
5+
Description: Execute cells in the active notebook.
6+
Parameters:
7+
- action: (required) The action to perform. Currently only "execute_cells" is supported.
8+
- start_index: (required) The starting index of the range to execute (0-based, inclusive). Must be a valid cell index in the notebook.
9+
- end_index: (required) The ending index of the range to execute (0-based, exclusive). Must be a valid cell index in the notebook and >= start_index.
10+
11+
Usage:
12+
<notebook_execute>
13+
<action>execute_cells</action>
14+
<start_index>start index value here</start_index>
15+
<end_index>end index value here</end_index>
16+
</notebook_execute>
17+
18+
Example: Execute cells from index 3 through 5 (inclusive)
19+
<notebook_execute>
20+
<action>execute_cells</action>
21+
<start_index>3</start_index>
22+
<end_index>6</end_index>
23+
</notebook_execute>
24+
25+
Notes:
26+
- The execution is initiated immediately, but completion time depends on the cells' content
27+
- The tool will wait for execution to complete and return the results
28+
- Results include both the cell content and any outputs produced by execution
29+
- Execution will timeout if it takes too long, and a timeout message will be included in the response
30+
- Cell outputs are truncated if they exceed the configured size limit
31+
- To execute a single cell, set end_index to start_index + 1`
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ToolArgs } from "./types"
2+
3+
export function getNotebookReadToolDescription(args: ToolArgs): string {
4+
return `## notebook_read
5+
Description: Retrieve information about the active notebook in the editor.
6+
Parameters:
7+
- action: (required) The action to perform. Valid values are:
8+
- "get_info": Get comprehensive information about the active notebook, including URI, kernel info, and cell statistics
9+
- "get_cells": Get the cells of the active notebook. Returns detailed information about each cell, including content and outputs
10+
11+
Usage:
12+
<notebook_read>
13+
<action>action name here</action>
14+
</notebook_read>
15+
16+
Example 1: Get comprehensive notebook information
17+
<notebook_read>
18+
<action>get_info</action>
19+
</notebook_read>
20+
21+
Example 2: Get the cells of the active notebook
22+
<notebook_read>
23+
<action>get_cells</action>
24+
</notebook_read>
25+
26+
Notes:
27+
- The "get_info" action provides a comprehensive overview including URI, kernel info, and statistics about cell types and languages
28+
- If no active notebook is found, "get_info" will return a message stating "No active notebook found"
29+
- The "get_cells" action provides a formatted analysis of all cells, including their content and outputs
30+
- If no active notebook is found, "get_cells" will return an error message
31+
- Cell content and outputs are truncated if they exceed the configured size limit
32+
- For code cells, both the source code and execution outputs are included`
33+
}

src/core/webview/ClineProvider.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,26 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
20202020
await this.postStateToWebview()
20212021
break
20222022
}
2023+
case "notebookOutputSizeLimit":
2024+
await this.updateGlobalState("notebookOutputSizeLimit", message.value)
2025+
await this.postStateToWebview()
2026+
break
2027+
case "notebookExecutionTimeoutSeconds":
2028+
await this.updateGlobalState("notebookExecutionTimeoutSeconds", message.value)
2029+
await this.postStateToWebview()
2030+
break
2031+
case "alwaysAllowReadNotebook":
2032+
await this.updateGlobalState("alwaysAllowReadNotebook", message.bool ?? undefined)
2033+
await this.postStateToWebview()
2034+
break
2035+
case "alwaysAllowEditNotebook":
2036+
await this.updateGlobalState("alwaysAllowEditNotebook", message.bool ?? undefined)
2037+
await this.postStateToWebview()
2038+
break
2039+
case "alwaysAllowExecuteNotebook":
2040+
await this.updateGlobalState("alwaysAllowExecuteNotebook", message.bool ?? undefined)
2041+
await this.postStateToWebview()
2042+
break
20232043
}
20242044
},
20252045
null,
@@ -2474,6 +2494,11 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
24742494
showRooIgnoredFiles,
24752495
language,
24762496
maxReadFileLine,
2497+
notebookOutputSizeLimit,
2498+
notebookExecutionTimeoutSeconds,
2499+
alwaysAllowReadNotebook,
2500+
alwaysAllowEditNotebook,
2501+
alwaysAllowExecuteNotebook,
24772502
} = await this.getState()
24782503

24792504
const telemetryKey = process.env.POSTHOG_API_KEY
@@ -2544,6 +2569,11 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
25442569
language,
25452570
renderContext: this.renderContext,
25462571
maxReadFileLine: maxReadFileLine ?? 500,
2572+
notebookOutputSizeLimit: notebookOutputSizeLimit ?? 2000,
2573+
notebookExecutionTimeoutSeconds: notebookExecutionTimeoutSeconds ?? 30,
2574+
alwaysAllowReadNotebook: alwaysAllowReadNotebook ?? false,
2575+
alwaysAllowEditNotebook: alwaysAllowEditNotebook ?? false,
2576+
alwaysAllowExecuteNotebook: alwaysAllowExecuteNotebook ?? false,
25472577
}
25482578
}
25492579

@@ -2703,6 +2733,11 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
27032733
telemetrySetting: stateValues.telemetrySetting || "unset",
27042734
showRooIgnoredFiles: stateValues.showRooIgnoredFiles ?? true,
27052735
maxReadFileLine: stateValues.maxReadFileLine ?? 500,
2736+
notebookOutputSizeLimit: stateValues.notebookOutputSizeLimit ?? 2000,
2737+
notebookExecutionTimeoutSeconds: stateValues.notebookExecutionTimeoutSeconds ?? 30,
2738+
alwaysAllowReadNotebook: stateValues.alwaysAllowReadNotebook ?? false,
2739+
alwaysAllowEditNotebook: stateValues.alwaysAllowEditNotebook ?? false,
2740+
alwaysAllowExecuteNotebook: stateValues.alwaysAllowExecuteNotebook ?? false,
27062741
}
27072742
}
27082743

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ describe("ClineProvider", () => {
461461
showRooIgnoredFiles: true,
462462
renderContext: "sidebar",
463463
maxReadFileLine: 500,
464+
notebookOutputSizeLimit: 1000,
465+
notebookExecutionTimeoutSeconds: 30,
464466
}
465467

466468
const message: ExtensionMessage = {

src/exports/roo-code.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ export type GlobalStateKey =
221221
| "writeDelayMs"
222222
| "terminalOutputLineLimit"
223223
| "terminalShellIntegrationTimeout"
224+
| "notebookOutputSizeLimit"
225+
| "notebookExecutionTimeoutSeconds"
226+
| "alwaysAllowReadNotebook"
227+
| "alwaysAllowEditNotebook"
228+
| "alwaysAllowExecuteNotebook"
224229
| "mcpEnabled"
225230
| "enableMcpServerCreation"
226231
| "alwaysApproveResubmit"

0 commit comments

Comments
 (0)