feat(cli): /terminals、/cmd/history、/terminal 对齐 WebUI(事件面 + ToolAPI,无需新接口)

去看了一遍源码,纠正上轮判断:终端与命令历史也不是 WebUI 插件私有。
- 终端会话:agentcli 插件持有,发 EventTerminalOutput;WebUI 只是订阅该事件
  自己攒视图。命令历史:WebUI 订阅 EventToolCall 的 cmd_run 攒的。
- 于是 CLI 插件订阅同样两个事件即可同口径:/terminals、/cmd/history。
- 开/写/读/关终端:SDK 的 ToolAPI.ExecuteTool 已允许跨插件调用工具,
  CLI 直接调 agentcli 的 terminal_create/write/read/close,新增 /terminal 子命令。

waiter 侧同步:/terminals、/cmd/history 两条路(local/remote)都接;/terminal
仅在 local 可用(远端 WebUI 无对应 REST 端点,明确提示而不是当聊天发出去)。
This commit is contained in:
JianFeeeee
2026-09-15 15:31:32 +08:00
parent 0227fc2d4d
commit 3cce605722
2 changed files with 246 additions and 0 deletions

View File

@ -47,6 +47,9 @@ Server commands (local 与 remote 行为一致):
/adapters remove <name> remove a Lua adapter
/network network status + LLM endpoints
/runtime scheduler / residents / channel topology
/terminals list terminal sessions
/cmd/history command execution history
/terminal create|write|read|close … (local mode; calls agentcli tools)
/persona show persona (/persona set default|custom|later [text])
/agents list agents
/chat <text> send to agent
@ -353,6 +356,34 @@ Any other text is sent to the agent directly.`)
}
return true
case cmd == "/terminals":
if rc := state.RemoteConn(); rc != nil {
d, _ := rc.DoAPI("GET", "/api/v1/terminals", "")
printJSON(out, d)
} else {
state.Send("/terminals")
}
return true
case cmd == "/cmd/history":
if rc := state.RemoteConn(); rc != nil {
d, _ := rc.DoAPI("GET", "/api/v1/cmd/history", "")
printJSON(out, d)
} else {
state.Send("/cmd/history")
}
return true
case cmd == "/terminal" || strings.HasPrefix(cmd, "/terminal "):
if rc := state.RemoteConn(); rc != nil {
// 远端 WebUI 没有“开终端”的 REST 端点(终端由 agentcli 工具创建),
// 不静默当聊天发出去,直接说明。
fmt.Fprintln(out, "remote 模式暂不支持终端操作;请在 local 模式或让 agent 调 terminal_* 工具")
} else {
state.Send(cmd)
}
return true
case cmd == "/runtime":
if rc := state.RemoteConn(); rc != nil {
d, _ := rc.DoAPI("GET", "/api/v1/runtime", "")