Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
refactor(httpapi): extract assistantSessionToolName for session MCP prefix stripping (#392)
fx-kurumi80ec3cc04ae9
diff --git a/internal/httpapi/assistant_session_tool_name_test.go b/internal/httpapi/assistant_session_tool_name_test.gonew file mode 100644index 00000000..efc788f7--- /dev/null+++ b/internal/httpapi/assistant_session_tool_name_test.go@@ -0,0 +1,41 @@+package httpapi++import (+ "encoding/json"+ "testing"+)++func TestAssistantSessionToolName(t *testing.T) {+ cases := map[string]string{+ "mcp__agentflow_session__submit_assistant_reply": "submit_assistant_reply",+ " mcp__agentflow_session__workbench_workspace_open ": "workbench_workspace_open",+ "Agent": "Agent",+ " Read\n": "Read",+ "mcp__other__x": "mcp__other__x",+ "": "",+ " ": "",+ }+ for in, want := range cases {+ if got := assistantSessionToolName(in); got != want {+ t.Errorf("assistantSessionToolName(%q) = %q, want %q", in, got, want)+ }+ }+}++func TestAssistantSessionToolNameCallSites(t *testing.T) {+ if !assistantProtocolTool(" mcp__agentflow_session__submit_clarification ") {+ t.Fatal("prefixed protocol tool must be recognized")+ }+ if _, ok := assistantToolStreamEvent("t1", "mcp__agentflow_session__submit_assistant_reply", nil); ok {+ t.Fatal("protocol tool must not produce a stream event")+ }+ tool, detail := assistantToolDisplay(" mcp__agentflow_session__workbench_publish_artifact", json.RawMessage(`{"title":"报告"}`))+ if tool != "发布产物" || detail != "报告" {+ t.Fatalf("display = %q %q", tool, detail)+ }+ start := `{"type":"stream_event","event":{"type":"content_block_start","content_block":{"type":"tool_use","id":"r1","name":"mcp__agentflow_session__submit_assistant_reply"}}}`+ events := assistantLineEvents(start)+ if len(events) != 1 || events[0].Kind != "draftStart" || events[0].ID != "r1" {+ t.Fatalf("events = %+v", events)+ }+}diff --git a/internal/httpapi/assistant_stream.go b/internal/httpapi/assistant_stream.goindex ad31d3e0..a3ce7178 100644--- a/internal/httpapi/assistant_stream.go+++ b/internal/httpapi/assistant_stream.go@@ -101,8 +101,17 @@ func (f *assistantStreamFilter) accept(ev assistantStreamEvent) bool {}}+// assistantSessionToolPrefix namespaces the platform's own session MCP tools.+const assistantSessionToolPrefix = "mcp__agentflow_session__"++// assistantSessionToolName returns name without surrounding space and the+// session MCP prefix, so session tools compare by their bare tool name.+func assistantSessionToolName(name string) string {+ return strings.TrimPrefix(strings.TrimSpace(name), assistantSessionToolPrefix)+}+func assistantProtocolTool(name string) bool {- switch strings.TrimPrefix(strings.TrimSpace(name), "mcp__agentflow_session__") {+ switch assistantSessionToolName(name) {case "submit_assistant_reply", "submit_clarification":return truedefault:@@ -203,7 +212,7 @@ func assistantLineEvents(line string) []assistantStreamEvent {if evt.Event.Type == "content_block_start" {switch evt.Event.ContentBlock.Type {case "tool_use":- if strings.TrimPrefix(strings.TrimSpace(evt.Event.ContentBlock.Name), "mcp__agentflow_session__") == "submit_assistant_reply" {+ if assistantSessionToolName(evt.Event.ContentBlock.Name) == "submit_assistant_reply" {if subAgent {return nil}@@ -268,7 +277,7 @@ func assistantCLINoticeText(text string) bool {}func assistantToolStreamEvent(id, name string, input json.RawMessage) (assistantStreamEvent, bool) {- name = strings.TrimPrefix(strings.TrimSpace(name), "mcp__agentflow_session__")+ name = assistantSessionToolName(name)if name == "" || assistantProtocolTool(name) {return assistantStreamEvent{}, false}@@ -332,7 +341,7 @@ func assistantAgentReport(text string) string {}func assistantToolDisplay(name string, input json.RawMessage) (string, string) {- name = strings.TrimPrefix(strings.TrimSpace(name), "mcp__agentflow_session__")+ name = assistantSessionToolName(name)var m map[string]anyif len(input) > 0 {_ = json.Unmarshal(input, &m)@@ -356,7 +365,7 @@ func assistantToolDisplay(name string, input json.RawMessage) (string, string) {}return "发布产物", ""case "DeferExecuteTool", "MCP":- inner := strings.TrimPrefix(str("toolName", "tool", "tool_name", "name", "mcp_tool"), "mcp__agentflow_session__")+ inner := assistantSessionToolName(str("toolName", "tool", "tool_name", "name", "mcp_tool"))if inner == "" || inner == name {// CodeBuddy streams an empty wrapper input first. Wait for the// complete snapshot instead of consuming its tool ID with an