platform

package
v2.4.19 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mode

type Mode string

Mode selects which backend the binary runs. The set is closed and contains exactly three stable values:

  • ModeLocal ("local") — the single-binary SQLite composition with the local stdio MCP server. It has no network dependency and is byte-compatible with pre-v2 behavior.

  • ModeHybrid ("hybrid") — the local SQLite composition plus the remote sync/replication loop. Hybrid is NOT a distinct store or a third backend: it is exactly ModeLocal's composition with replication layered on by internal/app (see startHybridReplication). The literal string "hybrid" is part of the public surface (CORTEX_MODE / --mode) and its meaning is locked by decision D2; it must never be renamed and must never acquire new semantics.

  • ModeServer ("server") — the single-tenant PostgreSQL composition served over authenticated HTTP and streamable MCP. cmd/cortex is the sole bridge to that composition root; internal/platform/server owns it.

Mode is a closed set. Every consumer must reject unknown values instead of falling back to a silent default.

const (
	// ModeLocal runs the single-binary SQLite + stdio-MCP path.
	// This is byte-identical to pre-v2 behavior.
	ModeLocal Mode = "local"

	// ModeHybrid runs the local SQLite composition with remote replication
	// enabled. It is ModeLocal plus the sync loop, never a separate store.
	ModeHybrid Mode = "hybrid"

	// ModeServer runs the single-tenant PostgreSQL + authenticated HTTP path.
	// cmd/cortex is the sole bridge to the server composition root.
	ModeServer Mode = "server"
)
const DefaultMode Mode = ModeLocal

DefaultMode is used when no --mode flag is provided on the command line.

func ParseMode

func ParseMode(args []string) (Mode, []string)

ParseMode is the two-value compatibility surface used by cmd/cortex. It delegates to ParseModeStrict and drops the error: an unknown value yields the raw rejected Mode, which never satisfies Mode.Valid(), so the caller's switch default fails closed while still enumerating the three valid modes.

New callers that can surface a startup error must use ParseModeStrict.

func ParseModeStrict added in v2.4.0

func ParseModeStrict(args []string) (Mode, []string, error)

ParseModeStrict extracts the --mode flag from args and validates it against the closed triad. It returns the resolved Mode, a copy of args with the flag removed, and a non-nil error for any value outside the triad.

Both syntactic forms are accepted:

cortex --mode local <command>    (space-separated)
cortex --mode=local <command>    (equals form)

The flag may appear before or after the subcommand. When --mode is absent, DefaultMode (ModeLocal) is returned and args are returned unchanged (same slice values, no allocation).

Unknown values fail closed: the returned error enumerates the three valid modes and args are returned unchanged, so a caller can abort startup without observing a partially parsed command line.

func (Mode) Valid added in v2.4.0

func (m Mode) Valid() bool

Valid reports whether m is one of the three closed-set triad modes.

type Runtime

type Runtime struct {
	// App is the local-mode composition root from internal/app.
	// Non-nil when Mode == ModeLocal || Mode == ModeHybrid; nil for server mode.
	App *app.App
}

Runtime holds the wired services for the selected Mode.

This type is the local composition selector. The server runtime is owned by internal/platform/server and wired directly by cmd/cortex.

func Local

func Local(ctx context.Context, opts app.Options) (*Runtime, error)

Local wires the local-mode Runtime by delegating to app.Open.

This function MUST NOT duplicate or alter app wiring. It calls app.Open with the exact same (ctx, opts) arguments, preserving byte-identical local behavior: the same SQLite database, the same store bundle, the same config defaults, the same archival lifecycle, the same stdio-MCP transport.

The returned Runtime wraps the *app.App unchanged.

func Select

func Select(mode Mode, ctx context.Context, opts app.Options) (*Runtime, error)

Select wires the Runtime for the given Mode.

ModeLocal, ModeHybrid → delegates to Local, which calls app.Open byte-identically (same SQLite database, same stores, same config defaults). Hybrid carries no extra wiring here: replication is started by internal/app itself when it observes the hybrid composition.

ModeServer returns an error because this local-only API intentionally cannot import the server composition root. cmd/cortex performs that bridge.

func (*Runtime) Close

func (r *Runtime) Close() error

Close releases resources held by the Runtime.

Directories

Path Synopsis
Hand-rolled Prometheus text exposition (v0.0.4) for the server runtime: a tiny registry of sync/atomic counters plus render-time gauges.
Hand-rolled Prometheus text exposition (v0.0.4) for the server runtime: a tiny registry of sync/atomic counters plus render-time gauges.

Jump to

Keyboard shortcuts

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