@@ -25,6 +25,11 @@ import {
2525 resolveReadOnlyWorkspaceSkillMounts ,
2626 type ReadOnlyWorkspaceSkillMount ,
2727} from "./sandbox/workspace-mounts.js" ;
28+ import type {
29+ createEditTool ,
30+ createReadTool as CreateReadTool ,
31+ createWriteTool ,
32+ } from "./sessions/tools/index.js" ;
2833import { createReadTool } from "./sessions/tools/read.js" ;
2934
3035function readOnlySandboxReadMounts (
@@ -63,7 +68,7 @@ function resolveSkillReadRoots(skillsSnapshot?: SkillSnapshot): string[] | undef
6368 return roots . size > 0 ? Array . from ( roots ) : undefined ;
6469}
6570
66- export type CoreCodingToolsOptions = {
71+ type CoreCodingToolsOptions = {
6772 codingRoot : string ;
6873 includeBaseCodingTools : boolean ;
6974 includeShellTools : boolean ;
@@ -73,6 +78,12 @@ export type CoreCodingToolsOptions = {
7378 modelContextWindowTokens ?: number ;
7479 imageSanitization ?: ImageSanitizationLimits ;
7580 memoryWriteProvenance ?: MemoryWriteProvenanceObserver ;
81+ baseToolNames ?: readonly string [ ] ;
82+ baseToolFactories ?: {
83+ createEditTool : typeof createEditTool ;
84+ createReadTool : typeof CreateReadTool ;
85+ createWriteTool : typeof createWriteTool ;
86+ } ;
7687 applyPatchEnabled : boolean ;
7788 applyPatchWorkspaceOnly : boolean ;
7889 execDefaults : ExecToolDefaults ;
@@ -106,54 +117,63 @@ export function createCoreCodingTools(options: CoreCodingToolsOptions): AnyAgent
106117
107118 const base : AnyAgentTool [ ] = [ ] ;
108119 if ( options . includeBaseCodingTools ) {
109- if ( sandboxRoot ) {
110- const sandboxed = createSandboxedReadTool ( {
111- root : sandboxRoot ,
112- bridge : sandboxFsBridge ! ,
113- modelContextWindowTokens : options . modelContextWindowTokens ,
114- imageSanitization : options . imageSanitization ,
115- } ) ;
116- const guarded = options . workspaceOnly
117- ? wrapToolWorkspaceRootGuardWithOptions ( sandboxed , sandboxRoot , {
118- additionalContainerMounts : readOnlySandboxReadMounts (
119- sandbox ,
120- readOnlyWorkspaceSkillMounts ,
121- ) ,
122- containerWorkdir : sandbox . containerWorkdir ,
120+ const baseToolNames = new Set ( options . baseToolNames ?? [ "read" , "edit" , "write" ] ) ;
121+ if ( baseToolNames . has ( "read" ) ) {
122+ const wrapped = sandboxRoot
123+ ? createSandboxedReadTool ( {
124+ root : sandboxRoot ,
125+ bridge : sandboxFsBridge ! ,
126+ modelContextWindowTokens : options . modelContextWindowTokens ,
127+ imageSanitization : options . imageSanitization ,
128+ createTool : options . baseToolFactories ?. createReadTool ,
123129 } )
124- : sandboxed ;
125- base . push (
126- wrapReadToolWithSkillContent ( guarded , options . skillsSnapshot ?. resolvedSkills , {
127- modelContextWindowTokens : options . modelContextWindowTokens ,
128- imageSanitization : options . imageSanitization ,
129- } ) ,
130- ) ;
131- } else {
132- const wrapped = createOpenClawReadTool ( createReadTool ( options . codingRoot ) , {
133- modelContextWindowTokens : options . modelContextWindowTokens ,
134- imageSanitization : options . imageSanitization ,
135- } ) ;
130+ : createOpenClawReadTool (
131+ options . baseToolFactories ?. createReadTool ( options . codingRoot ) ??
132+ createReadTool ( options . codingRoot ) ,
133+ {
134+ modelContextWindowTokens : options . modelContextWindowTokens ,
135+ imageSanitization : options . imageSanitization ,
136+ } ,
137+ ) ;
136138 const guarded = options . workspaceOnly
137- ? wrapToolWorkspaceRootGuardWithOptions ( wrapped , options . codingRoot , {
138- additionalRoots : skillReadRoots ,
139- } )
139+ ? wrapToolWorkspaceRootGuardWithOptions (
140+ wrapped ,
141+ sandboxRoot ?? options . codingRoot ,
142+ sandboxRoot
143+ ? {
144+ additionalContainerMounts : readOnlySandboxReadMounts (
145+ sandbox ,
146+ readOnlyWorkspaceSkillMounts ,
147+ ) ,
148+ containerWorkdir : sandbox . containerWorkdir ,
149+ }
150+ : { additionalRoots : skillReadRoots } ,
151+ )
140152 : wrapped ;
141153 base . push (
142154 wrapReadToolWithSkillContent ( guarded , options . skillsSnapshot ?. resolvedSkills , {
143155 modelContextWindowTokens : options . modelContextWindowTokens ,
144156 imageSanitization : options . imageSanitization ,
145157 } ) ,
146158 ) ;
159+ }
160+ if ( ! sandboxRoot && baseToolNames . has ( "edit" ) ) {
147161 const edit = createHostWorkspaceEditTool ( options . codingRoot , {
148162 workspaceOnly : options . workspaceOnly ,
149163 memoryWriteProvenance : options . memoryWriteProvenance ,
164+ createTool : options . baseToolFactories ?. createEditTool ,
150165 } ) ;
166+ base . push (
167+ options . workspaceOnly ? wrapToolWorkspaceRootGuard ( edit , options . codingRoot ) : edit ,
168+ ) ;
169+ }
170+ if ( ! sandboxRoot && baseToolNames . has ( "write" ) ) {
151171 const write = createHostWorkspaceWriteTool ( options . codingRoot , {
152172 workspaceOnly : options . workspaceOnly ,
153173 memoryWriteProvenance : options . memoryWriteProvenance ,
174+ createTool : options . baseToolFactories ?. createWriteTool ,
154175 } ) ;
155176 base . push (
156- options . workspaceOnly ? wrapToolWorkspaceRootGuard ( edit , options . codingRoot ) : edit ,
157177 options . workspaceOnly ? wrapToolWorkspaceRootGuard ( write , options . codingRoot ) : write ,
158178 ) ;
159179 }
@@ -165,8 +185,14 @@ export function createCoreCodingTools(options: CoreCodingToolsOptions): AnyAgent
165185 bridge : sandboxFsBridge ! ,
166186 memoryWriteProvenance : options . memoryWriteProvenance ,
167187 } ;
168- const edit = createSandboxedEditTool ( toolOptions ) ;
169- const write = createSandboxedWriteTool ( toolOptions ) ;
188+ const edit = createSandboxedEditTool ( {
189+ ...toolOptions ,
190+ createTool : options . baseToolFactories ?. createEditTool ,
191+ } ) ;
192+ const write = createSandboxedWriteTool ( {
193+ ...toolOptions ,
194+ createTool : options . baseToolFactories ?. createWriteTool ,
195+ } ) ;
170196 base . push (
171197 options . workspaceOnly
172198 ? wrapToolWorkspaceRootGuardWithOptions ( edit , sandboxRoot , {
0 commit comments