@@ -23,6 +23,9 @@ $includeDefinitions := toolOptionValue[ "WolframLanguageEvaluator", "Inclu
2323$sandboxEvaluationTimeout := toolOptionValue [ "WolframLanguageEvaluator" , "EvaluationTimeConstraint" ];
2424$sandboxPingTimeout := toolOptionValue [ "WolframLanguageEvaluator" , "PingTimeConstraint" ];
2525$evaluatorMethod := toolOptionValue [ "WolframLanguageEvaluator" , "Method" ];
26+ $readPaths := toolOptionValue [ "WolframLanguageEvaluator" , "AllowedReadPaths" ];
27+ $writePaths := toolOptionValue [ "WolframLanguageEvaluator" , "AllowedWritePaths" ];
28+ $executePaths := toolOptionValue [ "WolframLanguageEvaluator" , "AllowedExecutePaths" ];
2629$cloudEvaluatorLocation = "/Chatbook/Tools/WolframLanguageEvaluator/Evaluate" ;
2730$cloudLineNumber = 1 ;
2831$cloudSession = None ;
@@ -114,6 +117,9 @@ $$probableFailure = Alternatives[
114117 _ Missing
115118];
116119
120+ $$pathItem = _ String | $$unspecified | ParentList | All | None | _ Hold | _ HoldComplete | _ HoldCompleteForm ;
121+ $$pathSpec = $$pathItem | { $$pathItem ... };
122+
117123(* ::**************************************************************************************************************:: *)
118124(* ::Section::Closed:: *)
119125(*Messages*)
@@ -126,13 +132,17 @@ Chatbook::InvalidEvaluatorProperty = "Invalid evaluator property: `1`.";
126132WolframLanguageToolEvaluate // beginDefinition ;
127133
128134WolframLanguageToolEvaluate // Options = {
135+ "AllowedExecutePaths" -> Automatic ,
136+ "AllowedReadPaths" -> Automatic ,
137+ "AllowedWritePaths" -> Automatic ,
129138 "AppendRetryNotice" -> False ,
130139 "AppendURIInstructions" -> True ,
140+ "IncludeDefinitions" -> Automatic ,
141+ "Line" -> Automatic ,
131142 "MaxCharacterCount" -> 10000 ,
132- Line -> Automatic ,
133- Method -> Automatic ,
134- PageWidth -> Infinity ,
135- TimeConstraint -> 60
143+ "Method" -> Automatic ,
144+ "PageWidth" -> Infinity ,
145+ "TimeConstraint" -> 60
136146};
137147
138148WolframLanguageToolEvaluate [ code_ , opts : OptionsPattern [ ] ] :=
@@ -189,9 +199,13 @@ wolframLanguageToolEvaluate[ code_, property_, opts_Association ] := Enclose[
189199 $appendRetryNotice = getOption [ "AppendRetryNotice" , opts ],
190200 $appendURIInstructions = getOption [ "AppendURIInstructions" , opts ],
191201 $evaluatorMethod = getOption [ "Method" , opts ],
202+ $executePaths = getOption [ "AllowedExecutePaths" , opts ],
203+ $includeDefinitions = getOption [ "IncludeDefinitions" , opts ],
204+ $readPaths = getOption [ "AllowedReadPaths" , opts ],
205+ $sandboxEvaluationTimeout = getOption [ "TimeConstraint" , opts ],
192206 $toolOutputPageWidth = getOption [ "PageWidth" , opts ],
193207 $toolResultStringLength = getOption [ "MaxCharacterCount" , opts ],
194- $sandboxEvaluationTimeout = getOption [ "TimeConstraint" , opts ],
208+ $writePaths = getOption [ "AllowedWritePaths" , opts ],
195209 $Line = getOption [ "Line" , opts ]
196210 },
197211 getProperty [ sandboxEvaluate @ preprocessCodeForTool @ code , property ]
@@ -238,8 +252,25 @@ getOption[ "Line", $$unspecified ] := $Line;
238252getOption [ "Line" , line_ Integer ? Positive ] := line ;
239253getOption [ "Line" , line_ ] := throwFailure [ "InvalidOptionValue" , "Line" , line ];
240254
255+ getOption [ "IncludeDefinitions" , $$unspecified ] := $includeDefinitions ;
256+ getOption [ "IncludeDefinitions" , include : True |False ] := include ;
257+ getOption [ "IncludeDefinitions" , include_ ] := throwFailure [ "InvalidOptionValue" , "IncludeDefinitions" , include ];
258+
259+ getOption [ "AllowedReadPaths" , paths_ ] := getAllowedPaths [ "AllowedReadPaths" , paths ];
260+ getOption [ "AllowedWritePaths" , paths_ ] := getAllowedPaths [ "AllowedWritePaths" , paths ];
261+ getOption [ "AllowedExecutePaths" , paths_ ] := getAllowedPaths [ "AllowedExecutePaths" , paths ];
262+
241263getOption // endDefinition ;
242264
265+ (* ::**************************************************************************************************************:: *)
266+ (* ::Subsubsection::Closed:: *)
267+ (*getAllowedPaths*)
268+ getAllowedPaths // beginDefinition ;
269+ getAllowedPaths [ name_ , $$unspecified ] := $DefaultToolOptions [ "WolframLanguageEvaluator" , name ];
270+ getAllowedPaths [ name_ , paths : $$pathSpec ] := paths ;
271+ getAllowedPaths [ name_ String , paths_ ] := throwFailure [ "InvalidOptionValue" , name , paths ];
272+ getAllowedPaths // endDefinition ;
273+
243274(* ::**************************************************************************************************************:: *)
244275(* ::Subsubsection::Closed:: *)
245276(*getProperty*)
@@ -454,9 +485,9 @@ startSandboxKernel[ ] := Enclose[
454485
455486 kernel = ConfirmMatch [ LinkLaunch @ $sandboxKernelCommandLine , _ LinkObject , "LinkLaunch" ];
456487
457- readPaths = makeReadPaths @ toolOptionValue [ "WolframLanguageEvaluator" , "AllowedReadPaths" ] ;
458- writePaths = makeWritePaths @ toolOptionValue [ "WolframLanguageEvaluator" , "AllowedWritePaths" ] ;
459- executePaths = makeExecutePaths @ toolOptionValue [ "WolframLanguageEvaluator" , "AllowedExecutePaths" ] ;
488+ readPaths = makeReadPaths @ $readPaths ;
489+ writePaths = makeWritePaths @ $writePaths ;
490+ executePaths = makeExecutePaths @ $executePaths ;
460491
461492 (* Use StartProtectedMode instead of passing the -sandbox argument, since we need to initialize the FE first *)
462493 With [ { read = readPaths , write = writePaths , execute = executePaths },
@@ -517,11 +548,9 @@ $defaultReadPaths := $defaultReadPaths = Select[
517548 FileNameJoin @ { $BaseDirectory , "Autoload" , "PacletManager" },
518549 FileNameJoin @ { $UserBaseDirectory , "Paclets" },
519550 FileNameJoin @ { $UserBaseDirectory , "Autoload" , "PacletManager" },
520- FileNameJoin @ { $UserBaseDirectory , "ApplicationData" , "CloudObject" , "Authentication" },
521- FileNameJoin @ { $UserBaseDirectory , "ApplicationData" , "Parallel" , "Preferences" },
522- FileNameJoin @ { $UserBaseDirectory , "ApplicationData" , "Credentials" },
523- FileNameJoin @ { $UserBaseDirectory , "ApplicationData" , "Astro" },
551+ FileNameJoin @ { $UserBaseDirectory , "ApplicationData" },
524552 FileNameJoin @ { $UserBaseDirectory , "Knowledgebase" },
553+ FileNameJoin @ { $UserBaseDirectory , "Logs" },
525554 SystemInformation [ "FrontEnd" , "DocumentationInformation" ][ "Directory" ],
526555 ExpandFileName @ URL @ $LocalBase
527556 },
@@ -547,6 +576,7 @@ $defaultWritePaths := $defaultWritePaths = Select[
547576 FileNameJoin @ { $UserBaseDirectory , "ApplicationData" , "Credentials" },
548577 FileNameJoin @ { $UserBaseDirectory , "ApplicationData" , "Astro" },
549578 FileNameJoin @ { $UserBaseDirectory , "Knowledgebase" },
579+ FileNameJoin @ { $UserBaseDirectory , "Logs" },
550580 FileNameJoin @ { ExpandFileName @ URL @ $LocalBase , "Resources" }
551581 },
552582 StringQ
@@ -607,7 +637,7 @@ makePaths[ All ] := If[ $OperatingSystem === "Windows", # <> ":\\" & /@ Characte
607637makePaths [ None ] := { };
608638makePaths [ paths_ List ] := DeleteDuplicates @ Flatten [ makePaths /@ Flatten @ paths ];
609639makePaths [ path_ String ] := path ;
610- makePaths [ h : _ Hold |_ HoldComplete ] := makePaths @ ReleaseHold @ h ;
640+ makePaths [ h : _ Hold |_ HoldComplete | _ HoldCompleteForm ] := makePaths @ ReleaseHold @ h ;
611641makePaths [ ParentList |Inherited ] := ParentList ;
612642makePaths [ $$unspecified ] := Automatic ;
613643makePaths // endDefinition ;
0 commit comments