tools

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 32 Imported by: 0 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllApprovals added in v1.12.0

func AllApprovals() (map[string]Approvals, error)

AllApprovals returns what is kept for every project.

func NormalizeName

func NormalizeName(name string) string

NormalizeName strips the suffix the server appends to tool names.

func PermissionsFile added in v1.12.0

func PermissionsFile() string

PermissionsFile is where the approvals of every project are kept.

func ProjectRoot added in v1.12.0

func ProjectRoot(dir string) string

ProjectRoot is the project dir belongs to: the nearest directory with a .git, else dir itself, symlinks resolved.

func Refused added in v1.7.0

func Refused(result string) bool

Refused reports whether result is what Handle returned for a call that did not run: denied, interrupted at the prompt, or not approvable.

func RunShell added in v1.7.0

func RunShell(ctx context.Context, show UI, command string) (out string, ok bool)

RunShell runs a command the user typed in the chat ("!cmd"), shown with show like the agent's commands but without asking and without a time limit. It returns the output and exit status, for the model, and whether the command succeeded (exit 0).

func ToolDefinitions

func ToolDefinitions(timeout int, bg Background) []docsgpt.Tool

ToolDefinitions returns the tool schemas to send in chat completion requests. timeout is the default a command gets, in seconds.

func UpdateApprovals added in v1.12.0

func UpdateApprovals(project string, change func(a *Approvals)) error

UpdateApprovals changes what is kept for project with change, read afresh (another chat may have added to it) and written atomically, 0600.

Types

type Approvals added in v1.12.0

type Approvals struct {
	Commands   []string  `json:"commands,omitempty"` // alwaysKey keys
	MCP        []string  `json:"mcp,omitempty"`      // a server, or server/tool
	Writes     bool      `json:"writes,omitempty"`
	Reads      bool      `json:"reads,omitempty"`
	ApproveAll bool      `json:"approve_all,omitempty"`
	Updated    time.Time `json:"updated"`
}

Approvals are the "Always allow" and "Always approve" choices kept for a project in ~/.docsgpt/permissions.json, never in the project itself: a repository cannot approve anything for whoever clones it.

func ProjectApprovals added in v1.12.0

func ProjectApprovals(project string) (Approvals, error)

ProjectApprovals returns what is kept for project.

func (Approvals) Describe added in v1.12.0

func (a Approvals) Describe() []string

Describe lists what is kept, a line each.

func (Approvals) Empty added in v1.12.0

func (a Approvals) Empty() bool

Empty reports whether nothing is kept.

type Background added in v1.12.0

type Background int

Background says where background processes go: nowhere, a chat (they run until it ends, and their events start a turn), or one answer (ask: they stop when it ends).

const (
	NoBackground Background = iota
	ChatBackground
	AnswerBackground
)

type Event added in v1.12.0

type Event struct {
	ID   string
	Text string // for the model and the transcript
}

Event is something a background process did, for the model.

type Info added in v1.12.0

type Info struct {
	ID, Command, Description string
	Monitor, Running         bool
	Started, Ended           time.Time
	Exit                     int
	How                      string
	Log                      string
	Left                     time.Duration // a running monitor's time left
}

Info describes a process for /ps and the footer.

func (Info) Describe added in v1.12.0

func (i Info) Describe() string

Describe is a line about the process for the model.

func (Info) Status added in v1.12.0

func (i Info) Status() string

Status says what a process is doing, in a few words: "running · 3m", "exited 0 · 2m ago", "monitor · 4m left".

type Processes added in v1.12.0

type Processes struct {
	// Wake, when set, is called (from any goroutine) once events wait,
	// eventDelay after the first: the chat sends them to the model. Ask
	// leaves it nil; its events go with the next tool result only.
	Wake func()
	// contains filtered or unexported fields
}

Processes runs the commands the model starts in the background (run_command with run_in_background, local_monitor, a command the user moves there with Ctrl+B) for one chat or ask run: each in a process group of its own, its output in a log file, all of them stopped by Close. What they do comes back as events: an exit, a monitor's lines.

func NewProcesses added in v1.12.0

func NewProcesses(wake func()) *Processes

NewProcesses returns an empty set; wake is Processes.Wake.

func (*Processes) Adopt added in v1.12.0

func (ps *Processes) Adopt(r *shellRun, command string, started time.Time, before func() string) (Info, error)

Adopt takes over a command that ran in the foreground since started (moved with Ctrl+B): what it printed so far (before, read as its output is held) goes first into its log, then the rest.

func (*Processes) Close added in v1.12.0

func (ps *Processes) Close() int

Close stops every process still running and returns how many it stopped. Events stop with it.

func (*Processes) Drain added in v1.12.0

func (ps *Processes) Drain() []Event

Drain returns the events waiting, and forgets them.

func (*Processes) Format added in v1.12.0

func (ps *Processes) Format(events []Event) string

Format writes events for the model, with what still runs.

func (*Processes) List added in v1.12.0

func (ps *Processes) List() []Info

List describes every process of the run, oldest first.

func (*Processes) Monitor added in v1.12.0

func (ps *Processes) Monitor(command, dir, desc string, timeout time.Duration) (Info, error)

Monitor runs command in the background as a monitor: each line of its stdout is an event, its stderr goes only to its log. It is stopped after timeout.

func (*Processes) Output added in v1.12.0

func (ps *Processes) Output(id string, n int) (Info, string, error)

Output is process id's status and the last n lines of its output.

func (*Processes) Running added in v1.12.0

func (ps *Processes) Running() int

Running counts the processes still running.

func (*Processes) Start added in v1.12.0

func (ps *Processes) Start(command, dir string, timeout time.Duration) (Info, error)

Start runs command in the background in dir, its output in its log; a timeout over 0 stops it then.

func (*Processes) Stop added in v1.12.0

func (ps *Processes) Stop(id string, user bool) (Info, error)

Stop stops process id with everything it started. user says the user stopped it (the model is told), else the model did (it knows).

func (*Processes) Unread added in v1.12.0

func (ps *Processes) Unread(events []Event)

Unread puts events back, first, without waking anyone: a turn that carried them failed, so they go with the next one.

type Session added in v1.7.0

type Session struct {
	AutoApprove bool          // run every call unasked: --auto-approve, "Always approve", /approve
	Timeout     time.Duration // per command or read
	UI          UI            // stderr when nil
	MCP         *mcp.Manager  // the MCP servers' tools, if any
	// Processes runs the background processes and monitors; nil offers
	// none (run_in_background is then ignored).
	Processes *Processes
	// Project is the project root the "Always" choices are kept for (see
	// Approvals); "" keeps them for the session only.
	Project string
	// contains filtered or unexported fields
}

Session runs the model's tool calls for one chat session or ask run. Approval is the only gate: every command and write is shown and asked about, unless AutoApprove is set or the user chose "Always allow" for it earlier in the session. Reads ask only outside the working directory or for files that may hold secrets (readReason).

func (*Session) Forget added in v1.12.0

func (s *Session) Forget(line string) error

Forget drops one kept approval, as Describe names it.

func (*Session) ForgetApprovals added in v1.12.0

func (s *Session) ForgetApprovals(flag bool) error

ForgetApprovals drops what the session allowed and what is kept for its project; AutoApprove stays as the flag (--auto-approve) set it, given.

func (*Session) Handle added in v1.7.0

Handle runs one tool call and returns the result for the model. A Ctrl+C (or Esc) at the approval prompt calls cancel, which stops the run.

func (*Session) LoadApprovals added in v1.12.0

func (s *Session) LoadApprovals() (approveAll bool, err error)

LoadApprovals takes what is kept for the session's project: what it allows runs without asking. It reports whether every call is approved that way, for the chat to say so.

func (*Session) SetApproveAll added in v1.12.0

func (s *Session) SetApproveAll(on bool) error

SetApproveAll turns AutoApprove on or off, and keeps that for the project (/approve).

type UI added in v1.7.0

type UI interface {
	// Open starts the block of a call; another Open before Close ends
	// the first as it is (a command the user edited).
	Open(title, note string)
	Lines(lines []string) // preview lines, safe already
	Output() io.Writer    // a running command's output, until Close
	Close(ok bool, status string)
	Choose(items []ui.Item) (string, error) // ui.ErrCancelled on Esc or Ctrl+C
	Edit(title, value string) (string, error)
}

UI shows tool calls and asks the user about them: on stderr by default (ask), in the transcript and panel of the chat's screen there.

func StderrUI added in v1.12.0

func StderrUI() UI

StderrUI is the UI a Session has by default.

Jump to

Keyboard shortcuts

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