localmost

package
v0.69.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package localmost is a clean-room, behaviourally-compatible reimplementation of the federicotdn/localmost rule engine. It evaluates a shell command against allow/deny rules loaded from a localmost-format config.json and returns one of three policies: allow, ask, or deny.

It is written from localmost's public documentation (its README and docs/examples.md), NOT from its GPL-3.0 Haskell source. Behavioural parity is validated by a conformance corpus rather than bit-identical parsing (graith uses mvdan.cc/sh where localmost uses ShellCheck). Known divergences are tracked in docs/design/2026-07-03-pluggable-approvals-backends-design.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine evaluates commands against compiled allow/deny rules.

func Load

func Load(path string) (*Engine, error)

Load reads and compiles a localmost-format config.json from path.

func Parse

func Parse(data []byte) (*Engine, error)

Parse compiles a localmost-format config from raw JSON bytes.

func (*Engine) AskNoninteractive

func (e *Engine) AskNoninteractive() bool

AskNoninteractive reports the config's askNoninteractive setting (default true). When false, callers should turn an "ask" into a "deny" in non-interactive contexts.

func (*Engine) Evaluate

func (e *Engine) Evaluate(command string) (Policy, error)

Evaluate parses a shell command into subcommands and returns the combined policy: deny if any subcommand is denied, allow if all are allowed, otherwise ask. A parse failure is treated as ask (fail-safe to the human).

type Policy

type Policy string

Policy is the result of evaluating a command.

const (
	PolicyAllow Policy = "allow"
	PolicyAsk   Policy = "ask"
	PolicyDeny  Policy = "deny"
)

type Rule

type Rule struct {
	Rule     string
	Unless   []string
	Redirect redirectPolicy
	Pipe     pipePolicy
}

Rule is a single allow/deny rule from the config.

func (*Rule) UnmarshalJSON

func (r *Rule) UnmarshalJSON(b []byte) error

UnmarshalJSON parses a rule, applying localmost's defaults (redirect="safe", pipe=true) and accepting the bool/string forms of the redirect and pipe keys. A rule may be given either as an object ({"rule":"..."}) or, as a convenience, as a bare string ("...").

Jump to

Keyboard shortcuts

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