Documentation
¶
Index ¶
- func AllApprovals() (map[string]Approvals, error)
- func NormalizeName(name string) string
- func PermissionsFile() string
- func ProjectRoot(dir string) string
- func Refused(result string) bool
- func RunShell(ctx context.Context, show UI, command string) (out string, ok bool)
- func ToolDefinitions(timeout int, bg Background) []docsgpt.Tool
- func UpdateApprovals(project string, change func(a *Approvals)) error
- type Approvals
- type Background
- type Event
- type Info
- type Processes
- func (ps *Processes) Adopt(r *shellRun, command string, started time.Time, before func() string) (Info, error)
- func (ps *Processes) Close() int
- func (ps *Processes) Drain() []Event
- func (ps *Processes) Format(events []Event) string
- func (ps *Processes) List() []Info
- func (ps *Processes) Monitor(command, dir, desc string, timeout time.Duration) (Info, error)
- func (ps *Processes) Output(id string, n int) (Info, string, error)
- func (ps *Processes) Running() int
- func (ps *Processes) Start(command, dir string, timeout time.Duration) (Info, error)
- func (ps *Processes) Stop(id string, user bool) (Info, error)
- func (ps *Processes) Unread(events []Event)
- type Session
- func (s *Session) Forget(line string) error
- func (s *Session) ForgetApprovals(flag bool) error
- func (s *Session) Handle(ctx context.Context, cancel context.CancelFunc, tc docsgpt.ToolCall) docsgpt.ToolResult
- func (s *Session) LoadApprovals() (approveAll bool, err error)
- func (s *Session) SetApproveAll(on bool) error
- type UI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllApprovals ¶ added in v1.12.0
AllApprovals returns what is kept for every project.
func NormalizeName ¶
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
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
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
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
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
ProjectApprovals returns what is kept for project.
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 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.
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
Close stops every process still running and returns how many it stopped. Events stop with it.
func (*Processes) Format ¶ added in v1.12.0
Format writes events for the model, with what still runs.
func (*Processes) Monitor ¶ added in v1.12.0
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
Output is process id's status and the last n lines of its output.
func (*Processes) Start ¶ added in v1.12.0
Start runs command in the background in dir, its output in its log; a timeout over 0 stops it then.
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) ForgetApprovals ¶ added in v1.12.0
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
func (s *Session) Handle(ctx context.Context, cancel context.CancelFunc, tc docsgpt.ToolCall) docsgpt.ToolResult
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
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
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.