Commit Β·
ae24efc
1
Parent(s): d644dff
feat: resolve sandbox file paths and show tool description in status
Browse files- Extract resolve_sandbox_script utility in sandbox_tool.py to detect
file paths and read content from sandbox via cat
- Resolve script paths before sending approval_required event so the
frontend receives actual file content for display and editing
- Show tool description arg in status chip and activity bar instead of
generic "running" / "Running bash" text
Files changed (6)
490 unmodified lines491492493494495496490 unmodified linestool_args = json.loads(tc.function.arguments)except (json.JSONDecodeError, TypeError):tool_args = {}tools_data.append({"tool": tool_name,490 unmodified lines491492493494495496497498499500501502503504505506490 unmodified linestool_args = json.loads(tc.function.arguments)except (json.JSONDecodeError, TypeError):tool_args = {}# Resolve sandbox file paths for hf_jobs scripts so the# frontend can display & edit the actual file content.if tool_name == "hf_jobs" and isinstance(tool_args.get("script"), str):from agent.tools.sandbox_tool import resolve_sandbox_scriptsandbox = getattr(session, "sandbox", None)content, _ = await resolve_sandbox_script(sandbox, tool_args["script"])if content:tool_args = {**tool_args, "script": content}tools_data.append({"tool": tool_name,
11 unmodified lines1213141516171 unmodified line19202122232411 unmodified linesfrom __future__ import annotationsimport asynciofrom typing import Anyfrom huggingface_hub import HfApi, SpaceHardware1 unmodified linefrom agent.core.session import Eventfrom agent.tools.sandbox_client import Sandbox# ββ Tool name mapping (short agent names β Sandbox client names) ββββββ11 unmodified lines121314151617181 unmodified line2021222324252627282930313233343536373839404142434445464748495051525354555611 unmodified linesfrom __future__ import annotationsimport asyncioimport shlexfrom typing import Anyfrom huggingface_hub import HfApi, SpaceHardware1 unmodified linefrom agent.core.session import Eventfrom agent.tools.sandbox_client import Sandboxdef _looks_like_path(script: str) -> bool:"""Return True if the script string looks like a file path (not inline code)."""return (isinstance(script, str)and script.strip() == scriptand not any(c in script for c in "\r\n\0")and (script.startswith("/") or script.startswith("./") or script.startswith("../")))async def resolve_sandbox_script(sandbox: Any, script: str) -> tuple[str | None, str | None]:"""Read a file from the sandbox if *script* looks like a path.Returns:(content, error) β content is the file text on success,error is a message on failure. Both None means *script*is not a path (caller should use it as-is)."""if not sandbox or not _looks_like_path(script):return None, Nonetry:result = await asyncio.to_thread(sandbox.bash, f"cat {shlex.quote(script)}")if result.success and result.output:return result.output, Nonereturn None, f"Failed to read {script} from sandbox: {result.error}"except Exception as e:return None, f"Failed to read {script} from sandbox: {e}"# ββ Tool name mapping (short agent names β Sandbox client names) ββββββ
20 unmodified lines2122232425262720 unmodified linesswitch (status.type) {case 'thinking': return 'Thinking';case 'streaming': return 'Writing';case 'tool': return TOOL_LABELS[status.toolName] || `Running ${status.toolName}`;case 'waiting-approval': return 'Waiting for approval';default: return '';}20 unmodified lines2122232425262720 unmodified linesswitch (status.type) {case 'thinking': return 'Thinking';case 'streaming': return 'Writing';case 'tool': return status.description || TOOL_LABELS[status.toolName] || `Running ${status.toolName}`;case 'waiting-approval': return 'Waiting for approval';default: return '';}
194 unmodified lines195196197198199200201202194 unmodified linesonStreaming: () => {if (isActiveRef.current) setActivityStatus({ type: 'streaming' });},onToolRunning: (toolName: string) => {if (isActiveRef.current) setActivityStatus({ type: 'tool', toolName });},}),// sessionId is the only real dependency β Zustand setters are stable194 unmodified lines195196197198199200201202194 unmodified linesonStreaming: () => {if (isActiveRef.current) setActivityStatus({ type: 'streaming' });},onToolRunning: (toolName: string, description?: string) => {if (isActiveRef.current) setActivityStatus({ type: 'tool', toolName, description });},}),// sessionId is the only real dependency β Zustand setters are stable
34 unmodified lines35363738394041457 unmodified lines49950050150250350450534 unmodified lines/** Called when assistant text starts streaming */onStreaming: () => void;/** Called when a tool starts running (non-plan) */onToolRunning: (toolName: string) => void;}// ---------------------------------------------------------------------------457 unmodified linesthis.enqueue({ type: 'tool-input-start', toolCallId, toolName, dynamic: true });this.enqueue({ type: 'tool-input-available', toolCallId, toolName, input: args, dynamic: true });this.sideChannel.onToolRunning(toolName);this.sideChannel.onToolCallPanel(toolName, args as Record<string, unknown>);break;}34 unmodified lines35363738394041457 unmodified lines49950050150250350450534 unmodified lines/** Called when assistant text starts streaming */onStreaming: () => void;/** Called when a tool starts running (non-plan) */onToolRunning: (toolName: string, description?: string) => void;}// ---------------------------------------------------------------------------457 unmodified linesthis.enqueue({ type: 'tool-input-start', toolCallId, toolName, dynamic: true });this.enqueue({ type: 'tool-input-available', toolCallId, toolName, input: args, dynamic: true });this.sideChannel.onToolRunning(toolName, (args as Record<string, unknown>)?.description as string | undefined);this.sideChannel.onToolCallPanel(toolName, args as Record<string, unknown>);break;}
40 unmodified lines4142434445464740 unmodified linesexport type ActivityStatus =| { type: 'idle' }| { type: 'thinking' }| { type: 'tool'; toolName: string }| { type: 'waiting-approval' }| { type: 'streaming' };40 unmodified lines4142434445464740 unmodified linesexport type ActivityStatus =| { type: 'idle' }| { type: 'thinking' }| { type: 'tool'; toolName: string; description?: string }| { type: 'waiting-approval' }| { type: 'streaming' };
agent/core/agent_loop.py+10
agent/tools/sandbox_tool.py+32
frontend/src/components/Chat/ActivityStatusBar.tsx+1-1
frontend/src/hooks/useAgentChat.ts+2-2
frontend/src/lib/ws-chat-transport.ts+2-2
frontend/src/store/agentStore.ts+1-1