docs(cyrene): cmd/cyrene 存量英文注释中文化(22 个非测试文件,仅注释)
- 四组并行完成:main/wire*.go、wire_capacity|channels|runtime、channels|persona_*|emotion|observability、 voice|plugins|stream|skills|vision|subagent_tool|extractor|mcp|sessionread_tool|terminal_tool。 - 机械校验(git diff -U0 去 // 行与空行)仅剩 wire_frontend.go:84 一处行尾注释:代码前缀 「\ta.gw = gw 」经 cat -A 与 HEAD 逐字节比对一致(allow 清单已声明)。 - 验收:隔离 worktree(HEAD + 本批 patch)go build/vet 绿、全树 58 包 ok、 linux/amd64 + darwin/arm64 交叉编译绿;gofmt -l 干净。 - 备注:整树两次红均为负载敏感 flake(backthink / orchestration 的 timeout 类用例单独 -count=20 全过)。
This commit is contained in:
1 parent
5c2189efb0
commit
52f08dc343
22 files changed
+455
-586
No files matched your search
+13
-17
@@ -11,27 +11,26 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/exec"
|
||||
)
|
||||
|
||||
// terminalToolName is the registered name of the exec/terminal tool.
|
||||
// terminalToolName 是 exec/terminal 工具的注册名。
|
||||
const terminalToolName = "terminal"
|
||||
|
||||
// terminalTool is an sdk.Tool that runs a command through the grant-based exec
|
||||
// sandbox (exec.Provider). It is registered even when the sandbox is closed:
|
||||
// Execute then returns exec.ErrExecutionDisabled, so the agent gains the ability
|
||||
// to run code only after the owner explicitly enables the sandbox (default off).
|
||||
// terminalTool 是 sdk.Tool,通过基于授权的 exec 沙箱(exec.Provider)运行命令。
|
||||
// 即使沙箱关闭它也会被注册:此时 Execute 返回 exec.ErrExecutionDisabled,因此
|
||||
// agent 只有在主人显式启用沙箱后才获得执行代码的能力(默认关闭)。
|
||||
type terminalTool struct {
|
||||
prov exec.Provider
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
// Name returns the tool identifier.
|
||||
// Name 返回工具标识符。
|
||||
func (t *terminalTool) Name() string { return terminalToolName }
|
||||
|
||||
// Description explains what the tool does.
|
||||
// Description 说明工具做什么。
|
||||
func (t *terminalTool) Description() string {
|
||||
return "Run a terminal command through the sandboxed exec provider and return its stdout, stderr and exit code."
|
||||
}
|
||||
|
||||
// Parameters returns the input JSON Schema.
|
||||
// Parameters 返回输入 JSON Schema。
|
||||
func (t *terminalTool) Parameters() (map[string]any, error) {
|
||||
return map[string]any{
|
||||
"type": "object",
|
||||
@@ -53,9 +52,8 @@ func (t *terminalTool) Parameters() (map[string]any, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Execute runs the command via the exec provider and returns its outcome. When
|
||||
// the sandbox is closed the provider returns exec.ErrExecutionDisabled, which the
|
||||
// dispatcher wraps into a tool error safe to feed back to the LLM.
|
||||
// Execute 通过 exec provider 运行命令并返回结果。沙箱关闭时 provider 返回
|
||||
// exec.ErrExecutionDisabled,分发器会把它包装成可安全回喂给 LLM 的工具错误。
|
||||
func (t *terminalTool) Execute(ctx context.Context, args any) (any, error) {
|
||||
m, ok := args.(map[string]any)
|
||||
if !ok {
|
||||
@@ -85,9 +83,8 @@ func (t *terminalTool) Execute(ctx context.Context, args any) (any, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// timeoutArg converts the optional timeout argument (seconds) to a duration. A
|
||||
// missing or non-positive value returns zero, letting the provider apply its own
|
||||
// default.
|
||||
// timeoutArg 把可选的 timeout 参数(秒)转换为 duration。缺失或非正值返回 0,
|
||||
// 由 provider 应用自己的默认值。
|
||||
func timeoutArg(v any) time.Duration {
|
||||
switch n := v.(type) {
|
||||
case float64:
|
||||
@@ -102,9 +99,8 @@ func timeoutArg(v any) time.Duration {
|
||||
return 0
|
||||
}
|
||||
|
||||
// wireTerminalTool registers the terminal tool with the dispatcher so the agent
|
||||
// can issue sandboxed terminal commands. It no-ops (with a warning) when no exec
|
||||
// provider is wired, which keeps callers safe.
|
||||
// wireTerminalTool 向分发器注册 terminal 工具,使 agent 能发出沙箱内终端命令。
|
||||
// 未接入 exec provider 时它只告警并空操作,以保证调用方安全。
|
||||
func (a *app) wireTerminalTool() {
|
||||
log := logger.WithSource(a.log, "cmd/cyrene")
|
||||
if a.execProv == nil {
|
||||
|
||||
Reference in new issue
Block a user