Help us shape the future of Go! Take the 2026 Go Developer Survey

acpclient

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package acpclient 提供 fastgit 作为 ACP Client 的最小可用实现: spawn 外部 ACP agent 子进程,通过 stdio JSON-RPC 完成 initialize -> session/new -> session/prompt,并收集 agent_message 文本。

Index

Constants

View Source
const DefaultTimeout = 2 * time.Minute

DefaultTimeout 是单轮 prompt 的默认上限。

Variables

This section is empty.

Functions

func PermissionAllowOnce added in v0.0.18

PermissionAllowOnce 是自动放行策略:优先 allow_once,其次 allow_always, 都没有则取消。适合 CI/批处理的 agent 模式。

func UpdateLine added in v0.0.18

func UpdateLine(update acp.SessionUpdate) string

UpdateLine renders a session/update into a short one-line progress string. Returns empty string for updates not worth showing.

Types

type Agent

type Agent struct {
	Name    string
	Command string
	Args    []string
	Env     map[string]string
}

Agent 描述如何启动一个 ACP agent 子进程。

type Options

type Options struct {
	// Cwd 为 session 工作目录,空则使用当前目录。
	Cwd string
	// System 与 Prompt 合并为一条用户消息(ACP 没有独立的 system 通道)。
	System string
	Prompt string
	// Timeout 为整个轮次上限,零值使用 DefaultTimeout。
	Timeout time.Duration
	// OnUpdate 可选,收到每个 session/update 时回调。
	OnUpdate func(update acp.SessionUpdate) error
	// OnPermission 可选,nil 表示自动拒绝 agent 的权限请求(只读场景)。
	OnPermission PermissionHandler
	// ClientFS 为 true 时声明并处理 fs/read_text_file、fs/write_text_file,
	// 路径沙箱限定在 Cwd 内。
	ClientFS bool
}

Options 控制一次 prompt 轮次。

type PermissionHandler added in v0.0.18

PermissionHandler 决定如何回应 agent 的 session/request_permission。 Options.OnPermission 为 nil 时维持自动拒绝(commit 生成等只读场景)。

func PermissionInteractive added in v0.0.18

func PermissionInteractive(ask func(title string, options []acp.PermissionOption) string) PermissionHandler

PermissionInteractive 用注入的 ask 回调向用户确认。ask 返回选中的 optionId;返回空字符串视为拒绝(取消)。

type Result

type Result struct {
	Text       string
	StopReason acp.StopReason
}

Result 是一次 prompt 轮次的输出。

func Run

func Run(ctx context.Context, agent Agent, opts Options) (Result, error)

Run spawns the agent, performs one prompt turn and returns the collected agent_message text. The agent process is always terminated before returning.

Jump to

Keyboard shortcuts

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