mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
feat: create new session with yolo mode (#13)
* feat: create new session with yolo mode Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix: harden sequence typecheck * feat: add unified --yolo flag across all agents --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com> Co-authored-by: weishu <twsxtd@gmail.com>
This commit is contained in:
@@ -227,10 +227,15 @@ export class ApiClient {
|
||||
return await this.request<MachinesResponse>('/api/machines')
|
||||
}
|
||||
|
||||
async spawnSession(machineId: string, directory: string, agent?: 'claude' | 'codex' | 'gemini'): Promise<SpawnResponse> {
|
||||
async spawnSession(
|
||||
machineId: string,
|
||||
directory: string,
|
||||
agent?: 'claude' | 'codex' | 'gemini',
|
||||
yolo?: boolean
|
||||
): Promise<SpawnResponse> {
|
||||
return await this.request<SpawnResponse>(`/api/machines/${encodeURIComponent(machineId)}/spawn`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ directory, agent })
|
||||
body: JSON.stringify({ directory, agent, yolo })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ export function NewSession(props: {
|
||||
const [machineId, setMachineId] = useState<string | null>(null)
|
||||
const [directory, setDirectory] = useState('')
|
||||
const [agent, setAgent] = useState<AgentType>('claude')
|
||||
const [yoloMode, setYoloMode] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
// Initialize with last used machine or first available
|
||||
@@ -83,6 +84,7 @@ export function NewSession(props: {
|
||||
machineId,
|
||||
directory: directory.trim(),
|
||||
agent,
|
||||
yolo: yoloMode
|
||||
})
|
||||
|
||||
if (result.type === 'success') {
|
||||
@@ -194,6 +196,34 @@ export function NewSession(props: {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* YOLO Mode */}
|
||||
<div className="flex flex-col gap-1.5 px-3 py-3">
|
||||
<label className="text-xs font-medium text-[var(--app-hint)]">
|
||||
YOLO mode
|
||||
</label>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm text-[var(--app-fg)]">
|
||||
Bypass approvals and sandbox
|
||||
</span>
|
||||
<span className="text-xs text-[var(--app-hint)]">
|
||||
Uses dangerous agent flags when spawning.
|
||||
</span>
|
||||
</div>
|
||||
<label className="relative inline-flex h-5 w-9 items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={yoloMode}
|
||||
onChange={(e) => setYoloMode(e.target.checked)}
|
||||
disabled={isFormDisabled}
|
||||
className="peer sr-only"
|
||||
/>
|
||||
<span className="absolute inset-0 rounded-full bg-[var(--app-border)] transition-colors peer-checked:bg-[var(--app-link)] peer-disabled:opacity-50" />
|
||||
<span className="absolute left-0.5 h-4 w-4 rounded-full bg-[var(--app-bg)] transition-transform peer-checked:translate-x-4 peer-disabled:opacity-50" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Error Message */}
|
||||
{(error ?? spawnError) ? (
|
||||
<div className="px-3 py-2 text-sm text-red-600">
|
||||
|
||||
@@ -7,6 +7,7 @@ type SpawnInput = {
|
||||
machineId: string
|
||||
directory: string
|
||||
agent?: 'claude' | 'codex' | 'gemini'
|
||||
yolo?: boolean
|
||||
}
|
||||
|
||||
export function useSpawnSession(api: ApiClient | null): {
|
||||
@@ -21,7 +22,7 @@ export function useSpawnSession(api: ApiClient | null): {
|
||||
if (!api) {
|
||||
throw new Error('API unavailable')
|
||||
}
|
||||
return await api.spawnSession(input.machineId, input.directory, input.agent)
|
||||
return await api.spawnSession(input.machineId, input.directory, input.agent, input.yolo)
|
||||
},
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.sessions })
|
||||
|
||||
Reference in New Issue
Block a user