Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

4.6 KB
Raw Blame
import { projectSectionId } from './project-settings-targets'
import type { ProjectIcon } from '@shared/project-icon'

export type SettingsSectionId =
  | 'terminal'
  | 'shell'
  | 'behavior'
  | 'appearance'
  | 'notch'
  | 'phone'
  | 'speech'
  | 'shortcuts'
  | 'agents'
  | 'usage'
  | 'accounts'
  | 'custom-agents'
  | 'model-gateway'
  | 'notifications'
  | 'commit'
  | 'tmux'
  | 'github-issues'
  | 'license'
  | 'presence'
  | 'remote'
  | 'team-access'
  | 'ssh'
  | 'updates'
  | 'privacy'
  | 'sign-in'
  | 'debug'
  | `project-${string}`

export interface ProjectNavItem {
  id: string
  name: string
  color: string
  icon?: ProjectIcon
}

export interface SettingsSectionRef {
  id: SettingsSectionId
  title: string
  /** Only meaningful on macOS (the notch capsule) — hidden elsewhere by `visibleSettingsGroups`. */
  macOnly?: boolean
  /** Only meaningful in a browser tab (the Server Edition's sign-in session) — hidden under Electron. */
  browserOnly?: boolean
  /** Project-section rows only (`project-${string}` ids): the project's own color/icon, so the
   *  sidebar can render its `ProjectGlyph` beside the title instead of the generic folder glyph
   *  every project section used to share. Absent on every static section. */
  color?: string
  icon?: ProjectIcon
}

export interface SettingsGroup {
  id: string
  title: string
  sections: SettingsSectionRef[]
}

// Grouped by what the user is DOING, not by where the code lives: AI work first (it is what
// the app is for), then the workspace around it, then connectivity, then app housekeeping.
export const SETTINGS_GROUPS: SettingsGroup[] = [
  {
    id: 'ai',
    title: 'AI capabilities',
    sections: [
      { id: 'agents', title: 'Agents' },
      { id: 'accounts', title: 'Accounts' },
      { id: 'custom-agents', title: 'Custom agents' },
      { id: 'model-gateway', title: 'Model gateway' },
      { id: 'usage', title: 'Usage' },
      { id: 'commit', title: 'Commit messages' }
    ]
  },
  {
    id: 'workspace',
    title: 'Workspace',
    sections: [
      { id: 'terminal', title: 'Terminal' },
      { id: 'shell', title: 'Shell' },
      { id: 'tmux', title: 'Session protection' },
      { id: 'github-issues', title: 'GitHub Issues' },
      { id: 'behavior', title: 'Behavior' }
    ]
  },
  {
    id: 'interface',
    title: 'Interface',
    sections: [
      { id: 'appearance', title: 'Appearance' },
      { id: 'notch', title: 'Notch', macOnly: true },
      { id: 'notifications', title: 'Notifications' },
      { id: 'speech', title: 'Speech' },
      { id: 'shortcuts', title: 'Keyboard Shortcuts' }
    ]
  },
  {
    id: 'connectivity',
    title: 'Remote & team',
    sections: [
      { id: 'presence', title: 'Your name' },
      { id: 'phone', title: 'Phone' },
      { id: 'remote', title: 'Remote access' },
      { id: 'team-access', title: 'Team seats' },
      { id: 'ssh', title: 'Remote (SSH)' }
    ]
  },
  {
    id: 'application',
    title: 'Application',
    sections: [
      { id: 'license', title: 'License' },
      { id: 'updates', title: 'Updates' },
      { id: 'privacy', title: 'Privacy' },
      { id: 'sign-in', title: 'Sign-in', browserOnly: true },
      { id: 'debug', title: 'Debug' }
    ]
  }
]

export const FIRST_SECTION_ID: SettingsSectionId = 'agents'

export function allSectionIds(): SettingsSectionId[] {
  return SETTINGS_GROUPS.flatMap((g) => g.sections.map((s) => s.id))
}

/**
 * The groups as the sidebar should render them for this platform: a mac-only section is dropped
 * entirely off macOS, a browser-only one under Electron (an empty group would be dropped too,
 * though none exists today). Pure — the caller passes the platform so this stays testable.
 */
export function visibleSettingsGroups(isMac: boolean, isBrowser = false): SettingsGroup[] {
  return SETTINGS_GROUPS.map((g) => ({
    ...g,
    sections: g.sections.filter((s) => (isMac || !s.macOnly) && (isBrowser || !s.browserOnly))
  })).filter((g) => g.sections.length > 0)
}

/**
 * Render-time only — deliberately NOT part of `SETTINGS_GROUPS`. Open projects change at
 * runtime, so this builds a group from the current project list on every render instead of
 * baking project ids into the static nav (which would break the `nav.test.ts` section-count
 * pins). Returns null when there are no open projects, so callers can skip rendering the group.
 */
export function projectsSettingsGroup(projects: ProjectNavItem[]): SettingsGroup | null {
  if (projects.length === 0) return null
  return {
    id: 'projects',
    title: 'Projects',
    sections: projects.map((p) => ({
      id: projectSectionId(p.id),
      title: p.name,
      color: p.color,
      icon: p.icon
    }))
  }
}