cli

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 39 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cli parses Daisybell's command line and dispatches subcommands: serve (the MCP server, default) and the human-facing setup, doctor, uninstall, recordings, install-browser, version.

Index

Constants

View Source
const ServerName = "daisybell"

ServerName is Daisybell's key in every client's server list.

Variables

View Source
var Clients = []*Client{
	{
		ID: "claude-code", Name: "Claude Code",
		Detect: func(e *Env) bool { return e.has("claude") || exists(e.claudeDir()) || exists(e.claudeJSON()) },
		Targets: func(e *Env, s Scope) []Target {
			if s == ScopeProject {
				return []Target{{Path: filepath.Join(e.Cwd, ".mcp.json"), Format: FormatJSON, Key: "mcpServers", Entry: stdio}}
			}
			f := FormatJSON
			if e.has("claude") {
				f = FormatClaudeCLI
			}
			return []Target{{Path: e.claudeJSON(), Format: f, Key: "mcpServers", Entry: stdio}}
		},
		Skill: func(e *Env, s Scope) string {
			if s == ScopeProject {
				return filepath.Join(e.Cwd, ".claude", "skills", ServerName, "SKILL.md")
			}
			return filepath.Join(e.claudeDir(), "skills", ServerName, "SKILL.md")
		},
		Restart: "restartClaudeCode",
	},
	{
		ID: "claude-desktop", Name: "Claude Desktop",
		Detect: func(e *Env) bool { return exists(filepath.Join(e.appSupport(), "Claude")) },
		Targets: func(e *Env, s Scope) []Target {
			if s == ScopeProject {
				return nil
			}
			return []Target{{Path: filepath.Join(e.appSupport(), "Claude", "claude_desktop_config.json"), Format: FormatJSON, Key: "mcpServers", Entry: plain}}
		},
		Restart: "restartDesktop",
	},
	{
		ID: "cursor", Name: "Cursor",
		Detect: func(e *Env) bool { return exists(filepath.Join(e.Home, ".cursor")) || e.has("cursor") },
		Targets: func(e *Env, s Scope) []Target {
			if s == ScopeProject {
				return []Target{{Path: filepath.Join(e.Cwd, ".cursor", "mcp.json"), Format: FormatJSON, Key: "mcpServers", Entry: plain}}
			}
			return []Target{{Path: filepath.Join(e.Home, ".cursor", "mcp.json"), Format: FormatJSON, Key: "mcpServers", Entry: plain}}
		},
		Skill: func(e *Env, s Scope) string {
			if s == ScopeProject {
				return filepath.Join(e.Cwd, ".cursor", "rules", ServerName+".mdc")
			}
			return ""
		},
		Restart: "restartCursor",
	},
	{

		ID: "vscode", Name: "VS Code (Copilot)",
		Detect: func(e *Env) bool {
			if exists(e.copilotHome()) || e.has("code") || e.has("copilot") {
				return true
			}
			for _, d := range e.vscodeUserDirs() {
				if exists(d) {
					return true
				}
			}
			return false
		},
		Targets: func(e *Env, s Scope) []Target {
			if s == ScopeProject {
				return []Target{
					{Path: filepath.Join(e.Cwd, ".mcp.json"), Format: FormatJSON, Key: "mcpServers", Entry: stdio},
					{Path: filepath.Join(e.Cwd, ".vscode", "mcp.json"), Format: FormatJSON, Key: "servers", Entry: stdio, Legacy: true},
				}
			}
			ts := []Target{{Path: filepath.Join(e.copilotHome(), "mcp-config.json"), Format: FormatJSON, Key: "mcpServers", Entry: func(bin string) Entry {
				en := stdio(bin)
				en.Tools = []string{"*"}
				return en
			}}}
			for _, d := range e.vscodeUserDirs() {
				ts = append(ts, Target{Path: filepath.Join(d, "mcp.json"), Format: FormatJSON, Key: "servers", Entry: stdio, Legacy: true})
			}
			return ts
		},
		Skill: func(e *Env, s Scope) string {
			if s == ScopeProject {
				return filepath.Join(e.Cwd, ".github", "skills", ServerName, "SKILL.md")
			}
			return filepath.Join(e.copilotHome(), "skills", ServerName, "SKILL.md")
		},
		Restart: "restartVSCode",
	},
	{
		ID: "windsurf", Name: "Windsurf",
		Detect: func(e *Env) bool { return exists(filepath.Join(e.Home, ".codeium", "windsurf")) || e.has("windsurf") },
		Targets: func(e *Env, s Scope) []Target {
			if s == ScopeProject {
				return nil
			}
			return []Target{{Path: filepath.Join(e.Home, ".codeium", "windsurf", "mcp_config.json"), Format: FormatJSON, Key: "mcpServers", Entry: plain}}
		},
		Restart: "restartWindsurf",
	},
	{
		ID: "codex", Name: "Codex CLI",
		Detect: func(e *Env) bool { return exists(e.codexHome()) || e.has("codex") },
		Targets: func(e *Env, s Scope) []Target {
			if s == ScopeProject {
				return nil
			}
			return []Target{{Path: filepath.Join(e.codexHome(), "config.toml"), Format: FormatTOML, Entry: plain}}
		},
		Restart: "restartCodex",
	},
	{
		ID: "zed", Name: "Zed",
		Detect: func(e *Env) bool { return exists(e.zedDir()) || e.has("zed") },
		Targets: func(e *Env, s Scope) []Target {
			if s == ScopeProject {
				return nil
			}
			return []Target{{Path: filepath.Join(e.zedDir(), "settings.json"), Format: FormatJSON, Key: "context_servers", Entry: func(bin string) Entry {
				en := plain(bin)
				en.Env = &struct{}{}
				return en
			}}}
		},
		Restart: "restartZed",
	},
}

Clients is every app setup knows, in the order they are shown.

View Source
var Version = "0.0.0-dev"

Version is set at build time with -ldflags "-X .../cli.Version=...".

Functions

func Run

func Run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) int

Run executes the command line and returns the process exit code.

Types

type Change

type Change struct {
	Target  Target
	Clients []string // display names sharing this file (.mcp.json: Claude Code and VS Code)
	Kind    changeKind
	Before  found
	Bin     string
	Old     []byte
	New     []byte
}

Change is one planned edit of one target. Old/New are the file's bytes before and after (nil for FormatClaudeCLI, which runs the claude CLI instead).

type Check

type Check struct {
	ID     string `json:"id"`
	Status Status `json:"status"`
	Text   string `json:"text"`
	Fix    string `json:"fix,omitempty"`
}

Check is one line of doctor's report.

type Client

type Client struct {
	ID   string
	Name string
	// Detect reports whether the app seems installed (its config dir exists or its CLI is on PATH).
	Detect func(e *Env) bool
	// Targets lists the files for a scope (nil when the app has no such scope).
	Targets func(e *Env, s Scope) []Target
	// Skill is where the usage guide goes for a scope ("" when the app has none).
	Skill func(e *Env, s Scope) string
	// Restart is the human's next step after setup.
	Restart string
}

Client is an AI app Daisybell can configure.

type Entry

type Entry struct {
	Type    string    `json:"type,omitempty"`
	Command string    `json:"command"`
	Args    []string  `json:"args"`
	Env     *struct{} `json:"env,omitempty"`
	Tools   []string  `json:"tools,omitempty"`
}

Entry is Daisybell's server entry in a client's config file. Fields are written in this order; empty optional fields are left out, so each client gets the shape its docs show.

type Env

type Env struct {
	Home       string // the user's home directory
	Cwd        string // project directory for --scope project
	GOOS       string
	Executable string // this binary, symlinks resolved
	Layout     paths.Layout
	Getenv     func(string) string
	LookPath   func(string) (string, error)
	// Run runs a program and returns its combined output (claude mcp, daisybell version, git).
	Run    func(ctx context.Context, name string, args ...string) (string, error)
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	// Interactive is true when stdin is a terminal: setup may ask questions.
	Interactive bool
	// Lang is "en" or "pt-BR" (human-facing output).
	Lang string
	// Open opens a file or URL with the OS (recordings open).
	Open func(target string) error
	// Smoke launches a headless browser with the Cockpit and waits for it to connect (doctor).
	Smoke func(ctx context.Context) error
	// SmokeProfile does the same on an existing profile (doctor probes the default one, where a
	// stale Cockpit worker can hide). It returns errCockpit, errStaleWorker or the launch error.
	SmokeProfile func(ctx context.Context, dir string) error
	// Quarantined reports the macOS quarantine flag on a file (doctor).
	Quarantined func(path string) bool
	// InstallBrowser downloads the pinned browser (setup); nil uses the real installer.
	InstallBrowser func(ctx context.Context) (string, error)
}

Env is everything the human-facing commands (setup, doctor, uninstall, recordings) take from the machine, so tests run them against a temp HOME with fakes and never touch the real one.

func DefaultEnv

func DefaultEnv(stdin io.Reader, stdout, stderr io.Writer) (*Env, error)

DefaultEnv is the real process environment.

func (*Env) Checks

func (e *Env) Checks(ctx context.Context, launch bool) []Check

Checks runs every check. launch includes the headless smoke test (a few seconds).

func (*Env) Doctor

func (e *Env) Doctor(ctx context.Context, args []string) int

Doctor checks the install and prints one line per check, each failure with its fix.

func (*Env) Flags

func (e *Env) Flags(args []string) int

Flags prints the server flags as a Markdown table.

func (*Env) GenDocs

func (e *Env) GenDocs(ctx context.Context, files []string) int

GenDocs rewrites the generated blocks of the given files (`make docs`).

func (*Env) InstallBrowserCmd

func (e *Env) InstallBrowserCmd(ctx context.Context, args []string, logger *slog.Logger) int

InstallBrowserCmd downloads the pinned Chrome for Testing, or installs it from a zip the human downloaded themselves (--from, for offline machines and proxies that block the download).

func (*Env) Main

func (e *Env) Main(ctx context.Context, args []string) int

Main parses the global flags and runs the command on this environment.

func (*Env) Map

func (e *Env) Map(args []string, opts server.Options) int

Map is `daisybell map`.

func (*Env) Recordings

func (e *Env) Recordings(args []string) int

Recordings manages ~/.daisybell/recordings: list, open (the HTML replay) and clean.

func (*Env) Session

func (e *Env) Session(ctx context.Context, args []string, opts server.Options, logger *slog.Logger) int

Session is `daisybell session save|list|delete`.

func (*Env) Setup

func (e *Env) Setup(ctx context.Context, args []string) int

Setup installs the binary to ~/.daisybell/bin, configures the chosen AI apps, downloads the browser and offers the usage guide. Running it again updates everything in place.

func (*Env) Tools

func (e *Env) Tools(ctx context.Context, args []string) int

Tools lists the MCP tools (`daisybell tools`), or prints the README's table (--markdown).

func (*Env) Uninstall

func (e *Env) Uninstall(ctx context.Context, args []string) int

Uninstall removes Daisybell's entry from every app config (user and current project) and the guides it wrote. With --all it also deletes ~/.daisybell (binary, browser, profile, recordings).

type Format

type Format int

Format is how a target file is edited.

const (
	FormatJSON      Format = iota // JSON or JSONC, edited in place with comments kept
	FormatTOML                    // Codex config.toml
	FormatClaudeCLI               // `claude mcp add/remove --scope user` (reads ~/.claude.json)
)

type Scope

type Scope string

Scope is where a client's config goes: the user's (every project) or the current project's.

const (
	ScopeUser    Scope = "user"
	ScopeProject Scope = "project"
)

type Status

type Status string

Status of one doctor check. Only fail makes doctor exit non-zero.

const (
	StatusOK   Status = "ok"
	StatusFail Status = "fail"
	StatusInfo Status = "info" // optional, skipped or just informative
)

type Target

type Target struct {
	Client *Client
	Scope  Scope
	Path   string // the file; for FormatClaudeCLI the file the CLI writes (read to compare)
	Format Format
	Key    string // JSON key holding the servers (mcpServers, servers, context_servers)
	Entry  func(bin string) Entry
	// Legacy targets are only updated or removed when Daisybell is already in them, never added.
	Legacy bool
}

Target is one config file (or CLI call) for one client and scope.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL