selfcheck

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 13 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 selfcheck implements the boot-time verification that permissions.defaultMode "deny" in the per-spawn settings file still enforces the whitelist when claude is spawned in interactive mode.

The Phase A spike (#329) verified empirically that under {"permissions":{"allow":["Read"],"defaultMode":"deny"}} a prompt asking for Bash gets refused (no tool_use with name=="Bash" appears in claude's session JSONL). That contract is load-bearing on a single Anthropic- controlled string; if defaultMode is renamed, removed, or the schema otherwise drifts, the per-agent security boundary the dispatcher relies on silently dissolves.

SelfCheckDenyDefault spawns a throwaway claude under deny-default settings, drives the canonical "Use Bash to echo hello" prompt, watches the on-disk JSONL via internal/agentrun/jsonl/tail, and returns a structured Result. The CLI wrapper at cmd/pyry/agent_run_selfcheck.go renders that Result as PASS / FAIL / inconclusive for operator + CI consumption.

This package lives in a sub-package of agentrun (not in agentrun itself) because internal/agentrun/jsonl/tail already imports agentrun for EncodeProjectDir; placing the helper inside agentrun would create an import cycle. The package boundary is still "primitives used by pyry agent-run to verify claude's environment", consistent with the architect's intent.

SECURITY: this package MUST NOT log Event.Raw bytes or claude stdout/stderr at any layer — the canned prompt is operator-controlled only for tests, but the assistant's response may carry operator- meaningful context. The Result.Evidence field is the explicit exception: it is the load-bearing security finding on FAIL.

Index

Constants

This section is empty.

Variables

View Source
var ErrBashInvoked = errors.New("agentrun: self-check: Bash invoked despite deny-default settings")

ErrBashInvoked is returned (wrapped) by SelfCheckDenyDefault when the watcher observed a tool_use content block named "Bash". The boundary failed; the deny-default whitelist did NOT enforce.

View Source
var ErrTimeout = errors.New("agentrun: self-check: overall timeout")

ErrTimeout is returned when the overall timeout fires before either an end-of-turn signal or a Bash invocation was observed. Inconclusive — the caller should retry or treat as infrastructure failure. Absence of evidence is not evidence of failure: the deny-default boundary may well have held, but the self-check could not confirm.

Functions

This section is empty.

Types

type Config

type Config struct {
	ClaudeBin string       // required; claude executable path
	HomeDir   string       // required; trust-dialog write target and JSONL root
	Workdir   string       // required; must exist and contain the settings file
	Prompt    string       // optional; defaults to canonicalPrompt
	Logger    *slog.Logger // optional; defaults to slog.Default()

	// TrustDialogDelay and PromptDelay are exposed for unit tests. Zero
	// values fall back to the production defaults inherited from Drive.
	TrustDialogDelay time.Duration
	PromptDelay      time.Duration

	// OverallTimeout caps the whole self-check, including spawn + drive +
	// watch. Zero defaults to defaultSelfCheckTimeout. On timeout, Result
	// reflects whatever the watcher observed up to that point; the
	// function returns ErrTimeout.
	OverallTimeout time.Duration

	// Env is appended to os.Environ() in the spawned child. Tests use this
	// to thread fake-claude wiring. Production leaves it nil.
	Env []string
}

Config parameterises SelfCheckDenyDefault.

Pre-condition: Workdir must exist and must already contain `.pyry-agent-run-settings.json` — the caller owns the settings shape. The production CLI uses agentrun.WriteSettings to write the canonical deny-default shape; tests inject bogus shapes (e.g. defaultMode "DENY" uppercase) to exercise the detector against runtime enforcement, not against file-content presence.

type Result

type Result struct {
	// BashInvoked is true iff a content-block tool_use with name "Bash"
	// was observed on any assistant entry during the run.
	BashInvoked bool

	// Evidence is the verbatim Raw bytes of the first assistant entry
	// where a Bash tool_use appeared. nil on PASS.
	Evidence json.RawMessage

	// EndOfTurnObserved is true iff the watcher's OnEndOfTurn fired
	// before the context ended.
	EndOfTurnObserved bool

	// AssistantCount counts assistant Events observed (informational).
	AssistantCount int
}

Result captures what the self-check observed. Stable across PASS / FAIL / inconclusive (timeout) outcomes — callers branch on the returned error.

func SelfCheckDenyDefault

func SelfCheckDenyDefault(ctx context.Context, cfg Config) (Result, error)

SelfCheckDenyDefault spawns claude under cfg, drives the canonical "Use Bash to echo hello" prompt, and reports whether the deny-default whitelist enforced refusal of Bash.

Pre-condition: cfg.Workdir exists and contains `.pyry-agent-run-settings.json`. The trust dialog for cfg.Workdir is pre-accepted by this function (via agentrun.MarkWorkdirTrusted). A zero-byte system-prompt file is written to cfg.Workdir so the --append-system-prompt-file contract is satisfied without leaking operator context.

Returns (Result, nil) on PASS: no Bash tool_use observed and end-of-turn fired. Returns (Result, ErrBashInvoked-wrapped) on FAIL: a Bash tool_use was observed. Returns (Result, ErrTimeout) on inconclusive. Returns (Result, other) on infrastructure failure (spawn, I/O, write, etc.).

Jump to

Keyboard shortcuts

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