// src/stores/gitStore.ts
import { create as create9 } from "zustand";

// src/stores/sessionFilesStore.ts
import { create as create8 } from "zustand";

// src/stores/researchStore.ts
import { create as create7 } from "zustand";

// src/stores/settingsStore.ts
import { create as create6 } from "zustand";

// src/stores/tunnelStore.ts
import { create as create5 } from "zustand";

// src/stores/fileBrowserStore.ts
import { create as create4 } from "zustand";

// src/stores/mcpStore.ts
import { create as create3 } from "zustand";

// src/stores/skillsStore.ts
import { create as create2 } from "zustand";

// src/stores/viewerTabsStore.ts
import { create } from "zustand";
function titleFromPath(path) {
  return path.split("/").pop() || path;
}
function normalizeViewerPath(path) {
  return path.trim().replace(/^a\//, "").replace(/^b\//, "").replace(/^\.\//, "").replace(/\/+/g, "/").replace(/\/+$/, "");
}
function viewerPathsMatch(left, right) {
  const normalizedLeft = normalizeViewerPath(left);
  const normalizedRight = normalizeViewerPath(right);
  return normalizedLeft === normalizedRight || normalizedLeft.endsWith(`/${normalizedRight}`) || normalizedRight.endsWith(`/${normalizedLeft}`);
}
function fileTabId(path) {
  return `file:${normalizeViewerPath(path)}`;
}
function browserTabId(kind) {
  return `browser:${kind}`;
}
function newBrowserTabId() {
  return `browser:browser:${Date.now()}:${Math.random().toString(36).slice(2)}`;
}
function modeForTab(tab) {
  return tab.type === "browser" ? "preview" : "work";
}
function findFallbackTabId(tabs, mode, closingIndex) {
  const next = tabs.slice(closingIndex).find((tab) => modeForTab(tab) === mode);
  if (next)
    return next.id;
  const previous = [...tabs].slice(0, closingIndex).reverse().find((tab) => modeForTab(tab) === mode);
  return previous?.id ?? null;
}
function activeIdForWorkUpdate(state, targetId) {
  return state.activeMode === "preview" && state.activePreviewTabId ? state.activePreviewTabId : targetId;
}
function upsertTab(tabs, tab) {
  const existingIndex = tabs.findIndex((item) => item.id === tab.id);
  if (existingIndex === -1) {
    return [...tabs, tab];
  }
  const next = [...tabs];
  next[existingIndex] = tab;
  return next;
}
function isSamePatchCall(existing, preview) {
  if (!existing)
    return false;
  if (preview.callId || existing.callId) {
    return Boolean(preview.callId && existing.callId === preview.callId);
  }
  if (preview.status === "streaming" && existing.status !== "streaming") {
    return false;
  }
  if (!preview.patch || !existing.patch)
    return existing.status === "streaming";
  return preview.patch === existing.patch || preview.patch.startsWith(existing.patch) || existing.patch.startsWith(preview.patch);
}
function mergeChangedLines(existing, incoming) {
  if (!existing?.length)
    return incoming;
  if (!incoming?.length)
    return existing;
  return [...new Set([...existing, ...incoming])].sort((a, b) => a - b);
}
function countContentLines(content) {
  return content.length === 0 ? 1 : content.split(`
`).length;
}
function annotationId(preview, targetPath) {
  return `${preview.toolName}:${preview.callId ?? `${normalizeViewerPath(targetPath)}:${preview.patch ?? preview.content ?? ""}`}`;
}
function buildAnnotation(preview, targetPath, existing) {
  if (preview.status === "error")
    return existing;
  const id = annotationId(preview, targetPath);
  if (preview.toolName === "write") {
    const content = preview.content;
    if (content === undefined)
      return existing;
    return {
      id,
      reason: "write",
      callId: preview.callId,
      status: preview.status,
      lineTones: Array.from({ length: countContentLines(content) }, (_, index) => [index + 1, "add"]),
      createdAt: existing?.createdAt ?? Date.now()
    };
  }
  const lineTones = preview.previewLineTones?.length ? preview.previewLineTones : preview.changedLines?.length ? preview.changedLines.map((line) => [line, "add"]) : existing?.lineTones;
  if (!lineTones?.length)
    return existing;
  return {
    id,
    reason: "apply_patch",
    callId: preview.callId,
    status: preview.status,
    lineTones,
    createdAt: existing?.createdAt ?? Date.now()
  };
}
function upsertAnnotation(annotations, annotation) {
  if (!annotation)
    return annotations;
  const existing = annotations ?? [];
  const index = existing.findIndex((item) => item.id === annotation.id);
  if (index === -1)
    return [...existing, annotation];
  const next = [...existing];
  next[index] = annotation;
  return next;
}
var useViewerTabsStore = create((set) => ({
  tabs: [],
  activeTabId: null,
  activeMode: "work",
  activeWorkTabId: null,
  activePreviewTabId: null,
  followToolActivity: false,
  toggleFollowToolActivity: () => set((state) => ({ followToolActivity: !state.followToolActivity })),
  setFollowToolActivity: (enabled) => set({ followToolActivity: enabled }),
  setViewerMode: (mode) => set((state) => {
    const activeTabId = mode === "preview" ? state.activePreviewTabId : state.activeWorkTabId;
    return {
      activeMode: mode,
      activeTabId: activeTabId ?? null
    };
  }),
  openGitDiffTab: (path, staged) => {
    const id = `git-diff:${staged ? "staged" : "unstaged"}:${path}`;
    set((state) => ({
      tabs: upsertTab(state.tabs, {
        id,
        type: "git-diff",
        title: titleFromPath(path),
        path,
        staged
      }),
      activeMode: "work",
      activeWorkTabId: id,
      activeTabId: id
    }));
  },
  openSessionFileDiffTab: (path, operations) => {
    const id = `session-file-diff:${path}`;
    set((state) => ({
      tabs: upsertTab(state.tabs, {
        id,
        type: "session-file-diff",
        title: titleFromPath(path),
        path,
        operations,
        selectedOperationIndex: Math.max(0, operations.length - 1)
      }),
      activeMode: "work",
      activeWorkTabId: id,
      activeTabId: id
    }));
  },
  openFileTab: (path) => {
    const id = fileTabId(path);
    set((state) => {
      const matchingFileTabs = state.tabs.filter((tab) => tab.type === "file" && viewerPathsMatch(tab.path, path));
      const existingFile = matchingFileTabs.find((tab) => tab.id === state.activeTabId) ?? matchingFileTabs[0];
      const targetId = existingFile?.id ?? id;
      const targetPath = existingFile?.path ?? path;
      const tabs = state.tabs.filter((tab) => !((tab.type === "tool-preview" || tab.type === "file") && tab.id !== targetId && viewerPathsMatch(tab.path, path)));
      return {
        tabs: upsertTab(tabs, {
          id: targetId,
          type: "file",
          title: existingFile?.title ?? titleFromPath(targetPath),
          path: targetPath,
          highlight: existingFile?.highlight,
          annotations: existingFile?.annotations,
          patchPreview: existingFile?.patchPreview,
          writePreview: existingFile?.writePreview
        }),
        activeMode: "work",
        activeWorkTabId: targetId,
        activeTabId: targetId
      };
    });
  },
  openToolReadTab: (path, highlight) => {
    const id = fileTabId(path);
    set((state) => {
      const matchingFileTabs = state.tabs.filter((tab) => tab.type === "file" && viewerPathsMatch(tab.path, path));
      const existingFile = matchingFileTabs.find((tab) => tab.id === state.activeTabId) ?? matchingFileTabs[0];
      const targetId = existingFile?.id ?? id;
      const targetPath = existingFile?.path ?? path;
      const tabs = state.tabs.filter((tab) => !((tab.type === "tool-preview" || tab.type === "file") && tab.id !== targetId && viewerPathsMatch(tab.path, path)));
      return {
        tabs: upsertTab(tabs, {
          id: targetId,
          type: "file",
          title: existingFile?.title ?? titleFromPath(targetPath),
          path: targetPath,
          highlight,
          annotations: existingFile?.annotations,
          patchPreview: undefined,
          writePreview: undefined
        }),
        activeWorkTabId: targetId,
        activeTabId: activeIdForWorkUpdate(state, targetId)
      };
    });
  },
  openToolPreviewTab: (preview) => {
    const id = fileTabId(preview.path);
    set((state) => {
      const matchingFileTabs = state.tabs.filter((tab) => tab.type === "file" && viewerPathsMatch(tab.path, preview.path));
      const existingFile = matchingFileTabs.find((tab) => tab.id === state.activeTabId) ?? matchingFileTabs[0];
      const targetId = existingFile?.id ?? id;
      const targetPath = existingFile?.path ?? preview.path;
      const existing = state.tabs.find((tab) => tab.type === "tool-preview" && viewerPathsMatch(tab.path, preview.path));
      const tabs = state.tabs.filter((tab) => !((tab.type === "tool-preview" || tab.type === "file") && tab.id !== targetId && (viewerPathsMatch(tab.path, preview.path) || Boolean(preview.callId && "toolName" in tab && tab.callId === preview.callId))));
      if (preview.toolName === "apply_patch") {
        const existingPatchPreview = existingFile?.patchPreview ?? (existing?.toolName === "apply_patch" ? existing : undefined);
        const samePatchCall = isSamePatchCall(existingPatchPreview, preview);
        const baseContent = preview.baseContent ?? (samePatchCall ? existingPatchPreview?.baseContent : existingPatchPreview?.resultContent ?? existingPatchPreview?.baseContent);
        const changedLines = samePatchCall ? preview.changedLines ?? existingPatchPreview?.changedLines : mergeChangedLines(existingPatchPreview?.changedLines, preview.changedLines);
        const annotationPreview = {
          ...preview,
          changedLines: preview.changedLines
        };
        const existingAnnotation = existingFile?.annotations?.find((annotation2) => annotation2.id === annotationId(annotationPreview, targetPath));
        const annotations = upsertAnnotation(existingFile?.annotations, buildAnnotation(annotationPreview, targetPath, existingAnnotation));
        return {
          tabs: upsertTab(tabs, {
            id: targetId,
            type: "file",
            title: existingFile?.title ?? titleFromPath(targetPath),
            path: targetPath,
            highlight: undefined,
            annotations,
            writePreview: undefined,
            patchPreview: {
              path: targetPath,
              toolName: "apply_patch",
              callId: preview.callId ?? existingPatchPreview?.callId,
              baseContent,
              patch: preview.patch ?? existingPatchPreview?.patch,
              changedLines,
              previewContent: preview.previewContent ?? (samePatchCall ? existingPatchPreview?.previewContent : undefined),
              resultContent: preview.resultContent ?? (samePatchCall ? existingPatchPreview?.resultContent : undefined),
              previewLineTones: preview.previewLineTones ?? (samePatchCall ? existingPatchPreview?.previewLineTones : undefined),
              previewFirstLine: preview.previewFirstLine ?? (samePatchCall ? existingPatchPreview?.previewFirstLine : undefined),
              previewLatestLine: preview.previewLatestLine ?? (samePatchCall ? existingPatchPreview?.previewLatestLine : undefined),
              status: preview.status,
              error: preview.error ?? existingPatchPreview?.error
            }
          }),
          activeWorkTabId: targetId,
          activeTabId: activeIdForWorkUpdate(state, targetId)
        };
      }
      if (existingFile) {
        const existingWritePreview = existingFile.writePreview;
        const existingAnnotation = existingFile.annotations?.find((annotation2) => annotation2.id === annotationId(preview, targetPath));
        const annotations = upsertAnnotation(existingFile.annotations, buildAnnotation(preview, targetPath, existingAnnotation));
        return {
          tabs: upsertTab(tabs, {
            ...existingFile,
            highlight: undefined,
            annotations,
            patchPreview: undefined,
            writePreview: {
              path: targetPath,
              toolName: "write",
              callId: preview.callId ?? existingWritePreview?.callId,
              content: preview.content ?? existingWritePreview?.content,
              changeCount: preview.changeCount ?? existingWritePreview?.changeCount,
              status: preview.status,
              error: preview.error ?? existingWritePreview?.error
            }
          }),
          activeWorkTabId: targetId,
          activeTabId: activeIdForWorkUpdate(state, targetId)
        };
      }
      const existingWrite = existing?.toolName === "write" ? existing : undefined;
      const annotation = buildAnnotation(preview, preview.path);
      return {
        tabs: upsertTab(tabs, {
          id,
          type: "file",
          title: titleFromPath(preview.path),
          path: preview.path,
          highlight: undefined,
          annotations: annotation ? [annotation] : undefined,
          patchPreview: undefined,
          writePreview: {
            path: preview.path,
            toolName: "write",
            callId: preview.callId,
            content: preview.content ?? existingWrite?.content,
            changeCount: preview.changeCount ?? existingWrite?.changeCount,
            status: preview.status,
            error: preview.error ?? existingWrite?.error
          }
        }),
        activeWorkTabId: id,
        activeTabId: activeIdForWorkUpdate(state, id)
      };
    });
  },
  openSkillFileTab: (skill, file) => {
    const displayFile = file ?? "SKILL.md";
    const id = `skill-file:${skill}:${displayFile}`;
    set((state) => ({
      tabs: upsertTab(state.tabs, {
        id,
        type: "skill-file",
        title: titleFromPath(displayFile),
        skill,
        file
      }),
      activeMode: "work",
      activeWorkTabId: id,
      activeTabId: id
    }));
  },
  openBrowserTab: (url = "", options = {}) => {
    const kind = options.kind ?? "browser";
    set((state) => {
      const shouldCreate = kind === "browser" && options.newTab === true;
      const id = shouldCreate ? newBrowserTabId() : browserTabId(kind);
      const existing = state.tabs.find((tab) => !shouldCreate && tab.type === "browser" && tab.id === id);
      return {
        tabs: upsertTab(state.tabs, {
          id,
          type: "browser",
          title: options.title ?? existing?.title ?? "Browser",
          url: url || existing?.url || "",
          kind,
          reloadKey: existing?.reloadKey ?? 0
        }),
        activeMode: "preview",
        activePreviewTabId: id,
        activeTabId: id
      };
    });
  },
  updateBrowserTabUrl: (id, url) => set((state) => ({
    tabs: state.tabs.map((tab) => tab.id === id && tab.type === "browser" ? {
      ...tab,
      url,
      title: tab.kind === "simulator" ? "Simulator" : "Browser"
    } : tab)
  })),
  reloadBrowserTab: (id) => set((state) => ({
    tabs: state.tabs.map((tab) => tab.id === id && tab.type === "browser" ? { ...tab, reloadKey: tab.reloadKey + 1 } : tab)
  })),
  setActiveTab: (id) => set((state) => {
    const tab = state.tabs.find((item) => item.id === id);
    const mode = tab ? modeForTab(tab) : state.activeMode;
    return {
      activeMode: mode,
      activeWorkTabId: mode === "work" ? id : state.activeWorkTabId,
      activePreviewTabId: mode === "preview" ? id : state.activePreviewTabId,
      activeTabId: id
    };
  }),
  closeTab: (id) => set((state) => {
    const closingIndex = state.tabs.findIndex((tab) => tab.id === id);
    const closingTab = state.tabs[closingIndex];
    const tabs = state.tabs.filter((tab) => tab.id !== id);
    let activeMode = state.activeMode;
    let activeWorkTabId = state.activeWorkTabId;
    let activePreviewTabId = state.activePreviewTabId;
    if (closingTab && modeForTab(closingTab) === "work" && activeWorkTabId === id) {
      activeWorkTabId = findFallbackTabId(tabs, "work", closingIndex);
    }
    if (closingTab && modeForTab(closingTab) === "preview" && activePreviewTabId === id) {
      activePreviewTabId = findFallbackTabId(tabs, "preview", closingIndex);
    }
    if (activeMode === "work" && !activeWorkTabId && activePreviewTabId) {
      activeMode = "preview";
    }
    if (activeMode === "preview" && !activePreviewTabId && activeWorkTabId) {
      activeMode = "work";
    }
    return {
      tabs,
      activeMode,
      activeWorkTabId,
      activePreviewTabId,
      activeTabId: activeMode === "preview" ? activePreviewTabId : activeWorkTabId
    };
  }),
  updateSessionFileOperationIndex: (id, index) => set((state) => ({
    tabs: state.tabs.map((tab) => tab.id === id && tab.type === "session-file-diff" ? { ...tab, selectedOperationIndex: index } : tab)
  })),
  closeAllTabs: () => set({
    tabs: [],
    activeTabId: null,
    activeMode: "work",
    activeWorkTabId: null,
    activePreviewTabId: null
  })
}));

// src/stores/skillsStore.ts
var useSkillsStore = create2((set, get) => ({
  isExpanded: false,
  skills: [],
  globalEnabled: true,
  totalCount: 0,
  enabledCount: 0,
  selectedSkill: null,
  isViewerOpen: false,
  viewingFile: null,
  toggleSidebar: () => {
    set((state) => {
      const newExpanded = !state.isExpanded;
      if (newExpanded) {
        useGitStore.getState().collapseSidebar();
        useSessionFilesStore.getState().collapseSidebar();
        useResearchStore.getState().collapseSidebar();
        useSettingsStore.getState().collapseSidebar();
        useTunnelStore.getState().collapseSidebar();
        useFileBrowserStore.getState().collapseSidebar();
        useMCPStore.getState().collapseSidebar();
      }
      return { isExpanded: newExpanded };
    });
  },
  expandSidebar: () => {
    useGitStore.getState().collapseSidebar();
    useSessionFilesStore.getState().collapseSidebar();
    useResearchStore.getState().collapseSidebar();
    useSettingsStore.getState().collapseSidebar();
    useTunnelStore.getState().collapseSidebar();
    useFileBrowserStore.getState().collapseSidebar();
    useMCPStore.getState().collapseSidebar();
    set({ isExpanded: true });
  },
  collapseSidebar: () => set({ isExpanded: false }),
  setSkills: (skills) => set({ skills }),
  setSkillsConfig: ({ skills, globalEnabled, totalCount, enabledCount }) => set({ skills, globalEnabled, totalCount, enabledCount }),
  selectSkill: (name) => {
    if (name) {
      useViewerTabsStore.getState().openSkillFileTab(name, null);
      set({ selectedSkill: name, isViewerOpen: true, viewingFile: null });
      return;
    }
    set({ selectedSkill: null, isViewerOpen: false, viewingFile: null });
  },
  openViewer: (file) => {
    const selectedSkill = get().selectedSkill;
    if (selectedSkill) {
      useViewerTabsStore.getState().openSkillFileTab(selectedSkill, file);
    }
    set({ isViewerOpen: true, viewingFile: file });
  },
  closeViewer: () => set({ isViewerOpen: false, viewingFile: null })
}));

// src/stores/mcpStore.ts
var useMCPStore = create3((set) => ({
  isExpanded: false,
  servers: [],
  loading: new Set,
  authUrls: new Map,
  copilotDevice: null,
  toggleSidebar: () => {
    set((state) => {
      const newExpanded = !state.isExpanded;
      if (newExpanded) {
        useGitStore.getState().collapseSidebar();
        useSessionFilesStore.getState().collapseSidebar();
        useResearchStore.getState().collapseSidebar();
        useSettingsStore.getState().collapseSidebar();
        useTunnelStore.getState().collapseSidebar();
        useFileBrowserStore.getState().collapseSidebar();
        useSkillsStore.getState().collapseSidebar();
      }
      return { isExpanded: newExpanded };
    });
  },
  expandSidebar: () => {
    useGitStore.getState().collapseSidebar();
    useSessionFilesStore.getState().collapseSidebar();
    useResearchStore.getState().collapseSidebar();
    useSettingsStore.getState().collapseSidebar();
    useTunnelStore.getState().collapseSidebar();
    useFileBrowserStore.getState().collapseSidebar();
    useSkillsStore.getState().collapseSidebar();
    set({ isExpanded: true });
  },
  collapseSidebar: () => set({ isExpanded: false }),
  setServers: (servers) => set({ servers }),
  setLoading: (name, loading) => set((state) => {
    const next = new Set(state.loading);
    if (loading)
      next.add(name);
    else
      next.delete(name);
    return { loading: next };
  }),
  updateServer: (name, updates) => set((state) => ({
    servers: state.servers.map((s) => s.name === name ? { ...s, ...updates } : s)
  })),
  setAuthUrl: (name, url) => set((state) => {
    const next = new Map(state.authUrls);
    if (url)
      next.set(name, url);
    else
      next.delete(name);
    return { authUrls: next };
  }),
  setCopilotDevice: (info) => set({ copilotDevice: info })
}));

// src/stores/fileBrowserStore.ts
function getAncestorDirs(path) {
  const normalizedPath = path.replace(/\\/g, "/").replace(/^\.\//, "");
  const parts = normalizedPath.split("/").filter(Boolean);
  return parts.slice(0, -1).map((_, index) => parts.slice(0, index + 1).join("/"));
}
function revealFileState(state, path) {
  const expandedDirs = new Set(state.expandedDirs);
  for (const dir of getAncestorDirs(path)) {
    expandedDirs.add(dir);
  }
  return {
    selectedFile: path,
    expandedDirs
  };
}
var useFileBrowserStore = create4((set) => ({
  isExpanded: false,
  selectedFile: null,
  isViewerOpen: false,
  expandedDirs: new Set,
  toggleSidebar: () => {
    set((state) => {
      const newExpanded = !state.isExpanded;
      if (newExpanded) {
        useGitStore.getState().collapseSidebar();
        useSessionFilesStore.getState().collapseSidebar();
        useResearchStore.getState().collapseSidebar();
        useSettingsStore.getState().collapseSidebar();
        useTunnelStore.getState().collapseSidebar();
        useMCPStore.getState().collapseSidebar();
        useSkillsStore.getState().collapseSidebar();
      }
      return { isExpanded: newExpanded };
    });
  },
  expandSidebar: () => {
    useGitStore.getState().collapseSidebar();
    useSessionFilesStore.getState().collapseSidebar();
    useResearchStore.getState().collapseSidebar();
    useSettingsStore.getState().collapseSidebar();
    useTunnelStore.getState().collapseSidebar();
    useMCPStore.getState().collapseSidebar();
    useSkillsStore.getState().collapseSidebar();
    set({ isExpanded: true });
  },
  collapseSidebar: () => set({
    isExpanded: false,
    isViewerOpen: false,
    selectedFile: null
  }),
  openFile: (path) => {
    useViewerTabsStore.getState().openFileTab(path);
    set((state) => ({
      ...revealFileState(state, path),
      isViewerOpen: true
    }));
  },
  revealFile: (path) => set((state) => revealFileState(state, path)),
  closeViewer: () => set({
    isViewerOpen: false,
    selectedFile: null
  }),
  toggleDir: (path) => set((state) => {
    const next = new Set(state.expandedDirs);
    if (next.has(path)) {
      next.delete(path);
    } else {
      next.add(path);
    }
    return { expandedDirs: next };
  })
}));

// src/stores/tunnelStore.ts
var useTunnelStore = create5((set) => ({
  isExpanded: false,
  status: "idle",
  url: null,
  qrCode: null,
  error: null,
  progress: null,
  toggleSidebar: () => {
    set((state) => {
      const newExpanded = !state.isExpanded;
      if (newExpanded) {
        useGitStore.getState().collapseSidebar();
        useSessionFilesStore.getState().collapseSidebar();
        useSettingsStore.getState().collapseSidebar();
        useResearchStore.getState().collapseSidebar();
        useFileBrowserStore.getState().collapseSidebar();
        useMCPStore.getState().collapseSidebar();
        useSkillsStore.getState().collapseSidebar();
      }
      return { isExpanded: newExpanded };
    });
  },
  expandSidebar: () => {
    useGitStore.getState().collapseSidebar();
    useSessionFilesStore.getState().collapseSidebar();
    useSettingsStore.getState().collapseSidebar();
    useResearchStore.getState().collapseSidebar();
    useFileBrowserStore.getState().collapseSidebar();
    useMCPStore.getState().collapseSidebar();
    useSkillsStore.getState().collapseSidebar();
    set({ isExpanded: true });
  },
  collapseSidebar: () => set({ isExpanded: false }),
  setStatus: (status) => set({ status }),
  setUrl: (url) => set({ url }),
  setQrCode: (qrCode) => set({ qrCode }),
  setError: (error) => set({ error }),
  setProgress: (progress) => set({ progress }),
  reset: () => set({
    status: "idle",
    url: null,
    qrCode: null,
    error: null,
    progress: null
  })
}));

// src/stores/settingsStore.ts
var useSettingsStore = create6((set) => ({
  isExpanded: false,
  toggleSidebar: () => {
    set((state) => {
      const newExpanded = !state.isExpanded;
      if (newExpanded) {
        useGitStore.getState().collapseSidebar();
        useSessionFilesStore.getState().collapseSidebar();
        useResearchStore.getState().collapseSidebar();
        useTunnelStore.getState().collapseSidebar();
        useFileBrowserStore.getState().collapseSidebar();
        useMCPStore.getState().collapseSidebar();
        useSkillsStore.getState().collapseSidebar();
      }
      return { isExpanded: newExpanded };
    });
  },
  expandSidebar: () => set({ isExpanded: true }),
  collapseSidebar: () => set({ isExpanded: false })
}));

// src/stores/researchStore.ts
var useResearchStore = create7((set, get) => ({
  isExpanded: false,
  activeResearchSessionId: null,
  parentSessionId: null,
  toggleSidebar: () => {
    set((state) => {
      const newExpanded = !state.isExpanded;
      if (newExpanded) {
        useGitStore.getState().collapseSidebar();
        useSessionFilesStore.getState().collapseSidebar();
        useSettingsStore.getState().collapseSidebar();
        useTunnelStore.getState().collapseSidebar();
        useFileBrowserStore.getState().collapseSidebar();
        useMCPStore.getState().collapseSidebar();
        useSkillsStore.getState().collapseSidebar();
      }
      return { isExpanded: newExpanded };
    });
  },
  expandSidebar: () => {
    useGitStore.getState().collapseSidebar();
    useSessionFilesStore.getState().collapseSidebar();
    useSettingsStore.getState().collapseSidebar();
    useTunnelStore.getState().collapseSidebar();
    useFileBrowserStore.getState().collapseSidebar();
    useMCPStore.getState().collapseSidebar();
    useSkillsStore.getState().collapseSidebar();
    set({ isExpanded: true });
  },
  collapseSidebar: () => set({ isExpanded: false }),
  selectResearchSession: (id) => set({ activeResearchSessionId: id }),
  setParentSessionId: (id) => {
    const currentParentId = get().parentSessionId;
    if (currentParentId !== id) {
      set({
        parentSessionId: id,
        activeResearchSessionId: null
      });
    }
  },
  reset: () => set({
    activeResearchSessionId: null,
    parentSessionId: null
  })
}));

// src/stores/sessionFilesStore.ts
var useSessionFilesStore = create8((set) => ({
  isExpanded: false,
  selectedFile: null,
  allOperations: [],
  selectedOperationIndex: 0,
  isDiffOpen: false,
  toggleSidebar: () => {
    set((state) => {
      const newExpanded = !state.isExpanded;
      if (newExpanded) {
        useGitStore.getState().collapseSidebar();
        useResearchStore.getState().collapseSidebar();
        useSettingsStore.getState().collapseSidebar();
        useTunnelStore.getState().collapseSidebar();
        useFileBrowserStore.getState().collapseSidebar();
        useMCPStore.getState().collapseSidebar();
        useSkillsStore.getState().collapseSidebar();
      }
      return { isExpanded: newExpanded };
    });
  },
  expandSidebar: () => {
    useGitStore.getState().collapseSidebar();
    useResearchStore.getState().collapseSidebar();
    useSettingsStore.getState().collapseSidebar();
    useTunnelStore.getState().collapseSidebar();
    useFileBrowserStore.getState().collapseSidebar();
    useMCPStore.getState().collapseSidebar();
    useSkillsStore.getState().collapseSidebar();
    set({ isExpanded: true });
  },
  collapseSidebar: () => set({
    isExpanded: false,
    isDiffOpen: false,
    selectedFile: null,
    allOperations: [],
    selectedOperationIndex: 0
  }),
  openDiff: (file, operations) => {
    useViewerTabsStore.getState().openSessionFileDiffTab(file, operations);
    set({
      selectedFile: file,
      allOperations: operations,
      selectedOperationIndex: operations.length - 1,
      isDiffOpen: true,
      isExpanded: true
    });
  },
  selectOperation: (index) => set({ selectedOperationIndex: index }),
  closeDiff: () => set({
    isDiffOpen: false,
    selectedFile: null,
    allOperations: [],
    selectedOperationIndex: 0
  })
}));

// src/stores/gitStore.ts
var GIT_TREE_SECTION_ORDER = ["conflicts", "staged", "changes"];
function areGitTreeRowsEqual(left = [], right = []) {
  if (left.length !== right.length)
    return false;
  return left.every((row, index) => {
    const other = right[index];
    return row.id === other.id && row.type === other.type && row.path === other.path && row.staged === other.staged && row.status === other.status && row.actionPaths.length === other.actionPaths.length && row.actionPaths.every((path, pathIndex) => path === other.actionPaths[pathIndex]);
  });
}
var useGitStore = create9((set) => ({
  isExpanded: false,
  activeSessionId: null,
  selectedFile: null,
  selectedFileStaged: false,
  isDiffOpen: false,
  isCommitModalOpen: false,
  commitSessionId: null,
  wasSessionListCollapsed: false,
  gitTreeSections: {},
  gitTreeRows: [],
  toggleSidebar: () => {
    set((state) => {
      const newExpanded = !state.isExpanded;
      if (newExpanded) {
        useSessionFilesStore.getState().collapseSidebar();
        useResearchStore.getState().collapseSidebar();
        useSettingsStore.getState().collapseSidebar();
        useTunnelStore.getState().collapseSidebar();
        useFileBrowserStore.getState().collapseSidebar();
        useMCPStore.getState().collapseSidebar();
        useSkillsStore.getState().collapseSidebar();
      }
      return { isExpanded: newExpanded };
    });
  },
  expandSidebar: () => set({ isExpanded: true }),
  collapseSidebar: () => set({ isExpanded: false, isDiffOpen: false, selectedFile: null }),
  openDiff: (file, staged) => {
    useViewerTabsStore.getState().openGitDiffTab(file, staged);
    set({
      selectedFile: file,
      selectedFileStaged: staged,
      isDiffOpen: true,
      isExpanded: true
    });
  },
  closeDiff: () => set({
    isDiffOpen: false,
    selectedFile: null
  }),
  switchFile: (file, staged) => set({
    selectedFile: file,
    selectedFileStaged: staged
  }),
  openCommitModal: () => set((state) => ({
    isCommitModalOpen: true,
    commitSessionId: state.activeSessionId
  })),
  openCommitModalForSession: (sessionId) => set({ isCommitModalOpen: true, commitSessionId: sessionId }),
  closeCommitModal: () => set({ isCommitModalOpen: false, commitSessionId: null }),
  setActiveSessionId: (sessionId) => set({ activeSessionId: sessionId }),
  setSessionListCollapsed: (collapsed) => set({ wasSessionListCollapsed: collapsed }),
  setGitTreeSectionRows: (sectionId, rows) => set((state) => {
    if (areGitTreeRowsEqual(state.gitTreeSections[sectionId], rows)) {
      return state;
    }
    const gitTreeSections = {
      ...state.gitTreeSections,
      [sectionId]: rows
    };
    const gitTreeRows = GIT_TREE_SECTION_ORDER.flatMap((id) => gitTreeSections[id] ?? []);
    return { gitTreeSections, gitTreeRows };
  })
}));
// src/stores/sidebarStore.ts
import { create as create10 } from "zustand";
import { persist } from "zustand/middleware";
var useSidebarStore = create10()(persist((set) => ({
  isCollapsed: false,
  toggleCollapse: () => set((state) => ({ isCollapsed: !state.isCollapsed })),
  setCollapsed: (collapsed) => set({ isCollapsed: collapsed })
}), {
  name: "sidebar-storage"
}));
// src/stores/focusStore.ts
import { create as create11 } from "zustand";
var useFocusStore = create11((set) => ({
  currentFocus: null,
  sessionIndex: 0,
  gitFileIndex: 0,
  setFocus: (area) => set({ currentFocus: area }),
  setSessionIndex: (index) => set({ sessionIndex: index }),
  setGitFileIndex: (index) => set({ gitFileIndex: index }),
  resetGitFileIndex: () => set({ gitFileIndex: 0 }),
  resetSessionIndex: () => set({ sessionIndex: 0 })
}));
// src/stores/confirmationStore.ts
import { create as create12 } from "zustand";
var useConfirmationStore = create12((set) => ({
  isOpen: false,
  title: "Confirm Action",
  message: "",
  confirmLabel: "Confirm",
  cancelLabel: "Cancel",
  variant: "default",
  onConfirm: () => {},
  onCancel: undefined,
  openConfirmation: (options) => set({
    isOpen: true,
    title: options.title || "Confirm Action",
    message: options.message,
    confirmLabel: options.confirmLabel || "Confirm",
    cancelLabel: options.cancelLabel || "Cancel",
    variant: options.variant || "default",
    onConfirm: options.onConfirm,
    onCancel: options.onCancel
  }),
  closeConfirmation: () => set({
    isOpen: false,
    onConfirm: () => {},
    onCancel: undefined
  })
}));
// src/stores/queueStore.ts
import { create as create13 } from "zustand";
var useQueueStore = create13((set, get) => ({
  pendingRestoreText: null,
  setPendingRestoreText: (text) => set({ pendingRestoreText: text }),
  consumeRestoreText: () => {
    const text = get().pendingRestoreText;
    set({ pendingRestoreText: null });
    return text;
  }
}));
// src/stores/pendingResearchStore.ts
import { create as create14 } from "zustand";
var usePendingResearchStore = create14((set, get) => ({
  pendingContexts: new Map,
  addContext: (parentSessionId, context) => {
    set((state) => {
      const newMap = new Map(state.pendingContexts);
      const existing = newMap.get(parentSessionId) || [];
      if (!existing.some((c) => c.id === context.id)) {
        newMap.set(parentSessionId, [...existing, context]);
      }
      return { pendingContexts: newMap };
    });
  },
  removeContext: (parentSessionId, contextId) => {
    set((state) => {
      const newMap = new Map(state.pendingContexts);
      const existing = newMap.get(parentSessionId) || [];
      newMap.set(parentSessionId, existing.filter((c) => c.id !== contextId));
      return { pendingContexts: newMap };
    });
  },
  getContexts: (parentSessionId) => {
    return get().pendingContexts.get(parentSessionId) || [];
  },
  clearContexts: (parentSessionId) => {
    set((state) => {
      const newMap = new Map(state.pendingContexts);
      newMap.delete(parentSessionId);
      return { pendingContexts: newMap };
    });
  },
  consumeContexts: (parentSessionId) => {
    const contexts = get().getContexts(parentSessionId);
    get().clearContexts(parentSessionId);
    return contexts;
  }
}));
// src/stores/toastStore.ts
import { create as create15 } from "zustand";
var toastId = 0;
var useToastStore = create15((set) => ({
  toasts: [],
  addToast: (toast) => {
    const id = `toast-${++toastId}`;
    set((state) => ({
      toasts: [...state.toasts, { ...toast, id }]
    }));
    return id;
  },
  removeToast: (id) => set((state) => ({
    toasts: state.toasts.filter((t) => t.id !== id)
  })),
  updateToast: (id, updates) => set((state) => ({
    toasts: state.toasts.map((t) => t.id === id ? { ...t, ...updates } : t)
  })),
  clearToasts: () => set({ toasts: [] })
}));
function toast(message, type = "default", duration = 4000) {
  const id = useToastStore.getState().addToast({ message, type, duration });
  if (duration > 0) {
    setTimeout(() => {
      useToastStore.getState().removeToast(id);
    }, duration);
  }
  return id;
}
toast.success = (message, duration = 4000) => toast(message, "success", duration);
toast.error = (message, duration = 5000) => toast(message, "error", duration);
toast.info = (message, duration = 4000) => toast(message, "default", duration);
toast.loading = (message) => toast(message, "loading", 0);
toast.successWithAction = (message, action, duration = 6000) => {
  const id = useToastStore.getState().addToast({
    message,
    type: "success",
    duration,
    action
  });
  if (duration > 0) {
    setTimeout(() => {
      useToastStore.getState().removeToast(id);
    }, duration);
  }
  return id;
};
// src/stores/ottorouterStore.ts
import { create as create16 } from "zustand";
var useOttoRouterStore = create16((set) => ({
  balance: null,
  usdcBalance: null,
  network: "mainnet",
  isPaymentPending: false,
  lastPaymentAmount: null,
  walletAddress: null,
  isLoading: false,
  isTopupModalOpen: false,
  scope: null,
  payg: null,
  subscription: null,
  limits: null,
  setBalance: (balance) => set({ balance }),
  setUsdcBalance: (usdcBalance) => set({ usdcBalance }),
  setNetwork: (network) => set({ network }),
  setPaymentPending: (isPaymentPending) => set({ isPaymentPending }),
  setLastPaymentAmount: (lastPaymentAmount) => set({ lastPaymentAmount }),
  setWalletAddress: (walletAddress) => set({ walletAddress }),
  setLoading: (isLoading) => set({ isLoading }),
  openTopupModal: () => set({ isTopupModalOpen: true }),
  closeTopupModal: () => set({ isTopupModalOpen: false }),
  setScope: (scope) => set({ scope }),
  setPayg: (payg) => set({ payg }),
  setSubscription: (subscription) => set({ subscription }),
  setLimits: (limits) => set({ limits })
}));
// src/stores/toolApprovalStore.ts
import { create as create17 } from "zustand";
var useToolApprovalStore = create17((set) => ({
  pendingApprovals: [],
  addPendingApproval: (approval) => set((state) => ({
    pendingApprovals: [...state.pendingApprovals, approval]
  })),
  removePendingApproval: (callId) => set((state) => ({
    pendingApprovals: state.pendingApprovals.filter((a) => a.callId !== callId)
  })),
  updatePendingApproval: (callId, args) => set((state) => ({
    pendingApprovals: state.pendingApprovals.map((a) => a.callId === callId ? { ...a, args } : a)
  })),
  clearPendingApprovals: () => set({ pendingApprovals: [] }),
  setPendingApprovals: (approvals) => set({ pendingApprovals: approvals })
}));
// src/stores/secureInputStore.ts
import { create as create18 } from "zustand";
var useSecureInputStore = create18((set) => ({
  pendingInputs: [],
  addPendingInput: (input) => set((state) => ({
    pendingInputs: [
      ...state.pendingInputs.filter((item) => item.promptId !== input.promptId),
      input
    ]
  })),
  removePendingInput: (promptId) => set((state) => ({
    pendingInputs: state.pendingInputs.filter((input) => input.promptId !== promptId)
  })),
  setPendingInputs: (inputs) => set({ pendingInputs: inputs }),
  clearPendingInputs: () => set({ pendingInputs: [] })
}));
// src/stores/topupApprovalStore.ts
import { create as create19 } from "zustand";
var useTopupApprovalStore = create19((set) => ({
  pendingTopup: null,
  isProcessing: false,
  selectedMethod: null,
  setPendingTopup: (pendingTopup) => set({ pendingTopup, isProcessing: false, selectedMethod: null }),
  setProcessing: (isProcessing) => set({ isProcessing }),
  setSelectedMethod: (selectedMethod) => set({ selectedMethod }),
  clearPendingTopup: () => set({ pendingTopup: null, isProcessing: false, selectedMethod: null })
}));
// src/stores/todoStore.ts
import { create as create20 } from "zustand";
var useTodoStore = create20((set) => ({
  todosBySession: {},
  setSessionTodos: (sessionId, snapshot) => set((state) => ({
    todosBySession: {
      ...state.todosBySession,
      [sessionId]: snapshot ? {
        ...snapshot,
        updatedAt: Date.now()
      } : undefined
    }
  })),
  clearSessionTodos: (sessionId) => set((state) => ({
    todosBySession: {
      ...state.todosBySession,
      [sessionId]: undefined
    }
  }))
}));
// src/stores/onboardingStore.ts
import { create as create21 } from "zustand";
var STEPS = ["wallet", "defaults"];
var useOnboardingStore = create21((set, get) => ({
  isOpen: false,
  currentStep: "wallet",
  manageMode: false,
  isLoading: false,
  error: null,
  authStatus: null,
  setOpen: (isOpen) => set({ isOpen }),
  setStep: (currentStep) => set({ currentStep }),
  setManageMode: (manageMode) => set({ manageMode }),
  setLoading: (isLoading) => set({ isLoading }),
  setError: (error) => set({ error }),
  setAuthStatus: (authStatus) => set({ authStatus }),
  nextStep: () => {
    const { currentStep } = get();
    const currentIndex = STEPS.indexOf(currentStep);
    if (currentIndex < STEPS.length - 1) {
      set({ currentStep: STEPS[currentIndex + 1] });
    }
  },
  prevStep: () => {
    const { currentStep } = get();
    const currentIndex = STEPS.indexOf(currentStep);
    if (currentIndex > 0) {
      set({ currentStep: STEPS[currentIndex - 1] });
    }
  },
  reset: () => set({
    isOpen: false,
    currentStep: "wallet",
    manageMode: false,
    isLoading: false,
    error: null
  })
}));
// src/stores/panelWidthStore.ts
import { create as create22 } from "zustand";
import { persist as persist2 } from "zustand/middleware";
var usePanelWidthStore = create22()(persist2((set, get) => ({
  widths: {},
  setWidth: (key, width) => set((state) => ({
    widths: { ...state.widths, [key]: width }
  })),
  getWidth: (key, defaultWidth) => get().widths[key] ?? defaultWidth
}), {
  name: "panel-widths"
}));
// src/stores/usageStore.ts
import { create as create23 } from "zustand";
var useUsageStore = create23((set) => ({
  usage: {},
  isLoading: {},
  lastFetched: {},
  isModalOpen: false,
  modalProvider: null,
  setUsage: (provider, data) => set((s) => ({ usage: { ...s.usage, [provider]: data } })),
  setLoading: (provider, loading) => set((s) => ({ isLoading: { ...s.isLoading, [provider]: loading } })),
  setLastFetched: (provider, time) => set((s) => ({ lastFetched: { ...s.lastFetched, [provider]: time } })),
  openModal: (provider) => set({ isModalOpen: true, modalProvider: provider }),
  closeModal: () => set({ isModalOpen: false, modalProvider: null })
}));
// src/stores/filePickerStore.ts
import { create as create24 } from "zustand";
var useFilePickerStore = create24((set) => ({
  isOpen: false,
  open: () => set({ isOpen: true }),
  close: () => set({ isOpen: false }),
  toggle: () => set((state) => ({ isOpen: !state.isOpen }))
}));
// src/stores/rightRailStore.ts
import { create as create25 } from "zustand";
import { persist as persist3 } from "zustand/middleware";
var useRightRailStore = create25()(persist3((set) => ({
  isPinned: false,
  togglePinned: () => set((state) => ({ isPinned: !state.isPinned })),
  setPinned: (pinned) => set({ isPinned: pinned })
}), {
  name: "right-rail-storage"
}));
// src/stores/terminalStore.ts
import { create as create26 } from "zustand";
var DEFAULT_HEIGHT = 300;
var MIN_HEIGHT = 150;
var useTerminalStore = create26((set) => ({
  isOpen: false,
  panelHeight: DEFAULT_HEIGHT,
  activeTabId: null,
  isMaximized: false,
  get isExpanded() {
    return this.isOpen;
  },
  get selectedTerminalId() {
    return this.activeTabId;
  },
  openPanel: () => set({ isOpen: true }),
  closePanel: () => set({ isOpen: false, isMaximized: false }),
  togglePanel: () => set((s) => ({
    isOpen: !s.isOpen,
    isMaximized: !s.isOpen ? s.isMaximized : false
  })),
  setPanelHeight: (height) => set({ panelHeight: Math.max(MIN_HEIGHT, height) }),
  selectTab: (id) => set({ activeTabId: id, isOpen: true }),
  toggleMaximize: () => set((s) => ({ isMaximized: !s.isMaximized })),
  expandSidebar: () => set({ isOpen: true }),
  collapseSidebar: () => set({ isOpen: false, activeTabId: null, isMaximized: false }),
  toggleSidebar: () => set((s) => ({
    isOpen: !s.isOpen,
    isMaximized: !s.isOpen ? s.isMaximized : false
  })),
  selectTerminal: (id) => set({ activeTabId: id, isOpen: true })
}));
export {
  useViewerTabsStore,
  useUsageStore,
  useTunnelStore,
  useTopupApprovalStore,
  useToolApprovalStore,
  useTodoStore,
  useToastStore,
  useTerminalStore,
  useSkillsStore,
  useSidebarStore,
  useSettingsStore,
  useSessionFilesStore,
  useSecureInputStore,
  useRightRailStore,
  useResearchStore,
  useQueueStore,
  usePendingResearchStore,
  usePanelWidthStore,
  useOttoRouterStore,
  useOnboardingStore,
  useMCPStore,
  useGitStore,
  useFocusStore,
  useFilePickerStore,
  useFileBrowserStore,
  useConfirmationStore,
  toast
};

//# debugId=1E5AA746BAA462B864756E2164756E21
