chatguard

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 6 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 chatguard is what a machine's runtime does about the chat's typing while the machine's local policy keeps the terminal switched off for the hub.

The machine agent's route filter refuses the routes of a terminal, but the chat page's own routes (a message, a queued message, "send now", an answer) type into the tmux pane of a conversation, and a pane is a terminal when the agent in it has gone: the text would be read by a shell and run. Claude Code's bash mode (a message that starts with "!") runs the rest of the line as a command without asking either. The filter cannot see a pane, so the agent tells the runtime when the terminal is off (POST <agent API>/policy, see cmd/runtime/hub_routes.go), and the runtime refuses at the source: text goes only into a pane where an agent runs, and never as a bash-mode line.

Index

Constants

This section is empty.

Variables

View Source
var ErrTerminalOff = errors.New("the terminal is switched off on this machine: text goes only into a running agent, and not as a shell command")

ErrTerminalOff is what a refused write says.

Functions

func AgentInForeground

func AgentInForeground(command string) bool

AgentInForeground says that a program other than a bare shell runs in the foreground of the pane; false when tmux did not say (an empty command), as the answer of a loaded machine proves nothing.

func BashMode

func BashMode(text string) bool

BashMode says that an agent reads the text as a shell command: Claude Code (and Codex) enter their bash mode on a "!" at the start of the input. Whitespace and invisible format characters before it are skipped, since a paste or an editor may trim them, and it costs nothing to refuse a line that merely looks like one.

func Guarded

func Guarded(p typist.Pane, g *Guard, foreground func() string) typist.Pane

Guarded is the pane as the conversations type into it: every write is checked against the pane's foreground program (foreground reads it) while the terminal is off, and refused with ErrTerminalOff when that is a shell. With the terminal on it is the pane itself.

Types

type Guard

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

Guard says whether the terminal is switched off. The zero value, and a nil *Guard, is on: a runtime without a hub asks nobody. A runtime a hub carries starts with it off (New(true)) until the machine agent has said what the policy is, so that the minutes after a restart are not an open door.

func New

func New(off bool) *Guard

New makes a Guard that starts off or on.

func (*Guard) Func

func (g *Guard) Func() func() bool

Func is Off as a function, for the places that take one (nil for a nil Guard).

func (*Guard) Off

func (g *Guard) Off() bool

Off says whether the terminal is switched off.

func (*Guard) Set

func (g *Guard) Set(off bool)

Set records what the machine agent said.

Jump to

Keyboard shortcuts

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