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 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 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) SetHooks(onRequest func(Request), onResolved func(id string, answered bool))
- type Field
- 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 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 ¶
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 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.
Types ¶
type Answer ¶
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.
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 ¶
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"`
}
Request is what the owner approves. Every field is fixed when the request is created, so what the card shows is what runs.