secretaction

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 17 Imported by: ? 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 secretaction lets the owner hand a password to one exact action the agent prepared — a command on a PTY or a field in the browser — without the value ever reaching the model, the transcript, the bus or the disk.

The request (what the card shows) is ordinary, non-secret metadata and may travel like any other pending approval. The answer does not: it goes from the HTTP handler straight into the waiting tool through an in-memory channel owned by the Broker, and the tool wipes it when its execution ends.

Index

Constants

View Source
const (
	KindCommand = "command"
	KindBrowser = "browser"
)

Request kinds.

View Source
const (
	FieldPassword = "password"
	FieldUsername = "username"
	FieldText     = "text"
)

Field kinds.

View Source
const (
	// MaxFields bounds the values one action may ask for.
	MaxFields = 4
	// MaxValueBytes bounds one value.
	MaxValueBytes = 16 << 10
)
View Source
const BrowserFillToolName = "browser_fill_secret"

BrowserFillToolName is the model-facing name of the browser tool.

View Source
const Placeholder = "[secret]"

Placeholder replaces every delivered value in output.

Variables

View Source
var (
	ErrUnknownRequest = errors.New("unknown secret request")
	ErrMissingValue   = errors.New("a value is required for every field")
	ErrInvalidValue   = errors.New("invalid secret value")
)

Functions

func BrowserFingerprint

func BrowserFingerprint(origin string, fields []Field, submit bool) string

BrowserFingerprint identifies a browser fill action: hex sha256 over the canonical JSON of {kind, origin, fields:[{realLabel, realType, kind}], submit}. Only what the server observed counts, not the model's words.

func CommandFingerprint

func CommandFingerprint(command, cwd, host string) string

CommandFingerprint identifies a command action: hex sha256 over the canonical JSON of {kind, command, cwd, host}. The phone compares it with the fingerprint it saved a value under to tell "exactly the same action".

func DecodeJSONString

func DecodeJSONString(raw []byte) ([]byte, error)

DecodeJSONString decodes a JSON string literal into a fresh []byte the caller can wipe, without going through an immutable Go string (which encoding/json would produce and nobody could zero).

func EscapedVariants

func EscapedVariants(values [][]byte) [][]byte

EscapedVariants returns copies of values plus the escaped forms a browser tool may echo them in: as a JSON string body and as a single-quoted JS string body (Playwright prints `fill('<value>')`). The caller wipes them.

func ParseSSHHost

func ParseSSHHost(command string) string

ParseSSHHost returns the host the first `ssh` invocation in command connects to (without user or port), or "". Best effort, for the card only: it splits words on whitespace and shell separators and understands quotes just enough to skip quoted arguments.

func RedactString

func RedactString(s string, values [][]byte) string

RedactString redacts a complete text in one go.

func Requester

func Requester(ctx context.Context) string

Requester names who asks: "main" or "subagent · <job id>". Subagents run their tools under a context tagged with their job ID.

func SyncBrowserFillTool

func SyncBrowserFillTool(reg *core.Registry, broker *Broker)

SyncBrowserFillTool registers browser_fill_secret when the registry holds an MCP server exposing both browser_type and browser_evaluate (Playwright), and removes it when none does. Call it whenever MCP tools change.

func ValidFieldKind

func ValidFieldKind(kind string) bool

ValidFieldKind reports whether kind is one of the field kinds.

func ValidateField

func ValidateField(label, kind, alias string) error

ValidateField checks the model-supplied card text of one field.

func Wipe

func Wipe(b []byte)

Wipe zeroes b.

Types

type Answer

type Answer struct {
	Allow  bool
	Values [][]byte
}

Answer is the owner's decision. Values are indexed like Request.Fields and belong to the receiver, which must Wipe them.

func (*Answer) Wipe

func (a *Answer) Wipe()

Wipe zeroes every value. Best effort: Go may have copied the bytes before.

type Broker

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

Broker holds the pending requests of one session. It is the only path an answer takes: Resolve hands copies of the values to the goroutine blocked in Request through a buffered channel, and nothing else sees them.

func NewBroker

func NewBroker(sessionID string) *Broker

NewBroker creates the broker of a session.

func (*Broker) IsPending

func (b *Broker) IsPending(id string) bool

IsPending reports whether id is still waiting.

func (*Broker) Pending

func (b *Broker) Pending() []Request

Pending lists the open requests, oldest first.

func (*Broker) Request

func (b *Broker) Request(ctx context.Context, req Request) (Answer, error)

Request publishes req and blocks until the owner answers or ctx ends. The returned values belong to the caller, who must Wipe the Answer.

func (*Broker) Resolve

func (b *Broker) Resolve(id string, allow bool, values [][]byte) error

Resolve answers a pending request. values are indexed like the request's fields; on allow every field needs a non-empty value. The broker copies them: the caller keeps (and must wipe) its own slices whatever the result.

func (*Broker) SetHooks

func (b *Broker) SetHooks(onRequest func(Request), onResolved func(id string, answered bool))

SetHooks installs the notifications of a request appearing and going away (answered reports an allow/deny rather than a cancellation). They receive no values. Either may be nil.

type Field

type Field struct {
	Index        int    `json:"index"`
	Label        string `json:"label"`
	Kind         string `json:"kind"`
	Alias        string `json:"alias,omitempty"`
	Element      string `json:"element,omitempty"`
	RealLabel    string `json:"realLabel,omitempty"`
	RealType     string `json:"realType,omitempty"`
	Autocomplete string `json:"autocomplete,omitempty"`
}

Field is one value the action needs, as the card shows it. It never carries the value.

type Redactor

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

Redactor replaces exact values in a stream whose chunks may split a value. Every byte inside any occurrence of any value is covered, overlapping occurrences included, and each run of overlapping occurrences becomes one placeholder: a value that starts inside another cannot leave a tail behind. It holds back the shortest tail that could still become a value, so a value cut between two chunks is redacted once its end arrives. Redaction prevents accidental echoes (a terminal with echo on, an error message); it is not a defence against a command written to exfiltrate what it reads.

func NewRedactor

func NewRedactor(values [][]byte) *Redactor

NewRedactor builds a redactor over values (empty ones are ignored). It keeps references to values, not copies: wiping them later is enough.

func (*Redactor) Flush

func (r *Redactor) Flush() []byte

Flush returns whatever was held back, redacted, and forgets it.

func (*Redactor) Write

func (r *Redactor) Write(p []byte) []byte

Write ingests p and returns the bytes that are safe to emit now. The returned slice is fresh; p is not retained.

type Request

type Request struct {
	ID                string    `json:"id"`
	SessionID         string    `json:"sessionId"`
	Requester         string    `json:"requester"`
	Kind              string    `json:"kind"`
	Command           string    `json:"command,omitempty"`
	Cwd               string    `json:"cwd,omitempty"`
	SSHHost           string    `json:"sshHost,omitempty"`
	Origin            string    `json:"origin,omitempty"`
	Submit            bool      `json:"submit,omitempty"`
	ActionFingerprint string    `json:"actionFingerprint"`
	Fields            []Field   `json:"fields"`
	RequestedAt       time.Time `json:"requestedAt"`
}

Request is what the owner approves. Every field is fixed when the request is created, so what the card shows is what runs.

Jump to

Keyboard shortcuts

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