agy

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 23 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

Overview

Package agy 提供 agy (Antigravity CLI) 的 executor.Adapter 契约实现。

perm.go —— 权限裁决 unix socket 服务端。

职责:

  • 在任务目录的 perm.sock 上受理裁决请求(由 agy 经 PreToolUse hook 拉起的 permission-hook 进程发来)
  • 把请求以回调交给 adapter(转成 AdapterEvent 进 manager 审批链)
  • 收到裁决后回发给对应连接,放行或拒绝该次工具调用

probe.go —— 只读存活探测。

Package agy 提供 agy (Antigravity CLI) 的 executor.Adapter 实现。

职责:

  • 组 agy 的 argv(headless 双向 stream-json),经 prochost 以 detached 方式拉起
  • 经命名管道 in.fifo 投递指令;stdout 落 out.jsonl,stderr 落 agy.log
  • 死亡判定(out.jsonl 末尾的 handoff_exit 哨兵 + 存活锁)与凭据持久化(proc.json)

reap.go —— 无内存运行态时的确定性兜底回收与进程句柄获取。

resume.go —— 执行恢复:热重连与冷恢复。

spend.go —— agy 的用量消耗账目解析。

职责:把 result 行的 usage(会话累计值)解析成一条 proto.SpendEntry。 使用会话级稳定 Key 覆盖既有条目,防止多回合累计值在 ledger 中被错误求和。

stream.go —— out.jsonl 的增量解析(agy stream-json → 内部消息)。

职责:

  • 从指定 offset 起持续读 out.jsonl 的新行,宽容解码为 streamMsg 交回调
  • 维护已消费 offset,供 proc.json 持久化与 agentd 重启后续读

taskenv.go —— agy 任务级运行环境与策略物料生成。

职责:

  • 在 taskDir/agyhome 下生成 headless agy 读取的 hooks(matcher=*)、原生 allow 与登录凭据
  • 渲染首回合 prompt(带任务 ID、计划内容与纪律块)
  • RestoreTaskEnv 仍能清掉历史任务写进 workspace 的 gate sidecar

不写 workdir/.agents/hooks.json:那份会被 --add-dir 再加载,与 HOME 双开火。

边界:Stop、Start rollback 与 Reap 必须调用 RestoreTaskEnv;本文件不负责启停进程。

usage.go —— agy 的 token 用量解析。

职责:把 step_update 或 result 里的 usage 对象解析为 proto.Usage。 边界:纯函数,不碰 runState、不发事件、不写日志。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseUsage

func ParseUsage(raw *AgyUsageRaw) *proto.Usage

ParseUsage 把 agy 的原始用量转换为 proto.Usage。

上下文占用 = input_tokens + cache_read_tokens。 零值时返回 nil(不使用 0 冒充)。

func RestoreTaskEnv

func RestoreTaskEnv(taskDir string) (err error)

RestoreTaskEnv 从 taskDir 的 sidecar 恢复 agy hooks 物料。

参数:taskDir 为任务专属目录,sidecar 位于其中。 返回:所有恢复动作成功时返回 nil;缺少 sidecar 视为幂等成功。 注意:workdir 被回收时跳过文件恢复;已跟踪 hooks 的 skip-worktree 必须清除。

func WriteTaskEnv

func WriteTaskEnv(workdir, taskDir, taskID, planContent, sockPath, handoffBin, disciplineBlock string) (hooksPath, promptText string, err error)

WriteTaskEnv 在任务 HOME 落下 agy 策略物料,并渲染首回合 prompt。

参数:workdir 为任务工作区(本函数不再往其中写 gate);taskDir 为任务专属目录; sockPath 为权限裁决套接字;其余参数用于 prompt 与 hooks 命令。 返回任务 HOME 内 hooks.json 路径和首回合 prompt;oauth 凭据缺失或任一物料 写入失败时返回错误。

不写 workspace .agents/hooks.json:headless 读的是 HOME;B309 --add-dir 会 再加载 workspace 那份,双写同一 gate 导致同一 step_N 打两次(B310/B314)。

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter 是 agy 的 executor.Adapter 实现。

func New

func New(log *slog.Logger) *Adapter

New 创建 agy adapter。

func (*Adapter) DenyReasonInBand

func (a *Adapter) DenyReasonInBand() bool

DenyReasonInBand 表明本 adapter 把拒绝理由与裁决同帧送达模型(通过 PreToolUse hook 的 reason 字段)。 manager 据此跳过 B50 的带外挂起注入,避免模型被同一条理由说两遍。

func (*Adapter) Events

func (a *Adapter) Events(taskID string) <-chan executor.AdapterEvent

Events 返回任务的事件流通道。

func (*Adapter) Probe

Probe 只读探测 agy 执行器是否仍存活。

func (*Adapter) ProcHandle

func (a *Adapter) ProcHandle(taskID, taskDir string) (prochost.Handle, error)

ProcHandle 交出该任务的进程句柄(来自任务目录的 proc.json)。

func (*Adapter) Reap

func (a *Adapter) Reap(taskID, taskDir string) error

Reap 在没有内存运行态时按 proc.json 兜底回收 executor 侧资源。

func (*Adapter) RespondPermission

func (a *Adapter) RespondPermission(ctx context.Context, taskID, permID, decision, reason string) error

RespondPermission 应答权限门。

func (*Adapter) Resume

func (a *Adapter) Resume(req executor.ResumeReq) (out executor.ResumeOutcome, err error)

Resume 恢复 agentd 重启前已在执行的任务。

func (*Adapter) Send

func (a *Adapter) Send(ctx context.Context, taskID, text string) (err error)

Send 往同一会话续发指令。

func (*Adapter) Start

func (a *Adapter) Start(ctx context.Context, req executor.StartReq) (err error)

Start 启动任务执行并立即返回。

func (*Adapter) Stop

func (a *Adapter) Stop(taskID string) (err error)

Stop 终止任务执行并回收资源。

type AgyUsageRaw

type AgyUsageRaw struct {
	InputTokens     int `json:"input_tokens"`
	OutputTokens    int `json:"output_tokens"`
	ThinkingTokens  int `json:"thinking_tokens"`
	CacheReadTokens int `json:"cache_read_tokens"`
	TotalTokens     int `json:"total_tokens"`
}

AgyUsageRaw 是 agy 输出中的 usage 结构。

type Proc

type Proc struct {
	Handle    prochost.Handle
	TaskDir   string
	SessionID string
}

Proc 描述一个运行中的 agy 进程句柄。

func StartProc

func StartProc(ctx context.Context, req StartProcReq, log *slog.Logger) (*Proc, error)

StartProc 备物料、经 prochost 拉起 shim 承载 agy,返回进程句柄。

func (*Proc) Alive

func (p *Proc) Alive() bool

Alive 探测 agy 进程是否仍存活。

func (*Proc) Kill

func (p *Proc) Kill() error

Kill 终止 agy 进程并清理存活锁。

func (*Proc) WriteInput

func (p *Proc) WriteInput(text string) error

WriteInput 往输入通道投递一条 stream-json user message。

type StartProcReq

type StartProcReq struct {
	RepoPath  string
	TaskID    string
	TaskDir   string
	SessionID string
	Model     string
	Env       []string
	MarkRoot  string
	Resume    bool
}

StartProcReq 是一次 StartProc 的完整入参。

Jump to

Keyboard shortcuts

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