Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

79 lines
2.5 KiB
TypeScript

import { useEffect, useState } from "react";
import { useOptionalAgentHostApi } from "../../../agentActivityHost";
import type { AgentGUIAgentTarget } from "../../../types";
import type { AgentGUISessionLaunchMode } from "../model/agentSessionLaunchMode";
export interface SessionWorktreeLaunchState {
mode: AgentGUISessionLaunchMode;
visible: boolean;
onModeChange: (mode: AgentGUISessionLaunchMode) => void;
}
export function useSessionWorktreeLaunch(input: {
agentSessionId?: string | null;
enabled?: boolean;
mode?: AgentGUISessionLaunchMode;
onModeChange?: (mode: AgentGUISessionLaunchMode) => void | Promise<void>;
projectSectionKey?: string | null;
selectedAgentTarget?: AgentGUIAgentTarget | null;
selectedProjectPath?: string | null;
}): SessionWorktreeLaunchState {
const hostApi = useOptionalAgentHostApi();
const [support, setSupport] = useState<{
key: string;
supported: boolean;
} | null>(null);
const agentTargetId =
input.selectedAgentTarget?.agentTargetId?.trim() ||
input.selectedAgentTarget?.targetId.trim() ||
"";
const cwd = input.selectedProjectPath?.trim() ?? "";
const projectSectionKey = input.projectSectionKey?.trim() ?? "";
const resolveSupport = hostApi?.workspace.resolveSessionWorktreeSupport;
const eligible =
input.enabled === true &&
!input.agentSessionId?.trim() &&
input.selectedAgentTarget?.ownership === "self" &&
Boolean(agentTargetId && cwd && projectSectionKey) &&
typeof resolveSupport === "function" &&
typeof input.onModeChange === "function";
const probeKey = eligible ? `${agentTargetId}\u0000${cwd}` : "";
useEffect(() => {
let active = true;
if (!eligible) {
return () => {
active = false;
};
}
void Promise.resolve(resolveSupport!({ agentTargetId, cwd }))
.then((result) => {
if (active) {
setSupport({ key: probeKey, supported: result.supported === true });
}
})
.catch(() => {
if (active) {
setSupport({ key: probeKey, supported: false });
}
});
return () => {
active = false;
};
}, [agentTargetId, cwd, eligible, probeKey, resolveSupport]);
const visible =
eligible && support?.key === probeKey && support.supported === true;
const mode = visible && input.mode === "worktree" ? "worktree" : "local";
return {
mode,
visible,
onModeChange: (nextMode) => {
if (!visible || nextMode === mode) {
return;
}
void input.onModeChange?.(nextMode);
}
};
}