Documentation
¶
Index ¶
- type Config
- type Server
- func (s *Server) ApplyConfigYAML(data []byte, ifMatch string, force bool) (api.ConfigApplyResult, error)
- func (s *Server) BrokerSocket() string
- func (s *Server) BrokerTLSAddr() string
- func (s *Server) CLIListenAddr() string
- func (s *Server) ConfigYAML() (data []byte, revision string, err error)
- func (s *Server) DB() *sql.DB
- func (s *Server) GatewayCAPEM() []byte
- func (s *Server) GatewayTLSAddr() string
- func (s *Server) GatewayURL() string
- func (s *Server) HostCommands() map[string]orchestrator.HostCommandSpec
- func (s *Server) InstallID() string
- func (s *Server) KitsDir() string
- func (s *Server) MutateConfig(req api.ConfigMutateRequest) (api.ConfigMutateResult, error)
- func (s *Server) ProxyPort() int
- func (s *Server) ReloadHostCommands() error
- func (s *Server) Router() chi.Router
- func (s *Server) SocketPath() string
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop() error
- func (s *Server) Store() *orchestrator.ProjectStore
- func (s *Server) TCPAddr() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
DBPath string
SocketPath string
HTTPAddr string
KitsDir string // base dir for installed kit repos
KeyFilePath string // path to secret encryption key file
AllowedDomains []string // proxy allowed domains
// EgressProxyPortLow/High bound the band the egress proxy allocates
// stable per-workspace ports from (config.yaml
// sandbox.egress_proxy_port_low/high — docs/plans/egress-proxy-stable-port.md).
// Zero means "use sandbox.DefaultProxyPortRange{Low,High}"; the default
// literal deliberately lives in internal/sandbox only. Captured once at
// startup, ReloadRestartRequired, exactly like AllowedDomains — a
// listener cannot move to a different band without rebinding anyway.
EgressProxyPortLow int
EgressProxyPortHigh int
// ServicesFloor is the daemon-wide API gateway service allowlist floor
// (config.yaml services_floor — docs/plans/api-gateway.md §3), captured
// once here exactly like AllowedDomains is for the proxy egress
// allowlist: cmd/start.go's buildStartConfig reads it from its own
// config.Load() call and passes it in, so a later `boid config set
// services_floor ...` only takes effect on the next daemon restart, same
// ReloadRestartRequired posture as sandbox.allowed_domains.
ServicesFloor []string
// Backend, when non-nil, overrides buildRuntime's default construction
// of a real containerBackend (sandboxBackendForConfig) — a test/DI seam
// (the successor to the pre-PR-4 JobRuntime field, which let tests
// inject a fake JobRuntime for the now-removed userns backend, docs/
// plans/volume-only-daemon.md §論点e) so tests can exercise daemon
// startup / the HTTP API / attach-resize wiring against a fake
// backend.SandboxBackend without a live docker daemon.
Backend backend.SandboxBackend
// TLSDir, when non-empty, is the directory holding (or to generate)
// the per-daemon internal CA (ca.crt/ca.key) used to secure the
// broker/git-gateway TCP(mTLS) listeners added in
// docs/plans/phase6-container-backend.md §PR4/§決定5. Empty (the
// zero value, and every pre-PR4 caller/test) skips binding those
// listeners entirely — only the pre-existing UNIX socket / plaintext
// loopback listeners are bound, i.e. today's behavior is unchanged.
// cmd/start.go sets a real default (~/.local/share/boid/tls) so a
// live daemon actually binds them; nothing dispatches through them
// yet (the container backend that will is PR5).
TLSDir string
// InstallIDDir, when non-empty, is the directory holding (or to
// generate) this installation's plain-UUID install_id file
// (internal/install.LoadOrCreate — docs/plans/
// phase6-container-backend.md §PR6/§決定6: "daemon が作る全
// container/network/volume に boid.install_id... label を付与"). Empty
// (the zero value, and every pre-PR6 test) skips this entirely — New
// leaves Server.installID at "" and nothing changes. cmd/start.go sets
// a real default (~/.local/share/boid, the same dir web_secret and
// boid.db live in) so a live daemon actually has one; nothing consumes
// it in production dispatch yet (containerBackend construction is
// still test/DI-only — see NewContainerBackend's doc comment — the
// same "config 非公開" scope PR5 shipped under).
InstallIDDir string
// CLIAddr, when non-empty, is the "host:port" the dedicated CLI TCP
// listener binds — PR-3 Option 4 host-mode redesign (docs/plans/
// volume-only-daemon.md §論点c, nose directive 2026-07-25). Only the
// PORT is actually load-bearing: Start() ignores the host half and
// binds gatewayBindHost(s.usingContainerBackend) instead — "127.0.0.1"
// for the userns backend (unchanged; this listener is reached
// exclusively by the `boid` CLI's own host-mode orchestration,
// cmd/host.go, dialing the docker-published port on the SAME host,
// never by a remote caller or a sibling job container) or
// composeBindHost ("0.0.0.0") for the container backend (round-4 fix:
// under compose, this daemon IS the container being dialed — docker's
// bridge-mode port publish DNATs the host's own 127.0.0.1 to the
// container's bridge IP, never the container's loopback interface, so
// a loopback-only bind there is unreachable from the host at all; see
// gatewayBindHost's own doc comment for the identical routing already
// used by the git gateway/broker TLS listeners). Separate from
// HTTPAddr (the Web UI's own TCP listener, default :8080) so a CLI
// session keeps working even if an operator firewalls off or disables
// the Web UI port.
//
// Binding is further gated on CLIToken being non-empty (see that
// field's own doc comment) — CLIAddr alone is not enough, unlike every
// other listener in this Config, because this listener has no
// TLS/loopback-trust/cookie fallback: an unset token would otherwise
// mean an open, unauthenticated TCP port.
CLIAddr string
// CLIToken, when non-empty, is the shared secret
// (auth.NewCLITokenAuthMiddleware) the dedicated CLI TCP listener
// (CLIAddr) requires on every request's `Authorization: Bearer`
// header — PR-3 Option 4 host-mode redesign. Sourced from the
// BOID_CLI_TOKEN env var (cmd/start.go's buildStartConfig), which
// `boid`'s own host-mode orchestration (cmd/host.go) generates/reads
// from ~/.config/boid/cli-token and passes to the daemon container via
// build/container/compose.yml's `environment:` block — the same value
// on both ends is what authenticates a host-mode CLI dispatch with no
// TLS and no device-pairing ceremony. Empty (the zero value, and every
// non-container-mode caller/test) skips binding the CLIAddr listener
// entirely, same as CLIAddr=="" — see Start()'s own bind condition.
CLIToken string
// LogLevel is config.yaml's log.level (internal/config.LogConfig.Level),
// copied here by cmd/start.go's buildStartConfig purely so it can travel
// alongside the rest of this struct from the parent's config.Load() call
// to runDaemonChild — unlike every other field above, Server itself
// never reads LogLevel; runDaemonChild applies it directly
// (daemon.ApplyLogLevel(cfg.LogLevel)), before New/Start are even
// called, since it is a process-wide slog concern with nothing to do
// with the HTTP/dispatch server New builds. Empty (the zero value, and
// every pre-this-field caller/test) is a no-op — see
// internal/config.LogConfig and internal/daemon.ApplyLogLevel's own doc
// comments for the full contract.
LogLevel string
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) ApplyConfigYAML ¶ added in v0.1.0
func (s *Server) ApplyConfigYAML(data []byte, ifMatch string, force bool) (api.ConfigApplyResult, error)
ApplyConfigYAML validates, persists, and (for hot-reloadable keys) live-applies a full replacement config.yaml document — see api.ConfigService.ApplyConfigYAML's doc comment for the contract.
ifMatch/force implement the same ETag/If-Match convention `boid workspace edit` already established (internal/api/project_service.go's UpdateWorkspace, cmd/workspace.go's runWorkspaceEdit) — BLOCKER 1, codex review round 1: unless force is true, ifMatch must be non-empty (else 428 Precondition Required) and must match the current revision (else 412 Precondition Failed). This is what makes `boid config edit`/`apply -f` (without --force) reject a write against config.yaml that changed since the caller's GET, instead of silently discarding whatever the other writer just applied.
The whole check-validate-diff-write-swap sequence runs under configMu, so concurrent POST /api/config calls are strictly serialized (docs/plans/ volume-only-daemon.md §論点 f's concurrency decision) — the second call's revision check, validation, and diff always see the first call's already-applied liveConfig and on-disk bytes (currentRevisionLocked re-reads them fresh under this same lock), never a half-applied intermediate state, and the on-disk config.yaml is always written by WriteFileAtomic's temp+rename (never a byte-interleaved torn file).
func (*Server) BrokerSocket ¶
BrokerSocket returns the broker UNIX socket path.
func (*Server) BrokerTLSAddr ¶ added in v0.1.0
BrokerTLSAddr returns the broker's TCP(mTLS) listener address (docs/plans/phase6-container-backend.md §PR4), or "" when cfg.TLSDir was unset (no TLS listener bound) or before Start has bound it.
func (*Server) CLIListenAddr ¶ added in v0.1.0
CLIListenAddr returns the dedicated CLI TCP listener's bound address (docs/plans/volume-only-daemon.md §論点c, PR-3 Option 4 host-mode redesign), or "" when it was never bound (cfg.CLIAddr=="" or cfg.CLIToken=="" — see Config.CLIAddr's own doc comment) or before Start has run.
func (*Server) ConfigYAML ¶ added in v0.1.0
ConfigYAML returns the daemon's config.yaml document exactly as it sits on disk, alongside its current revision — see api.ConfigService.ConfigYAML's doc comment. The revision is the same ETag value GET /api/config's response header carries; round-tripping it into a later POST's If-Match (`boid config edit`/`apply -f` without --force) is BLOCKER 1's optimistic-concurrency guard (codex review round 1).
Deliberately NOT a fully-expanded (defaults-merged) view of s.liveConfig: several Config sub-structs (WebConfig, NotifyConfig, SandboxConfig, ...) have no `omitempty` on their yaml tags, so marshaling the merged struct would make EVERY key "present" (e.g. `web: {public_url: ""}` even when nothing was ever configured) — collapsing `boid config unset`'s "key not found" into meaninglessness (a zero-value key would always exist to "unset"). Returning the raw file instead keeps get/set/unset/apply/edit a faithful, sparse round trip of exactly what the operator has explicitly written — the same contract config.yaml has always had (docs/ja/reference/config-yaml.md: "ファイルが存在しない場合はデフォルト値で 動作します"; per-key defaults are documented in prose there, not by requiring the file to spell every one out). A missing file (fresh install, nothing explicitly configured yet) returns an empty document, not an error.
func (*Server) GatewayCAPEM ¶ added in v0.1.0
GatewayCAPEM returns the daemon's internal CA's own PEM-encoded certificate (see the gatewayCAPEM field's own doc comment), or nil before Start has loaded/created it (cfg.TLSDir unset, or Start hasn't run). Exposed for internal/dispatcher.WireConfig.GatewayCAPEM (via internal/server/wire.go) and for tests — see server_container_backend_gateway_test.go.
func (*Server) GatewayTLSAddr ¶ added in v0.1.0
GatewayTLSAddr returns the git gateway's TCP(mTLS) listener address (docs/plans/phase6-container-backend.md §PR4), or "" when cfg.TLSDir was unset (no TLS listener bound) or before Start has bound it.
func (*Server) GatewayURL ¶ added in v0.0.10
GatewayURL returns the git gateway's sandbox-facing base URL (http://10.0.2.2:<port>), or "" before Start has bound its listener. docs/plans/git-gateway-cutover.md PR4 wires this into SandboxRuntimeInfo.GatewayURL (via dispatcher.WireConfig.GatewayURL), but nothing consumes it yet — the sandbox env var advertise and the runner clone sequence are PR6/PR5.
func (*Server) HostCommands ¶ added in v0.0.13
func (s *Server) HostCommands() map[string]orchestrator.HostCommandSpec
HostCommands returns a deep-copy snapshot of the aggregated host_commands config assembled at startup from every installed kit.yaml (docs/plans/workspace-db-consolidation.md PR2). It is read-only reference data during PR2/PR3's parity-verification window — nothing dispatches through it yet. A snapshot (rather than the live internal map) is returned so a caller mutating the result can never corrupt daemon state, and so a future reload API (PR4) can safely swap s.hostCommands without racing against an in-flight caller.
func (*Server) InstallID ¶ added in v0.1.0
InstallID returns this installation's plain-UUID identity (§決定6), or "" when cfg.InstallIDDir was empty (New never generated one). Nothing in production dispatch consumes this yet as of PR6 (containerBackend construction is still test/DI-only) — it exists so `boid reap` and a future PR7 containerBackend wiring have a single, already-tested source for the value rather than each re-implementing the load.
func (*Server) KitsDir ¶ added in v0.0.13
KitsDir returns this daemon's effective base directory for installed kits (MAJOR 1, codex review round 1, docs/plans/workspace-db-consolidation.md Phase 2.5 PR7): s.cfg is set once in New() and never mutated afterward, so no locking is needed, unlike the mutable s.hostCommands snapshot below. Backs GET /api/config/kits-dir (api.ConfigService) so a CLI client-side helper can resolve a legacy workspace.yaml's `kits:` references against the running daemon's actual kits directory, including one overridden by `boid start --kits-dir <custom>`.
func (*Server) MutateConfig ¶ added in v0.1.0
func (s *Server) MutateConfig(req api.ConfigMutateRequest) (api.ConfigMutateResult, error)
MutateConfig performs one or more dotted-path set/unset operations as one configMu-held read-modify-write — BLOCKER 1, codex review round 1: `boid config set/unset` (cmd/config.go) route here instead of the old client-side GET → mutate → POST round trip, whose two separate daemon calls left a window for a second concurrent `set`'s POST to silently discard a first `set`'s already-applied change (configMu only serialized the POSTs, not the whole client-side transaction around them). Holding configMu across the read, every op's dotted-path Set/Unset, and the write closes that window entirely: two concurrent MutateConfig calls on different keys are strictly serialized, and BOTH changes land — see TestMutateConfig_ConcurrentSetsOfDifferentKeys_BothSucceed.
Batch mode (BLOCKER, codex review round 1 on PR #831): when req.Ops is non-empty, every element is applied to the SAME in-memory tree in order, and the resulting document is validated exactly ONCE, after the last op — not once per op. This is what makes it possible to create a brand-new gateway.forges.<id> entry at all: a single-op call always validates the full document before returning, so setting "<id>.host" alone leaves the document with an empty "<id>.forge", which config.ValidateYAML rejects ("unrecognized forge \"\"") — no sequence of independently-validated single-op calls can ever get all three of host/forge/secret_key in place together. When req.Ops is empty, req itself is treated as the sole operation — the exact pre-existing single-op behavior, unchanged. See TestMutateConfig_Batch_NewForgeAllFieldsAtOnce_Succeeds and TestMutateConfig_Batch_PartialFailureLeavesDocumentUnchanged.
No If-Match/force parameter, unlike ApplyConfigYAML: there is no client-supplied stale snapshot to protect against here at all, since the caller only sends operations (op + key + value), never a full document — the snapshot MutateConfig reads is always the current one, read fresh under the very same lock that performs the write.
func (*Server) ReloadHostCommands ¶ added in v0.0.13
ReloadHostCommands re-reads the aggregated host_commands.yaml config from disk and swaps in both the raw snapshot (what HostCommands() hands out) and the dispatch-facing expanded copy wired into the ProjectStore (docs/plans/workspace-db-consolidation.md PR4 Step G). This is the daemon-side half of the plan doc's documented hand-edit path ("host_commands 実定義の集約先": 手で ~/.config/boid/host_commands.yaml を編集 → boid host-commands reload で daemon に読み直させる) — there is no create/edit API for individual host_command entries, only this reload.
A parse error (a typo introduced by the hand edit) is returned as-is and leaves the daemon's live config untouched — s.hostCommands and the store's copy are only swapped after LoadHostCommandsConfig succeeds, so a bad reload never degrades an already-running daemon.
func (*Server) SocketPath ¶
SocketPath returns the UNIX socket path.
func (*Server) Store ¶
func (s *Server) Store() *orchestrator.ProjectStore
Store returns the project store.