Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions src/cli/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
type RalphState,
ralphMode,
} from "../ralph/mode";
import { getSandboxStatus, type SandboxStatus } from "../sandbox";
import { updateProjectSettings } from "../settings";
import { settingsManager } from "../settings-manager";
import { telemetry } from "../telemetry";
Expand Down Expand Up @@ -104,6 +105,7 @@ import { PinDialog, validateAgentName } from "./components/PinDialog";
// QuestionDialog removed - now using InlineQuestionApproval
import { ReasoningMessage } from "./components/ReasoningMessageRich";
import { ResumeSelector } from "./components/ResumeSelector";
import { SandboxSelector } from "./components/SandboxSelector";
import { formatUsageStats } from "./components/SessionStats";
// InlinePlanApproval kept for easy rollback if needed
// import { InlinePlanApproval } from "./components/InlinePlanApproval";
Expand Down Expand Up @@ -791,6 +793,7 @@ export default function App({
| "pin"
| "new"
| "mcp"
| "sandbox"
| "help"
| "oauth"
| null;
Expand All @@ -804,6 +807,11 @@ export default function App({
// Pin dialog state
const [pinDialogLocal, setPinDialogLocal] = useState(false);

// Sandbox state
const [sandboxStatus, setSandboxStatus] = useState<SandboxStatus | null>(
null,
);

// Derived: check if any selector/overlay is open (blocks queue processing and hides input)
const anySelectorOpen = activeOverlay !== null;

Expand Down Expand Up @@ -1381,6 +1389,14 @@ export default function App({
: "default";
setCurrentToolset(derivedToolset);
}

// Fetch sandbox status
try {
const status = await getSandboxStatus(agentId);
setSandboxStatus(status);
} catch {
setSandboxStatus(null);
}
} catch (error) {
console.error("Error fetching agent config:", error);
}
Expand Down Expand Up @@ -3510,6 +3526,69 @@ export default function App({
return { submitted: true };
}

// Special handling for /sandbox command - manage sandbox providers
if (trimmed === "/sandbox" || trimmed.startsWith("/sandbox ")) {
const afterSandbox = trimmed.slice(8).trim();
const firstWord = afterSandbox.split(/\s+/)[0]?.toLowerCase();

// /sandbox or /sandbox enable - open sandbox selector
if (!firstWord || firstWord === "enable") {
setActiveOverlay("sandbox");
return { submitted: true };
}

// /sandbox disable - disable sandbox directly
if (firstWord === "disable") {
setCommandRunning(true);

try {
const { disableSandbox } = await import("../sandbox");
const removed = await disableSandbox(agentId);
setSandboxStatus({ enabled: false, provider: null });
const cmdId = uid("cmd");
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: trimmed,
output: `Sandbox disabled (${removed} tools removed)`,
phase: "finished",
success: true,
});
buffersRef.current.order.push(cmdId);
} catch (err) {
const cmdId = uid("cmd");
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: trimmed,
output: `Failed to disable sandbox: ${err}`,
phase: "finished",
success: false,
});
buffersRef.current.order.push(cmdId);
}

setCommandRunning(false);
refreshDerived();
return { submitted: true };
}

// Unknown subcommand - show usage
const cmdId = uid("cmd");
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: trimmed,
output:
"Usage: /sandbox [enable|disable]\n /sandbox - Open sandbox provider selector\n /sandbox enable - Same as /sandbox\n /sandbox disable - Remove sandbox tools",
phase: "finished",
success: true,
});
buffersRef.current.order.push(cmdId);
refreshDerived();
return { submitted: true };
}

// Special handling for /connect command - OAuth connection
if (msg.trim().startsWith("/connect")) {
const parts = msg.trim().split(/\s+/);
Expand Down Expand Up @@ -7179,6 +7258,7 @@ Plan file path: ${planFilePath}`;
agentName={agentName}
currentModel={currentModelDisplay}
currentModelProvider={currentModelProvider}
sandboxProvider={sandboxStatus?.provider ?? null}
messageQueue={messageQueue}
onEnterQueueEditMode={handleEnterQueueEditMode}
onEscapeCancel={
Expand Down Expand Up @@ -7292,6 +7372,34 @@ Plan file path: ${planFilePath}`;
/>
)}

{/* Sandbox Selector - conditionally mounted as overlay */}
{activeOverlay === "sandbox" && (
<SandboxSelector
agentId={agentId}
initialStatus={sandboxStatus ?? undefined}
onComplete={(message) => {
closeOverlay();
// Update sandbox status
getSandboxStatus(agentId)
.then(setSandboxStatus)
.catch(() => setSandboxStatus(null));
// Show result
const cmdId = uid("cmd");
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: cmdId,
input: "/sandbox",
output: message,
phase: "finished",
success: true,
});
buffersRef.current.order.push(cmdId);
refreshDerived();
}}
onCancel={closeOverlay}
/>
)}

{/* Help Dialog - conditionally mounted as overlay */}
{activeOverlay === "help" && <HelpDialog onClose={closeOverlay} />}

Expand Down
8 changes: 8 additions & 0 deletions src/cli/commands/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ export const commands: Record<string, Command> = {
return `Installed Shift+Enter keybinding for ${terminalName}\nLocation: ${keybindingsPath}`;
},
},
"/sandbox": {
desc: "Connect remote sandbox (E2B/Daytona)",
order: 37,
handler: () => {
// Handled specially in App.tsx to open SandboxSelector component
return "Opening sandbox selector...";
},
},

// === Session management (order 40-49) ===
"/connect": {
Expand Down
8 changes: 8 additions & 0 deletions src/cli/components/InputRich.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const InputFooter = memo(function InputFooter({
agentName,
currentModel,
isAnthropicProvider,
sandboxProvider,
}: {
ctrlCPressed: boolean;
escapePressed: boolean;
Expand All @@ -61,6 +62,7 @@ const InputFooter = memo(function InputFooter({
agentName: string | null | undefined;
currentModel: string | null | undefined;
isAnthropicProvider: boolean;
sandboxProvider: string | null | undefined;
}) {
return (
<Box justifyContent="space-between" marginBottom={1}>
Expand Down Expand Up @@ -95,6 +97,9 @@ const InputFooter = memo(function InputFooter({
>
{` [${currentModel ?? "unknown"}]`}
</Text>
{sandboxProvider && (
<Text color="#22C55E">{` [${sandboxProvider.toUpperCase()}]`}</Text>
)}
</Text>
</Box>
);
Expand Down Expand Up @@ -124,6 +129,7 @@ export function Input({
agentName,
currentModel,
currentModelProvider,
sandboxProvider,
messageQueue,
onEnterQueueEditMode,
onEscapeCancel,
Expand All @@ -147,6 +153,7 @@ export function Input({
agentName?: string | null;
currentModel?: string | null;
currentModelProvider?: string | null;
sandboxProvider?: string | null;
messageQueue?: string[];
onEnterQueueEditMode?: () => void;
onEscapeCancel?: () => void;
Expand Down Expand Up @@ -836,6 +843,7 @@ export function Input({
agentName={agentName}
currentModel={currentModel}
isAnthropicProvider={currentModelProvider === ANTHROPIC_PROVIDER_NAME}
sandboxProvider={sandboxProvider}
/>
</Box>
</Box>
Expand Down
Loading
Loading