Skip to content

feat(core): ToolRegistry execute 注入 ToolContext #52

@uchouT

Description

@uchouT

背景

当前 ToolRegistryEntry.execute 签名只接收 args,没有任何执行上下文:

execute: (args: Record<string, unknown>) => Promise<ToolExecutionResult>

用户自定义 tool 无法获取当前 sessionId、StelloAgent 引用、对话元数据等信息。目前只能通过闭包捕获外部引用,但这对第三方插件开发者不友好。

对比

OpenCode 给 tool 提供 ToolContext

  • sessionID / messageID — 当前会话定位
  • agent — 当前 agent 标识
  • directory / worktree — 工作目录
  • abort — AbortSignal
  • metadata() — 元数据读写
  • ask() — 权限确认回调

Claude Code 通过 MCP 协议在独立进程间传递上下文。

提议

execute 注入第二个参数 ToolContext

interface ToolContext {
  sessionId: string
  // 按需扩展
}

interface ToolRegistryEntry {
  execute: (args: Record<string, unknown>, ctx: ToolContext) => Promise<ToolExecutionResult>
}

ToolContext 的具体字段在实现时再确定,初始保持最小集合。

优先级

低。当前闭包方式可以满足应用作者的需求,此 issue 主要为第三方插件生态做准备。

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions