You've already forked agentic-coding-workflow
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
// Package handlers 实现 ACP method 的服务端处理器。
|
|
//
|
|
// 每个 file 一个具体 method handler,对应 spec §5.5:
|
|
// - server_fs_read.go fs/read_text_file
|
|
// - server_fs_write.go fs/write_text_file
|
|
// - server_permission.go session/request_permission(MVP 自动批/拒)
|
|
//
|
|
// client_*.go 是服务端 *发起* 请求的辅助 builder(initialize / session/new),
|
|
// 不需要 Handle 接口,直接被 supervisor / relay 调用 NewClientInitializeRequest 等。
|
|
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// SessionContext 是 handler 可见的 session 上下文(dirent 化 acp.Session 的需要字段)。
|
|
// 避免 handlers 子包 import internal/acp 引发循环。
|
|
type SessionContext struct {
|
|
SessionID uuid.UUID
|
|
WorkspaceID uuid.UUID
|
|
UserID uuid.UUID
|
|
CwdPath string
|
|
AgentSessionID *string // 可能 nil(handshake 未完成时不应触发 fs/* 但兜底)
|
|
ToolAllowlist []string // agent kind 配置的工具白名单,命中则自动放行
|
|
}
|
|
|
|
// FsResult 是 fs/* method 处理后返回给 relay 的结果。要么 OK(带 result),
|
|
// 要么 Err(带 jsonrpc 错误码)。
|
|
type FsResult struct {
|
|
OK json.RawMessage
|
|
Err *FsError
|
|
}
|
|
|
|
// FsError 是 jsonrpc 错误码(spec §5.4 定义 -32001 = path outside worktree)。
|
|
type FsError struct {
|
|
Code int
|
|
Message string
|
|
}
|
|
|
|
// FsHandler combines fs/* method handlers so Relay can hold one reference.
|
|
type FsHandler struct {
|
|
Read *FsReadHandler
|
|
Write *FsWriteHandler
|
|
List *FsListHandler
|
|
Grep *GrepHandler
|
|
}
|
|
|
|
// NewFsHandler constructs a composite FsHandler with default sub-handlers.
|
|
func NewFsHandler() *FsHandler {
|
|
return &FsHandler{
|
|
Read: NewFsReadHandler(),
|
|
Write: NewFsWriteHandler(),
|
|
List: NewFsListHandler(),
|
|
Grep: NewGrepHandler(),
|
|
}
|
|
}
|