返回 DeepSeek-Reasonix
browser.go
根目录 / internal / config / browser.go
1 package config
2
3 import (
4 "fmt"
5 "strings"
6 )
7
8 // BrowserConfig attaches a browser to sessions that have no Electron shell
9 // behind them (CLI, Serve, headless). It stays off by default because
10 // attaching means driving or launching a real Chrome; the desktop keeps its
11 // own built-in browser and ignores this section. Endpoint attaches to a
12 // running Chrome started with --remote-debugging-port, and an empty Endpoint
13 // launches one Reasonix owns and kills with the session. Either way the
14 // browser is not touched until a browser tool is actually called.
15 type BrowserConfig struct {
16 Enabled bool `toml:"enabled"`
17 Endpoint string `toml:"endpoint"`
18 // AllowRemoteEndpoint permits a non-loopback endpoint. A DevTools endpoint
19 // grants full control of the browser and of every file it can read.
20 AllowRemoteEndpoint bool `toml:"allow_remote_endpoint"`
21 ChromePath string `toml:"chrome_path"`
22 ChromeArgs []string `toml:"chrome_args"`
23 // UserDataDir is the launched browser's profile. Empty uses a throwaway
24 // directory, so logins never outlive the session.
25 UserDataDir string `toml:"user_data_dir"`
26 Headless bool `toml:"headless"`
27 }
28
29 // renderBrowserConfig writes the [browser] table. Only values that differ from
30 // the defaults reach here, so the section stays absent for the common case of
31 // a session with no browser.
32 func renderBrowserConfig(b *strings.Builder, cfg BrowserConfig) {
33 b.WriteString("[browser]\n")
34 fmt.Fprintf(b, "enabled = %v # browser tools for CLI/Serve sessions; the browser attaches on first use\n", cfg.Enabled)
35 if cfg.Endpoint != "" {
36 fmt.Fprintf(b, "endpoint = %q # a running Chrome's --remote-debugging-port endpoint; empty launches one\n", cfg.Endpoint)
37 }
38 if cfg.AllowRemoteEndpoint {
39 b.WriteString("allow_remote_endpoint = true # a DevTools endpoint grants full control of that browser\n")
40 }
41 if cfg.ChromePath != "" {
42 fmt.Fprintf(b, "chrome_path = %q\n", cfg.ChromePath)
43 }
44 if len(cfg.ChromeArgs) > 0 {
45 fmt.Fprintf(b, "chrome_args = %s\n", renderStringArray(cfg.ChromeArgs))
46 }
47 if cfg.UserDataDir != "" {
48 fmt.Fprintf(b, "user_data_dir = %q\n", cfg.UserDataDir)
49 }
50 if cfg.Headless {
51 b.WriteString("headless = true\n")
52 }
53 b.WriteString("\n")
54 }
55
55 lines GO