diff --git a/.agents/commands/create-plan-file.md b/.agents/commands/create-plan-file.md new file mode 100644 index 00000000000..3b092d269ed --- /dev/null +++ b/.agents/commands/create-plan-file.md @@ -0,0 +1,271 @@ +# Superset Execution Plans (ExecPlans): + +> **DO NOT EDIT THIS FILE** +> This file is the ExecPlan template and guide only. +> Create plans in the appropriate location: +> - **App-specific work**: `apps//.agents/plans/-.md` +> - **Package work**: `packages//.agents/plans/-.md` +> - **Cross-app/shared work**: `.agents/plans/-.md` (root) + +This document describes the requirements for an execution plan ("ExecPlan"), a design document that a coding agent can follow to deliver a working feature or system change. Treat the reader as a complete beginner to this repository: they have only the current working tree and the single ExecPlan file you provide. There is no memory of prior plans and no external context. + +## Process + +Steps: +1. Discovery & Orientation: map the repo, name the scope, enumerate unknowns. Capture initial Assumptions and Open Questions in the ExecPlan. +2. Question-driven Clarification: ask focused, acceptance-oriented questions grouped by plan section. Maintain the Open Questions list in the ExecPlan and pre-link each item to a Decision Log placeholder. +3. Draft the Plan: complete the ExecPlan skeleton end-to-end (Purpose, Context, Plan of Work, Validation, Idempotence, etc.), calling out risks and dependencies. +4. Resolve Questions: as answers arrive, immediately update the ExecPlan—move items from Open Questions to the Decision Log with rationale; adjust Plan of Work and Acceptance accordingly. +5. Approval Gate: present the updated ExecPlan for approval. Do not implement until approved. +6. Implementation & Validation: implement per the plan, update Progress with timestamps, and validate via tests and acceptance. Log learnings in Surprises & Discoveries. +7. Closeout: write Outcomes & Retrospective; ensure the plan remains self-contained and accurate. +8. Write your plan to the appropriate location: + - App-specific: `apps//.agents/plans/-.md` + - Package-specific: `packages//.agents/plans/-.md` + - Cross-app: `.agents/plans/-.md` + Use `` in `YYYYMMDD-HHmm` format (e.g., `20240613-1045-my-feature-plan.md`). This ensures plans are sorted from most recent to oldest. +9. Plan Lifecycle: When the plan is complete and a PR is created, move it to the `done/` folder within the same directory. If abandoned, move it to `abandoned/`. + +Example questions: +``` +I reviewed the existing auth implementation in apps/web/src/app/auth/. + +Where should the new OAuth provider live? +a) apps/web/src/lib/auth/providers/ (co-located with auth logic) +b) packages/shared/src/auth/ (shared across apps) +c) Other (specify) + +How should we handle token refresh? +a) Silent refresh via interceptor +b) Explicit refresh on 401 response +c) Other (specify) +``` + +## How to use ExecPlans and PLANS.md + +When authoring an executable specification (ExecPlan), follow this document _to the letter_. Be thorough in reading (and re-reading) source material to produce an accurate specification. When creating a spec, start from the skeleton and flesh it out as you do your research. + +When implementing an executable specification (ExecPlan), do not prompt the user for "next steps"; simply proceed to the next milestone. Keep all sections up to date, add or split entries in the list at every stopping point to affirmatively state the progress made and next steps. Resolve ambiguities autonomously, and commit frequently. + +When discussing an executable specification (ExecPlan), record decisions in a log in the spec for posterity; it should be unambiguously clear why any change to the specification was made. ExecPlans are living documents, and it should always be possible to restart from _only_ the ExecPlan and no other work. + +When researching a design with challenging requirements or significant unknowns, use milestones to implement proof of concepts, "toy implementations", etc., that allow validating whether the user's proposal is feasible. Read the source code of libraries by finding or acquiring them, research deeply, and include prototypes to guide a fuller implementation. + +## Requirements + +NON-NEGOTIABLE REQUIREMENTS: + +* Every ExecPlan must be fully self-contained. Self-contained means that in its current form it contains all knowledge and instructions needed for a novice to succeed. +* Every ExecPlan is a living document. Contributors are required to revise it as progress is made, as discoveries occur, and as design decisions are finalized. Each revision must remain fully self-contained. +* Every ExecPlan must enable a complete novice to implement the feature end-to-end without prior knowledge of this repo. +* Every ExecPlan must produce a demonstrably working behavior, not merely code changes to "meet a definition". +* Every ExecPlan must define every term of art in plain language or do not use it. + +Purpose and intent come first. Begin by explaining, in a few sentences, why the work matters from a user's perspective: what someone can do after this change that they could not do before, and how to see it working. Then guide the reader through the exact steps to achieve that outcome, including what to edit, what to run, and what they should observe. + +The agent executing your plan can list files, read files, search, run the project, and run tests. It does not know any prior context and cannot infer what you meant from earlier milestones. Repeat any assumption you rely on. Do not point to external blogs or docs; if knowledge is required, embed it in the plan itself in your own words. If an ExecPlan builds upon a prior ExecPlan and that file is checked in, incorporate it by reference. If it is not, you must include all relevant context from that plan. + +## Formatting + +Format and envelope are simple and strict. Each ExecPlan must be one single fenced code block labeled as `md` that begins and ends with triple backticks. Do not nest additional triple-backtick code fences inside; when you need to show commands, transcripts, diffs, or code, present them as indented blocks within that single fence. Use indentation for clarity rather than code fences inside an ExecPlan to avoid prematurely closing the ExecPlan's code fence. Use two newlines after every heading, use # and ## and so on, and correct syntax for ordered and unordered lists. + +When writing an ExecPlan to a Markdown (.md) file where the content of the file *is only* the single ExecPlan, you should omit the triple backticks. + +Write in plain prose. Prefer sentences over lists. Avoid checklists, tables, and long enumerations unless brevity would obscure meaning. Checklists are permitted only in the `Progress` section, where they are mandatory. Narrative sections must remain prose-first. + +## Guidelines + +Self-containment and plain language are paramount. If you introduce a phrase that is not ordinary English ("daemon", "middleware", "RPC gateway", "filter graph"), define it immediately and remind the reader how it manifests in this repository (for example, by naming the files or commands where it appears). Do not say "as defined previously" or "according to the architecture doc." Include the needed explanation here, even if you repeat yourself. + +Avoid common failure modes. Do not rely on undefined jargon. Do not describe "the letter of a feature" so narrowly that the resulting code compiles but does nothing meaningful. Do not outsource key decisions to the reader. When ambiguity exists, resolve it in the plan itself and explain why you chose that path. Err on the side of over-explaining user-visible effects and under-specifying incidental implementation details. + +Question discipline and placement: +- Keep each question atomic and acceptance-oriented (what behavior must hold? how will we observe it?). +- Record questions in an Open Questions section of the ExecPlan; tag each with the plan section it affects (e.g., Validation, Plan of Work). +- When a question is answered, create a Decision Log entry with rationale and update the affected sections. Remove the item from Open Questions. +- Prefer at most 3-7 active questions; timebox low-impact ones or convert them into explicit Assumptions. + +Anchor the plan with observable outcomes. State what the user can do after implementation, the commands to run, and the outputs they should see. Acceptance should be phrased as behavior a human can verify ("after starting the server, navigating to http://localhost:3000/health returns HTTP 200 with body OK") rather than internal attributes ("added a HealthCheck struct"). If a change is internal, explain how its impact can still be demonstrated (for example, by running tests that fail before and pass after, and by showing a scenario that uses the new behavior). + +Specify repository context explicitly. Name files with full repository-relative paths, name functions and modules precisely, and describe where new files should be created. If touching multiple areas, include a short orientation paragraph that explains how those parts fit together so a novice can navigate confidently. When running commands, show the working directory and exact command line. When outcomes depend on environment, state the assumptions and provide alternatives when reasonable. + +Be idempotent and safe. Write the steps so they can be run multiple times without causing damage or drift. If a step can fail halfway, include how to retry or adapt. If a migration or destructive operation is necessary, spell out backups or safe fallbacks. Prefer additive, testable changes that can be validated as you go. + +Validation is not optional. Include instructions to run tests, to start the system if applicable, and to observe it doing something useful. Describe comprehensive testing for any new features or capabilities. Include expected outputs and error messages so a novice can tell success from failure. Where possible, show how to prove that the change is effective beyond compilation (for example, through a small end-to-end scenario, a CLI invocation, or an HTTP request/response transcript). State the exact test commands appropriate to the project's toolchain and how to interpret their results. + +## Superset-Specific Context + +This is a Bun + Turborepo monorepo with the following structure: + +**Apps:** +- `apps/web` - Main web application (app.superset.sh) +- `apps/marketing` - Marketing site (superset.sh) +- `apps/admin` - Admin dashboard +- `apps/api` - API backend +- `apps/desktop` - Electron desktop application +- `apps/docs` - Documentation site +- `apps/cli` - CLI tooling + +**Packages:** +- `packages/ui` - Shared UI components (shadcn/ui + TailwindCSS v4) +- `packages/db` - Drizzle ORM database schema +- `packages/local-db` - Local database schema +- `packages/queries` - Shared query logic +- `packages/shared` - Shared constants and utilities +- `packages/trpc` - tRPC configuration + +**Common Commands:** +- `bun dev` - Start all dev servers +- `bun test` - Run tests +- `bun build` - Build all packages +- `bun run lint` - Check for lint issues +- `bun run lint:fix` - Fix auto-fixable lint issues +- `bun run typecheck` - Type check all packages +- `bun run db:push` - Apply schema changes +- `bun run db:migrate` - Run migrations + +Capture evidence. When your steps produce terminal output, short diffs, or logs, include them inside the single fenced block as indented examples. Keep them concise and focused on what proves success. If you need to include a patch, prefer file-scoped diffs or small excerpts that a reader can recreate by following your instructions rather than pasting large blobs. + +## Milestones + +Milestones are narrative, not bureaucracy. If you break the work into milestones, introduce each with a brief paragraph that describes the scope, what will exist at the end of the milestone that did not exist before, the commands to run, and the acceptance you expect to observe. Keep it readable as a story: goal, work, result, proof. Progress and milestones are distinct: milestones tell the story, progress tracks granular work. Both must exist. Never abbreviate a milestone merely for the sake of brevity, do not leave out details that could be crucial to a future implementation. + +Each milestone must be independently verifiable and incrementally implement the overall goal of the execution plan. + +## Living plans and design decisions + +* ExecPlans are living documents. As you make key design decisions, update the plan to record both the decision and the thinking behind it. Record all decisions in the `Decision Log` section. +* ExecPlans must contain and maintain a `Progress` section, a `Surprises & Discoveries` section, a `Decision Log`, and an `Outcomes & Retrospective` section. These are not optional. +* When you discover optimizer behavior, performance tradeoffs, unexpected bugs, or inverse/unapply semantics that shaped your approach, capture those observations in the `Surprises & Discoveries` section with short evidence snippets (test output is ideal). +* If you change course mid-implementation, document why in the `Decision Log` and reflect the implications in `Progress`. Plans are guides for the next contributor as much as checklists for you. +* At completion of a major task or the full plan, write an `Outcomes & Retrospective` entry summarizing what was achieved, what remains, and lessons learned. + +# Prototyping milestones and parallel implementations + +It is acceptable--and often encouraged--to include explicit prototyping milestones when they de-risk a larger change. Examples: adding a low-level operator to a dependency to validate feasibility, or exploring two composition orders while measuring optimizer effects. Keep prototypes additive and testable. Clearly label the scope as "prototyping"; describe how to run and observe results; and state the criteria for promoting or discarding the prototype. + +Prefer additive code changes followed by subtractions that keep tests passing. Parallel implementations (e.g., keeping an adapter alongside an older path during migration) are fine when they reduce risk or enable tests to continue passing during a large migration. Describe how to validate both paths and how to retire one safely with tests. When working with multiple new libraries or feature areas, consider creating spikes that evaluate the feasibility of these features _independently_ of one another, proving that the external library performs as expected and implements the features we need in isolation. + +## Skeleton of a Good ExecPlan + +```md +# + +This ExecPlan is a living document. The sections `Progress`, `Surprises & Discoveries`, `Decision Log`, and `Outcomes & Retrospective` must be kept up to date as work proceeds. + +## Purpose / Big Picture + +Explain in a few sentences what someone gains after this change and how they can see it working. State the user-visible behavior you will enable. + +## Assumptions + +State temporary assumptions that unblock planning. Every assumption must either be confirmed (moved to the Decision Log) or removed by implementation end. + +## Open Questions + +List unresolved, acceptance-oriented questions. For each, note the impacted plan sections (e.g., Validation, Plan of Work) and add a placeholder in the Decision Log for the eventual answer. + +## Progress + +Use a list with checkboxes to summarize granular steps. Every stopping point must be documented here, even if it requires splitting a partially completed task into two ("done" vs. "remaining"). This section must always reflect the actual current state of the work. + +- [x] (2025-10-01 13:00Z) Example completed step. +- [ ] Example incomplete step. +- [ ] Example partially completed step (completed: X; remaining: Y). + +Use timestamps to measure rates of progress. + +## Surprises & Discoveries + +Document unexpected behaviors, bugs, optimizations, or insights discovered during implementation. Provide concise evidence. + +- Observation: ... + Evidence: ... + +## Decision Log + +Record every decision made while working on the plan in the format: + +- Decision: ... + Rationale: ... + Date/Author: ... + +## Outcomes & Retrospective + +Summarize outcomes, gaps, and lessons learned at major milestones or at completion. Compare the result against the original purpose. + +## Context and Orientation + +Describe the current state relevant to this task as if the reader knows nothing. Name the key files and modules by full path. Define any non-obvious term you will use. Do not refer to prior plans. + +## Plan of Work + +Describe, in prose, the sequence of edits and additions. For each edit, name the file and location (function, module) and what to insert or change. Keep it concrete and minimal. + +## Concrete Steps + +State the exact commands to run and where to run them (working directory). When a command generates output, show a short expected transcript so the reader can compare. This section must be updated as work proceeds. + +## Validation and Acceptance + +Describe how to start or exercise the system and what to observe. Phrase acceptance as behavior, with specific inputs and outputs. If tests are involved, say "run `bun test` and expect passed; the new test fails before the change and passes after". + +## Idempotence and Recovery + +If steps can be repeated safely, say so. If a step is risky, provide a safe retry or rollback path. Keep the environment clean after completion. + +## Artifacts and Notes + +Include the most important transcripts, diffs, or snippets as indented examples. Keep them concise and focused on what proves success. + +## Interfaces and Dependencies + +Be prescriptive. Name the libraries, modules, and services to use and why. Specify the types, traits/interfaces, and function signatures that must exist at the end of the milestone. Prefer stable names and paths such as `packages/db/src/schema/users.ts` or `apps/web/src/lib/auth.ts`. E.g.: + +In packages/db/src/schema/users.ts, define: + + export const users = pgTable('users', { + id: text('id').primaryKey(), + email: text('email').notNull().unique(), + createdAt: timestamp('created_at').defaultNow(), + }); +``` + +If you follow the guidance above, a single, stateless agent -- or a human novice -- can read your ExecPlan from top to bottom and produce a working, observable result. That is the bar: SELF-CONTAINED, SELF-SUFFICIENT, NOVICE-GUIDING, OUTCOME-FOCUSED. + +When you revise a plan, you must ensure your changes are comprehensively reflected across all sections, including the living document sections, and you must write a note at the bottom of the plan describing the change and the reason why. ExecPlans must describe not just the what but the why for almost everything. + +## Plan Lifecycle + +ExecPlans have a defined lifecycle that keeps the `.agents/plans/` folder clean and provides a historical record of completed work. + +### Directory Structure + +``` +apps//.agents/plans/ # App-specific plans + .md + done/ + abandoned/ + +packages//.agents/plans/ # Package-specific plans + .md + done/ + abandoned/ + +.agents/plans/ # Cross-app/shared plans + .md + done/ + abandoned/ +``` + +### When to Move Plans + +**To `done/`**: Move the plan to the `done/` folder within the same directory when creating a PR that completes the work. Before moving, ensure the plan's `Outcomes & Retrospective` section is filled in. + +**To `abandoned/`**: Move the plan to the `abandoned/` folder within the same directory if work is stopped without completion. Add a note explaining why (scope changed, approach invalidated, deprioritized, etc.). + +### Edge Cases + +- **PR closed without merging**: The plan stays in `done/`. If work resumes, move it back to the active plans folder and update the `Progress` section. +- **Plan spans multiple PRs**: Keep the plan in the active folder until the final PR. Reference intermediate PRs in the `Progress` section, then move to `done/` on the final PR. +- **Reopening abandoned work**: Move the plan from `abandoned/` back to the active plans folder and update the `Progress` section to reflect the restart. diff --git a/apps/desktop/.agents/plans/20251231-1200-workspace-sidebar-navigation.md b/apps/desktop/.agents/plans/20251231-1200-workspace-sidebar-navigation.md new file mode 100644 index 00000000000..88aba9783e4 --- /dev/null +++ b/apps/desktop/.agents/plans/20251231-1200-workspace-sidebar-navigation.md @@ -0,0 +1,691 @@ +# Configurable Workspace Navigation: Sidebar Mode + +This ExecPlan is a living document. The sections `Progress`, `Surprises & Discoveries`, `Decision Log`, and `Outcomes & Retrospective` must be kept up to date as work proceeds. + +## Purpose / Big Picture + +Currently, workspaces are displayed as horizontal tabs in the TopBar, grouped by project. This change allows users to configure an alternative "sidebar" navigation style where workspaces appear in a dedicated left sidebar panel, matching designs from tools like Linear/GitHub Desktop. + +After this change, users can: +1. Open Settings > Behavior and toggle "Navigation style" between "Top bar" and "Sidebar" +2. In sidebar mode, see a dedicated workspace sidebar with collapsible project sections +3. Switch between workspaces by clicking items in the sidebar +4. See PR status, diff stats, and keyboard shortcuts inline with workspace items +5. Continue using ⌘1-9 shortcuts to switch workspaces regardless of mode + +## Design Reference + +The target design (based on provided mockup): + + ┌─────────────────────────────────────────────────────────────────────┐ + │ [Sidebar Toggle] [Workbench|Review] [Branch ▾] [Open In ▾] [Avatar]│ <- TopBar (sidebar mode) + ├──────────────────────┬──────────────────────────────────────────────┤ + │ ≡ Workspaces │ │ + │ │ │ + │ web │ │ + │ + New workspace ... │ Main Content Area │ + │ ┃ andreasasprou/cebu │ (Workbench or Review mode) │ + │ cebu · PR #144 │ │ + │ Ready to merge ⌘1 │ │ + │ +1850 -301 │ │ + │ │ │ + │ ▸ andreasasprou/feat │ │ + │ harare · PR #107 │ │ + │ Merge conflicts ⌘2 │ │ + │ ├──────────────────────────────────────────────┤ + │ nova │ │ + │ + New workspace ... │ Changes Sidebar │ + │ ┃ andreasasprou/pdf │ (existing ResizableSidebar) │ + │ la-paz-v2 · PR#720 │ │ + │ Uncommitted ⌘3 │ │ + │ +23823 -5 │ │ + │ │ │ + │ frontend │ │ + │ + New workspace ... │ │ + │ │ │ + │──────────────────── │ │ + │ [+] Add project │ │ + └──────────────────────┴──────────────────────────────────────────────┘ + Workspace Changes Content + Sidebar Sidebar (Mosaic Panes) + (NEW) (existing) + +Key visual elements: +- Active workspace: Green/project-colored left border (┃) +- Status badges: "Ready to merge", "Merge conflicts", "Uncommitted changes", "Archive" +- Diff stats: +insertions -deletions (always visible for active, hover for others) +- Keyboard shortcuts: ⌘1-9 displayed inline +- Collapsible project sections with header + "..." context menu +- "+ New workspace" per project section +- "Add project" at bottom footer + +## Assumptions + +1. The existing `WorkspaceHoverCard` already fetches PR status via `workspaces.getGitHubStatus` and can be reused +2. The `feat/desktop-workbench-review-mode` branch changes are the baseline (already rebased) +3. Users will primarily use one mode or the other, not switch frequently +4. The `packages/local-db` migration system handles schema changes on app startup + +## Open Questions + +(All questions resolved - see Decision Log) + +## Progress + +- [ ] Initial plan created and awaiting approval +- [ ] (Pending) Milestone 1: Add navigation style setting +- [ ] (Pending) Milestone 2: Create WorkspaceSidebar component +- [ ] (Pending) Milestone 3: Create sidebar-mode TopBar variant +- [ ] (Pending) Milestone 4: Wire up setting to conditionally render layouts +- [ ] (Pending) Milestone 5: Polish and validation + +## Surprises & Discoveries + +(To be filled during implementation) + +## Decision Log + +- **Decision**: Navigation style setting stored in SQLite settings table via existing tRPC pattern + - Rationale: Matches existing "confirmOnQuit" behavior setting pattern, persists across sessions + - Date: 2025-12-31 / Planning phase + +- **Decision**: Workspace sidebar is a NEW dedicated sidebar, not a mode in existing ModeCarousel + - Rationale: User preference for dedicated panel, keeps workspaces separate from terminal tabs/changes + - Date: 2025-12-31 / Planning phase + +- **Decision**: Both sidebars independently resizable + - Rationale: User may want different widths for workspace nav vs file changes + - Date: 2025-12-31 / Planning phase + +- **Decision**: ⌘1-9 shortcuts work in both navigation modes + - Rationale: Consistency for keyboard users regardless of UI layout preference + - Date: 2025-12-31 / Planning phase + +- **Decision**: Manual testing only, no automated tests for initial release + - Rationale: Feature is primarily UI/layout, visual verification more appropriate + - Date: 2025-12-31 / Planning phase + +- **Decision**: Workspace sidebar width persisted independently from changes sidebar + - Rationale: Users may want different widths for workspace nav vs file changes + - Date: 2025-12-31 / Planning phase + +- **Decision**: Workspace display format is "github-username/branch-name" (e.g., "andreasasprou/cebu") + - Rationale: Matches GitHub PR branch naming, provides author context + - Date: 2025-12-31 / Planning phase + +- **Decision**: Skip "Archive" status badge for initial release + - Rationale: Archive feature doesn't exist in app, can add later if needed + - Date: 2025-12-31 / Planning phase + +- **Decision**: Keep Workbench/Review toggle and Open In in WorkspaceActionBar, not TopBar + - Rationale: Avoids duplicating components, maintains consistent location across navigation modes + - Date: 2025-12-31 / Planning phase (review feedback) + +- **Decision**: Sidebar toggles use distinct naming: "Workspaces" and "Files" with different icons + - Rationale: With two sidebars, "Toggle sidebar" is ambiguous. Clear naming prevents confusion + - Date: 2025-12-31 / Planning phase (review feedback) + +- **Decision**: Workspace sidebar is toggleable (not always-on), default open on first use + - Rationale: Matches changes sidebar pattern, provides flexibility for screen sizes + - Date: 2025-12-31 / Planning phase (review feedback) + +- **Decision**: Use `workspaces.getGitHubStatus` for diff stats, lazy-load on hover + - Rationale: Reuses existing infrastructure, avoids N+1 queries, matches WorkspaceHoverCard + - Date: 2025-12-31 / Planning phase (review feedback) + +- **Decision**: Extract ⌘1-9 shortcuts and auto-create workspace logic into shared hook + - Rationale: These behaviors must work in BOTH navigation modes, avoiding code duplication + - Date: 2025-12-31 / Planning phase (review feedback) + +## Outcomes & Retrospective + +(To be filled at completion) + +--- + +## Context and Orientation + +### Current Architecture + +The desktop app (`apps/desktop/`) uses: + +**Layout Structure** (in `src/renderer/screens/main/`): +- `MainScreen` - Root component, manages view state (workspace/settings/tasks) +- `TopBar` - Contains `WorkspacesTabs` for horizontal workspace navigation +- `WorkspaceView` - Main content area with `ResizableSidebar` (changes) + `ContentView` + +**State Management**: +- `sidebar-state.ts` - Zustand store for changes sidebar (width, visibility, mode) +- `workspace-view-mode.ts` - Zustand store for Workbench/Review mode per workspace +- `app-state.ts` - Current view, settings section, etc. + +**Settings System**: +- Settings stored in SQLite via `packages/local-db/src/schema/schema.ts` +- tRPC routes in `src/lib/trpc/routers/settings/` +- UI in `src/renderer/screens/main/components/SettingsView/BehaviorSettings.tsx` + +**Key Files**: +- `src/renderer/screens/main/components/TopBar/index.tsx` - Current TopBar +- `src/renderer/screens/main/components/TopBar/WorkspaceTabs/index.tsx` - Horizontal tabs +- `src/renderer/screens/main/components/WorkspaceView/index.tsx` - Main workspace layout +- `src/renderer/screens/main/components/WorkspaceView/ResizableSidebar/` - Existing sidebar + +### Terminology + +- **Navigation style**: User preference for workspace display location ("top-bar" or "sidebar") +- **Workspace sidebar**: NEW left panel showing workspaces grouped by project +- **Changes sidebar**: EXISTING left panel showing git changes (file tree) +- **Workbench mode**: Terminal panes + file viewers (mosaic layout) +- **Review mode**: Full-page changes/diff view + +--- + +## Plan of Work + +### Milestone 1: Add Navigation Style Setting + +Add the setting infrastructure following the existing "confirmOnQuit" pattern. + +**1.1 Add setting to database schema** + +In `packages/local-db/src/schema/schema.ts`, add to settings table: + + navigationStyle: text("navigation_style").$type<"top-bar" | "sidebar">(), + +**1.2 Generate local-db migration** + +Run from `packages/local-db`: + + pnpm drizzle-kit generate --name="add_navigation_style" + +This creates a migration file in `packages/local-db/drizzle/`. The migration runs automatically on app startup via `apps/desktop/src/main/lib/local-db/index.ts` migrate logic. + +**IMPORTANT**: Do NOT use `bun run db:push` - that targets packages/db (Neon/Postgres), not local-db. + +**1.3 Add default constant** + +In `apps/desktop/src/shared/constants.ts`: + + export const DEFAULT_NAVIGATION_STYLE = "top-bar" as const; + export type NavigationStyle = "top-bar" | "sidebar"; + +**1.4 Add tRPC routes** + +In `apps/desktop/src/lib/trpc/routers/settings/index.ts`, add: + + getNavigationStyle: publicProcedure.query(async () => { + const row = getSettings(); + return row.navigationStyle ?? DEFAULT_NAVIGATION_STYLE; + }), + + setNavigationStyle: publicProcedure + .input(z.object({ style: z.enum(["top-bar", "sidebar"]) })) + .mutation(async ({ input }) => { + localDb.insert(settings) + .values({ id: 1, navigationStyle: input.style }) + .onConflictDoUpdate({ + target: settings.id, + set: { navigationStyle: input.style } + }) + .run(); + return { success: true }; + }), + +**1.5 Add UI in BehaviorSettings** + +In `apps/desktop/src/renderer/screens/main/components/SettingsView/BehaviorSettings.tsx`, add a toggle/select for "Navigation style" with options "Top bar" and "Sidebar". + +### Milestone 2: Create WorkspaceSidebar Component + +Create the new sidebar component matching the design. + +**2.1 Create store for workspace sidebar state** + +Create `apps/desktop/src/renderer/stores/workspace-sidebar-state.ts`: + + interface WorkspaceSidebarState { + isOpen: boolean; + width: number; + // Use string[] instead of Set for JSON serialization with Zustand persist + collapsedProjectIds: string[]; + toggleOpen: () => void; + setWidth: (width: number) => void; + toggleProjectCollapsed: (projectId: string) => void; + isProjectCollapsed: (projectId: string) => boolean; + } + +**NOTE**: Do NOT use `Set` for `collapsedProjectIds` - Zustand persist uses JSON serialization which drops Sets. Use `string[]` and provide helper methods. + +**2.2 Create component structure** + +Create folder: `apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/` + +Files to create: +- `index.tsx` - Main component +- `WorkspaceSidebarHeader.tsx` - "Workspaces" header with icon +- `ProjectSection/ProjectSection.tsx` - Collapsible project group +- `ProjectSection/ProjectHeader.tsx` - Project name + actions +- `WorkspaceListItem/WorkspaceListItem.tsx` - Individual workspace row +- `WorkspaceListItem/WorkspaceStatusBadge.tsx` - Status badges +- `WorkspaceListItem/WorkspaceDiffStats.tsx` - +/- diff display +- `WorkspaceSidebarFooter.tsx` - "Add project" button + +**2.3 WorkspaceListItem design** + +Each workspace item displays: +- Left border (project color when active) +- Branch icon (git-branch, git-pull-request, etc. based on type) +- Author/branch: "andreasasprou/feature-name" +- Worktree name + PR info: "worktree-city · PR #123" +- Status badge: "Ready to merge" / "Merge conflicts" / "Uncommitted changes" / "Archive" +- Keyboard shortcut badge: "⌘1" +- Diff stats (for active): "+1850 -301" + +**2.4 Data fetching** + +Reuse existing queries: +- `trpc.workspaces.getAllGrouped.useQuery()` for project/workspace list +- `trpc.workspaces.getActive.useQuery()` for active workspace + +**Diff stats source**: Use `workspaces.getGitHubStatus` (already used by WorkspaceHoverCard) for PR additions/deletions. This is the authoritative source. Do NOT add a new git diff endpoint. For workspaces without PRs, show local uncommitted changes count from the changes router as fallback. + +**Performance consideration**: Avoid N+1 `getGitHubStatus` calls per workspace row. Options: +1. Extend `getAllGrouped` to include a summary `githubStatus` field (batched) +2. Reuse cached data from `worktrees.githubStatus` if already fetched +3. Lazy-load status on hover only (simplest, matches current WorkspaceHoverCard behavior) + +Recommended: Start with option 3 (lazy-load on hover) to match existing patterns, then optimize with batching if performance is an issue. + +**2.5 Extract shared workspace behaviors** + +Currently `WorkspacesTabs/index.tsx` owns critical behaviors that must work in BOTH navigation modes: +- ⌘1-9 workspace switching shortcuts +- Auto-create main workspace for new projects effect + +Create a shared hook: `apps/desktop/src/renderer/hooks/useWorkspaceShortcuts.ts` + + export function useWorkspaceShortcuts() { + const { data: groups = [] } = trpc.workspaces.getAllGrouped.useQuery(); + const setActiveWorkspace = useSetActiveWorkspace(); + const createBranchWorkspace = useCreateBranchWorkspace(); + + // Flatten workspaces for ⌘1-9 navigation + const allWorkspaces = groups.flatMap((group) => group.workspaces); + + // ⌘1-9 shortcuts + useHotkeys(workspaceKeys, handleWorkspaceSwitch); + useHotkeys(HOTKEYS.PREV_WORKSPACE.keys, handlePrevWorkspace); + useHotkeys(HOTKEYS.NEXT_WORKSPACE.keys, handleNextWorkspace); + + // Auto-create main workspace for new projects + useEffect(() => { /* existing logic */ }, [groups]); + + return { allWorkspaces }; + } + +Then use this hook in BOTH: +- `WorkspaceSidebar/index.tsx` (sidebar mode) +- `WorkspacesTabs/index.tsx` (top-bar mode) + +This ensures shortcuts work regardless of navigation style. + +### Milestone 3: Create Sidebar-Mode TopBar Variant + +When navigation style is "sidebar", the TopBar should show a unified bar without workspace tabs. + +**3.1 Decide on control placement** + +Currently, `WorkspaceActionBar` contains: +- ViewModeToggle (Workbench/Review) +- Branch selector +- Open In dropdown + +**Decision needed**: In sidebar mode, do these controls: +A) Stay in WorkspaceActionBar (below TopBar) - no duplication, consistent location +B) Move to TopBarSidebarMode - more prominent, frees up vertical space + +**Recommendation**: Keep controls in WorkspaceActionBar (option A). This: +- Avoids duplicating components +- Maintains consistent location across modes +- Keeps TopBar focused on navigation + +TopBarSidebarMode then only needs: +- Changes sidebar toggle (existing SidebarControl, renamed for clarity) +- Workspace sidebar toggle (new) +- Avatar/user menu + +**3.2 Sidebar toggle disambiguation** + +With two sidebars, we need clear naming: +- **"Files" / file icon**: Toggle changes sidebar (existing, currently just "sidebar") +- **"Workspaces" / layers icon**: Toggle workspace sidebar (new) + +Update tooltips and potentially add labels on hover. Both toggles live in TopBar. + +**3.3 Create TopBarSidebarMode component** + +Create `apps/desktop/src/renderer/screens/main/components/TopBar/TopBarSidebarMode.tsx`: + +Layout (left to right): +- Workspace sidebar toggle (new, tooltip: "Toggle workspaces") +- Changes sidebar toggle (existing SidebarControl, tooltip: "Toggle files") +- [Spacer] +- [Right] Avatar dropdown + +The Workbench/Review toggle, branch selector, and Open In dropdown remain in WorkspaceActionBar. + +**3.4 Workspace sidebar always-on vs toggleable** + +The workspace sidebar should be toggleable (not always-on) because: +- Users may want full-width content when not switching workspaces +- Matches the existing changes sidebar pattern +- Provides flexibility for different screen sizes + +Default state: Open (on first use), then persisted via Zustand. + +**3.5 Conditional rendering in TopBar** + +Modify `apps/desktop/src/renderer/screens/main/components/TopBar/index.tsx`: + + const { data: navigationStyle } = trpc.settings.getNavigationStyle.useQuery(); + + if (navigationStyle === "sidebar") { + return ; + } + + return ; // Rename current implementation + +### Milestone 4: Wire Up Layout Switching + +Connect the setting to conditionally render the appropriate layout. + +**4.1 Modify MainScreen layout** + +In `apps/desktop/src/renderer/screens/main/index.tsx`, when rendering workspace view: + + const { data: navigationStyle } = trpc.settings.getNavigationStyle.useQuery(); + + // In render: + {navigationStyle === "sidebar" && } + + +**4.2 Modify WorkspaceView** + +The `WorkspaceView` component remains largely unchanged - it already has the ResizableSidebar (changes) and ContentView. The WorkspaceSidebar sits to its left. + +**4.3 Layout structure in sidebar mode** + +
+ {/* NEW - workspace navigation */} + {/* EXISTING - contains changes sidebar + content */} +
+ +### Milestone 5: Polish and Validation + +**5.1 Keyboard shortcuts** + +Ensure ⌘1-9 workspace switching works in both modes. The existing `useHotkeys` in `WorkspacesTabs/index.tsx` should be moved/shared. + +**5.2 Hover preview** + +Implement hover preview showing branch + PR status. Can reuse `WorkspaceHoverCard` component or adapt it. + +**5.3 Animations** + +- Smooth sidebar show/hide with Framer Motion +- Collapse/expand project sections with animation +- Active workspace indicator transition + +**5.4 Persistence** + +- Workspace sidebar width persists (Zustand + localStorage) +- Collapsed project sections persist +- Navigation style persists (SQLite) + +--- + +## Concrete Steps + +All commands run from repository root: `/Users/andreasasprou/.superset/worktrees/superset/workspace-sidebar` + +**Step 1: Verify current state** + + cd apps/desktop + bun run typecheck + +Expected: No type errors (baseline) + +**Step 2: Add database schema field and generate migration** + +Edit `packages/local-db/src/schema/schema.ts` to add `navigationStyle` column. + + cd packages/local-db + pnpm drizzle-kit generate --name="add_navigation_style" + +Expected: Migration file created in `packages/local-db/drizzle/` + +The migration runs automatically on app startup. Do NOT use `bun run db:push` (that's for Neon/Postgres). + +**Step 3: Add setting routes** + +Edit `apps/desktop/src/lib/trpc/routers/settings/index.ts` + + bun run typecheck + +Expected: Types pass with new routes + +**Step 4: Create WorkspaceSidebar component** + +Create component files as specified in Milestone 2. + +**Step 5: Add to layout** + +Wire up conditional rendering in MainScreen. + + bun dev + +Expected: App starts, can toggle setting, layout switches + +**Step 6: Full validation** + + bun run lint:fix + bun run typecheck + bun test + +Expected: All pass + +--- + +## Validation and Acceptance + +### Manual Testing Checklist + +1. **Setting toggle works** + - Open Settings > Behavior + - See "Navigation style" option + - Toggle between "Top bar" and "Sidebar" + - Layout changes immediately (or after brief transition) + +2. **Sidebar mode displays correctly** + - WorkspaceSidebar appears on left + - Projects shown as collapsible sections + - Workspaces listed under each project + - Active workspace has colored left border + - Status badges visible + - Diff stats visible for active workspace + - ⌘1-9 shortcuts displayed + +3. **Interactions work** + - Click workspace to switch + - Click project header to collapse/expand + - Hover shows preview card + - ⌘1-9 switches workspaces + - "+ New workspace" opens creation dialog + - "Add project" opens project creation + +4. **TopBar adapts** + - In sidebar mode: No workspace tabs, unified bar with Workbench/Review toggle + - In top-bar mode: Original layout preserved + +5. **Persistence** + - Close and reopen app + - Navigation style preserved + - Sidebar widths preserved + - Collapsed projects preserved + +6. **Both sidebars coexist** + - Workspace sidebar (left) + - Changes sidebar (right of workspace sidebar) + - Both independently resizable + - Both can be toggled independently + +--- + +## Idempotence and Recovery + +- Database schema changes are additive (new nullable column) +- Running `db:push` multiple times is safe +- Component files are new additions, no destructive changes +- Setting defaults to "top-bar" if not set (backwards compatible) +- If implementation fails partway, the existing top-bar mode continues working + +--- + +## Artifacts and Notes + +### Component File Structure + + apps/desktop/src/renderer/ + ├── hooks/ + │ └── useWorkspaceShortcuts.ts (new - shared ⌘1-9 + auto-create logic) + ├── screens/main/components/ + │ ├── WorkspaceSidebar/ + │ │ ├── index.tsx + │ │ ├── WorkspaceSidebarHeader.tsx + │ │ ├── WorkspaceSidebarFooter.tsx + │ │ ├── ResizableWorkspaceSidebar.tsx (wrapper with resize handle) + │ │ ├── ProjectSection/ + │ │ │ ├── ProjectSection.tsx + │ │ │ ├── ProjectHeader.tsx + │ │ │ └── index.ts + │ │ └── WorkspaceListItem/ + │ │ ├── WorkspaceListItem.tsx + │ │ ├── WorkspaceStatusBadge.tsx + │ │ ├── WorkspaceDiffStats.tsx + │ │ └── index.ts + │ └── TopBar/ + │ ├── index.tsx (modified - conditional render) + │ ├── TopBarSidebarMode.tsx (new) + │ ├── TopBarDefault.tsx (renamed from inline JSX) + │ ├── SidebarControl.tsx (updated tooltip: "Toggle files") + │ ├── WorkspaceSidebarControl.tsx (new - "Toggle workspaces") + │ └── ... (existing files) + └── stores/ + └── workspace-sidebar-state.ts (new) + +### State Structure + + // workspace-sidebar-state.ts (Zustand + persist) + { + isOpen: true, + width: 280, // pixels + collapsedProjectIds: ["project-id-1", "project-id-2"], // string[] NOT Set + } + + // settings table (SQLite via local-db) + { + navigationStyle: "sidebar" | "top-bar" + } + +**Important**: Use `string[]` for `collapsedProjectIds`, not `Set`. Zustand persist uses JSON serialization which drops Sets. + +--- + +## Interfaces and Dependencies + +### New tRPC Routes + +In `apps/desktop/src/lib/trpc/routers/settings/index.ts`: + + getNavigationStyle: publicProcedure.query(() => NavigationStyle) + setNavigationStyle: publicProcedure.input({ style: NavigationStyle }).mutation() + +### New Zustand Store + +In `apps/desktop/src/renderer/stores/workspace-sidebar-state.ts`: + + export const useWorkspaceSidebarStore = create()( + devtools( + persist( + (set, get) => ({ + isOpen: true, + width: 280, + collapsedProjectIds: [], // string[] for JSON serialization + + toggleOpen: () => set((s) => ({ isOpen: !s.isOpen })), + + setWidth: (width) => set({ width }), + + toggleProjectCollapsed: (projectId) => + set((s) => ({ + collapsedProjectIds: s.collapsedProjectIds.includes(projectId) + ? s.collapsedProjectIds.filter((id) => id !== projectId) + : [...s.collapsedProjectIds, projectId], + })), + + isProjectCollapsed: (projectId) => + get().collapsedProjectIds.includes(projectId), + }), + { name: "workspace-sidebar-store" } + ) + ) + ); + +### New Shared Hook + +In `apps/desktop/src/renderer/hooks/useWorkspaceShortcuts.ts`: + + export function useWorkspaceShortcuts() { + // Extract from WorkspacesTabs: ⌘1-9 shortcuts + auto-create logic + // Used by BOTH WorkspaceSidebar and WorkspacesTabs + } + +### Component Props + + interface WorkspaceListItemProps { + workspace: { + id: string; + name: string; + branch: string; + worktreePath: string; + type: "worktree" | "branch"; + projectId: string; + }; + project: { + id: string; + name: string; + color: string; + }; + isActive: boolean; + index: number; // for ⌘N shortcut display + onSelect: () => void; + onHover: () => void; + } + +--- + +## Dependencies on External Data + +The following data is needed for full feature parity with the design: + +1. **PR Status + Diff Stats** - Available via `workspaces.getGitHubStatus` (already used by WorkspaceHoverCard) + - This is the authoritative source for PR additions/deletions + - Do NOT add a new git diff endpoint + +2. **Workspace Status** (uncommitted changes) - Available via changes router + - Fallback for workspaces without PRs + +3. **GitHub Author/Branch** - Extract from PR branch name or remote tracking branch + - Already available in workspace data + +**Performance strategy**: Lazy-load status on hover (matching WorkspaceHoverCard behavior). If batching is needed later, extend `getAllGrouped` to include summary status. diff --git a/apps/desktop/src/lib/trpc/routers/changes/branches.ts b/apps/desktop/src/lib/trpc/routers/changes/branches.ts index bc63ab91aa3..b2351e98bdd 100644 --- a/apps/desktop/src/lib/trpc/routers/changes/branches.ts +++ b/apps/desktop/src/lib/trpc/routers/changes/branches.ts @@ -4,6 +4,11 @@ import { localDb } from "main/lib/local-db"; import simpleGit from "simple-git"; import { z } from "zod"; import { publicProcedure, router } from "../.."; +import { + assertRegisteredWorktree, + getRegisteredWorktree, + gitSwitchBranch, +} from "./security"; export const createBranchesRouter = () => { return router({ @@ -18,6 +23,8 @@ export const createBranchesRouter = () => { defaultBranch: string; checkedOutBranches: Record; }> => { + assertRegisteredWorktree(input.worktreePath); + const git = simpleGit(input.worktreePath); const branchSummary = await git.branch(["-a"]); @@ -59,18 +66,11 @@ export const createBranchesRouter = () => { }), ) .mutation(async ({ input }): Promise<{ success: boolean }> => { - const git = simpleGit(input.worktreePath); - - const worktree = localDb - .select() - .from(worktrees) - .where(eq(worktrees.path, input.worktreePath)) - .get(); - if (!worktree) { - throw new Error(`No worktree found at path "${input.worktreePath}"`); - } + // Get worktree record for updating branch info + const worktree = getRegisteredWorktree(input.worktreePath); - await git.checkout(input.branch); + // Use gitSwitchBranch which uses `git switch` (correct branch syntax) + await gitSwitchBranch(input.worktreePath, input.branch); // Update the branch in the worktree record const gitStatus = worktree.gitStatus diff --git a/apps/desktop/src/lib/trpc/routers/changes/file-contents.ts b/apps/desktop/src/lib/trpc/routers/changes/file-contents.ts index 8af04dd68e4..4b2ae5aca2c 100644 --- a/apps/desktop/src/lib/trpc/routers/changes/file-contents.ts +++ b/apps/desktop/src/lib/trpc/routers/changes/file-contents.ts @@ -1,11 +1,48 @@ -import { readFile, writeFile } from "node:fs/promises"; -import { join } from "node:path"; import type { FileContents } from "shared/changes-types"; import simpleGit from "simple-git"; import { z } from "zod"; import { publicProcedure, router } from "../.."; +import { + assertRegisteredWorktree, + PathValidationError, + secureFs, +} from "./security"; import { detectLanguage } from "./utils/parse-status"; +/** Maximum file size for reading (2 MiB) */ +const MAX_FILE_SIZE = 2 * 1024 * 1024; + +/** Bytes to scan for binary detection */ +const BINARY_CHECK_SIZE = 8192; + +/** + * Result type for readWorkingFile procedure + */ +type ReadWorkingFileResult = + | { ok: true; content: string; truncated: boolean; byteLength: number } + | { + ok: false; + reason: + | "not-found" + | "too-large" + | "binary" + | "outside-worktree" + | "symlink-escape"; + }; + +/** + * Detects if a buffer contains binary content by checking for NUL bytes + */ +function isBinaryContent(buffer: Buffer): boolean { + const checkLength = Math.min(buffer.length, BINARY_CHECK_SIZE); + for (let i = 0; i < checkLength; i++) { + if (buffer[i] === 0) { + return true; + } + } + return false; +} + export const createFileContentsRouter = () => { return router({ getFileContents: publicProcedure @@ -20,6 +57,8 @@ export const createFileContentsRouter = () => { }), ) .query(async ({ input }): Promise => { + assertRegisteredWorktree(input.worktreePath); + const git = simpleGit(input.worktreePath); const defaultBranch = input.defaultBranch || "main"; const originalPath = input.oldPath || input.filePath; @@ -50,10 +89,63 @@ export const createFileContentsRouter = () => { }), ) .mutation(async ({ input }): Promise<{ success: boolean }> => { - const fullPath = join(input.worktreePath, input.filePath); - await writeFile(fullPath, input.content, "utf-8"); + // secureFs.writeFile validates worktree registration and path traversal + await secureFs.writeFile( + input.worktreePath, + input.filePath, + input.content, + ); return { success: true }; }), + + /** + * Read a working tree file safely with size cap and binary detection. + * Used for File Viewer raw/rendered modes. + */ + readWorkingFile: publicProcedure + .input( + z.object({ + worktreePath: z.string(), + filePath: z.string(), + }), + ) + .query(async ({ input }): Promise => { + try { + // Check file size first (uses stat which follows symlinks) + const stats = await secureFs.stat(input.worktreePath, input.filePath); + if (stats.size > MAX_FILE_SIZE) { + return { ok: false, reason: "too-large" }; + } + + // Read file content as buffer for binary detection + const buffer = await secureFs.readFileBuffer( + input.worktreePath, + input.filePath, + ); + + // Check for binary content + if (isBinaryContent(buffer)) { + return { ok: false, reason: "binary" }; + } + + return { + ok: true, + content: buffer.toString("utf-8"), + truncated: false, + byteLength: buffer.length, + }; + } catch (error) { + if (error instanceof PathValidationError) { + // Map specific error codes to distinct reasons + if (error.code === "SYMLINK_ESCAPE") { + return { ok: false, reason: "symlink-escape" }; + } + return { ok: false, reason: "outside-worktree" }; + } + // File not found or other read error + return { ok: false, reason: "not-found" }; + } + }), }); }; @@ -91,26 +183,41 @@ async function getFileVersions( } } +/** Helper to safely get git show content with size limit and memory protection */ +async function safeGitShow( + git: ReturnType, + spec: string, +): Promise { + try { + // Preflight: check blob size before loading into memory + // This prevents memory spikes from large files in git history + try { + const sizeOutput = await git.raw(["cat-file", "-s", spec]); + const blobSize = Number.parseInt(sizeOutput.trim(), 10); + if (!Number.isNaN(blobSize) && blobSize > MAX_FILE_SIZE) { + return `[File content truncated - exceeds ${MAX_FILE_SIZE / 1024 / 1024}MB limit]`; + } + } catch { + // cat-file failed (blob doesn't exist) - let git.show handle the error + } + + const content = await git.show([spec]); + return content; + } catch { + return ""; + } +} + async function getAgainstBaseVersions( git: ReturnType, filePath: string, originalPath: string, defaultBranch: string, ): Promise { - let original = ""; - let modified = ""; - - try { - original = await git.show([`origin/${defaultBranch}:${originalPath}`]); - } catch { - original = ""; - } - - try { - modified = await git.show([`HEAD:${filePath}`]); - } catch { - modified = ""; - } + const [original, modified] = await Promise.all([ + safeGitShow(git, `origin/${defaultBranch}:${originalPath}`), + safeGitShow(git, `HEAD:${filePath}`), + ]); return { original, modified }; } @@ -121,20 +228,10 @@ async function getCommittedVersions( originalPath: string, commitHash: string, ): Promise { - let original = ""; - let modified = ""; - - try { - original = await git.show([`${commitHash}^:${originalPath}`]); - } catch { - original = ""; - } - - try { - modified = await git.show([`${commitHash}:${filePath}`]); - } catch { - modified = ""; - } + const [original, modified] = await Promise.all([ + safeGitShow(git, `${commitHash}^:${originalPath}`), + safeGitShow(git, `${commitHash}:${filePath}`), + ]); return { original, modified }; } @@ -144,20 +241,10 @@ async function getStagedVersions( filePath: string, originalPath: string, ): Promise { - let original = ""; - let modified = ""; - - try { - original = await git.show([`HEAD:${originalPath}`]); - } catch { - original = ""; - } - - try { - modified = await git.show([`:0:${filePath}`]); - } catch { - modified = ""; - } + const [original, modified] = await Promise.all([ + safeGitShow(git, `HEAD:${originalPath}`), + safeGitShow(git, `:0:${filePath}`), + ]); return { original, modified }; } @@ -168,22 +255,23 @@ async function getUnstagedVersions( filePath: string, originalPath: string, ): Promise { - let original = ""; - let modified = ""; - - try { - original = await git.show([`:0:${originalPath}`]); - } catch { - try { - original = await git.show([`HEAD:${originalPath}`]); - } catch { - original = ""; - } + // Try staged version first, fall back to HEAD + let original = await safeGitShow(git, `:0:${originalPath}`); + if (!original) { + original = await safeGitShow(git, `HEAD:${originalPath}`); } + let modified = ""; try { - modified = await readFile(join(worktreePath, filePath), "utf-8"); + // Check file size before reading (uses stat which follows symlinks) + const stats = await secureFs.stat(worktreePath, filePath); + if (stats.size <= MAX_FILE_SIZE) { + modified = await secureFs.readFile(worktreePath, filePath); + } else { + modified = `[File content truncated - exceeds ${MAX_FILE_SIZE / 1024 / 1024}MB limit]`; + } } catch { + // File doesn't exist or validation failed - that's ok for diff display modified = ""; } diff --git a/apps/desktop/src/lib/trpc/routers/changes/git-operations.ts b/apps/desktop/src/lib/trpc/routers/changes/git-operations.ts index 6e6f584cfe4..35f58d7c956 100644 --- a/apps/desktop/src/lib/trpc/routers/changes/git-operations.ts +++ b/apps/desktop/src/lib/trpc/routers/changes/git-operations.ts @@ -1,10 +1,9 @@ -import { writeFile } from "node:fs/promises"; -import { resolve } from "node:path"; import { shell } from "electron"; import simpleGit from "simple-git"; import { z } from "zod"; import { publicProcedure, router } from "../.."; import { isUpstreamMissingError } from "./git-utils"; +import { assertRegisteredWorktree } from "./security"; export { isUpstreamMissingError }; @@ -21,25 +20,8 @@ async function hasUpstreamBranch( export const createGitOperationsRouter = () => { return router({ - saveFile: publicProcedure - .input( - z.object({ - worktreePath: z.string(), - filePath: z.string(), - content: z.string(), - }), - ) - .mutation(async ({ input }): Promise<{ success: boolean }> => { - const resolvedWorktree = resolve(input.worktreePath); - const fullPath = resolve(resolvedWorktree, input.filePath); - - if (!fullPath.startsWith(`${resolvedWorktree}/`)) { - throw new Error("Invalid file path: path traversal detected"); - } - - await writeFile(fullPath, input.content, "utf-8"); - return { success: true }; - }), + // NOTE: saveFile is defined in file-contents.ts with hardened path validation + // Do NOT add saveFile here - it would overwrite the secure version commit: publicProcedure .input( @@ -50,6 +32,9 @@ export const createGitOperationsRouter = () => { ) .mutation( async ({ input }): Promise<{ success: boolean; hash: string }> => { + // SECURITY: Validate worktreePath exists in localDb + assertRegisteredWorktree(input.worktreePath); + const git = simpleGit(input.worktreePath); const result = await git.commit(input.message); return { success: true, hash: result.commit }; @@ -64,6 +49,9 @@ export const createGitOperationsRouter = () => { }), ) .mutation(async ({ input }): Promise<{ success: boolean }> => { + // SECURITY: Validate worktreePath exists in localDb + assertRegisteredWorktree(input.worktreePath); + const git = simpleGit(input.worktreePath); const hasUpstream = await hasUpstreamBranch(git); @@ -84,6 +72,9 @@ export const createGitOperationsRouter = () => { }), ) .mutation(async ({ input }): Promise<{ success: boolean }> => { + // SECURITY: Validate worktreePath exists in localDb + assertRegisteredWorktree(input.worktreePath); + const git = simpleGit(input.worktreePath); try { await git.pull(["--rebase"]); @@ -107,6 +98,9 @@ export const createGitOperationsRouter = () => { }), ) .mutation(async ({ input }): Promise<{ success: boolean }> => { + // SECURITY: Validate worktreePath exists in localDb + assertRegisteredWorktree(input.worktreePath); + const git = simpleGit(input.worktreePath); try { await git.pull(["--rebase"]); @@ -134,6 +128,9 @@ export const createGitOperationsRouter = () => { ) .mutation( async ({ input }): Promise<{ success: boolean; url: string }> => { + // SECURITY: Validate worktreePath exists in localDb + assertRegisteredWorktree(input.worktreePath); + const git = simpleGit(input.worktreePath); const branch = (await git.revparse(["--abbrev-ref", "HEAD"])).trim(); const hasUpstream = await hasUpstreamBranch(git); diff --git a/apps/desktop/src/lib/trpc/routers/changes/security/git-commands.ts b/apps/desktop/src/lib/trpc/routers/changes/security/git-commands.ts new file mode 100644 index 00000000000..643c7826e6d --- /dev/null +++ b/apps/desktop/src/lib/trpc/routers/changes/security/git-commands.ts @@ -0,0 +1,139 @@ +import simpleGit from "simple-git"; +import { + assertRegisteredWorktree, + assertValidGitPath, +} from "./path-validation"; + +/** + * Git command helpers with semantic naming. + * + * Design principle: Different functions for different git semantics. + * You can't accidentally use file checkout syntax for branch switching. + * + * Each function: + * 1. Validates worktree is registered + * 2. Validates paths/refs as appropriate + * 3. Uses the correct git command syntax + */ + +/** + * Switch to a branch. + * + * Uses `git switch` (unambiguous branch operation, git 2.23+). + * Falls back to `git checkout ` for older git versions. + * + * Note: `git checkout -- ` is WRONG - that's file checkout syntax. + */ +export async function gitSwitchBranch( + worktreePath: string, + branch: string, +): Promise { + assertRegisteredWorktree(worktreePath); + + // Validate: reject anything that looks like a flag + if (branch.startsWith("-")) { + throw new Error("Invalid branch name: cannot start with -"); + } + + // Validate: reject empty branch names + if (!branch.trim()) { + throw new Error("Invalid branch name: cannot be empty"); + } + + const git = simpleGit(worktreePath); + + try { + // Prefer `git switch` - unambiguous branch operation (git 2.23+) + await git.raw(["switch", branch]); + } catch (switchError) { + // Check if it's because `switch` command doesn't exist (old git) + const errorMessage = String(switchError); + if ( + errorMessage.includes("is not a git command") || + errorMessage.includes("unknown switch") + ) { + // Fallback for older git versions + // Note: checkout WITHOUT -- is correct for branches + await git.checkout(branch); + } else { + throw switchError; + } + } +} + +/** + * Checkout (restore) a file path, discarding local changes. + * + * Uses `git checkout -- ` - the `--` is REQUIRED here + * to indicate path mode (not branch mode). + */ +export async function gitCheckoutFile( + worktreePath: string, + filePath: string, +): Promise { + assertRegisteredWorktree(worktreePath); + assertValidGitPath(filePath); + + const git = simpleGit(worktreePath); + // `--` is correct here - we want path semantics + await git.checkout(["--", filePath]); +} + +/** + * Stage a file for commit. + * + * Uses `git add -- ` - the `--` prevents paths starting + * with `-` from being interpreted as flags. + */ +export async function gitStageFile( + worktreePath: string, + filePath: string, +): Promise { + assertRegisteredWorktree(worktreePath); + assertValidGitPath(filePath); + + const git = simpleGit(worktreePath); + await git.add(["--", filePath]); +} + +/** + * Stage all changes for commit. + * + * Uses `git add -A` to stage all changes (new, modified, deleted). + */ +export async function gitStageAll(worktreePath: string): Promise { + assertRegisteredWorktree(worktreePath); + + const git = simpleGit(worktreePath); + await git.add("-A"); +} + +/** + * Unstage a file (remove from staging area). + * + * Uses `git reset HEAD -- ` to unstage without + * discarding changes. + */ +export async function gitUnstageFile( + worktreePath: string, + filePath: string, +): Promise { + assertRegisteredWorktree(worktreePath); + assertValidGitPath(filePath); + + const git = simpleGit(worktreePath); + await git.reset(["HEAD", "--", filePath]); +} + +/** + * Unstage all files. + * + * Uses `git reset HEAD` to unstage all changes without + * discarding them. + */ +export async function gitUnstageAll(worktreePath: string): Promise { + assertRegisteredWorktree(worktreePath); + + const git = simpleGit(worktreePath); + await git.reset(["HEAD"]); +} diff --git a/apps/desktop/src/lib/trpc/routers/changes/security/index.ts b/apps/desktop/src/lib/trpc/routers/changes/security/index.ts new file mode 100644 index 00000000000..8fdb09c9e7a --- /dev/null +++ b/apps/desktop/src/lib/trpc/routers/changes/security/index.ts @@ -0,0 +1,31 @@ +/** + * Security module for changes routers. + * + * Security model: + * - PRIMARY: Worktree must be registered in localDb + * - SECONDARY: Paths validated for traversal attempts + * + * See path-validation.ts header for full threat model. + */ + +export { + gitCheckoutFile, + gitStageAll, + gitStageFile, + gitSwitchBranch, + gitUnstageAll, + gitUnstageFile, +} from "./git-commands"; + +export { + assertRegisteredWorktree, + assertValidGitPath, + getRegisteredWorktree, + PathValidationError, + type PathValidationErrorCode, + resolvePathInWorktree, + type ValidatePathOptions, + validateRelativePath, +} from "./path-validation"; + +export { secureFs } from "./secure-fs"; diff --git a/apps/desktop/src/lib/trpc/routers/changes/security/path-validation.ts b/apps/desktop/src/lib/trpc/routers/changes/security/path-validation.ts new file mode 100644 index 00000000000..317994323f3 --- /dev/null +++ b/apps/desktop/src/lib/trpc/routers/changes/security/path-validation.ts @@ -0,0 +1,194 @@ +import { isAbsolute, normalize, resolve, sep } from "node:path"; +import { projects, worktrees } from "@superset/local-db"; +import { eq } from "drizzle-orm"; +import { localDb } from "main/lib/local-db"; + +/** + * Security model for desktop app filesystem access: + * + * THREAT MODEL: + * While a compromised renderer can execute commands via terminal panes, + * the File Viewer presents a distinct threat: malicious repositories can + * contain symlinks that trick users into reading/writing sensitive files + * (e.g., `docs/config.yml` → `~/.bashrc`). Users clicking these links + * don't know they're accessing files outside the repo. + * + * PRIMARY BOUNDARY: assertRegisteredWorktree() + * - Only worktree paths registered in localDb are accessible via tRPC + * - Prevents direct filesystem access to unregistered paths + * + * SECONDARY: validateRelativePath() + * - Rejects absolute paths and ".." traversal segments + * - Defense in depth against path manipulation + * + * SYMLINK PROTECTION (secure-fs.ts): + * - Writes: Block if realpath escapes worktree (prevents accidental overwrites) + * - Reads: Caller can check isSymlinkEscaping() to warn users + */ + +/** + * Security error codes for path validation failures. + */ +export type PathValidationErrorCode = + | "ABSOLUTE_PATH" + | "PATH_TRAVERSAL" + | "UNREGISTERED_WORKTREE" + | "INVALID_TARGET" + | "SYMLINK_ESCAPE"; + +/** + * Error thrown when path validation fails. + * Includes a code for programmatic handling. + */ +export class PathValidationError extends Error { + constructor( + message: string, + public readonly code: PathValidationErrorCode, + ) { + super(message); + this.name = "PathValidationError"; + } +} + +/** + * Validates that a workspace path is registered in localDb. + * This is THE critical security boundary. + * + * Accepts: + * - Worktree paths (from worktrees table) + * - Project mainRepoPath (for branch workspaces that work on the main repo) + * + * @throws PathValidationError if path is not registered + */ +export function assertRegisteredWorktree(workspacePath: string): void { + // Check worktrees table first (most common case) + const worktreeExists = localDb + .select() + .from(worktrees) + .where(eq(worktrees.path, workspacePath)) + .get(); + + if (worktreeExists) { + return; + } + + // Check projects.mainRepoPath for branch workspaces + const projectExists = localDb + .select() + .from(projects) + .where(eq(projects.mainRepoPath, workspacePath)) + .get(); + + if (projectExists) { + return; + } + + throw new PathValidationError( + "Workspace path not registered in database", + "UNREGISTERED_WORKTREE", + ); +} + +/** + * Gets the worktree record if registered. Returns record for updates. + * Only works for actual worktrees, not project mainRepoPath. + * + * @throws PathValidationError if worktree is not registered + */ +export function getRegisteredWorktree( + worktreePath: string, +): typeof worktrees.$inferSelect { + const worktree = localDb + .select() + .from(worktrees) + .where(eq(worktrees.path, worktreePath)) + .get(); + + if (!worktree) { + throw new PathValidationError( + "Worktree not registered in database", + "UNREGISTERED_WORKTREE", + ); + } + + return worktree; +} + +/** + * Options for path validation. + */ +export interface ValidatePathOptions { + /** + * Allow empty/root path (resolves to worktree itself). + * Default: false (prevents accidental worktree deletion) + */ + allowRoot?: boolean; +} + +/** + * Validates a relative file path for safety. + * Rejects absolute paths and path traversal attempts. + * + * @throws PathValidationError if path is invalid + */ +export function validateRelativePath( + filePath: string, + options: ValidatePathOptions = {}, +): void { + const { allowRoot = false } = options; + + // Reject absolute paths + if (isAbsolute(filePath)) { + throw new PathValidationError( + "Absolute paths are not allowed", + "ABSOLUTE_PATH", + ); + } + + const normalized = normalize(filePath); + const segments = normalized.split(sep); + + // Reject ".." as a path segment (allows "..foo" directories) + if (segments.includes("..")) { + throw new PathValidationError( + "Path traversal not allowed", + "PATH_TRAVERSAL", + ); + } + + // Reject root path unless explicitly allowed + if (!allowRoot && (normalized === "" || normalized === ".")) { + throw new PathValidationError( + "Cannot target worktree root", + "INVALID_TARGET", + ); + } +} + +/** + * Validates and resolves a path within a worktree. Sync, simple. + * + * @param worktreePath - The worktree base path + * @param filePath - The relative file path to validate + * @param options - Validation options + * @returns The resolved full path + * @throws PathValidationError if path is invalid + */ +export function resolvePathInWorktree( + worktreePath: string, + filePath: string, + options: ValidatePathOptions = {}, +): string { + validateRelativePath(filePath, options); + // Use resolve to handle any worktreePath (relative or absolute) + return resolve(worktreePath, normalize(filePath)); +} + +/** + * Validates a path for git commands. Lighter check that allows root. + * + * @throws PathValidationError if path is invalid + */ +export function assertValidGitPath(filePath: string): void { + validateRelativePath(filePath, { allowRoot: true }); +} diff --git a/apps/desktop/src/lib/trpc/routers/changes/security/secure-fs.ts b/apps/desktop/src/lib/trpc/routers/changes/security/secure-fs.ts new file mode 100644 index 00000000000..6d72eb31109 --- /dev/null +++ b/apps/desktop/src/lib/trpc/routers/changes/security/secure-fs.ts @@ -0,0 +1,466 @@ +import type { Stats } from "node:fs"; +import { + lstat, + readFile, + readlink, + realpath, + rm, + stat, + writeFile, +} from "node:fs/promises"; +import { dirname, isAbsolute, relative, resolve, sep } from "node:path"; +import { + assertRegisteredWorktree, + PathValidationError, + resolvePathInWorktree, +} from "./path-validation"; + +/** + * Secure filesystem operations with built-in validation. + * + * Each operation: + * 1. Validates worktree is registered (security boundary) + * 2. Validates path doesn't escape worktree (defense in depth) + * 3. For writes: validates target is not a symlink escaping worktree + * 4. Performs the filesystem operation + * + * See path-validation.ts for the full security model and threat assumptions. + */ + +/** + * Check if a resolved path is within the worktree boundary using path.relative(). + * This is safer than string prefix matching which can have boundary bugs. + */ +function isPathWithinWorktree( + worktreeReal: string, + targetReal: string, +): boolean { + if (targetReal === worktreeReal) { + return true; + } + const relativePath = relative(worktreeReal, targetReal); + // Check if path escapes worktree: + // - ".." means direct parent + // - "../" prefix means ancestor escape (use sep for cross-platform) + // - Absolute path means completely outside + // Note: Don't use startsWith("..") as it incorrectly catches "..config" directories + const escapesWorktree = + relativePath === ".." || + relativePath.startsWith(`..${sep}`) || + isAbsolute(relativePath) || + relativePath === ""; + + return !escapesWorktree; +} + +/** + * Validate that the parent directory chain stays within the worktree. + * Handles the case where the target file doesn't exist yet (ENOENT). + * + * This function walks up the directory tree to find the first existing + * ancestor and validates it. It also detects dangling symlinks by checking + * if any component is a symlink pointing outside the worktree. + * + * @throws PathValidationError if any ancestor escapes the worktree + */ +async function assertParentInWorktree( + worktreePath: string, + fullPath: string, +): Promise { + const worktreeReal = await realpath(worktreePath); + let currentPath = dirname(fullPath); + + // Walk up the directory tree until we find an existing directory + while (currentPath !== dirname(currentPath)) { + // Stop at filesystem root + try { + // First check if this path component is a symlink (even if target doesn't exist) + const stats = await lstat(currentPath); + + if (stats.isSymbolicLink()) { + // This is a symlink - validate its target even if it doesn't exist + const linkTarget = await readlink(currentPath); + // Resolve the link target relative to the symlink's parent + const resolvedTarget = isAbsolute(linkTarget) + ? linkTarget + : resolve(dirname(currentPath), linkTarget); + + // Try to get the realpath of the resolved target + try { + const targetReal = await realpath(resolvedTarget); + if (!isPathWithinWorktree(worktreeReal, targetReal)) { + throw new PathValidationError( + "Symlink in path resolves outside the worktree", + "SYMLINK_ESCAPE", + ); + } + } catch (error) { + // Target doesn't exist - check if the resolved target path + // would be within worktree if it existed + if ( + error instanceof Error && + "code" in error && + error.code === "ENOENT" + ) { + // For dangling symlinks, validate the target path itself + // We need to check if the target, when resolved, would be in worktree + // This is conservative: if we can't determine, fail closed + const targetRelative = relative(worktreeReal, resolvedTarget); + // Use sep-aware check to avoid false positives on "..config" dirs + if ( + targetRelative === ".." || + targetRelative.startsWith(`..${sep}`) || + isAbsolute(targetRelative) + ) { + throw new PathValidationError( + "Dangling symlink points outside the worktree", + "SYMLINK_ESCAPE", + ); + } + // Target would be within worktree if it existed - continue + return; + } + if (error instanceof PathValidationError) { + throw error; + } + // Other errors - fail closed for security + throw new PathValidationError( + "Cannot validate symlink target", + "SYMLINK_ESCAPE", + ); + } + return; // Symlink validated successfully + } + + // Not a symlink - get realpath and validate + const parentReal = await realpath(currentPath); + if (!isPathWithinWorktree(worktreeReal, parentReal)) { + throw new PathValidationError( + "Parent directory resolves outside the worktree", + "SYMLINK_ESCAPE", + ); + } + return; // Found valid ancestor + } catch (error) { + if (error instanceof PathValidationError) { + throw error; + } + if ( + error instanceof Error && + "code" in error && + error.code === "ENOENT" + ) { + // This ancestor doesn't exist either, keep walking up + currentPath = dirname(currentPath); + continue; + } + // Other errors (EACCES, ENOTDIR, etc.) - fail closed for security + throw new PathValidationError( + "Cannot validate path ancestry", + "SYMLINK_ESCAPE", + ); + } + } + + // Reached filesystem root without finding valid ancestor + throw new PathValidationError( + "Could not validate path ancestry within worktree", + "SYMLINK_ESCAPE", + ); +} + +/** + * Check if the resolved realpath stays within the worktree boundary. + * Prevents symlink escape attacks where a symlink points outside the worktree. + * + * @throws PathValidationError if realpath escapes worktree + */ +async function assertRealpathInWorktree( + worktreePath: string, + fullPath: string, +): Promise { + try { + const real = await realpath(fullPath); + const worktreeReal = await realpath(worktreePath); + + // Use path.relative for safer boundary checking + if (!isPathWithinWorktree(worktreeReal, real)) { + throw new PathValidationError( + "File is a symlink pointing outside the worktree", + "SYMLINK_ESCAPE", + ); + } + } catch (error) { + // If realpath fails with ENOENT, the target doesn't exist + // But the path itself might be a dangling symlink - check that first! + if (error instanceof Error && "code" in error && error.code === "ENOENT") { + await assertDanglingSymlinkSafe(worktreePath, fullPath); + return; + } + // Re-throw PathValidationError + if (error instanceof PathValidationError) { + throw error; + } + // Other errors (permission denied, etc.) - fail closed for security + throw new PathValidationError( + "Cannot validate file path", + "SYMLINK_ESCAPE", + ); + } +} + +/** + * Handle the ENOENT case: check if fullPath is a dangling symlink pointing outside + * the worktree, or if it truly doesn't exist (in which case validate parent chain). + * + * Attack scenario this prevents: + * - Repo contains `docs/config.yml` → symlink to `~/.ssh/some_new_file` (doesn't exist) + * - realpath() fails with ENOENT (target missing) + * - Without this check, we'd only validate parent (`docs/`) which is valid + * - Write would follow symlink and create `~/.ssh/some_new_file` + * + * @throws PathValidationError if symlink escapes worktree + */ +async function assertDanglingSymlinkSafe( + worktreePath: string, + fullPath: string, +): Promise { + const worktreeReal = await realpath(worktreePath); + + try { + // Check if the path itself exists (as a symlink or otherwise) + const stats = await lstat(fullPath); + + if (stats.isSymbolicLink()) { + // It's a dangling symlink - validate where it points + const linkTarget = await readlink(fullPath); + const resolvedTarget = isAbsolute(linkTarget) + ? linkTarget + : resolve(dirname(fullPath), linkTarget); + + // Check if the resolved target would be within worktree + // For dangling symlinks, we can't use realpath on the target, + // so we check the literal resolved path + const targetRelative = relative(worktreeReal, resolvedTarget); + if ( + targetRelative === ".." || + targetRelative.startsWith(`..${sep}`) || + isAbsolute(targetRelative) + ) { + throw new PathValidationError( + "Dangling symlink points outside the worktree", + "SYMLINK_ESCAPE", + ); + } + // Dangling symlink points within worktree - allow the operation + return; + } + + // Not a symlink but lstat succeeded - weird state, but validate parent chain + await assertParentInWorktree(worktreePath, fullPath); + } catch (error) { + if (error instanceof PathValidationError) { + throw error; + } + if (error instanceof Error && "code" in error && error.code === "ENOENT") { + // Path truly doesn't exist (not even as a symlink) - validate parent chain + await assertParentInWorktree(worktreePath, fullPath); + return; + } + // Other errors - fail closed + throw new PathValidationError("Cannot validate path", "SYMLINK_ESCAPE"); + } +} +export const secureFs = { + /** + * Read a file within a worktree. + * + * SECURITY: Enforces symlink-escape check. If the file is a symlink + * pointing outside the worktree, this will throw PathValidationError. + * + * @throws PathValidationError with code "SYMLINK_ESCAPE" if file escapes worktree + */ + async readFile( + worktreePath: string, + filePath: string, + encoding: BufferEncoding = "utf-8", + ): Promise { + assertRegisteredWorktree(worktreePath); + const fullPath = resolvePathInWorktree(worktreePath, filePath); + + // Block reads through symlinks that escape the worktree + await assertRealpathInWorktree(worktreePath, fullPath); + + return readFile(fullPath, encoding); + }, + + /** + * Read a file as a Buffer within a worktree. + * + * SECURITY: Enforces symlink-escape check. If the file is a symlink + * pointing outside the worktree, this will throw PathValidationError. + * + * @throws PathValidationError with code "SYMLINK_ESCAPE" if file escapes worktree + */ + async readFileBuffer( + worktreePath: string, + filePath: string, + ): Promise { + assertRegisteredWorktree(worktreePath); + const fullPath = resolvePathInWorktree(worktreePath, filePath); + + // Block reads through symlinks that escape the worktree + await assertRealpathInWorktree(worktreePath, fullPath); + + return readFile(fullPath); + }, + + /** + * Write content to a file within a worktree. + * + * SECURITY: Blocks writes if the file is a symlink pointing outside + * the worktree. This prevents malicious repos from tricking users + * into overwriting sensitive files like ~/.bashrc. + * + * @throws PathValidationError with code "SYMLINK_ESCAPE" if target escapes worktree + */ + async writeFile( + worktreePath: string, + filePath: string, + content: string, + ): Promise { + assertRegisteredWorktree(worktreePath); + const fullPath = resolvePathInWorktree(worktreePath, filePath); + + // Block writes through symlinks that escape the worktree + await assertRealpathInWorktree(worktreePath, fullPath); + + await writeFile(fullPath, content, "utf-8"); + }, + + /** + * Delete a file or directory within a worktree. + * + * SECURITY: Validates the real path is within worktree before deletion. + * - Symlinks: Deletes the link itself (safe - link lives in worktree) + * - Files/dirs: Validates realpath then deletes + * + * This prevents symlink escape attacks where a malicious repo contains + * `docs -> /Users/victim` and a delete of `docs/file` would delete + * `/Users/victim/file`. + */ + async delete(worktreePath: string, filePath: string): Promise { + assertRegisteredWorktree(worktreePath); + // allowRoot: false prevents deleting the worktree itself + const fullPath = resolvePathInWorktree(worktreePath, filePath, { + allowRoot: false, + }); + + let stats: Stats; + try { + stats = await lstat(fullPath); + } catch (error) { + // File doesn't exist - idempotent delete, nothing to do + if ( + error instanceof Error && + "code" in error && + error.code === "ENOENT" + ) { + return; + } + throw error; + } + + if (stats.isSymbolicLink()) { + // Symlink - safe to delete the link itself (it lives in the worktree). + // Don't use recursive as we're just removing the symlink file. + await rm(fullPath); + return; + } + + // Regular file or directory - validate realpath is within worktree. + // This catches path traversal via symlinked parent components: + // e.g., `docs -> /victim`, delete `docs/file` → realpath is `/victim/file` + await assertRealpathInWorktree(worktreePath, fullPath); + + // Safe to delete - realpath confirmed within worktree. + // Note: Symlinks INSIDE a directory are safe - rm deletes the links, not targets. + await rm(fullPath, { recursive: true, force: true }); + }, + + /** + * Get file stats within a worktree. + * + * Uses `stat` (follows symlinks) to get the real file size. + */ + async stat(worktreePath: string, filePath: string): Promise { + assertRegisteredWorktree(worktreePath); + const fullPath = resolvePathInWorktree(worktreePath, filePath); + return stat(fullPath); + }, + + /** + * Get file stats without following symlinks. + * + * Use this when you need to know if something IS a symlink. + * For size checks, prefer `stat` instead. + */ + async lstat(worktreePath: string, filePath: string): Promise { + assertRegisteredWorktree(worktreePath); + const fullPath = resolvePathInWorktree(worktreePath, filePath); + return lstat(fullPath); + }, + + /** + * Check if a file exists within a worktree. + * + * Returns false for non-existent files and validation failures. + */ + async exists(worktreePath: string, filePath: string): Promise { + try { + assertRegisteredWorktree(worktreePath); + const fullPath = resolvePathInWorktree(worktreePath, filePath); + await stat(fullPath); + return true; + } catch { + return false; + } + }, + + /** + * Check if a file is a symlink that points outside the worktree. + * + * WARNING: This is a best-effort helper for UI warnings only. + * It returns `false` on errors, so it is NOT suitable as a security gate. + * For security enforcement, use the read/write methods which call + * assertRealpathInWorktree internally. + * + * @returns true if the file is definitely a symlink escaping the worktree, + * false if not escaping OR if we can't determine (errors) + */ + async isSymlinkEscaping( + worktreePath: string, + filePath: string, + ): Promise { + try { + assertRegisteredWorktree(worktreePath); + const fullPath = resolvePathInWorktree(worktreePath, filePath); + + // Check if it's a symlink first + const stats = await lstat(fullPath); + if (!stats.isSymbolicLink()) { + return false; + } + + // Check if realpath escapes worktree + const real = await realpath(fullPath); + const worktreeReal = await realpath(worktreePath); + + return !isPathWithinWorktree(worktreeReal, real); + } catch { + // If we can't determine, assume not escaping (file may not exist) + // NOTE: This makes this method unsuitable as a security gate + return false; + } + }, +}; diff --git a/apps/desktop/src/lib/trpc/routers/changes/staging.ts b/apps/desktop/src/lib/trpc/routers/changes/staging.ts index 1d3109a65d8..037227fa4f8 100644 --- a/apps/desktop/src/lib/trpc/routers/changes/staging.ts +++ b/apps/desktop/src/lib/trpc/routers/changes/staging.ts @@ -1,8 +1,13 @@ -import { rm } from "node:fs/promises"; -import { join } from "node:path"; -import simpleGit from "simple-git"; import { z } from "zod"; import { publicProcedure, router } from "../.."; +import { + gitCheckoutFile, + gitStageAll, + gitStageFile, + gitUnstageAll, + gitUnstageFile, + secureFs, +} from "./security"; export const createStagingRouter = () => { return router({ @@ -14,8 +19,7 @@ export const createStagingRouter = () => { }), ) .mutation(async ({ input }): Promise<{ success: boolean }> => { - const git = simpleGit(input.worktreePath); - await git.add(input.filePath); + await gitStageFile(input.worktreePath, input.filePath); return { success: true }; }), @@ -27,8 +31,7 @@ export const createStagingRouter = () => { }), ) .mutation(async ({ input }): Promise<{ success: boolean }> => { - const git = simpleGit(input.worktreePath); - await git.reset(["HEAD", "--", input.filePath]); + await gitUnstageFile(input.worktreePath, input.filePath); return { success: true }; }), @@ -40,24 +43,21 @@ export const createStagingRouter = () => { }), ) .mutation(async ({ input }): Promise<{ success: boolean }> => { - const git = simpleGit(input.worktreePath); - await git.checkout(["--", input.filePath]); + await gitCheckoutFile(input.worktreePath, input.filePath); return { success: true }; }), stageAll: publicProcedure .input(z.object({ worktreePath: z.string() })) .mutation(async ({ input }): Promise<{ success: boolean }> => { - const git = simpleGit(input.worktreePath); - await git.add("-A"); + await gitStageAll(input.worktreePath); return { success: true }; }), unstageAll: publicProcedure .input(z.object({ worktreePath: z.string() })) .mutation(async ({ input }): Promise<{ success: boolean }> => { - const git = simpleGit(input.worktreePath); - await git.reset(["HEAD"]); + await gitUnstageAll(input.worktreePath); return { success: true }; }), @@ -69,8 +69,8 @@ export const createStagingRouter = () => { }), ) .mutation(async ({ input }): Promise<{ success: boolean }> => { - const fullPath = join(input.worktreePath, input.filePath); - await rm(fullPath, { recursive: true, force: true }); + // secureFs.delete validates worktree registration and path traversal + await secureFs.delete(input.worktreePath, input.filePath); return { success: true }; }), }); diff --git a/apps/desktop/src/lib/trpc/routers/changes/status.ts b/apps/desktop/src/lib/trpc/routers/changes/status.ts index c547b98558c..9b79a161a71 100644 --- a/apps/desktop/src/lib/trpc/routers/changes/status.ts +++ b/apps/desktop/src/lib/trpc/routers/changes/status.ts @@ -1,9 +1,8 @@ -import { readFile } from "node:fs/promises"; -import { join } from "node:path"; import type { ChangedFile, GitChangesStatus } from "shared/changes-types"; import simpleGit from "simple-git"; import { z } from "zod"; import { publicProcedure, router } from "../.."; +import { assertRegisteredWorktree, secureFs } from "./security"; import { applyNumstatToFiles } from "./utils/apply-numstat"; import { parseGitLog, @@ -21,6 +20,8 @@ export const createStatusRouter = () => { }), ) .query(async ({ input }): Promise => { + assertRegisteredWorktree(input.worktreePath); + const git = simpleGit(input.worktreePath); const defaultBranch = input.defaultBranch || "main"; @@ -64,6 +65,8 @@ export const createStatusRouter = () => { }), ) .query(async ({ input }): Promise => { + assertRegisteredWorktree(input.worktreePath); + const git = simpleGit(input.worktreePath); const nameStatus = await git.raw([ @@ -141,18 +144,34 @@ async function getBranchComparison( return { commits, againstBase, ahead, behind }; } +/** Max file size for line counting (1 MiB) - skip larger files to avoid OOM */ +const MAX_LINE_COUNT_SIZE = 1 * 1024 * 1024; + +/** + * Apply line counts to untracked files. + * + * Uses secureFs which: + * - Validates paths don't escape worktree + * - Uses stat (follows symlinks) for accurate size checks + * - Checks for symlink escapes + */ async function applyUntrackedLineCount( worktreePath: string, untracked: ChangedFile[], ): Promise { for (const file of untracked) { try { - const fullPath = join(worktreePath, file.path); - const content = await readFile(fullPath, "utf-8"); + // secureFs.stat uses stat (follows symlinks) for accurate size + const stats = await secureFs.stat(worktreePath, file.path); + if (stats.size > MAX_LINE_COUNT_SIZE) continue; + + const content = await secureFs.readFile(worktreePath, file.path); const lineCount = content.split("\n").length; file.additions = lineCount; file.deletions = 0; - } catch {} + } catch { + // Skip files that fail validation or reading + } } } diff --git a/apps/desktop/src/lib/trpc/routers/settings/index.ts b/apps/desktop/src/lib/trpc/routers/settings/index.ts index ce624581628..abc5cd8f903 100644 --- a/apps/desktop/src/lib/trpc/routers/settings/index.ts +++ b/apps/desktop/src/lib/trpc/routers/settings/index.ts @@ -1,6 +1,14 @@ -import { settings, type TerminalPreset } from "@superset/local-db"; +import { + settings, + TERMINAL_LINK_BEHAVIORS, + type TerminalPreset, +} from "@superset/local-db"; import { localDb } from "main/lib/local-db"; -import { DEFAULT_CONFIRM_ON_QUIT } from "shared/constants"; +import { + DEFAULT_CONFIRM_ON_QUIT, + DEFAULT_NAVIGATION_STYLE, + DEFAULT_TERMINAL_LINK_BEHAVIOR, +} from "shared/constants"; import { DEFAULT_RINGTONE_ID, RINGTONES } from "shared/ringtones"; import { z } from "zod"; import { publicProcedure, router } from "../.."; @@ -180,5 +188,45 @@ export const createSettingsRouter = () => { return { success: true }; }), + + getTerminalLinkBehavior: publicProcedure.query(() => { + const row = getSettings(); + return row.terminalLinkBehavior ?? DEFAULT_TERMINAL_LINK_BEHAVIOR; + }), + + setTerminalLinkBehavior: publicProcedure + .input(z.object({ behavior: z.enum(TERMINAL_LINK_BEHAVIORS) })) + .mutation(({ input }) => { + localDb + .insert(settings) + .values({ id: 1, terminalLinkBehavior: input.behavior }) + .onConflictDoUpdate({ + target: settings.id, + set: { terminalLinkBehavior: input.behavior }, + }) + .run(); + + return { success: true }; + }), + + getNavigationStyle: publicProcedure.query(() => { + const row = getSettings(); + return row.navigationStyle ?? DEFAULT_NAVIGATION_STYLE; + }), + + setNavigationStyle: publicProcedure + .input(z.object({ style: z.enum(["top-bar", "sidebar"]) })) + .mutation(({ input }) => { + localDb + .insert(settings) + .values({ id: 1, navigationStyle: input.style }) + .onConflictDoUpdate({ + target: settings.id, + set: { navigationStyle: input.style }, + }) + .run(); + + return { success: true }; + }), }); }; diff --git a/apps/desktop/src/lib/trpc/routers/ui-state/index.ts b/apps/desktop/src/lib/trpc/routers/ui-state/index.ts index 0d2b8e87f55..afbff9fc94b 100644 --- a/apps/desktop/src/lib/trpc/routers/ui-state/index.ts +++ b/apps/desktop/src/lib/trpc/routers/ui-state/index.ts @@ -10,19 +10,39 @@ import { import { z } from "zod"; import { publicProcedure, router } from "../.."; +/** + * Zod schema for FileViewerState persistence. + * Note: initialLine/initialColumn from shared/tabs-types.ts are intentionally + * omitted as they are transient (applied once on open, not persisted). + */ +const fileViewerStateSchema = z.object({ + filePath: z.string(), + viewMode: z.enum(["rendered", "raw", "diff"]), + isLocked: z.boolean(), + diffLayout: z.enum(["inline", "side-by-side"]), + diffCategory: z + .enum(["against-base", "committed", "staged", "unstaged"]) + .optional(), + commitHash: z.string().optional(), + oldPath: z.string().optional(), +}); + /** * Zod schema for Pane */ const paneSchema = z.object({ id: z.string(), tabId: z.string(), - type: z.enum(["terminal", "webview"]), + type: z.enum(["terminal", "webview", "file-viewer"]), name: z.string(), isNew: z.boolean().optional(), needsAttention: z.boolean().optional(), initialCommands: z.array(z.string()).optional(), initialCwd: z.string().optional(), url: z.string().optional(), + cwd: z.string().nullable().optional(), + cwdConfirmed: z.boolean().optional(), + fileViewer: fileViewerStateSchema.optional(), }); /** diff --git a/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts b/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts index 670b8e41b11..4a57d0a0c8c 100644 --- a/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts +++ b/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts @@ -7,7 +7,7 @@ import { workspaces, worktrees, } from "@superset/local-db"; -import { and, desc, eq, isNotNull } from "drizzle-orm"; +import { and, desc, eq, isNotNull, not } from "drizzle-orm"; import { track } from "main/lib/analytics"; import { localDb } from "main/lib/local-db"; import { terminalManager } from "main/lib/terminal"; @@ -305,22 +305,11 @@ export const createWorkspacesRouter = () => { }; } - // Shift existing workspaces to make room at front - const projectWorkspaces = localDb - .select() - .from(workspaces) - .where(eq(workspaces.projectId, input.projectId)) - .all(); - for (const ws of projectWorkspaces) { - localDb - .update(workspaces) - .set({ tabOrder: ws.tabOrder + 1 }) - .where(eq(workspaces.id, ws.id)) - .run(); - } - - // Insert new workspace - const workspace = localDb + // Insert new workspace first with conflict handling for race conditions + // The unique partial index (projectId WHERE type='branch') prevents duplicates + // We insert first, then shift - this prevents race conditions where + // concurrent calls both shift before either inserts (causing double shifts) + const insertResult = localDb .insert(workspaces) .values({ projectId: input.projectId, @@ -329,8 +318,54 @@ export const createWorkspacesRouter = () => { name: branch, tabOrder: 0, }) + .onConflictDoNothing() .returning() - .get(); + .all(); + + const wasExisting = insertResult.length === 0; + + // Only shift existing workspaces if we successfully inserted + // Losers of the race should NOT shift (they didn't create anything) + if (!wasExisting) { + const newWorkspaceId = insertResult[0].id; + const projectWorkspaces = localDb + .select() + .from(workspaces) + .where( + and( + eq(workspaces.projectId, input.projectId), + // Exclude the workspace we just inserted + not(eq(workspaces.id, newWorkspaceId)), + ), + ) + .all(); + for (const ws of projectWorkspaces) { + localDb + .update(workspaces) + .set({ tabOrder: ws.tabOrder + 1 }) + .where(eq(workspaces.id, ws.id)) + .run(); + } + } + + // If insert returned nothing, another concurrent call won the race + // Fetch the existing workspace instead + const workspace = + insertResult[0] ?? + localDb + .select() + .from(workspaces) + .where( + and( + eq(workspaces.projectId, input.projectId), + eq(workspaces.type, "branch"), + ), + ) + .get(); + + if (!workspace) { + throw new Error("Failed to create or find branch workspace"); + } // Update settings localDb @@ -342,41 +377,43 @@ export const createWorkspacesRouter = () => { }) .run(); - // Update project - const activeProjects = localDb - .select() - .from(projects) - .where(isNotNull(projects.tabOrder)) - .all(); - const maxProjectTabOrder = - activeProjects.length > 0 - ? Math.max(...activeProjects.map((p) => p.tabOrder ?? 0)) - : -1; + // Update project (only if we actually inserted a new workspace) + if (!wasExisting) { + const activeProjects = localDb + .select() + .from(projects) + .where(isNotNull(projects.tabOrder)) + .all(); + const maxProjectTabOrder = + activeProjects.length > 0 + ? Math.max(...activeProjects.map((p) => p.tabOrder ?? 0)) + : -1; - localDb - .update(projects) - .set({ - lastOpenedAt: Date.now(), - tabOrder: - project.tabOrder === null - ? maxProjectTabOrder + 1 - : project.tabOrder, - }) - .where(eq(projects.id, input.projectId)) - .run(); + localDb + .update(projects) + .set({ + lastOpenedAt: Date.now(), + tabOrder: + project.tabOrder === null + ? maxProjectTabOrder + 1 + : project.tabOrder, + }) + .where(eq(projects.id, input.projectId)) + .run(); - track("workspace_opened", { - workspace_id: workspace.id, - project_id: project.id, - type: "branch", - was_existing: false, - }); + track("workspace_opened", { + workspace_id: workspace.id, + project_id: project.id, + type: "branch", + was_existing: false, + }); + } return { workspace, worktreePath: project.mainRepoPath, projectId: project.id, - wasExisting: false, + wasExisting, }; }), @@ -546,6 +583,7 @@ export const createWorkspacesRouter = () => { createdAt: number; updatedAt: number; lastOpenedAt: number; + isUnread: boolean; }>; } >(); @@ -575,6 +613,7 @@ export const createWorkspacesRouter = () => { ...workspace, type: workspace.type as "worktree" | "branch", worktreePath: getWorkspacePath(workspace) ?? "", + isUnread: workspace.isUnread ?? false, }); } } @@ -977,10 +1016,18 @@ export const createWorkspacesRouter = () => { throw new Error(`Workspace ${input.id} not found`); } + // Track if workspace was unread before clearing + const wasUnread = workspace.isUnread ?? false; + const now = Date.now(); localDb .update(workspaces) - .set({ lastOpenedAt: now, updatedAt: now }) + .set({ + lastOpenedAt: now, + updatedAt: now, + // Auto-clear unread state when switching to workspace + isUnread: false, + }) .where(eq(workspaces.id, input.id)) .run(); @@ -993,7 +1040,7 @@ export const createWorkspacesRouter = () => { }) .run(); - return { success: true }; + return { success: true, wasUnread }; }), reorder: publicProcedure @@ -1331,6 +1378,27 @@ export const createWorkspacesRouter = () => { }; }), + setUnread: publicProcedure + .input(z.object({ id: z.string(), isUnread: z.boolean() })) + .mutation(({ input }) => { + const workspace = localDb + .select() + .from(workspaces) + .where(eq(workspaces.id, input.id)) + .get(); + if (!workspace) { + throw new Error(`Workspace ${input.id} not found`); + } + + localDb + .update(workspaces) + .set({ isUnread: input.isUnread }) + .where(eq(workspaces.id, input.id)) + .run(); + + return { success: true, isUnread: input.isUnread }; + }), + close: publicProcedure .input(z.object({ id: z.string() })) .mutation(async ({ input }) => { diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/SafeImage/SafeImage.tsx b/apps/desktop/src/renderer/components/MarkdownRenderer/components/SafeImage/SafeImage.tsx new file mode 100644 index 00000000000..91295eaa98f --- /dev/null +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/SafeImage/SafeImage.tsx @@ -0,0 +1,71 @@ +import { LuImageOff } from "react-icons/lu"; + +/** + * Check if an image source is safe to load. + * + * Uses strict ALLOWLIST approach - only data: URLs are safe. + * + * ALLOWED: + * - data: URLs (embedded base64 images) + * + * BLOCKED (everything else): + * - http://, https:// (tracking pixels, privacy leak) + * - file:// URLs (arbitrary local file access) + * - Absolute paths /... or \... (become file:// in Electron) + * - Relative paths with .. (can escape repo boundary) + * - UNC paths //server/share (Windows NTLM credential leak) + * - Empty or malformed sources + * + * Security context: In Electron production, renderer loads via file:// + * protocol. Any non-data: image src could access local filesystem or + * trigger network requests to attacker-controlled servers. + */ +function isSafeImageSrc(src: string | undefined): boolean { + if (!src) return false; + const trimmed = src.trim(); + if (trimmed.length === 0) return false; + + // Only allow data: URLs (embedded images) + // These are self-contained and can't access external resources + return trimmed.toLowerCase().startsWith("data:"); +} + +interface SafeImageProps { + src?: string; + alt?: string; + className?: string; +} + +/** + * Safe image component for untrusted markdown content. + * + * Only renders embedded data: URLs. All other sources are blocked + * to prevent local file access, network requests, and path traversal + * attacks from malicious repository content. + * + * Future: Could add opt-in support for repo-relative images via a + * secure loader that validates paths through secureFs and serves + * as blob: URLs. + */ +export function SafeImage({ src, alt, className }: SafeImageProps) { + if (!isSafeImageSrc(src)) { + return ( +
+ + Image blocked +
+ ); + } + + // Safe to render - embedded data: URL + return ( + {alt} + ); +} diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/SafeImage/index.ts b/apps/desktop/src/renderer/components/MarkdownRenderer/components/SafeImage/index.ts new file mode 100644 index 00000000000..3a608bf50fd --- /dev/null +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/SafeImage/index.ts @@ -0,0 +1 @@ +export { SafeImage } from "./SafeImage"; diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/components/index.ts b/apps/desktop/src/renderer/components/MarkdownRenderer/components/index.ts index b5cd6b0e8fd..d208845016c 100644 --- a/apps/desktop/src/renderer/components/MarkdownRenderer/components/index.ts +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/components/index.ts @@ -1,2 +1,3 @@ export { CodeBlock } from "./CodeBlock"; +export { SafeImage } from "./SafeImage"; export { SelectionContextMenu } from "./SelectionContextMenu"; diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/styles/default/config.tsx b/apps/desktop/src/renderer/components/MarkdownRenderer/styles/default/config.tsx index 61ef8cdd6a0..c19cc5e1b78 100644 --- a/apps/desktop/src/renderer/components/MarkdownRenderer/styles/default/config.tsx +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/styles/default/config.tsx @@ -1,5 +1,5 @@ import { cn } from "@superset/ui/utils"; -import { CodeBlock } from "../../components"; +import { CodeBlock, SafeImage } from "../../components"; import type { MarkdownStyleConfig } from "../types"; import "./default.css"; @@ -41,7 +41,11 @@ export const defaultConfig: MarkdownStyleConfig = { ), img: ({ src, alt }) => ( - {alt} + ), hr: () =>
, li: ({ children, className }) => { diff --git a/apps/desktop/src/renderer/components/MarkdownRenderer/styles/tufte/config.tsx b/apps/desktop/src/renderer/components/MarkdownRenderer/styles/tufte/config.tsx index 077f8d91371..5173f7e4557 100644 --- a/apps/desktop/src/renderer/components/MarkdownRenderer/styles/tufte/config.tsx +++ b/apps/desktop/src/renderer/components/MarkdownRenderer/styles/tufte/config.tsx @@ -1,4 +1,4 @@ -import { CodeBlock } from "../../components"; +import { CodeBlock, SafeImage } from "../../components"; import type { MarkdownStyleConfig } from "../types"; import "./tufte.css"; @@ -12,5 +12,7 @@ export const tufteConfig: MarkdownStyleConfig = { {children} ), + // Block external images for privacy (tracking pixels, etc.) + img: ({ src, alt }) => , }, }; diff --git a/apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModal.tsx b/apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModal.tsx index 98d08f1af40..17f02c2718b 100644 --- a/apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModal.tsx +++ b/apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModal.tsx @@ -36,6 +36,7 @@ import { useCreateWorkspace } from "renderer/react-query/workspaces"; import { useCloseNewWorkspaceModal, useNewWorkspaceModalOpen, + usePreSelectedProjectId, } from "renderer/stores/new-workspace-modal"; import { ExistingWorktreesList } from "./components/ExistingWorktreesList"; @@ -57,6 +58,7 @@ type Mode = "existing" | "new"; export function NewWorkspaceModal() { const isOpen = useNewWorkspaceModalOpen(); const closeModal = useCloseNewWorkspaceModal(); + const preSelectedProjectId = usePreSelectedProjectId(); const [selectedProjectId, setSelectedProjectId] = useState( null, ); @@ -94,12 +96,15 @@ export function NewWorkspaceModal() { ); }, [branchData?.branches, branchSearch]); - // Auto-select current project when modal opens + // Auto-select project when modal opens (prioritize pre-selected, then current) useEffect(() => { - if (isOpen && currentProjectId && !selectedProjectId) { - setSelectedProjectId(currentProjectId); + if (isOpen && !selectedProjectId) { + const projectToSelect = preSelectedProjectId ?? currentProjectId; + if (projectToSelect) { + setSelectedProjectId(projectToSelect); + } } - }, [isOpen, currentProjectId, selectedProjectId]); + }, [isOpen, currentProjectId, selectedProjectId, preSelectedProjectId]); // Effective base branch - use explicit selection or fall back to default const effectiveBaseBranch = baseBranch ?? branchData?.defaultBranch ?? null; diff --git a/apps/desktop/src/renderer/hooks/useWorkspaceShortcuts.ts b/apps/desktop/src/renderer/hooks/useWorkspaceShortcuts.ts new file mode 100644 index 00000000000..a37a8684377 --- /dev/null +++ b/apps/desktop/src/renderer/hooks/useWorkspaceShortcuts.ts @@ -0,0 +1,117 @@ +import { useCallback, useEffect, useRef, useState } from "react"; +import { useHotkeys } from "react-hotkeys-hook"; +import { trpc } from "renderer/lib/trpc"; +import { + useCreateBranchWorkspace, + useSetActiveWorkspace, +} from "renderer/react-query/workspaces"; +import { getHotkey } from "shared/hotkeys"; + +/** + * Shared hook for workspace keyboard shortcuts and auto-creation logic. + * This hook should be used in both: + * - WorkspacesTabs (top-bar mode) + * - WorkspaceSidebar (sidebar mode) + * + * It handles: + * - ⌘1-9 workspace switching shortcuts + * - Previous/next workspace shortcuts + * - Auto-create main workspace for new projects + */ +export function useWorkspaceShortcuts() { + const { data: groups = [] } = trpc.workspaces.getAllGrouped.useQuery(); + const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); + const activeWorkspaceId = activeWorkspace?.id || null; + const setActiveWorkspace = useSetActiveWorkspace(); + const createBranchWorkspace = useCreateBranchWorkspace(); + + // Track projects we've attempted to create workspaces for (persists across renders) + const attemptedProjectsRef = useRef>(new Set()); + const [isCreating, setIsCreating] = useState(false); + + // Auto-create main workspace for new projects (one-time per project) + useEffect(() => { + if (isCreating) return; + + for (const group of groups) { + const projectId = group.project.id; + const hasMainWorkspace = group.workspaces.some( + (w) => w.type === "branch", + ); + + // Skip if already has main workspace or we've already attempted this project + if (hasMainWorkspace || attemptedProjectsRef.current.has(projectId)) { + continue; + } + + // Mark as attempted before creating (prevents retries) + attemptedProjectsRef.current.add(projectId); + setIsCreating(true); + + // Auto-create fails silently - this is a background convenience feature + createBranchWorkspace.mutate( + { projectId }, + { + onSettled: () => { + setIsCreating(false); + }, + }, + ); + // Only create one at a time + break; + } + }, [groups, isCreating, createBranchWorkspace]); + + // Flatten workspaces for keyboard navigation + const allWorkspaces = groups.flatMap((group) => group.workspaces); + + // Workspace switching shortcuts (⌘+1-9) + const workspaceKeys = Array.from( + { length: 9 }, + (_, i) => `meta+${i + 1}`, + ).join(", "); + + const handleWorkspaceSwitch = useCallback( + (event: KeyboardEvent) => { + const num = Number(event.key); + if (num >= 1 && num <= 9) { + const workspace = allWorkspaces[num - 1]; + if (workspace) { + setActiveWorkspace.mutate({ id: workspace.id }); + } + } + }, + [allWorkspaces, setActiveWorkspace], + ); + + const handlePrevWorkspace = useCallback(() => { + if (!activeWorkspaceId) return; + const currentIndex = allWorkspaces.findIndex( + (w) => w.id === activeWorkspaceId, + ); + if (currentIndex > 0) { + setActiveWorkspace.mutate({ id: allWorkspaces[currentIndex - 1].id }); + } + }, [activeWorkspaceId, allWorkspaces, setActiveWorkspace]); + + const handleNextWorkspace = useCallback(() => { + if (!activeWorkspaceId) return; + const currentIndex = allWorkspaces.findIndex( + (w) => w.id === activeWorkspaceId, + ); + if (currentIndex < allWorkspaces.length - 1) { + setActiveWorkspace.mutate({ id: allWorkspaces[currentIndex + 1].id }); + } + }, [activeWorkspaceId, allWorkspaces, setActiveWorkspace]); + + useHotkeys(workspaceKeys, handleWorkspaceSwitch); + useHotkeys(getHotkey("PREV_WORKSPACE"), handlePrevWorkspace); + useHotkeys(getHotkey("NEXT_WORKSPACE"), handleNextWorkspace); + + return { + groups, + allWorkspaces, + activeWorkspaceId, + setActiveWorkspace, + }; +} diff --git a/apps/desktop/src/renderer/react-query/workspaces/index.ts b/apps/desktop/src/renderer/react-query/workspaces/index.ts index 60a9c29b75d..438ba849573 100644 --- a/apps/desktop/src/renderer/react-query/workspaces/index.ts +++ b/apps/desktop/src/renderer/react-query/workspaces/index.ts @@ -6,3 +6,4 @@ export { useOpenWorktree } from "./useOpenWorktree"; export { useReorderWorkspaces } from "./useReorderWorkspaces"; export { useSetActiveWorkspace } from "./useSetActiveWorkspace"; export { useUpdateWorkspace } from "./useUpdateWorkspace"; +export { useWorkspaceDeleteHandler } from "./useWorkspaceDeleteHandler"; diff --git a/apps/desktop/src/renderer/react-query/workspaces/useSetActiveWorkspace.ts b/apps/desktop/src/renderer/react-query/workspaces/useSetActiveWorkspace.ts index 7dc43e36b0b..dfbff3ef05a 100644 --- a/apps/desktop/src/renderer/react-query/workspaces/useSetActiveWorkspace.ts +++ b/apps/desktop/src/renderer/react-query/workspaces/useSetActiveWorkspace.ts @@ -1,23 +1,48 @@ +import { toast } from "@superset/ui/sonner"; import { trpc } from "renderer/lib/trpc"; /** * Mutation hook for setting the active workspace * Automatically invalidates getActive and getAll queries on success + * Shows undo toast if workspace was marked as unread (auto-cleared on switch) */ export function useSetActiveWorkspace( options?: Parameters[0], ) { const utils = trpc.useUtils(); + const setUnread = trpc.workspaces.setUnread.useMutation({ + onSuccess: () => { + utils.workspaces.getAllGrouped.invalidate(); + }, + }); return trpc.workspaces.setActive.useMutation({ ...options, - onSuccess: async (...args) => { + onSuccess: async (data, variables, ...rest) => { // Auto-invalidate active workspace and all workspaces queries - await utils.workspaces.getActive.invalidate(); - await utils.workspaces.getAll.invalidate(); + await Promise.all([ + utils.workspaces.getActive.invalidate(), + utils.workspaces.getAll.invalidate(), + utils.workspaces.getAllGrouped.invalidate(), + ]); + + // Show undo toast if workspace was marked as unread + if (data.wasUnread) { + toast("Marked as read", { + description: "Workspace unread marker cleared", + action: { + label: "Undo", + onClick: () => { + setUnread.mutate({ id: variables.id, isUnread: true }); + }, + }, + duration: 5000, + }); + } // Call user's onSuccess if provided - await options?.onSuccess?.(...args); + // biome-ignore lint/suspicious/noExplicitAny: spread args for compatibility + await (options?.onSuccess as any)?.(data, variables, ...rest); }, }); } diff --git a/apps/desktop/src/renderer/react-query/workspaces/useWorkspaceDeleteHandler.ts b/apps/desktop/src/renderer/react-query/workspaces/useWorkspaceDeleteHandler.ts new file mode 100644 index 00000000000..cdd2075e12b --- /dev/null +++ b/apps/desktop/src/renderer/react-query/workspaces/useWorkspaceDeleteHandler.ts @@ -0,0 +1,29 @@ +import { useState } from "react"; + +interface UseWorkspaceDeleteHandlerResult { + /** Whether the delete dialog should be shown */ + showDeleteDialog: boolean; + /** Set whether the delete dialog should be shown */ + setShowDeleteDialog: (show: boolean) => void; + /** Handle delete click - always shows the dialog to let user choose close or delete */ + handleDeleteClick: (e?: React.MouseEvent) => void; +} + +/** + * Shared hook for workspace delete/close dialog state. + * Always shows the confirmation dialog to let user choose between closing or deleting. + */ +export function useWorkspaceDeleteHandler(): UseWorkspaceDeleteHandlerResult { + const [showDeleteDialog, setShowDeleteDialog] = useState(false); + + const handleDeleteClick = (e?: React.MouseEvent) => { + e?.stopPropagation(); + setShowDeleteDialog(true); + }; + + return { + showDeleteDialog, + setShowDeleteDialog, + handleDeleteClick, + }; +} diff --git a/apps/desktop/src/renderer/screens/main/components/SettingsView/BehaviorSettings.tsx b/apps/desktop/src/renderer/screens/main/components/SettingsView/BehaviorSettings.tsx index f21aff0a34f..bbcd9c9d80f 100644 --- a/apps/desktop/src/renderer/screens/main/components/SettingsView/BehaviorSettings.tsx +++ b/apps/desktop/src/renderer/screens/main/components/SettingsView/BehaviorSettings.tsx @@ -1,37 +1,99 @@ +import type { TerminalLinkBehavior } from "@superset/local-db"; import { Label } from "@superset/ui/label"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@superset/ui/select"; import { Switch } from "@superset/ui/switch"; import { trpc } from "renderer/lib/trpc"; +type NavigationStyle = "top-bar" | "sidebar"; + export function BehaviorSettings() { const utils = trpc.useUtils(); - const { data: confirmOnQuit, isLoading } = + + // Confirm on quit setting + const { data: confirmOnQuit, isLoading: isConfirmLoading } = trpc.settings.getConfirmOnQuit.useQuery(); const setConfirmOnQuit = trpc.settings.setConfirmOnQuit.useMutation({ onMutate: async ({ enabled }) => { - // Cancel outgoing fetches await utils.settings.getConfirmOnQuit.cancel(); - // Snapshot previous value const previous = utils.settings.getConfirmOnQuit.getData(); - // Optimistically update utils.settings.getConfirmOnQuit.setData(undefined, enabled); return { previous }; }, onError: (_err, _vars, context) => { - // Rollback on error if (context?.previous !== undefined) { utils.settings.getConfirmOnQuit.setData(undefined, context.previous); } }, onSettled: () => { - // Refetch to ensure sync with server utils.settings.getConfirmOnQuit.invalidate(); }, }); - const handleToggle = (enabled: boolean) => { + // Navigation style setting + const { data: navigationStyle, isLoading: isNavLoading } = + trpc.settings.getNavigationStyle.useQuery(); + const setNavigationStyle = trpc.settings.setNavigationStyle.useMutation({ + onMutate: async ({ style }) => { + await utils.settings.getNavigationStyle.cancel(); + const previous = utils.settings.getNavigationStyle.getData(); + utils.settings.getNavigationStyle.setData(undefined, style); + return { previous }; + }, + onError: (_err, _vars, context) => { + if (context?.previous !== undefined) { + utils.settings.getNavigationStyle.setData(undefined, context.previous); + } + }, + onSettled: () => { + utils.settings.getNavigationStyle.invalidate(); + }, + }); + + const handleConfirmToggle = (enabled: boolean) => { setConfirmOnQuit.mutate({ enabled }); }; + // Terminal link behavior setting + const { data: terminalLinkBehavior, isLoading: isLoadingLinkBehavior } = + trpc.settings.getTerminalLinkBehavior.useQuery(); + + const setTerminalLinkBehavior = + trpc.settings.setTerminalLinkBehavior.useMutation({ + onMutate: async ({ behavior }) => { + await utils.settings.getTerminalLinkBehavior.cancel(); + const previous = utils.settings.getTerminalLinkBehavior.getData(); + utils.settings.getTerminalLinkBehavior.setData(undefined, behavior); + return { previous }; + }, + onError: (_err, _vars, context) => { + if (context?.previous !== undefined) { + utils.settings.getTerminalLinkBehavior.setData( + undefined, + context.previous, + ); + } + }, + onSettled: () => { + utils.settings.getTerminalLinkBehavior.invalidate(); + }, + }); + + const handleLinkBehaviorChange = (value: string) => { + setTerminalLinkBehavior.mutate({ + behavior: value as TerminalLinkBehavior, + }); + }; + + const handleNavigationStyleChange = (style: NavigationStyle) => { + setNavigationStyle.mutate({ style }); + }; + return (
@@ -42,6 +104,32 @@ export function BehaviorSettings() {
+ {/* Navigation Style */} +
+
+ +

+ Choose how workspaces are displayed +

+
+ +
+ + {/* Confirm on Quit */}
+ +
+
+ +

+ Choose how to open file paths when Cmd+clicking in the terminal +

+
+ +
); diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/SidebarControl.tsx b/apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx similarity index 92% rename from apps/desktop/src/renderer/screens/main/components/TopBar/SidebarControl.tsx rename to apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx index 6fa45f91846..275d0e03424 100644 --- a/apps/desktop/src/renderer/screens/main/components/TopBar/SidebarControl.tsx +++ b/apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx @@ -14,7 +14,7 @@ export function SidebarControl() { variant="ghost" size="icon" onClick={toggleSidebar} - aria-label="Toggle sidebar" + aria-label="Toggle Changes Sidebar" className="no-drag" > {isSidebarOpen ? ( @@ -26,7 +26,7 @@ export function SidebarControl() { diff --git a/apps/desktop/src/renderer/screens/main/components/SidebarControl/index.ts b/apps/desktop/src/renderer/screens/main/components/SidebarControl/index.ts new file mode 100644 index 00000000000..c4a177ae7a3 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/SidebarControl/index.ts @@ -0,0 +1 @@ +export { SidebarControl } from "./SidebarControl"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarRight/WorkspaceActionBarRight.tsx b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/OpenInMenuButton.tsx similarity index 66% rename from apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarRight/WorkspaceActionBarRight.tsx rename to apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/OpenInMenuButton.tsx index 222cade48cf..5287546fbee 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarRight/WorkspaceActionBarRight.tsx +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/OpenInMenuButton.tsx @@ -10,9 +10,11 @@ import { DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@superset/ui/dropdown-menu"; +import { toast } from "@superset/ui/sonner"; import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; +import { cn } from "@superset/ui/utils"; import { HiChevronDown } from "react-icons/hi2"; -import { LuArrowUpRight, LuCopy } from "react-icons/lu"; +import { LuCopy } from "react-icons/lu"; import jetbrainsIcon from "renderer/assets/app-icons/jetbrains.svg"; import vscodeIcon from "renderer/assets/app-icons/vscode.svg"; import { @@ -21,117 +23,105 @@ import { JETBRAINS_OPTIONS, VSCODE_OPTIONS, } from "renderer/components/OpenInButton"; -import { shortenHomePath } from "renderer/lib/formatPath"; import { trpc } from "renderer/lib/trpc"; import { useHotkeyText } from "renderer/stores/hotkeys"; -interface FormattedPath { - prefix: string; - worktreeName: string; -} - -function formatWorktreePath( - path: string, - homeDir: string | undefined, -): FormattedPath { - const shortenedPath = shortenHomePath(path, homeDir); - - // Split into prefix and worktree name (last segment) - const lastSlashIndex = shortenedPath.lastIndexOf("/"); - if (lastSlashIndex !== -1) { - return { - prefix: shortenedPath.slice(0, lastSlashIndex + 1), - worktreeName: shortenedPath.slice(lastSlashIndex + 1), - }; - } - - return { prefix: "", worktreeName: shortenedPath }; -} - -interface WorkspaceActionBarRightProps { +interface OpenInMenuButtonProps { worktreePath: string; } -export function WorkspaceActionBarRight({ - worktreePath, -}: WorkspaceActionBarRightProps) { - const { data: homeDir } = trpc.window.getHomeDir.useQuery(); +export function OpenInMenuButton({ worktreePath }: OpenInMenuButtonProps) { const utils = trpc.useUtils(); const { data: lastUsedApp = "cursor" } = trpc.settings.getLastUsedApp.useQuery(); const openInApp = trpc.external.openInApp.useMutation({ onSuccess: () => utils.settings.getLastUsedApp.invalidate(), + onError: (error) => toast.error(`Failed to open: ${error.message}`), + }); + const copyPath = trpc.external.copyPath.useMutation({ + onSuccess: () => toast.success("Path copied to clipboard"), + onError: (error) => toast.error(`Failed to copy path: ${error.message}`), }); - const copyPath = trpc.external.copyPath.useMutation(); - const formattedPath = formatWorktreePath(worktreePath, homeDir); const currentApp = getAppOption(lastUsedApp); const openInShortcut = useHotkeyText("OPEN_IN_APP"); const copyPathShortcut = useHotkeyText("COPY_PATH"); const showOpenInShortcut = openInShortcut !== "Unassigned"; const showCopyPathShortcut = copyPathShortcut !== "Unassigned"; + const isLoading = openInApp.isPending || copyPath.isPending; const handleOpenInEditor = () => { + if (isLoading) return; openInApp.mutate({ path: worktreePath, app: lastUsedApp }); }; const handleOpenInOtherApp = (appId: ExternalApp) => { + if (isLoading) return; openInApp.mutate({ path: worktreePath, app: appId }); }; const handleCopyPath = () => { + if (isLoading) return; copyPath.mutate(worktreePath); }; const BUTTON_HEIGHT = 24; return ( - <> - {/* Path - clickable to open */} +
+ {/* Main button - opens in last used app */} - - - Open in {currentApp.displayLabel ?? currentApp.label} - - {showOpenInShortcut ? openInShortcut : "—"} - - + +
+ + Open in {currentApp.displayLabel ?? currentApp.label} + {showOpenInShortcut && ( + + {openInShortcut} + + )} + + + {worktreePath} + +
- {/* Open dropdown button */} + {/* Dropdown trigger */} @@ -215,6 +205,6 @@ export function WorkspaceActionBarRight({ - +
); } diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/ViewModeToggleCompact.tsx b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/ViewModeToggleCompact.tsx new file mode 100644 index 00000000000..a93f91fb3c6 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/ViewModeToggleCompact.tsx @@ -0,0 +1,61 @@ +import { cn } from "@superset/ui/utils"; +import { + useWorkspaceViewModeStore, + type WorkspaceViewMode, +} from "renderer/stores/workspace-view-mode"; + +interface ViewModeToggleCompactProps { + workspaceId: string; +} + +export function ViewModeToggleCompact({ + workspaceId, +}: ViewModeToggleCompactProps) { + // Select only this workspace's mode to minimize rerenders + const currentMode = useWorkspaceViewModeStore( + (s) => s.viewModeByWorkspaceId[workspaceId] ?? "workbench", + ); + const setWorkspaceViewMode = useWorkspaceViewModeStore( + (s) => s.setWorkspaceViewMode, + ); + + const handleModeChange = (mode: WorkspaceViewMode) => { + setWorkspaceViewMode(workspaceId, mode); + }; + + const BUTTON_HEIGHT = 24; + + return ( +
+ + +
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/WorkspaceControls.tsx b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/WorkspaceControls.tsx new file mode 100644 index 00000000000..e590051951c --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/WorkspaceControls.tsx @@ -0,0 +1,22 @@ +import { OpenInMenuButton } from "./OpenInMenuButton"; +import { ViewModeToggleCompact } from "./ViewModeToggleCompact"; + +interface WorkspaceControlsProps { + workspaceId: string | undefined; + worktreePath: string | undefined; +} + +export function WorkspaceControls({ + workspaceId, + worktreePath, +}: WorkspaceControlsProps) { + // Don't render if no active workspace with a worktree path + if (!workspaceId || !worktreePath) return null; + + return ( +
+ + +
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/index.ts b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/index.ts new file mode 100644 index 00000000000..736202ad160 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceControls/index.ts @@ -0,0 +1 @@ +export { WorkspaceControls } from "./WorkspaceControls"; diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceSidebarControl.tsx b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceSidebarControl.tsx new file mode 100644 index 00000000000..a5a517901f6 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceSidebarControl.tsx @@ -0,0 +1,47 @@ +import { Button } from "@superset/ui/button"; +import { Kbd, KbdGroup } from "@superset/ui/kbd"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; +import { LuPanelLeft, LuPanelLeftClose } from "react-icons/lu"; +import { useWorkspaceSidebarStore } from "renderer/stores"; +import { + formatHotkeyDisplay, + getCurrentPlatform, + getHotkey, +} from "shared/hotkeys"; + +export function WorkspaceSidebarControl() { + const { isOpen, toggleOpen } = useWorkspaceSidebarStore(); + + return ( + + + + + + + Toggle Workspaces + + {formatHotkeyDisplay( + getHotkey("TOGGLE_WORKSPACE_SIDEBAR"), + getCurrentPlatform(), + ).map((key) => ( + {key} + ))} + + + + + ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceGroup.tsx b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceGroup.tsx index 0b042f2ef52..75505bf3313 100644 --- a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceGroup.tsx +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceGroup.tsx @@ -11,6 +11,7 @@ interface Workspace { branch: string; name: string; tabOrder: number; + isUnread: boolean; } interface WorkspaceGroupProps { @@ -79,6 +80,7 @@ export function WorkspaceGroup({ branch={workspace.branch} title={workspace.name} isActive={workspace.id === activeWorkspaceId} + isUnread={workspace.isUnread} index={index} width={workspaceWidth} onMouseEnter={() => onWorkspaceHover(workspace.id)} diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceItem.tsx b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceItem.tsx index 089d3487e88..8b3dd67e6b2 100644 --- a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceItem.tsx +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceItem.tsx @@ -1,21 +1,20 @@ import { Button } from "@superset/ui/button"; import { Input } from "@superset/ui/input"; -import { toast } from "@superset/ui/sonner"; import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; import { cn } from "@superset/ui/utils"; -import { useState } from "react"; import { useDrag, useDrop } from "react-dnd"; import { HiMiniXMark } from "react-icons/hi2"; import { LuGitBranch } from "react-icons/lu"; -import { trpc } from "renderer/lib/trpc"; import { - useDeleteWorkspace, useReorderWorkspaces, useSetActiveWorkspace, + useWorkspaceDeleteHandler, } from "renderer/react-query/workspaces"; import { useCloseSettings } from "renderer/stores/app-state"; import { useTabsStore } from "renderer/stores/tabs/store"; +import { extractPaneIdsFromLayout } from "renderer/stores/tabs/utils"; import { BranchSwitcher } from "./BranchSwitcher"; +import { DELETE_TOOLTIP_DELAY, WORKSPACE_TOOLTIP_DELAY } from "./constants"; import { DeleteWorkspaceDialog } from "./DeleteWorkspaceDialog"; import { useWorkspaceRename } from "./useWorkspaceRename"; import { WorkspaceItemContextMenu } from "./WorkspaceItemContextMenu"; @@ -30,6 +29,7 @@ interface WorkspaceItemProps { branch?: string; title: string; isActive: boolean; + isUnread?: boolean; index: number; width: number; onMouseEnter?: () => void; @@ -44,6 +44,7 @@ export function WorkspaceItem({ branch, title, isActive, + isUnread = false, index, width, onMouseEnter, @@ -52,105 +53,30 @@ export function WorkspaceItem({ const isBranchWorkspace = workspaceType === "branch"; const setActive = useSetActiveWorkspace(); const reorderWorkspaces = useReorderWorkspaces(); - const deleteWorkspace = useDeleteWorkspace(); const closeSettings = useCloseSettings(); - const [showDeleteDialog, setShowDeleteDialog] = useState(false); const tabs = useTabsStore((s) => s.tabs); const panes = useTabsStore((s) => s.panes); - const rename = useWorkspaceRename(id, title); - - // Query to check if workspace is empty - only enabled when needed - const canDeleteQuery = trpc.workspaces.canDelete.useQuery( - { id }, - { enabled: false }, + const clearWorkspaceAttention = useTabsStore( + (s) => s.clearWorkspaceAttention, ); + const rename = useWorkspaceRename(id, title); - const handleDeleteClick = async () => { - // Prevent double-clicks and race conditions - if (deleteWorkspace.isPending || canDeleteQuery.isFetching) return; - - try { - // Always fetch fresh data before deciding - const { data: canDeleteData } = await canDeleteQuery.refetch(); - - // For branch workspaces, only show dialog if there are active terminals - // (no destructive action - branch stays in repo) - if (isBranchWorkspace) { - if ( - canDeleteData?.activeTerminalCount && - canDeleteData.activeTerminalCount > 0 - ) { - setShowDeleteDialog(true); - } else { - // Close directly without confirmation - toast.promise(deleteWorkspace.mutateAsync({ id }), { - loading: `Closing "${title}"...`, - success: `Workspace "${title}" closed`, - error: (error) => - error instanceof Error - ? `Failed to close workspace: ${error.message}` - : "Failed to close workspace", - }); - } - return; - } - - // For worktree workspaces, check all conditions - const isEmpty = - canDeleteData?.canDelete && - canDeleteData.activeTerminalCount === 0 && - !canDeleteData.warning && - !canDeleteData.hasChanges && - !canDeleteData.hasUnpushedCommits; - - if (isEmpty) { - // Delete directly without confirmation - toast.promise(deleteWorkspace.mutateAsync({ id }), { - loading: `Deleting "${title}"...`, - success: `Workspace "${title}" deleted`, - error: (error) => - error instanceof Error - ? `Failed to delete workspace: ${error.message}` - : "Failed to delete workspace", - }); - } else { - // Show confirmation dialog - setShowDeleteDialog(true); - } - } catch { - // On error checking status, show dialog for user to decide - setShowDeleteDialog(true); - } - }; + // Shared delete logic + const { showDeleteDialog, setShowDeleteDialog, handleDeleteClick } = + useWorkspaceDeleteHandler(); - // Check if any pane in tabs belonging to this workspace needs attention + // Check if any pane in tabs belonging to this workspace needs attention (agent notifications) const workspaceTabs = tabs.filter((t) => t.workspaceId === id); const workspacePaneIds = new Set( - workspaceTabs.flatMap((t) => { - // Extract pane IDs from the layout (which is a MosaicNode) - const collectPaneIds = (node: unknown): string[] => { - if (typeof node === "string") return [node]; - if ( - node && - typeof node === "object" && - "first" in node && - "second" in node - ) { - const branch = node as { first: unknown; second: unknown }; - return [ - ...collectPaneIds(branch.first), - ...collectPaneIds(branch.second), - ]; - } - return []; - }; - return collectPaneIds(t.layout); - }), + workspaceTabs.flatMap((t) => extractPaneIdsFromLayout(t.layout)), ); - const needsAttention = Object.values(panes) - .filter((p) => workspacePaneIds.has(p.id)) + const hasPaneAttention = Object.values(panes) + .filter((p) => p != null && workspacePaneIds.has(p.id)) .some((p) => p.needsAttention); + // Show indicator if workspace is manually marked as unread OR has pane-level attention + const needsAttention = isUnread || hasPaneAttention; + const [{ isDragging }, drag] = useDrag( () => ({ type: WORKSPACE_TYPE, @@ -183,6 +109,7 @@ export function WorkspaceItem({ workspaceId={id} worktreePath={worktreePath} workspaceAlias={title} + isUnread={isUnread} onRename={rename.startRename} canRename={!isBranchWorkspace} showHoverCard={!isBranchWorkspace} @@ -201,6 +128,7 @@ export function WorkspaceItem({ if (!rename.isRenaming) { closeSettings(); setActive.mutate({ id }); + clearWorkspaceAttention(id); } }} onDoubleClick={isBranchWorkspace ? undefined : rename.startRename} @@ -230,7 +158,7 @@ export function WorkspaceItem({ /> ) : isBranchWorkspace ? (
- +
@@ -292,7 +220,7 @@ export function WorkspaceItem({ {/* Only show close button for worktree workspaces */} {!isBranchWorkspace && ( - + - Delete workspace + Close or delete )} diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceItemContextMenu.tsx b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceItemContextMenu.tsx index 142b12651dc..81b8b6ce181 100644 --- a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceItemContextMenu.tsx +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceItemContextMenu.tsx @@ -11,6 +11,7 @@ import { HoverCardTrigger, } from "@superset/ui/hover-card"; import type { ReactNode } from "react"; +import { LuEye, LuEyeOff } from "react-icons/lu"; import { trpc } from "renderer/lib/trpc"; import { WorkspaceHoverCardContent } from "./WorkspaceHoverCard"; @@ -19,6 +20,7 @@ interface WorkspaceItemContextMenuProps { workspaceId: string; worktreePath: string; workspaceAlias?: string; + isUnread?: boolean; onRename: () => void; canRename?: boolean; showHoverCard?: boolean; @@ -29,11 +31,18 @@ export function WorkspaceItemContextMenu({ workspaceId, worktreePath, workspaceAlias, + isUnread = false, onRename, canRename = true, showHoverCard = true, }: WorkspaceItemContextMenuProps) { + const utils = trpc.useUtils(); const openInFinder = trpc.external.openInFinder.useMutation(); + const setUnread = trpc.workspaces.setUnread.useMutation({ + onSuccess: () => { + utils.workspaces.getAllGrouped.invalidate(); + }, + }); const handleOpenInFinder = () => { if (worktreePath) { @@ -41,6 +50,26 @@ export function WorkspaceItemContextMenu({ } }; + const handleToggleUnread = () => { + setUnread.mutate({ id: workspaceId, isUnread: !isUnread }); + }; + + const unreadMenuItem = ( + + {isUnread ? ( + <> + + Mark as Read + + ) : ( + <> + + Mark as Unread + + )} + + ); + // For branch workspaces, just show context menu without hover card if (!showHoverCard) { return ( @@ -56,6 +85,8 @@ export function WorkspaceItemContextMenu({ Open in Finder + + {unreadMenuItem} ); @@ -77,6 +108,8 @@ export function WorkspaceItemContextMenu({ Open in Finder + + {unreadMenuItem} diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/constants.ts b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/constants.ts new file mode 100644 index 00000000000..d6abc8abb81 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/constants.ts @@ -0,0 +1,9 @@ +/** + * Constants for workspace tabs behavior + */ + +/** Tooltip delay for delete button (ms) */ +export const DELETE_TOOLTIP_DELAY = 500; + +/** Tooltip delay for workspace name (ms) */ +export const WORKSPACE_TOOLTIP_DELAY = 600; diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/index.tsx b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/index.tsx index 27c58551259..8c8455c85ad 100644 --- a/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/index.tsx +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/WorkspaceTabs/index.tsx @@ -1,14 +1,9 @@ -import { Fragment, useCallback, useEffect, useRef, useState } from "react"; -import { trpc } from "renderer/lib/trpc"; -import { - useCreateBranchWorkspace, - useSetActiveWorkspace, -} from "renderer/react-query/workspaces"; +import { Fragment, useEffect, useRef, useState } from "react"; +import { useWorkspaceShortcuts } from "renderer/hooks/useWorkspaceShortcuts"; import { useCurrentView, useIsSettingsTabOpen, } from "renderer/stores/app-state"; -import { useAppHotkey } from "renderer/stores/hotkeys"; import { CreateWorkspaceButton } from "./CreateWorkspaceButton"; import { SettingsTab } from "./SettingsTab"; import { WorkspaceGroup } from "./WorkspaceGroup"; @@ -18,11 +13,9 @@ const MAX_WORKSPACE_WIDTH = 160; const ADD_BUTTON_WIDTH = 40; export function WorkspacesTabs() { - const { data: groups = [] } = trpc.workspaces.getAllGrouped.useQuery(); - const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); - const activeWorkspaceId = activeWorkspace?.id || null; - const setActiveWorkspace = useSetActiveWorkspace(); - const createBranchWorkspace = useCreateBranchWorkspace(); + // Use shared hook for workspace shortcuts and auto-create logic + const { groups, allWorkspaces, activeWorkspaceId } = useWorkspaceShortcuts(); + const currentView = useCurrentView(); const isSettingsTabOpen = useIsSettingsTabOpen(); const isSettingsActive = currentView === "settings"; @@ -35,140 +28,6 @@ export function WorkspacesTabs() { null, ); - // Track projects we've attempted to create workspaces for (persists across renders) - // Using ref to avoid re-triggering the effect - const attemptedProjectsRef = useRef>(new Set()); - const [isCreating, setIsCreating] = useState(false); - - // Auto-create main workspace for new projects (one-time per project) - // This only runs for projects we haven't attempted yet - useEffect(() => { - if (isCreating) return; - - for (const group of groups) { - const projectId = group.project.id; - const hasMainWorkspace = group.workspaces.some( - (w) => w.type === "branch", - ); - - // Skip if already has main workspace or we've already attempted this project - if (hasMainWorkspace || attemptedProjectsRef.current.has(projectId)) { - continue; - } - - // Mark as attempted before creating (prevents retries) - attemptedProjectsRef.current.add(projectId); - setIsCreating(true); - - // Auto-create fails silently - this is a background convenience feature - // Users can manually create the workspace via the dropdown if needed - createBranchWorkspace.mutate( - { projectId }, - { - onSettled: () => { - setIsCreating(false); - }, - }, - ); - // Only create one at a time - break; - } - }, [groups, isCreating, createBranchWorkspace]); - - // Flatten workspaces for keyboard navigation - const allWorkspaces = groups.flatMap((group) => group.workspaces); - - const handleWorkspaceSwitch = useCallback( - (index: number) => { - const workspace = allWorkspaces[index]; - if (workspace) { - setActiveWorkspace.mutate({ id: workspace.id }); - } - }, - [allWorkspaces, setActiveWorkspace], - ); - - const handlePrevWorkspace = useCallback(() => { - if (!activeWorkspaceId) return; - const currentIndex = allWorkspaces.findIndex( - (w) => w.id === activeWorkspaceId, - ); - if (currentIndex > 0) { - setActiveWorkspace.mutate({ id: allWorkspaces[currentIndex - 1].id }); - } - }, [activeWorkspaceId, allWorkspaces, setActiveWorkspace]); - - const handleNextWorkspace = useCallback(() => { - if (!activeWorkspaceId) return; - const currentIndex = allWorkspaces.findIndex( - (w) => w.id === activeWorkspaceId, - ); - if (currentIndex < allWorkspaces.length - 1) { - setActiveWorkspace.mutate({ id: allWorkspaces[currentIndex + 1].id }); - } - }, [activeWorkspaceId, allWorkspaces, setActiveWorkspace]); - - useAppHotkey( - "JUMP_TO_WORKSPACE_1", - () => handleWorkspaceSwitch(0), - undefined, - [handleWorkspaceSwitch], - ); - useAppHotkey( - "JUMP_TO_WORKSPACE_2", - () => handleWorkspaceSwitch(1), - undefined, - [handleWorkspaceSwitch], - ); - useAppHotkey( - "JUMP_TO_WORKSPACE_3", - () => handleWorkspaceSwitch(2), - undefined, - [handleWorkspaceSwitch], - ); - useAppHotkey( - "JUMP_TO_WORKSPACE_4", - () => handleWorkspaceSwitch(3), - undefined, - [handleWorkspaceSwitch], - ); - useAppHotkey( - "JUMP_TO_WORKSPACE_5", - () => handleWorkspaceSwitch(4), - undefined, - [handleWorkspaceSwitch], - ); - useAppHotkey( - "JUMP_TO_WORKSPACE_6", - () => handleWorkspaceSwitch(5), - undefined, - [handleWorkspaceSwitch], - ); - useAppHotkey( - "JUMP_TO_WORKSPACE_7", - () => handleWorkspaceSwitch(6), - undefined, - [handleWorkspaceSwitch], - ); - useAppHotkey( - "JUMP_TO_WORKSPACE_8", - () => handleWorkspaceSwitch(7), - undefined, - [handleWorkspaceSwitch], - ); - useAppHotkey( - "JUMP_TO_WORKSPACE_9", - () => handleWorkspaceSwitch(8), - undefined, - [handleWorkspaceSwitch], - ); - useAppHotkey("PREV_WORKSPACE", handlePrevWorkspace, undefined, [ - handlePrevWorkspace, - ]); - useAppHotkey("NEXT_WORKSPACE", handleNextWorkspace, undefined, [ - handleNextWorkspace, - ]); - useEffect(() => { const checkScroll = () => { if (!scrollRef.current) return; diff --git a/apps/desktop/src/renderer/screens/main/components/TopBar/index.tsx b/apps/desktop/src/renderer/screens/main/components/TopBar/index.tsx index d5f1132cc2d..f9f163791dc 100644 --- a/apps/desktop/src/renderer/screens/main/components/TopBar/index.tsx +++ b/apps/desktop/src/renderer/screens/main/components/TopBar/index.tsx @@ -1,26 +1,58 @@ +import type { NavigationStyle } from "@superset/local-db"; import { trpc } from "renderer/lib/trpc"; import { AvatarDropdown } from "../AvatarDropdown"; -import { SidebarControl } from "./SidebarControl"; +import { SidebarControl } from "../SidebarControl"; import { WindowControls } from "./WindowControls"; +import { WorkspaceControls } from "./WorkspaceControls"; +import { WorkspaceSidebarControl } from "./WorkspaceSidebarControl"; import { WorkspacesTabs } from "./WorkspaceTabs"; -export function TopBar() { +interface TopBarProps { + navigationStyle?: NavigationStyle; +} + +export function TopBar({ navigationStyle = "top-bar" }: TopBarProps) { const { data: platform } = trpc.window.getPlatform.useQuery(); - const isMac = platform === "darwin"; + const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); + // Default to Mac layout while loading to avoid overlap with traffic lights + const isMac = platform === undefined || platform === "darwin"; + const isSidebarMode = navigationStyle === "sidebar"; + return ( -
+
- + {isSidebarMode && } + {!isSidebarMode && }
-
- -
-
+ + {isSidebarMode ? ( +
+ {activeWorkspace && ( + + {activeWorkspace.project?.name ?? "Workspace"} + / + {activeWorkspace.name} + + )} +
+ ) : ( +
+ +
+ )} + +
+ {!isSidebarMode && ( + + )} {!isMac && }
diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/ProjectHeader.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/ProjectHeader.tsx new file mode 100644 index 00000000000..85a1fe3d72a --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/ProjectHeader.tsx @@ -0,0 +1,42 @@ +import { cn } from "@superset/ui/utils"; +import { LuChevronDown, LuChevronRight } from "react-icons/lu"; + +interface ProjectHeaderProps { + projectName: string; + projectColor: string; + isCollapsed: boolean; + onToggleCollapse: () => void; + workspaceCount: number; +} + +export function ProjectHeader({ + projectName, + projectColor, + isCollapsed, + onToggleCollapse, + workspaceCount, +}: ProjectHeaderProps) { + return ( + + ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/ProjectSection.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/ProjectSection.tsx new file mode 100644 index 00000000000..75c933b2482 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/ProjectSection.tsx @@ -0,0 +1,143 @@ +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@superset/ui/dropdown-menu"; +import { toast } from "@superset/ui/sonner"; +import { AnimatePresence, motion } from "framer-motion"; +import { useState } from "react"; +import { HiMiniPlus, HiOutlineBolt } from "react-icons/hi2"; +import { useCreateWorkspace } from "renderer/react-query/workspaces"; +import { useWorkspaceSidebarStore } from "renderer/stores"; +import { useOpenNewWorkspaceModal } from "renderer/stores/new-workspace-modal"; +import { WorkspaceListItem } from "../WorkspaceListItem"; +import { ProjectHeader } from "./ProjectHeader"; + +interface Workspace { + id: string; + projectId: string; + worktreePath: string; + type: "worktree" | "branch"; + branch: string; + name: string; + tabOrder: number; + isUnread: boolean; +} + +interface ProjectSectionProps { + projectId: string; + projectName: string; + projectColor: string; + workspaces: Workspace[]; + activeWorkspaceId: string | null; + /** Base index for keyboard shortcuts (0-based) */ + shortcutBaseIndex: number; +} + +export function ProjectSection({ + projectId, + projectName, + projectColor, + workspaces, + activeWorkspaceId, + shortcutBaseIndex, +}: ProjectSectionProps) { + const [dropdownOpen, setDropdownOpen] = useState(false); + const { isProjectCollapsed, toggleProjectCollapsed } = + useWorkspaceSidebarStore(); + const createWorkspace = useCreateWorkspace(); + const openModal = useOpenNewWorkspaceModal(); + + const isCollapsed = isProjectCollapsed(projectId); + + const handleQuickCreate = () => { + setDropdownOpen(false); + toast.promise(createWorkspace.mutateAsync({ projectId }), { + loading: "Creating workspace...", + success: "Workspace created", + error: (err) => + err instanceof Error ? err.message : "Failed to create workspace", + }); + }; + + const handleNewWorkspace = () => { + setDropdownOpen(false); + openModal(projectId); + }; + + return ( +
+ toggleProjectCollapsed(projectId)} + workspaceCount={workspaces.length} + /> + + + {!isCollapsed && ( + +
+ {workspaces.map((workspace, index) => ( + + ))} + + + + + + + + New Workspace + + + + Quick Create + + + +
+
+ )} +
+
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/index.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/index.ts new file mode 100644 index 00000000000..2111af01d6b --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ProjectSection/index.ts @@ -0,0 +1,2 @@ +export { ProjectHeader } from "./ProjectHeader"; +export { ProjectSection } from "./ProjectSection"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ResizableWorkspaceSidebar.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ResizableWorkspaceSidebar.tsx new file mode 100644 index 00000000000..526fa283d2c --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/ResizableWorkspaceSidebar.tsx @@ -0,0 +1,94 @@ +import { cn } from "@superset/ui/utils"; +import { useCallback, useEffect, useRef } from "react"; +import { + MAX_WORKSPACE_SIDEBAR_WIDTH, + MIN_WORKSPACE_SIDEBAR_WIDTH, + useWorkspaceSidebarStore, +} from "renderer/stores"; +import { WorkspaceSidebar } from "./WorkspaceSidebar"; + +export function ResizableWorkspaceSidebar() { + const { isOpen, width, setWidth, isResizing, setIsResizing } = + useWorkspaceSidebarStore(); + + const startXRef = useRef(0); + const startWidthRef = useRef(0); + + const handleMouseDown = useCallback( + (e: React.MouseEvent) => { + e.preventDefault(); + startXRef.current = e.clientX; + startWidthRef.current = width; + setIsResizing(true); + }, + [width, setIsResizing], + ); + + const handleMouseMove = useCallback( + (e: MouseEvent) => { + if (!isResizing) return; + + const delta = e.clientX - startXRef.current; + const newWidth = startWidthRef.current + delta; + const clampedWidth = Math.max( + MIN_WORKSPACE_SIDEBAR_WIDTH, + Math.min(MAX_WORKSPACE_SIDEBAR_WIDTH, newWidth), + ); + setWidth(clampedWidth); + }, + [isResizing, setWidth], + ); + + const handleMouseUp = useCallback(() => { + if (isResizing) { + setIsResizing(false); + } + }, [isResizing, setIsResizing]); + + useEffect(() => { + if (isResizing) { + document.addEventListener("mousemove", handleMouseMove); + document.addEventListener("mouseup", handleMouseUp); + document.body.style.userSelect = "none"; + document.body.style.cursor = "col-resize"; + } + + return () => { + document.removeEventListener("mousemove", handleMouseMove); + document.removeEventListener("mouseup", handleMouseUp); + document.body.style.userSelect = ""; + document.body.style.cursor = ""; + }; + }, [isResizing, handleMouseMove, handleMouseUp]); + + if (!isOpen) { + return null; + } + + return ( +
+ + + {/* Resize handle */} + {/* biome-ignore lint/a11y/useSemanticElements:
is not appropriate for interactive resize handles */} +
+
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceDiffStats.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceDiffStats.tsx new file mode 100644 index 00000000000..a2758d40b01 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceDiffStats.tsx @@ -0,0 +1,16 @@ +interface WorkspaceDiffStatsProps { + additions: number; + deletions: number; +} + +export function WorkspaceDiffStats({ + additions, + deletions, +}: WorkspaceDiffStatsProps) { + return ( +
+ +{additions} + -{deletions} +
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceListItem.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceListItem.tsx new file mode 100644 index 00000000000..04afd81d085 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceListItem.tsx @@ -0,0 +1,353 @@ +import { Button } from "@superset/ui/button"; +import { + ContextMenu, + ContextMenuContent, + ContextMenuItem, + ContextMenuSeparator, + ContextMenuTrigger, +} from "@superset/ui/context-menu"; +import { + HoverCard, + HoverCardContent, + HoverCardTrigger, +} from "@superset/ui/hover-card"; +import { Input } from "@superset/ui/input"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; +import { cn } from "@superset/ui/utils"; +import { useState } from "react"; +import { useDrag, useDrop } from "react-dnd"; +import { HiMiniXMark } from "react-icons/hi2"; +import { LuEye, LuEyeOff, LuGitBranch } from "react-icons/lu"; +import { trpc } from "renderer/lib/trpc"; +import { + useReorderWorkspaces, + useSetActiveWorkspace, + useWorkspaceDeleteHandler, +} from "renderer/react-query/workspaces"; +import { BranchSwitcher } from "renderer/screens/main/components/TopBar/WorkspaceTabs/BranchSwitcher"; +import { DeleteWorkspaceDialog } from "renderer/screens/main/components/TopBar/WorkspaceTabs/DeleteWorkspaceDialog"; +import { useWorkspaceRename } from "renderer/screens/main/components/TopBar/WorkspaceTabs/useWorkspaceRename"; +import { WorkspaceHoverCardContent } from "renderer/screens/main/components/TopBar/WorkspaceTabs/WorkspaceHoverCard"; +import { useTabsStore } from "renderer/stores/tabs/store"; +import { extractPaneIdsFromLayout } from "renderer/stores/tabs/utils"; +import { + GITHUB_STATUS_STALE_TIME, + HOVER_CARD_CLOSE_DELAY, + HOVER_CARD_OPEN_DELAY, + MAX_KEYBOARD_SHORTCUT_INDEX, +} from "./constants"; +import { WorkspaceDiffStats } from "./WorkspaceDiffStats"; +import { WorkspaceStatusBadge } from "./WorkspaceStatusBadge"; + +const WORKSPACE_TYPE = "WORKSPACE"; + +interface WorkspaceListItemProps { + id: string; + projectId: string; + worktreePath: string; + name: string; + branch: string; + type: "worktree" | "branch"; + isActive: boolean; + isUnread?: boolean; + index: number; + shortcutIndex?: number; +} + +export function WorkspaceListItem({ + id, + projectId, + worktreePath, + name, + branch, + type, + isActive, + isUnread = false, + index, + shortcutIndex, +}: WorkspaceListItemProps) { + const isBranchWorkspace = type === "branch"; + const setActiveWorkspace = useSetActiveWorkspace(); + const reorderWorkspaces = useReorderWorkspaces(); + const [hasHovered, setHasHovered] = useState(false); + const rename = useWorkspaceRename(id, name); + const tabs = useTabsStore((s) => s.tabs); + const panes = useTabsStore((s) => s.panes); + const clearWorkspaceAttention = useTabsStore( + (s) => s.clearWorkspaceAttention, + ); + const utils = trpc.useUtils(); + const openInFinder = trpc.external.openInFinder.useMutation(); + const setUnread = trpc.workspaces.setUnread.useMutation({ + onSuccess: () => { + utils.workspaces.getAllGrouped.invalidate(); + }, + }); + + // Shared delete logic + const { showDeleteDialog, setShowDeleteDialog, handleDeleteClick } = + useWorkspaceDeleteHandler(); + + // Lazy-load GitHub status on hover to avoid N+1 queries + const { data: githubStatus } = trpc.workspaces.getGitHubStatus.useQuery( + { workspaceId: id }, + { + enabled: hasHovered && type === "worktree", + staleTime: GITHUB_STATUS_STALE_TIME, + }, + ); + + // Check if any pane in tabs belonging to this workspace needs attention (agent notifications) + const workspaceTabs = tabs.filter((t) => t.workspaceId === id); + const workspacePaneIds = new Set( + workspaceTabs.flatMap((t) => extractPaneIdsFromLayout(t.layout)), + ); + const hasPaneAttention = Object.values(panes) + .filter((p) => p != null && workspacePaneIds.has(p.id)) + .some((p) => p.needsAttention); + + // Show indicator if workspace is manually marked as unread OR has pane-level attention + const needsAttention = isUnread || hasPaneAttention; + + const handleClick = () => { + if (!rename.isRenaming) { + setActiveWorkspace.mutate({ id }); + clearWorkspaceAttention(id); + } + }; + + const handleMouseEnter = () => { + if (!hasHovered) { + setHasHovered(true); + } + }; + + const handleOpenInFinder = () => { + if (worktreePath) { + openInFinder.mutate(worktreePath); + } + }; + + const handleToggleUnread = () => { + setUnread.mutate({ id, isUnread: !isUnread }); + }; + + // Drag and drop + const [{ isDragging }, drag] = useDrag( + () => ({ + type: WORKSPACE_TYPE, + item: { id, projectId, index }, + collect: (monitor) => ({ + isDragging: monitor.isDragging(), + }), + }), + [id, projectId, index], + ); + + const [, drop] = useDrop({ + accept: WORKSPACE_TYPE, + hover: (item: { id: string; projectId: string; index: number }) => { + if (item.projectId === projectId && item.index !== index) { + reorderWorkspaces.mutate({ + projectId, + fromIndex: item.index, + toIndex: index, + }); + item.index = index; + } + }, + }); + + const pr = githubStatus?.pr; + const showDiffStats = pr && (pr.additions > 0 || pr.deletions > 0); + + const content = ( + + + + Close or delete + + + )} + + ); + + const unreadMenuItem = ( + + {isUnread ? ( + <> + + Mark as Read + + ) : ( + <> + + Mark as Unread + + )} + + ); + + // Wrap with context menu and hover card + if (isBranchWorkspace) { + return ( + <> + + {content} + + + Open in Finder + + + {unreadMenuItem} + + + + + ); + } + + return ( + <> + + + + {content} + + + + Rename + + + + Open in Finder + + + {unreadMenuItem} + + + + + + + + + ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceStatusBadge.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceStatusBadge.tsx new file mode 100644 index 00000000000..d6eb509d730 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceStatusBadge.tsx @@ -0,0 +1,53 @@ +import { cn } from "@superset/ui/utils"; +import { LuCircleDot, LuGitMerge, LuGitPullRequest } from "react-icons/lu"; + +type PRState = "open" | "merged" | "closed" | "draft"; + +interface WorkspaceStatusBadgeProps { + state: PRState; + prNumber?: number; +} + +export function WorkspaceStatusBadge({ + state, + prNumber, +}: WorkspaceStatusBadgeProps) { + const iconClass = "w-3 h-3"; + + const config = { + open: { + icon: , + bgColor: "bg-emerald-500/10", + }, + merged: { + icon: , + bgColor: "bg-purple-500/10", + }, + closed: { + icon: , + bgColor: "bg-destructive/10", + }, + draft: { + icon: ( + + ), + bgColor: "bg-muted", + }, + }; + + const { icon, bgColor } = config[state]; + + return ( +
+ {icon} + {prNumber && ( + #{prNumber} + )} +
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/constants.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/constants.ts new file mode 100644 index 00000000000..b6768dfb732 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/constants.ts @@ -0,0 +1,15 @@ +/** + * Constants for workspace list item behavior + */ + +/** Maximum index for keyboard shortcuts (Cmd+1 through Cmd+9) */ +export const MAX_KEYBOARD_SHORTCUT_INDEX = 9; + +/** Stale time for GitHub status queries (30 seconds) */ +export const GITHUB_STATUS_STALE_TIME = 30_000; + +/** Delay before showing hover card (ms) */ +export const HOVER_CARD_OPEN_DELAY = 400; + +/** Delay before hiding hover card (ms) */ +export const HOVER_CARD_CLOSE_DELAY = 100; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/index.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/index.ts new file mode 100644 index 00000000000..4dd9ef18a6e --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/index.ts @@ -0,0 +1,3 @@ +export { WorkspaceDiffStats } from "./WorkspaceDiffStats"; +export { WorkspaceListItem } from "./WorkspaceListItem"; +export { WorkspaceStatusBadge } from "./WorkspaceStatusBadge"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebar.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebar.tsx new file mode 100644 index 00000000000..c4d68290bfb --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebar.tsx @@ -0,0 +1,45 @@ +import { useWorkspaceShortcuts } from "renderer/hooks/useWorkspaceShortcuts"; +import { ProjectSection } from "./ProjectSection"; +import { WorkspaceSidebarFooter } from "./WorkspaceSidebarFooter"; +import { WorkspaceSidebarHeader } from "./WorkspaceSidebarHeader"; + +export function WorkspaceSidebar() { + const { groups, activeWorkspaceId } = useWorkspaceShortcuts(); + + // Calculate shortcut base indices for each project group + let shortcutIndex = 0; + const projectShortcutIndices = groups.map((group) => { + const baseIndex = shortcutIndex; + shortcutIndex += group.workspaces.length; + return baseIndex; + }); + + return ( +
+ + +
+ {groups.map((group, index) => ( + + ))} + + {groups.length === 0 && ( +
+ No workspaces yet + Add a project to get started +
+ )} +
+ + +
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebarFooter.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebarFooter.tsx new file mode 100644 index 00000000000..99c4117a96d --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebarFooter.tsx @@ -0,0 +1,62 @@ +import { Button } from "@superset/ui/button"; +import { toast } from "@superset/ui/sonner"; +import { LuFolderPlus } from "react-icons/lu"; +import { useOpenNew } from "renderer/react-query/projects"; +import { useCreateBranchWorkspace } from "renderer/react-query/workspaces"; + +export function WorkspaceSidebarFooter() { + const openNew = useOpenNew(); + const createBranchWorkspace = useCreateBranchWorkspace(); + + const handleOpenNewProject = async () => { + try { + const result = await openNew.mutateAsync(undefined); + if (result.canceled) { + return; + } + if ("error" in result) { + toast.error("Failed to open project", { + description: result.error, + }); + return; + } + if ("needsGitInit" in result) { + toast.error("Selected folder is not a git repository", { + description: + "Please use 'Open project' from the start view to initialize git.", + }); + return; + } + // Create a main workspace on the current branch for the new project + toast.promise( + createBranchWorkspace.mutateAsync({ projectId: result.project.id }), + { + loading: "Opening project...", + success: "Project opened", + error: (err) => + err instanceof Error ? err.message : "Failed to open project", + }, + ); + } catch (error) { + toast.error("Failed to open project", { + description: + error instanceof Error ? error.message : "An unknown error occurred", + }); + } + }; + + return ( +
+ +
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebarHeader.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebarHeader.tsx new file mode 100644 index 00000000000..bc54cd8e98b --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceSidebarHeader.tsx @@ -0,0 +1,10 @@ +import { LuLayers } from "react-icons/lu"; + +export function WorkspaceSidebarHeader() { + return ( +
+ + Workspaces +
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/index.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/index.ts new file mode 100644 index 00000000000..d8dc226739d --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/index.ts @@ -0,0 +1,2 @@ +export { ResizableWorkspaceSidebar } from "./ResizableWorkspaceSidebar"; +export { WorkspaceSidebar } from "./WorkspaceSidebar"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ContentHeader/ContentHeader.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ContentHeader/ContentHeader.tsx new file mode 100644 index 00000000000..85abdc17a8d --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ContentHeader/ContentHeader.tsx @@ -0,0 +1,28 @@ +import type { ReactNode } from "react"; + +interface ContentHeaderProps { + /** Optional leading action (e.g., SidebarControl) */ + leadingAction?: ReactNode; + /** Mode-specific header content (e.g., GroupStrip or file info) */ + children: ReactNode; + /** Optional trailing action (e.g., WorkspaceControls) */ + trailingAction?: ReactNode; +} + +export function ContentHeader({ + leadingAction, + children, + trailingAction, +}: ContentHeaderProps) { + return ( +
+ {leadingAction && ( +
{leadingAction}
+ )} +
{children}
+ {trailingAction && ( +
{trailingAction}
+ )} +
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ContentHeader/index.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ContentHeader/index.ts new file mode 100644 index 00000000000..26fb6ccbc3e --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ContentHeader/index.ts @@ -0,0 +1 @@ +export { ContentHeader } from "./ContentHeader"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/EmptyTabView.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/EmptyTabView.tsx index 0f9a435a873..daaff3366fd 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/EmptyTabView.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/EmptyTabView.tsx @@ -3,16 +3,16 @@ import { HiMiniCommandLine } from "react-icons/hi2"; import { useHotkeyDisplay } from "renderer/stores/hotkeys"; export function EmptyTabView() { - const newTerminalDisplay = useHotkeyDisplay("NEW_TERMINAL"); + const newGroupDisplay = useHotkeyDisplay("NEW_GROUP"); const openInAppDisplay = useHotkeyDisplay("OPEN_IN_APP"); const shortcuts = [ - { label: "New Terminal", display: newTerminalDisplay }, + { label: "New Group", display: newGroupDisplay }, { label: "Open in App", display: openInAppDisplay }, ]; return ( -
+
diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/GroupStrip/GroupStrip.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/GroupStrip/GroupStrip.tsx new file mode 100644 index 00000000000..77790ae7b88 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/GroupStrip/GroupStrip.tsx @@ -0,0 +1,172 @@ +import { Button } from "@superset/ui/button"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; +import { cn } from "@superset/ui/utils"; +import { useMemo } from "react"; +import { HiMiniPlus, HiMiniXMark } from "react-icons/hi2"; +import { trpc } from "renderer/lib/trpc"; +import { useTabsStore } from "renderer/stores/tabs/store"; +import type { Tab } from "renderer/stores/tabs/types"; +import { getTabDisplayName } from "renderer/stores/tabs/utils"; + +interface GroupItemProps { + tab: Tab; + isActive: boolean; + needsAttention: boolean; + onSelect: () => void; + onClose: () => void; +} + +function GroupItem({ + tab, + isActive, + needsAttention, + onSelect, + onClose, +}: GroupItemProps) { + const displayName = getTabDisplayName(tab); + + return ( +
+ + + + + + {displayName} + + + + + + + + Close group + + +
+ ); +} + +export function GroupStrip() { + const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); + const activeWorkspaceId = activeWorkspace?.id; + + const allTabs = useTabsStore((s) => s.tabs); + const panes = useTabsStore((s) => s.panes); + const activeTabIds = useTabsStore((s) => s.activeTabIds); + const addTab = useTabsStore((s) => s.addTab); + const removeTab = useTabsStore((s) => s.removeTab); + const setActiveTab = useTabsStore((s) => s.setActiveTab); + + const tabs = useMemo( + () => + activeWorkspaceId + ? allTabs.filter((tab) => tab.workspaceId === activeWorkspaceId) + : [], + [activeWorkspaceId, allTabs], + ); + + const activeTabId = activeWorkspaceId + ? activeTabIds[activeWorkspaceId] + : null; + + // Check which tabs have panes that need attention + const tabsWithAttention = useMemo(() => { + const result = new Set(); + for (const pane of Object.values(panes)) { + if (pane.needsAttention) { + result.add(pane.tabId); + } + } + return result; + }, [panes]); + + const handleAddGroup = () => { + if (activeWorkspaceId) { + addTab(activeWorkspaceId); + } + }; + + const handleSelectGroup = (tabId: string) => { + if (activeWorkspaceId) { + setActiveTab(activeWorkspaceId, tabId); + } + }; + + const handleCloseGroup = (tabId: string) => { + removeTab(tabId); + }; + + return ( +
+ {tabs.length > 0 && ( +
+ {tabs.map((tab) => ( +
+ handleSelectGroup(tab.id)} + onClose={() => handleCloseGroup(tab.id)} + /> +
+ ))} +
+ )} + + + + + + New Group + + +
+ ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/GroupStrip/index.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/GroupStrip/index.ts new file mode 100644 index 00000000000..e905a6c8bad --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/GroupStrip/index.ts @@ -0,0 +1 @@ +export { GroupStrip } from "./GroupStrip"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/FileViewerPane.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/FileViewerPane.tsx new file mode 100644 index 00000000000..e33ce675d2a --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/FileViewerPane.tsx @@ -0,0 +1,672 @@ +import Editor, { type OnMount } from "@monaco-editor/react"; +import { Badge } from "@superset/ui/badge"; +import { ToggleGroup, ToggleGroupItem } from "@superset/ui/toggle-group"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; +import type * as Monaco from "monaco-editor"; +import { useCallback, useEffect, useRef, useState } from "react"; +import { + HiMiniLockClosed, + HiMiniLockOpen, + HiMiniPencil, + HiMiniXMark, +} from "react-icons/hi2"; +import { LuLoader } from "react-icons/lu"; +import { TbLayoutColumns, TbLayoutRows } from "react-icons/tb"; +import type { MosaicBranch } from "react-mosaic-component"; +import { MosaicWindow } from "react-mosaic-component"; +import { MarkdownRenderer } from "renderer/components/MarkdownRenderer"; +import { + monaco, + SUPERSET_THEME, + useMonacoReady, +} from "renderer/contexts/MonacoProvider"; +import { trpc } from "renderer/lib/trpc"; +import { useTabsStore } from "renderer/stores/tabs/store"; +import type { Pane } from "renderer/stores/tabs/types"; +import type { FileViewerMode } from "shared/tabs-types"; +import { DiffViewer } from "../../../ChangesContent/components/DiffViewer"; + +type SplitOrientation = "vertical" | "horizontal"; + +/** Client-side language detection for Monaco editor */ +function detectLanguage(filePath: string): string { + const ext = filePath.split(".").pop()?.toLowerCase() ?? ""; + const languageMap: Record = { + ts: "typescript", + tsx: "typescript", + js: "javascript", + jsx: "javascript", + mjs: "javascript", + cjs: "javascript", + json: "json", + md: "markdown", + mdx: "markdown", + css: "css", + scss: "scss", + less: "less", + html: "html", + xml: "xml", + yaml: "yaml", + yml: "yaml", + py: "python", + rs: "rust", + go: "go", + java: "java", + kt: "kotlin", + swift: "swift", + c: "c", + cpp: "cpp", + h: "c", + hpp: "cpp", + sh: "shell", + bash: "shell", + zsh: "shell", + sql: "sql", + graphql: "graphql", + gql: "graphql", + }; + return languageMap[ext] ?? "plaintext"; +} + +interface FileViewerPaneProps { + paneId: string; + path: MosaicBranch[]; + pane: Pane; + isActive: boolean; + tabId: string; + worktreePath: string; + splitPaneAuto: ( + tabId: string, + sourcePaneId: string, + dimensions: { width: number; height: number }, + path?: MosaicBranch[], + ) => void; + removePane: (paneId: string) => void; + setFocusedPane: (tabId: string, paneId: string) => void; +} + +export function FileViewerPane({ + paneId, + path, + pane, + isActive, + tabId, + worktreePath, + splitPaneAuto, + removePane, + setFocusedPane, +}: FileViewerPaneProps) { + const containerRef = useRef(null); + const [splitOrientation, setSplitOrientation] = + useState("vertical"); + const isMonacoReady = useMonacoReady(); + const editorRef = useRef(null); + const [isDirty, setIsDirty] = useState(false); + const originalContentRef = useRef(""); + // Store draft content to preserve edits across view mode switches + const draftContentRef = useRef(null); + const utils = trpc.useUtils(); + + // Track container dimensions for auto-split orientation + useEffect(() => { + const container = containerRef.current; + if (!container) return; + + const updateOrientation = () => { + const { width, height } = container.getBoundingClientRect(); + setSplitOrientation(width >= height ? "vertical" : "horizontal"); + }; + + updateOrientation(); + + const resizeObserver = new ResizeObserver(updateOrientation); + resizeObserver.observe(container); + + return () => { + resizeObserver.disconnect(); + }; + }, []); + + const fileViewer = pane.fileViewer; + + // Extract values with defaults for hooks (hooks must be called unconditionally) + const filePath = fileViewer?.filePath ?? ""; + const viewMode = fileViewer?.viewMode ?? "raw"; + const isLocked = fileViewer?.isLocked ?? false; + const diffCategory = fileViewer?.diffCategory; + const commitHash = fileViewer?.commitHash; + const oldPath = fileViewer?.oldPath; + // Line/column for initial scroll position (raw mode only, applied once) + const initialLine = fileViewer?.initialLine; + const initialColumn = fileViewer?.initialColumn; + + // Fetch branch info for against-base diffs (P1-1) + const { data: branchData } = trpc.changes.getBranches.useQuery( + { worktreePath }, + { enabled: !!worktreePath && diffCategory === "against-base" }, + ); + const effectiveBaseBranch = branchData?.defaultBranch ?? "main"; + + // Track if we're saving from raw mode to know when to clear draft + const savingFromRawRef = useRef(false); + + // Track if we've applied initial line/column navigation (reset on file change) + const hasAppliedInitialLocationRef = useRef(false); + + // Save mutation + const saveFileMutation = trpc.changes.saveFile.useMutation({ + onSuccess: () => { + setIsDirty(false); + // Update original content to current content after save + if (editorRef.current) { + originalContentRef.current = editorRef.current.getValue(); + } + // P1: Only clear draft if we saved from Raw mode (we saved the draft content) + // Don't clear if saving from Diff mode as that would discard Raw edits + if (savingFromRawRef.current) { + draftContentRef.current = null; + } + savingFromRawRef.current = false; + // Invalidate queries to refresh data + utils.changes.readWorkingFile.invalidate(); + utils.changes.getFileContents.invalidate(); + utils.changes.getStatus.invalidate(); + + // P1-2: Switch to unstaged view if saving from staged (edits become unstaged changes) + if (diffCategory === "staged") { + const panes = useTabsStore.getState().panes; + const currentPane = panes[paneId]; + if (currentPane?.fileViewer) { + useTabsStore.setState({ + panes: { + ...panes, + [paneId]: { + ...currentPane, + fileViewer: { + ...currentPane.fileViewer, + diffCategory: "unstaged", + }, + }, + }, + }); + } + } + }, + }); + + // Save handler for raw mode editor + const handleSaveRaw = useCallback(() => { + if (!editorRef.current || !filePath || !worktreePath) return; + // Mark that we're saving from Raw mode so onSuccess knows to clear draft + savingFromRawRef.current = true; + saveFileMutation.mutate({ + worktreePath, + filePath, + content: editorRef.current.getValue(), + }); + }, [worktreePath, filePath, saveFileMutation]); + + // Save handler for diff mode + const handleSaveDiff = useCallback( + (content: string) => { + if (!filePath || !worktreePath) return; + // Not saving from Raw mode - don't clear draft + savingFromRawRef.current = false; + saveFileMutation.mutate({ + worktreePath, + filePath, + content, + }); + }, + [worktreePath, filePath, saveFileMutation], + ); + + // Editor mount handler - set up Cmd+S keybinding + const handleEditorMount: OnMount = useCallback( + (editor) => { + editorRef.current = editor; + // Store original content for dirty tracking (only if not restoring draft) + // If we have draft content, originalContentRef is already set to the file content + if (!draftContentRef.current) { + originalContentRef.current = editor.getValue(); + } + // P1: Update dirty state based on restored draft content + setIsDirty(editor.getValue() !== originalContentRef.current); + + // Register save action with Cmd+S / Ctrl+S + editor.addAction({ + id: "save-file", + label: "Save File", + keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS], + run: () => { + handleSaveRaw(); + }, + }); + }, + [handleSaveRaw], + ); + + // Track content changes for dirty state + const handleEditorChange = useCallback((value: string | undefined) => { + if (value !== undefined) { + setIsDirty(value !== originalContentRef.current); + } + }, []); + + // Reset dirty state, draft, and initial location tracking when file changes + // biome-ignore lint/correctness/useExhaustiveDependencies: Reset on file change only + useEffect(() => { + setIsDirty(false); + originalContentRef.current = ""; + draftContentRef.current = null; + hasAppliedInitialLocationRef.current = false; + }, [filePath]); + + // P1: Reset navigation flag when line/column changes (e.g., clicking same file from terminal with different line) + // biome-ignore lint/correctness/useExhaustiveDependencies: Only reset when coordinates change + useEffect(() => { + hasAppliedInitialLocationRef.current = false; + }, [initialLine, initialColumn]); + + // Fetch raw file content - always call hook, use enabled to control fetching + const { data: rawFileData, isLoading: isLoadingRaw } = + trpc.changes.readWorkingFile.useQuery( + { worktreePath, filePath }, + { + enabled: + !!fileViewer && viewMode !== "diff" && !!filePath && !!worktreePath, + }, + ); + + // Fetch diff content - always call hook, use enabled to control fetching + const { data: diffData, isLoading: isLoadingDiff } = + trpc.changes.getFileContents.useQuery( + { + worktreePath, + filePath, + oldPath, + category: diffCategory ?? "unstaged", + commitHash, + // P1-1: Pass defaultBranch for against-base diffs + defaultBranch: + diffCategory === "against-base" ? effectiveBaseBranch : undefined, + }, + { + enabled: + !!fileViewer && + viewMode === "diff" && + !!diffCategory && + !!filePath && + !!worktreePath, + }, + ); + + // P1-1: Update originalContentRef when raw content loads (dirty tracking fix) + // biome-ignore lint/correctness/useExhaustiveDependencies: Only update baseline when content loads + useEffect(() => { + if (rawFileData?.ok === true && !isDirty) { + originalContentRef.current = rawFileData.content; + } + }, [rawFileData]); + + // Apply initial line/column navigation when raw content is ready + // NOTE: Line/column navigation only supported in raw mode. + // Diff mode has different line numbers between sides; rendered mode has no line concept. + useEffect(() => { + if ( + viewMode !== "raw" || + !editorRef.current || + !initialLine || + hasAppliedInitialLocationRef.current || + isLoadingRaw || + !rawFileData?.ok + ) { + return; + } + + const editor = editorRef.current; + const model = editor.getModel(); + if (!model) return; + + // Clamp to valid range to handle lines that exceed file length + const lineCount = model.getLineCount(); + const safeLine = Math.max(1, Math.min(initialLine, lineCount)); + const maxColumn = model.getLineMaxColumn(safeLine); + const safeColumn = Math.max(1, Math.min(initialColumn ?? 1, maxColumn)); + + const position = { lineNumber: safeLine, column: safeColumn }; + editor.setPosition(position); + editor.revealPositionInCenter(position); + editor.focus(); + + hasAppliedInitialLocationRef.current = true; + }, [viewMode, initialLine, initialColumn, isLoadingRaw, rawFileData]); + + // Early return AFTER hooks + if (!fileViewer) { + return ( + path={path} title=""> +
+ No file viewer state +
+ + ); + } + + const handleFocus = () => { + setFocusedPane(tabId, paneId); + }; + + const handleClosePane = (e: React.MouseEvent) => { + e.stopPropagation(); + removePane(paneId); + }; + + const handleSplitPane = (e: React.MouseEvent) => { + e.stopPropagation(); + const container = containerRef.current; + if (!container) return; + + const { width, height } = container.getBoundingClientRect(); + splitPaneAuto(tabId, paneId, { width, height }, path); + }; + + const handleToggleLock = () => { + // Update the pane's lock state in the store + const panes = useTabsStore.getState().panes; + const currentPane = panes[paneId]; + if (currentPane?.fileViewer) { + useTabsStore.setState({ + panes: { + ...panes, + [paneId]: { + ...currentPane, + fileViewer: { + ...currentPane.fileViewer, + isLocked: !currentPane.fileViewer.isLocked, + }, + }, + }, + }); + } + }; + + const handleViewModeChange = (value: string) => { + if (!value) return; + const newMode = value as FileViewerMode; + + // P1: Save current editor content before switching away from raw mode + if (viewMode === "raw" && editorRef.current) { + draftContentRef.current = editorRef.current.getValue(); + } + + // Update the pane's view mode in the store + const panes = useTabsStore.getState().panes; + const currentPane = panes[paneId]; + if (currentPane?.fileViewer) { + useTabsStore.setState({ + panes: { + ...panes, + [paneId]: { + ...currentPane, + fileViewer: { + ...currentPane.fileViewer, + viewMode: newMode, + }, + }, + }, + }); + } + }; + + const fileName = filePath.split("/").pop() || filePath; + + // P1-3: Only allow editing for staged/unstaged diffs (not committed/against-main) + // P1: Also disable Diff editing when a Raw draft exists to prevent silent data loss + // User must go back to Raw mode to save their unsaved edits first + const hasDraft = draftContentRef.current !== null; + const isDiffEditable = + (diffCategory === "staged" || diffCategory === "unstaged") && !hasDraft; + + // Render content based on view mode + const renderContent = () => { + if (viewMode === "diff") { + if (isLoadingDiff) { + return ( +
+ Loading diff... +
+ ); + } + if (!diffData) { + return ( +
+ No diff available +
+ ); + } + return ( + + ); + } + + if (isLoadingRaw) { + return ( +
+ Loading... +
+ ); + } + + if (!rawFileData?.ok) { + const errorMessage = + rawFileData?.reason === "too-large" + ? "File is too large to preview" + : rawFileData?.reason === "binary" + ? "Binary file preview not supported" + : rawFileData?.reason === "outside-worktree" + ? "File is outside worktree" + : rawFileData?.reason === "symlink-escape" + ? "File is a symlink pointing outside worktree" + : "File not found"; + return ( +
+ {errorMessage} +
+ ); + } + + if (viewMode === "rendered") { + return ( +
+ +
+ ); + } + + // Raw mode - editable Monaco editor + if (!isMonacoReady) { + return ( +
+ + Loading editor... +
+ ); + } + + // P0-2: Key by filePath to force remount and fresh action registration + // P1: Use draft content if available (preserves edits across view mode switches) + return ( + + + Loading editor... +
+ } + options={{ + minimap: { enabled: false }, + scrollBeyondLastLine: false, + wordWrap: "on", + fontSize: 13, + lineHeight: 20, + fontFamily: + "ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace", + padding: { top: 8, bottom: 8 }, + scrollbar: { + verticalScrollbarSize: 8, + horizontalScrollbarSize: 8, + }, + }} + /> + ); + }; + + // Determine which view modes are available + // P1-2: Include .mdx for consistency with default view mode logic + const isMarkdown = + filePath.endsWith(".md") || + filePath.endsWith(".markdown") || + filePath.endsWith(".mdx"); + const hasDiff = !!diffCategory; + + const splitIcon = + splitOrientation === "vertical" ? ( + + ) : ( + + ); + + // Show editable badge only for editable modes + const showEditableBadge = + viewMode === "raw" || (viewMode === "diff" && isDiffEditable); + const isSaving = saveFileMutation.isPending; + + return ( + + path={path} + title="" + renderToolbar={() => ( +
+
+ + {isDirty && } + {fileName} + + {showEditableBadge && ( + + + {isSaving ? "Saving..." : "⌘S"} + + )} +
+
+ + {isMarkdown && ( + + Rendered + + )} + + Raw + + {hasDiff && ( + + Diff + + )} + + + + + + + Split pane + + + + + + + + {isLocked + ? "Unlock (allow file replacement)" + : "Lock (prevent file replacement)"} + + + + + + + + Close + + +
+
+ )} + className={isActive ? "mosaic-window-focused" : ""} + > + {/* biome-ignore lint/a11y/useKeyWithClickEvents lint/a11y/noStaticElementInteractions: Focus handler */} +
+ {renderContent()} +
+ + ); +} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/index.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/index.ts new file mode 100644 index 00000000000..96c33fa0b12 --- /dev/null +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/FileViewerPane/index.ts @@ -0,0 +1 @@ +export { FileViewerPane } from "./FileViewerPane"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/index.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/index.tsx index b6df3608e13..3502a82dce2 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/index.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/index.tsx @@ -8,6 +8,7 @@ import { type MosaicNode, } from "react-mosaic-component"; import { dragDropManager } from "renderer/lib/dnd"; +import { trpc } from "renderer/lib/trpc"; import { useTabsStore } from "renderer/stores/tabs/store"; import type { Pane, Tab } from "renderer/stores/tabs/types"; import { @@ -15,6 +16,7 @@ import { extractPaneIdsFromLayout, getPaneIdsForTab, } from "renderer/stores/tabs/utils"; +import { FileViewerPane } from "./FileViewerPane"; import { TabPane } from "./TabPane"; interface TabViewProps { @@ -35,6 +37,10 @@ export function TabView({ tab, panes }: TabViewProps) { const movePaneToNewTab = useTabsStore((s) => s.movePaneToNewTab); const allTabs = useTabsStore((s) => s.tabs); + // Get worktree path for file viewer panes + const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); + const worktreePath = activeWorkspace?.worktreePath ?? ""; + // Get tabs in the same workspace for move targets const workspaceTabs = allTabs.filter( (t) => t.workspaceId === tab.workspaceId, @@ -90,6 +96,24 @@ export function TabView({ tab, panes }: TabViewProps) { ); } + // Route file-viewer panes to FileViewerPane component + if (pane.type === "file-viewer") { + return ( + + ); + } + + // Default: terminal panes return ( { const setTabAutoTitle = useTabsStore((s) => s.setTabAutoTitle); const updatePaneCwd = useTabsStore((s) => s.updatePaneCwd); const focusedPaneIds = useTabsStore((s) => s.focusedPaneIds); + const addFileViewerPane = useTabsStore((s) => s.addFileViewerPane); const terminalTheme = useTerminalTheme(); // Ref for initial theme to avoid recreating terminal on theme change @@ -68,6 +71,76 @@ export const Terminal = ({ tabId, workspaceId }: TerminalProps) => { const { data: workspaceCwd } = trpc.terminal.getWorkspaceCwd.useQuery(workspaceId); + // Query terminal link behavior setting + const { data: terminalLinkBehavior } = + trpc.settings.getTerminalLinkBehavior.useQuery(); + + // Handler for file link clicks - uses current setting value + const handleFileLinkClick = useCallback( + (path: string, line?: number, column?: number) => { + const behavior = terminalLinkBehavior ?? "external-editor"; + + // Helper to open in external editor + const openInExternalEditor = () => { + trpcClient.external.openFileInEditor + .mutate({ + path, + line, + column, + cwd: workspaceCwd ?? undefined, + }) + .catch((error) => { + console.error( + "[Terminal] Failed to open file in editor:", + path, + error, + ); + toast.error("Failed to open file in editor", { + description: path, + }); + }); + }; + + if (behavior === "file-viewer") { + // If workspaceCwd is not loaded yet, fall back to external editor + // This prevents confusing errors when the workspace is still initializing + if (!workspaceCwd) { + console.warn( + "[Terminal] workspaceCwd not loaded, falling back to external editor", + ); + openInExternalEditor(); + return; + } + + // Normalize absolute paths to worktree-relative paths for file viewer + // File viewer expects relative paths, but terminal links can be absolute + let filePath = path; + // Use path boundary check to avoid incorrect prefix stripping + // e.g., /repo vs /repo-other should not match + if (path === workspaceCwd) { + filePath = "."; + } else if (path.startsWith(`${workspaceCwd}/`)) { + filePath = path.slice(workspaceCwd.length + 1); + } else if (path.startsWith("/")) { + // Absolute path outside workspace - show warning and don't attempt to open + toast.warning("File is outside the workspace", { + description: + "Switch to 'External editor' in Settings to open this file", + }); + return; + } + addFileViewerPane(workspaceId, { filePath, line, column }); + } else { + openInExternalEditor(); + } + }, + [terminalLinkBehavior, workspaceId, workspaceCwd, addFileViewerPane], + ); + + // Ref to avoid terminal recreation when callback changes + const handleFileLinkClickRef = useRef(handleFileLinkClick); + handleFileLinkClickRef.current = handleFileLinkClick; + // Seed cwd from initialCwd or workspace path (shell spawns there) // OSC-7 will override if/when the shell reports directory changes useEffect(() => { @@ -197,11 +270,12 @@ export const Terminal = ({ tabId, workspaceId }: TerminalProps) => { xterm, fitAddon, cleanup: cleanupQuerySuppression, - } = createTerminalInstance( - container, - workspaceCwd, - initialThemeRef.current, - ); + } = createTerminalInstance(container, { + cwd: workspaceCwd, + initialTheme: initialThemeRef.current, + onFileLinkClick: (path, line, column) => + handleFileLinkClickRef.current(path, line, column), + }); xtermRef.current = xterm; fitAddonRef.current = fitAddon; isExitedRef.current = false; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts index 6058503b816..89473cdf9d6 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts @@ -92,19 +92,26 @@ function loadRenderer(xterm: XTerm): { dispose: () => void } { }; } +export interface CreateTerminalOptions { + cwd?: string; + initialTheme?: ITheme | null; + onFileLinkClick?: (path: string, line?: number, column?: number) => void; +} + export function createTerminalInstance( container: HTMLDivElement, - cwd?: string, - initialTheme?: ITheme | null, + options: CreateTerminalOptions = {}, ): { xterm: XTerm; fitAddon: FitAddon; cleanup: () => void; } { + const { cwd, initialTheme, onFileLinkClick } = options; + // Use provided theme, or fall back to localStorage-based default to prevent flash const theme = initialTheme ?? getDefaultTerminalTheme(); - const options = { ...TERMINAL_OPTIONS, theme }; - const xterm = new XTerm(options); + const terminalOptions = { ...TERMINAL_OPTIONS, theme }; + const xterm = new XTerm(terminalOptions); const fitAddon = new FitAddon(); const clipboardAddon = new ClipboardAddon(); @@ -142,20 +149,25 @@ export function createTerminalInstance( const filePathLinkProvider = new FilePathLinkProvider( xterm, (_event, path, line, column) => { - trpcClient.external.openFileInEditor - .mutate({ - path, - line, - column, - cwd, - }) - .catch((error) => { - console.error( - "[Terminal] Failed to open file in editor:", + if (onFileLinkClick) { + onFileLinkClick(path, line, column); + } else { + // Fallback to default behavior (external editor) + trpcClient.external.openFileInEditor + .mutate({ path, - error, - ); - }); + line, + column, + cwd, + }) + .catch((error) => { + console.error( + "[Terminal] Failed to open file in editor:", + path, + error, + ); + }); + } }, ); xterm.registerLinkProvider(filePathLinkProvider); diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx index e04866eb656..fb3908f55f4 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx @@ -23,5 +23,9 @@ export function TabsContent() { return ; } - return ; + return ( +
+ +
+ ); } diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/index.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/index.tsx index 1a2e20bd0fb..01d80ffa175 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/index.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/index.tsx @@ -1,19 +1,69 @@ -import { SidebarMode, useSidebarStore } from "renderer/stores"; +import { trpc } from "renderer/lib/trpc"; +import { useWorkspaceViewModeStore } from "renderer/stores/workspace-view-mode"; +import { DEFAULT_NAVIGATION_STYLE } from "shared/constants"; +import { SidebarControl } from "../../SidebarControl"; +import { WorkspaceControls } from "../../TopBar/WorkspaceControls"; import { ChangesContent } from "./ChangesContent"; +import { ContentHeader } from "./ContentHeader"; import { TabsContent } from "./TabsContent"; +import { GroupStrip } from "./TabsContent/GroupStrip"; export function ContentView() { - const { currentMode } = useSidebarStore(); + const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); + const workspaceId = activeWorkspace?.id; - if (currentMode === SidebarMode.Changes) { + // Subscribe to the actual data, not just the getter function + const viewModeByWorkspaceId = useWorkspaceViewModeStore( + (s) => s.viewModeByWorkspaceId, + ); + + const viewMode = workspaceId + ? (viewModeByWorkspaceId[workspaceId] ?? "workbench") + : "workbench"; + + // Get navigation style to conditionally show sidebar toggle + const { data: navigationStyle } = trpc.settings.getNavigationStyle.useQuery(); + const isSidebarMode = + (navigationStyle ?? DEFAULT_NAVIGATION_STYLE) === "sidebar"; + + // Render WorkspaceControls in ContentHeader when in sidebar mode + const workspaceControls = isSidebarMode ? ( + + ) : undefined; + + if (viewMode === "review") { return ( -
-
- +
+ {isSidebarMode && ( + } + trailingAction={workspaceControls} + > + {/* Review mode has no group tabs */} +
+ + )} +
+
+ +
); } - return ; + return ( +
+ : undefined} + trailingAction={workspaceControls} + > + + + +
+ ); } diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/ChangesView/ChangesView.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/ChangesView/ChangesView.tsx index ee0ec6d2e9c..b269533cc7f 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/ChangesView/ChangesView.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/ChangesView/ChangesView.tsx @@ -6,13 +6,22 @@ import { HiMiniMinus, HiMiniPlus } from "react-icons/hi2"; import { trpc } from "renderer/lib/trpc"; import { useChangesStore } from "renderer/stores/changes"; import type { ChangeCategory, ChangedFile } from "shared/changes-types"; +import { PortsList } from "../TabsView/PortsList"; import { CategorySection } from "./components/CategorySection"; import { ChangesHeader } from "./components/ChangesHeader"; import { CommitInput } from "./components/CommitInput"; import { CommitItem } from "./components/CommitItem"; import { FileList } from "./components/FileList"; -export function ChangesView() { +interface ChangesViewProps { + onFileOpen?: ( + file: ChangedFile, + category: ChangeCategory, + commitHash?: string, + ) => void; +} + +export function ChangesView({ onFileOpen }: ChangesViewProps) { const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); const worktreePath = activeWorkspace?.worktreePath; @@ -128,11 +137,13 @@ export function ChangesView() { const handleFileSelect = (file: ChangedFile, category: ChangeCategory) => { if (!worktreePath) return; selectFile(worktreePath, file, category, null); + onFileOpen?.(file, category); }; const handleCommitFileSelect = (file: ChangedFile, commitHash: string) => { if (!worktreePath) return; selectFile(worktreePath, file, "committed", commitHash); + onFileOpen?.(file, "committed", commitHash); }; const handleCommitToggle = (hash: string) => { @@ -349,6 +360,8 @@ export function ChangesView() {
)} + +
); } diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/index.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/index.tsx index 7511587610a..b93ef1f3849 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/index.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/index.tsx @@ -1,29 +1,40 @@ -import { useSidebarStore } from "renderer/stores"; -import { SidebarMode } from "renderer/stores/sidebar-state"; +import { trpc } from "renderer/lib/trpc"; +import { useTabsStore } from "renderer/stores/tabs/store"; +import { useWorkspaceViewModeStore } from "renderer/stores/workspace-view-mode"; +import type { ChangeCategory, ChangedFile } from "shared/changes-types"; import { ChangesView } from "./ChangesView"; -import { ModeCarousel } from "./ModeCarousel"; -import { TabsView } from "./TabsView"; export function Sidebar() { - const { currentMode, setMode } = useSidebarStore(); + const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); + const workspaceId = activeWorkspace?.id; - const modes: SidebarMode[] = [SidebarMode.Tabs, SidebarMode.Changes]; + // Subscribe to the actual data, not just the getter function + const viewModeByWorkspaceId = useWorkspaceViewModeStore( + (s) => s.viewModeByWorkspaceId, + ); + + const viewMode = workspaceId + ? (viewModeByWorkspaceId[workspaceId] ?? "workbench") + : "workbench"; + + const addFileViewerPane = useTabsStore((s) => s.addFileViewerPane); + + // In Workbench mode, open files in FileViewerPane + const handleFileOpen = + viewMode === "workbench" && workspaceId + ? (file: ChangedFile, category: ChangeCategory, commitHash?: string) => { + addFileViewerPane(workspaceId, { + filePath: file.path, + diffCategory: category, + commitHash, + oldPath: file.oldPath, + }); + } + : undefined; return ( ); } diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/WorkspaceActionBar.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/WorkspaceActionBar.tsx deleted file mode 100644 index f641fde5af1..00000000000 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/WorkspaceActionBar.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { WorkspaceActionBarLeft } from "./components/WorkspaceActionBarLeft"; -import { WorkspaceActionBarRight } from "./components/WorkspaceActionBarRight"; - -interface WorkspaceActionBarProps { - worktreePath: string | undefined; -} - -export function WorkspaceActionBar({ worktreePath }: WorkspaceActionBarProps) { - if (!worktreePath) return null; - - return ( -
-
- -
-
- -
-
- ); -} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarLeft/WorkspaceActionBarLeft.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarLeft/WorkspaceActionBarLeft.tsx deleted file mode 100644 index 0db773eb901..00000000000 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarLeft/WorkspaceActionBarLeft.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; -import { GoGitBranch } from "react-icons/go"; -import { trpc } from "renderer/lib/trpc"; - -export function WorkspaceActionBarLeft() { - const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); - const currentBranch = activeWorkspace?.worktree?.branch; - const baseBranch = activeWorkspace?.worktree?.baseBranch; - return ( - <> - {currentBranch && ( - - - - - - {currentBranch} - - - - - Current branch - - - )} - {baseBranch && baseBranch !== currentBranch && ( - - - - from - {baseBranch} - - - - Based on {baseBranch} - - - )} - - ); -} diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarLeft/index.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarLeft/index.ts deleted file mode 100644 index 9a42acaa856..00000000000 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarLeft/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { WorkspaceActionBarLeft } from "./WorkspaceActionBarLeft"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarRight/index.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarRight/index.ts deleted file mode 100644 index da70bada5b9..00000000000 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/components/WorkspaceActionBarRight/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { WorkspaceActionBarRight } from "./WorkspaceActionBarRight"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/index.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/index.ts deleted file mode 100644 index c8caa3fbcd3..00000000000 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/WorkspaceActionBar/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { WorkspaceActionBar } from "./WorkspaceActionBar"; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/index.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/index.tsx index 661543c8580..84f22532079 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/index.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/index.tsx @@ -1,11 +1,12 @@ import { useMemo } from "react"; +import { useHotkeys } from "react-hotkeys-hook"; import { trpc } from "renderer/lib/trpc"; -import { useAppHotkey } from "renderer/stores/hotkeys"; import { useTabsStore } from "renderer/stores/tabs/store"; import { getNextPaneId, getPreviousPaneId } from "renderer/stores/tabs/utils"; +import { useWorkspaceViewModeStore } from "renderer/stores/workspace-view-mode"; +import { getHotkey } from "shared/hotkeys"; import { ContentView } from "./ContentView"; import { ResizableSidebar } from "./ResizableSidebar"; -import { WorkspaceActionBar } from "./WorkspaceActionBar"; export function WorkspaceView() { const { data: activeWorkspace } = trpc.workspaces.getActive.useQuery(); @@ -39,121 +40,95 @@ export function WorkspaceView() { // Get focused pane ID for the active tab const focusedPaneId = activeTabId ? focusedPaneIds[activeTabId] : null; - // Tab management shortcuts - useAppHotkey( - "NEW_TERMINAL", - () => { - if (activeWorkspaceId) { - addTab(activeWorkspaceId); - } - }, - undefined, - [activeWorkspaceId, addTab], + // View mode for terminal creation - subscribe to actual data for reactivity + const viewModeByWorkspaceId = useWorkspaceViewModeStore( + (s) => s.viewModeByWorkspaceId, ); - - useAppHotkey( - "CLOSE_TERMINAL", - () => { - // Close focused pane (which may close the tab if it's the last pane) - if (focusedPaneId) { - removePane(focusedPaneId); - } - }, - undefined, - [focusedPaneId, removePane], + const setWorkspaceViewMode = useWorkspaceViewModeStore( + (s) => s.setWorkspaceViewMode, ); + const viewMode = activeWorkspaceId + ? (viewModeByWorkspaceId[activeWorkspaceId] ?? "workbench") + : "workbench"; - // Switch between tabs (configurable shortcut) - useAppHotkey( - "PREV_TERMINAL", - () => { - if (!activeWorkspaceId || !activeTabId) return; - const index = tabs.findIndex((t) => t.id === activeTabId); - if (index > 0) { - setActiveTab(activeWorkspaceId, tabs[index - 1].id); + // Tab management shortcuts + useHotkeys(getHotkey("NEW_GROUP"), () => { + if (activeWorkspaceId) { + // If in Review mode, switch to Workbench first + if (viewMode === "review") { + setWorkspaceViewMode(activeWorkspaceId, "workbench"); } - }, - undefined, - [activeWorkspaceId, activeTabId, tabs, setActiveTab], - ); + addTab(activeWorkspaceId); + } + }, [activeWorkspaceId, addTab, viewMode, setWorkspaceViewMode]); - useAppHotkey( - "NEXT_TERMINAL", - () => { - if (!activeWorkspaceId || !activeTabId) return; - const index = tabs.findIndex((t) => t.id === activeTabId); - if (index < tabs.length - 1) { - setActiveTab(activeWorkspaceId, tabs[index + 1].id); - } - }, - undefined, - [activeWorkspaceId, activeTabId, tabs, setActiveTab], - ); + useHotkeys(getHotkey("CLOSE_TERMINAL"), () => { + // Close focused pane (which may close the tab if it's the last pane) + if (focusedPaneId) { + removePane(focusedPaneId); + } + }, [focusedPaneId, removePane]); - // Switch between panes within a tab (configurable shortcut) - useAppHotkey( - "PREV_PANE", - () => { - if (!activeTabId || !activeTab?.layout || !focusedPaneId) return; - const prevPaneId = getPreviousPaneId(activeTab.layout, focusedPaneId); - if (prevPaneId) { - setFocusedPane(activeTabId, prevPaneId); - } - }, - undefined, - [activeTabId, activeTab?.layout, focusedPaneId, setFocusedPane], - ); + // Switch between tabs (⌘+Up/Down) + useHotkeys(getHotkey("PREV_TERMINAL"), () => { + if (!activeWorkspaceId || !activeTabId) return; + const index = tabs.findIndex((t) => t.id === activeTabId); + if (index > 0) { + setActiveTab(activeWorkspaceId, tabs[index - 1].id); + } + }, [activeWorkspaceId, activeTabId, tabs, setActiveTab]); - useAppHotkey( - "NEXT_PANE", - () => { - if (!activeTabId || !activeTab?.layout || !focusedPaneId) return; - const nextPaneId = getNextPaneId(activeTab.layout, focusedPaneId); - if (nextPaneId) { - setFocusedPane(activeTabId, nextPaneId); - } - }, - undefined, - [activeTabId, activeTab?.layout, focusedPaneId, setFocusedPane], - ); + useHotkeys(getHotkey("NEXT_TERMINAL"), () => { + if (!activeWorkspaceId || !activeTabId) return; + const index = tabs.findIndex((t) => t.id === activeTabId); + if (index < tabs.length - 1) { + setActiveTab(activeWorkspaceId, tabs[index + 1].id); + } + }, [activeWorkspaceId, activeTabId, tabs, setActiveTab]); + + // Switch between panes within a tab (⌘+⌥+Left/Right) + useHotkeys(getHotkey("PREV_PANE"), () => { + if (!activeTabId || !activeTab?.layout || !focusedPaneId) return; + const prevPaneId = getPreviousPaneId(activeTab.layout, focusedPaneId); + if (prevPaneId) { + setFocusedPane(activeTabId, prevPaneId); + } + }, [activeTabId, activeTab?.layout, focusedPaneId, setFocusedPane]); + + useHotkeys(getHotkey("NEXT_PANE"), () => { + if (!activeTabId || !activeTab?.layout || !focusedPaneId) return; + const nextPaneId = getNextPaneId(activeTab.layout, focusedPaneId); + if (nextPaneId) { + setFocusedPane(activeTabId, nextPaneId); + } + }, [activeTabId, activeTab?.layout, focusedPaneId, setFocusedPane]); // Open in last used app shortcut const { data: lastUsedApp = "cursor" } = trpc.settings.getLastUsedApp.useQuery(); const openInApp = trpc.external.openInApp.useMutation(); - useAppHotkey( - "OPEN_IN_APP", - () => { - if (activeWorkspace?.worktreePath) { - openInApp.mutate({ - path: activeWorkspace.worktreePath, - app: lastUsedApp, - }); - } - }, - undefined, - [activeWorkspace?.worktreePath, lastUsedApp], - ); + useHotkeys("meta+o", () => { + if (activeWorkspace?.worktreePath) { + openInApp.mutate({ + path: activeWorkspace.worktreePath, + app: lastUsedApp, + }); + } + }, [activeWorkspace?.worktreePath, lastUsedApp]); // Copy path shortcut const copyPath = trpc.external.copyPath.useMutation(); - useAppHotkey( - "COPY_PATH", - () => { - if (activeWorkspace?.worktreePath) { - copyPath.mutate(activeWorkspace.worktreePath); - } - }, - undefined, - [activeWorkspace?.worktreePath], - ); + useHotkeys("meta+shift+c", () => { + if (activeWorkspace?.worktreePath) { + copyPath.mutate(activeWorkspace.worktreePath); + } + }, [activeWorkspace?.worktreePath]); return (
-
diff --git a/apps/desktop/src/renderer/screens/main/index.tsx b/apps/desktop/src/renderer/screens/main/index.tsx index 98f2cc947a2..580f08bbf7f 100644 --- a/apps/desktop/src/renderer/screens/main/index.tsx +++ b/apps/desktop/src/renderer/screens/main/index.tsx @@ -3,6 +3,7 @@ import { Button } from "@superset/ui/button"; import { useFeatureFlagEnabled } from "posthog-js/react"; import { useCallback, useState } from "react"; import { DndProvider } from "react-dnd"; +import { useHotkeys } from "react-hotkeys-hook"; import { HiArrowPath } from "react-icons/hi2"; import { NewWorkspaceModal } from "renderer/components/NewWorkspaceModal"; import { SetupConfigModal } from "renderer/components/SetupConfigModal"; @@ -19,6 +20,9 @@ import { useTabsStore } from "renderer/stores/tabs/store"; import type { Tab } from "renderer/stores/tabs/types"; import { useAgentHookListener } from "renderer/stores/tabs/useAgentHookListener"; import { findPanePath, getFirstPaneId } from "renderer/stores/tabs/utils"; +import { useWorkspaceSidebarStore } from "renderer/stores/workspace-sidebar-state"; +import { DEFAULT_NAVIGATION_STYLE } from "shared/constants"; +import { getHotkey } from "shared/hotkeys"; import { dragDropManager } from "../../lib/dnd"; import { AppFrame } from "./components/AppFrame"; import { Background } from "./components/Background"; @@ -26,6 +30,7 @@ import { SettingsView } from "./components/SettingsView"; import { StartView } from "./components/StartView"; import { TasksView } from "./components/TasksView"; import { TopBar } from "./components/TopBar"; +import { ResizableWorkspaceSidebar } from "./components/WorkspaceSidebar"; import { WorkspaceView } from "./components/WorkspaceView"; function LoadingSpinner() { @@ -56,10 +61,16 @@ export function MainScreen() { const currentView = useCurrentView(); const openSettings = useOpenSettings(); - const { toggleSidebar } = useSidebarStore(); + const toggleSidebar = useSidebarStore((s) => s.toggleSidebar); + const toggleWorkspaceSidebar = useWorkspaceSidebarStore((s) => s.toggleOpen); const hasTasksAccess = useFeatureFlagEnabled( FEATURE_FLAGS.ELECTRIC_TASKS_ACCESS, ); + + // Navigation style setting + const { data: navigationStyle } = trpc.settings.getNavigationStyle.useQuery(); + const effectiveNavigationStyle = navigationStyle ?? DEFAULT_NAVIGATION_STYLE; + const isSidebarMode = effectiveNavigationStyle === "sidebar"; const { data: activeWorkspace, isLoading: isWorkspaceLoading, @@ -111,6 +122,10 @@ export function MainScreen() { [toggleSidebar, isWorkspaceView], ); + useHotkeys(getHotkey("TOGGLE_WORKSPACE_SIDEBAR"), () => { + if (isSidebarMode) toggleWorkspaceSidebar(); + }, [toggleWorkspaceSidebar, isSidebarMode]); + /** * Resolves the target pane for split operations. * If the focused pane is desynced from layout (e.g., was removed), @@ -336,8 +351,11 @@ export function MainScreen() { ) : (
- -
{renderContent()}
+ +
+ {isSidebarMode && } + {renderContent()} +
)} diff --git a/apps/desktop/src/renderer/stores/index.ts b/apps/desktop/src/renderer/stores/index.ts index b289f0bfb38..8d3726bd2c1 100644 --- a/apps/desktop/src/renderer/stores/index.ts +++ b/apps/desktop/src/renderer/stores/index.ts @@ -6,3 +6,5 @@ export * from "./ringtone"; export * from "./sidebar-state"; export * from "./tabs"; export * from "./theme"; +export * from "./workspace-sidebar-state"; +export * from "./workspace-view-mode"; diff --git a/apps/desktop/src/renderer/stores/new-workspace-modal.ts b/apps/desktop/src/renderer/stores/new-workspace-modal.ts index 0890c7797e4..38b18916b32 100644 --- a/apps/desktop/src/renderer/stores/new-workspace-modal.ts +++ b/apps/desktop/src/renderer/stores/new-workspace-modal.ts @@ -3,7 +3,8 @@ import { devtools } from "zustand/middleware"; interface NewWorkspaceModalState { isOpen: boolean; - openModal: () => void; + preSelectedProjectId: string | null; + openModal: (projectId?: string) => void; closeModal: () => void; } @@ -11,13 +12,14 @@ export const useNewWorkspaceModalStore = create()( devtools( (set) => ({ isOpen: false, + preSelectedProjectId: null, - openModal: () => { - set({ isOpen: true }); + openModal: (projectId?: string) => { + set({ isOpen: true, preSelectedProjectId: projectId ?? null }); }, closeModal: () => { - set({ isOpen: false }); + set({ isOpen: false, preSelectedProjectId: null }); }, }), { name: "NewWorkspaceModalStore" }, @@ -31,3 +33,5 @@ export const useOpenNewWorkspaceModal = () => useNewWorkspaceModalStore((state) => state.openModal); export const useCloseNewWorkspaceModal = () => useNewWorkspaceModalStore((state) => state.closeModal); +export const usePreSelectedProjectId = () => + useNewWorkspaceModalStore((state) => state.preSelectedProjectId); diff --git a/apps/desktop/src/renderer/stores/tabs/store.ts b/apps/desktop/src/renderer/stores/tabs/store.ts index d28d8316add..828d0679dc1 100644 --- a/apps/desktop/src/renderer/stores/tabs/store.ts +++ b/apps/desktop/src/renderer/stores/tabs/store.ts @@ -4,9 +4,10 @@ import { create } from "zustand"; import { devtools, persist } from "zustand/middleware"; import { trpcTabsStorage } from "../../lib/trpc-storage"; import { movePaneToNewTab, movePaneToTab } from "./actions/move-pane"; -import type { TabsState, TabsStore } from "./types"; +import type { AddFileViewerPaneOptions, TabsState, TabsStore } from "./types"; import { type CreatePaneOptions, + createFileViewerPane, createPane, createTabWithPane, extractPaneIdsFromLayout, @@ -125,7 +126,11 @@ export const useTabsStore = create()( const paneIds = getPaneIdsForTab(state.panes, tabId); for (const paneId of paneIds) { - killTerminalForPane(paneId); + // Only kill terminal sessions for terminal panes (avoids unnecessary IPC for file-viewers) + const pane = state.panes[paneId]; + if (pane?.type === "terminal") { + killTerminalForPane(paneId); + } } const newPanes = { ...state.panes }; @@ -285,7 +290,10 @@ export const useTabsStore = create()( const newPanes = { ...state.panes }; for (const paneId of removedPaneIds) { - killTerminalForPane(paneId); + // P2: Only kill terminal for actual terminal panes (avoid unnecessary IPC) + if (state.panes[paneId]?.type === "terminal") { + killTerminalForPane(paneId); + } delete newPanes[paneId]; } @@ -340,6 +348,112 @@ export const useTabsStore = create()( return newPane.id; }, + addFileViewerPane: ( + workspaceId: string, + options: AddFileViewerPaneOptions, + ) => { + const state = get(); + const activeTabId = state.activeTabIds[workspaceId]; + const activeTab = state.tabs.find((t) => t.id === activeTabId); + + // If no active tab, create a new one (this shouldn't normally happen) + if (!activeTab) { + const { tabId, paneId } = get().addTab(workspaceId); + // Update the pane to be a file-viewer (must use set() to get fresh state after addTab) + const fileViewerPane = createFileViewerPane(tabId, options); + set((s) => ({ + panes: { + ...s.panes, + [paneId]: { + ...fileViewerPane, + id: paneId, // Keep the original ID + }, + }, + })); + return paneId; + } + + // Look for an existing unlocked file-viewer pane in the active tab + const tabPaneIds = extractPaneIdsFromLayout(activeTab.layout); + const fileViewerPanes = tabPaneIds + .map((id) => state.panes[id]) + .filter( + (p) => + p?.type === "file-viewer" && + p.fileViewer && + !p.fileViewer.isLocked, + ); + + // If we found an unlocked file-viewer pane, reuse it + if (fileViewerPanes.length > 0) { + const paneToReuse = fileViewerPanes[0]; + const fileName = + options.filePath.split("/").pop() || options.filePath; + + // Determine default view mode + let viewMode: "raw" | "rendered" | "diff" = "raw"; + if (options.diffCategory) { + viewMode = "diff"; + } else if ( + options.filePath.endsWith(".md") || + options.filePath.endsWith(".markdown") || + options.filePath.endsWith(".mdx") + ) { + viewMode = "rendered"; + } + + set({ + panes: { + ...state.panes, + [paneToReuse.id]: { + ...paneToReuse, + name: fileName, + fileViewer: { + filePath: options.filePath, + viewMode, + isLocked: false, + diffLayout: "inline", + diffCategory: options.diffCategory, + commitHash: options.commitHash, + oldPath: options.oldPath, + initialLine: options.line, + initialColumn: options.column, + }, + }, + }, + focusedPaneIds: { + ...state.focusedPaneIds, + [activeTab.id]: paneToReuse.id, + }, + }); + + return paneToReuse.id; + } + + // No reusable pane found, create a new one + const newPane = createFileViewerPane(activeTab.id, options); + + const newLayout: MosaicNode = { + direction: "row", + first: activeTab.layout, + second: newPane.id, + splitPercentage: 50, + }; + + set({ + tabs: state.tabs.map((t) => + t.id === activeTab.id ? { ...t, layout: newLayout } : t, + ), + panes: { ...state.panes, [newPane.id]: newPane }, + focusedPaneIds: { + ...state.focusedPaneIds, + [activeTab.id]: newPane.id, + }, + }); + + return newPane.id; + }, + removePane: (paneId) => { const state = get(); const pane = state.panes[paneId]; @@ -354,7 +468,10 @@ export const useTabsStore = create()( return; } - killTerminalForPane(paneId); + // Only kill terminal sessions for terminal panes (avoids unnecessary IPC for file-viewers) + if (pane.type === "terminal") { + killTerminalForPane(paneId); + } const newLayout = removePaneFromLayout(tab.layout, paneId); if (!newLayout) { @@ -428,6 +545,33 @@ export const useTabsStore = create()( })); }, + clearWorkspaceAttention: (workspaceId) => { + const state = get(); + const workspaceTabs = state.tabs.filter( + (t) => t.workspaceId === workspaceId, + ); + const workspacePaneIds = workspaceTabs.flatMap((t) => + extractPaneIdsFromLayout(t.layout), + ); + + if (workspacePaneIds.length === 0) { + return; + } + + const newPanes = { ...state.panes }; + let hasChanges = false; + for (const paneId of workspacePaneIds) { + if (newPanes[paneId]?.needsAttention) { + newPanes[paneId] = { ...newPanes[paneId], needsAttention: false }; + hasChanges = true; + } + } + + if (hasChanges) { + set({ panes: newPanes }); + } + }, + updatePaneCwd: (paneId, cwd, confirmed) => { set((state) => ({ panes: { @@ -463,7 +607,19 @@ export const useTabsStore = create()( const sourcePane = state.panes[sourcePaneId]; if (!sourcePane || sourcePane.tabId !== tabId) return; - const newPane = createPane(tabId); + // Clone file-viewer panes instead of creating a terminal + const newPane = + sourcePane.type === "file-viewer" && sourcePane.fileViewer + ? createFileViewerPane(tabId, { + filePath: sourcePane.fileViewer.filePath, + viewMode: sourcePane.fileViewer.viewMode, + isLocked: true, // Lock the cloned pane + diffLayout: sourcePane.fileViewer.diffLayout, + diffCategory: sourcePane.fileViewer.diffCategory, + commitHash: sourcePane.fileViewer.commitHash, + oldPath: sourcePane.fileViewer.oldPath, + }) + : createPane(tabId); let newLayout: MosaicNode; if (path && path.length > 0) { @@ -511,7 +667,19 @@ export const useTabsStore = create()( const sourcePane = state.panes[sourcePaneId]; if (!sourcePane || sourcePane.tabId !== tabId) return; - const newPane = createPane(tabId); + // Clone file-viewer panes instead of creating a terminal + const newPane = + sourcePane.type === "file-viewer" && sourcePane.fileViewer + ? createFileViewerPane(tabId, { + filePath: sourcePane.fileViewer.filePath, + viewMode: sourcePane.fileViewer.viewMode, + isLocked: true, // Lock the cloned pane + diffLayout: sourcePane.fileViewer.diffLayout, + diffCategory: sourcePane.fileViewer.diffCategory, + commitHash: sourcePane.fileViewer.commitHash, + oldPath: sourcePane.fileViewer.oldPath, + }) + : createPane(tabId); let newLayout: MosaicNode; if (path && path.length > 0) { diff --git a/apps/desktop/src/renderer/stores/tabs/types.ts b/apps/desktop/src/renderer/stores/tabs/types.ts index bcb0f70af82..9638df6e072 100644 --- a/apps/desktop/src/renderer/stores/tabs/types.ts +++ b/apps/desktop/src/renderer/stores/tabs/types.ts @@ -1,4 +1,5 @@ import type { MosaicBranch, MosaicNode } from "react-mosaic-component"; +import type { ChangeCategory } from "shared/changes-types"; import type { BaseTab, BaseTabsState, Pane, PaneType } from "shared/tabs-types"; // Re-export shared types @@ -28,6 +29,20 @@ export interface AddTabOptions { initialCwd?: string; } +/** + * Options for opening a file in a file-viewer pane + */ +export interface AddFileViewerPaneOptions { + filePath: string; + diffCategory?: ChangeCategory; + commitHash?: string; + oldPath?: string; + /** Line to scroll to (raw mode only) */ + line?: number; + /** Column to scroll to (raw mode only) */ + column?: number; +} + /** * Actions available on the tabs store */ @@ -51,10 +66,15 @@ export interface TabsStore extends TabsState { // Pane operations addPane: (tabId: string, options?: AddTabOptions) => string; + addFileViewerPane: ( + workspaceId: string, + options: AddFileViewerPaneOptions, + ) => string; removePane: (paneId: string) => void; setFocusedPane: (tabId: string, paneId: string) => void; markPaneAsUsed: (paneId: string) => void; setNeedsAttention: (paneId: string, needsAttention: boolean) => void; + clearWorkspaceAttention: (workspaceId: string) => void; updatePaneCwd: ( paneId: string, cwd: string | null, diff --git a/apps/desktop/src/renderer/stores/tabs/utils.ts b/apps/desktop/src/renderer/stores/tabs/utils.ts index a1e7bef16cf..77eecc76c1f 100644 --- a/apps/desktop/src/renderer/stores/tabs/utils.ts +++ b/apps/desktop/src/renderer/stores/tabs/utils.ts @@ -1,4 +1,10 @@ import type { MosaicBranch, MosaicNode } from "react-mosaic-component"; +import type { ChangeCategory } from "shared/changes-types"; +import type { + DiffLayout, + FileViewerMode, + FileViewerState, +} from "shared/tabs-types"; import type { Pane, PaneType, Tab } from "./types"; /** @@ -82,6 +88,68 @@ export const createPane = ( }; }; +/** + * Options for creating a file-viewer pane + */ +export interface CreateFileViewerPaneOptions { + filePath: string; + viewMode?: FileViewerMode; + isLocked?: boolean; + diffLayout?: DiffLayout; + diffCategory?: ChangeCategory; + commitHash?: string; + oldPath?: string; + /** Line to scroll to (raw mode only) */ + line?: number; + /** Column to scroll to (raw mode only) */ + column?: number; +} + +/** + * Creates a new file-viewer pane with the given properties + */ +export const createFileViewerPane = ( + tabId: string, + options: CreateFileViewerPaneOptions, +): Pane => { + const id = generateId("pane"); + + // Determine default view mode based on file and category + let defaultViewMode: FileViewerMode = "raw"; + if (options.diffCategory) { + defaultViewMode = "diff"; + } else if ( + options.filePath.endsWith(".md") || + options.filePath.endsWith(".markdown") || + options.filePath.endsWith(".mdx") + ) { + defaultViewMode = "rendered"; + } + + const fileViewer: FileViewerState = { + filePath: options.filePath, + viewMode: options.viewMode ?? defaultViewMode, + isLocked: options.isLocked ?? false, + diffLayout: options.diffLayout ?? "inline", + diffCategory: options.diffCategory, + commitHash: options.commitHash, + oldPath: options.oldPath, + initialLine: options.line, + initialColumn: options.column, + }; + + // Use filename for display name + const fileName = options.filePath.split("/").pop() || options.filePath; + + return { + id, + tabId, + type: "file-viewer", + name: fileName, + fileViewer, + }; +}; + /** * Generates a static tab name based on existing tabs * (e.g., "Terminal 1", "Terminal 2", finding the next available number) diff --git a/apps/desktop/src/renderer/stores/workspace-sidebar-state.ts b/apps/desktop/src/renderer/stores/workspace-sidebar-state.ts new file mode 100644 index 00000000000..adb12801ebe --- /dev/null +++ b/apps/desktop/src/renderer/stores/workspace-sidebar-state.ts @@ -0,0 +1,105 @@ +import { create } from "zustand"; +import { devtools, persist } from "zustand/middleware"; + +const DEFAULT_WORKSPACE_SIDEBAR_WIDTH = 280; +export const MIN_WORKSPACE_SIDEBAR_WIDTH = 220; +export const MAX_WORKSPACE_SIDEBAR_WIDTH = 400; + +interface WorkspaceSidebarState { + isOpen: boolean; + width: number; + lastOpenWidth: number; + // Use string[] instead of Set for JSON serialization with Zustand persist + collapsedProjectIds: string[]; + isResizing: boolean; + + toggleOpen: () => void; + setOpen: (open: boolean) => void; + setWidth: (width: number) => void; + setIsResizing: (isResizing: boolean) => void; + toggleProjectCollapsed: (projectId: string) => void; + isProjectCollapsed: (projectId: string) => boolean; +} + +export const useWorkspaceSidebarStore = create()( + devtools( + persist( + (set, get) => ({ + isOpen: true, + width: DEFAULT_WORKSPACE_SIDEBAR_WIDTH, + lastOpenWidth: DEFAULT_WORKSPACE_SIDEBAR_WIDTH, + collapsedProjectIds: [], + isResizing: false, + + toggleOpen: () => { + const { isOpen, lastOpenWidth } = get(); + if (isOpen) { + set({ isOpen: false, width: 0 }); + } else { + set({ + isOpen: true, + width: lastOpenWidth, + }); + } + }, + + setOpen: (open) => { + const { lastOpenWidth } = get(); + set({ + isOpen: open, + width: open ? lastOpenWidth : 0, + }); + }, + + setWidth: (width) => { + const clampedWidth = Math.max( + MIN_WORKSPACE_SIDEBAR_WIDTH, + Math.min(MAX_WORKSPACE_SIDEBAR_WIDTH, width), + ); + + if (width > 0) { + set({ + width: clampedWidth, + lastOpenWidth: clampedWidth, + isOpen: true, + }); + } else { + set({ + width: 0, + isOpen: false, + }); + } + }, + + setIsResizing: (isResizing) => { + set({ isResizing }); + }, + + toggleProjectCollapsed: (projectId) => { + set((state) => ({ + collapsedProjectIds: state.collapsedProjectIds.includes(projectId) + ? state.collapsedProjectIds.filter((id) => id !== projectId) + : [...state.collapsedProjectIds, projectId], + })); + }, + + isProjectCollapsed: (projectId) => { + return get().collapsedProjectIds.includes(projectId); + }, + }), + { + name: "workspace-sidebar-store", + version: 1, + // Exclude ephemeral state from persistence + partialize: (state) => ({ + isOpen: state.isOpen, + width: state.width, + lastOpenWidth: state.lastOpenWidth, + collapsedProjectIds: state.collapsedProjectIds, + // isResizing intentionally excluded - ephemeral UI state + }), + }, + ), + { name: "WorkspaceSidebarStore" }, + ), +); diff --git a/apps/desktop/src/renderer/stores/workspace-view-mode.ts b/apps/desktop/src/renderer/stores/workspace-view-mode.ts new file mode 100644 index 00000000000..b9bee9b2665 --- /dev/null +++ b/apps/desktop/src/renderer/stores/workspace-view-mode.ts @@ -0,0 +1,56 @@ +import { create } from "zustand"; +import { devtools, persist } from "zustand/middleware"; + +/** + * Workspace view modes: + * - "workbench": Groups + Mosaic panes layout for in-flow work + * - "review": Dedicated Changes page for focused code review + */ +export type WorkspaceViewMode = "workbench" | "review"; + +interface WorkspaceViewModeState { + /** + * Per-workspace view mode. Defaults to "workbench" when not set. + */ + viewModeByWorkspaceId: Record; + + /** + * Get the view mode for a workspace, defaulting to "workbench" + */ + getWorkspaceViewMode: (workspaceId: string) => WorkspaceViewMode; + + /** + * Set the view mode for a workspace + */ + setWorkspaceViewMode: (workspaceId: string, mode: WorkspaceViewMode) => void; +} + +export const useWorkspaceViewModeStore = create()( + devtools( + persist( + (set, get) => ({ + viewModeByWorkspaceId: {}, + + getWorkspaceViewMode: (workspaceId: string) => { + return get().viewModeByWorkspaceId[workspaceId] ?? "workbench"; + }, + + setWorkspaceViewMode: ( + workspaceId: string, + mode: WorkspaceViewMode, + ) => { + set((state) => ({ + viewModeByWorkspaceId: { + ...state.viewModeByWorkspaceId, + [workspaceId]: mode, + }, + })); + }, + }), + { + name: "workspace-view-mode-store", + }, + ), + { name: "WorkspaceViewModeStore" }, + ), +); diff --git a/apps/desktop/src/shared/constants.ts b/apps/desktop/src/shared/constants.ts index 6bc788cead4..35c6207de41 100644 --- a/apps/desktop/src/shared/constants.ts +++ b/apps/desktop/src/shared/constants.ts @@ -46,3 +46,5 @@ export const NOTIFICATION_EVENTS = { // Default user preference values export const DEFAULT_CONFIRM_ON_QUIT = true; +export const DEFAULT_TERMINAL_LINK_BEHAVIOR = "external-editor" as const; +export const DEFAULT_NAVIGATION_STYLE = "top-bar" as const; diff --git a/apps/desktop/src/shared/hotkeys.ts b/apps/desktop/src/shared/hotkeys.ts index c4e38007bbe..2a2b4620789 100644 --- a/apps/desktop/src/shared/hotkeys.ts +++ b/apps/desktop/src/shared/hotkeys.ts @@ -423,7 +423,12 @@ export const HOTKEYS = { // Layout TOGGLE_SIDEBAR: defineHotkey({ keys: "meta+b", - label: "Toggle Sidebar", + label: "Toggle Files Sidebar", + category: "Layout", + }), + TOGGLE_WORKSPACE_SIDEBAR: defineHotkey({ + keys: "meta+shift+b", + label: "Toggle Workspaces Sidebar", category: "Layout", }), SPLIT_RIGHT: defineHotkey({ @@ -452,9 +457,9 @@ export const HOTKEYS = { category: "Terminal", description: "Search text in the active terminal", }), - NEW_TERMINAL: defineHotkey({ + NEW_GROUP: defineHotkey({ keys: "meta+t", - label: "New Terminal", + label: "New Group", category: "Terminal", }), CLOSE_TERMINAL: defineHotkey({ @@ -575,6 +580,15 @@ export function getDefaultHotkey( return HOTKEYS[id].defaults[platform]; } +/** + * Get the hotkey binding for the current platform. + * Convenience wrapper around getDefaultHotkey. + * Returns empty string if no hotkey is defined (safe for useHotkeys). + */ +export function getHotkey(id: HotkeyId): string { + return getDefaultHotkey(id, getCurrentPlatform()) ?? ""; +} + export function getEffectiveHotkey( id: HotkeyId, overrides: Partial>, diff --git a/apps/desktop/src/shared/tabs-types.ts b/apps/desktop/src/shared/tabs-types.ts index 8ae323601eb..d8c921186eb 100644 --- a/apps/desktop/src/shared/tabs-types.ts +++ b/apps/desktop/src/shared/tabs-types.ts @@ -3,10 +3,46 @@ * Renderer extends these with MosaicNode layout specifics. */ +import type { ChangeCategory } from "./changes-types"; + /** * Pane types that can be displayed within a tab */ -export type PaneType = "terminal" | "webview"; +export type PaneType = "terminal" | "webview" | "file-viewer"; + +/** + * File viewer display modes + */ +export type FileViewerMode = "rendered" | "raw" | "diff"; + +/** + * Diff layout options for file viewer + */ +export type DiffLayout = "inline" | "side-by-side"; + +/** + * File viewer pane-specific properties + */ +export interface FileViewerState { + /** Worktree-relative file path */ + filePath: string; + /** Display mode: rendered (markdown), raw (source), or diff */ + viewMode: FileViewerMode; + /** If true, this pane won't be reused for new file clicks */ + isLocked: boolean; + /** Diff display layout */ + diffLayout: DiffLayout; + /** Category for diff source (against-main, committed, staged, unstaged) */ + diffCategory?: ChangeCategory; + /** Commit hash for committed category diffs */ + commitHash?: string; + /** Original path for renamed files */ + oldPath?: string; + /** Initial line to scroll to (raw mode only, transient - applied once) */ + initialLine?: number; + /** Initial column to scroll to (raw mode only, transient - applied once) */ + initialColumn?: number; +} /** * Base Pane interface - shared between main and renderer @@ -23,6 +59,7 @@ export interface Pane { url?: string; // For webview panes cwd?: string | null; // Current working directory cwdConfirmed?: boolean; // True if cwd confirmed via OSC-7, false if seeded + fileViewer?: FileViewerState; // For file-viewer panes } /** diff --git a/packages/local-db/drizzle/0004_add_terminal_link_behavior_setting.sql b/packages/local-db/drizzle/0004_add_terminal_link_behavior_setting.sql new file mode 100644 index 00000000000..ad70f21f3fe --- /dev/null +++ b/packages/local-db/drizzle/0004_add_terminal_link_behavior_setting.sql @@ -0,0 +1 @@ +ALTER TABLE `settings` ADD `terminal_link_behavior` text; \ No newline at end of file diff --git a/packages/local-db/drizzle/0005_add_navigation_style.sql b/packages/local-db/drizzle/0005_add_navigation_style.sql new file mode 100644 index 00000000000..c3c175a0327 --- /dev/null +++ b/packages/local-db/drizzle/0005_add_navigation_style.sql @@ -0,0 +1 @@ +ALTER TABLE `settings` ADD `navigation_style` text; \ No newline at end of file diff --git a/packages/local-db/drizzle/0006_add_unique_branch_workspace_index.sql b/packages/local-db/drizzle/0006_add_unique_branch_workspace_index.sql new file mode 100644 index 00000000000..6945d545ce6 --- /dev/null +++ b/packages/local-db/drizzle/0006_add_unique_branch_workspace_index.sql @@ -0,0 +1,46 @@ +-- Dedupe existing duplicate branch workspaces before creating unique index. +-- Keep the most recently used one (highest last_opened_at), with id ASC as tiebreaker. +-- First, update settings.last_active_workspace_id if it points to a workspace we're about to delete +UPDATE settings +SET last_active_workspace_id = ( + SELECT w1.id FROM workspaces w1 + WHERE w1.type = 'branch' + AND w1.project_id = ( + SELECT w2.project_id FROM workspaces w2 WHERE w2.id = settings.last_active_workspace_id + ) + ORDER BY w1.last_opened_at DESC NULLS LAST, w1.id ASC + LIMIT 1 +) +WHERE last_active_workspace_id IN ( + SELECT w1.id FROM workspaces w1 + WHERE w1.type = 'branch' + AND EXISTS ( + SELECT 1 FROM workspaces w2 + WHERE w2.type = 'branch' + AND w2.project_id = w1.project_id + AND ( + w2.last_opened_at > w1.last_opened_at + OR (w2.last_opened_at = w1.last_opened_at AND w2.id < w1.id) + OR (w2.last_opened_at IS NOT NULL AND w1.last_opened_at IS NULL) + ) + ) +); + +-- Delete duplicate branch workspaces, keeping the most recently used per project +-- Survivor selection: highest last_opened_at, then lowest id as tiebreaker +DELETE FROM workspaces +WHERE type = 'branch' +AND id NOT IN ( + SELECT id FROM ( + SELECT id, ROW_NUMBER() OVER ( + PARTITION BY project_id + ORDER BY last_opened_at DESC NULLS LAST, id ASC + ) as rn + FROM workspaces + WHERE type = 'branch' + ) ranked + WHERE rn = 1 +); + +-- Now safe to create the unique index +CREATE UNIQUE INDEX IF NOT EXISTS `workspaces_unique_branch_per_project` ON `workspaces` (`project_id`) WHERE `type` = 'branch'; diff --git a/packages/local-db/drizzle/0007_add_workspace_is_unread.sql b/packages/local-db/drizzle/0007_add_workspace_is_unread.sql new file mode 100644 index 00000000000..9f3ca8ec300 --- /dev/null +++ b/packages/local-db/drizzle/0007_add_workspace_is_unread.sql @@ -0,0 +1 @@ +ALTER TABLE `workspaces` ADD `is_unread` integer DEFAULT false; diff --git a/packages/local-db/drizzle/meta/0004_snapshot.json b/packages/local-db/drizzle/meta/0004_snapshot.json new file mode 100644 index 00000000000..991b5469eb5 --- /dev/null +++ b/packages/local-db/drizzle/meta/0004_snapshot.json @@ -0,0 +1,977 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "bb9f9f85-bcbb-4003-b20f-4c172a1c6fc8", + "prevId": "d5a52ac9-bc1e-4529-89bf-5748d4df5006", + "tables": { + "organization_members": { + "name": "organization_members", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "organization_members_organization_id_idx": { + "name": "organization_members_organization_id_idx", + "columns": [ + "organization_id" + ], + "isUnique": false + }, + "organization_members_user_id_idx": { + "name": "organization_members_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "organization_members_organization_id_organizations_id_fk": { + "name": "organization_members_organization_id_organizations_id_fk", + "tableFrom": "organization_members", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_members_user_id_users_id_fk": { + "name": "organization_members_user_id_users_id_fk", + "tableFrom": "organization_members", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "organizations": { + "name": "organizations", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "clerk_org_id": { + "name": "clerk_org_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "github_org": { + "name": "github_org", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "organizations_clerk_org_id_unique": { + "name": "organizations_clerk_org_id_unique", + "columns": [ + "clerk_org_id" + ], + "isUnique": true + }, + "organizations_slug_unique": { + "name": "organizations_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "organizations_slug_idx": { + "name": "organizations_slug_idx", + "columns": [ + "slug" + ], + "isUnique": false + }, + "organizations_clerk_org_id_idx": { + "name": "organizations_clerk_org_id_idx", + "columns": [ + "clerk_org_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "projects": { + "name": "projects", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "main_repo_path": { + "name": "main_repo_path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tab_order": { + "name": "tab_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "config_toast_dismissed": { + "name": "config_toast_dismissed", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "default_branch": { + "name": "default_branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "projects_main_repo_path_idx": { + "name": "projects_main_repo_path_idx", + "columns": [ + "main_repo_path" + ], + "isUnique": false + }, + "projects_last_opened_at_idx": { + "name": "projects_last_opened_at_idx", + "columns": [ + "last_opened_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "settings": { + "name": "settings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "last_active_workspace_id": { + "name": "last_active_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_used_app": { + "name": "last_used_app", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_presets": { + "name": "terminal_presets", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_presets_initialized": { + "name": "terminal_presets_initialized", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "selected_ringtone_id": { + "name": "selected_ringtone_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "active_organization_id": { + "name": "active_organization_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "confirm_on_quit": { + "name": "confirm_on_quit", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_link_behavior": { + "name": "terminal_link_behavior", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tasks": { + "name": "tasks", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status_color": { + "name": "status_color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_type": { + "name": "status_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_position": { + "name": "status_position", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "repository_id": { + "name": "repository_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_id": { + "name": "assignee_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "creator_id": { + "name": "creator_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "estimate": { + "name": "estimate", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "due_date": { + "name": "due_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "labels": { + "name": "labels", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pr_url": { + "name": "pr_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_provider": { + "name": "external_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_key": { + "name": "external_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_url": { + "name": "external_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sync_error": { + "name": "sync_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "completed_at": { + "name": "completed_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "tasks_slug_unique": { + "name": "tasks_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "tasks_slug_idx": { + "name": "tasks_slug_idx", + "columns": [ + "slug" + ], + "isUnique": false + }, + "tasks_organization_id_idx": { + "name": "tasks_organization_id_idx", + "columns": [ + "organization_id" + ], + "isUnique": false + }, + "tasks_assignee_id_idx": { + "name": "tasks_assignee_id_idx", + "columns": [ + "assignee_id" + ], + "isUnique": false + }, + "tasks_status_idx": { + "name": "tasks_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "tasks_created_at_idx": { + "name": "tasks_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "tasks_organization_id_organizations_id_fk": { + "name": "tasks_organization_id_organizations_id_fk", + "tableFrom": "tasks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_assignee_id_users_id_fk": { + "name": "tasks_assignee_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "assignee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_creator_id_users_id_fk": { + "name": "tasks_creator_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "clerk_id": { + "name": "clerk_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "users_clerk_id_unique": { + "name": "users_clerk_id_unique", + "columns": [ + "clerk_id" + ], + "isUnique": true + }, + "users_email_unique": { + "name": "users_email_unique", + "columns": [ + "email" + ], + "isUnique": true + }, + "users_email_idx": { + "name": "users_email_idx", + "columns": [ + "email" + ], + "isUnique": false + }, + "users_clerk_id_idx": { + "name": "users_clerk_id_idx", + "columns": [ + "clerk_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "workspaces": { + "name": "workspaces", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "worktree_id": { + "name": "worktree_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tab_order": { + "name": "tab_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "workspaces_project_id_idx": { + "name": "workspaces_project_id_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "workspaces_worktree_id_idx": { + "name": "workspaces_worktree_id_idx", + "columns": [ + "worktree_id" + ], + "isUnique": false + }, + "workspaces_last_opened_at_idx": { + "name": "workspaces_last_opened_at_idx", + "columns": [ + "last_opened_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "workspaces_project_id_projects_id_fk": { + "name": "workspaces_project_id_projects_id_fk", + "tableFrom": "workspaces", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspaces_worktree_id_worktrees_id_fk": { + "name": "workspaces_worktree_id_worktrees_id_fk", + "tableFrom": "workspaces", + "tableTo": "worktrees", + "columnsFrom": [ + "worktree_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "worktrees": { + "name": "worktrees", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base_branch": { + "name": "base_branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "git_status": { + "name": "git_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "github_status": { + "name": "github_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "worktrees_project_id_idx": { + "name": "worktrees_project_id_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "worktrees_branch_idx": { + "name": "worktrees_branch_idx", + "columns": [ + "branch" + ], + "isUnique": false + } + }, + "foreignKeys": { + "worktrees_project_id_projects_id_fk": { + "name": "worktrees_project_id_projects_id_fk", + "tableFrom": "worktrees", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/packages/local-db/drizzle/meta/0005_snapshot.json b/packages/local-db/drizzle/meta/0005_snapshot.json new file mode 100644 index 00000000000..14c02c328fd --- /dev/null +++ b/packages/local-db/drizzle/meta/0005_snapshot.json @@ -0,0 +1,984 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "ac200b80-657f-4cd7-b338-2d6adeb925e7", + "prevId": "bb9f9f85-bcbb-4003-b20f-4c172a1c6fc8", + "tables": { + "organization_members": { + "name": "organization_members", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "organization_members_organization_id_idx": { + "name": "organization_members_organization_id_idx", + "columns": [ + "organization_id" + ], + "isUnique": false + }, + "organization_members_user_id_idx": { + "name": "organization_members_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "organization_members_organization_id_organizations_id_fk": { + "name": "organization_members_organization_id_organizations_id_fk", + "tableFrom": "organization_members", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_members_user_id_users_id_fk": { + "name": "organization_members_user_id_users_id_fk", + "tableFrom": "organization_members", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "organizations": { + "name": "organizations", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "clerk_org_id": { + "name": "clerk_org_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "github_org": { + "name": "github_org", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "organizations_clerk_org_id_unique": { + "name": "organizations_clerk_org_id_unique", + "columns": [ + "clerk_org_id" + ], + "isUnique": true + }, + "organizations_slug_unique": { + "name": "organizations_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "organizations_slug_idx": { + "name": "organizations_slug_idx", + "columns": [ + "slug" + ], + "isUnique": false + }, + "organizations_clerk_org_id_idx": { + "name": "organizations_clerk_org_id_idx", + "columns": [ + "clerk_org_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "projects": { + "name": "projects", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "main_repo_path": { + "name": "main_repo_path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tab_order": { + "name": "tab_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "config_toast_dismissed": { + "name": "config_toast_dismissed", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "default_branch": { + "name": "default_branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "projects_main_repo_path_idx": { + "name": "projects_main_repo_path_idx", + "columns": [ + "main_repo_path" + ], + "isUnique": false + }, + "projects_last_opened_at_idx": { + "name": "projects_last_opened_at_idx", + "columns": [ + "last_opened_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "settings": { + "name": "settings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "last_active_workspace_id": { + "name": "last_active_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_used_app": { + "name": "last_used_app", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_presets": { + "name": "terminal_presets", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_presets_initialized": { + "name": "terminal_presets_initialized", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "selected_ringtone_id": { + "name": "selected_ringtone_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "active_organization_id": { + "name": "active_organization_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "confirm_on_quit": { + "name": "confirm_on_quit", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_link_behavior": { + "name": "terminal_link_behavior", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "navigation_style": { + "name": "navigation_style", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tasks": { + "name": "tasks", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status_color": { + "name": "status_color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_type": { + "name": "status_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_position": { + "name": "status_position", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "repository_id": { + "name": "repository_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_id": { + "name": "assignee_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "creator_id": { + "name": "creator_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "estimate": { + "name": "estimate", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "due_date": { + "name": "due_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "labels": { + "name": "labels", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pr_url": { + "name": "pr_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_provider": { + "name": "external_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_key": { + "name": "external_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_url": { + "name": "external_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sync_error": { + "name": "sync_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "completed_at": { + "name": "completed_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "tasks_slug_unique": { + "name": "tasks_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "tasks_slug_idx": { + "name": "tasks_slug_idx", + "columns": [ + "slug" + ], + "isUnique": false + }, + "tasks_organization_id_idx": { + "name": "tasks_organization_id_idx", + "columns": [ + "organization_id" + ], + "isUnique": false + }, + "tasks_assignee_id_idx": { + "name": "tasks_assignee_id_idx", + "columns": [ + "assignee_id" + ], + "isUnique": false + }, + "tasks_status_idx": { + "name": "tasks_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "tasks_created_at_idx": { + "name": "tasks_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "tasks_organization_id_organizations_id_fk": { + "name": "tasks_organization_id_organizations_id_fk", + "tableFrom": "tasks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_assignee_id_users_id_fk": { + "name": "tasks_assignee_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "assignee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_creator_id_users_id_fk": { + "name": "tasks_creator_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "clerk_id": { + "name": "clerk_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "users_clerk_id_unique": { + "name": "users_clerk_id_unique", + "columns": [ + "clerk_id" + ], + "isUnique": true + }, + "users_email_unique": { + "name": "users_email_unique", + "columns": [ + "email" + ], + "isUnique": true + }, + "users_email_idx": { + "name": "users_email_idx", + "columns": [ + "email" + ], + "isUnique": false + }, + "users_clerk_id_idx": { + "name": "users_clerk_id_idx", + "columns": [ + "clerk_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "workspaces": { + "name": "workspaces", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "worktree_id": { + "name": "worktree_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tab_order": { + "name": "tab_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "workspaces_project_id_idx": { + "name": "workspaces_project_id_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "workspaces_worktree_id_idx": { + "name": "workspaces_worktree_id_idx", + "columns": [ + "worktree_id" + ], + "isUnique": false + }, + "workspaces_last_opened_at_idx": { + "name": "workspaces_last_opened_at_idx", + "columns": [ + "last_opened_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "workspaces_project_id_projects_id_fk": { + "name": "workspaces_project_id_projects_id_fk", + "tableFrom": "workspaces", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspaces_worktree_id_worktrees_id_fk": { + "name": "workspaces_worktree_id_worktrees_id_fk", + "tableFrom": "workspaces", + "tableTo": "worktrees", + "columnsFrom": [ + "worktree_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "worktrees": { + "name": "worktrees", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base_branch": { + "name": "base_branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "git_status": { + "name": "git_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "github_status": { + "name": "github_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "worktrees_project_id_idx": { + "name": "worktrees_project_id_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "worktrees_branch_idx": { + "name": "worktrees_branch_idx", + "columns": [ + "branch" + ], + "isUnique": false + } + }, + "foreignKeys": { + "worktrees_project_id_projects_id_fk": { + "name": "worktrees_project_id_projects_id_fk", + "tableFrom": "worktrees", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/packages/local-db/drizzle/meta/0006_snapshot.json b/packages/local-db/drizzle/meta/0006_snapshot.json new file mode 100644 index 00000000000..5362480f6e2 --- /dev/null +++ b/packages/local-db/drizzle/meta/0006_snapshot.json @@ -0,0 +1,984 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "f1e2d3c4-b5a6-7890-abcd-ef1234567890", + "prevId": "ac200b80-657f-4cd7-b338-2d6adeb925e7", + "tables": { + "organization_members": { + "name": "organization_members", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "organization_members_organization_id_idx": { + "name": "organization_members_organization_id_idx", + "columns": [ + "organization_id" + ], + "isUnique": false + }, + "organization_members_user_id_idx": { + "name": "organization_members_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "organization_members_organization_id_organizations_id_fk": { + "name": "organization_members_organization_id_organizations_id_fk", + "tableFrom": "organization_members", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_members_user_id_users_id_fk": { + "name": "organization_members_user_id_users_id_fk", + "tableFrom": "organization_members", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "organizations": { + "name": "organizations", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "clerk_org_id": { + "name": "clerk_org_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "github_org": { + "name": "github_org", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "organizations_clerk_org_id_unique": { + "name": "organizations_clerk_org_id_unique", + "columns": [ + "clerk_org_id" + ], + "isUnique": true + }, + "organizations_slug_unique": { + "name": "organizations_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "organizations_slug_idx": { + "name": "organizations_slug_idx", + "columns": [ + "slug" + ], + "isUnique": false + }, + "organizations_clerk_org_id_idx": { + "name": "organizations_clerk_org_id_idx", + "columns": [ + "clerk_org_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "projects": { + "name": "projects", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "main_repo_path": { + "name": "main_repo_path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tab_order": { + "name": "tab_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "config_toast_dismissed": { + "name": "config_toast_dismissed", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "default_branch": { + "name": "default_branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "projects_main_repo_path_idx": { + "name": "projects_main_repo_path_idx", + "columns": [ + "main_repo_path" + ], + "isUnique": false + }, + "projects_last_opened_at_idx": { + "name": "projects_last_opened_at_idx", + "columns": [ + "last_opened_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "settings": { + "name": "settings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "last_active_workspace_id": { + "name": "last_active_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_used_app": { + "name": "last_used_app", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_presets": { + "name": "terminal_presets", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_presets_initialized": { + "name": "terminal_presets_initialized", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "selected_ringtone_id": { + "name": "selected_ringtone_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "active_organization_id": { + "name": "active_organization_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "confirm_on_quit": { + "name": "confirm_on_quit", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_link_behavior": { + "name": "terminal_link_behavior", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "navigation_style": { + "name": "navigation_style", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tasks": { + "name": "tasks", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status_color": { + "name": "status_color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_type": { + "name": "status_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_position": { + "name": "status_position", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "repository_id": { + "name": "repository_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_id": { + "name": "assignee_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "creator_id": { + "name": "creator_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "estimate": { + "name": "estimate", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "due_date": { + "name": "due_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "labels": { + "name": "labels", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pr_url": { + "name": "pr_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_provider": { + "name": "external_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_key": { + "name": "external_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_url": { + "name": "external_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sync_error": { + "name": "sync_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "completed_at": { + "name": "completed_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "tasks_slug_unique": { + "name": "tasks_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "tasks_slug_idx": { + "name": "tasks_slug_idx", + "columns": [ + "slug" + ], + "isUnique": false + }, + "tasks_organization_id_idx": { + "name": "tasks_organization_id_idx", + "columns": [ + "organization_id" + ], + "isUnique": false + }, + "tasks_assignee_id_idx": { + "name": "tasks_assignee_id_idx", + "columns": [ + "assignee_id" + ], + "isUnique": false + }, + "tasks_status_idx": { + "name": "tasks_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "tasks_created_at_idx": { + "name": "tasks_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "tasks_organization_id_organizations_id_fk": { + "name": "tasks_organization_id_organizations_id_fk", + "tableFrom": "tasks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_assignee_id_users_id_fk": { + "name": "tasks_assignee_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "assignee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_creator_id_users_id_fk": { + "name": "tasks_creator_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "clerk_id": { + "name": "clerk_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "users_clerk_id_unique": { + "name": "users_clerk_id_unique", + "columns": [ + "clerk_id" + ], + "isUnique": true + }, + "users_email_unique": { + "name": "users_email_unique", + "columns": [ + "email" + ], + "isUnique": true + }, + "users_email_idx": { + "name": "users_email_idx", + "columns": [ + "email" + ], + "isUnique": false + }, + "users_clerk_id_idx": { + "name": "users_clerk_id_idx", + "columns": [ + "clerk_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "workspaces": { + "name": "workspaces", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "worktree_id": { + "name": "worktree_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tab_order": { + "name": "tab_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "workspaces_project_id_idx": { + "name": "workspaces_project_id_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "workspaces_worktree_id_idx": { + "name": "workspaces_worktree_id_idx", + "columns": [ + "worktree_id" + ], + "isUnique": false + }, + "workspaces_last_opened_at_idx": { + "name": "workspaces_last_opened_at_idx", + "columns": [ + "last_opened_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "workspaces_project_id_projects_id_fk": { + "name": "workspaces_project_id_projects_id_fk", + "tableFrom": "workspaces", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspaces_worktree_id_worktrees_id_fk": { + "name": "workspaces_worktree_id_worktrees_id_fk", + "tableFrom": "workspaces", + "tableTo": "worktrees", + "columnsFrom": [ + "worktree_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "worktrees": { + "name": "worktrees", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base_branch": { + "name": "base_branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "git_status": { + "name": "git_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "github_status": { + "name": "github_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "worktrees_project_id_idx": { + "name": "worktrees_project_id_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "worktrees_branch_idx": { + "name": "worktrees_branch_idx", + "columns": [ + "branch" + ], + "isUnique": false + } + }, + "foreignKeys": { + "worktrees_project_id_projects_id_fk": { + "name": "worktrees_project_id_projects_id_fk", + "tableFrom": "worktrees", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} diff --git a/packages/local-db/drizzle/meta/0007_snapshot.json b/packages/local-db/drizzle/meta/0007_snapshot.json new file mode 100644 index 00000000000..dbf24a697c3 --- /dev/null +++ b/packages/local-db/drizzle/meta/0007_snapshot.json @@ -0,0 +1,992 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "a7b8c9d0-e1f2-3456-7890-abcdef123456", + "prevId": "f1e2d3c4-b5a6-7890-abcd-ef1234567890", + "tables": { + "organization_members": { + "name": "organization_members", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "organization_members_organization_id_idx": { + "name": "organization_members_organization_id_idx", + "columns": [ + "organization_id" + ], + "isUnique": false + }, + "organization_members_user_id_idx": { + "name": "organization_members_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "organization_members_organization_id_organizations_id_fk": { + "name": "organization_members_organization_id_organizations_id_fk", + "tableFrom": "organization_members", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_members_user_id_users_id_fk": { + "name": "organization_members_user_id_users_id_fk", + "tableFrom": "organization_members", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "organizations": { + "name": "organizations", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "clerk_org_id": { + "name": "clerk_org_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "github_org": { + "name": "github_org", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "organizations_clerk_org_id_unique": { + "name": "organizations_clerk_org_id_unique", + "columns": [ + "clerk_org_id" + ], + "isUnique": true + }, + "organizations_slug_unique": { + "name": "organizations_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "organizations_slug_idx": { + "name": "organizations_slug_idx", + "columns": [ + "slug" + ], + "isUnique": false + }, + "organizations_clerk_org_id_idx": { + "name": "organizations_clerk_org_id_idx", + "columns": [ + "clerk_org_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "projects": { + "name": "projects", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "main_repo_path": { + "name": "main_repo_path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tab_order": { + "name": "tab_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "config_toast_dismissed": { + "name": "config_toast_dismissed", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "default_branch": { + "name": "default_branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "projects_main_repo_path_idx": { + "name": "projects_main_repo_path_idx", + "columns": [ + "main_repo_path" + ], + "isUnique": false + }, + "projects_last_opened_at_idx": { + "name": "projects_last_opened_at_idx", + "columns": [ + "last_opened_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "settings": { + "name": "settings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "last_active_workspace_id": { + "name": "last_active_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_used_app": { + "name": "last_used_app", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_presets": { + "name": "terminal_presets", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_presets_initialized": { + "name": "terminal_presets_initialized", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "selected_ringtone_id": { + "name": "selected_ringtone_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "active_organization_id": { + "name": "active_organization_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "confirm_on_quit": { + "name": "confirm_on_quit", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_link_behavior": { + "name": "terminal_link_behavior", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "navigation_style": { + "name": "navigation_style", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tasks": { + "name": "tasks", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status_color": { + "name": "status_color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_type": { + "name": "status_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status_position": { + "name": "status_position", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority": { + "name": "priority", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "repository_id": { + "name": "repository_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_id": { + "name": "assignee_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "creator_id": { + "name": "creator_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "estimate": { + "name": "estimate", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "due_date": { + "name": "due_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "labels": { + "name": "labels", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pr_url": { + "name": "pr_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_provider": { + "name": "external_provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_key": { + "name": "external_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_url": { + "name": "external_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sync_error": { + "name": "sync_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "completed_at": { + "name": "completed_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "tasks_slug_unique": { + "name": "tasks_slug_unique", + "columns": [ + "slug" + ], + "isUnique": true + }, + "tasks_slug_idx": { + "name": "tasks_slug_idx", + "columns": [ + "slug" + ], + "isUnique": false + }, + "tasks_organization_id_idx": { + "name": "tasks_organization_id_idx", + "columns": [ + "organization_id" + ], + "isUnique": false + }, + "tasks_assignee_id_idx": { + "name": "tasks_assignee_id_idx", + "columns": [ + "assignee_id" + ], + "isUnique": false + }, + "tasks_status_idx": { + "name": "tasks_status_idx", + "columns": [ + "status" + ], + "isUnique": false + }, + "tasks_created_at_idx": { + "name": "tasks_created_at_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "tasks_organization_id_organizations_id_fk": { + "name": "tasks_organization_id_organizations_id_fk", + "tableFrom": "tasks", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tasks_assignee_id_users_id_fk": { + "name": "tasks_assignee_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "assignee_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tasks_creator_id_users_id_fk": { + "name": "tasks_creator_id_users_id_fk", + "tableFrom": "tasks", + "tableTo": "users", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "clerk_id": { + "name": "clerk_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "users_clerk_id_unique": { + "name": "users_clerk_id_unique", + "columns": [ + "clerk_id" + ], + "isUnique": true + }, + "users_email_unique": { + "name": "users_email_unique", + "columns": [ + "email" + ], + "isUnique": true + }, + "users_email_idx": { + "name": "users_email_idx", + "columns": [ + "email" + ], + "isUnique": false + }, + "users_clerk_id_idx": { + "name": "users_clerk_id_idx", + "columns": [ + "clerk_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "workspaces": { + "name": "workspaces", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "worktree_id": { + "name": "worktree_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tab_order": { + "name": "tab_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "is_unread": { + "name": "is_unread", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": false + } + }, + "indexes": { + "workspaces_project_id_idx": { + "name": "workspaces_project_id_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "workspaces_worktree_id_idx": { + "name": "workspaces_worktree_id_idx", + "columns": [ + "worktree_id" + ], + "isUnique": false + }, + "workspaces_last_opened_at_idx": { + "name": "workspaces_last_opened_at_idx", + "columns": [ + "last_opened_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "workspaces_project_id_projects_id_fk": { + "name": "workspaces_project_id_projects_id_fk", + "tableFrom": "workspaces", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspaces_worktree_id_worktrees_id_fk": { + "name": "workspaces_worktree_id_worktrees_id_fk", + "tableFrom": "workspaces", + "tableTo": "worktrees", + "columnsFrom": [ + "worktree_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "worktrees": { + "name": "worktrees", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "branch": { + "name": "branch", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base_branch": { + "name": "base_branch", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "git_status": { + "name": "git_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "github_status": { + "name": "github_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "worktrees_project_id_idx": { + "name": "worktrees_project_id_idx", + "columns": [ + "project_id" + ], + "isUnique": false + }, + "worktrees_branch_idx": { + "name": "worktrees_branch_idx", + "columns": [ + "branch" + ], + "isUnique": false + } + }, + "foreignKeys": { + "worktrees_project_id_projects_id_fk": { + "name": "worktrees_project_id_projects_id_fk", + "tableFrom": "worktrees", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} diff --git a/packages/local-db/drizzle/meta/_journal.json b/packages/local-db/drizzle/meta/_journal.json index 3117a6e2266..c63757dc471 100644 --- a/packages/local-db/drizzle/meta/_journal.json +++ b/packages/local-db/drizzle/meta/_journal.json @@ -29,6 +29,34 @@ "when": 1766932805546, "tag": "0003_add_confirm_on_quit_setting", "breakpoints": true + }, + { + "idx": 4, + "version": "6", + "when": 1767166138761, + "tag": "0004_add_terminal_link_behavior_setting", + "breakpoints": true + }, + { + "idx": 5, + "version": "6", + "when": 1767166547886, + "tag": "0005_add_navigation_style", + "breakpoints": true + }, + { + "idx": 6, + "version": "6", + "when": 1767230000000, + "tag": "0006_add_unique_branch_workspace_index", + "breakpoints": true + }, + { + "idx": 7, + "version": "6", + "when": 1767350000000, + "tag": "0007_add_workspace_is_unread", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/local-db/src/schema/schema.ts b/packages/local-db/src/schema/schema.ts index 9b0639805f0..8c4daa138e6 100644 --- a/packages/local-db/src/schema/schema.ts +++ b/packages/local-db/src/schema/schema.ts @@ -5,6 +5,7 @@ import type { ExternalApp, GitHubStatus, GitStatus, + TerminalLinkBehavior, TerminalPreset, WorkspaceType, } from "./zod"; @@ -100,17 +101,29 @@ export const workspaces = sqliteTable( lastOpenedAt: integer("last_opened_at") .notNull() .$defaultFn(() => Date.now()), + isUnread: integer("is_unread", { mode: "boolean" }).default(false), }, (table) => [ index("workspaces_project_id_idx").on(table.projectId), index("workspaces_worktree_id_idx").on(table.worktreeId), index("workspaces_last_opened_at_idx").on(table.lastOpenedAt), + // NOTE: Migration 0006 creates an additional partial unique index: + // CREATE UNIQUE INDEX workspaces_unique_branch_per_project + // ON workspaces(project_id) WHERE type = 'branch' + // This enforces one branch workspace per project. Drizzle's schema DSL + // doesn't support partial/filtered indexes, so this constraint is only + // applied via the migration, not schema push. See migration 0006 for details. ], ); export type InsertWorkspace = typeof workspaces.$inferInsert; export type SelectWorkspace = typeof workspaces.$inferSelect; +/** + * Navigation style for workspace display + */ +export type NavigationStyle = "top-bar" | "sidebar"; + /** * Settings table - single row with typed columns */ @@ -127,6 +140,10 @@ export const settings = sqliteTable("settings", { selectedRingtoneId: text("selected_ringtone_id"), activeOrganizationId: text("active_organization_id"), confirmOnQuit: integer("confirm_on_quit", { mode: "boolean" }), + terminalLinkBehavior: text( + "terminal_link_behavior", + ).$type(), + navigationStyle: text("navigation_style").$type(), }); export type InsertSettings = typeof settings.$inferInsert; diff --git a/packages/local-db/src/schema/zod.ts b/packages/local-db/src/schema/zod.ts index bb33e1d1596..ca8221e405d 100644 --- a/packages/local-db/src/schema/zod.ts +++ b/packages/local-db/src/schema/zod.ts @@ -96,3 +96,13 @@ export const EXTERNAL_APPS = [ ] as const; export type ExternalApp = (typeof EXTERNAL_APPS)[number]; + +/** + * Terminal link behavior options + */ +export const TERMINAL_LINK_BEHAVIORS = [ + "external-editor", + "file-viewer", +] as const; + +export type TerminalLinkBehavior = (typeof TERMINAL_LINK_BEHAVIORS)[number];