Skip to content

Commit efc1596

Browse files
committed
Data Engineer mode (base 3.11.17)
1 parent 9a50235 commit efc1596

32 files changed

+2067
-6
lines changed

src/core/Cline.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ import { askFollowupQuestionTool } from "./tools/askFollowupQuestionTool"
8181
import { switchModeTool } from "./tools/switchModeTool"
8282
import { attemptCompletionTool } from "./tools/attemptCompletionTool"
8383
import { newTaskTool } from "./tools/newTaskTool"
84+
import { notebookReadTool } from "./tools/notebookReadTool"
85+
import { notebookEditTool } from "./tools/notebookEditTool"
86+
import { notebookExecuteTool } from "./tools/notebookExecuteTool"
8487

8588
export type ToolResponse = string | Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam>
8689
type UserContent = Array<Anthropic.Messages.ContentBlockParam>
@@ -1430,6 +1433,12 @@ export class Cline extends EventEmitter<ClineEvents> {
14301433
const modeName = getModeBySlug(mode, customModes)?.name ?? mode
14311434
return `[${block.name} in ${modeName} mode: '${message}']`
14321435
}
1436+
case "notebook_read":
1437+
return `[${block.name} action '${block.params.action}']`
1438+
case "notebook_edit":
1439+
return `[${block.name} action '${block.params.action}']`
1440+
case "notebook_execute":
1441+
return `[${block.name} action '${block.params.action}']`
14331442
}
14341443
}
14351444

@@ -1674,6 +1683,22 @@ export class Cline extends EventEmitter<ClineEvents> {
16741683
askFinishSubTaskApproval,
16751684
)
16761685
break
1686+
case "notebook_read":
1687+
await notebookReadTool(this, block, askApproval, handleError, pushToolResult, removeClosingTag)
1688+
break
1689+
case "notebook_edit":
1690+
await notebookEditTool(this, block, askApproval, handleError, pushToolResult, removeClosingTag)
1691+
break
1692+
case "notebook_execute":
1693+
await notebookExecuteTool(
1694+
this,
1695+
block,
1696+
askApproval,
1697+
handleError,
1698+
pushToolResult,
1699+
removeClosingTag,
1700+
)
1701+
break
16771702
}
16781703

16791704
break

src/core/assistant-message/index.ts

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

3134
// Converts array of tool call names into a union type ("execute_command" | "read_file" | ...)
@@ -61,6 +64,11 @@ export const toolParamNames = [
6164
"follow_up",
6265
"task",
6366
"size",
67+
"cells",
68+
"insert_at_index",
69+
"start_index",
70+
"end_index",
71+
"noexec",
6472
] as const
6573

6674
export type ToolParamName = (typeof toolParamNames)[number]
@@ -148,3 +156,23 @@ export interface NewTaskToolUse extends ToolUse {
148156
name: "new_task"
149157
params: Partial<Pick<Record<ToolParamName, string>, "mode" | "message">>
150158
}
159+
160+
export interface NotebookReadToolUse extends ToolUse {
161+
name: "notebook_read"
162+
params: Partial<Pick<Record<ToolParamName, string>, "action">>
163+
}
164+
165+
export interface NotebookEditToolUse extends ToolUse {
166+
name: "notebook_edit"
167+
params: Partial<
168+
Pick<
169+
Record<ToolParamName, string>,
170+
"action" | "cells" | "insert_at_index" | "start_index" | "end_index" | "noexec"
171+
>
172+
>
173+
}
174+
175+
export interface NotebookExecuteToolUse extends ToolUse {
176+
name: "notebook_execute"
177+
params: Partial<Pick<Record<ToolParamName, string>, "action" | "start_index" | "end_index">>
178+
}

src/core/prompts/tools/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { getUseMcpToolDescription } from "./use-mcp-tool"
1414
import { getAccessMcpResourceDescription } from "./access-mcp-resource"
1515
import { getSwitchModeDescription } from "./switch-mode"
1616
import { getNewTaskDescription } from "./new-task"
17+
import { getNotebookReadToolDescription } from "./notebook-read"
18+
import { getNotebookEditToolDescription } from "./notebook-edit"
19+
import { getNotebookExecuteToolDescription } from "./notebook-execute"
1720
import { DiffStrategy } from "../../diff/DiffStrategy"
1821
import { McpHub } from "../../../services/mcp/McpHub"
1922
import { Mode, ModeConfig, getModeConfig, isToolAllowedForMode, getGroupName } from "../../../shared/modes"
@@ -38,6 +41,9 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined>
3841
new_task: (args) => getNewTaskDescription(args),
3942
insert_content: (args) => getInsertContentDescription(args),
4043
search_and_replace: (args) => getSearchAndReplaceDescription(args),
44+
notebook_read: (args) => getNotebookReadToolDescription(args),
45+
notebook_edit: (args) => getNotebookEditToolDescription(args),
46+
notebook_execute: (args) => getNotebookExecuteToolDescription(args),
4147
apply_diff: (args) =>
4248
args.diffStrategy ? args.diffStrategy.getToolDescription({ cwd: args.cwd, toolOptions: args.toolOptions }) : "",
4349
}
@@ -112,4 +118,7 @@ export {
112118
getSwitchModeDescription,
113119
getInsertContentDescription,
114120
getSearchAndReplaceDescription,
121+
getNotebookReadToolDescription,
122+
getNotebookEditToolDescription,
123+
getNotebookExecuteToolDescription,
115124
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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, append cells to the end, or replace existing cells. Note that new/modified code cells will be executed immediately by default, unless the noexec parameter is true.
6+
Parameters:
7+
- action: (required) The action to perform. Valid values are:
8+
- "insert_cells": Insert new cells into the notebook (or append to the end if insert_at_index is omitted)
9+
- "modify_cell_content": Modify the content of existing cells in the notebook (note: this will clear any existing outputs)
10+
- "replace_cells": Replace a range of cells with new cells (note: this will clear any existing outputs)
11+
- "delete_cells": Delete a range of cells from the notebook
12+
- cells: (required) A JSON array containing cell definitions. The structure depends on the action:
13+
- For insert_cells: Array of objects with properties:
14+
- content: (required) The cell content
15+
- cell_type: (optional) The type of cell, either "code" or "markdown"
16+
- language_id: (optional) The language of the cell (e.g., "python", "javascript")
17+
- For modify_cell_content: Array of objects with properties:
18+
- index: (required) The index of the cell to modify (0-based)
19+
- content: (required) The new content for the cell
20+
- For replace_cells: A single object with properties:
21+
- start_index: (required) The starting index of the range to replace (0-based, inclusive)
22+
- end_index: (required) The ending index of the range to replace (0-based, exclusive)
23+
- cells: (required) Array of objects with properties:
24+
- content: (required) The cell content
25+
- cell_type: (optional) The type of cell, either "code" or "markdown"
26+
- language_id: (optional) The language of the cell (e.g., "python", "javascript")
27+
- For delete_cells: A single object with properties:
28+
- start_index: (required) The starting index of the range to delete (0-based, inclusive)
29+
- end_index: (required) The ending index of the range to delete (0-based, exclusive)
30+
- insert_at_index: (optional, only for insert_cells action) The position to insert cells at (0-based, defaults to end of notebook)
31+
- noexec: (optional) Boolean value to prevent automatic execution of new/modified code cells.
32+
Usage:
33+
<notebook_edit>
34+
<action>action name here</action>
35+
<cells>[JSON array of cell definitions]</cells>
36+
<insert_at_index>index value here (if required)</insert_at_index>
37+
<noexec>true</noexec>
38+
</notebook_edit>
39+
40+
Example 1: Insert multiple cells at index 0
41+
<notebook_edit>
42+
<action>insert_cells</action>
43+
<insert_at_index>0</insert_at_index>
44+
<cells>[
45+
{
46+
"cell_type": "markdown",
47+
"content": "# Data Analysis\nThis notebook contains the analysis of our dataset."
48+
},
49+
{
50+
"cell_type": "code",
51+
"language_id": "python",
52+
"content": "import pandas as pd\nimport numpy as np\ndf = pd.read_csv('data.csv')\ndf.head()"
53+
}
54+
]</cells>
55+
</notebook_edit>
56+
57+
Example 2: Append a new markdown cell (no insert_at_index specified)
58+
<notebook_edit>
59+
<action>insert_cells</action>
60+
<cells>[
61+
{
62+
"cell_type": "markdown",
63+
"content": "# Data Analysis\nThis notebook contains the analysis of our dataset with the following steps:\n1. Data loading and cleaning\n2. Exploratory data analysis\n3. Statistical testing\n4. Visualization"
64+
}
65+
]</cells>
66+
</notebook_edit>
67+
68+
Example 3: Modify multiple existing cells without execution
69+
<notebook_edit>
70+
<action>modify_cell_content</action>
71+
<cells>[
72+
{
73+
"index": 2,
74+
"content": "import matplotlib.pyplot as plt\nplt.figure(figsize=(10, 6))\nplt.plot(df['x'], df['y'])\nplt.title('Data Visualization')\nplt.xlabel('X Axis')\nplt.ylabel('Y Axis')\nplt.show()"
75+
},
76+
{
77+
"index": 3,
78+
"content": "# Statistical Analysis\nLet's analyze the correlation between variables."
79+
}
80+
]</cells>
81+
<noexec>true</noexec>
82+
</notebook_edit>
83+
84+
Example 4: Replace a range of cells with new cells
85+
<notebook_edit>
86+
<action>replace_cells</action>
87+
<cells>{
88+
"start_index": 2,
89+
"end_index": 4,
90+
"cells": [
91+
{
92+
"cell_type": "code",
93+
"language_id": "python",
94+
"content": "import matplotlib.pyplot as plt\nimport seaborn as sns\n\nplt.figure(figsize=(10, 6))\nsns.scatterplot(x='x', y='y', data=df)\nplt.title('Scatter Plot')\nplt.show()"
95+
},
96+
{
97+
"cell_type": "markdown",
98+
"content": "## Observations\nThe scatter plot shows a positive correlation between x and y variables."
99+
}
100+
]
101+
}</cells>
102+
</notebook_edit>
103+
104+
Example 5: Delete a range of cells
105+
<notebook_edit>
106+
<action>delete_cells</action>
107+
<cells>{
108+
"start_index": 2,
109+
"end_index": 4
110+
}</cells>
111+
</notebook_edit>`
112+
}
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+
}

0 commit comments

Comments
 (0)