Repository navigation
fix(agui,harness): propagate runtime context and harden shell working_directory - #1780
guslegend0510 wants to merge 5 commits into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds RuntimeContext propagation through the AGUI request pipeline and hardens ShellExecuteTool against path traversal. The shell path validation correctly blocks absolute paths, .. traversal, and illegal characters. However, the RuntimeContext API plumbing is incomplete — no concrete Agent implementation overrides the new 3-parameter stream() method, so the runtime context is silently dropped by default. The default implementation also delegates to a @Deprecated(forRemoval=true) method, creating a future compilation hazard.
| return sb.toString(); | ||
| } | ||
|
|
||
| private static String validateWorkingDirectory(String workingDirectory) { |
There was a problem hiding this comment.
[recommended] Missing null-byte injection protection. When workingDirectory contains \0, some shell/native layers may truncate the path (e.g., cd 'safe\0/../../etc'). Add a null-byte check before the Path.of() validation: if (workingDirectory.indexOf('\0') >= 0) throw new IllegalArgumentException("working_directory must not contain null bytes");
| * @param runtimeContext Per-call runtime context, or {@code null} | ||
| * @return Flux of events emitted during execution | ||
| */ | ||
| default Flux<Event> stream( |
There was a problem hiding this comment.
[recommended] RuntimeContext is silently dropped by default. No concrete Agent implementation overrides the new 3-parameter stream(List, StreamOptions, RuntimeContext). The default implementation delegates to the 2-parameter version, discarding the RuntimeContext. Document this clearly in the Javadoc: "Default implementation drops runtimeContext; concrete agents must override to enable propagation." Also note that the default delegates to a @Deprecated(forRemoval=true) method in StreamableAgent — when that interface is removed, this default will fail to compile.
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds RuntimeContext propagation through the AGUI request pipeline and hardens ShellExecuteTool against path traversal. The shell path validation correctly blocks absolute paths, .. traversal, and illegal characters. However, the RuntimeContext API plumbing is incomplete — no concrete Agent implementation overrides the new 3-parameter stream() method, so the runtime context is silently dropped by default. The default implementation also delegates to a @Deprecated(forRemoval=true) method, creating a future compilation hazard.
| return sb.toString(); | ||
| } | ||
|
|
||
| private static String validateWorkingDirectory(String workingDirectory) { |
There was a problem hiding this comment.
[recommended] Missing null-byte injection protection. When workingDirectory contains \0, some shell/native layers may truncate the path (e.g., cd 'safe\0/../../etc'). Add a null-byte check before the Path.of() validation: if (workingDirectory.indexOf('\0') >= 0) throw new IllegalArgumentException("working_directory must not contain null bytes");
| * @param runtimeContext Per-call runtime context, or {@code null} | ||
| * @return Flux of events emitted during execution | ||
| */ | ||
| default Flux<Event> stream( |
There was a problem hiding this comment.
[recommended] RuntimeContext is silently dropped by default. No concrete Agent implementation overrides the new 3-parameter stream(List, StreamOptions, RuntimeContext). The default implementation delegates to the 2-parameter version, discarding the RuntimeContext. Document this clearly in the Javadoc: "Default implementation drops runtimeContext; concrete agents must override to enable propagation." Also note that the default delegates to a @Deprecated(forRemoval=true) method in StreamableAgent — when that interface is removed, this default will fail to compile.
| * @param runtimeContext Per-call runtime context, or {@code null} | ||
| * @return Flux of events emitted during execution | ||
| */ | ||
| default Flux<Event> stream( |
There was a problem hiding this comment.
Event will gradually be replaced by AgentEvent, would you like to reimplement the AGUI integration with AgentEvent?
There was a problem hiding this comment.
这次 PR 只是在 deprecated 的 stream(..., RuntimeContext) 上补一个兼容 overload,目的是保持旧 API 行为一致,不打算在这里改 AGUI 的事件体系。AgentEvent 的 runtimeContext 版本已经在 ReActAgent#streamEvents(..., RuntimeContext) 和 HarnessAgent#streamEvents(..., RuntimeContext) 上实现了,AGUI 迁移会放到单独的 PR 里。
这个PR已经移动到#1814 ,这里面了
@chickenlj
What
RuntimeContext透传,避免通过 AGUI 进入时丢失会话上下文。ShellExecuteTool的working_directory,拒绝绝对路径和..逃逸,并对cd参数做 shell quoting。Why
Tests
mvn -pl agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agui,agentscope-harness -am -DskipITs test "-Dtest=AguiAgentAdapterTest,AguiRequestProcessorTest,ShellExecuteToolTest"