v0.31.0 bf0756b

validation.go RawHistoryFolder

1package config
2
3import (
4	"fmt"
5	"math"
6	"net/url"
7	"os"
8	"path/filepath"
9	"sort"
10	"strings"
11
12	domainurl "github.com/bnema/dumber/internal/domain/url"
13	domainvalidation "github.com/bnema/dumber/internal/domain/validation"
14	"github.com/bnema/dumber/internal/domain/vimkeys"
15)
16
17const cefLogSeverityDisabled = 99
18
19// validateConfig performs comprehensive validation of configuration values
20func validateConfig(config *Config) error {
21	var validationErrors []string
22
23	validationErrors = append(validationErrors, validateHistory(config)...)
24	validationErrors = append(validationErrors, validateDmenu(config)...)
25	validationErrors = append(validationErrors, validateAppearance(config)...)
26	validationErrors = append(validationErrors, validateSearchEngine(config)...)
27	validationErrors = append(validationErrors, validatePopups(config)...)
28	validationErrors = append(validationErrors, validateExternalLinks(config)...)
29	validationErrors = append(validationErrors, validateWorkspaceStyling(config)...)
30	validationErrors = append(validationErrors, validatePaneMode(config)...)
31	validationErrors = append(validationErrors, validateTabBar(config)...)
32	validationErrors = append(validationErrors, validateTabMode(config)...)
33	validationErrors = append(validationErrors, validateVimMode(config)...)
34	validationErrors = append(validationErrors, validateFloatingPane(config)...)
35	validationErrors = append(validationErrors, validateLogging(config)...)
36	validationErrors = append(validationErrors, validateWorkspaceNewPaneURL(config)...)
37	validationErrors = append(validationErrors, validateOmnibox(config)...)
38	validationErrors = append(validationErrors, validateEngine(config)...)
39	validationErrors = append(validationErrors, validateRendering(config)...)
40	validationErrors = append(validationErrors, validatePrivacy(config)...)
41	validationErrors = append(validationErrors, validateColorScheme(config)...)
42	validationErrors = append(validationErrors, validateSession(config)...)
43	validationErrors = append(validationErrors, validatePerformanceProfile(config)...)
44	validationErrors = append(validationErrors, validateCEF(config)...)
45
46	// If there are validation errors, return them
47	if len(validationErrors) > 0 {
48		return fmt.Errorf("config validation failed:\n  - %s", strings.Join(validationErrors, "\n  - "))
49	}
50
51	return nil
52}
53
54func validateHistory(config *Config) []string {
55	var validationErrors []string
56	if config.History.MaxEntries < 0 {
57		validationErrors = append(validationErrors, "history.max_entries must be non-negative")
58	}
59	if config.History.RetentionPeriodDays < 0 {
60		validationErrors = append(validationErrors, "history.retention_period_days must be non-negative")
61	}
62	if config.History.CleanupIntervalDays < 0 {
63		validationErrors = append(validationErrors, "history.cleanup_interval_days must be non-negative")
64	}
65	return validationErrors
66}
67
68func validateDmenu(config *Config) []string {
69	if config.Dmenu.MaxHistoryDays < 0 {
70		return []string{"dmenu.max_history_days must be non-negative"}
71	}
72	return nil
73}
74
75func validateAppearance(config *Config) []string {
76	var validationErrors []string
77	if config.Appearance.DefaultFontSize < 1 || config.Appearance.DefaultFontSize > 72 {
78		validationErrors = append(validationErrors, "appearance.default_font_size must be between 1 and 72")
79	}
80	validationErrors = append(validationErrors, domainvalidation.ValidateFontFamily("appearance.sans_font", config.Appearance.SansFont)...)
81	validationErrors = append(validationErrors, domainvalidation.ValidateFontFamily("appearance.serif_font", config.Appearance.SerifFont)...)
82	validationErrors = append(validationErrors, domainvalidation.ValidateFontFamily("appearance.gtk_font", config.Appearance.GtkFont)...)
83	validationErrors = append(
84		validationErrors,
85		domainvalidation.ValidateFontFamily("appearance.monospace_font", config.Appearance.MonospaceFont)...,
86	)
87	validationErrors = append(validationErrors, domainvalidation.ValidatePaletteHex(
88		"appearance.light_palette",
89		config.Appearance.LightPalette.Background,
90		config.Appearance.LightPalette.Surface,
91		config.Appearance.LightPalette.SurfaceVariant,
92		config.Appearance.LightPalette.Text,
93		config.Appearance.LightPalette.Muted,
94		config.Appearance.LightPalette.Accent,
95		config.Appearance.LightPalette.Border,
96	)...)
97	validationErrors = append(validationErrors, domainvalidation.ValidatePaletteHex(
98		"appearance.dark_palette",
99		config.Appearance.DarkPalette.Background,
100		config.Appearance.DarkPalette.Surface,
101		config.Appearance.DarkPalette.SurfaceVariant,
102		config.Appearance.DarkPalette.Text,
103		config.Appearance.DarkPalette.Muted,
104		config.Appearance.DarkPalette.Accent,
105		config.Appearance.DarkPalette.Border,
106	)...)
107	if config.DefaultWebpageZoom < 0.1 || config.DefaultWebpageZoom > 5.0 {
108		validationErrors = append(validationErrors, "default_webpage_zoom must be between 0.1 and 5.0")
109	}
110	if config.DefaultUIScale < 0.5 || config.DefaultUIScale > 3.0 {
111		validationErrors = append(validationErrors, "default_ui_scale must be between 0.5 and 3.0")
112	}
113	if config.SidebarWidth != 0 && (config.SidebarWidth < 280 || config.SidebarWidth > 380) {
114		validationErrors = append(validationErrors, "sidebar_width must be between 280 and 380, or 0 for default")
115	}
116	validationErrors = append(validationErrors, validateExternalTheme(config)...)
117	return validationErrors
118}
119
120func validateExternalTheme(config *Config) []string {
121	externalTheme := config.Appearance.ExternalTheme
122	if !externalTheme.Enabled {
123		return nil
124	}
125
126	var validationErrors []string
127	if externalTheme.Provider != defaultExternalThemeProvider {
128		validationErrors = append(validationErrors, "appearance.external_theme.provider must be one of: noctalia")
129	}
130	if !isSupportedExternalThemeFormat(externalTheme.Format) {
131		validationErrors = append(validationErrors, "appearance.external_theme.format must be one of: colors-json, dumber-json")
132	}
133	if strings.TrimSpace(externalTheme.Path) == "" {
134		validationErrors = append(validationErrors, "appearance.external_theme.path is required when external_theme is enabled")
135	}
136	return validationErrors
137}
138
139func isSupportedExternalThemeFormat(format string) bool {
140	switch format {
141	case defaultExternalThemeFormat, defaultExternalThemeTemplateFormat:
142		return true
143	default:
144		return false
145	}
146}
147
148func validateSearchEngine(config *Config) []string {
149	if config.DefaultSearchEngine == "" {
150		return []string{"default_search_engine cannot be empty"}
151	}
152	if !strings.Contains(config.DefaultSearchEngine, "%s") {
153		return []string{"default_search_engine must contain %s placeholder for the search query"}
154	}
155	return nil
156}
157
158func validatePopups(config *Config) []string {
159	var validationErrors []string
160	// Validate against BrowsingContexts (canonical field).
161	// Popups is a runtime alias synced during normalization.
162	switch config.Workspace.BrowsingContexts.Behavior {
163	case PopupBehaviorSplit, PopupBehaviorStacked, PopupBehaviorTabbed, PopupBehaviorWindowed:
164	default:
165		validationErrors = append(validationErrors, fmt.Sprintf(
166			"workspace.browsing_contexts.behavior must be one of: split, stacked, tabbed, windowed (got: %s)",
167			config.Workspace.BrowsingContexts.Behavior,
168		))
169	}
170
171	if config.Workspace.BrowsingContexts.Behavior == PopupBehaviorSplit {
172		switch config.Workspace.BrowsingContexts.Placement {
173		case "right", "left", "top", "bottom":
174		default:
175			validationErrors = append(validationErrors, fmt.Sprintf(
176				"workspace.browsing_contexts.placement must be one of: right, left, top, bottom (got: %s)",
177				config.Workspace.BrowsingContexts.Placement,
178			))
179		}
180	}
181
182	switch config.Workspace.BrowsingContexts.BlankTargetBehavior {
183	case "split", "stacked", "tabbed":
184	default:
185		validationErrors = append(validationErrors, fmt.Sprintf(
186			"workspace.browsing_contexts.blank_target_behavior must be one of: split, stacked, tabbed (got: %s)",
187			config.Workspace.BrowsingContexts.BlankTargetBehavior,
188		))
189	}
190	return validationErrors
191}
192
193func validateExternalLinks(config *Config) []string {
194	var validationErrors []string
195	switch config.Workspace.ExternalLinks.Behavior {
196	case ExternalLinkBehaviorWindowed, ExternalLinkBehaviorTabbed, ExternalLinkBehaviorSplit, ExternalLinkBehaviorStacked:
197	default:
198		validationErrors = append(validationErrors, fmt.Sprintf(
199			"workspace.external_links.behavior must be one of: windowed, tabbed, split, stacked (got: %s)",
200			config.Workspace.ExternalLinks.Behavior,
201		))
202	}
203
204	switch config.Workspace.ExternalLinks.Placement {
205	case ExternalLinkPlacementRight, ExternalLinkPlacementLeft, ExternalLinkPlacementTop, ExternalLinkPlacementBottom:
206	default:
207		validationErrors = append(validationErrors, fmt.Sprintf(
208			"workspace.external_links.placement must be one of: right, left, top, bottom (got: %s)",
209			config.Workspace.ExternalLinks.Placement,
210		))
211	}
212	return validationErrors
213}
214
215func validateWorkspaceStyling(config *Config) []string {
216	var validationErrors []string
217	if config.Workspace.Styling.BorderWidth < 0 {
218		validationErrors = append(validationErrors, "workspace.styling.border_width must be non-negative")
219	}
220	if config.Workspace.Styling.ModeBorderWidth < 0 {
221		validationErrors = append(validationErrors, "workspace.styling.mode_border_width must be non-negative")
222	}
223	if config.Workspace.Styling.TransitionDuration < 0 {
224		validationErrors = append(validationErrors, "workspace.styling.transition_duration must be non-negative")
225	}
226	return validationErrors
227}
228
229func validatePaneMode(config *Config) []string {
230	return validateModalModeActions("pane_mode", config.Workspace.PaneMode.TimeoutMilliseconds, config.Workspace.PaneMode.Actions)
231}
232
233func validateTabBar(config *Config) []string {
234	switch config.Workspace.TabBarPosition {
235	case "top", "bottom":
236		return nil
237	default:
238		return []string{fmt.Sprintf("workspace.tab_bar_position must be 'top' or 'bottom' (got: %s)", config.Workspace.TabBarPosition)}
239	}
240}
241
242func validateTabMode(config *Config) []string {
243	return validateModalModeActions("tab_mode", config.Workspace.TabMode.TimeoutMilliseconds, config.Workspace.TabMode.Actions)
244}
245
246func validateVimMode(config *Config) []string {
247	var validationErrors []string
248	if config.Workspace.VimMode.SequenceTimeoutMilliseconds < 0 {
249		validationErrors = append(validationErrors, "workspace.vim_mode.sequence_timeout_ms must be non-negative")
250	}
251	validationErrors = append(validationErrors, validateModalModeActionsWithKeyCanon(
252		"vim_mode",
253		config.Workspace.VimMode.TimeoutMilliseconds,
254		config.Workspace.VimMode.Actions,
255		canonicalizeVimModeSequenceKey,
256	)...)
257	return validationErrors
258}
259
260// validateModalModeActions shared timeout/empty-actions/duplicate-key checks for
261// pane, tab, and page modal modes. Messages stay path-exact via modePath.
262func validateModalModeActions(modePath string, timeoutMS int, actions map[string]ActionBinding) []string {
263	return validateModalModeActionsWithKeyCanon(modePath, timeoutMS, actions, nil)
264}
265
266func validateModalModeActionsWithKeyCanon(
267	modePath string,
268	timeoutMS int,
269	actions map[string]ActionBinding,
270	keyCanon func(string) (string, error),
271) []string {
272	var validationErrors []string
273	if timeoutMS < 0 {
274		validationErrors = append(validationErrors, fmt.Sprintf("workspace.%s.timeout_ms must be non-negative", modePath))
275	}
276	if len(actions) == 0 {
277		validationErrors = append(validationErrors, fmt.Sprintf("workspace.%s.actions cannot be empty", modePath))
278	}
279
280	if keyCanon == nil {
281		keyCanon = func(key string) (string, error) { return key, nil }
282	}
283
284	actionNames := make([]string, 0, len(actions))
285	for action := range actions {
286		actionNames = append(actionNames, action)
287	}
288	sort.Strings(actionNames)
289
290	seenSequence := make(map[string]string)
291	for _, action := range actionNames {
292		binding := actions[action]
293		if len(binding.Keys) == 0 {
294			validationErrors = append(validationErrors, fmt.Sprintf("workspace.%s.actions.%s must have at least one key binding", modePath, action))
295			continue
296		}
297		keys := append([]string(nil), binding.Keys...)
298		sort.Strings(keys)
299		for _, key := range keys {
300			canonical, err := keyCanon(key)
301			if err != nil {
302				validationErrors = append(validationErrors, fmt.Sprintf(
303					"workspace.%s.actions.%s has invalid key binding '%s': %v",
304					modePath,
305					action,
306					key,
307					err,
308				))
309				continue
310			}
311			if modePath == "vim_mode" {
312				sequence, parseErr := vimkeys.ParseBinding(canonical)
313				if parseErr == nil {
314					if len(sequence) > 0 && isVimCountStartKey(sequence[0]) {
315						validationErrors = append(validationErrors, fmt.Sprintf(
316							"workspace.%s.actions.%s cannot start with a count digit (1-9): '%s'",
317							modePath,
318							action,
319							canonical,
320						))
321					}
322					legacyExit := action == "confirm" || action == "cancel"
323					if !legacyExit {
324						for _, key := range sequence {
325							if key.Mods == 0 && (key.Sym == "CR" || key.Sym == "Esc") {
326								validationErrors = append(validationErrors, fmt.Sprintf(
327									"workspace.%s.actions.%s cannot bind Enter or Escape outside the modal fallback actions",
328									modePath,
329									action,
330								))
331								break
332							}
333						}
334					}
335				}
336			}
337			if existingAction, exists := seenSequence[canonical]; exists {
338				validationErrors = append(validationErrors, fmt.Sprintf(
339					"duplicate key binding '%s' found in %s actions '%s' and '%s'",
340					canonical,
341					modePath,
342					existingAction,
343					action,
344				))
345			}
346			seenSequence[canonical] = action
347		}
348	}
349	return validationErrors
350}
351
352func isVimCountStartKey(key vimkeys.Key) bool {
353	return key.Mods == 0 && len(key.Sym) == 1 && key.Sym[0] >= '1' && key.Sym[0] <= '9'
354}
355
356func canonicalizeVimModeBinding(key string) string {
357	switch strings.ToLower(strings.TrimSpace(key)) {
358	case "enter":
359		return "<Return>"
360	case "escape":
361		return "<Escape>"
362	default:
363		return key
364	}
365}
366
367func canonicalizeVimModeSequenceKey(key string) (string, error) {
368	seq, err := vimkeys.ParseBinding(canonicalizeVimModeBinding(key))
369	if err != nil {
370		return "", err
371	}
372	return seq.String(), nil
373}
374
375func validateFloatingPane(config *Config) []string {
376	var validationErrors []string
377	seenProfileKeys := make(map[string]string)
378
379	if config.Workspace.FloatingPane.WidthPct <= 0 || config.Workspace.FloatingPane.WidthPct > 1 {
380		validationErrors = append(validationErrors, "workspace.floating_pane.width_pct must be in (0,1]")
381	}
382
383	if config.Workspace.FloatingPane.HeightPct <= 0 || config.Workspace.FloatingPane.HeightPct > 1 {
384		validationErrors = append(validationErrors, "workspace.floating_pane.height_pct must be in (0,1]")
385	}
386
387	profileNames := make([]string, 0, len(config.Workspace.FloatingPane.Profiles))
388	for profileName := range config.Workspace.FloatingPane.Profiles {
389		profileNames = append(profileNames, profileName)
390	}
391	sort.Strings(profileNames)
392
393	for _, profileName := range profileNames {
394		profile := config.Workspace.FloatingPane.Profiles[profileName]
395		if strings.TrimSpace(profile.URL) == "" {
396			validationErrors = append(validationErrors, fmt.Sprintf(
397				"workspace.floating_pane.profiles.%s.url is required",
398				profileName,
399			))
400		} else {
401			validationErrors = append(validationErrors, validateWorkspaceURLValue(
402				fmt.Sprintf("workspace.floating_pane.profiles.%s.url", profileName),
403				profile.URL,
404			)...)
405		}
406		if len(profile.Keys) == 0 {
407			validationErrors = append(validationErrors, fmt.Sprintf(
408				"workspace.floating_pane.profiles.%s.keys must have at least one entry",
409				profileName,
410			))
411		}
412
413		for _, key := range profile.Keys {
414			normalizedKey := normalizeBindingKeyString(key)
415			if normalizedKey == "" {
416				validationErrors = append(validationErrors, fmt.Sprintf(
417					"workspace.floating_pane.profiles.%s.keys contains empty or whitespace-only key binding %q",
418					profileName,
419					key,
420				))
421				continue
422			}
423
424			if existingProfile, exists := seenProfileKeys[normalizedKey]; exists {
425				validationErrors = append(validationErrors, fmt.Sprintf(
426					"workspace.floating_pane.profiles.%s.keys contains duplicate key binding %q already used by profile %q",
427					profileName,
428					key,
429					existingProfile,
430				))
431				continue
432			}
433
434			seenProfileKeys[normalizedKey] = profileName
435		}
436	}
437
438	return validationErrors
439}
440
441func normalizeBindingKeyString(key string) string {
442	normalized := strings.ToLower(strings.TrimSpace(key))
443	if normalized == "" {
444		return ""
445	}
446	return strings.Join(strings.Fields(normalized), "")
447}
448
449func validateLogging(config *Config) []string {
450	var validationErrors []string
451	if config.Logging.MaxAge < 0 {
452		validationErrors = append(validationErrors, "logging.max_age must be non-negative")
453	}
454	if config.Logging.MaxFiles < 0 {
455		validationErrors = append(validationErrors, "logging.max_files must be non-negative")
456	}
457	switch config.Logging.Level {
458	case "trace", "debug", "info", "warn", "error", "fatal", "":
459	default:
460		validationErrors = append(validationErrors, fmt.Sprintf(
461			"logging.level must be one of: trace, debug, info, warn, error, fatal (got: %s)",
462			config.Logging.Level,
463		))
464	}
465	switch config.Logging.Format {
466	case "text", "json", "console", "":
467	default:
468		validationErrors = append(validationErrors, fmt.Sprintf(
469			"logging.format must be one of: text, json, console (got: %s)",
470			config.Logging.Format,
471		))
472	}
473	return validationErrors
474}
475
476func validateCEF(config *Config) []string {
477	var validationErrors []string
478
479	switch config.Engine.CEF.CEFRenderStack() {
480	case CEFRenderStackVulkan, CEFRenderStackEGL:
481	default:
482		validationErrors = append(validationErrors, fmt.Sprintf(
483			"engine.cef.render_stack must be one of: vulkan, egl (got: %s)",
484			config.Engine.CEF.RenderStack,
485		))
486	}
487
488	switch config.Engine.CEF.LogSeverity {
489	case 0, 1, 2, 3, 4, cefLogSeverityDisabled:
490	default:
491		validationErrors = append(validationErrors, fmt.Sprintf(
492			"engine.cef.log_severity must be one of: 0, 1, 2, 3, 4, %d (got: %d)",
493			cefLogSeverityDisabled,
494			config.Engine.CEF.LogSeverity,
495		))
496	}
497
498	if config.Engine.CEF.WindowlessFrameRate < 0 {
499		validationErrors = append(validationErrors, "engine.cef.windowless_frame_rate must be >= 0")
500	}
501	if config.Engine.CEF.WindowlessFrameRateMax < 0 {
502		validationErrors = append(validationErrors, "engine.cef.windowless_frame_rate_max must be >= 0")
503	}
504
505	input := config.Engine.CEF.Input
506	if invalidPositiveFloat(input.ScrollWheelMultiplier) {
507		validationErrors = append(validationErrors, "engine.cef.input.scroll_wheel_multiplier must be > 0")
508	}
509	if invalidPositiveFloat(input.ScrollPreciseMultiplier) {
510		validationErrors = append(validationErrors, "engine.cef.input.scroll_precise_multiplier must be > 0")
511	}
512	if invalidPositiveFloat(input.ScrollHorizontalMultiplier) {
513		validationErrors = append(validationErrors, "engine.cef.input.scroll_horizontal_multiplier must be > 0")
514	}
515	if invalidPositiveFloat(input.ScrollVerticalMultiplier) {
516		validationErrors = append(validationErrors, "engine.cef.input.scroll_vertical_multiplier must be > 0")
517	}
518	if input.ScrollMaxDelta < 0 {
519		validationErrors = append(validationErrors, "engine.cef.input.scroll_max_delta must be >= 0")
520	}
521	if invalidPositiveFloat(input.TouchpadNavigationMinDelta) {
522		validationErrors = append(validationErrors, "engine.cef.input.touchpad_navigation_min_delta must be > 0")
523	}
524	if invalidPositiveFloat(input.TouchpadNavigationMaxVerticalRatio) {
525		validationErrors = append(validationErrors, "engine.cef.input.touchpad_navigation_max_vertical_ratio must be > 0")
526	}
527
528	return validationErrors
529}
530
531func invalidPositiveFloat(value float64) bool {
532	return value <= 0 || math.IsNaN(value) || math.IsInf(value, 0)
533}
534
535func validateWorkspaceNewPaneURL(config *Config) []string {
536	var validationErrors []string
537
538	if config.Workspace.NewPaneURL == "" {
539		validationErrors = append(validationErrors, "workspace.new_pane_url cannot be empty")
540		return validationErrors
541	}
542
543	validationErrors = append(validationErrors, validateWorkspaceURLValue(
544		"workspace.new_pane_url",
545		config.Workspace.NewPaneURL,
546	)...)
547
548	return validationErrors
549}
550
551func validateWorkspaceURLValue(fieldPath, value string) []string {
552	trimmed := strings.TrimSpace(value)
553	if isRelativeWorkspacePath(trimmed) {
554		return []string{fmt.Sprintf(
555			"%s relative local path cannot be resolved without config file context (got: %s)",
556			fieldPath,
557			value,
558		)}
559	}
560	if isLocalPathLikeWorkspaceURL(trimmed) {
561		if isExistingWorkspacePath(trimmed) {
562			return nil
563		}
564		return []string{fmt.Sprintf("%s local path must exist (got: %s)", fieldPath, value)}
565	}
566	candidate := trimmed
567	parsed, err := url.Parse(candidate)
568	if err != nil || parsed.Scheme == "" {
569		candidate = domainurl.Normalize(trimmed)
570		parsed, err = url.Parse(candidate)
571	}
572	if err != nil {
573		return []string{fmt.Sprintf("%s must be a valid URL (got: %s)", fieldPath, value)}
574	}
575
576	switch parsed.Scheme {
577	case "http", "https", "dumb", "file", "about":
578		return nil
579	default:
580		return []string{fmt.Sprintf(
581			"%s must use one of: http, https, dumb, file, about (got: %s)",
582			fieldPath,
583			parsed.Scheme,
584		)}
585	}
586}
587
588func isLocalPathLikeWorkspaceURL(value string) bool {
589	return strings.HasPrefix(value, "/") ||
590		strings.HasPrefix(value, "./") ||
591		strings.HasPrefix(value, "../") ||
592		strings.HasPrefix(value, "~/")
593}
594
595func isExistingWorkspacePath(value string) bool {
596	if value == "" || strings.Contains(value, "://") {
597		return false
598	}
599	candidate := value
600	if strings.HasPrefix(candidate, "~/") {
601		homeDir, err := os.UserHomeDir()
602		if err != nil || homeDir == "" {
603			return false
604		}
605		candidate = filepath.Join(homeDir, strings.TrimPrefix(candidate, "~/"))
606	}
607	absPath, err := filepath.Abs(candidate)
608	if err != nil {
609		return false
610	}
611	_, err = os.Stat(absPath)
612	return err == nil
613}
614
615func isRelativeWorkspacePath(value string) bool {
616	if value == "" || filepath.IsAbs(value) || strings.HasPrefix(value, "~/") ||
617		strings.Contains(value, "://") {
618		return false
619	}
620	if strings.HasPrefix(value, "./") || strings.HasPrefix(value, "../") ||
621		looksLikeBareRelativeWorkspacePath(value) {
622		return true
623	}
624	return !domainurl.LooksLikeURL(value) && !strings.Contains(value, ":")
625}
626
627func looksLikeBareRelativeWorkspacePath(value string) bool {
628	if strings.ContainsAny(value, `/\`) {
629		firstSegment, _, _ := strings.Cut(strings.ReplaceAll(value, `\`, "/"), "/")
630		return firstSegment == "" || (!strings.Contains(firstSegment, ".") &&
631			firstSegment != "localhost" && !strings.HasPrefix(firstSegment, "localhost:"))
632	}
633
634	switch strings.ToLower(filepath.Ext(value)) {
635	case ".css", ".gif", ".htm", ".html", ".jpeg", ".jpg", ".js", ".json",
636		".md", ".pdf", ".png", ".svg", ".toml", ".txt", ".webp", ".xml",
637		".yaml", ".yml":
638		return true
639	default:
640		return false
641	}
642}
643
644func validateOmnibox(config *Config) []string {
645	var validationErrors []string
646	if config.Omnibox.MostVisitedDays < 0 {
647		validationErrors = append(validationErrors, "omnibox.most_visited_days must be non-negative")
648	}
649	switch config.Omnibox.InitialBehavior {
650	case OmniboxInitialBehaviorRecent, OmniboxInitialBehaviorMostVisited, OmniboxInitialBehaviorNone:
651	default:
652		validationErrors = append(validationErrors, fmt.Sprintf(
653			"omnibox.initial_behavior must be one of: %s, %s, %s (got: %s)",
654			OmniboxInitialBehaviorRecent,
655			OmniboxInitialBehaviorMostVisited,
656			OmniboxInitialBehaviorNone,
657			config.Omnibox.InitialBehavior,
658		))
659	}
660	return validationErrors
661}
662
663func validateEngine(config *Config) []string {
664	switch config.Engine.Type {
665	case EngineTypeCEF, EngineTypeWebKit:
666		return nil
667	default:
668		return []string{fmt.Sprintf(
669			"engine.type must be one of: cef, webkit (got: %s)",
670			config.Engine.Type,
671		)}
672	}
673}
674
675func validateRendering(config *Config) []string {
676	var validationErrors []string
677
678	switch config.Engine.WebKit.GSKRenderer {
679	case GSKRendererAuto, GSKRendererOpenGL, GSKRendererVulkan, GSKRendererCairo, "":
680	default:
681		validationErrors = append(
682			validationErrors,
683			fmt.Sprintf(
684				"engine.webkit.gsk_renderer must be one of: auto, opengl, vulkan, cairo (got: %s)",
685				config.Engine.WebKit.GSKRenderer,
686			),
687		)
688	}
689
690	switch config.Engine.WebKit.GLRenderingMode {
691	case GLRenderingModeAuto, GLRenderingModeGLES2, GLRenderingModeGL3, GLRenderingModeNone, "":
692	default:
693		validationErrors = append(
694			validationErrors,
695			fmt.Sprintf(
696				"engine.webkit.gl_rendering_mode must be one of: auto, gles2, gl3, none (got: %s)",
697				config.Engine.WebKit.GLRenderingMode,
698			),
699		)
700	}
701
702	if config.Engine.WebKit.GStreamerDebugLevel < 0 || config.Engine.WebKit.GStreamerDebugLevel > 5 {
703		validationErrors = append(validationErrors, fmt.Sprintf(
704			"engine.webkit.gstreamer_debug_level must be between 0 and 5 (got: %d)",
705			config.Engine.WebKit.GStreamerDebugLevel,
706		))
707	}
708
709	if config.Engine.WebKit.ForceCompositingMode && config.Engine.WebKit.DisableCompositingMode {
710		validationErrors = append(validationErrors,
711			"engine.webkit.force_compositing_mode and engine.webkit.disable_compositing_mode cannot both be true",
712		)
713	}
714
715	return validationErrors
716}
717
718func validatePrivacy(config *Config) []string {
719	switch config.Engine.CookiePolicy {
720	case CookiePolicyAlways, CookiePolicyNoThirdParty, CookiePolicyNever, "":
721		return nil
722	default:
723		return []string{fmt.Sprintf(
724			"engine.cookie_policy must be one of: always, no_third_party, never (got: %s)",
725			config.Engine.CookiePolicy,
726		)}
727	}
728}
729
730func validateColorScheme(config *Config) []string {
731	switch config.Appearance.ColorScheme {
732	case ThemePreferDark, ThemePreferLight, ThemeDefault, "":
733		return nil
734	default:
735		return []string{fmt.Sprintf(
736			"appearance.color_scheme must be one of: prefer-dark, prefer-light, default (got: %s)",
737			config.Appearance.ColorScheme,
738		)}
739	}
740}
741
742func validateSession(config *Config) []string {
743	var validationErrors []string
744	if config.Session.MaxExitedSessions < 0 {
745		validationErrors = append(validationErrors, "session.max_exited_sessions must be non-negative")
746	}
747	if config.Session.MaxExitedSessionAgeDays < 0 {
748		validationErrors = append(validationErrors, "session.max_exited_session_age_days must be non-negative")
749	}
750	if config.Session.SnapshotIntervalMs < 0 {
751		validationErrors = append(validationErrors, "session.snapshot_interval_ms must be non-negative")
752	}
753	return validationErrors
754}
755
756func validatePerformanceProfile(config *Config) []string {
757	var validationErrors []string
758
759	// Performance profiles and webkit-specific tuning only apply to the webkit engine.
760	engineType := config.Engine.ResolveEngineType()
761	if engineType != "webkit" {
762		return nil
763	}
764
765	// Validate profile name
766	if !IsValidPerformanceProfile(config.Engine.Profile) {
767		validationErrors = append(validationErrors, fmt.Sprintf(
768			"engine.profile must be one of: default, lite, balanced, max, custom (got: %s)",
769			config.Engine.Profile,
770		))
771	}
772
773	// When profile is not "custom", warn if individual fields are set
774	// (they will be ignored in favor of profile-computed values)
775	if config.Engine.Profile != ProfileCustom && config.Engine.Profile != "" {
776		perfCfg := PerformanceConfigFromEngine(&config.Engine)
777		if HasCustomPerformanceFields(&perfCfg) {
778			validationErrors = append(validationErrors,
779				"engine performance tuning fields (skia_*, *_memory_*) are ignored when profile is not 'custom'; "+
780					"set profile = \"custom\" to use individual field values",
781			)
782		}
783	}
784
785	// Validate memory pressure threshold ordering: WebKit requires conservative < strict
786	webCons := config.Engine.WebKit.WebProcessMemoryConservativeThreshold
787	webStrict := config.Engine.WebKit.WebProcessMemoryStrictThreshold
788	if webCons > 0 && webStrict > 0 && webCons >= webStrict {
789		validationErrors = append(validationErrors,
790			"engine.webkit.web_process_memory_conservative_threshold must be less than "+
791				"web_process_memory_strict_threshold when both are set",
792		)
793	}
794
795	netCons := config.Engine.WebKit.NetworkProcessMemoryConservativeThreshold
796	netStrict := config.Engine.WebKit.NetworkProcessMemoryStrictThreshold
797	if netCons > 0 && netStrict > 0 && netCons >= netStrict {
798		validationErrors = append(validationErrors,
799			"engine.webkit.network_process_memory_conservative_threshold must be less than "+
800				"network_process_memory_strict_threshold when both are set",
801		)
802	}
803
804	return validationErrors
805}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close