Documentation
¶
Overview ¶
Package toolplane serves the AI plane's one tool, shell_read: a command run in ADR 0018's read-only sandbox, reaching data only through the read brokers (ADR 0019). Writes go through the recorded console instead.
Every call, served or refused, is written to a local append-only log the customer can read. The node's action level and consent files are still read and reported in the Hello; the Advisor applies them.
Index ¶
- Constants
- Variables
- func SandboxArgv(command string, timeout time.Duration) []string
- func SandboxArgvFor(command string, timeout time.Duration, callID string) []string
- func WriteConsent(dir, c string) error
- func WriteLevel(dir, level string) error
- type Auditor
- type Consent
- type FileAuditor
- type Level
- type Option
- type Registry
- func (r *Registry) Call(ctx context.Context, name string, args map[string]string) ([]byte, error)
- func (r *Registry) Consent() Consent
- func (r *Registry) Level() Level
- func (r *Registry) Names() []string
- func (r *Registry) SetRunnerForTest(fn func(ctx context.Context, argv []string, maxBytes int) ([]byte, error))
- type Tool
- type ToolCall
Constants ¶
const ConsentFileName = "consent"
ConsentFileName is the file in the agent's own directory that says how much this cluster asks a person before acting (ADR 0011, amended).
Beside the action level, and for the same reasons: the directory already exists per cluster, is owned by the customer, and has its modes enforced. The two dials are separate files rather than one because they are separate decisions — an operator raising what the assistant may do and an operator deciding when to be asked are different acts, and a single file would make changing one a rewrite of both.
const DefaultAuditPath = "/var/log/cube-advisor-agent/tool-calls.jsonl"
DefaultAuditPath is where the log lands on a CubeCOS node.
const DefaultConsent = ConsentAlways
DefaultConsent is what this agent requires when the cluster has said nothing. ADR 0011's "unset means always", named so the fail-closed choice is greppable rather than inferred from a zero value.
const DefaultLevel = LevelObserve
DefaultLevel is what this agent serves when the cluster has said nothing. ADR 0011's "unset means observe", named so the fail-closed choice is greppable rather than inferred from a zero value.
const LevelFileName = "action-level"
LevelFileName is the file in the agent's own directory that names this cluster's action level (ADR 0011). It sits beside the enrollment identity because that directory already exists per cluster, is owned by the customer, and already has its modes enforced — so the authoritative level needs no new distribution mechanism and arrives with the same custody as the key.
const SandboxCommandArg = "command"
SandboxCommandArg is the one argument a sandbox tool takes: the command text.
Variables ¶
var ( ErrUnknownTool = errors.New("toolplane: no such tool") ErrBadArgument = errors.New("toolplane: argument not permitted") )
Errors a caller may distinguish. They are deliberately coarse: the SaaS is told that a call was refused, never which check refused it, because a precise refusal is a probe oracle.
var ErrOutputTruncated = errors.New("toolplane: output truncated")
ErrOutputTruncated is how a runner reports that a command emitted more than the cap. Call converts it into a successful, marked result rather than a failure: the first half-megabyte of a log is evidence, silence is not.
var ErrToolTimedOut = errors.New("toolplane: tool exceeded its time limit")
ErrToolTimedOut distinguishes a tool that ran out of time from one that crashed. Without it, a killed process reports "signal: killed" — the same shape as a real failure — and neither the audit log nor an operator can tell a slow cluster from a broken one.
var SandboxBrokerDir string
SandboxBrokerDir is the broker directory bound into the sandbox (ADR 0019); empty means no brokers.
var Tools = []Tool{ { Name: "shell_read", Description: "Run a command in the read-only sandbox; anything that changes the system fails.", Sandbox: true, MaxOutputBytes: 64 << 10, Timeout: 60 * time.Second, }, }
Tools is every tool the agent serves.
Functions ¶
func SandboxArgv ¶
SandboxArgv is the argv that runs command in ADR 0018's read-only sandbox: a transient systemd unit with a read-only filesystem, a private /tmp, read-only block devices, no network, only the read-only DAC capability, setuid ignored, and credentials and control sockets hidden. No network because CubeCOS runs Ceph with cephx off, so any networked read could also write; network reads are declared tools.
func SandboxArgvFor ¶
SandboxArgvFor is SandboxArgv with the run's id, passed to the brokers so their audit records name the run that called them.
func WriteConsent ¶
WriteConsent records the consent setting beside the identity.
func WriteLevel ¶
WriteLevel records the action level beside the identity, validated first so an Advisor cannot leave the node with a word ReadLevel refuses.
Types ¶
type Consent ¶
type Consent int
Consent names how much this cluster asks a person before a call runs.
It mirrors the Advisor's vocabulary (cube-ai-advisor internal/consent). The words are a recorded format, so ParseConsent must accept exactly what String produces. The agent reports it in the Hello; the Advisor applies it.
const ( // ConsentNever asks nobody. The cluster acts within its action level // unattended. ConsentNever Consent = iota + 1 // ConsentDestructive asks only for destructive calls. ConsentDestructive // ConsentAlways asks for every call above a read. What an unconfigured // cluster gets. ConsentAlways )
func ParseConsent ¶
ParseConsent reads a recorded value, returning DefaultConsent alongside any error so a caller that logs and continues continues asking for everything rather than at an invalid setting.
func ReadConsent ¶
ReadConsent reads the cluster's consent setting from dir.
Absent, empty and whitespace all mean DefaultConsent and are not errors, for the reason ReadLevel gives: nobody expressed an intent, an empty file is what a half-finished write leaves, and the answer they get is the cautious one.
A word that is not a setting *is* an error, and loudly. An operator who wrote "none" meaning "never" has a cluster that asks about everything while they believe it asks about nothing — the reverse of the level's failure, and just as much a surprise. The value returned alongside is still DefaultConsent.
A file others may write is refused, for a sharper reason than the level's: whoever can write this file can stop a cluster asking a person before it acts. Readability is deliberately unconstrained — like the level this is a policy statement its customer should be able to read without root, and it holds no secret.
type FileAuditor ¶
type FileAuditor struct {
// contains filtered or unexported fields
}
FileAuditor appends JSON lines to a file on the cluster.
Local and append-only on purpose: the record of what the vendor did lives on the customer's own machine, readable with `cat`, and does not depend on the SaaS to be honest about it.
func NewFileAuditor ¶
func NewFileAuditor(path string) (*FileAuditor, error)
NewFileAuditor opens (creating if needed) an append-only log.
func NewWriterAuditor ¶
func NewWriterAuditor(w io.WriteCloser) *FileAuditor
NewWriterAuditor writes records to w. Used by tests and by callers that already own a log sink.
func (*FileAuditor) Close ¶
func (a *FileAuditor) Close() error
func (*FileAuditor) RecordToolCall ¶
func (a *FileAuditor) RecordToolCall(c ToolCall)
type Level ¶
type Level int
Level names how far the SaaS may go on this cluster.
It mirrors the Advisor's vocabulary (cube-ai-advisor internal/actionlevel). These words are a recorded format, so ParseLevel must accept exactly what String produces. The values start at 1 so the zero value is "unset".
func ParseLevel ¶
ParseLevel reads a recorded level, returning DefaultLevel alongside any error so a caller that logs and continues continues at the most restrictive level rather than an invalid one.
func ReadLevel ¶
ReadLevel reads the cluster's action level from dir.
Three absences are not errors, and all three answer DefaultLevel: no file, an empty file, and a file of whitespace. Nobody expressed an intent in any of them — an empty file is what a half-finished write leaves — and the answer they get is the restrictive one, so treating them as configuration would add noise without adding safety. This mirrors LoadServer in internal/identity, where a missing file means "not configured yet" rather than "broken".
A word that is not a level *is* an error, and the loudest thing this function can do is return one. Someone wrote something meaning something and it is not being honoured: a cluster whose file says "operator" is serving reads while its operator believes otherwise, and silence there is the failure mode a level exists to prevent. The value returned alongside is still DefaultLevel, so a caller that mishandles the error is mishandling it safely.
A file others may write is refused for the same reason the private key's mode is: this is a control, and a control any local account can raise is not one. Readability is deliberately not constrained — the level is a policy statement the customer should be able to inspect, not a secret.
type Option ¶
type Option func(*Registry)
Option configures a Registry at construction.
func WithConsent ¶
WithConsent sets the consent setting this node reports.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry serves the tools. Construct it with New, which refuses anything malformed at registration rather than at call time.
func (*Registry) SetRunnerForTest ¶
func (r *Registry) SetRunnerForTest(fn func(ctx context.Context, argv []string, maxBytes int) ([]byte, error))
SetRunnerForTest replaces the executor.
Named for its only legitimate use. Tests in other packages need to exercise the registry without shelling out, and the alternative — exporting the executor as a field — would make "what actually runs a tool" configurable in production, which is precisely what should not be.
type Tool ¶
type Tool struct {
// Name is what the Advisor asks for, matched exactly.
Name string
// Description is for the operator reading this file.
Description string
// Sandbox runs the caller's command text in SandboxArgvFor's sandbox.
Sandbox bool
// MaxOutputBytes caps one call's output. Zero means the registry default.
MaxOutputBytes int
// Timeout bounds one call. Zero means the registry default. It must stay
// under the server's per-call cap so this timeout fires first.
Timeout time.Duration
}
Tool is one operation the AI plane may invoke.
type ToolCall ¶
type ToolCall struct {
At time.Time `json:"at"`
Tool string `json:"tool"`
Args map[string]string `json:"args,omitempty"`
Argv []string `json:"argv,omitempty"` // exactly what ran, empty when refused or a GET
Path string `json:"path,omitempty"` // a broker request path; never carries auth
Allowed bool `json:"allowed"`
Reason string `json:"reason,omitempty"`
Duration time.Duration `json:"durationMs,omitempty"`
Bytes int `json:"bytes,omitempty"` // as returned, marker included when truncated
// Truncated records that the command emitted more than the cap and the
// result was cut. The original size is unknowable by design — the runner
// stops reading one byte past the cap rather than buffering the excess.
Truncated bool `json:"truncated,omitempty"`
}
ToolCall is one record in the local log.
Both halves matter. The allowed calls are what the vendor actually did; the refused ones are what the vendor asked for and did not get, which is the part a customer reviewing access most wants to see.