Documentation
¶
Overview ¶
Package tools bundles nocturn's own gated tools — the thin ones whose whole body is "build an agentkit.Tool that gates its target on a shared kind before it acts". They share only the gate model (each owns its own kind constant and target matcher), so they live together here rather than one sprawling package per tool. Heavier tools that carry their own runtime — code_run (QuickJS/wasm) and plugins — stay in their own packages; they just contribute agentkit.Tools that Base folds in the same way.
Index ¶
Constants ¶
const CodeRunTool = "code_run"
CodeRunTool is the tool name Compose adds, so callers can test an agent's filter for it.
const FileKind = "file"
FileKind is the shared gate Kind file MUTATIONS check; the Target is the workspace-relative, forward-slashed path. read/list/stat/search are observations — confined to the workspace Root but ungated (they prompt nobody, matching the old base policy where reads ran silently); write/remove/ move are mutations gated on this kind so they ask. Path matching (a "notes/*" grant covering that directory, path.Match's "*" not crossing "/") lives here with the tool that owns it.
const NotifyKind = "notify"
NotifyKind is the Kind of the notify tool. Its destination is the user, host-owned and never model-chosen, so there is no target to check: whether a holder may reach the user is its cell on the notify node of the permission tree.
const ReadKind = "file.read"
ReadKind is the Kind another tool checks when it reads a workspace file for the model to use elsewhere — a mail's attachment. Its Target is the workspace-relative path. It governs no tool: it is decided by file_read's node for the holder (ReadTool), so a holder that may not read the workspace with file_read may not have a file of it read by any other tool either, and an answer to it is never remembered, since it would be an answer about file_read.
const ReadTool = "file_read"
ReadTool is the tool whose node decides ReadKind.
Variables ¶
var FileSpec = kinds.Spec{Kind: FileKind, Attended: kinds.Ask, Unattended: kinds.Ask, Voice: true, Target: "path"}
FileSpec registers FileKind: a write in the workspace asks. Voice may use the Kind: a spoken session's cage holds only the read tools, which never check it.
var NotifySpec = kinds.Spec{Kind: NotifyKind, Attended: kinds.Allow, Unattended: kinds.Allow, Voice: true}
NotifySpec registers NotifyKind: reaching the user is what the user asked the assistant for, so it runs free everywhere, spoken sessions included.
var ReadSpec = kinds.Spec{Kind: ReadKind, Attended: kinds.Allow, Unattended: kinds.Allow, Voice: true, Target: "path"}
ReadSpec registers ReadKind. Its rules are file_read's defaults: no tool takes its defaults from it, and the decision is file_read's cell.
Functions ¶
func Base ¶
Base builds nocturn's base tools — the set every chat and agent draws from before a per-agent cage narrows it: the network tools (http_read/http_write/dns_resolve/ping), time_now, and — when a Root is given — the workspace-confined file tools. It grows as tools land (notify, …). Returned as a slice so the caller can both form the base ToolSet and scope per-agent subsets from it. code_run is NOT here: it is woven per cage by Compose, so a script's reach is bounded to the tools of its cage.
func Compose ¶
Compose finalizes one cage: the tools of `cage`, plus — only when allowCodeRun — a code_run whose script dispatches over EXACTLY those same tools and nothing more. This is the security seam for code_run: it can never widen authority beyond its cage. An agent caged to a subset that includes code_run reaches only that subset from a script too; an agent NOT granted code_run gets no interpreter at all. (code_run never dispatches itself — reentry is refused — nor sub-agent tools, which are layered on outside a cage.)
Types ¶
type Config ¶
type Config struct {
Secrets *secret.Injector // host-owned credential jar the network tool injects from
Named egress.Secrets // secrets a call names by alias ("as"); nil = naming one is refused
Scanner *secret.Scanner // bidirectional secret leak scanner
Root string // workspace root; file tools are confined here (empty = no file tools)
Notifier Notifier // out-of-band user notification; nil = no notify tool
Logger *slog.Logger // effect-trace (http request / path-escape); nil = silent. gate/scanner log their own events.
}
Config carries the per-workspace wiring the base tools need. Scanner is required (Base fails without it: nothing leaves unscanned). The rest may be zero: a nil Secrets injects no credentials, an empty Root drops the file tools.
type Net ¶
type Net struct {
// contains filtered or unexported fields
}
Net is the network tool group: http_read, http_write, dns_resolve and ping. The HTTP pair sends through egress.Guard, which gates the host, scans what leaves, injects a host-owned credential and redacts what comes back, so the model (and any script or plugin behind it) never sees a bearer and cannot smuggle a secret out. dns_resolve and ping gate and scan their host themselves.
func New ¶
New builds the network tools over a credential injector (nil = nothing to inject) and a leak scanner, which is required (egress.New). opts configure the guard (egress.WithSecrets lets a call name a secret with "as").
func (*Net) SetLogger ¶
SetLogger attaches the effect-trace logger (nil ignored). Call at construction, before the Net is shared across tool calls.
func (*Net) Tools ¶
Tools exposes the network tools. http_read and http_write are split so the tool the model (or a guest's fetch) picks IS the intent: safe methods go through http_read, mutating ones through http_write. Both return a JSON envelope {status, statusText, headers, body} so a caller sees the real outcome, not just a body (a 404 is not mistaken for success) — the same shape the prelude's fetch() reconstructs into a Response.
type Notification ¶
type Notification struct {
Ws string
Kind string
// ItemID is the work item it is about, what a tap opens; empty for a plain notice.
ItemID string
ChatID string
Title string
Message string
}
Notification is one proactive message to the user. Kind says which tool produced it (NotifyKind or reminders.Kind), Ws which workspace it came from, and ChatID the chat or agent run it originated in — together they let a device label it and open the conversation it came out of, instead of receiving an anonymous string. A reminder is rarely an end in itself ("remind me about the meeting" is usually followed by "what was it about"), so landing back in that chat is the useful destination. ChatID is empty when there is nothing to open. The model supplies only Title and Message.
type Notifier ¶
type Notifier interface {
Notify(ctx context.Context, n Notification) error
}
Notifier reaches the user out of band — a phone push, or the terminal. A nil Notifier means the notify tool is not offered at all.
Delivery is best-effort and must not block on the user: an implementation sends and returns, it never waits for an acknowledgement (that is what hitl is for). A non-nil error means the message reached NO device; it is not retryable here, and no implementation retries on its own — so a caller that cannot propagate it must log it rather than discard it. Reaching zero devices because none is registered is NOT an error (nothing failed), it simply returns nil.