configweb

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 24 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 configweb is a page in the browser for editing config.toml: every setting the TUI's Settings screen has, and the ones it only names (actions, permission rules, check commands), as a form.

It listens on 127.0.0.1 only, and the API answers only a request that carries the token handed out with the address — in the URL's fragment, which a browser never sends anywhere — in a header of its own. A page on another site can reach 127.0.0.1 but cannot read the fragment, and cannot set the header without a preflight this server never grants; the Host check stops a name that resolves to 127.0.0.1 being used to the same end. Anything else running as you could edit config.toml anyway.

Index

Constants

View Source
const (
	KindBool   = "bool"
	KindString = "string"
	KindSecret = "secret" // a string shown as dots until asked for
	KindText   = "text"   // a string of several lines, or a long command
	KindInt    = "int"
	KindFloat  = "float"
	KindSelect = "select" // one of Options; "" is allowed when Options has it
	KindList   = "list"   // a list of strings
	KindInts   = "ints"   // a list of integers
	KindMap    = "map"    // string keys to string values
	KindTables = "tables" // an array of tables, each with Fields
	KindKeyed  = "keyed"  // tables keyed by name, each with Fields
	KindTable  = "table"  // one nested table, [trackers.linear], with Fields
)

Kinds of field.

View Source
const TokenHeader = "X-Conch-Token"

TokenHeader carries the token on every API request.

Variables

This section is empty.

Functions

This section is empty.

Types

type Choices

type Choices struct {
	// Cloud is whether Conch Cloud is enabled (config.CloudEnabled), which
	// the server works out from the file it reads: while it is not, its
	// section offers only the switch.
	Cloud  bool
	Themes []Option
	// LightThemes are the ones drawn on a light background, which is all
	// light_theme offers: it is the theme for macOS's light appearance,
	// and a dark one there turned the window dark as the system went light.
	LightThemes []Option
	Accents     []string
	Agents      []Option
	// Providers are the sandbox providers this build knows, offered as
	// tables to add; a table for one it does not is kept and shown too.
	Providers []string
	// ZshThemes are the Oh My Zsh themes installed here, offered for
	// [shell] omz_theme; any other name can still be typed.
	ZshThemes []string
	// Scenes are the scene files of your own ($CONCH_HOME/scenes), offered
	// for [app] background after the built-in ones.
	Scenes []string
}

Choices are what the select fields offer that only the caller knows: the TUI's themes, the agents this build has.

type Field

type Field struct {
	Key         string   `json:"key"` // within its section's table
	Label       string   `json:"label"`
	Help        string   `json:"help,omitempty"`
	Kind        string   `json:"kind"`
	Options     []Option `json:"options,omitempty"`
	Placeholder string   `json:"placeholder,omitempty"`
	// Default is what an absent key means, for a field that may be left
	// out (a pointer in config.Config): the page shows it, and writes the
	// key only once it is changed.
	Default any     `json:"default,omitempty"`
	Min     *int    `json:"min,omitempty"`
	Max     *int    `json:"max,omitempty"`
	Fields  []Field `json:"fields,omitempty"` // for tables and keyed
	// KeyLabel names the key of a keyed or map entry ("Provider", "Project").
	KeyLabel string   `json:"keyLabel,omitempty"`
	Suggest  []string `json:"suggest,omitempty"` // names a keyed field offers to add, or a string field offers to pick
}

Field is one setting.

type Option

type Option struct {
	Value string `json:"value"`
	Label string `json:"label"`
}

Option is one choice of a select.

type Payload

type Payload struct {
	// Config is config.toml as TOML reads it, defaults filled in: tables
	// by their keys, so the page and the file use the same names.
	Config   map[string]any `json:"config"`
	Raw      string         `json:"raw"`     // the file as it is
	Version  string         `json:"version"` // what the file was when read; a save names it
	Path     string         `json:"path"`
	Exists   bool           `json:"exists"`
	Schema   []Section      `json:"schema"`
	Problems []string       `json:"problems,omitempty"` // what conch will not use as written
}

Payload is what the page is given, and what a save answers with.

type Running

type Running struct {
	URL string
	// contains filtered or unexported fields
}

Running is a server listening.

func (*Running) Close

func (r *Running) Close() error

Close stops it.

type Section

type Section struct {
	ID          string  `json:"id"`
	Key         string  `json:"key"` // the table; "" for the top level
	Title       string  `json:"title"`
	Description string  `json:"description"`
	Icon        string  `json:"icon"` // a lucide icon name the page knows
	Fields      []Field `json:"fields"`
}

Section is one table of config.toml — [ui], [notify] — or, for Key "", the top level, where the arrays of tables are.

func Schema

func Schema(c Choices) []Section

Schema is every section, in the order the page lists them.

type Server

type Server struct {
	Choices Choices
	OnSave  func(config.Config)
	// contains filtered or unexported fields
}

Server is the editor. OnSave, when set, is told about every saved configuration — the TUI takes it at once rather than writing its own older copy over it the next time it saves.

func New

func New(c Choices) (*Server, error)

New makes a server with a fresh token.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler serves the page and the API.

func (*Server) Listen

func (s *Server) Listen(port int) (*Running, error)

Listen starts s on 127.0.0.1:port (0 picks one).

func (*Server) Token

func (s *Server) Token() string

Token is what the page has to send back.

func (*Server) URL

func (s *Server) URL(addr string) string

URL is the address to open for a server listening on addr.

Jump to

Keyboard shortcuts

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