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
- Variables
- func BrowserFingerprint(origin string, fields []Field, submit bool) string
- func CommandFingerprint(command, cwd, host string) string
- func DecodeJSONString(raw []byte) ([]byte, error)
- func EscapedVariants(values [][]byte) [][]byte
- func ParseSSHHost(command string) string
- func RedactString(s string, values [][]byte) string
- func Rememberable(req Request) bool
- func Requester(ctx context.Context) string
- func SyncBrowserFillTool(reg *core.Registry, broker *Broker)
- func ValidFieldKind(kind string) bool
- func ValidateField(label, kind, alias string) error
- func ValidateRemember(keys []MemoryKey, values [][]byte) error
- func Wipe(b []byte)
- type Answer
- type Broker
- func (b *Broker) IsPending(id string) bool
- func (b *Broker) Pending() []Request
- func (b *Broker) Request(ctx context.Context, req Request) (Answer, error)
- func (b *Broker) Resolve(id string, allow bool, values [][]byte) error
- func (b *Broker) ResolveHold(id string, values [][]byte, hold time.Duration, epoch uint64) error
- func (b *Broker) SessionID() string
- func (b *Broker) SetHooks(onRequest func(Request), onResolved func(id string, answered bool))
- type Field
- type Memory
- func (m *Memory) AuthFailed(key MemoryKey, gen uint64)
- func (m *Memory) Dispatch(key MemoryKey, gen uint64, write func() error) (bool, error)
- func (m *Memory) Epoch() uint64
- func (m *Memory) Forget(alias string) bool
- func (m *Memory) ForgetAll()
- func (m *Memory) RememberMany(keys []MemoryKey, values [][]byte, d time.Duration, epoch uint64, by MemoryUse) (gens []uint64, until time.Time, err error)
- func (m *Memory) Shutdown()
- func (m *Memory) Status() MemoryStatus
- func (m *Memory) TakeAll(keys []MemoryKey, use MemoryUse) (values [][]byte, gens []uint64, until time.Time, ok bool)
- type MemoryEntry
- type MemoryKey
- type MemoryStatus
- type MemoryUse
- type Redactor
- type Request
Constants ¶
const ( KindCommand = "command" KindBrowser = "browser" )
Request kinds.
const ( FieldPassword = "password" FieldUsername = "username" FieldText = "text" )
Field kinds.
const ( // MaxFields bounds the values one action may ask for. MaxFields = 4 // MaxValueBytes bounds one value. MaxValueBytes = 16 << 10 )
const ( // MaxHoldHours bounds how long a value is remembered. MaxHoldHours = 10 // MaxHoldValueBytes bounds a remembered value, so typing it holds the // lock only briefly. MaxHoldValueBytes = 1024 )
const ( UseRemember = "remember" UseRun = "use" )
Use kinds.
const BrowserFillToolName = "browser_fill_secret"
BrowserFillToolName is the model-facing name of the browser tool.
const Placeholder = "[secret]"
Placeholder replaces every delivered value in output.
Variables ¶
var ( ErrUnknownRequest = errors.New("unknown secret request") ErrMissingValue = errors.New("a value is required for every field") ErrInvalidValue = errors.New("invalid secret value") )
var ( ErrForgotten = errors.New("the owner forgot remembered secrets after approving") ErrHoldDuration = fmt.Errorf("must be between 1 and %d hours", MaxHoldHours) ErrHoldValue = fmt.Errorf("each value must be 1 to %d bytes", MaxHoldValueBytes) ErrHoldConflict = errors.New("two fields of the same credential have different values") ErrNotRememberer = errors.New("this request cannot be remembered") )
Functions ¶
func BrowserFingerprint ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
RedactString redacts a complete text in one go.
func Rememberable ¶ added in v0.49.0
Rememberable reports whether a value for req may be remembered or recalled: a command whose every field names its credential by alias.
func Requester ¶
Requester names who asks: "main" or "subagent · <job id>". Subagents run their tools under a context tagged with their job ID.
func SyncBrowserFillTool ¶
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 ¶
ValidFieldKind reports whether kind is one of the field kinds.
func ValidateField ¶
ValidateField checks the model-supplied card text of one field.
func ValidateRemember ¶ added in v0.49.0
ValidateRemember checks values for keys before anything is resolved or stored: bounded, and the same value wherever a key repeats.
Types ¶
type Answer ¶
type Answer struct {
Allow bool
Values [][]byte
// Hold > 0 asks to remember the values for that long; HoldEpoch is the
// Memory epoch when the owner approved.
Hold time.Duration
HoldEpoch uint64
}
Answer is the owner's decision. Values are indexed like Request.Fields and belong to the receiver, which must Wipe them.
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 (*Broker) Request ¶
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 ¶
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) ResolveHold ¶ added in v0.49.0
ResolveHold allows a request and asks the tool to remember its values for hold. The request must be Rememberable.
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 Memory ¶ added in v0.49.0
type Memory struct {
// contains filtered or unexported fields
}
Memory holds the remembered values. Use NewMemory.
func (*Memory) AuthFailed ¶ added in v0.49.0
AuthFailed forgets entry (key, gen) after the program it was typed into evidently rejected it. A newer value under the same key is left alone.
func (*Memory) Dispatch ¶ added in v0.49.0
Dispatch runs write (typing a value into a terminal) only while entry (key, gen) is still remembered and unexpired, holding the lock so Forget cannot return in between. write must bound its own duration. It reports whether write ran, and write's error.
func (*Memory) Epoch ¶ added in v0.49.0
Epoch names the Forgets seen so far. An approval captures it, and RememberMany refuses it once any Forget has happened in between.
func (*Memory) Forget ¶ added in v0.49.0
Forget drops every kind remembered under alias and fences approvals in flight. It returns whether anything was dropped.
func (*Memory) ForgetAll ¶ added in v0.49.0
func (m *Memory) ForgetAll()
ForgetAll drops everything and fences approvals in flight.
func (*Memory) RememberMany ¶ added in v0.49.0
func (m *Memory) RememberMany(keys []MemoryKey, values [][]byte, d time.Duration, epoch uint64, by MemoryUse) (gens []uint64, until time.Time, err error)
RememberMany keeps copies of values (indexed like keys) for d, all or none, replacing what was remembered under the same keys. gens is indexed like keys.
func (*Memory) Shutdown ¶ added in v0.49.0
func (m *Memory) Shutdown()
Shutdown wipes everything when the server stops.
func (*Memory) Status ¶ added in v0.49.0
func (m *Memory) Status() MemoryStatus
Status reports the remembered credentials and their uses, never a value.
func (*Memory) TakeAll ¶ added in v0.49.0
func (m *Memory) TakeAll(keys []MemoryKey, use MemoryUse) (values [][]byte, gens []uint64, until time.Time, ok bool)
TakeAll returns fresh copies of the values for keys (indexed like keys) and records one use, only if every key is remembered and unexpired. until is the earliest deadline among them. The caller wipes the copies.
type MemoryEntry ¶ added in v0.49.0
type MemoryEntry struct {
MemoryKey
RememberedAt time.Time `json:"rememberedAt"`
ExpiresAt time.Time `json:"expiresAt"`
Uses int `json:"uses"`
}
MemoryEntry describes one remembered credential.
type MemoryKey ¶ added in v0.49.0
MemoryKey names one remembered credential.
func MemoryKeys ¶ added in v0.49.0
MemoryKeys returns the key of each field, in field order.
type MemoryStatus ¶ added in v0.49.0
type MemoryStatus struct {
Entries []MemoryEntry `json:"entries"`
Uses []MemoryUse `json:"uses"`
UsesDropped int `json:"usesDropped,omitempty"`
}
MemoryStatus is what the owner's clients see.
type MemoryUse ¶ added in v0.49.0
type MemoryUse struct {
At time.Time `json:"at"`
Kind string `json:"kind"`
Keys []MemoryKey `json:"keys"`
SessionID string `json:"sessionId"`
Requester string `json:"requester"`
Command string `json:"command"`
Cwd string `json:"cwd,omitempty"`
}
MemoryUse is one entry of the record. It never holds a 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 ¶
NewRedactor builds a redactor over values (empty ones are ignored). It keeps references to values, not copies: wiping them later is enough.
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"`
// HoldMaxHours > 0 offers the owner to remember the values for up to
// that many hours (see Memory); only set on Rememberable requests.
HoldMaxHours int `json:"holdMaxHours,omitempty"`
}
Request is what the owner approves. Every field is fixed when the request is created, so what the card shows is what runs.