You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/uno/anahata/ai/tools/spi/LocalShell.java
+16-7Lines changed: 16 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -10,21 +10,23 @@
10
10
importjava.util.Map;
11
11
importjava.util.concurrent.ExecutorService;
12
12
importjava.util.concurrent.Future;
13
+
importlombok.extern.slf4j.Slf4j;
13
14
importuno.anahata.ai.tools.AIToolMethod;
14
15
importuno.anahata.ai.tools.AIToolParam;
15
16
16
17
/**
17
18
* A tool provider that allows the AI model to execute commands in the local
18
-
* bash shell.
19
+
* shell (bash on Unix, cmd.exe on Windows).
19
20
* <p>
20
21
* This tool is powerful and should be used with caution. It captures standard
21
22
* output, standard error, and execution metadata.
22
23
* </p>
23
24
*/
25
+
@Slf4j
24
26
publicclassLocalShell {
25
27
26
28
/**
27
-
* Executes a shell command using {@code bash -c}.
29
+
* Executes a shell command using the appropriate system shell.
28
30
*
29
31
* @param command The shell command to execute.
30
32
* @return A map containing execution results:
@@ -40,8 +42,8 @@ public class LocalShell {
40
42
* </ul>
41
43
* @throws Exception if the command fails to start or execution is interrupted.
42
44
*/
43
-
@AIToolMethod("Runs a shell command with bash -c: <command> and returns a map with the following values:\n"
44
-
+ " \n\tthreadId (it of the thread that executed the shell command, "
45
+
@AIToolMethod("Runs a shell command using the system's default shell (cmd.exe on Windows, bash on Unix) and returns a map with the following values:\n"
46
+
+ " \n\tthreadId (id of the thread that executed the shell command, "
45
47
+ " \n\tpid, process id"
46
48
+ " \n\tstartTime, process start time as an ISO-8601 string"
47
49
+ " \n\tendTime, process end time as an ISO-8601 string"
@@ -51,10 +53,17 @@ public class LocalShell {
51
53
+ " \n\tstderr, process standard error"
52
54
)
53
55
publicstaticMap<String, Object> runShell(@AIToolParam("The command to run") Stringcommand) throwsException {
Copy file name to clipboardExpand all lines: src/main/java/uno/anahata/ai/tools/spi/RunningJVM.java
+17-1Lines changed: 17 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,22 @@
38
38
* test, and run code dynamically. It uses an in-memory file manager and a
39
39
* custom classloader to ensure that newly compiled classes take precedence.
40
40
* </p>
41
+
*
42
+
* <h3>The Hot-Reload Mechanism:</h3>
43
+
* <p>
44
+
* When code is compiled via {@link #compileJava(String, String, String, String[])}, the resulting
45
+
* bytecode is stored in memory. A custom {@link URLClassLoader} is then created with a
46
+
* <b>Child-First</b> strategy:
47
+
* </p>
48
+
* <ol>
49
+
* <li>It first checks if the class is the one just compiled in memory.</li>
50
+
* <li>If not, it attempts to load the class from the {@code extraClassPath} (e.g., a project's {@code target/classes}).</li>
51
+
* <li>Only if the class is not found in either location does it delegate to the parent classloader (e.g. the IDE's classpath or the host application's classpath).</li>
52
+
* </ol>
53
+
* <p>
54
+
* This ensures that any changes you make to the code are reflected immediately, even if a version
55
+
* of that class already exists in the IDE's main classpath.
0 commit comments