application

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 38 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 application holds Kumo's use cases. The desktop app, the CLI and the guardian process all drive the same services, so every surface starts, stops and configures the core the same way.

Index

Constants

View Source
const DelayTimeout = 5 * time.Second

DelayTimeout bounds one delay test.

Variables

This section is empty.

Functions

func GroupsFromConfig

func GroupsFromConfig(config string) ([]proxy.Group, error)

GroupsFromConfig reads proxy groups out of a configuration.

func Prompt

func Prompt(page, intent string) (string, error)

Prompt is a message to paste into a coding agent: what Kumo is, the rules of its CLI, and the steps of one intent.

Types

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus fans events out to subscribers. Publishing never blocks on a slow subscriber's work: subscribers return quickly or hand off.

func NewBus

func NewBus() *Bus

NewBus returns an empty bus.

func (*Bus) Publish

func (b *Bus) Publish(e Event)

Publish delivers e to every subscriber.

func (*Bus) Subscribe

func (b *Bus) Subscribe(fn func(Event)) func()

Subscribe registers fn and returns a function that removes it.

type Check

type Check struct {
	Name   string `json:"name"`
	OK     bool   `json:"ok"`
	Detail string `json:"detail"`
}

Check is one item of a doctor report.

type CoreExited

type CoreExited struct{ Exit core.Exit }

CoreExited reports a core that ended without Kumo stopping it.

type CoreSettings

type CoreSettings struct {
	Mode           core.Mode            `json:"mode"`
	Settings       core.RuntimeSettings `json:"settings"`
	ControllerHost string               `json:"controllerHost"`
	ControllerPort int                  `json:"controllerPort"`
	HasSecret      bool                 `json:"hasSecret"`
	CorePath       string               `json:"corePath"`
	Candidates     []mihomo.Candidate   `json:"candidates"`
	TUNPermission  TUNPermission        `json:"tunPermission"`
}

CoreSettings is what the Core and Configure pages edit.

type Dependencies

type Dependencies struct {
	Paths       paths.Paths
	Runtime     core.Store
	Profiles    profile.Repository
	Overrides   override.Repository
	Preferences preferences.Store
	SystemProxy systemproxy.Platform
	Fetcher     interface {
		profile.Fetcher
		Get(url string, proxyPort int) ([]byte, map[string][]string, error)
	}
	Transformer runtimeconfig.Transformer
	// Owner is the surface these services run in.
	Owner core.Owner
	// BundledDir holds a Mihomo shipped with the app, if any.
	BundledDir string
	// ReadyTimeout bounds how long a start waits for the controller.
	ReadyTimeout time.Duration
	// WatchInterval is how often the system proxy is checked for
	// contention while Kumo holds it.
	WatchInterval time.Duration
	Now           func() time.Time
}

Dependencies are the adapters the services run on. Tests and simulations swap the system proxy for an in-memory one.

func DefaultDependencies

func DefaultDependencies(p paths.Paths, owner core.Owner) Dependencies

DefaultDependencies wires the real adapters under p.

type Event

type Event interface {
	// contains filtered or unexported methods
}

Event is something the surfaces may want to show.

type Guide

type Guide struct {
	Page    string   `json:"page"`
	Intents []Intent `json:"intents"`
}

Guide is the intents of one page.

func GuideFor

func GuideFor(page string) (Guide, bool)

GuideFor returns a page's intents.

func Guides

func Guides() []Guide

Guides lists every page's intents.

type ImportRequest

type ImportRequest struct {
	URL  string `json:"url,omitempty"`
	Path string `json:"path,omitempty"`
	YAML string `json:"yaml,omitempty"`
	Name string `json:"name,omitempty"`
	// UseProxy fetches the URL through the running core.
	UseProxy bool `json:"useProxy,omitempty"`
	// Activate makes the imported profile current.
	Activate bool `json:"activate,omitempty"`
}

ImportRequest describes a profile to import from a URL, a file or text.

type InspectService

type InspectService struct {
	// contains filtered or unexported fields
}

InspectService reads what a running core reports.

func (*InspectService) CloseConnection

func (s *InspectService) CloseConnection(ctx context.Context, id string) error

CloseConnection closes one connection, or every one when id is "".

func (*InspectService) Connections

func (s *InspectService) Connections(ctx context.Context) (inspect.Connections, error)

Connections lists open connections with per-connection speeds, computed from the change since the previous call.

func (*InspectService) Providers

Providers lists proxy and rule providers.

func (*InspectService) RecentLogs

func (s *InspectService) RecentLogs(limit int) ([]inspect.LogEntry, error)

RecentLogs reads the last lines of the core's log file.

func (*InspectService) Rules

func (s *InspectService) Rules(ctx context.Context) ([]inspect.Rule, error)

Rules lists the running rules.

func (*InspectService) SetRuleEnabled

func (s *InspectService) SetRuleEnabled(ctx context.Context, index int, enabled bool) error

SetRuleEnabled turns a rule off or on until the core restarts.

func (*InspectService) StreamLogs

func (s *InspectService) StreamLogs(ctx context.Context, level string)

StreamLogs publishes log lines at level and above while ctx lives.

func (*InspectService) StreamTraffic

func (s *InspectService) StreamTraffic(ctx context.Context)

StreamTraffic publishes throughput every second while the core runs and ctx lives, reconnecting when the core restarts.

func (*InspectService) UpdateProvider

func (s *InspectService) UpdateProvider(ctx context.Context, kind, name string) error

UpdateProvider refreshes a proxy ("proxy") or rule ("rule") provider.

func (*InspectService) UpgradeGeoData

func (s *InspectService) UpgradeGeoData(ctx context.Context) error

UpgradeGeoData downloads fresh geo databases.

func (*InspectService) Version

func (s *InspectService) Version(ctx context.Context) (inspect.Version, error)

Version is the running core's version.

type Intent

type Intent struct {
	ID    string `json:"id"`
	Goal  string `json:"goal"`
	Steps []Step `json:"steps"`
}

Intent is one thing a user may want an agent to do on a page, with the kumo commands that do it.

type Kumo

type Kumo struct {
	Events *Bus

	Lifecycle   *Lifecycle
	SystemProxy *SystemProxyService
	Profiles    *ProfileService
	Overrides   *OverrideService
	Proxies     *ProxyService
	Inspect     *InspectService
	Settings    *SettingsService
	Topology    *TopologyService
	Preferences *PreferenceService
	// contains filtered or unexported fields
}

Kumo is every use case, sharing one set of adapters and one event bus.

func New

func New(deps Dependencies) *Kumo

New wires the services.

func (*Kumo) Doctor

func (k *Kumo) Doctor(ctx context.Context) (Report, error)

Doctor gathers status, the cores Kumo can find, port checks and what the system proxy shows.

func (*Kumo) Paths

func (k *Kumo) Paths() paths.Paths

Paths are where this Kumo keeps its files.

func (*Kumo) Runtime

func (k *Kumo) Runtime() (core.Runtime, error)

Runtime reads the stored runtime.

type Lifecycle

type Lifecycle struct {
	// contains filtered or unexported fields
}

Lifecycle starts, stops and watches the core.

func (*Lifecycle) Monitor

func (l *Lifecycle) Monitor(ctx context.Context)

Monitor keeps the status current while ctx lives: it notices cores that other surfaces start or stop, and system proxy changes by other apps.

func (*Lifecycle) Recover

func (l *Lifecycle) Recover() (Status, error)

Recover is the first thing the app does: it adopts a core that still runs from an earlier session, records one that died, and takes Kumo's settings out of the system when no core serves them any more.

func (*Lifecycle) Refresh

func (l *Lifecycle) Refresh() (Status, error)

Refresh reconciles and publishes the status if it changed.

func (*Lifecycle) Reload

func (l *Lifecycle) Reload(ctx context.Context) error

Reload rebuilds the configuration and has the running core read it, keeping its process and connections. When the core is off, it only writes the file for the next start.

func (*Lifecycle) Restart

func (l *Lifecycle) Restart(ctx context.Context, opts StartOptions) (Status, error)

Restart stops and starts the core again.

func (*Lifecycle) RuntimeConfig

func (l *Lifecycle) RuntimeConfig(rt core.Runtime) (string, error)

RuntimeConfig builds the configuration the core would run with now.

func (*Lifecycle) Shutdown

func (l *Lifecycle) Shutdown(ctx context.Context) ShutdownReport

Shutdown is the quit path: release the system proxy and stop the core, whichever surface started it. Every step runs even when an earlier one failed, and failures are reported rather than returned, so the app can always quit.

func (*Lifecycle) Start

func (l *Lifecycle) Start(ctx context.Context, opts StartOptions) (Status, error)

Start launches the core with the current profile and waits until its controller answers.

func (*Lifecycle) Status

func (l *Lifecycle) Status() (Status, error)

Status reconciles the stored runtime with the processes that actually run, and describes the result.

func (*Lifecycle) Stop

func (l *Lifecycle) Stop(ctx context.Context) (Status, error)

Stop lets go of the system proxy, then ends the core and waits for its ports to free up. The user's wish for the system proxy is kept, so the next start sets it again.

type LogReceived

type LogReceived struct{ Entry inspect.LogEntry }

LogReceived carries one line of the core's log.

type OverrideDetail

type OverrideDetail struct {
	override.Override
	Content string `json:"content"`
}

OverrideDetail is an override with its content.

type OverrideService

type OverrideService struct {
	// contains filtered or unexported fields
}

OverrideService manages the overrides applied on top of every profile.

func (*OverrideService) Delete

func (s *OverrideService) Delete(ctx context.Context, id string) error

Delete removes an override.

func (*OverrideService) Get

Get returns an override with its content.

func (*OverrideService) List

func (s *OverrideService) List() ([]override.Override, error)

List returns overrides in the order they apply.

func (*OverrideService) Reorder

func (s *OverrideService) Reorder(ctx context.Context, ids []string) error

Reorder changes the order overrides apply in.

func (*OverrideService) Save

Save validates and stores an override, then reloads a running core.

func (*OverrideService) SetDisabled

func (s *OverrideService) SetDisabled(ctx context.Context, id string, disabled bool) error

SetDisabled turns an override off or on without deleting it.

type PreferenceService

type PreferenceService struct {
	// contains filtered or unexported fields
}

PreferenceService keeps app-level preferences.

func (*PreferenceService) Get

Get returns the preferences.

func (*PreferenceService) Save

Save stores the preferences.

func (*PreferenceService) Update

Update changes the preferences with fn and stores them.

type ProfileService

type ProfileService struct {
	// contains filtered or unexported fields
}

ProfileService imports, refreshes and switches profiles.

func (*ProfileService) Content

func (s *ProfileService) Content(id string) (string, error)

Content returns a profile's YAML.

func (*ProfileService) Delete

func (s *ProfileService) Delete(ctx context.Context, id string) error

Delete removes a profile; when it was current, the core switches to the next one.

func (*ProfileService) Get

func (s *ProfileService) Get(id string) (profile.Summary, error)

Get returns one profile.

func (*ProfileService) Import

Import adds a profile and, when asked, switches to it.

func (*ProfileService) List

func (s *ProfileService) List() ([]profile.Summary, error)

List returns every profile, the current one marked.

func (*ProfileService) Refresh

func (s *ProfileService) Refresh(ctx context.Context, id string) (profile.Summary, error)

Refresh downloads a remote profile again, keeping its ID and settings.

func (*ProfileService) RefreshDue

func (s *ProfileService) RefreshDue(ctx context.Context) ([]profile.Summary, error)

RefreshDue refreshes every remote profile whose interval has passed.

func (*ProfileService) Select

func (s *ProfileService) Select(ctx context.Context, id string) error

Select makes a profile current and has a running core switch to it.

func (*ProfileService) Update

Update edits a profile's metadata and, optionally, its YAML.

type ProfilesChanged

type ProfilesChanged struct{}

ProfilesChanged reports that profiles were added, changed or removed.

type ProxyService

type ProxyService struct {
	// contains filtered or unexported fields
}

ProxyService lists proxy groups, selects nodes and measures delays.

func (*ProxyService) Groups

func (s *ProxyService) Groups(ctx context.Context) ([]proxy.Group, error)

Groups returns the live groups of a running core. When the core is off it reads them from the configuration instead, marked not live: Mihomo decides the actual selection when it starts.

func (*ProxyService) Select

func (s *ProxyService) Select(ctx context.Context, group, name string) error

Select picks a group's node and closes connections that used the old one, so traffic moves at once.

func (*ProxyService) TestGroup

func (s *ProxyService) TestGroup(ctx context.Context, group string) (map[string]int, error)

TestGroup measures every node of a group; nodes that time out read -1.

func (*ProxyService) TestNode

func (s *ProxyService) TestNode(ctx context.Context, name, testURL string) (int, error)

TestNode measures one node's delay.

type Report

type Report struct {
	Status      Status                `json:"status"`
	Checks      []Check               `json:"checks"`
	Cores       []mihomo.Candidate    `json:"cores"`
	SystemProxy *systemproxy.Snapshot `json:"observedSystemProxy,omitempty"`
	DataDir     string                `json:"dataDir"`
	Platform    string                `json:"platform"`
}

Report is a broad snapshot for diagnosing Kumo.

type SaveRequest

type SaveRequest struct {
	ID       string          `json:"id,omitempty"`
	Name     string          `json:"name"`
	Format   override.Format `json:"format"`
	Content  string          `json:"content"`
	URL      string          `json:"url,omitempty"`
	Disabled bool            `json:"disabled,omitempty"`
}

SaveRequest creates or edits an override. With a URL and no content, the content is downloaded.

type SettingsService

type SettingsService struct {
	// contains filtered or unexported fields
}

SettingsService changes how the core runs.

func (*SettingsService) Get

func (s *SettingsService) Get() (CoreSettings, error)

Get returns the stored settings and the cores Kumo can find.

func (*SettingsService) GrantTUN

func (s *SettingsService) GrantTUN(ctx context.Context) (TUNPermission, error)

GrantTUN asks the system for the permission TUN needs.

func (*SettingsService) InstallCore

func (s *SettingsService) InstallCore(ctx context.Context) (mihomo.Installed, error)

InstallCore downloads the latest Mihomo and selects it.

func (*SettingsService) SetController

func (s *SettingsService) SetController(ctx context.Context, host string, port int, secret *string) (Status, error)

SetController moves the external controller, which takes a restart.

func (*SettingsService) SetCorePath

func (s *SettingsService) SetCorePath(path string) error

SetCorePath chooses the Mihomo executable; "" goes back to discovery.

func (*SettingsService) SetMode

func (s *SettingsService) SetMode(ctx context.Context, mode core.Mode) (Status, error)

SetMode switches the outbound mode, at once when the core runs, and closes connections so they follow the new mode.

func (*SettingsService) SetTUN

func (s *SettingsService) SetTUN(ctx context.Context, enabled bool) (Status, error)

SetTUN turns TUN on or off.

func (*SettingsService) Update

func (s *SettingsService) Update(ctx context.Context, settings core.RuntimeSettings) (Status, error)

Update replaces the runtime settings and reloads a running core.

type ShutdownReport

type ShutdownReport struct {
	Status      Status   `json:"status"`
	Diagnostics []string `json:"diagnostics"`
}

ShutdownReport says what a shutdown did and what failed along the way.

func Guard

func Guard(ctx context.Context, k *Kumo, parent int, interval time.Duration) ShutdownReport

Guard watches the app with pid parent. If the app goes away without quitting properly (a crash, a force quit, a kill), Guard does what the quit would have done: it lets go of the system proxy and stops the core the app owned. A clean quit leaves nothing to do, and Guard just ends.

type StartOptions

type StartOptions struct {
	// CorePath overrides the executable for this start.
	CorePath string `json:"corePath,omitempty"`
	// ResolvePortConflicts moves Kumo to free ports instead of failing when
	// another process holds the mixed or controller port.
	ResolvePortConflicts bool `json:"resolvePortConflicts,omitempty"`
}

StartOptions tune one start.

type Status

type Status struct {
	State     core.RunState  `json:"state"`
	PID       int            `json:"pid,omitempty"`
	Owner     core.Owner     `json:"owner,omitempty"`
	Readiness core.Readiness `json:"readiness,omitempty"`
	StartedAt *time.Time     `json:"startedAt,omitempty"`
	Message   string         `json:"message,omitempty"`
	Mode      core.Mode      `json:"mode"`
	// Controller is the external controller's address.
	Controller  string            `json:"controller"`
	MixedPort   int               `json:"mixedPort"`
	CorePath    string            `json:"corePath,omitempty"`
	TUN         bool              `json:"tun"`
	SystemProxy SystemProxyStatus `json:"systemProxy"`
	Profile     profile.Summary   `json:"profile"`
	LastExit    *core.Exit        `json:"lastExit,omitempty"`
}

Status is the runtime as the surfaces show it.

func (Status) Running

func (s Status) Running() bool

Running reports whether the core is up.

type StatusChanged

type StatusChanged struct{ Status Status }

StatusChanged carries the new status after any change of the runtime.

type Step

type Step struct {
	Command string `json:"command"`
	Why     string `json:"why"`
}

Step is one command and why it runs.

type SystemProxyContended

type SystemProxyContended struct {
	Ownership systemproxy.Ownership `json:"ownership"`
	Observed  systemproxy.Snapshot  `json:"observed"`
	// Holder is the process listening where the system now points, when
	// that is on this machine.
	Holder string `json:"holder,omitempty"`
	// Reclaimed is true when Kumo put its proxy back.
	Reclaimed bool `json:"reclaimed"`
}

SystemProxyContended reports that another app changed the system proxy while Kumo had it.

type SystemProxyService

type SystemProxyService struct {
	// contains filtered or unexported fields
}

SystemProxyService points the operating system at the core, and notices when another app points it elsewhere.

func (*SystemProxyService) Apply

Apply writes Kumo's settings into the system and checks that they took.

func (*SystemProxyService) Check

func (s *SystemProxyService) Check()

Check looks whether the system still shows Kumo's settings. Another app's proxy is reported (and replaced, when the user asked Kumo to reclaim it); a proxy someone turned off stays off.

func (*SystemProxyService) Release

func (s *SystemProxyService) Release() error

Release takes Kumo's settings out of the system, if they are still there. Settings another app put in since are left alone: Kumo never clears a proxy it does not own.

func (*SystemProxyService) Services

func (s *SystemProxyService) Services() ([]string, error)

Services lists the network services the proxy can be set on.

func (*SystemProxyService) SetEnabled

func (s *SystemProxyService) SetEnabled(enabled bool) (Status, error)

SetEnabled records the user's wish and acts on it: with the core running, Kumo's settings go into the system; turned off, they come out.

func (*SystemProxyService) UpdateSettings

func (s *SystemProxyService) UpdateSettings(settings systemproxy.Settings) (Status, error)

UpdateSettings stores new settings and applies them when active.

type SystemProxyStatus

type SystemProxyStatus struct {
	// Enabled is what the user asked for; it survives restarts.
	Enabled bool `json:"enabled"`
	// Active is true while Kumo's settings are in the system.
	Active    bool                  `json:"active"`
	Ownership systemproxy.Ownership `json:"ownership,omitempty"`
	Settings  systemproxy.Settings  `json:"settings"`
	Applied   *systemproxy.Applied  `json:"applied,omitempty"`
}

SystemProxyStatus is the system proxy as the surfaces show it.

type TUNPermission

type TUNPermission struct {
	Granted bool `json:"granted"`
	// Method is how it was granted: "root" when Kumo itself runs as root,
	// "setuid" when the core is owned by root with the setuid bit, or
	// "capability" for Linux file capabilities.
	Method string `json:"method,omitempty"`
}

TUNPermission says whether the core can create a TUN interface.

type TopologyService

type TopologyService struct {
	// contains filtered or unexported fields
}

TopologyService draws the configuration as a graph.

func (*TopologyService) Graph

Graph builds the topology of the configuration the core runs (or would run), with the live selections when it runs.

type TrafficSampled

type TrafficSampled struct{ Traffic inspect.Traffic }

TrafficSampled carries one second of throughput.

type UpdateRequest

type UpdateRequest struct {
	ID         string  `json:"id"`
	Name       string  `json:"name"`
	RemoteURL  string  `json:"remoteURL"`
	AutoUpdate bool    `json:"autoUpdate"`
	UseProxy   bool    `json:"useProxy"`
	YAML       *string `json:"yaml,omitempty"`
}

UpdateRequest edits a profile.

Jump to

Keyboard shortcuts

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