dcg

package
v0.98.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package dcg integrates Destructive Command Guard (dcg) as a pre-exec check for chat agent run_terminal and run_code tools.

Index

Constants

View Source
const ReasonBlocked = "command blocked by dcg"

ReasonBlocked is the default denial message when dcg omits a reason.

Variables

This section is empty.

Functions

func CommandForTool

func CommandForTool(tool string, args map[string]any) (command string, ok bool, err error)

CommandForTool extracts the command string to check for a tool call. ok is false when the tool is not guarded by dcg (caller should skip).

func Init

func Init()

Init installs the process-wide BinaryChecker using the embedded config. When dcg is missing from PATH it logs a warning and installs an ErrorChecker so the first guarded tool call fails closed.

func MaterializeConfig

func MaterializeConfig() (string, error)

MaterializeConfig writes the embedded dcg.toml to a temp file once and returns its path.

func SetDefaultChecker

func SetDefaultChecker(c Checker)

SetDefaultChecker installs the process-wide checker used when ChatHookDeps.DCG is nil.

func StripBypassEnv

func StripBypassEnv(env []string) []string

StripBypassEnv returns env without DCG_BYPASS entries.

func SynthCommand

func SynthCommand(language, code string) (string, error)

SynthCommand builds a shell-shaped command string for dcg from run_code inputs. Language aliases match pkg/agent/coding run_code interpreters.

func TruncateCommandForLog

func TruncateCommandForLog(command string) string

TruncateCommandForLog shortens command strings for log lines.

Types

type AllowAllChecker

type AllowAllChecker struct{}

AllowAllChecker permits every command (tests).

func (AllowAllChecker) Check

Check implements Checker.

type BinaryChecker

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

BinaryChecker invokes the dcg CLI with --robot test.

func NewBinaryChecker

func NewBinaryChecker(opts BinaryCheckerOptions) *BinaryChecker

NewBinaryChecker builds a Checker that shells out to dcg.

func (*BinaryChecker) Check

func (c *BinaryChecker) Check(ctx context.Context, command string) (Decision, error)

Check runs dcg --robot test against command.

type BinaryCheckerOptions

type BinaryCheckerOptions struct {
	// Path is the dcg executable path; empty uses LookPath("dcg").
	Path string
	// ConfigPath is passed as --config; required for production use.
	ConfigPath string
	// Runner overrides process execution (tests).
	Runner commandRunner
}

BinaryCheckerOptions configures NewBinaryChecker.

type Checker

type Checker interface {
	// Check returns a Decision for command, or an error for fail-closed failures.
	Check(ctx context.Context, command string) (Decision, error)
}

Checker evaluates a shell command string before execution.

func DefaultChecker

func DefaultChecker() Checker

DefaultChecker returns the process-wide checker.

type Decision

type Decision struct {
	// Allow is true when dcg permits the command.
	Allow bool
	// Reason explains a denial when Allow is false.
	Reason string
	// RuleID is the matching dcg rule identifier when present.
	RuleID string
	// PackID is the matching dcg pack identifier when present.
	PackID string
}

Decision is the outcome of a dcg command evaluation.

type DenyChecker

type DenyChecker struct {
	// Reason is returned on denial.
	Reason string
}

DenyChecker denies every command with Reason (tests).

func (DenyChecker) Check

Check implements Checker.

type ErrorChecker

type ErrorChecker struct {
	// Err is returned from Check; nil uses a default message.
	Err error
}

ErrorChecker always fails closed.

func (ErrorChecker) Check

Check implements Checker.

Jump to

Keyboard shortcuts

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