The best way to control Claude Code, Codex and more from any computer or phone

main
ts 36 lines 1.17 KB
Raw
1 import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2 import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
3
4 import { useProjects } from "~/state/entities";
5
6 import { useHandleNewThread } from "./useHandleNewThread";
7
8 export interface ActiveProjectTarget {
9 readonly environmentId: EnvironmentId;
10 readonly cwd: string;
11 readonly projectName: string;
12 readonly threadRef: ScopedThreadRef;
13 }
14
15 export function useActiveProjectTarget(): ActiveProjectTarget | null {
16 const { activeDraftThread, activeThread } = useHandleNewThread();
17 const projects = useProjects();
18 const thread = activeThread ?? activeDraftThread;
19 const threadId = activeThread?.id ?? activeDraftThread?.threadId;
20 const project = thread
21 ? projects.find(
22 (candidate) =>
23 candidate.environmentId === thread.environmentId && candidate.id === thread.projectId,
24 )
25 : null;
26 const cwd = thread?.worktreePath ?? project?.workspaceRoot;
27
28 if (!thread || !threadId || !project || !cwd) return null;
29
30 return {
31 environmentId: project.environmentId,
32 cwd,
33 projectName: project.title,
34 threadRef: scopeThreadRef(thread.environmentId, threadId),
35 };
36 }